warn before loading incompatible replays

This commit is contained in:
Matthias Mailänder
2015-01-18 15:02:39 +01:00
parent 5fa7e50c8e
commit 3bb448b29b
9 changed files with 153 additions and 4 deletions

View File

@@ -8,8 +8,10 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.FileFormats;
using OpenRA.FileSystem;
using OpenRA.Mods.Common.Widgets.Logic;
using OpenRA.Widgets;
@@ -78,7 +80,10 @@ namespace OpenRA.Mods.Common.LoadScreens
var replay = args != null ? args.GetValue("Launch.Replay", null) : null;
if (!string.IsNullOrEmpty(replay))
{
Game.JoinReplay(replay);
var replayMeta = ReplayMetadata.Read(replay);
if (ReplayUtils.CheckReplayCompatibility(replayMeta, Game.LoadShellMap))
Game.JoinReplay(replay);
return;
}

View File

@@ -571,6 +571,7 @@
<Compile Include="UtilityCommands\CheckYaml.cs" />
<Compile Include="UtilityCommands\CheckCodeStyle.cs" />
<Compile Include="UtilityCommands\ReplayMetadataCommand.cs" />
<Compile Include="Widgets\Logic\ReplayUtils.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>

View File

@@ -39,6 +39,23 @@ namespace OpenRA.Mods.Common.Widgets
};
}
public static void CancelPrompt(string title, string text, Action onCancel = null, string cancelText = null)
{
var prompt = Ui.OpenWindow("CANCEL_PROMPT");
prompt.Get<LabelWidget>("PROMPT_TITLE").GetText = () => title;
prompt.Get<LabelWidget>("PROMPT_TEXT").GetText = () => text;
if (!string.IsNullOrEmpty(cancelText))
prompt.Get<ButtonWidget>("CANCEL_BUTTON").GetText = () => cancelText;
prompt.Get<ButtonWidget>("CANCEL_BUTTON").OnClick = () =>
{
Ui.CloseWindow();
if (onCancel != null)
onCancel();
};
}
public static void TextInputPrompt(
string title, string prompt, string initialText,
Action<string> onAccept, Action onCancel = null,

View File

@@ -32,11 +32,15 @@ namespace OpenRA.Mods.Common.Widgets.Logic
Dictionary<CPos, SpawnOccupant> selectedSpawns;
ReplayMetadata selectedReplay;
Action onStart;
[ObjectCreator.UseCtor]
public ReplayBrowserLogic(Widget widget, Action onExit, Action onStart)
{
panel = widget;
this.onStart = onStart;
playerList = panel.Get<ScrollPanelWidget>("PLAYER_LIST");
playerHeader = playerList.Get<ScrollItemWidget>("HEADER");
playerTemplate = playerList.Get<ScrollItemWidget>("TEMPLATE");
@@ -73,7 +77,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var watch = panel.Get<ButtonWidget>("WATCH_BUTTON");
watch.IsDisabled = () => selectedReplay == null || selectedReplay.GameInfo.MapPreview.Status != MapStatus.Available;
watch.OnClick = () => { WatchReplay(); onStart(); };
watch.OnClick = () => { WatchReplay(); };
panel.Get("REPLAY_INFO").IsVisible = () => selectedReplay != null;
@@ -624,11 +628,15 @@ namespace OpenRA.Mods.Common.Widgets.Logic
void WatchReplay()
{
if (selectedReplay != null && selectedReplay.GameInfo.MapPreview.Status == MapStatus.Available)
Action startReplay = () =>
{
Game.JoinReplay(selectedReplay.FilePath);
Ui.CloseWindow();
}
onStart();
};
if (selectedReplay != null && ReplayUtils.CheckReplayCompatibility(selectedReplay))
startReplay();
}
void AddReplay(ReplayMetadata replay, ScrollItemWidget template)

View File

@@ -0,0 +1,55 @@
#region Copyright & License Information
/*
* Copyright 2007-2015 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System;
using OpenRA.FileFormats;
namespace OpenRA.Mods.Common.Widgets.Logic
{
public static class ReplayUtils
{
static readonly Action DoNothing = () => { };
public static bool CheckReplayCompatibility(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);
var version = replayMeta.GameInfo.Version;
if (version == null)
return IncompatibleReplayDialog("an unknown version", version, onCancel);
var allMods = ModMetadata.AllMods;
if (!allMods.ContainsKey(mod))
return IncompatibleReplayDialog("an unavailable mod", mod, onCancel);
else if (allMods[mod].Version != version)
return IncompatibleReplayDialog("an incompatible version", version, onCancel);
if (replayMeta.GameInfo.MapPreview.Status != MapStatus.Available)
return IncompatibleReplayDialog("an unavailable map", replayMeta.GameInfo.MapUid, onCancel);
else
return true;
}
static bool IncompatibleReplayDialog(string type, string name, Action onCancel)
{
var error = "It was recorded with " + type;
error += string.IsNullOrEmpty(name) ? "." : ":\n{0}".F(name);
ConfirmationDialogs.CancelPrompt("Incompatible Replay", error, onCancel);
return false;
}
}
}