diff --git a/OpenRA.Mods.Cnc/Widgets/CncReplayBrowserLogic.cs b/OpenRA.Mods.Cnc/Widgets/CncReplayBrowserLogic.cs index 76b759dc53..5c596de7d9 100644 --- a/OpenRA.Mods.Cnc/Widgets/CncReplayBrowserLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/CncReplayBrowserLogic.cs @@ -35,16 +35,21 @@ namespace OpenRA.Mods.Cnc.Widgets var rl = widget.GetWidget("REPLAY_LIST"); var replayDir = Path.Combine(Platform.SupportDir, "Replays"); - var template = widget.GetWidget("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("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("DURATION").GetText = () => WidgetUtils.FormatTime(summary.Duration * 3 /* todo: 3:1 ratio isnt always true. */); - widget.GetWidget("MAP_PREVIEW").Map = () => mapStub; + widget.GetWidget("MAP_PREVIEW").Map = () => currentMap; widget.GetWidget("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("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("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); diff --git a/OpenRA.Mods.RA/Widgets/Delegates/ReplayBrowserDelegate.cs b/OpenRA.Mods.RA/Widgets/Delegates/ReplayBrowserDelegate.cs index 8a8a3cd5c7..7a5e44bdf8 100644 --- a/OpenRA.Mods.RA/Widgets/Delegates/ReplayBrowserDelegate.cs +++ b/OpenRA.Mods.RA/Widgets/Delegates/ReplayBrowserDelegate.cs @@ -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("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]; + } } } diff --git a/mods/cnc/chrome/replaybrowser.yaml b/mods/cnc/chrome/replaybrowser.yaml index c06b101238..329dcc02cc 100644 --- a/mods/cnc/chrome/replaybrowser.yaml +++ b/mods/cnc/chrome/replaybrowser.yaml @@ -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 \ No newline at end of file + Text:Back + CncMenuButton@WATCH_BUTTON: + Id:WATCH_BUTTON + X:380 + Y:299 + Width:140 + Height:35 + Text:Watch \ No newline at end of file