Improved replay browser

This commit is contained in:
Paul Chote
2011-05-08 11:11:15 +12:00
parent 14a904ab7a
commit c9dd1aa4bd
3 changed files with 94 additions and 76 deletions

View File

@@ -35,16 +35,21 @@ namespace OpenRA.Mods.Cnc.Widgets
var rl = widget.GetWidget<ScrollPanelWidget>("REPLAY_LIST");
var replayDir = Path.Combine(Platform.SupportDir, "Replays");
var template = widget.GetWidget<LabelWidget>("REPLAY_TEMPLATE");
var template = widget.GetWidget("REPLAY_TEMPLATE");
CurrentReplay = null;
rl.RemoveChildren();
if (Directory.Exists(replayDir))
foreach (var replayFile in Directory.GetFiles(replayDir, "*.rep").Reverse())
{
var files = Directory.GetFiles(replayDir, "*.rep").Reverse();
foreach (var replayFile in files)
AddReplay(rl, replayFile, template);
CurrentReplay = files.FirstOrDefault();
}
var watch = widget.GetWidget<CncMenuButtonWidget>("WATCH_BUTTON");
watch.IsDisabled = () => currentReplay == null;
watch.IsDisabled = () => currentReplay == null || currentMap == null;
watch.OnClick = () =>
{
if (currentReplay != null)
@@ -57,19 +62,8 @@ namespace OpenRA.Mods.Cnc.Widgets
widget.GetWidget("REPLAY_INFO").IsVisible = () => currentReplay != null;
}
Map MapFromSummary(ReplaySummary rs)
{
if (rs.LobbyInfo == null)
return null;
var map = rs.LobbyInfo.GlobalSettings.Map;
if (!Game.modData.AvailableMaps.ContainsKey(map))
return null;
return Game.modData.AvailableMaps[map];
}
string currentReplay = null;
Map currentMap = null;
string CurrentReplay
{
get { return currentReplay; }
@@ -81,29 +75,33 @@ namespace OpenRA.Mods.Cnc.Widgets
try
{
var summary = new ReplaySummary(currentReplay);
var mapStub = MapFromSummary(summary);
currentMap = 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<MapPreviewWidget>("MAP_PREVIEW").Map = () => currentMap;
widget.GetWidget<LabelWidget>("MAP_TITLE").GetText =
() => mapStub != null ? mapStub.Title : "(Unknown Map)";
() => currentMap != null ? currentMap.Title : "(Unknown Map)";
var players = summary.LobbyInfo.Slots.Count(s => summary.LobbyInfo.ClientInSlot(s) != null || s.Bot != null);
widget.GetWidget<LabelWidget>("PLAYERS").GetText = () => players.ToString();
}
catch(Exception e)
{
Log.Write("debug", "Exception while parsing replay: {0}", e.ToString());
currentReplay = null;
currentMap = null;
}
}
}
}
void AddReplay(ScrollPanelWidget list, string filename, LabelWidget template)
void AddReplay(ScrollPanelWidget list, string filename, Widget template)
{
var entry = template.Clone() as LabelWidget;
entry.Id = "REPLAY_";
entry.GetText = () => " {0}".F(Path.GetFileName(filename));
entry.GetBackground = () => (CurrentReplay == filename) ? "dialog2" : null;
var entry = template.Clone() as ContainerWidget;
var f = Path.GetFileName(filename);
entry.GetWidget<LabelWidget>("TITLE").GetText = () => f;
entry.GetBackground = () => (CurrentReplay == filename) ? "panel-darkred" : null;
entry.OnMouseDown = mi => { if (mi.Button != MouseButton.Left) return false; CurrentReplay = filename; return true; };
entry.IsVisible = () => true;
list.AddChild(entry);

View File

@@ -58,18 +58,6 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
widget.GetWidget("REPLAY_INFO").IsVisible = () => currentReplay != null;
}
Map MapFromSummary(ReplaySummary rs)
{
if (rs.LobbyInfo == null)
return null;
var map = rs.LobbyInfo.GlobalSettings.Map;
if (!Game.modData.AvailableMaps.ContainsKey(map))
return null;
return Game.modData.AvailableMaps[map];
}
string currentReplay = null;
string CurrentReplay
{
@@ -82,7 +70,7 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
try
{
var summary = new ReplaySummary(currentReplay);
var mapStub = MapFromSummary(summary);
var mapStub = summary.Map();
widget.GetWidget<LabelWidget>("DURATION").GetText =
() => WidgetUtils.FormatTime(summary.Duration * 3 /* todo: 3:1 ratio isnt always true. */);
@@ -147,5 +135,17 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
Duration = lastFrame;
LobbyInfo = lobbyInfo;
}
public Map Map()
{
if (LobbyInfo == null)
return null;
var map = LobbyInfo.GlobalSettings.Map;
if (!Game.modData.AvailableMaps.ContainsKey(map))
return null;
return Game.modData.AvailableMaps[map];
}
}
}

