diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index b3ed7c2915..9c43bd2581 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -361,13 +361,13 @@ namespace OpenRA foreach (var mod in ModMetadata.AllMods) Console.WriteLine("\t{0}: {1} ({2})", mod.Key, mod.Value.Title, mod.Value.Version); - InitializeWithMod(Settings.Game.Mod, args.GetValue("Launch.Replay", null)); + InitializeMod(Settings.Game.Mod, args); if (Settings.Server.DiscoverNatDevices) RunAfterDelay(Settings.Server.NatDiscoveryTimeout, UPnP.StoppingNatDiscovery); } - public static void InitializeWithMod(string mod, string replay) + public static void InitializeMod(string mod, Arguments args) { // Clear static state if we have switched mods LobbyInfoChanged = () => { }; @@ -439,13 +439,45 @@ namespace OpenRA } else { - modData.LoadScreen.StartGame(); - Settings.Save(); - if (!string.IsNullOrEmpty(replay)) - Game.JoinReplay(replay); + var window = args != null ? args.GetValue("Launch.Window", null) : null; + if (!string.IsNullOrEmpty(window)) + { + var installData = modData.Manifest.ContentInstaller; + if (installData.ContainsKey("InstallerBackgroundWidget")) + Ui.LoadWidget(installData["InstallerBackgroundWidget"], Ui.Root, new WidgetArgs()); + + Widgets.Ui.OpenWindow(window, new WidgetArgs()); + } + else + { + modData.LoadScreen.StartGame(); + Settings.Save(); + var replay = args != null ? args.GetValue("Launch.Replay", null) : null; + if (!string.IsNullOrEmpty(replay)) + Game.JoinReplay(replay); + } } } + public static void TestAndContinue() + { + Ui.ResetAll(); + var installData = modData.Manifest.ContentInstaller; + if (!installData["TestFiles"].Split(',').All(f => GlobalFileSystem.Exists(f.Trim()))) + { + var args = new WidgetArgs() + { + { "continueLoading", () => TestAndContinue() }, + { "installData", installData } + }; + if (installData.ContainsKey("InstallerBackgroundWidget")) + Ui.LoadWidget(installData["InstallerBackgroundWidget"], Ui.Root, args); + Ui.OpenWindow(installData["InstallerMenuWidget"], args); + } + else + LoadShellMap(); + } + public static void LoadShellMap() { var shellmap = ChooseShellmap(); @@ -471,7 +503,7 @@ namespace OpenRA static double idealFrameTime; public static void SetIdealFrameTime(int fps) - { + { idealFrameTime = 1.0 / fps; } diff --git a/OpenRA.Mods.Cnc/CncLoadScreen.cs b/OpenRA.Mods.Cnc/CncLoadScreen.cs index d2762f320f..ff7db891ac 100644 --- a/OpenRA.Mods.Cnc/CncLoadScreen.cs +++ b/OpenRA.Mods.Cnc/CncLoadScreen.cs @@ -121,25 +121,7 @@ namespace OpenRA.Mods.Cnc public void StartGame() { - TestAndContinue(); - } - - void TestAndContinue() - { - Ui.ResetAll(); - var installData = Game.modData.Manifest.ContentInstaller; - if (!installData["TestFiles"].Split(',').All(f => GlobalFileSystem.Exists(f.Trim()))) - { - var args = new WidgetArgs() - { - { "continueLoading", () => TestAndContinue() }, - { "installData", installData } - }; - Ui.LoadWidget(installData["InstallerBackgroundWidget"], Ui.Root, args); - Ui.OpenWindow(installData["InstallerMenuWidget"], args); - } - else - Game.LoadShellMap(); + Game.TestAndContinue(); } } } \ No newline at end of file diff --git a/OpenRA.Mods.RA/DefaultLoadScreen.cs b/OpenRA.Mods.RA/DefaultLoadScreen.cs index a9f01e9b5a..3e4481079a 100644 --- a/OpenRA.Mods.RA/DefaultLoadScreen.cs +++ b/OpenRA.Mods.RA/DefaultLoadScreen.cs @@ -69,24 +69,7 @@ namespace OpenRA.Mods.RA public void StartGame() { - TestAndContinue(); - } - - void TestAndContinue() - { - Ui.ResetAll(); - var installData = Game.modData.Manifest.ContentInstaller; - if (!installData["TestFiles"].Split(',').All(f => GlobalFileSystem.Exists(f.Trim()))) - { - var args = new WidgetArgs() - { - { "continueLoading", () => TestAndContinue() }, - { "installData", installData } - }; - Ui.OpenWindow(installData["InstallerMenuWidget"], args); - } - else - Game.LoadShellMap(); + Game.TestAndContinue(); } } } diff --git a/OpenRA.Mods.RA/NullLoadScreen.cs b/OpenRA.Mods.RA/NullLoadScreen.cs index 05217fe3f4..1515f8afd8 100644 --- a/OpenRA.Mods.RA/NullLoadScreen.cs +++ b/OpenRA.Mods.RA/NullLoadScreen.cs @@ -30,7 +30,7 @@ namespace OpenRA.Mods.RA public void StartGame() { Ui.ResetAll(); - Game.modData.WidgetLoader.LoadWidget( new WidgetArgs(), Ui.Root, "INIT_SETUP" ); + Game.modData.WidgetLoader.LoadWidget(new WidgetArgs(), Ui.Root, "INIT_SETUP"); } } } diff --git a/OpenRA.Mods.RA/Widgets/Logic/InstallLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/InstallLogic.cs index 0da7eebe25..4ffbaf0a48 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/InstallLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/InstallLogic.cs @@ -20,7 +20,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic public InstallLogic(Widget widget, IReadOnlyDictionary installData, Action continueLoading) { var panel = widget.Get("INSTALL_PANEL"); - var args = new WidgetArgs() + var widgetArgs = new WidgetArgs() { { "afterInstall", () => { Ui.CloseWindow(); continueLoading(); } }, { "installData", installData }, @@ -28,15 +28,15 @@ namespace OpenRA.Mods.RA.Widgets.Logic }; panel.Get("DOWNLOAD_BUTTON").OnClick = () => - Ui.OpenWindow("INSTALL_DOWNLOAD_PANEL", args); + Ui.OpenWindow("INSTALL_DOWNLOAD_PANEL", widgetArgs); panel.Get("INSTALL_BUTTON").OnClick = () => - Ui.OpenWindow("INSTALL_FROMCD_PANEL", args); + Ui.OpenWindow("INSTALL_FROMCD_PANEL", widgetArgs); panel.Get("BACK_BUTTON").OnClick = () => { Game.Settings.Game.PreviousMod = Game.modData.Manifest.Mod.Id; - Game.InitializeWithMod("modchooser", null); + Game.InitializeMod("modchooser", null); }; } } diff --git a/OpenRA.Mods.RA/Widgets/Logic/InstallMusicLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/InstallMusicLogic.cs index 544f365222..f38697f925 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/InstallMusicLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/InstallMusicLogic.cs @@ -19,56 +19,15 @@ namespace OpenRA.Mods.RA.Widgets.Logic { public class InstallMusicLogic { - ButtonWidget installButton; - Ruleset modRules; - IReadOnlyDictionary installData; - [ObjectCreator.UseCtor] - public InstallMusicLogic(Widget widget, Ruleset modRules) + public InstallMusicLogic(Widget widget) { - this.modRules = modRules; - - installData = Game.modData.Manifest.ContentInstaller; - - installButton = widget.GetOrNull("INSTALL_BUTTON"); - if (installButton != null) - { - installButton.OnClick = () => LoadInstallMusicContainer(); - installButton.IsVisible = () => - modRules.InstalledMusic.ToArray().Length <= Exts.ParseIntegerInvariant(installData["ShippedSoundtracks"]); - } - } - - bool previousShowShellSetting; - void LoadInstallMusicContainer() - { - var installMusicContainer = Ui.OpenWindow("INSTALL_MUSIC_PANEL", new WidgetArgs()); - - Action after = () => - { - try - { - GlobalFileSystem.LoadFromManifest(Game.modData.Manifest); - modRules.Music.Do(m => m.Value.Reload()); - var musicPlayerLogic = (MusicPlayerLogic)installButton.Parent.LogicObject; - musicPlayerLogic.BuildMusicTable(); - Ui.CloseWindow(); - Game.Settings.Game.ShowShellmap = previousShowShellSetting; - } - catch (Exception e) - { - Log.Write("debug", "Mounting the new MIX file and rebuild of scores list failed:\n{0}", e); - } - }; + var installMusicContainer = widget.Get("INSTALL_MUSIC_PANEL"); var cancelButton = installMusicContainer.GetOrNull("CANCEL_BUTTON"); if (cancelButton != null) { - cancelButton.OnClick = () => - { - Game.Settings.Game.ShowShellmap = previousShowShellSetting; - Ui.CloseWindow(); - }; + cancelButton.OnClick = () => Game.InitializeMod(Game.Settings.Game.Mod, null); } var copyFromDiscButton = installMusicContainer.GetOrNull("COPY_FROM_CD_BUTTON"); @@ -76,11 +35,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic { copyFromDiscButton.OnClick = () => { - previousShowShellSetting = Game.Settings.Game.ShowShellmap; - Game.Settings.Game.ShowShellmap = false; - GlobalFileSystem.UnmountAll(); Ui.OpenWindow("INSTALL_FROMCD_PANEL", new WidgetArgs() { - { "continueLoading", after }, + { "continueLoading", () => Game.InitializeMod(Game.Settings.Game.Mod, null) }, }); }; } @@ -88,17 +44,15 @@ namespace OpenRA.Mods.RA.Widgets.Logic var downloadButton = installMusicContainer.GetOrNull("DOWNLOAD_BUTTON"); if (downloadButton != null) { + var installData = Game.modData.Manifest.ContentInstaller; downloadButton.IsVisible = () => !string.IsNullOrEmpty(installData["MusicPackageMirrorList"]); var musicInstallData = new Dictionary { }; musicInstallData["PackageMirrorList"] = installData["MusicPackageMirrorList"]; downloadButton.OnClick = () => { - previousShowShellSetting = Game.Settings.Game.ShowShellmap; - Game.Settings.Game.ShowShellmap = false; - GlobalFileSystem.UnmountAll(); Ui.OpenWindow("INSTALL_DOWNLOAD_PANEL", new WidgetArgs() { - { "afterInstall", after }, + { "afterInstall", () => Game.InitializeMod(Game.Settings.Game.Mod, null) }, { "installData", new ReadOnlyDictionary(musicInstallData) }, }); }; diff --git a/OpenRA.Mods.RA/Widgets/Logic/MainMenuLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/MainMenuLogic.cs index 5231c797cd..70be5d890e 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/MainMenuLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/MainMenuLogic.cs @@ -54,7 +54,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic mainMenu.Get("MODS_BUTTON").OnClick = () => { Game.Settings.Game.PreviousMod = Game.modData.Manifest.Mod.Id; - Game.InitializeWithMod("modchooser", null); + Game.InitializeMod("modchooser", null); }; mainMenu.Get("SETTINGS_BUTTON").OnClick = () => diff --git a/OpenRA.Mods.RA/Widgets/Logic/ModBrowserLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/ModBrowserLogic.cs index 0d09193a9d..7a2a518185 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/ModBrowserLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/ModBrowserLogic.cs @@ -161,7 +161,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic Game.RunAfterTick(() => { Ui.CloseWindow(); - Game.InitializeWithMod(mod.Id, null); + Game.InitializeMod(mod.Id, null); }); } } diff --git a/OpenRA.Mods.RA/Widgets/Logic/MusicPlayerLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/MusicPlayerLogic.cs index 6b8dd1a4ce..8e49ba7fed 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/MusicPlayerLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/MusicPlayerLogic.cs @@ -81,6 +81,16 @@ namespace OpenRA.Mods.RA.Widgets.Logic musicSlider.OnChange += x => Sound.MusicVolume = x; musicSlider.Value = Sound.MusicVolume; + var installButton = widget.GetOrNull("INSTALL_BUTTON"); + if (installButton != null) + { + var args = new string[] { "Launch.Window=INSTALL_MUSIC_PANEL" }; + installButton.OnClick = () => Game.InitializeMod(Game.Settings.Game.Mod, new Arguments(args)); + var installData = Game.modData.Manifest.ContentInstaller; + installButton.IsVisible = () => + modRules.InstalledMusic.ToArray().Length <= Exts.ParseIntegerInvariant(installData["ShippedSoundtracks"]); + } + panel.Get("BACK_BUTTON").OnClick = () => { Game.Settings.Save(); Ui.CloseWindow(); onExit(); }; } diff --git a/mods/cnc/chrome/music.yaml b/mods/cnc/chrome/music.yaml index 8bc5ee0fc3..b7faa30885 100644 --- a/mods/cnc/chrome/music.yaml +++ b/mods/cnc/chrome/music.yaml @@ -170,7 +170,6 @@ Container@MUSIC_PANEL: Height: 35 Text: Back Button@INSTALL_BUTTON: - Logic: InstallMusicLogic X: 220 Y: 399 Width: 140 diff --git a/mods/ra/chrome/musicplayer.yaml b/mods/ra/chrome/musicplayer.yaml index f75d890ca9..50f0826a4d 100644 --- a/mods/ra/chrome/musicplayer.yaml +++ b/mods/ra/chrome/musicplayer.yaml @@ -150,7 +150,6 @@ Background@MUSIC_PANEL: Visible: false Text: No Music Installed Button@INSTALL_BUTTON: - Logic: InstallMusicLogic X: 20 Y: PARENT_BOTTOM - 45 Width: 120