restart the game instead of unmounting on the fly

avoid more redundancy between the load screens
This commit is contained in:
Matthias Mailänder
2014-06-28 12:51:54 +02:00
parent 334605287c
commit 2f55768c1b
11 changed files with 64 additions and 105 deletions

View File

@@ -361,13 +361,13 @@ namespace OpenRA
foreach (var mod in ModMetadata.AllMods) foreach (var mod in ModMetadata.AllMods)
Console.WriteLine("\t{0}: {1} ({2})", mod.Key, mod.Value.Title, mod.Value.Version); 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) if (Settings.Server.DiscoverNatDevices)
RunAfterDelay(Settings.Server.NatDiscoveryTimeout, UPnP.StoppingNatDiscovery); 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 // Clear static state if we have switched mods
LobbyInfoChanged = () => { }; LobbyInfoChanged = () => { };
@@ -439,13 +439,45 @@ namespace OpenRA
} }
else else
{ {
modData.LoadScreen.StartGame(); var window = args != null ? args.GetValue("Launch.Window", null) : null;
Settings.Save(); if (!string.IsNullOrEmpty(window))
if (!string.IsNullOrEmpty(replay)) {
Game.JoinReplay(replay); 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() public static void LoadShellMap()
{ {
var shellmap = ChooseShellmap(); var shellmap = ChooseShellmap();
@@ -471,7 +503,7 @@ namespace OpenRA
static double idealFrameTime; static double idealFrameTime;
public static void SetIdealFrameTime(int fps) public static void SetIdealFrameTime(int fps)
{ {
idealFrameTime = 1.0 / fps; idealFrameTime = 1.0 / fps;
} }

View File

@@ -121,25 +121,7 @@ namespace OpenRA.Mods.Cnc
public void StartGame() public void StartGame()
{ {
TestAndContinue(); Game.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();
} }
} }
} }

View File

@@ -69,24 +69,7 @@ namespace OpenRA.Mods.RA
public void StartGame() public void StartGame()
{ {
TestAndContinue(); Game.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();
} }
} }
} }

View File

@@ -30,7 +30,7 @@ namespace OpenRA.Mods.RA
public void StartGame() public void StartGame()
{ {
Ui.ResetAll(); Ui.ResetAll();
Game.modData.WidgetLoader.LoadWidget( new WidgetArgs(), Ui.Root, "INIT_SETUP" ); Game.modData.WidgetLoader.LoadWidget(new WidgetArgs(), Ui.Root, "INIT_SETUP");
} }
} }
} }

View File

@@ -20,7 +20,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
public InstallLogic(Widget widget, IReadOnlyDictionary<string, string> installData, Action continueLoading) public InstallLogic(Widget widget, IReadOnlyDictionary<string, string> installData, Action continueLoading)
{ {
var panel = widget.Get("INSTALL_PANEL"); var panel = widget.Get("INSTALL_PANEL");
var args = new WidgetArgs() var widgetArgs = new WidgetArgs()
{ {
{ "afterInstall", () => { Ui.CloseWindow(); continueLoading(); } }, { "afterInstall", () => { Ui.CloseWindow(); continueLoading(); } },
{ "installData", installData }, { "installData", installData },
@@ -28,15 +28,15 @@ namespace OpenRA.Mods.RA.Widgets.Logic
}; };
panel.Get<ButtonWidget>("DOWNLOAD_BUTTON").OnClick = () => panel.Get<ButtonWidget>("DOWNLOAD_BUTTON").OnClick = () =>
Ui.OpenWindow("INSTALL_DOWNLOAD_PANEL", args); Ui.OpenWindow("INSTALL_DOWNLOAD_PANEL", widgetArgs);
panel.Get<ButtonWidget>("INSTALL_BUTTON").OnClick = () => panel.Get<ButtonWidget>("INSTALL_BUTTON").OnClick = () =>
Ui.OpenWindow("INSTALL_FROMCD_PANEL", args); Ui.OpenWindow("INSTALL_FROMCD_PANEL", widgetArgs);
panel.Get<ButtonWidget>("BACK_BUTTON").OnClick = () => panel.Get<ButtonWidget>("BACK_BUTTON").OnClick = () =>
{ {
Game.Settings.Game.PreviousMod = Game.modData.Manifest.Mod.Id; Game.Settings.Game.PreviousMod = Game.modData.Manifest.Mod.Id;
Game.InitializeWithMod("modchooser", null); Game.InitializeMod("modchooser", null);
}; };
} }
} }

View File

