warn before loading incompatible replays
This commit is contained in:
@@ -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)
|
||||
|
||||
55
OpenRA.Mods.Common/Widgets/Logic/ReplayUtils.cs
Normal file
55
OpenRA.Mods.Common/Widgets/Logic/ReplayUtils.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user