From 98fce2310059bfc0cfc7cde262c10ffabdbfa18e Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 11 Apr 2010 18:01:20 +1200 Subject: [PATCH] Ingame settings menu --- OpenRA.Game/Chrome.cs | 1 + OpenRA.Game/Graphics/Viewport.cs | 2 +- .../Delegates/ConnectionDialogsDelegate.cs | 4 +-- .../Delegates/CreateServerMenuDelegate.cs | 6 ++--- .../Widgets/Delegates/IngameChromeDelegate.cs | 2 +- .../Delegates/ServerBrowserDelegate.cs | 6 ++--- .../Widgets/Delegates/SettingsMenuDelegate.cs | 4 +-- OpenRA.Game/Widgets/Widget.cs | 26 +++++++++++-------- mods/cnc/menus.yaml | 2 ++ mods/ra/menus.yaml | 2 ++ 10 files changed, 32 insertions(+), 23 deletions(-) diff --git a/OpenRA.Game/Chrome.cs b/OpenRA.Game/Chrome.cs index b698f3a3e4..7edcb8d811 100644 --- a/OpenRA.Game/Chrome.cs +++ b/OpenRA.Game/Chrome.cs @@ -119,6 +119,7 @@ namespace OpenRA rootWidget = WidgetLoader.LoadWidget( widgetYaml.FirstOrDefault() ); rootWidget.Initialize(); rootWidget.InitDelegates(); + Widget.WindowList.Push("MAINMENU_BG"); } } diff --git a/OpenRA.Game/Graphics/Viewport.cs b/OpenRA.Game/Graphics/Viewport.cs index cce13b8f02..e3e69de589 100644 --- a/OpenRA.Game/Graphics/Viewport.cs +++ b/OpenRA.Game/Graphics/Viewport.cs @@ -78,7 +78,7 @@ namespace OpenRA.Graphics { if (!gameWasStarted) { - Chrome.rootWidget.ShowMenu("INGAME_ROOT"); + Chrome.rootWidget.OpenWindow("INGAME_ROOT"); gameWasStarted = true; } diff --git a/OpenRA.Game/Widgets/Delegates/ConnectionDialogsDelegate.cs b/OpenRA.Game/Widgets/Delegates/ConnectionDialogsDelegate.cs index 7d376e7973..c505a637df 100644 --- a/OpenRA.Game/Widgets/Delegates/ConnectionDialogsDelegate.cs +++ b/OpenRA.Game/Widgets/Delegates/ConnectionDialogsDelegate.cs @@ -26,11 +26,11 @@ namespace OpenRA.Widgets.Delegates { var r = Chrome.rootWidget; r.GetWidget("CONNECTION_BUTTON_ABORT").OnMouseUp = mi => { - r.ShowMenu("MAINMENU_BG"); + r.CloseWindow(); return true; }; r.GetWidget("CONNECTION_BUTTON_CANCEL").OnMouseUp = mi => { - r.ShowMenu("MAINMENU_BG"); + r.CloseWindow(); return true; }; r.GetWidget("CONNECTION_BUTTON_RETRY").OnMouseUp = mi => { diff --git a/OpenRA.Game/Widgets/Delegates/CreateServerMenuDelegate.cs b/OpenRA.Game/Widgets/Delegates/CreateServerMenuDelegate.cs index 68fb75ebd4..2e8dad4391 100644 --- a/OpenRA.Game/Widgets/Delegates/CreateServerMenuDelegate.cs +++ b/OpenRA.Game/Widgets/Delegates/CreateServerMenuDelegate.cs @@ -31,17 +31,17 @@ namespace OpenRA.Widgets.Delegates { var r = Chrome.rootWidget; r.GetWidget("MAINMENU_BUTTON_CREATE").OnMouseUp = mi => { - r.ShowMenu("CREATESERVER_BG"); + r.OpenWindow("CREATESERVER_BG"); return true; }; r.GetWidget("CREATESERVER_BUTTON_CANCEL").OnMouseUp = mi => { - r.ShowMenu("MAINMENU_BG"); + r.CloseWindow(); return true; }; r.GetWidget("CREATESERVER_BUTTON_START").OnMouseUp = mi => { - r.ShowMenu(null); + r.OpenWindow("SERVER_LOBBY"); Log.Write("Creating server"); // TODO: Get this from a map chooser diff --git a/OpenRA.Game/Widgets/Delegates/IngameChromeDelegate.cs b/OpenRA.Game/Widgets/Delegates/IngameChromeDelegate.cs index 998e724319..5cdcfebdea 100644 --- a/OpenRA.Game/Widgets/Delegates/IngameChromeDelegate.cs +++ b/OpenRA.Game/Widgets/Delegates/IngameChromeDelegate.cs @@ -43,7 +43,7 @@ namespace OpenRA.Widgets.Delegates }; optionsBG.GetWidget("BUTTON_SETTINGS").OnMouseUp = mi => { - // Todo: Unfail ShowMenu to work with multiple root menus + r.OpenWindow("SETTINGS_BG"); return true; }; diff --git a/OpenRA.Game/Widgets/Delegates/ServerBrowserDelegate.cs b/OpenRA.Game/Widgets/Delegates/ServerBrowserDelegate.cs index 9ac28881f6..9efd8f8530 100644 --- a/OpenRA.Game/Widgets/Delegates/ServerBrowserDelegate.cs +++ b/OpenRA.Game/Widgets/Delegates/ServerBrowserDelegate.cs @@ -35,7 +35,7 @@ namespace OpenRA.Widgets.Delegates var r = Chrome.rootWidget; r.GetWidget("MAINMENU_BUTTON_JOIN").OnMouseUp = mi => { - var bg = r.ShowMenu("JOINSERVER_BG"); + var bg = r.OpenWindow("JOINSERVER_BG"); int height = 50; int width = 300; int i = 0; @@ -68,13 +68,13 @@ namespace OpenRA.Widgets.Delegates }; r.GetWidget("JOINSERVER_BUTTON_DIRECTCONNECT").OnMouseUp = mi => { - r.GetWidget("JOINSERVER_BG").Visible = false; + r.CloseWindow(); Game.JoinServer(Game.Settings.NetworkHost, Game.Settings.NetworkPort); return true; }; r.GetWidget("JOINSERVER_BUTTON_CANCEL").OnMouseUp = mi => { - r.ShowMenu("MAINMENU_BG"); + r.CloseWindow(); return true; }; } diff --git a/OpenRA.Game/Widgets/Delegates/SettingsMenuDelegate.cs b/OpenRA.Game/Widgets/Delegates/SettingsMenuDelegate.cs index 6796e8a971..45e46c8df0 100644 --- a/OpenRA.Game/Widgets/Delegates/SettingsMenuDelegate.cs +++ b/OpenRA.Game/Widgets/Delegates/SettingsMenuDelegate.cs @@ -38,12 +38,12 @@ namespace OpenRA.Widgets.Delegates // Menu Buttons r.GetWidget("MAINMENU_BUTTON_SETTINGS").OnMouseUp = mi => { - r.ShowMenu("SETTINGS_BG"); + r.OpenWindow("SETTINGS_BG"); return true; }; r.GetWidget("SETTINGS_BUTTON_OK").OnMouseUp = mi => { - r.ShowMenu("MAINMENU_BG"); + r.CloseWindow(); return true; }; } diff --git a/OpenRA.Game/Widgets/Widget.cs b/OpenRA.Game/Widgets/Widget.cs index 11b0ff7d67..8cfc2810a6 100644 --- a/OpenRA.Game/Widgets/Widget.cs +++ b/OpenRA.Game/Widgets/Widget.cs @@ -44,6 +44,7 @@ namespace OpenRA.Widgets public Rectangle Bounds; public Widget Parent = null; static List Delegates = new List(); + public static Stack WindowList = new Stack(); // Common Funcs that most widgets will want public Func OnMouseDown = mi => {return false;}; @@ -160,23 +161,26 @@ namespace OpenRA.Widgets return (T)GetWidget(id); } - public Widget GetCurrentMenu() + public Widget GetWindow() { + return Chrome.rootWidget.GetWidget(WindowList.Peek()); // HACK HACK HACK (this method will vanish soon, so not going to hack the widget yaml itself) - return Children.FirstOrDefault(c => c.Visible && c.Id != "MUSIC_BG" && c.Id != "PERF_BG"); + //return Children.FirstOrDefault(c => c.Visible && c.Id != "MUSIC_BG" && c.Id != "PERF_BG"); } - public Widget ShowMenu(string menu) + public void CloseWindow() { - var m = GetCurrentMenu(); - if (m != null) - m.Visible = false; + Chrome.rootWidget.GetWidget(WindowList.Pop()).Visible = false; + Chrome.rootWidget.GetWidget(WindowList.Peek()).Visible = true; + } - var widget = GetWidget(menu); - if (widget != null) - widget.Visible = true; - - return widget; + public Widget OpenWindow(string id) + { + Chrome.rootWidget.GetWidget(WindowList.Peek()).Visible = false; + WindowList.Push(id); + var window = Chrome.rootWidget.GetWidget(id); + window.Visible = true; + return window; } } diff --git a/mods/cnc/menus.yaml b/mods/cnc/menus.yaml index 45b080cc28..1dc039de55 100644 --- a/mods/cnc/menus.yaml +++ b/mods/cnc/menus.yaml @@ -237,6 +237,8 @@ Container: Width:160 Height:25 Text:Abort + Container@SERVER_LOBBY: + Id:SERVER_LOBBY Container@INGAME_ROOT: Id:INGAME_ROOT Delegate:IngameChromeDelegate diff --git a/mods/ra/menus.yaml b/mods/ra/menus.yaml index 45b080cc28..1dc039de55 100644 --- a/mods/ra/menus.yaml +++ b/mods/ra/menus.yaml @@ -237,6 +237,8 @@ Container: Width:160 Height:25 Text:Abort + Container@SERVER_LOBBY: + Id:SERVER_LOBBY Container@INGAME_ROOT: Id:INGAME_ROOT Delegate:IngameChromeDelegate