From 55ad12d9a398e05b1d6fa97c7afa72ee6aebfe91 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 23 Mar 2014 11:57:50 +1300 Subject: [PATCH] Show player and spawn details in the replay browser. --- .../Widgets/Logic/LobbyMapPreviewLogic.cs | 6 +- OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs | 4 +- .../Widgets/Logic/ReplayBrowserLogic.cs | 78 +++++++++-- mods/cnc/chrome/replaybrowser.yaml | 105 +++++++++------ mods/ra/chrome/replaybrowser.yaml | 127 ++++++++++-------- 5 files changed, 213 insertions(+), 107 deletions(-) diff --git a/OpenRA.Mods.RA/Widgets/Logic/LobbyMapPreviewLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/LobbyMapPreviewLogic.cs index a62cfa1b63..a7562a511d 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/LobbyMapPreviewLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/LobbyMapPreviewLogic.cs @@ -31,7 +31,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic var preview = available.Get("MAP_PREVIEW"); preview.Preview = () => lobby.Map; preview.OnMouseDown = mi => LobbyUtils.SelectSpawnPoint(orderManager, preview, lobby.Map, mi); - preview.SpawnClients = () => LobbyUtils.GetSpawnClients(orderManager, lobby.Map); + preview.SpawnClients = () => LobbyUtils.GetSpawnClients(orderManager.LobbyInfo, lobby.Map); var title = available.GetOrNull("MAP_TITLE"); if (title != null) @@ -54,7 +54,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic var preview = download.Get("MAP_PREVIEW"); preview.Preview = () => lobby.Map; preview.OnMouseDown = mi => LobbyUtils.SelectSpawnPoint(orderManager, preview, lobby.Map, mi); - preview.SpawnClients = () => LobbyUtils.GetSpawnClients(orderManager, lobby.Map); + preview.SpawnClients = () => LobbyUtils.GetSpawnClients(orderManager.LobbyInfo, lobby.Map); var title = download.GetOrNull("MAP_TITLE"); if (title != null) @@ -81,7 +81,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic var preview = progress.Get("MAP_PREVIEW"); preview.Preview = () => lobby.Map; preview.OnMouseDown = mi => LobbyUtils.SelectSpawnPoint(orderManager, preview, lobby.Map, mi); - preview.SpawnClients = () => LobbyUtils.GetSpawnClients(orderManager, lobby.Map); + preview.SpawnClients = () => LobbyUtils.GetSpawnClients(orderManager.LobbyInfo, lobby.Map); var title = progress.GetOrNull("MAP_TITLE"); if (title != null) diff --git a/OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs b/OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs index 25d32678e1..92764e834c 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs @@ -130,10 +130,10 @@ namespace OpenRA.Mods.RA.Widgets.Logic color.AttachPanel(colorChooser, onExit); } - public static Dictionary GetSpawnClients(OrderManager orderManager, MapPreview preview) + public static Dictionary GetSpawnClients(Session lobbyInfo, MapPreview preview) { var spawns = preview.SpawnPoints; - return orderManager.LobbyInfo.Clients + return lobbyInfo.Clients .Where(c => c.SpawnPoint != 0) .ToDictionary(c => spawns[c.SpawnPoint - 1], c => c); } diff --git a/OpenRA.Mods.RA/Widgets/Logic/ReplayBrowserLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/ReplayBrowserLogic.cs index 38d1c009bb..2f280ec317 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/ReplayBrowserLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/ReplayBrowserLogic.cs @@ -9,6 +9,8 @@ #endregion using System; +using System.Collections.Generic; +using System.Drawing; using System.IO; using System.Linq; using OpenRA.Network; @@ -19,10 +21,13 @@ namespace OpenRA.Mods.RA.Widgets.Logic public class ReplayBrowserLogic { Widget panel; + ScrollPanelWidget playerList; + ScrollItemWidget playerTemplate, playerHeader; + MapPreview selectedMap = MapCache.UnknownMap; + Dictionary selectedSpawns; string selectedFilename; string selectedDuration; - string selectedPlayers; bool selectedValid; [ObjectCreator.UseCtor] @@ -30,6 +35,11 @@ namespace OpenRA.Mods.RA.Widgets.Logic { panel = widget; + playerList = panel.Get("PLAYER_LIST"); + playerHeader = playerList.Get("HEADER"); + playerTemplate = playerList.Get("TEMPLATE"); + playerList.RemoveChildren(); + panel.Get("CANCEL_BUTTON").OnClick = () => { Ui.CloseWindow(); onExit(); }; var rl = panel.Get("REPLAY_LIST"); @@ -52,11 +62,21 @@ namespace OpenRA.Mods.RA.Widgets.Logic watch.IsDisabled = () => !selectedValid || selectedMap.Status != MapStatus.Available; watch.OnClick = () => { WatchReplay(); onStart(); }; - panel.Get("REPLAY_INFO").IsVisible = () => selectedFilename != null;; + panel.Get("REPLAY_INFO").IsVisible = () => selectedFilename != null; + + var preview = panel.Get("MAP_PREVIEW"); + preview.SpawnClients = () => selectedSpawns; + preview.Preview = () => selectedMap; + + var title = panel.GetOrNull("MAP_TITLE"); + if (title != null) + title.GetText = () => selectedMap.Title; + + var type = panel.GetOrNull("MAP_TYPE"); + if (type != null) + type.GetText = () => selectedMap.Type; + panel.Get("DURATION").GetText = () => selectedDuration; - panel.Get("MAP_PREVIEW").Preview = () => selectedMap; - panel.Get("MAP_TITLE").GetText = () => selectedMap.Title; - panel.Get("PLAYERS").GetText = () => selectedPlayers; } void SelectReplay(string filename) @@ -70,11 +90,53 @@ namespace OpenRA.Mods.RA.Widgets.Logic { selectedFilename = filename; selectedMap = Game.modData.MapCache[conn.LobbyInfo.GlobalSettings.Map]; + selectedSpawns = LobbyUtils.GetSpawnClients(conn.LobbyInfo, selectedMap); selectedDuration = WidgetUtils.FormatTime(conn.TickCount * Game.NetTickScale); - selectedPlayers = conn.LobbyInfo.Slots - .Count(s => conn.LobbyInfo.ClientInSlot(s.Key) != null) - .ToString(); selectedValid = conn.TickCount > 0; + + var clients = conn.LobbyInfo.Clients.Where(c => c.Slot != null) + .GroupBy(c => c.Team) + .OrderBy(g => g.Key); + + var teams = new Dictionary>(); + var noTeams = clients.Count() == 1; + foreach (var c in clients) + { + var label = noTeams ? "Players" : c.Key == 0 ? "No Team" : "Team {0}".F(c.Key); + teams.Add(label, c); + } + + playerList.RemoveChildren(); + + foreach (var kv in teams) + { + var group = kv.Key; + if (group.Length > 0) + { + var header = ScrollItemWidget.Setup(playerHeader, () => true, () => {}); + header.Get("LABEL").GetText = () => group; + playerList.AddChild(header); + } + + foreach (var option in kv.Value) + { + var o = option; + + var color = o.Color.RGB; + + var item = ScrollItemWidget.Setup(playerTemplate, () => false, () => { }); + + var label = item.Get("LABEL"); + label.GetText = () => o.Name; + label.GetColor = () => color; + + var flag = item.Get("FLAG"); + flag.GetImageCollection = () => "flags"; + flag.GetImageName = () => o.Country; + + playerList.AddChild(item); + } + } } } catch (Exception e) diff --git a/mods/cnc/chrome/replaybrowser.yaml b/mods/cnc/chrome/replaybrowser.yaml index af682d649c..b06c6e2b3d 100644 --- a/mods/cnc/chrome/replaybrowser.yaml +++ b/mods/cnc/chrome/replaybrowser.yaml @@ -1,9 +1,9 @@ Container@REPLAYBROWSER_PANEL: Logic:ReplayBrowserLogic X:(WINDOW_RIGHT - WIDTH)/2 - Y:(WINDOW_BOTTOM - 300)/2 + Y:(WINDOW_BOTTOM - 500)/2 Width:520 - Height:335 + Height:535 Children: Label@TITLE: Width:520 @@ -14,14 +14,14 @@ Container@REPLAYBROWSER_PANEL: Text:Replay Viewer Background@bg: Width:520 - Height:300 + Height:500 Background:panel-black Children: ScrollPanel@REPLAY_LIST: X:15 Y:15 - Width:286 - Height:270 + Width:282 + Height:PARENT_BOTTOM-30 Children: ScrollItem@REPLAY_TEMPLATE: Width:PARENT_RIGHT-27 @@ -46,58 +46,81 @@ Container@REPLAYBROWSER_PANEL: Y:1 Width:192 Height:192 + TooltipContainer:TOOLTIP_CONTAINER Container@REPLAY_INFO: X:PARENT_RIGHT-WIDTH-15 - Y:219 + Y:15 Width:194 - Height:56 - Visible:false + Height:PARENT_BOTTOM - 15 Children: - Label@MAP_TITLE_LABEL: - Align:Right - Width:70 - Height:20 - Text:Map: - Font:Bold Label@MAP_TITLE: - X:75 - Width:70 - Height:20 - Label@DURATION_LABEL: - Y:20 - Align:Right - Width:70 - Height:20 - Text:Duration: + Y:197 + Width:PARENT_RIGHT + Height:25 Font:Bold + Align:Center + Label@MAP_TYPE: + Y:212 + Width:PARENT_RIGHT + Height:25 + Font:TinyBold + Align:Center Label@DURATION: - X:75 - Y:20 - Width:70 - Height:20 - Label@PLAYERS_LABEL: - Y:40 - Align:Right - Width:70 - Height:20 - Text:Players: - Font:Bold - Label@PLAYERS: - X:75 - Y:40 - Width:70 - Height:20 + Y:225 + Width:PARENT_RIGHT + Height:25 + Font:Tiny + Align:Center + ScrollPanel@PLAYER_LIST: + Y:250 + Width:PARENT_RIGHT + Height:PARENT_BOTTOM - 250 - 15 + IgnoreChildMouseOver:true + Children: + ScrollItem@HEADER: + Width:PARENT_RIGHT-27 + Height:13 + X:2 + Y:0 + Visible:false + Children: + Label@LABEL: + Font:TinyBold + Width:PARENT_RIGHT + Height:10 + Align:Center + ScrollItem@TEMPLATE: + Width:PARENT_RIGHT-27 + Height:25 + X:2 + Y:0 + Visible:false + Children: + Image@FLAG: + X:4 + Y:4 + Width:32 + Height:16 + Label@LABEL: + X:40 + Width:60 + Height:25 + Label@NOFLAG_LABEL: + X:5 + Width:PARENT_RIGHT + Height:25 Button@CANCEL_BUTTON: Key:escape X:0 - Y:299 + Y:499 Width:140 Height:35 Text:Back Button@WATCH_BUTTON: Key:return X:380 - Y:299 + Y:499 Width:140 Height:35 Text:Watch + TooltipContainer@TOOLTIP_CONTAINER: diff --git a/mods/ra/chrome/replaybrowser.yaml b/mods/ra/chrome/replaybrowser.yaml index c2805a4091..085bf4d8ec 100644 --- a/mods/ra/chrome/replaybrowser.yaml +++ b/mods/ra/chrome/replaybrowser.yaml @@ -2,11 +2,10 @@ Background@REPLAYBROWSER_PANEL: Logic:ReplayBrowserLogic X:(WINDOW_RIGHT - WIDTH)/2 Y:(WINDOW_BOTTOM - HEIGHT)/2 - Width:700 - Height:410 + Width:530 + Height:535 Children: Label@REPLAYBROWSER_LABEL_TITLE: - X:0 Y:20 Width:PARENT_RIGHT Height:25 @@ -16,74 +15,95 @@ Background@REPLAYBROWSER_PANEL: ScrollPanel@REPLAY_LIST: X:20 Y:50 - Width:390 - Height:300 + Width:282 + Height:430 Children: ScrollItem@REPLAY_TEMPLATE: Width:PARENT_RIGHT-27 Height:25 X:2 - Y:0 Visible:false Children: Label@TITLE: X:10 Width:PARENT_RIGHT-20 Height:25 - Container@REPLAY_INFO: - X:0 - Y:0 - Width:PARENT_RIGHT - Height:PARENT_BOTTOM - Visible:false + Background@MAP_BG: + X:PARENT_RIGHT-WIDTH-20 + Y:50 + Width:194 + Height:194 + Background:dialog3 Children: MapPreview@MAP_PREVIEW: - X:PARENT_RIGHT-241 - Y:30 + X:1 + Y:1 Width:192 Height:192 - Label@MAP_TITLE_LABEL: - X:PARENT_RIGHT - 200 - WIDTH - Y:250 - Align:Right - Width:70 - Height:20 - Text:Map: - Font:Bold + TooltipContainer:TOOLTIP_CONTAINER + Container@REPLAY_INFO: + X:PARENT_RIGHT-WIDTH - 20 + Y:50 + Width:194 + Height:PARENT_BOTTOM - 15 + Children: Label@MAP_TITLE: - X:PARENT_RIGHT - 195 - Y:250 - Align:Left - Width:70 - Height:20 - Label@DURATION_LABEL: - X:PARENT_RIGHT - 200 - WIDTH - Y:270 - Align:Right - Width:70 - Height:20 - Text:Duration: + Y:197 + Width:PARENT_RIGHT + Height:25 Font:Bold + Align:Center + Label@MAP_TYPE: + Y:212 + Width:PARENT_RIGHT + Height:25 + Font:TinyBold + Align:Center Label@DURATION: - X:PARENT_RIGHT - 195 - Y:270 - Align:Left - Width:70 - Height:20 - Label@PLAYERS_LABEL: - X:PARENT_RIGHT - 200 - WIDTH - Y:290 - Align:Right - Width:70 - Height:20 - Text:Players: - Font:Bold - Label@PLAYERS: - X:PARENT_RIGHT - 195 - Y:290 - Align:Left - Width:70 - Height:20 + Y:225 + Width:PARENT_RIGHT + Height:25 + Font:Tiny + Align:Center + ScrollPanel@PLAYER_LIST: + Y:250 + Width:PARENT_RIGHT + Height:PARENT_BOTTOM - 340 + IgnoreChildMouseOver:true + Children: + ScrollItem@HEADER: + BaseName:scrollheader + Width:PARENT_RIGHT-27 + Height:13 + X:2 + Y:0 + Visible:false + Children: + Label@LABEL: + Font:TinyBold + Width:PARENT_RIGHT + Height:10 + Align:Center + ScrollItem@TEMPLATE: + Width:PARENT_RIGHT-27 + Height:25 + X:2 + Y:0 + Visible:false + Children: + Image@FLAG: + X:4 + Y:4 + Width:32 + Height:16 + Label@LABEL: + X:40 + Width:60 + Height:25 + Label@NOFLAG_LABEL: + X:5 + Width:PARENT_RIGHT + Height:25 Button@WATCH_BUTTON: X:PARENT_RIGHT - 140 - 130 Y:PARENT_BOTTOM - 45 @@ -100,3 +120,4 @@ Background@REPLAYBROWSER_PANEL: Text:Cancel Font:Bold Key:escape + TooltipContainer@TOOLTIP_CONTAINER: