From 30a374b9e9e6ba3db590d18d3decc8a980fec32f Mon Sep 17 00:00:00 2001 From: Scott_NZ Date: Sat, 24 Nov 2012 18:11:34 +1300 Subject: [PATCH] Add total earned/spent tracking --- OpenRA.Game/Traits/Player/PlayerResources.cs | 17 +++++++++-- .../Widgets/Logic/ObserverStatsLogic.cs | 3 ++ mods/ra/chrome/ingame.yaml | 28 +++++++++++++++++-- 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/OpenRA.Game/Traits/Player/PlayerResources.cs b/OpenRA.Game/Traits/Player/PlayerResources.cs index 391c76f16b..e0742edd6b 100644 --- a/OpenRA.Game/Traits/Player/PlayerResources.cs +++ b/OpenRA.Game/Traits/Player/PlayerResources.cs @@ -87,9 +87,13 @@ namespace OpenRA.Traits public int DisplayOre; public int IncomePerMin; - public double IncomeChange; int incomeCounter; + public double IncomeChange; + + public int TotalEarned; + public int TotalSpent; + public bool CanGiveOre(int amount) { return Ore + amount <= OreCapacity; @@ -98,20 +102,25 @@ namespace OpenRA.Traits public void GiveOre(int num) { Ore += num; + incomeCounter += num; + TotalEarned += num; if (Ore > OreCapacity) { nextSiloAdviceTime = 0; + + incomeCounter -= Ore - OreCapacity; + TotalEarned -= Ore - OreCapacity; + Ore = OreCapacity; } - - incomeCounter += num; } public bool TakeOre(int num) { if (Ore < num) return false; Ore -= num; + TotalSpent += num; return true; } @@ -120,6 +129,7 @@ namespace OpenRA.Traits { Cash += num; incomeCounter += num; + TotalEarned += num; } public bool TakeCash(int num) @@ -128,6 +138,7 @@ namespace OpenRA.Traits // Spend ore before cash Ore -= num; + TotalSpent += num; if (Ore < 0) { Cash += Ore; diff --git a/OpenRA.Mods.RA/Widgets/Logic/ObserverStatsLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/ObserverStatsLogic.cs index 8b53853b52..5744641c1b 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/ObserverStatsLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/ObserverStatsLogic.cs @@ -175,6 +175,9 @@ namespace OpenRA.Mods.RA.Widgets.Logic .Where(a => a.Owner == player && !a.IsDead() && a.Info.Traits.WithInterface().Any()) .Sum(a => a.Info.Traits.WithInterface().First().Cost); + template.Get("TOTAL_EARNED").GetText = () => "$" + res.TotalEarned; + template.Get("TOTAL_SPENT").GetText = () => "$" + res.TotalSpent; + var numHarvesters = template.Get("NUMBER_HARVESTERS"); numHarvesters.GetText = () => world.Actors.Count(a => a.Owner == player && !a.IsDead() && a.HasTrait()).ToString(); diff --git a/mods/ra/chrome/ingame.yaml b/mods/ra/chrome/ingame.yaml index 5f49aff40d..81286f367e 100644 --- a/mods/ra/chrome/ingame.yaml +++ b/mods/ra/chrome/ingame.yaml @@ -510,8 +510,22 @@ Container@OBSERVER_ROOT: Height:25 Font:Bold Text:Assets + Label@TOTAL_EARNED_HEADER + X:505 + Y:40 + Width:60 + Height:25 + Font:Bold + Text:Earned + Label@TOTAL_SPENT_HEADER + X:565 + Y:40 + Width:60 + Height:25 + Font:Bold + Text:Spent Label@NUMBER_HARVESTERS_HEADER - X:525 + X:645 Y:40 Width:60 Height:25 @@ -648,8 +662,18 @@ Container@OBSERVER_ROOT: Y:0 Width:60 Height:PARENT_BOTTOM + Label@TOTAL_EARNED: + X:475 + Y:0 + Width:60 + Height:PARENT_BOTTOM + Label@TOTAL_SPENT: + X:535 + Y:0 + Width:60 + Height:PARENT_BOTTOM Label@NUMBER_HARVESTERS: - X:495 + X:615 Y:0 Width:60 Height:PARENT_BOTTOM