diff --git a/OpenRA.Game/Widgets/Widget.cs b/OpenRA.Game/Widgets/Widget.cs index 1802ad2dd5..936173b6e3 100644 --- a/OpenRA.Game/Widgets/Widget.cs +++ b/OpenRA.Game/Widgets/Widget.cs @@ -46,7 +46,7 @@ namespace OpenRA.Widgets { var window = Game.ModData.WidgetLoader.LoadWidget(args, Root, id); if (WindowList.Count > 0) - Root.RemoveChild(WindowList.Peek()); + Root.HideChild(WindowList.Peek()); WindowList.Push(window); return window; } @@ -448,12 +448,32 @@ namespace OpenRA.Widgets } } + public virtual void HideChild(Widget child) + { + if (child != null) + { + Children.Remove(child); + child.Hidden(); + } + } + public virtual void RemoveChildren() { while (Children.Count > 0) RemoveChild(Children[Children.Count - 1]); } + public virtual void Hidden() + { + // Using the forced versions because the widgets + // have been removed + ForceYieldKeyboardFocus(); + ForceYieldMouseFocus(); + + foreach (var c in Children.OfType().Reverse()) + c.Hidden(); + } + public virtual void Removed() { // Using the forced versions because the widgets @@ -463,6 +483,11 @@ namespace OpenRA.Widgets foreach (var c in Children.OfType().Reverse()) c.Removed(); + + if (LogicObjects != null) + foreach (var l in LogicObjects) + if (l is IDisposable) + ((IDisposable)l).Dispose(); } public Widget GetOrNull(string id) diff --git a/OpenRA.Mods.Common/Widgets/DropDownButtonWidget.cs b/OpenRA.Mods.Common/Widgets/DropDownButtonWidget.cs index 135c890522..863572dd8c 100644 --- a/OpenRA.Mods.Common/Widgets/DropDownButtonWidget.cs +++ b/OpenRA.Mods.Common/Widgets/DropDownButtonWidget.cs @@ -56,6 +56,12 @@ namespace OpenRA.Mods.Common.Widgets // This is crap public override int UsableWidth { get { return Bounds.Width - Bounds.Height; } } /* space for button */ + public override void Hidden() + { + base.Hidden(); + RemovePanel(); + } + public override void Removed() { base.Removed();