Refactor the stats YAML and logic to more easily support swapping in data

This commit is contained in:
Scott_NZ
2012-11-23 20:42:47 +13:00
parent bb1c87b084
commit babf1556e3
2 changed files with 67 additions and 59 deletions

View File

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

View File

@@ -412,6 +412,12 @@ Container@OBSERVER_ROOT:
Font:Bold Font:Bold
Align:Center Align:Center
Text:Players Text:Players
Container@BASIC_STATS:
X:0
Y:0
Width:PARENT_RIGHT
Height:PARENT_BOTTOM
Children:
Label@PLAYER_HEADER: Label@PLAYER_HEADER:
X:85 X:85
Y:40 Y:40
@@ -464,7 +470,7 @@ Container@OBSERVER_ROOT:
Font:Bold Font:Bold
Text:Production Text:Production
Align:Center Align:Center
ScrollPanel@PLAYERS: 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