diff --git a/OpenRA.Game/Widgets/ButtonWidget.cs b/OpenRA.Game/Widgets/ButtonWidget.cs index ac40e7d138..53157dcae7 100644 --- a/OpenRA.Game/Widgets/ButtonWidget.cs +++ b/OpenRA.Game/Widgets/ButtonWidget.cs @@ -24,6 +24,8 @@ namespace OpenRA.Widgets public string Font = ChromeMetrics.Get("ButtonFont"); public Func GetText; public Func IsDisabled = () => false; + public Func OnMouseDown = mi => false; + public Action OnClick = () => {}; public Action OnKeyPress = _ => {}; @@ -43,6 +45,8 @@ namespace OpenRA.Widgets Depressed = widget.Depressed; VisualHeight = widget.VisualHeight; GetText = widget.GetText; + OnMouseDown = widget.OnMouseDown; + OnMouseUp = mi => { if (!IsDisabled()) OnClick(); return true; }; OnKeyPress = _ => OnClick(); } diff --git a/OpenRA.Game/Widgets/DropDownButtonWidget.cs b/OpenRA.Game/Widgets/DropDownButtonWidget.cs index 0e05f326a4..681ae0eea6 100644 --- a/OpenRA.Game/Widgets/DropDownButtonWidget.cs +++ b/OpenRA.Game/Widgets/DropDownButtonWidget.cs @@ -18,7 +18,7 @@ namespace OpenRA.Widgets public class DropDownButtonWidget : ButtonWidget { Widget panel; - Widget fullscreenMask; + MaskWidget fullscreenMask; public DropDownButtonWidget() : base() @@ -75,17 +75,11 @@ namespace OpenRA.Widgets panel = p; // Mask to prevent any clicks from being sent to other widgets - fullscreenMask = new ContainerWidget(); + fullscreenMask = new MaskWidget(); fullscreenMask.Bounds = new Rectangle(0, 0, Game.viewport.Width, Game.viewport.Height); + fullscreenMask.OnMouseDown = mi => RemovePanel(); Widget.RootWidget.AddChild(fullscreenMask); - fullscreenMask.OnMouseDown = mi => - { - RemovePanel(); - return true; - }; - fullscreenMask.OnMouseUp = mi => true; - var oldBounds = panel.Bounds; panel.Bounds = new Rectangle(RenderOrigin.X, RenderOrigin.Y + Bounds.Height, oldBounds.Width, oldBounds.Height); Widget.RootWidget.AddChild(panel); @@ -114,4 +108,30 @@ namespace OpenRA.Widgets AttachPanel(panel); } } + + public class MaskWidget : Widget + { + public Action OnMouseDown = _ => {}; + public MaskWidget() : base() { } + public MaskWidget(MaskWidget other) + : base(other) + { + OnMouseDown = other.OnMouseDown; + } + + public override bool HandleMouseInput(MouseInput mi) + { + if (mi.Event != MouseInputEvent.Down && mi.Event != MouseInputEvent.Up) + return false; + + if (mi.Event == MouseInputEvent.Down) + OnMouseDown(mi); + + return true; + } + + public override void DrawInner() { } + public override string GetCursor(int2 pos) { return null; } + public override Widget Clone() { return new MaskWidget(this); } + } } \ No newline at end of file diff --git a/OpenRA.Game/Widgets/MapPreviewWidget.cs b/OpenRA.Game/Widgets/MapPreviewWidget.cs index 6800059485..9526d76844 100644 --- a/OpenRA.Game/Widgets/MapPreviewWidget.cs +++ b/OpenRA.Game/Widgets/MapPreviewWidget.cs @@ -20,6 +20,8 @@ namespace OpenRA.Widgets { public Func Map = () => null; public Func> SpawnColors = () => new Dictionary(); + public Action OnMouseDown = _ => {}; + Cache PreviewCache = new Cache(stub => Minimap.RenderMapPreview( new Map( stub.Path ))); public MapPreviewWidget() : base() { } @@ -32,6 +34,15 @@ namespace OpenRA.Widgets } public override Widget Clone() { return new MapPreviewWidget(this); } + public override bool HandleMouseInput(MouseInput mi) + { + if (mi.Event != MouseInputEvent.Down) + return false; + + OnMouseDown(mi); + return true; + } + public int2 ConvertToPreview(Map map, int2 point) { return new int2(MapRect.X + (int)(PreviewScale*(point.X - map.Bounds.Left)) , MapRect.Y + (int)(PreviewScale*(point.Y - map.Bounds.Top))); diff --git a/OpenRA.Game/Widgets/Widget.cs b/OpenRA.Game/Widgets/Widget.cs index 39c8957bcc..ade8fb12ce 100644 --- a/OpenRA.Game/Widgets/Widget.cs +++ b/OpenRA.Game/Widgets/Widget.cs @@ -38,7 +38,6 @@ namespace OpenRA.Widgets static Stack WindowList = new Stack(); // Common Funcs that most widgets will want - public Func OnMouseDown = mi => false; public Func OnMouseUp = mi => false; public Func IsVisible; @@ -65,7 +64,6 @@ namespace OpenRA.Widgets Bounds = widget.Bounds; Parent = widget.Parent; - OnMouseDown = widget.OnMouseDown; OnMouseUp = widget.OnMouseUp; IsVisible = widget.IsVisible; @@ -226,7 +224,6 @@ namespace OpenRA.Widgets public virtual bool HandleMouseInput(MouseInput mi) { // Apply any special logic added by event handlers; they return true if they caught the input - if (mi.Event == MouseInputEvent.Down && OnMouseDown(mi)) return true; if (mi.Event == MouseInputEvent.Up && OnMouseUp(mi)) return true; return false; diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/CncLobbyLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/CncLobbyLogic.cs index 745a51a110..edddac3f9e 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/CncLobbyLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/CncLobbyLogic.cs @@ -120,7 +120,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic var map = mapPreview.Map(); if (map == null || mi.Button != MouseButton.Left || orderManager.LocalClient.State == Session.ClientState.Ready) - return false; + return; var p = map.SpawnPoints .Select((sp, i) => Pair.New(mapPreview.ConvertToPreview(map, sp), i)) @@ -131,8 +131,6 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic var owned = orderManager.LobbyInfo.Clients.Any(c => c.SpawnPoint == p); if (p == 0 || !owned) orderManager.IssueOrder(Order.Command("spawn {0} {1}".F(orderManager.LocalClient.Index, p))); - - return true; }; var mapTitle = lobby.GetWidget("MAP_TITLE"); diff --git a/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs index e58a85a76f..3141b72b77 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs @@ -65,7 +65,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic var map = mapPreview.Map(); if (map == null || mi.Button != MouseButton.Left || orderManager.LocalClient.State == Session.ClientState.Ready) - return false; + return; var p = map.SpawnPoints .Select((sp, i) => Pair.New(mapPreview.ConvertToPreview(map, sp), i)) @@ -76,8 +76,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic var owned = orderManager.LobbyInfo.Clients.Any(c => c.SpawnPoint == p); if (p == 0 || !owned) orderManager.IssueOrder(Order.Command("spawn {0} {1}".F(orderManager.LocalClient.Index, p))); - - return true; }; mapPreview.SpawnColors = () =>