Add Dispose support to widget logic objects.

This commit is contained in:
Paul Chote
2015-10-10 14:18:25 +01:00
parent 426e187a4c
commit 4ba78f65b9
2 changed files with 32 additions and 1 deletions

View File

@@ -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<Widget>().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<Widget>().Reverse())
c.Removed();
if (LogicObjects != null)
foreach (var l in LogicObjects)
if (l is IDisposable)
((IDisposable)l).Dispose();
}
public Widget GetOrNull(string id)

View File

@@ -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();