@@ -19,56 +19,15 @@ namespace OpenRA.Mods.RA.Widgets.Logic
{ {
public class InstallMusicLogic public class InstallMusicLogic
{ {
ButtonWidget installButton;
Ruleset modRules;
IReadOnlyDictionary<string, string> installData;
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public InstallMusicLogic(Widget widget, Ruleset modRules) public InstallMusicLogic(Widget widget)
{ {
this.modRules = modRules; var installMusicContainer = widget.Get("INSTALL_MUSIC_PANEL");
installData = Game.modData.Manifest.ContentInstaller;
installButton = widget.GetOrNull<ButtonWidget>("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 cancelButton = installMusicContainer.GetOrNull<ButtonWidget>("CANCEL_BUTTON"); var cancelButton = installMusicContainer.GetOrNull<ButtonWidget>("CANCEL_BUTTON");
if (cancelButton != null) if (cancelButton != null)
{ {
cancelButton.OnClick = () => cancelButton.OnClick = () => Game.InitializeMod(Game.Settings.Game.Mod, null);
{
Game.Settings.Game.ShowShellmap = previousShowShellSetting;
Ui.CloseWindow();
};
} }
var copyFromDiscButton = installMusicContainer.GetOrNull<ButtonWidget>("COPY_FROM_CD_BUTTON"); var copyFromDiscButton = installMusicContainer.GetOrNull<ButtonWidget>("COPY_FROM_CD_BUTTON");
@@ -76,11 +35,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic
{ {
copyFromDiscButton.OnClick = () => copyFromDiscButton.OnClick = () =>
{ {
previousShowShellSetting = Game.Settings.Game.ShowShellmap;
Game.Settings.Game.ShowShellmap = false;
GlobalFileSystem.UnmountAll();
Ui.OpenWindow("INSTALL_FROMCD_PANEL", new WidgetArgs() { 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<ButtonWidget>("DOWNLOAD_BUTTON"); var downloadButton = installMusicContainer.GetOrNull<ButtonWidget>("DOWNLOAD_BUTTON");
if (downloadButton != null) if (downloadButton != null)
{ {
var installData = Game.modData.Manifest.ContentInstaller;
downloadButton.IsVisible = () => !string.IsNullOrEmpty(installData["MusicPackageMirrorList"]); downloadButton.IsVisible = () => !string.IsNullOrEmpty(installData["MusicPackageMirrorList"]);
var musicInstallData = new Dictionary<string, string> { }; var musicInstallData = new Dictionary<string, string> { };
musicInstallData["PackageMirrorList"] = installData["MusicPackageMirrorList"]; musicInstallData["PackageMirrorList"] = installData["MusicPackageMirrorList"];
downloadButton.OnClick = () => downloadButton.OnClick = () =>
{ {
previousShowShellSetting = Game.Settings.Game.ShowShellmap;
Game.Settings.Game.ShowShellmap = false;
GlobalFileSystem.UnmountAll();
Ui.OpenWindow("INSTALL_DOWNLOAD_PANEL", new WidgetArgs() { Ui.OpenWindow("INSTALL_DOWNLOAD_PANEL", new WidgetArgs() {
{ "afterInstall", after }, { "afterInstall", () => Game.InitializeMod(Game.Settings.Game.Mod, null) },
{ "installData", new ReadOnlyDictionary<string, string>(musicInstallData) }, { "installData", new ReadOnlyDictionary<string, string>(musicInstallData) },
}); });
}; };

View File

@@ -54,7 +54,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
mainMenu.Get<ButtonWidget>("MODS_BUTTON").OnClick = () => mainMenu.Get<ButtonWidget>("MODS_BUTTON").OnClick = () =>
{ {
Game.Settings.Game.PreviousMod = Game.modData.Manifest.Mod.Id; Game.Settings.Game.PreviousMod = Game.modData.Manifest.Mod.Id;
Game.InitializeWithMod("modchooser", null); Game.InitializeMod("modchooser", null);
}; };
mainMenu.Get<ButtonWidget>("SETTINGS_BUTTON").OnClick = () => mainMenu.Get<ButtonWidget>("SETTINGS_BUTTON").OnClick = () =>

View File

@@ -161,7 +161,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
Game.RunAfterTick(() => Game.RunAfterTick(() =>
{ {
Ui.CloseWindow(); Ui.CloseWindow();
Game.InitializeWithMod(mod.Id, null); Game.InitializeMod(mod.Id, null);
}); });
} }
} }

View File

@@ -81,6 +81,16 @@ namespace OpenRA.Mods.RA.Widgets.Logic
musicSlider.OnChange += x => Sound.MusicVolume = x; musicSlider.OnChange += x => Sound.MusicVolume = x;
musicSlider.Value = Sound.MusicVolume; musicSlider.Value = Sound.MusicVolume;
var installButton = widget.GetOrNull<ButtonWidget>("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<ButtonWidget>("BACK_BUTTON").OnClick = () => { Game.Settings.Save(); Ui.CloseWindow(); onExit(); }; panel.Get<ButtonWidget>("BACK_BUTTON").OnClick = () => { Game.Settings.Save(); Ui.CloseWindow(); onExit(); };
} }

View File

@@ -170,7 +170,6 @@ Container@MUSIC_PANEL:
Height: 35 Height: 35
Text: Back Text: Back
Button@INSTALL_BUTTON: Button@INSTALL_BUTTON:
Logic: InstallMusicLogic
X: 220 X: 220
Y: 399 Y: 399
Width: 140 Width: 140

View File

@@ -150,7 +150,6 @@ Background@MUSIC_PANEL:
Visible: false Visible: false
Text: No Music Installed Text: No Music Installed
Button@INSTALL_BUTTON: Button@INSTALL_BUTTON:
Logic: InstallMusicLogic
X: 20 X: 20
Y: PARENT_BOTTOM - 45 Y: PARENT_BOTTOM - 45
Width: 120 Width: 120