Add Dispose support to widget logic objects.
This commit is contained in:
@@ -46,7 +46,7 @@ namespace OpenRA.Widgets
|
|||||||
{
|
{
|
||||||
var window = Game.ModData.WidgetLoader.LoadWidget(args, Root, id);
|
var window = Game.ModData.WidgetLoader.LoadWidget(args, Root, id);
|
||||||
if (WindowList.Count > 0)
|
if (WindowList.Count > 0)
|
||||||
Root.RemoveChild(WindowList.Peek());
|
Root.HideChild(WindowList.Peek());
|
||||||
WindowList.Push(window);
|
WindowList.Push(window);
|
||||||
return 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()
|
public virtual void RemoveChildren()
|
||||||
{
|
{
|
||||||
while (Children.Count > 0)
|
while (Children.Count > 0)
|
||||||
RemoveChild(Children[Children.Count - 1]);
|
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()
|
public virtual void Removed()
|
||||||
{
|
{
|
||||||
// Using the forced versions because the widgets
|
// Using the forced versions because the widgets
|
||||||
@@ -463,6 +483,11 @@ namespace OpenRA.Widgets
|
|||||||
|
|
||||||
foreach (var c in Children.OfType<Widget>().Reverse())
|
foreach (var c in Children.OfType<Widget>().Reverse())
|
||||||
c.Removed();
|
c.Removed();
|
||||||
|
|
||||||
|
if (LogicObjects != null)
|
||||||
|
foreach (var l in LogicObjects)
|
||||||
|
if (l is IDisposable)
|
||||||
|
((IDisposable)l).Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Widget GetOrNull(string id)
|
public Widget GetOrNull(string id)
|
||||||
|
|||||||
@@ -56,6 +56,12 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
// This is crap
|
// This is crap
|
||||||
public override int UsableWidth { get { return Bounds.Width - Bounds.Height; } } /* space for button */
|
public override int UsableWidth { get { return Bounds.Width - Bounds.Height; } } /* space for button */
|
||||||
|
|
||||||
|
public override void Hidden()
|
||||||
|
{
|
||||||
|
base.Hidden();
|
||||||
|
RemovePanel();
|
||||||
|
}
|
||||||
|
|
||||||
public override void Removed()
|
public override void Removed()
|
||||||
{
|
{
|
||||||
base.Removed();
|
base.Removed();
|
||||||
|
|||||||
Reference in New Issue
Block a user