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