View File

@@ -2,52 +2,64 @@ Container@REPLAYBROWSER_PANEL:
Id:REPLAYBROWSER_PANEL
Delegate:CncReplayBrowserLogic
X:(WINDOW_RIGHT - WIDTH)/2
Y:(WINDOW_BOTTOM - 500)/2
Width:740
Height:535
Y:(WINDOW_BOTTOM - 300)/2
Width:520
Height:335
Children:
Label@TITLE:
Width:740
Width:520
Y:0-25
Font:BigBold
Contrast:true
Align:Center
Text:Replay Viewer
Background@bg:
Width:740
Height:500
Width:520
Height:300
Background:panel-black
Children:
CncScrollPanel@REPLAY_LIST:
Id:REPLAY_LIST
X:15
Y:50
Width:390
Height:300
Y:15
Width:286
Height:270
Children:
Label@REPLAY_TEMPLATE:
Container@REPLAY_TEMPLATE:
Id:REPLAY_TEMPLATE
Width:PARENT_RIGHT-28
Width:PARENT_RIGHT-27
Height:25
X:2
Y:0
Visible:false
Container@REPLAY_INFO:
Id:REPLAY_INFO
Width:PARENT_RIGHT
Height:PARENT_BOTTOM
Visible:false
Children:
Label@TITLE:
X:10
Id:TITLE
Width:PARENT_RIGHT-20
Height:25
Background@MAP_BG:
X:PARENT_RIGHT-WIDTH-15
Y:15
Width:194
Height:194
Background:panel-gray
Children:
MapPreview@MAP_PREVIEW:
Id:MAP_PREVIEW
X:PARENT_RIGHT-241
Y:30
X:1
Y:1
Width:192
Height:192
Container@REPLAY_INFO:
Id:REPLAY_INFO
X:PARENT_RIGHT-WIDTH-15
Y:219
Width:194
Height:56
Visible:false
Children:
Label@MAP_TITLE_LABEL:
Id:MAP_TITLE_LABEL
X:PARENT_RIGHT - 200 - WIDTH
Y:250
Align:Right
Width:70
Height:20
@@ -55,15 +67,11 @@ Container@REPLAYBROWSER_PANEL:
Bold:True
Label@MAP_TITLE:
Id:MAP_TITLE
X:PARENT_RIGHT - 195
Y:250
Align:Left
X:75
Width:70
Height:20
Label@DURATION_LABEL:
Id:DURATION_LABEL
X:PARENT_RIGHT - 200 - WIDTH
Y:270
Y:20
Align:Right
Width:70
Height:20
@@ -71,22 +79,34 @@ Container@REPLAYBROWSER_PANEL:
Bold:True
Label@DURATION:
Id:DURATION
X:PARENT_RIGHT - 195
Y:270
Align:Left
X:75
Y:20
Width:70
Height:20
Label@PLAYERS_LABEL:
Y:40
Align:Right
Width:70
Height:20
Text:Players:
Bold:True
Label@PLAYERS:
Id:PLAYERS
X:75
Y:40
Width:70
Height:20
CncMenuButton@WATCH_BUTTON:
Id:WATCH_BUTTON
X:0
Y:499
Width:140
Height:35
Text:Watch
CncMenuButton@CANCEL_BUTTON:
Id:CANCEL_BUTTON
X:600
Y:499
X:0
Y:299
Width:140
Height:35
Text:Back
Text:Back
CncMenuButton@WATCH_BUTTON:
Id:WATCH_BUTTON
X:380
Y:299
Width:140
Height:35
Text:Watch