From 3e1db3e8ae73790fcca905fe4ca793cafdf2b723 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Wed, 5 Jan 2011 22:16:01 +1300 Subject: [PATCH] Move MapPreviewWidget.HandleInputInner to the lobby delegate. --- OpenRA.Game/Widgets/MapPreviewWidget.cs | 27 ++----------------- OpenRA.Game/Widgets/Widget.cs | 9 +++---- .../Widgets/Delegates/LobbyDelegate.cs | 22 +++++++++++---- 3 files changed, 23 insertions(+), 35 deletions(-) diff --git a/OpenRA.Game/Widgets/MapPreviewWidget.cs b/OpenRA.Game/Widgets/MapPreviewWidget.cs index b80fd6ff84..ab60f3ee77 100644 --- a/OpenRA.Game/Widgets/MapPreviewWidget.cs +++ b/OpenRA.Game/Widgets/MapPreviewWidget.cs @@ -19,10 +19,7 @@ namespace OpenRA.Widgets { public class MapPreviewWidget : Widget { - public int SpawnClickRadius = 50; - public Func Map = () => null; - public Action OnSpawnClick = spawn => {}; public Func> SpawnColors = () => new Dictionary(); static Cache PreviewCache = new Cache(stub => Minimap.RenderMapPreview( new Map( stub.Path ))); @@ -32,37 +29,17 @@ namespace OpenRA.Widgets { lastMap = other.lastMap; Map = other.Map; - OnSpawnClick = other.OnSpawnClick; SpawnColors = other.SpawnColors; } public override Widget Clone() { return new MapPreviewWidget(this); } - + public override bool HandleInputInner(MouseInput mi) { return true; } + public int2 ConvertToPreview(MapStub map, int2 point) { return new int2(MapRect.X + (int)(PreviewScale*(point.X - map.Bounds.Left)) , MapRect.Y + (int)(PreviewScale*(point.Y - map.Bounds.Top))); } - public override bool HandleInputInner(MouseInput mi) - { - var map = Map(); - if (map == null) - return false; - - if (mi.Event == MouseInputEvent.Down && mi.Button == MouseButton.Left) - { - var p = map.Waypoints - .Select((sp, i) => Pair.New(ConvertToPreview(map, sp.Value), i)) - .Where(a => (a.First - mi.Location).LengthSquared < SpawnClickRadius) - .Select(a => a.Second + 1) - .FirstOrDefault(); - OnSpawnClick(p); - return true; - } - - return false; - } - Sheet mapChooserSheet; Sprite mapChooserSprite; MapStub lastMap; diff --git a/OpenRA.Game/Widgets/Widget.cs b/OpenRA.Game/Widgets/Widget.cs index 91ad7f22aa..5ebbb27eba 100644 --- a/OpenRA.Game/Widgets/Widget.cs +++ b/OpenRA.Game/Widgets/Widget.cs @@ -194,10 +194,6 @@ namespace OpenRA.Widgets return EventBounds.Contains(pos.ToPoint()) ? GetCursor(pos) : null; } - // Hack: Don't eat mouse input that others want - // TODO: Solve this properly - public virtual bool HandleInputInner(MouseInput mi) { return !ClickThrough && mi.Button == MouseButton.Left && mi.Event != MouseInputEvent.Move; } - public static bool HandleInput(MouseInput mi) { bool handled = false; @@ -238,7 +234,10 @@ namespace OpenRA.Widgets return true; } - + + // Hack: Don't eat mouse input that others want + // TODO: Solve this properly + public virtual bool HandleInputInner(MouseInput mi) { return !ClickThrough && mi.Button == MouseButton.Left && mi.Event != MouseInputEvent.Move; } public virtual bool HandleKeyPressInner(KeyInput e) { return false; } public virtual bool HandleKeyPressOuter(KeyInput e) diff --git a/OpenRA.Mods.RA/Widgets/Delegates/LobbyDelegate.cs b/OpenRA.Mods.RA/Widgets/Delegates/LobbyDelegate.cs index 631c41d4f9..714a3cfb13 100755 --- a/OpenRA.Mods.RA/Widgets/Delegates/LobbyDelegate.cs +++ b/OpenRA.Mods.RA/Widgets/Delegates/LobbyDelegate.cs @@ -49,12 +49,24 @@ namespace OpenRA.Mods.RA.Widgets.Delegates var mapPreview = lobby.GetWidget("LOBBY_MAP_PREVIEW"); mapPreview.Map = () => Map; - mapPreview.OnSpawnClick = sp => + mapPreview.OnMouseDown = mi => { - if (orderManager.LocalClient.State == Session.ClientState.Ready) return; - var owned = orderManager.LobbyInfo.Clients.Any(c => c.SpawnPoint == sp); - if (sp == 0 || !owned) - orderManager.IssueOrder(Order.Command("spawn {0}".F(sp))); + var map = mapPreview.Map(); + if (map == null || mi.Button != MouseButton.Left + || orderManager.LocalClient.State == Session.ClientState.Ready) + return false; + + var p = map.Waypoints + .Select((sp, i) => Pair.New(mapPreview.ConvertToPreview(map, sp.Value), i)) + .Where(a => (a.First - mi.Location).LengthSquared < 64) + .Select(a => a.Second + 1) + .FirstOrDefault(); + + var owned = orderManager.LobbyInfo.Clients.Any(c => c.SpawnPoint == p); + if (p == 0 || !owned) + orderManager.IssueOrder(Order.Command("spawn {0}".F(p))); + + return true; }; mapPreview.SpawnColors = () =>