automatically switch mods when possible

This commit is contained in:
Matthias Mailänder
2015-01-25 13:57:12 +01:00
parent 3bb448b29b
commit e13447e641
3 changed files with 27 additions and 17 deletions

View File

@@ -77,12 +77,19 @@ namespace OpenRA.Mods.Common.LoadScreens
}
// Load a replay directly
var replay = args != null ? args.GetValue("Launch.Replay", null) : null;
if (!string.IsNullOrEmpty(replay))
var replayFilename = args != null ? args.GetValue("Launch.Replay", null) : null;
if (!string.IsNullOrEmpty(replayFilename))
{
var replayMeta = ReplayMetadata.Read(replay);
if (ReplayUtils.CheckReplayCompatibility(replayMeta, Game.LoadShellMap))
Game.JoinReplay(replay);
var replayMeta = ReplayMetadata.Read(replayFilename);
if (ReplayUtils.PromptConfirmReplayCompatibility(replayMeta, Game.LoadShellMap))
Game.JoinReplay(replayFilename);
if (replayMeta != null)
{
var mod = replayMeta.GameInfo.Mod;
if (mod != null && mod != Game.ModData.Manifest.Mod.Id && ModMetadata.AllMods.ContainsKey(mod))
Game.InitializeMod(mod, args);
}
return;
}

View File

@@ -635,7 +635,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
onStart();
};
if (selectedReplay != null && ReplayUtils.CheckReplayCompatibility(selectedReplay))
if (selectedReplay != null && ReplayUtils.PromptConfirmReplayCompatibility(selectedReplay))
startReplay();
}

View File

@@ -17,34 +17,37 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{
static readonly Action DoNothing = () => { };
public static bool CheckReplayCompatibility(ReplayMetadata replayMeta, Action onCancel = null)
public static bool PromptConfirmReplayCompatibility(ReplayMetadata replayMeta, Action onCancel = null)
{
if (onCancel == null)
onCancel = DoNothing;
var mod = replayMeta.GameInfo.Mod;
if (mod == null)
return IncompatibleReplayDialog("an unknown mod", mod, onCancel);
if (replayMeta == null)
return IncompatibleReplayDialog("outdated engine", null, onCancel);
var version = replayMeta.GameInfo.Version;
if (version == null)
return IncompatibleReplayDialog("an unknown version", version, onCancel);
return IncompatibleReplayDialog("unknown version", version, onCancel);
var mod = replayMeta.GameInfo.Mod;
if (mod == null)
return IncompatibleReplayDialog("unknown mod", mod, onCancel);
var allMods = ModMetadata.AllMods;
if (!allMods.ContainsKey(mod))
return IncompatibleReplayDialog("an unavailable mod", mod, onCancel);
return IncompatibleReplayDialog("unavailable mod", mod, onCancel);
else if (allMods[mod].Version != version)
return IncompatibleReplayDialog("an incompatible version", version, onCancel);
return IncompatibleReplayDialog("incompatible version", version, onCancel);
if (replayMeta.GameInfo.MapPreview.Status != MapStatus.Available)
return IncompatibleReplayDialog("an unavailable map", replayMeta.GameInfo.MapUid, onCancel);
else
return IncompatibleReplayDialog("unavailable map", replayMeta.GameInfo.MapUid, onCancel);
return true;
}
static bool IncompatibleReplayDialog(string type, string name, Action onCancel)
{
var error = "It was recorded with " + type;
var error = "It was recorded with an " + type;
error += string.IsNullOrEmpty(name) ? "." : ":\n{0}".F(name);
ConfirmationDialogs.CancelPrompt("Incompatible Replay", error, onCancel);