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.

This commit is contained in:
Paul Chote
2011-05-05 22:44:21 +12:00
parent f74b1b6d27
commit a3b430c24a
9 changed files with 85 additions and 34 deletions

View File

@@ -329,9 +329,6 @@ namespace OpenRA
var shellmap = ChooseShellmap(); var shellmap = ChooseShellmap();
JoinLocal(); JoinLocal();
StartGame(shellmap); StartGame(shellmap);
Widget.CloseWindow();
Widget.OpenWindow("MAINMENU_BG");
} }
public static T CreateObject<T>( string name ) public static T CreateObject<T>( string name )

View File

@@ -313,6 +313,7 @@ namespace OpenRA.Widgets
public static void CloseWindow() public static void CloseWindow()
{ {
if (WindowList.Count > 0)
RootWidget.Children.Remove(WindowList.Pop()); RootWidget.Children.Remove(WindowList.Pop());
if (WindowList.Count > 0) if (WindowList.Count > 0)
rootWidget.Children.Add(WindowList.Peek()); rootWidget.Children.Add(WindowList.Peek());
@@ -332,6 +333,11 @@ namespace OpenRA.Widgets
return window; return window;
} }
public static Widget LoadWidget(string id)
{
return Game.modData.WidgetLoader.LoadWidget(new Dictionary<string, object>(), rootWidget, id);
}
public static void DoTick() public static void DoTick()
{ {
RootWidget.Tick(); RootWidget.Tick();

View File

@@ -59,6 +59,8 @@ namespace OpenRA.Mods.Cnc
{ {
Sound.StopMusic(); Sound.StopMusic();
Game.Disconnect(); Game.Disconnect();
Widget.CloseWindow();
Widget.LoadWidget("MENU_BACKGROUND");
}))); })));
} }
@@ -75,6 +77,8 @@ namespace OpenRA.Mods.Cnc
{ {
Sound.StopMusic(); Sound.StopMusic();
Game.Disconnect(); Game.Disconnect();
Widget.CloseWindow();
Widget.LoadWidget("MENU_BACKGROUND");
}))); })));
} }

View File

@@ -24,6 +24,8 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
widget.GetWidget("CONNECTION_BUTTON_ABORT").OnMouseUp = mi => { widget.GetWidget("CONNECTION_BUTTON_ABORT").OnMouseUp = mi => {
widget.GetWidget("CONNECTION_BUTTON_ABORT").Parent.Visible = false; widget.GetWidget("CONNECTION_BUTTON_ABORT").Parent.Visible = false;
Game.Disconnect(); Game.Disconnect();
Widget.CloseWindow();
Widget.OpenWindow("MAINMENU_BG");
return true; return true;
}; };
@@ -42,6 +44,8 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
widget.GetWidget("CONNECTION_BUTTON_CANCEL").OnMouseUp = mi => { widget.GetWidget("CONNECTION_BUTTON_CANCEL").OnMouseUp = mi => {
widget.GetWidget("CONNECTION_BUTTON_CANCEL").Parent.Visible = false; widget.GetWidget("CONNECTION_BUTTON_CANCEL").Parent.Visible = false;
Game.Disconnect(); Game.Disconnect();
Widget.CloseWindow();
Widget.OpenWindow("MAINMENU_BG");
return true; return true;
}; };
widget.GetWidget("CONNECTION_BUTTON_RETRY").OnMouseUp = mi => { widget.GetWidget("CONNECTION_BUTTON_RETRY").OnMouseUp = mi => {

View File

@@ -33,6 +33,8 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
} }
public void Init() public void Init()
{
if (Info.InstallMode == "cnc")
{ {
Game.ConnectionStateChanged += orderManager => Game.ConnectionStateChanged += orderManager =>
{ {
@@ -40,7 +42,7 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
switch (orderManager.Connection.ConnectionState) switch (orderManager.Connection.ConnectionState)
{ {
case ConnectionState.PreConnecting: case ConnectionState.PreConnecting:
Widget.OpenWindow("MAINMENU_BG"); Widget.OpenWindow("MENU_BACKGROUND");
break; break;
case ConnectionState.Connecting: case ConnectionState.Connecting:
Widget.OpenWindow("CONNECTING_BG", Widget.OpenWindow("CONNECTING_BG",
@@ -60,7 +62,36 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
break; 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<string, object> { { "host", orderManager.Host }, { "port", orderManager.Port } });
break;
case ConnectionState.NotConnected:
Widget.OpenWindow("CONNECTION_FAILED_BG",
new Dictionary<string, object> { { "orderManager", orderManager } });
break;
case ConnectionState.Connected:
var lobby = Game.OpenWindow(orderManager.world, "SERVER_LOBBY");
lobby.GetWidget<ChatDisplayWidget>("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(); TestAndContinue();
} }
@@ -70,6 +101,9 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
{ {
Game.LoadShellMap(); Game.LoadShellMap();
Widget.RootWidget.RemoveChildren(); Widget.RootWidget.RemoveChildren();
if (Info.InstallMode == "cnc")
Widget.LoadWidget("MENU_BACKGROUND");
else
Widget.OpenWindow("MAINMENU_BG"); Widget.OpenWindow("MAINMENU_BG");
} }
else else

View File

@@ -30,6 +30,8 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
optionsBG.GetWidget("DISCONNECT").OnMouseUp = mi => { optionsBG.GetWidget("DISCONNECT").OnMouseUp = mi => {
optionsBG.Visible = false; optionsBG.Visible = false;
Game.Disconnect(); Game.Disconnect();
Widget.CloseWindow();
Widget.OpenWindow("MAINMENU_BG");
return true; return true;
}; };

View File

@@ -30,6 +30,8 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
optionsBG.GetWidget("DISCONNECT").OnMouseUp = mi => { optionsBG.GetWidget("DISCONNECT").OnMouseUp = mi => {
optionsBG.Visible = false; optionsBG.Visible = false;
Game.Disconnect(); Game.Disconnect();
Widget.CloseWindow();
Widget.OpenWindow("MAINMENU_BG");
return true; return true;
}; };

View File

@@ -102,6 +102,8 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
disconnectButton.OnMouseUp = mi => disconnectButton.OnMouseUp = mi =>
{ {
Game.Disconnect(); Game.Disconnect();
Widget.CloseWindow();
Widget.OpenWindow("MAINMENU_BG");
return true; return true;
}; };

View File

@@ -1,5 +1,5 @@
Container@MAINMENU_BG: Container@MENU_BACKGROUND:
Id:MAINMENU_BG Id:MENU_BACKGROUND
X:0 X:0
Y:0 Y:0
Width:WINDOW_RIGHT Width:WINDOW_RIGHT