diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index 091a776b18..305ee751d1 100755 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -102,7 +102,6 @@ namespace OpenRA static object syncroot = new object(); static Action tickActions = () => {}; - public static void RunAfterTick(Action a) { lock(syncroot) tickActions += a; } static void Tick( OrderManager orderManager, Viewport viewPort ) { @@ -251,9 +250,19 @@ namespace OpenRA public static void InitializeWithMods(string[] mods) { + // Clear static state if we have switched mods + LobbyInfoChanged = () => {}; + AddChatLine = (a,b,c) => {}; + worldRenderer = null; + if (server != null) + server.Shutdown(); + if (orderManager != null) + orderManager.Dispose(); + // Discard any invalid mods var mm = mods.Where( m => Mod.AllMods.ContainsKey( m ) ).ToArray(); Console.WriteLine("Loading mods: {0}",string.Join(",",mm)); + modData = new ModData( mm ); modData.LoadInitialAssets(); diff --git a/OpenRA.Mods.RA/OpenWidgetAtGameStart.cs b/OpenRA.Mods.RA/OpenWidgetAtGameStart.cs index 16a49d53d5..f91ab3542b 100644 --- a/OpenRA.Mods.RA/OpenWidgetAtGameStart.cs +++ b/OpenRA.Mods.RA/OpenWidgetAtGameStart.cs @@ -9,6 +9,7 @@ #endregion using OpenRA.Traits; +using OpenRA.Widgets; namespace OpenRA.Mods.RA { @@ -30,6 +31,9 @@ namespace OpenRA.Mods.RA public void WorldLoaded(World world) { + // Remove all open widgets + Widget.RootWidget.Children.Clear(); + if (world.LocalPlayer != null) Game.OpenWindow(world, Info.Widget); else if (Info.ObserverWidget != null) diff --git a/OpenRA.Mods.RA/Widgets/Delegates/MainMenuButtonsDelegate.cs b/OpenRA.Mods.RA/Widgets/Delegates/MainMenuButtonsDelegate.cs index 1d30e4ca25..002886a9cf 100755 --- a/OpenRA.Mods.RA/Widgets/Delegates/MainMenuButtonsDelegate.cs +++ b/OpenRA.Mods.RA/Widgets/Delegates/MainMenuButtonsDelegate.cs @@ -31,7 +31,8 @@ namespace OpenRA.Mods.RA.Widgets.Delegates widget.GetWidget("MAINMENU_BUTTON_REPLAY_VIEWER").OnMouseUp = mi => { Widget.OpenWindow("REPLAYBROWSER_BG"); return true; }; widget.GetWidget("MAINMENU_BUTTON_QUIT").OnMouseUp = mi => { Game.Exit(); return true; }; - var selector = widget.GetWidget("QUICKMODSWITCHER"); + var switcher = Game.modData.WidgetLoader.LoadWidget( new Dictionary(), Widget.RootWidget, "QUICKMODSWITCHER" ); + var selector = switcher.GetWidget("SWITCHER"); selector.OnMouseDown = _ => ShowModsDropDown(selector); selector.GetText = ActiveModTitle; } @@ -57,7 +58,7 @@ namespace OpenRA.Mods.RA.Widgets.Delegates } dropDownOptions.Add(new Pair( kv.Value.Title, - () => Game.InitializeWithMods( modList.ToArray() ) )); + () => Game.RunAfterTick(() => Game.InitializeWithMods( modList.ToArray() ) ))); } DropDownButtonWidget.ShowDropDown( selector, diff --git a/mods/cnc/chrome/mainmenu.yaml b/mods/cnc/chrome/mainmenu.yaml index 3e4a598064..b8e169ae54 100644 --- a/mods/cnc/chrome/mainmenu.yaml +++ b/mods/cnc/chrome/mainmenu.yaml @@ -72,28 +72,29 @@ Background@MAINMENU_BG: Height:25 Text:Video Player Bold:True - Background@QUICKMODSWITCHER_BG: - Background: dialog4 - X:(WINDOW_RIGHT - PARENT_LEFT - WIDTH - 10) - Y:10 - PARENT_TOP - Width:205 - Height:35 - Children: - Label@TITLE: - X:8 - Y:3 - Width:PARENT_RIGHT - Height:25 - Text:Mod: - Align:Left - Bold:True - DropDownButton@QUICKMODSWITCHER: - Id:QUICKMODSWITCHER - Text:Team - Width:150 - Height:25 - X:50 - Y:5 +Background@QUICKMODSWITCHER: + Id:QUICKMODSWITCHER + Background: dialog4 + X:(WINDOW_RIGHT - PARENT_LEFT - WIDTH - 10) + Y:10 - PARENT_TOP + Width:205 + Height:35 + Children: + Label@TITLE: + X:8 + Y:3 + Width:PARENT_RIGHT + Height:25 + Text:Mod: + Align:Left + Bold:True + DropDownButton@SWITCHER: + Id:SWITCHER + Text:Team + Width:150 + Height:25 + X:50 + Y:5 Background@PERF_BG: Id:PERF_BG Background:dialog4 diff --git a/mods/ra/chrome/mainmenu.yaml b/mods/ra/chrome/mainmenu.yaml index 5ad31f4a17..46138a3501 100644 --- a/mods/ra/chrome/mainmenu.yaml +++ b/mods/ra/chrome/mainmenu.yaml @@ -73,28 +73,29 @@ Background@MAINMENU_BG: Height:25 Text:Video Player Bold:True - Background@QUICKMODSWITCHER_BG: - Background: dialog4 - X:(WINDOW_RIGHT - PARENT_LEFT - WIDTH - 10) - Y:10 - PARENT_TOP - Width:205 - Height:35 - Children: - Label@TITLE: - X:8 - Y:3 - Width:PARENT_RIGHT - Height:25 - Text:Mod: - Align:Left - Bold:True - DropDownButton@QUICKMODSWITCHER: - Id:QUICKMODSWITCHER - Text:Team - Width:150 - Height:25 - X:50 - Y:5 +Background@QUICKMODSWITCHER: + Id:QUICKMODSWITCHER + Background: dialog4 + X:(WINDOW_RIGHT - PARENT_LEFT - WIDTH - 10) + Y:10 - PARENT_TOP + Width:205 + Height:35 + Children: + Label@TITLE: + X:8 + Y:3 + Width:PARENT_RIGHT + Height:25 + Text:Mod: + Align:Left + Bold:True + DropDownButton@SWITCHER: + Id:SWITCHER + Text:Team + Width:150 + Height:25 + X:50 + Y:5 Background@PERF_BG: ClickThrough:true Id:PERF_BG