From 7d02a801ad94adddfa76dc5b8ec599224bcf5317 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Wed, 21 Jul 2010 00:26:32 +1200 Subject: [PATCH] minicursors for minimap. Bugs: ra doesn't define a sequence for move-blocked-minimap; cursor hotspot is wrong. --- OpenRA.Game/Graphics/SequenceProvider.cs | 5 +++++ OpenRA.Game/Orders/UnitOrderGenerator.cs | 25 ++++++++---------------- OpenRA.Game/Widgets/RadarBinWidget.cs | 21 ++++++++++++++++++++ mods/cnc/sequences.xml | 2 +- 4 files changed, 35 insertions(+), 18 deletions(-) diff --git a/OpenRA.Game/Graphics/SequenceProvider.cs b/OpenRA.Game/Graphics/SequenceProvider.cs index f5977c5047..41f1755573 100644 --- a/OpenRA.Game/Graphics/SequenceProvider.cs +++ b/OpenRA.Game/Graphics/SequenceProvider.cs @@ -78,6 +78,11 @@ namespace OpenRA.Graphics { return units[unit].ContainsKey(seq); } + + public static bool HasCursorSequence(string cursor) + { + return cursors.ContainsKey(cursor); + } public static CursorSequence GetCursorSequence(string cursor) { diff --git a/OpenRA.Game/Orders/UnitOrderGenerator.cs b/OpenRA.Game/Orders/UnitOrderGenerator.cs index 436cc83f59..b5ae41d598 100644 --- a/OpenRA.Game/Orders/UnitOrderGenerator.cs +++ b/OpenRA.Game/Orders/UnitOrderGenerator.cs @@ -55,24 +55,15 @@ namespace OpenRA.Orders public string GetCursor( World world, int2 xy, MouseInput mi ) { - return ChooseCursor(world, mi); - } + var c = Order(world, xy, mi) + .Select(o => o.Subject.traits.WithInterface() + .Select(pc => pc.CursorForOrderString(o.OrderString, o.Subject, o.TargetLocation)).FirstOrDefault(a => a != null)) + .FirstOrDefault(a => a != null); - string ChooseCursor(World world, MouseInput mi) - { - //using (new PerfSample("cursor")) - { - var p = Game.controller.MousePosition; - var c = Order(world, p.ToInt2(), mi) - .Select(o => o.Subject.traits.WithInterface() - .Select(pc => pc.CursorForOrderString(o.OrderString, o.Subject, o.TargetLocation)).FirstOrDefault(a => a != null)) - .FirstOrDefault(a => a != null); - - return c ?? - (world.SelectActorsInBox(Game.CellSize * p, - Game.CellSize * p).Any() - ? "select" : "default"); - } + return c ?? + (world.SelectActorsInBox(Game.CellSize * xy, + Game.CellSize * xy).Any() + ? "select" : "default"); } } } diff --git a/OpenRA.Game/Widgets/RadarBinWidget.cs b/OpenRA.Game/Widgets/RadarBinWidget.cs index bc84644cfe..385aa05f7f 100644 --- a/OpenRA.Game/Widgets/RadarBinWidget.cs +++ b/OpenRA.Game/Widgets/RadarBinWidget.cs @@ -29,6 +29,27 @@ namespace OpenRA.Widgets string radarCollection; + public override string GetCursor(int2 pos) + { + var mapRect = new RectangleF(radarOrigin.X + 9, radarOrigin.Y + (192 - radarMinimapHeight) / 2, + 192, radarMinimapHeight); + + var loc = Game.world.Minimap.MinimapPixelToCell(mapRect, pos); + + var mi = new MouseInput + { + Location = loc, + Button = MouseButton.Right, + Modifiers = Game.controller.GetModifiers() + }; + + var cursor = Game.controller.orderGenerator.GetCursor( Game.world, loc, mi ); + if (cursor == null) + return "default"; + + return SequenceProvider.HasCursorSequence(cursor+"-minimap") ? cursor+"-minimap" : cursor; + } + public override bool HandleInput(MouseInput mi) { if (!hasRadar || radarAnimating) return false; // we're not set up for this. diff --git a/mods/cnc/sequences.xml b/mods/cnc/sequences.xml index 47246851af..5fbe0eb1da 100644 --- a/mods/cnc/sequences.xml +++ b/mods/cnc/sequences.xml @@ -13,7 +13,7 @@ - +