get RA replay browser closer to CNC version

This commit is contained in:
Chris Forbes
2011-10-19 20:04:05 +13:00
parent f5c4a94f93
commit 808464f4d5

View File

@@ -32,7 +32,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
var replayDir = Path.Combine(Platform.SupportDir, "Replays"); var replayDir = Path.Combine(Platform.SupportDir, "Replays");
var template = widget.GetWidget<ScrollItemWidget>("REPLAY_TEMPLATE"); var template = widget.GetWidget<ScrollItemWidget>("REPLAY_TEMPLATE");
CurrentReplay = null; SelectReplay(null);
rl.RemoveChildren(); rl.RemoveChildren();
if (Directory.Exists(replayDir)) if (Directory.Exists(replayDir))
@@ -44,38 +44,36 @@ namespace OpenRA.Mods.RA.Widgets.Logic
if (currentReplay != null) if (currentReplay != null)
{ {
Widget.CloseWindow(); Widget.CloseWindow();
Game.JoinReplay(CurrentReplay); Game.JoinReplay(currentReplay);
} }
}; };
widget.GetWidget("REPLAY_INFO").IsVisible = () => currentReplay != null; widget.GetWidget("REPLAY_INFO").IsVisible = () => currentReplay != null;
} }
string currentReplay = null; string currentReplay;
string CurrentReplay
{
get { return currentReplay; }
set
{
currentReplay = value;
if (currentReplay != null)
{
try
{
var summary = new Replay(currentReplay);
var mapStub = summary.Map();
widget.GetWidget<LabelWidget>("DURATION").GetText = void SelectReplay(string filename)
() => WidgetUtils.FormatTime(summary.Duration * 3 /* todo: 3:1 ratio isnt always true. */); {
widget.GetWidget<MapPreviewWidget>("MAP_PREVIEW").Map = () => mapStub; currentReplay = filename;
widget.GetWidget<LabelWidget>("MAP_TITLE").GetText =
() => mapStub != null ? mapStub.Title : "(Unknown Map)"; if (currentReplay != null)
} {
catch(Exception e) try
{ {
Log.Write("debug", "Exception while parsing replay: {0}", e); var summary = new Replay(currentReplay);
currentReplay = null; var mapStub = summary.Map();
}
widget.GetWidget<LabelWidget>("DURATION").GetText =
() => WidgetUtils.FormatTime(summary.Duration * 3 /* todo: 3:1 ratio isnt always true. */);
widget.GetWidget<MapPreviewWidget>("MAP_PREVIEW").Map = () => mapStub;
widget.GetWidget<LabelWidget>("MAP_TITLE").GetText =
() => mapStub != null ? mapStub.Title : "(Unknown Map)";
}
catch(Exception e)
{
Log.Write("debug", "Exception while parsing replay: {0}", e);
currentReplay = null;
} }
} }
} }
@@ -83,8 +81,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic
void AddReplay(ScrollPanelWidget list, string filename, ScrollItemWidget template) void AddReplay(ScrollPanelWidget list, string filename, ScrollItemWidget template)
{ {
var item = ScrollItemWidget.Setup(template, var item = ScrollItemWidget.Setup(template,
() => CurrentReplay == filename, () => currentReplay == filename,
() => CurrentReplay = filename); () => SelectReplay(filename));
var f = Path.GetFileName(filename); var f = Path.GetFileName(filename);
item.GetWidget<LabelWidget>("TITLE").GetText = () => f; item.GetWidget<LabelWidget>("TITLE").GetText = () => f;
list.AddChild(item); list.AddChild(item);