diff --git a/OpenRA.Game/Chrome.cs b/OpenRA.Game/Chrome.cs index cd39f04638..1f8003e916 100644 --- a/OpenRA.Game/Chrome.cs +++ b/OpenRA.Game/Chrome.cs @@ -1066,11 +1066,8 @@ namespace OpenRA public bool HitTest(int2 mousePos) { - if (Game.orderManager.Connection.ConnectionState == ConnectionState.PreConnecting) - if (rootWidget.EventBounds.Contains(mousePos.X, mousePos.Y)) - return true; - - return buttons.Any(a => a.First.Contains(mousePos.ToPoint())); + return rootWidget.GetEventBounds().Contains(mousePos.X, mousePos.Y) + || buttons.Any(a => a.First.Contains(mousePos.ToPoint())); } void DrawRightAligned(string text, int2 pos, Color c) diff --git a/OpenRA.Game/Chrome/DefaultWidgetDelegates.cs b/OpenRA.Game/Chrome/DefaultWidgetDelegates.cs index b00fddc1fb..5108f7c105 100644 --- a/OpenRA.Game/Chrome/DefaultWidgetDelegates.cs +++ b/OpenRA.Game/Chrome/DefaultWidgetDelegates.cs @@ -36,7 +36,8 @@ namespace OpenRA.Widgets.Delegates } if (w.Id == "CREATESERVER_BUTTON_START") - { + { + Game.chrome.rootWidget.GetWidget("CREATESERVER_BG").Visible = false; Game.CreateServer(); return true; } @@ -75,7 +76,6 @@ namespace OpenRA.Widgets.Delegates b.GetType().GetField("Text").SetValue( b, "{0} ({1})".F(game.Name, game.Address)); b.GetType().GetField("Delegate").SetValue( b, "ServerBrowserDelegate"); - b.EventBounds = b.Bounds; bg.AddChild(b); GameButtons.Add(b); diff --git a/OpenRA.Game/Chrome/Widget.cs b/OpenRA.Game/Chrome/Widget.cs index 7448615503..d77c56d8c6 100644 --- a/OpenRA.Game/Chrome/Widget.cs +++ b/OpenRA.Game/Chrome/Widget.cs @@ -2,7 +2,8 @@ using System; using System.Collections.Generic; using System.Drawing; using OpenRA.FileFormats; -using OpenRA.Widgets.Delegates; +using OpenRA.Widgets.Delegates; +using System.Linq; namespace OpenRA.Widgets { @@ -23,7 +24,6 @@ namespace OpenRA.Widgets // Calculated internally public Rectangle Bounds; - public Rectangle EventBounds; public Widget Parent = null; public Widget() { InputHandler = Lazy.New(() => BindHandler(Delegate)); } @@ -49,13 +49,16 @@ namespace OpenRA.Widgets width, height); - // Calculate the region that we accept mouse events in - EventBounds = Bounds; foreach (var child in Children) - { child.Initialize(); - EventBounds = Rectangle.Union(EventBounds, child.EventBounds); - } + } + + public Rectangle GetEventBounds() + { + return Children + .Where(c => c.Visible) + .Select(c => c.GetEventBounds()) + .Aggregate(Bounds, Rectangle.Union); } static IWidgetDelegate BindHandler(string name) @@ -69,21 +72,12 @@ namespace OpenRA.Widgets } throw new InvalidOperationException("Cannot locate widget delegate: {0}".F(name)); - } - - public virtual void UpdateEventBounds() - { - EventBounds = Bounds; - foreach (var child in Children) - EventBounds = Rectangle.Union(EventBounds, child.EventBounds); - - Parent.UpdateEventBounds(); } public virtual bool HandleInput(MouseInput mi) { // Are we able to handle this event? - if (!Visible || !EventBounds.Contains(mi.Location.X,mi.Location.Y)) + if (!Visible || !GetEventBounds().Contains(mi.Location.X,mi.Location.Y)) return false; // Can any of our children handle this?