Improved replay browser
This commit is contained in:
@@ -35,16 +35,21 @@ namespace OpenRA.Mods.Cnc.Widgets
|
|||||||
var rl = widget.GetWidget<ScrollPanelWidget>("REPLAY_LIST");
|
var rl = widget.GetWidget<ScrollPanelWidget>("REPLAY_LIST");
|
||||||
var replayDir = Path.Combine(Platform.SupportDir, "Replays");
|
var replayDir = Path.Combine(Platform.SupportDir, "Replays");
|
||||||
|
|
||||||
var template = widget.GetWidget<LabelWidget>("REPLAY_TEMPLATE");
|
var template = widget.GetWidget("REPLAY_TEMPLATE");
|
||||||
CurrentReplay = null;
|
CurrentReplay = null;
|
||||||
|
|
||||||
rl.RemoveChildren();
|
rl.RemoveChildren();
|
||||||
if (Directory.Exists(replayDir))
|
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);
|
AddReplay(rl, replayFile, template);
|
||||||
|
|
||||||
|
CurrentReplay = files.FirstOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
var watch = widget.GetWidget<CncMenuButtonWidget>("WATCH_BUTTON");
|
var watch = widget.GetWidget<CncMenuButtonWidget>("WATCH_BUTTON");
|
||||||
watch.IsDisabled = () => currentReplay == null;
|
watch.IsDisabled = () => currentReplay == null || currentMap == null;
|
||||||
watch.OnClick = () =>
|
watch.OnClick = () =>
|
||||||
{
|
{
|
||||||
if (currentReplay != null)
|
if (currentReplay != null)
|
||||||
@@ -57,19 +62,8 @@ namespace OpenRA.Mods.Cnc.Widgets
|
|||||||
widget.GetWidget("REPLAY_INFO").IsVisible = () => currentReplay != null;
|
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 = null;
|
||||||
|
Map currentMap = null;
|
||||||
string CurrentReplay
|
string CurrentReplay
|
||||||
{
|
{
|
||||||
get { return currentReplay; }
|
get { return currentReplay; }
|
||||||
@@ -81,29 +75,33 @@ namespace OpenRA.Mods.Cnc.Widgets
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var summary = new ReplaySummary(currentReplay);
|
var summary = new ReplaySummary(currentReplay);
|
||||||
var mapStub = MapFromSummary(summary);
|
currentMap = summary.Map();
|
||||||
|
|
||||||
widget.GetWidget<LabelWidget>("DURATION").GetText =
|
widget.GetWidget<LabelWidget>("DURATION").GetText =
|
||||||
() => WidgetUtils.FormatTime(summary.Duration * 3 /* todo: 3:1 ratio isnt always true. */);
|
() => 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 =
|
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)
|
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;
|
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;
|
var entry = template.Clone() as ContainerWidget;
|
||||||
entry.Id = "REPLAY_";
|
var f = Path.GetFileName(filename);
|
||||||
entry.GetText = () => " {0}".F(Path.GetFileName(filename));
|
entry.GetWidget<LabelWidget>("TITLE").GetText = () => f;
|
||||||
entry.GetBackground = () => (CurrentReplay == filename) ? "dialog2" : null;
|
entry.GetBackground = () => (CurrentReplay == filename) ? "panel-darkred" : 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; CurrentReplay = filename; return true; };
|
||||||
entry.IsVisible = () => true;
|
entry.IsVisible = () => true;
|
||||||
list.AddChild(entry);
|
list.AddChild(entry);
|
||||||
|
|||||||
@@ -58,18 +58,6 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
|
|||||||
widget.GetWidget("REPLAY_INFO").IsVisible = () => currentReplay != null;
|
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 = null;
|
||||||
string CurrentReplay
|
string CurrentReplay
|
||||||
{
|
{
|
||||||
@@ -82,7 +70,7 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var summary = new ReplaySummary(currentReplay);
|
var summary = new ReplaySummary(currentReplay);
|
||||||
var mapStub = MapFromSummary(summary);
|
var mapStub = summary.Map();
|
||||||
|
|
||||||
widget.GetWidget<LabelWidget>("DURATION").GetText =
|
widget.GetWidget<LabelWidget>("DURATION").GetText =
|
||||||
() => WidgetUtils.FormatTime(summary.Duration * 3 /* todo: 3:1 ratio isnt always true. */);
|
() => WidgetUtils.FormatTime(summary.Duration * 3 /* todo: 3:1 ratio isnt always true. */);
|
||||||
@@ -147,5 +135,17 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
|
|||||||
Duration = lastFrame;
|
Duration = lastFrame;
|
||||||
LobbyInfo = lobbyInfo;
|
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];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,52 +2,64 @@ Container@REPLAYBROWSER_PANEL:
|
|||||||
Id:REPLAYBROWSER_PANEL
|
Id:REPLAYBROWSER_PANEL
|
||||||
Delegate:CncReplayBrowserLogic
|
Delegate:CncReplayBrowserLogic
|
||||||
X:(WINDOW_RIGHT - WIDTH)/2
|
X:(WINDOW_RIGHT - WIDTH)/2
|
||||||
Y:(WINDOW_BOTTOM - 500)/2
|
Y:(WINDOW_BOTTOM - 300)/2
|
||||||
Width:740
|
Width:520
|
||||||
Height:535
|
Height:335
|
||||||
Children:
|
Children:
|
||||||
Label@TITLE:
|
Label@TITLE:
|
||||||
Width:740
|
Width:520
|
||||||
Y:0-25
|
Y:0-25
|
||||||
Font:BigBold
|
Font:BigBold
|
||||||
Contrast:true
|
Contrast:true
|
||||||
Align:Center
|
Align:Center
|
||||||
Text:Replay Viewer
|
Text:Replay Viewer
|
||||||
Background@bg:
|
Background@bg:
|
||||||
Width:740
|
Width:520
|
||||||
Height:500
|
Height:300
|
||||||
Background:panel-black
|
Background:panel-black
|
||||||
Children:
|
Children:
|
||||||
CncScrollPanel@REPLAY_LIST:
|
CncScrollPanel@REPLAY_LIST:
|
||||||
Id:REPLAY_LIST
|
Id:REPLAY_LIST
|
||||||
X:15
|
X:15
|
||||||
Y:50
|
Y:15
|
||||||
Width:390
|
Width:286
|
||||||
Height:300
|
Height:270
|
||||||
Children:
|
Children:
|
||||||
Label@REPLAY_TEMPLATE:
|
Container@REPLAY_TEMPLATE:
|
||||||
Id:REPLAY_TEMPLATE
|
Id:REPLAY_TEMPLATE
|
||||||
Width:PARENT_RIGHT-28
|
Width:PARENT_RIGHT-27
|
||||||
Height:25
|
Height:25
|
||||||
X:2
|
X:2
|
||||||
Y:0
|
Y:0
|
||||||
Visible:false
|
Visible:false
|
||||||
Container@REPLAY_INFO:
|
Children:
|
||||||
Id:REPLAY_INFO
|
Label@TITLE:
|
||||||
Width:PARENT_RIGHT
|
X:10
|
||||||
Height:PARENT_BOTTOM
|
Id:TITLE
|
||||||
Visible:false
|
Width:PARENT_RIGHT-20
|
||||||
|
Height:25
|
||||||
|
Background@MAP_BG:
|
||||||
|
X:PARENT_RIGHT-WIDTH-15
|
||||||
|
Y:15
|
||||||
|
Width:194
|
||||||
|
Height:194
|
||||||
|
Background:panel-gray
|
||||||
Children:
|
Children:
|
||||||
MapPreview@MAP_PREVIEW:
|
MapPreview@MAP_PREVIEW:
|
||||||
Id:MAP_PREVIEW
|
Id:MAP_PREVIEW
|
||||||
X:PARENT_RIGHT-241
|
X:1
|
||||||
Y:30
|
Y:1
|
||||||
Width:192
|
Width:192
|
||||||
Height: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:
|
Label@MAP_TITLE_LABEL:
|
||||||
Id:MAP_TITLE_LABEL
|
|
||||||
X:PARENT_RIGHT - 200 - WIDTH
|
|
||||||
Y:250
|
|
||||||
Align:Right
|
Align:Right
|
||||||
Width:70
|
Width:70
|
||||||
Height:20
|
Height:20
|
||||||
@@ -55,15 +67,11 @@ Container@REPLAYBROWSER_PANEL:
|
|||||||
Bold:True
|
Bold:True
|
||||||
Label@MAP_TITLE:
|
Label@MAP_TITLE:
|
||||||
Id:MAP_TITLE
|
Id:MAP_TITLE
|
||||||
X:PARENT_RIGHT - 195
|
X:75
|
||||||
Y:250
|
|
||||||
Align:Left
|
|
||||||
Width:70
|
Width:70
|
||||||
Height:20
|
Height:20
|
||||||
Label@DURATION_LABEL:
|
Label@DURATION_LABEL:
|
||||||
Id:DURATION_LABEL
|
Y:20
|
||||||
X:PARENT_RIGHT - 200 - WIDTH
|
|
||||||
Y:270
|
|
||||||
Align:Right
|
Align:Right
|
||||||
Width:70
|
Width:70
|
||||||
Height:20
|
Height:20
|
||||||
@@ -71,22 +79,34 @@ Container@REPLAYBROWSER_PANEL:
|
|||||||
Bold:True
|
Bold:True
|
||||||
Label@DURATION:
|
Label@DURATION:
|
||||||
Id:DURATION
|
Id:DURATION
|
||||||
X:PARENT_RIGHT - 195
|
X:75
|
||||||
Y:270
|
Y:20
|
||||||
Align:Left
|
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
|
Width:70
|
||||||
Height:20
|
Height:20
|
||||||
CncMenuButton@WATCH_BUTTON:
|
|
||||||
Id:WATCH_BUTTON
|
|
||||||
X:0
|
|
||||||
Y:499
|
|
||||||
Width:140
|
|
||||||
Height:35
|
|
||||||
Text:Watch
|
|
||||||
CncMenuButton@CANCEL_BUTTON:
|
CncMenuButton@CANCEL_BUTTON:
|
||||||
Id:CANCEL_BUTTON
|
Id:CANCEL_BUTTON
|
||||||
X:600
|
X:0
|
||||||
Y:499
|
Y:299
|
||||||
Width:140
|
Width:140
|
||||||
Height:35
|
Height:35
|
||||||
Text:Back
|
Text:Back
|
||||||
|
CncMenuButton@WATCH_BUTTON:
|
||||||
|
Id:WATCH_BUTTON
|
||||||
|
X:380
|
||||||
|
Y:299
|
||||||
|
Width:140
|
||||||
|
Height:35
|
||||||
|
Text:Watch
|
||||||
Reference in New Issue
Block a user