From a3b430c24a9e73854227803a3d0a86b6c8de154d Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Thu, 5 May 2011 22:44:21 +1200 Subject: [PATCH] Remove engine references to MAINMENU_BG. Don't push the menu background onto the window list. Crashes whenever a delegate tries to open MAINMENU_BG. --- OpenRA.Game/Game.cs | 3 - OpenRA.Game/Widgets/Widget.cs | 8 +- OpenRA.Mods.Cnc/Missions/Gdi01Script.cs | 4 + .../Delegates/ConnectionDialogsDelegate.cs | 4 + .../Widgets/Delegates/GameInitDelegate.cs | 90 +++++++++++++------ .../Widgets/Delegates/IngameChromeDelegate.cs | 2 + .../Delegates/IngameObserverChromeDelegate.cs | 2 + .../Widgets/Delegates/LobbyDelegate.cs | 2 + mods/cnc/chrome/mainmenu.yaml | 4 +- 9 files changed, 85 insertions(+), 34 deletions(-) diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index 977d237d8e..b8a0b1c006 100755 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -329,9 +329,6 @@ namespace OpenRA var shellmap = ChooseShellmap(); JoinLocal(); StartGame(shellmap); - - Widget.CloseWindow(); - Widget.OpenWindow("MAINMENU_BG"); } public static T CreateObject( string name ) diff --git a/OpenRA.Game/Widgets/Widget.cs b/OpenRA.Game/Widgets/Widget.cs index 440941145c..10de528997 100644 --- a/OpenRA.Game/Widgets/Widget.cs +++ b/OpenRA.Game/Widgets/Widget.cs @@ -313,7 +313,8 @@ namespace OpenRA.Widgets public static void CloseWindow() { - RootWidget.Children.Remove(WindowList.Pop()); + if (WindowList.Count > 0) + RootWidget.Children.Remove(WindowList.Pop()); if (WindowList.Count > 0) rootWidget.Children.Add(WindowList.Peek()); } @@ -331,6 +332,11 @@ namespace OpenRA.Widgets WindowList.Push(window); return window; } + + public static Widget LoadWidget(string id) + { + return Game.modData.WidgetLoader.LoadWidget(new Dictionary(), rootWidget, id); + } public static void DoTick() { diff --git a/OpenRA.Mods.Cnc/Missions/Gdi01Script.cs b/OpenRA.Mods.Cnc/Missions/Gdi01Script.cs index f6c0eef37d..89543a4446 100644 --- a/OpenRA.Mods.Cnc/Missions/Gdi01Script.cs +++ b/OpenRA.Mods.Cnc/Missions/Gdi01Script.cs @@ -59,6 +59,8 @@ namespace OpenRA.Mods.Cnc { Sound.StopMusic(); Game.Disconnect(); + Widget.CloseWindow(); + Widget.LoadWidget("MENU_BACKGROUND"); }))); } @@ -75,6 +77,8 @@ namespace OpenRA.Mods.Cnc { Sound.StopMusic(); Game.Disconnect(); + Widget.CloseWindow(); + Widget.LoadWidget("MENU_BACKGROUND"); }))); } diff --git a/OpenRA.Mods.RA/Widgets/Delegates/ConnectionDialogsDelegate.cs b/OpenRA.Mods.RA/Widgets/Delegates/ConnectionDialogsDelegate.cs index f6efcebea3..e338add139 100644 --- a/OpenRA.Mods.RA/Widgets/Delegates/ConnectionDialogsDelegate.cs +++ b/OpenRA.Mods.RA/Widgets/Delegates/ConnectionDialogsDelegate.cs @@ -24,6 +24,8 @@ namespace OpenRA.Mods.RA.Widgets.Delegates widget.GetWidget("CONNECTION_BUTTON_ABORT").OnMouseUp = mi => { widget.GetWidget("CONNECTION_BUTTON_ABORT").Parent.Visible = false; Game.Disconnect(); + Widget.CloseWindow(); + Widget.OpenWindow("MAINMENU_BG"); return true; }; @@ -42,6 +44,8 @@ namespace OpenRA.Mods.RA.Widgets.Delegates widget.GetWidget("CONNECTION_BUTTON_CANCEL").OnMouseUp = mi => { widget.GetWidget("CONNECTION_BUTTON_CANCEL").Parent.Visible = false; Game.Disconnect(); + Widget.CloseWindow(); + Widget.OpenWindow("MAINMENU_BG"); return true; }; widget.GetWidget("CONNECTION_BUTTON_RETRY").OnMouseUp = mi => { diff --git a/OpenRA.Mods.RA/Widgets/Delegates/GameInitDelegate.cs b/OpenRA.Mods.RA/Widgets/Delegates/GameInitDelegate.cs index 9f089a0ab8..57bfbf8837 100755 --- a/OpenRA.Mods.RA/Widgets/Delegates/GameInitDelegate.cs +++ b/OpenRA.Mods.RA/Widgets/Delegates/GameInitDelegate.cs @@ -34,33 +34,64 @@ namespace OpenRA.Mods.RA.Widgets.Delegates public void Init() { - Game.ConnectionStateChanged += orderManager => - { - Widget.CloseWindow(); - switch (orderManager.Connection.ConnectionState) - { - case ConnectionState.PreConnecting: - Widget.OpenWindow("MAINMENU_BG"); - break; - case ConnectionState.Connecting: - Widget.OpenWindow("CONNECTING_BG", - new Dictionary { { "host", orderManager.Host }, { "port", orderManager.Port } }); - break; - case ConnectionState.NotConnected: - Widget.OpenWindow("CONNECTION_FAILED_BG", - new Dictionary { { "orderManager", orderManager } }); - break; - case ConnectionState.Connected: - var lobby = Game.OpenWindow(orderManager.world, "SERVER_LOBBY"); - lobby.GetWidget("CHAT_DISPLAY").ClearChat(); - lobby.GetWidget("CHANGEMAP_BUTTON").Visible = true; - lobby.GetWidget("LOCKTEAMS_CHECKBOX").Visible = true; - lobby.GetWidget("ALLOWCHEATS_CHECKBOX").Visible = true; - lobby.GetWidget("DISCONNECT_BUTTON").Visible = true; - break; - } - }; - + if (Info.InstallMode == "cnc") + { + Game.ConnectionStateChanged += orderManager => + { + Widget.CloseWindow(); + switch (orderManager.Connection.ConnectionState) + { + case ConnectionState.PreConnecting: + Widget.OpenWindow("MENU_BACKGROUND"); + break; + case ConnectionState.Connecting: + Widget.OpenWindow("CONNECTING_BG", + new Dictionary { { "host", orderManager.Host }, { "port", orderManager.Port } }); + break; + case ConnectionState.NotConnected: + Widget.OpenWindow("CONNECTION_FAILED_BG", + new Dictionary { { "orderManager", orderManager } }); + break; + case ConnectionState.Connected: + var lobby = Game.OpenWindow(orderManager.world, "SERVER_LOBBY"); + lobby.GetWidget("CHAT_DISPLAY").ClearChat(); + lobby.GetWidget("CHANGEMAP_BUTTON").Visible = true; + lobby.GetWidget("LOCKTEAMS_CHECKBOX").Visible = true; + lobby.GetWidget("ALLOWCHEATS_CHECKBOX").Visible = true; + lobby.GetWidget("DISCONNECT_BUTTON").Visible = true; + break; + } + }; + } + else + { + Game.ConnectionStateChanged += orderManager => + { + Widget.CloseWindow(); + switch (orderManager.Connection.ConnectionState) + { + case ConnectionState.PreConnecting: + Widget.LoadWidget("MAINMENU_BG"); + break; + case ConnectionState.Connecting: + Widget.OpenWindow("CONNECTING_BG", + new Dictionary { { "host", orderManager.Host }, { "port", orderManager.Port } }); + break; + case ConnectionState.NotConnected: + Widget.OpenWindow("CONNECTION_FAILED_BG", + new Dictionary { { "orderManager", orderManager } }); + break; + case ConnectionState.Connected: + var lobby = Game.OpenWindow(orderManager.world, "SERVER_LOBBY"); + lobby.GetWidget("CHAT_DISPLAY").ClearChat(); + lobby.GetWidget("CHANGEMAP_BUTTON").Visible = true; + lobby.GetWidget("LOCKTEAMS_CHECKBOX").Visible = true; + lobby.GetWidget("ALLOWCHEATS_CHECKBOX").Visible = true; + lobby.GetWidget("DISCONNECT_BUTTON").Visible = true; + break; + } + }; + } TestAndContinue(); } @@ -70,7 +101,10 @@ namespace OpenRA.Mods.RA.Widgets.Delegates { Game.LoadShellMap(); Widget.RootWidget.RemoveChildren(); - Widget.OpenWindow("MAINMENU_BG"); + if (Info.InstallMode == "cnc") + Widget.LoadWidget("MENU_BACKGROUND"); + else + Widget.OpenWindow("MAINMENU_BG"); } else { diff --git a/OpenRA.Mods.RA/Widgets/Delegates/IngameChromeDelegate.cs b/OpenRA.Mods.RA/Widgets/Delegates/IngameChromeDelegate.cs index 58d1c61389..4c1d4ca3a1 100755 --- a/OpenRA.Mods.RA/Widgets/Delegates/IngameChromeDelegate.cs +++ b/OpenRA.Mods.RA/Widgets/Delegates/IngameChromeDelegate.cs @@ -30,6 +30,8 @@ namespace OpenRA.Mods.RA.Widgets.Delegates optionsBG.GetWidget("DISCONNECT").OnMouseUp = mi => { optionsBG.Visible = false; Game.Disconnect(); + Widget.CloseWindow(); + Widget.OpenWindow("MAINMENU_BG"); return true; }; diff --git a/OpenRA.Mods.RA/Widgets/Delegates/IngameObserverChromeDelegate.cs b/OpenRA.Mods.RA/Widgets/Delegates/IngameObserverChromeDelegate.cs index e78f41c1a8..52fda8747c 100644 --- a/OpenRA.Mods.RA/Widgets/Delegates/IngameObserverChromeDelegate.cs +++ b/OpenRA.Mods.RA/Widgets/Delegates/IngameObserverChromeDelegate.cs @@ -30,6 +30,8 @@ namespace OpenRA.Mods.RA.Widgets.Delegates optionsBG.GetWidget("DISCONNECT").OnMouseUp = mi => { optionsBG.Visible = false; Game.Disconnect(); + Widget.CloseWindow(); + Widget.OpenWindow("MAINMENU_BG"); return true; }; diff --git a/OpenRA.Mods.RA/Widgets/Delegates/LobbyDelegate.cs b/OpenRA.Mods.RA/Widgets/Delegates/LobbyDelegate.cs index 5a467474e7..77671e031e 100755 --- a/OpenRA.Mods.RA/Widgets/Delegates/LobbyDelegate.cs +++ b/OpenRA.Mods.RA/Widgets/Delegates/LobbyDelegate.cs @@ -102,6 +102,8 @@ namespace OpenRA.Mods.RA.Widgets.Delegates disconnectButton.OnMouseUp = mi => { Game.Disconnect(); + Widget.CloseWindow(); + Widget.OpenWindow("MAINMENU_BG"); return true; }; diff --git a/mods/cnc/chrome/mainmenu.yaml b/mods/cnc/chrome/mainmenu.yaml index 9ebcb82b3a..fe8768e556 100644 --- a/mods/cnc/chrome/mainmenu.yaml +++ b/mods/cnc/chrome/mainmenu.yaml @@ -1,5 +1,5 @@ -Container@MAINMENU_BG: - Id:MAINMENU_BG +Container@MENU_BACKGROUND: + Id:MENU_BACKGROUND X:0 Y:0 Width:WINDOW_RIGHT