From 38486e8184aeb6f26b7dd017a96c77e9faf04c6c Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Mon, 8 Nov 2010 13:23:36 +1300 Subject: [PATCH] Move some mod-specific UI code out of Game --- OpenRA.Game/Game.cs | 28 +-------------- .../Delegates/MainMenuButtonsDelegate.cs | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+), 27 deletions(-) diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index b58c203e47..f2d47d9276 100755 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -230,33 +230,7 @@ namespace OpenRA JoinLocal(); StartGame(modData.Manifest.ShellmapUid); - 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 { { "host", orderManager.Host }, { "port", orderManager.Port } } ); - break; - case ConnectionState.Connected: - var lobby = Widget.OpenWindow( "SERVER_LOBBY", new Dictionary { { "orderManager", orderManager } } ); - lobby.GetWidget("CHAT_DISPLAY").ClearChat(); - lobby.GetWidget("CHANGEMAP_BUTTON").Visible = true; - lobby.GetWidget("LOCKTEAMS_CHECKBOX").Visible = true; - lobby.GetWidget("DISCONNECT_BUTTON").Visible = true; - //r.GetWidget("INGAME_ROOT").GetWidget("CHAT_DISPLAY").ClearChat(); - break; - } - }; - + // TODO: unhardcode this modData.WidgetLoader.LoadWidget( new Dictionary(), Widget.RootWidget, "PERF_BG" ); Widget.OpenWindow("MAINMENU_BG"); diff --git a/OpenRA.Game/Widgets/Delegates/MainMenuButtonsDelegate.cs b/OpenRA.Game/Widgets/Delegates/MainMenuButtonsDelegate.cs index f4368441a9..54e2a04743 100755 --- a/OpenRA.Game/Widgets/Delegates/MainMenuButtonsDelegate.cs +++ b/OpenRA.Game/Widgets/Delegates/MainMenuButtonsDelegate.cs @@ -10,11 +10,15 @@ using OpenRA.FileFormats; using OpenRA.Server; +using OpenRA.Network; +using System.Collections.Generic; namespace OpenRA.Widgets.Delegates { public class MainMenuButtonsDelegate : IWidgetDelegate { + static bool FirstInit = true; + [ObjectCreator.UseCtor] public MainMenuButtonsDelegate( [ObjectCreator.Param] Widget widget ) { @@ -48,6 +52,37 @@ namespace OpenRA.Widgets.Delegates MasterServerQuery.ClientVersion = version.Text; MasterServerQuery.GetMOTD(Game.Settings.Server.MasterServer); + + if (FirstInit) + { + FirstInit = false; + 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 { { "host", orderManager.Host }, { "port", orderManager.Port } } ); + break; + case ConnectionState.Connected: + var lobby = Widget.OpenWindow( "SERVER_LOBBY", new Dictionary { { "orderManager", orderManager } } ); + lobby.GetWidget("CHAT_DISPLAY").ClearChat(); + lobby.GetWidget("CHANGEMAP_BUTTON").Visible = true; + lobby.GetWidget("LOCKTEAMS_CHECKBOX").Visible = true; + lobby.GetWidget("DISCONNECT_BUTTON").Visible = true; + //r.GetWidget("INGAME_ROOT").GetWidget("CHAT_DISPLAY").ClearChat(); + break; + } + }; + } } } }