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

@@ -18,8 +18,12 @@ namespace OpenRA
{ {
public class GameInformation public class GameInformation
{ {
public string Mod;
public string Version;
public string MapUid; public string MapUid;
public string MapTitle; public string MapTitle;
public DateTime StartTimeUtc; public DateTime StartTimeUtc;
// Game end timestamp (when the recoding stopped). // Game end timestamp (when the recoding stopped).

View File

@@ -199,6 +199,9 @@ namespace OpenRA
gameInfo = new GameInformation gameInfo = new GameInformation
{ {
Mod = Game.ModData.Manifest.Mod.Id,
Version = Game.ModData.Manifest.Mod.Version,
MapUid = Map.Uid, MapUid = Map.Uid,
MapTitle = Map.Title MapTitle = Map.Title
}; };

View File

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

View File

@@ -571,6 +571,7 @@
<Compile Include="UtilityCommands\CheckYaml.cs" /> <Compile Include="UtilityCommands\CheckYaml.cs" />
<Compile Include="UtilityCommands\CheckCodeStyle.cs" /> <Compile Include="UtilityCommands\CheckCodeStyle.cs" />
<Compile Include="UtilityCommands\ReplayMetadataCommand.cs" /> <Compile Include="UtilityCommands\ReplayMetadataCommand.cs" />
<Compile Include="Widgets\Logic\ReplayUtils.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup> <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( public static void TextInputPrompt(
string title, string prompt, string initialText, string title, string prompt, string initialText,
Action<string> onAccept, Action onCancel = null, Action<string> onAccept, Action onCancel = null,

View File

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

View File

@@ -155,6 +155,35 @@ Container@CONFIRM_PROMPT:
Height: 35 Height: 35
Text: Confirm Text: Confirm
Container@CANCEL_PROMPT:
X: (WINDOW_RIGHT - WIDTH)/2
Y: (WINDOW_BOTTOM - 90)/2
Width: 370
Height: 125
Children:
Label@PROMPT_TITLE:
Width: PARENT_RIGHT
Y: 0-25
Font: BigBold
Contrast: true
Align: Center
Background@bg:
Width: 370
Height: 90
Background: panel-black
Children:
Label@PROMPT_TEXT:
Y: (PARENT_BOTTOM-HEIGHT)/2
Width: PARENT_RIGHT
Height: 25
Font: Bold
Align: Center
Button@CANCEL_BUTTON:
Key: escape
Y: 89
Width: 140
Height: 35
Text: Cancel
Container@TEXT_INPUT_PROMPT: Container@TEXT_INPUT_PROMPT:
X: (WINDOW_RIGHT - WIDTH)/2 X: (WINDOW_RIGHT - WIDTH)/2

View File

@@ -33,6 +33,33 @@ Background@CONFIRM_PROMPT:
Font: Bold Font: Bold
Key: escape Key: escape
Background@CANCEL_PROMPT:
X: (WINDOW_RIGHT - WIDTH)/2
Y: (WINDOW_BOTTOM - 90)/2
Width: 370
Height: 175
Children:
Label@PROMPT_TITLE:
Width: PARENT_RIGHT
Y: 20
Height: 25
Font: Bold
Align: Center
Label@PROMPT_TEXT:
X: 15
Y: 50
Width: PARENT_RIGHT - 30
Height: 65
Align: Center
Button@CANCEL_BUTTON:
X: PARENT_RIGHT/2 - WIDTH/2
Y: PARENT_BOTTOM - 45
Width: 160
Height: 25
Text: Cancel
Font: Bold
Key: escape
Background@TEXT_INPUT_PROMPT: Background@TEXT_INPUT_PROMPT:
X: (WINDOW_RIGHT - WIDTH)/2 X: (WINDOW_RIGHT - WIDTH)/2
Y: (WINDOW_BOTTOM - HEIGHT)/2 Y: (WINDOW_BOTTOM - HEIGHT)/2