diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverStatsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverStatsLogic.cs index 2a87b8b430..2178dfa46f 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverStatsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverStatsLogic.cs @@ -233,7 +233,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic tt.IgnoreMouseOver = true; var teamLabel = tt.Get("TEAM"); - teamLabel.GetText = () => team.Key == 0 ? "No Team" : "Team " + team.Key; + var teamText = team.Key == 0 ? "No Team" : "Team " + team.Key; + teamLabel.GetText = () => teamText; tt.Bounds.Width = teamLabel.Bounds.Width = Game.Renderer.Fonts[tt.Font].Measure(tt.Get("TEAM").GetText()).X; var colorBlockWidget = tt.Get("TEAM_COLOR"); @@ -273,14 +274,29 @@ namespace OpenRA.Mods.Common.Widgets.Logic SetupPlayerColor(player, template, playerColor, playerGradient); var stats = player.PlayerActor.TraitOrDefault(); - if (stats == null) return template; - template.Get("ASSETS_DESTROYED").GetText = () => "$" + stats.KillsCost; - template.Get("ASSETS_LOST").GetText = () => "$" + stats.DeathsCost; - template.Get("UNITS_KILLED").GetText = () => stats.UnitsKilled.ToString(); - template.Get("UNITS_DEAD").GetText = () => stats.UnitsDead.ToString(); - template.Get("BUILDINGS_KILLED").GetText = () => stats.BuildingsKilled.ToString(); - template.Get("BUILDINGS_DEAD").GetText = () => stats.BuildingsDead.ToString(); - template.Get("ARMY_VALUE").GetText = () => "$" + stats.ArmyValue.ToString(); + if (stats == null) + return template; + + var destroyedText = new CachedTransform(i => "$" + i); + template.Get("ASSETS_DESTROYED").GetText = () => destroyedText.Update(stats.KillsCost); + + var lostText = new CachedTransform(i => "$" + i); + template.Get("ASSETS_LOST").GetText = () => lostText.Update(stats.DeathsCost); + + var unitsKilledText = new CachedTransform(i => i.ToString()); + template.Get("UNITS_KILLED").GetText = () => unitsKilledText.Update(stats.UnitsKilled); + + var unitsDeadText = new CachedTransform(i => i.ToString()); + template.Get("UNITS_DEAD").GetText = () => unitsDeadText.Update(stats.UnitsDead); + + var buildingsKilledText = new CachedTransform(i => i.ToString()); + template.Get("BUILDINGS_KILLED").GetText = () => buildingsKilledText.Update(stats.BuildingsKilled); + + var buildingsDeadText = new CachedTransform(i => i.ToString()); + template.Get("BUILDINGS_DEAD").GetText = () => buildingsDeadText.Update(stats.BuildingsDead); + + var armyText = new CachedTransform(i => "$" + i); + template.Get("ARMY_VALUE").GetText = () => armyText.Update(stats.ArmyValue); return template; } @@ -347,15 +363,23 @@ namespace OpenRA.Mods.Common.Widgets.Logic if (stats == null) return template; - template.Get("CASH").GetText = () => "$" + (res.Cash + res.Resources); - template.Get("INCOME").GetText = () => "$" + stats.DisplayIncome; - template.Get("EARNED").GetText = () => "$" + res.Earned; - template.Get("SPENT").GetText = () => "$" + res.Spent; + var cashText = new CachedTransform(i => "$" + i); + template.Get("CASH").GetText = () => cashText.Update(res.Cash + res.Resources); + var incomeText = new CachedTransform(i => "$" + i); + template.Get("INCOME").GetText = () => incomeText.Update(stats.DisplayIncome); + + var earnedText = new CachedTransform(i => "$" + i); + template.Get("EARNED").GetText = () => earnedText.Update(res.Earned); + + var spentText = new CachedTransform(i => "$" + i); + template.Get("SPENT").GetText = () => spentText.Update(res.Spent); + + var assetsText = new CachedTransform(i => "$" + i); var assets = template.Get("ASSETS"); - assets.GetText = () => "$" + world.ActorsHavingTrait() + assets.GetText = () => assetsText.Update(world.ActorsHavingTrait() .Where(a => a.Owner == player && !a.IsDead) - .Sum(a => a.Info.TraitInfos().First().Cost); + .Sum(a => a.Info.TraitInfos().First().Cost)); var harvesters = template.Get("HARVESTERS"); harvesters.GetText = () => world.ActorsHavingTrait().Count(a => a.Owner == player && !a.IsDead).ToString(); @@ -383,13 +407,15 @@ namespace OpenRA.Mods.Common.Widgets.Logic SetupPlayerColor(player, template, playerColor, playerGradient); var res = player.PlayerActor.Trait(); - template.Get("CASH").GetText = () => "$" + (res.Cash + res.Resources); + var cashText = new CachedTransform(i => "$" + i); + template.Get("CASH").GetText = () => cashText.Update(res.Cash + res.Resources); var powerRes = player.PlayerActor.TraitOrDefault(); if (powerRes != null) { var power = template.Get("POWER"); - power.GetText = () => powerRes.PowerDrained + "/" + powerRes.PowerProvided; + var powerText = new CachedTransform, string>(p => p.First + "/" + p.Second); + power.GetText = () => powerText.Update(new Pair(powerRes.PowerDrained, powerRes.PowerProvided)); power.GetColor = () => GetPowerColor(powerRes.PowerState); } @@ -397,12 +423,23 @@ namespace OpenRA.Mods.Common.Widgets.Logic if (stats == null) return template; - template.Get("KILLS").GetText = () => (stats.UnitsKilled + stats.BuildingsKilled).ToString(); - template.Get("DEATHS").GetText = () => (stats.UnitsDead + stats.BuildingsDead).ToString(); - template.Get("ASSETS_DESTROYED").GetText = () => "$" + stats.KillsCost; - template.Get("ASSETS_LOST").GetText = () => "$" + stats.DeathsCost; - template.Get("EXPERIENCE").GetText = () => stats.Experience.ToString(); - template.Get("ACTIONS_MIN").GetText = () => AverageOrdersPerMinute(stats.OrderCount); + var killsText = new CachedTransform(i => i.ToString()); + template.Get("KILLS").GetText = () => killsText.Update(stats.UnitsKilled + stats.BuildingsKilled); + + var deathsText = new CachedTransform(i => i.ToString()); + template.Get("DEATHS").GetText = () => deathsText.Update(stats.UnitsDead + stats.BuildingsDead); + + var destroyedText = new CachedTransform(i => "$" + i); + template.Get("ASSETS_DESTROYED").GetText = () => destroyedText.Update(stats.KillsCost); + + var lostText = new CachedTransform(i => "$" + i); + template.Get("ASSETS_LOST").GetText = () => lostText.Update(stats.DeathsCost); + + var experienceText = new CachedTransform(i => i.ToString()); + template.Get("EXPERIENCE").GetText = () => experienceText.Update(stats.Experience); + + var actionsText = new CachedTransform(d => AverageOrdersPerMinute(d)); + template.Get("ACTIONS_MIN").GetText = () => actionsText.Update(stats.OrderCount); return template; }