Disallow watching replays with zero duration.

This commit is contained in:
Paul Chote
2011-05-10 18:31:24 +12:00
parent 814845730f
commit ab28f5867f
2 changed files with 32 additions and 36 deletions

View File

@@ -37,7 +37,6 @@ namespace OpenRA.Mods.Cnc.Widgets
var replayDir = Path.Combine(Platform.SupportDir, "Replays"); var replayDir = Path.Combine(Platform.SupportDir, "Replays");
var template = panel.GetWidget("REPLAY_TEMPLATE"); var template = panel.GetWidget("REPLAY_TEMPLATE");
CurrentReplay = null;
rl.RemoveChildren(); rl.RemoveChildren();
if (Directory.Exists(replayDir)) if (Directory.Exists(replayDir))
@@ -46,54 +45,49 @@ namespace OpenRA.Mods.Cnc.Widgets
foreach (var replayFile in files) foreach (var replayFile in files)
AddReplay(rl, replayFile, template); AddReplay(rl, replayFile, template);
CurrentReplay = files.FirstOrDefault(); SelectReplay(files.FirstOrDefault());
} }
var watch = panel.GetWidget<CncMenuButtonWidget>("WATCH_BUTTON"); var watch = panel.GetWidget<CncMenuButtonWidget>("WATCH_BUTTON");
watch.IsDisabled = () => currentReplay == null || currentMap == null; watch.IsDisabled = () => currentSummary == null || currentMap == null || currentSummary.Duration == 0;
watch.OnClick = () => watch.OnClick = () =>
{ {
if (currentReplay != null) if (currentSummary != null)
{ {
Game.JoinReplay(CurrentReplay); Game.JoinReplay(currentSummary.Filename);
onStart(); onStart();
} }
}; };
panel.GetWidget("REPLAY_INFO").IsVisible = () => currentReplay != null; panel.GetWidget("REPLAY_INFO").IsVisible = () => currentSummary != null;
} }
string currentReplay = null; ReplaySummary currentSummary;
Map currentMap = null; Map currentMap;
string CurrentReplay void SelectReplay(string filename)
{ {
get { return currentReplay; } if (filename == null)
set return;
try
{ {
currentReplay = value; currentSummary = new ReplaySummary(filename);
if (currentReplay != null) currentMap = currentSummary.Map();
{
try
{
var summary = new ReplaySummary(currentReplay);
currentMap = summary.Map();
panel.GetWidget<LabelWidget>("DURATION").GetText = panel.GetWidget<LabelWidget>("DURATION").GetText =
() => WidgetUtils.FormatTime(summary.Duration * 3 /* todo: 3:1 ratio isnt always true. */); () => WidgetUtils.FormatTime(currentSummary.Duration * 3 /* todo: 3:1 ratio isnt always true. */);
panel.GetWidget<MapPreviewWidget>("MAP_PREVIEW").Map = () => currentMap; panel.GetWidget<MapPreviewWidget>("MAP_PREVIEW").Map = () => currentMap;
panel.GetWidget<LabelWidget>("MAP_TITLE").GetText = panel.GetWidget<LabelWidget>("MAP_TITLE").GetText =
() => currentMap != null ? currentMap.Title : "(Unknown Map)"; () => currentMap != null ? currentMap.Title : "(Unknown Map)";
var players = summary.LobbyInfo.Slots.Count(s => summary.LobbyInfo.ClientInSlot(s) != null || s.Bot != null); var players = currentSummary.LobbyInfo.Slots.Count(s => currentSummary.LobbyInfo.ClientInSlot(s) != null || s.Bot != null);
panel.GetWidget<LabelWidget>("PLAYERS").GetText = () => players.ToString(); panel.GetWidget<LabelWidget>("PLAYERS").GetText = () => players.ToString();
} }
catch(Exception e) catch(Exception e)
{ {
Log.Write("debug", "Exception while parsing replay: {0}", e.ToString()); Log.Write("debug", "Exception while parsing replay: {0}", e.ToString());
currentReplay = null; currentSummary = null;
currentMap = null; currentMap = null;
}
}
} }
} }
@@ -102,8 +96,8 @@ namespace OpenRA.Mods.Cnc.Widgets
var entry = template.Clone() as ContainerWidget; var entry = template.Clone() as ContainerWidget;
var f = Path.GetFileName(filename); var f = Path.GetFileName(filename);
entry.GetWidget<LabelWidget>("TITLE").GetText = () => f; entry.GetWidget<LabelWidget>("TITLE").GetText = () => f;
entry.GetBackground = () => (entry.RenderBounds.Contains(Viewport.LastMousePos) ? "button-hover" : (CurrentReplay == filename) ? "button-pressed" : null); entry.GetBackground = () => (entry.RenderBounds.Contains(Viewport.LastMousePos) ? "button-hover" : (currentSummary != null && currentSummary.Filename == filename) ? "button-pressed" : null);
entry.OnMouseDown = mi => { if (mi.Button != MouseButton.Left) return false; CurrentReplay = filename; return true; }; entry.OnMouseDown = mi => { if (mi.Button != MouseButton.Left) return false; SelectReplay(filename); return true; };
entry.IsVisible = () => true; entry.IsVisible = () => true;
list.AddChild(entry); list.AddChild(entry);
} }

View File

@@ -102,11 +102,13 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
/* a maze of twisty little hacks,... */ /* a maze of twisty little hacks,... */
public class ReplaySummary public class ReplaySummary
{ {
public readonly string Filename;
public readonly int Duration; public readonly int Duration;
public readonly Session LobbyInfo; public readonly Session LobbyInfo;
public ReplaySummary(string filename) public ReplaySummary(string filename)
{ {
Filename = filename;
var lastFrame = 0; var lastFrame = 0;
var hasSeenGameStart = false; var hasSeenGameStart = false;
var lobbyInfo = null as Session; var lobbyInfo = null as Session;