Show player and spawn details in the replay browser.

This commit is contained in:
Paul Chote
2014-03-23 11:57:50 +13:00
parent 272e872357
commit 55ad12d9a3
5 changed files with 213 additions and 107 deletions

View File

@@ -31,7 +31,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
var preview = available.Get<MapPreviewWidget>("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<LabelWidget>("MAP_TITLE");
if (title != null)
@@ -54,7 +54,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
var preview = download.Get<MapPreviewWidget>("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<LabelWidget>("MAP_TITLE");
if (title != null)
@@ -81,7 +81,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
var preview = progress.Get<MapPreviewWidget>("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<LabelWidget>("MAP_TITLE");
if (title != null)

View File

@@ -130,10 +130,10 @@ namespace OpenRA.Mods.RA.Widgets.Logic
color.AttachPanel(colorChooser, onExit);
}
public static Dictionary<CPos, Session.Client> GetSpawnClients(OrderManager orderManager, MapPreview preview)
public static Dictionary<CPos, Session.Client> 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);
}

View File

@@ -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<CPos, Session.Client> 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<ScrollPanelWidget>("PLAYER_LIST");
playerHeader = playerList.Get<ScrollItemWidget>("HEADER");
playerTemplate = playerList.Get<ScrollItemWidget>("TEMPLATE");
playerList.RemoveChildren();
panel.Get<ButtonWidget>("CANCEL_BUTTON").OnClick = () => { Ui.CloseWindow(); onExit(); };
var rl = panel.Get<ScrollPanelWidget>("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<MapPreviewWidget>("MAP_PREVIEW");
preview.SpawnClients = () => selectedSpawns;
preview.Preview = () => selectedMap;
var title = panel.GetOrNull<LabelWidget>("MAP_TITLE");
if (title != null)
title.GetText = () => selectedMap.Title;
var type = panel.GetOrNull<LabelWidget>("MAP_TYPE");
if (type != null)
type.GetText = () => selectedMap.Type;
panel.Get<LabelWidget>("DURATION").GetText = () => selectedDuration;
panel.Get<MapPreviewWidget>("MAP_PREVIEW").Preview = () => selectedMap;
panel.Get<LabelWidget>("MAP_TITLE").GetText = () => selectedMap.Title;
panel.Get<LabelWidget>("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<string, IEnumerable<Session.Client>>();
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<LabelWidget>("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<LabelWidget>("LABEL");
label.GetText = () => o.Name;
label.GetColor = () => color;
var flag = item.Get<ImageWidget>("FLAG");
flag.GetImageCollection = () => "flags";
flag.GetImageName = () => o.Country;
playerList.AddChild(item);
}
}
}
}
catch (Exception e)

View File

@@ -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:

View File

@@ -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: