Refactor the stats YAML and logic to more easily support swapping in data
This commit is contained in:
@@ -20,15 +20,17 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
{
|
{
|
||||||
public class ObserverStatsLogic
|
public class ObserverStatsLogic
|
||||||
{
|
{
|
||||||
|
ContainerWidget basicStats;
|
||||||
ScrollPanelWidget playersPanel;
|
ScrollPanelWidget playersPanel;
|
||||||
ScrollItemWidget playerTemplate;
|
ScrollItemWidget basicPlayerTemplate;
|
||||||
ScrollItemWidget teamTemplate;
|
ScrollItemWidget teamTemplate;
|
||||||
|
|
||||||
[ObjectCreator.UseCtor]
|
[ObjectCreator.UseCtor]
|
||||||
public ObserverStatsLogic(World world, Widget widget)
|
public ObserverStatsLogic(World world, Widget widget)
|
||||||
{
|
{
|
||||||
playersPanel = widget.Get<ScrollPanelWidget>("PLAYERS");
|
basicStats = widget.Get<ContainerWidget>("BASIC_STATS");
|
||||||
playerTemplate = playersPanel.Get<ScrollItemWidget>("PLAYER_TEMPLATE");
|
playersPanel = widget.Get<ScrollPanelWidget>("PLAYERS_PANEL");
|
||||||
|
basicPlayerTemplate = playersPanel.Get<ScrollItemWidget>("BASIC_PLAYER_TEMPLATE");
|
||||||
teamTemplate = playersPanel.Get<ScrollItemWidget>("TEAM_TEMPLATE");
|
teamTemplate = playersPanel.Get<ScrollItemWidget>("TEAM_TEMPLATE");
|
||||||
playersPanel.RemoveChildren();
|
playersPanel.RemoveChildren();
|
||||||
playersPanel.Layout = new GridLayout(playersPanel);
|
playersPanel.Layout = new GridLayout(playersPanel);
|
||||||
@@ -36,7 +38,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
var players = world.Players.Where(p => !p.NonCombatant);
|
var players = world.Players.Where(p => !p.NonCombatant);
|
||||||
|
|
||||||
widget.Height = (200 + (Math.Min(8, players.Count()) * 25)).ToString();
|
widget.Height = (200 + (Math.Min(8, players.Count()) * 25)).ToString();
|
||||||
Initialize(widget, widget.Get("BACKGROUND"), widget.Get("PLAYERS"));
|
Initialize(widget, widget.Get("BACKGROUND"), widget.Get("PLAYERS_PANEL"));
|
||||||
|
|
||||||
var teams = players.GroupBy(p => (world.LobbyInfo.ClientWithIndex(p.ClientIndex) ?? new Session.Client()).Team).OrderBy(g => g.Key);
|
var teams = players.GroupBy(p => (world.LobbyInfo.ClientWithIndex(p.ClientIndex) ?? new Session.Client()).Team).OrderBy(g => g.Key);
|
||||||
foreach (var t in teams)
|
foreach (var t in teams)
|
||||||
@@ -49,7 +51,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
foreach (var p in team)
|
foreach (var p in team)
|
||||||
{
|
{
|
||||||
var player = p;
|
var player = p;
|
||||||
var template = ScrollItemWidget.Setup(playerTemplate, () => false, () =>
|
var template = ScrollItemWidget.Setup(basicPlayerTemplate, () => false, () =>
|
||||||
{
|
{
|
||||||
var playerBase = world.Actors.FirstOrDefault(a => !a.IsDead() && a.HasTrait<BaseBuilding>() && a.Owner == player);
|
var playerBase = world.Actors.FirstOrDefault(a => !a.IsDead() && a.HasTrait<BaseBuilding>() && a.Owner == player);
|
||||||
if (playerBase != null)
|
if (playerBase != null)
|
||||||
|
|||||||
@@ -412,59 +412,65 @@ Container@OBSERVER_ROOT:
|
|||||||
Font:Bold
|
Font:Bold
|
||||||
Align:Center
|
Align:Center
|
||||||
Text:Players
|
Text:Players
|
||||||
Label@PLAYER_HEADER:
|
Container@BASIC_STATS:
|
||||||
X:85
|
X:0
|
||||||
Y:40
|
Y:0
|
||||||
Width:160
|
Width:PARENT_RIGHT
|
||||||
Height:25
|
Height:PARENT_BOTTOM
|
||||||
Font:Bold
|
Children:
|
||||||
Text:Player
|
Label@PLAYER_HEADER:
|
||||||
Label@CASH_HEADER:
|
X:85
|
||||||
X:245
|
Y:40
|
||||||
Y:40
|
Width:160
|
||||||
Width:80
|
Height:25
|
||||||
Height:25
|
Font:Bold
|
||||||
Font:Bold
|
Text:Player
|
||||||
Text:Cash
|
Label@CASH_HEADER:
|
||||||
Label@INCOME_HEADER:
|
X:245
|
||||||
X:325
|
Y:40
|
||||||
Y:40
|
Width:80
|
||||||
Width:160
|
Height:25
|
||||||
Height:25
|
Font:Bold
|
||||||
Font:Bold
|
Text:Cash
|
||||||
Text:Income
|
Label@INCOME_HEADER:
|
||||||
Label@POWER_HEADER
|
X:325
|
||||||
X:445
|
Y:40
|
||||||
Y:40
|
Width:160
|
||||||
Width:80
|
Height:25
|
||||||
Height:25
|
Font:Bold
|
||||||
Font:Bold
|
Text:Income
|
||||||
Text:Power
|
Label@POWER_HEADER
|
||||||
Label@KILLS_HEADER:
|
X:445
|
||||||
X:525
|
Y:40
|
||||||
Y:40
|
Width:80
|
||||||
Width:40
|
Height:25
|
||||||
Height:25
|
Font:Bold
|
||||||
Font:Bold
|
Text:Power
|
||||||
Text:Kills
|
Label@KILLS_HEADER:
|
||||||
Align:Right
|
X:525
|
||||||
Label@DEATHS_HEADER:
|
Y:40
|
||||||
X:585
|
Width:40
|
||||||
Y:40
|
Height:25
|
||||||
Width:40
|
Font:Bold
|
||||||
Height:25
|
Text:Kills
|
||||||
Font:Bold
|
Align:Right
|
||||||
Text:Deaths
|
Label@DEATHS_HEADER:
|
||||||
Align:Right
|
X:585
|
||||||
Label@PRODUCTION_HEADER
|
Y:40
|
||||||
X:625
|
Width:40
|
||||||
Y:40
|
Height:25
|
||||||
Width:PARENT_RIGHT-625
|
Font:Bold
|
||||||
Height:25
|
Text:Deaths
|
||||||
Font:Bold
|
Align:Right
|
||||||
Text:Production
|
Label@PRODUCTION_HEADER
|
||||||
Align:Center
|
X:625
|
||||||
ScrollPanel@PLAYERS:
|
Y:40
|
||||||
|
Width:PARENT_RIGHT-625
|
||||||
|
Height:25
|
||||||
|
Font:Bold
|
||||||
|
Text:Production
|
||||||
|
Align:Center
|
||||||
|
ScrollPanel@PLAYERS_PANEL:
|
||||||
X:25
|
X:25
|
||||||
Y:70
|
Y:70
|
||||||
Width:PARENT_RIGHT-50
|
Width:PARENT_RIGHT-50
|
||||||
@@ -483,7 +489,7 @@ Container@OBSERVER_ROOT:
|
|||||||
Width:PARENT_RIGHT
|
Width:PARENT_RIGHT
|
||||||
Height:PARENT_BOTTOM
|
Height:PARENT_BOTTOM
|
||||||
Font:Bold
|
Font:Bold
|
||||||
ScrollItem@PLAYER_TEMPLATE:
|
ScrollItem@BASIC_PLAYER_TEMPLATE:
|
||||||
X:0
|
X:0
|
||||||
Y:0
|
Y:0
|
||||||
Width:PARENT_RIGHT-35
|
Width:PARENT_RIGHT-35
|
||||||
|
|||||||
Reference in New Issue
Block a user