Add a hook for widgets being removed, and ensure widgets are removed consistently.
This commit is contained in:
@@ -276,8 +276,7 @@ namespace OpenRA
|
|||||||
ConnectionStateChanged = om => {};
|
ConnectionStateChanged = om => {};
|
||||||
BeforeGameStart = () => {};
|
BeforeGameStart = () => {};
|
||||||
AfterGameStart = w => {};
|
AfterGameStart = w => {};
|
||||||
while (Widget.WindowList.Count > 0)
|
Widget.ResetAll();
|
||||||
Widget.CloseWindow();
|
|
||||||
|
|
||||||
worldRenderer = null;
|
worldRenderer = null;
|
||||||
if (server != null)
|
if (server != null)
|
||||||
|
|||||||
@@ -29,13 +29,13 @@ namespace OpenRA.Widgets
|
|||||||
public object LogicObject { get; private set; }
|
public object LogicObject { get; private set; }
|
||||||
public bool Visible = true;
|
public bool Visible = true;
|
||||||
|
|
||||||
public readonly List<Widget> Children = new List<Widget>();
|
protected readonly List<Widget> Children = new List<Widget>();
|
||||||
|
|
||||||
// Calculated internally
|
// Calculated internally
|
||||||
public Rectangle Bounds;
|
public Rectangle Bounds;
|
||||||
public Widget Parent = null;
|
public Widget Parent = null;
|
||||||
|
|
||||||
public static Stack<Widget> WindowList = new Stack<Widget>();
|
static Stack<Widget> WindowList = new Stack<Widget>();
|
||||||
|
|
||||||
// Common Funcs that most widgets will want
|
// Common Funcs that most widgets will want
|
||||||
public Func<MouseInput, bool> OnMouseDown = mi => false;
|
public Func<MouseInput, bool> OnMouseDown = mi => false;
|
||||||
@@ -293,9 +293,24 @@ namespace OpenRA.Widgets
|
|||||||
Children.Add(child);
|
Children.Add(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void RemoveChild(Widget child) { Children.Remove(child); }
|
public virtual void RemoveChild(Widget child)
|
||||||
public virtual void RemoveChildren() { Children.Clear(); }
|
{
|
||||||
|
Children.Remove(child);
|
||||||
|
child.Removed();
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void RemoveChildren()
|
||||||
|
{
|
||||||
|
while (Children.Count > 0)
|
||||||
|
RemoveChild(Children[Children.Count-1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void Removed()
|
||||||
|
{
|
||||||
|
foreach (var c in Children.OfType<Widget>().Reverse())
|
||||||
|
c.Removed();
|
||||||
|
}
|
||||||
|
|
||||||
public Widget GetWidget(string id)
|
public Widget GetWidget(string id)
|
||||||
{
|
{
|
||||||
if (this.Id == id)
|
if (this.Id == id)
|
||||||
@@ -319,9 +334,9 @@ namespace OpenRA.Widgets
|
|||||||
public static void CloseWindow()
|
public static void CloseWindow()
|
||||||
{
|
{
|
||||||
if (WindowList.Count > 0)
|
if (WindowList.Count > 0)
|
||||||
RootWidget.Children.Remove(WindowList.Pop());
|
RootWidget.RemoveChild(WindowList.Pop());
|
||||||
if (WindowList.Count > 0)
|
if (WindowList.Count > 0)
|
||||||
rootWidget.Children.Add(WindowList.Peek());
|
rootWidget.AddChild(WindowList.Peek());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Widget OpenWindow(string id)
|
public static Widget OpenWindow(string id)
|
||||||
@@ -333,7 +348,7 @@ namespace OpenRA.Widgets
|
|||||||
{
|
{
|
||||||
var window = Game.modData.WidgetLoader.LoadWidget(args, rootWidget, id);
|
var window = Game.modData.WidgetLoader.LoadWidget(args, rootWidget, id);
|
||||||
if (WindowList.Count > 0)
|
if (WindowList.Count > 0)
|
||||||
rootWidget.Children.Remove(WindowList.Peek());
|
rootWidget.RemoveChild(WindowList.Peek());
|
||||||
WindowList.Push(window);
|
WindowList.Push(window);
|
||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
@@ -352,6 +367,14 @@ namespace OpenRA.Widgets
|
|||||||
{
|
{
|
||||||
RootWidget.Draw();
|
RootWidget.Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void ResetAll()
|
||||||
|
{
|
||||||
|
RootWidget.RemoveChildren();
|
||||||
|
|
||||||
|
while (Widget.WindowList.Count > 0)
|
||||||
|
Widget.CloseWindow();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ContainerWidget : Widget
|
public class ContainerWidget : Widget
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ namespace OpenRA.Mods.Cnc
|
|||||||
|
|
||||||
void TestAndContinue()
|
void TestAndContinue()
|
||||||
{
|
{
|
||||||
Widget.RootWidget.RemoveChildren();
|
Widget.ResetAll();
|
||||||
if (!FileSystem.Exists(Info["TestFile"]))
|
if (!FileSystem.Exists(Info["TestFile"]))
|
||||||
{
|
{
|
||||||
var args = new WidgetArgs()
|
var args = new WidgetArgs()
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
|||||||
world.WorldActor.QueueActivity(new CallFunc(() =>
|
world.WorldActor.QueueActivity(new CallFunc(() =>
|
||||||
{
|
{
|
||||||
Game.Disconnect();
|
Game.Disconnect();
|
||||||
Widget.RootWidget.RemoveChildren();
|
Widget.ResetAll();
|
||||||
Game.LoadShellMap();
|
Game.LoadShellMap();
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace OpenRA.Mods.RA
|
|||||||
|
|
||||||
public void StartGame()
|
public void StartGame()
|
||||||
{
|
{
|
||||||
Widget.RootWidget.RemoveChildren();
|
Widget.ResetAll();
|
||||||
Game.modData.WidgetLoader.LoadWidget( new WidgetArgs(), Widget.RootWidget, "INIT_SETUP" );
|
Game.modData.WidgetLoader.LoadWidget( new WidgetArgs(), Widget.RootWidget, "INIT_SETUP" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA
|
|||||||
public void WorldLoaded(World world)
|
public void WorldLoaded(World world)
|
||||||
{
|
{
|
||||||
// Remove all open widgets
|
// Remove all open widgets
|
||||||
Widget.RootWidget.Children.Clear();
|
Widget.ResetAll();
|
||||||
|
|
||||||
if (world.LocalPlayer != null)
|
if (world.LocalPlayer != null)
|
||||||
Game.OpenWindow(world, Info.Widget);
|
Game.OpenWindow(world, Info.Widget);
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ namespace OpenRA.Mods.RA
|
|||||||
|
|
||||||
public void StartGame()
|
public void StartGame()
|
||||||
{
|
{
|
||||||
Widget.RootWidget.RemoveChildren();
|
Widget.ResetAll();
|
||||||
Game.modData.WidgetLoader.LoadWidget( new WidgetArgs(), Widget.RootWidget, "INIT_SETUP" );
|
Game.modData.WidgetLoader.LoadWidget( new WidgetArgs(), Widget.RootWidget, "INIT_SETUP" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
// This is shit
|
// This is shit
|
||||||
void LayoutDialog(Widget bg)
|
void LayoutDialog(Widget bg)
|
||||||
{
|
{
|
||||||
bg.Children.RemoveAll(w => controls.Contains(w));
|
foreach (var c in controls)
|
||||||
|
bg.RemoveChild(c);
|
||||||
controls.Clear();
|
controls.Clear();
|
||||||
|
|
||||||
var y = 50;
|
var y = 50;
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
Game.LoadShellMap();
|
Game.LoadShellMap();
|
||||||
if (Info.InstallMode != "cnc")
|
if (Info.InstallMode != "cnc")
|
||||||
{
|
{
|
||||||
Widget.RootWidget.RemoveChildren();
|
Widget.ResetAll();
|
||||||
Widget.OpenWindow("MAINMENU_BG");
|
Widget.OpenWindow("MAINMENU_BG");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user