Add total earned/spent tracking

This commit is contained in:
Scott_NZ
2012-11-24 18:11:34 +13:00
parent 2a0b9a8596
commit 30a374b9e9
3 changed files with 43 additions and 5 deletions

View File

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

View File

@@ -175,6 +175,9 @@ namespace OpenRA.Mods.RA.Widgets.Logic
.Where(a => a.Owner == player && !a.IsDead() && a.Info.Traits.WithInterface<ValuedInfo>().Any())
.Sum(a => a.Info.Traits.WithInterface<ValuedInfo>().First().Cost);
template.Get<LabelWidget>("TOTAL_EARNED").GetText = () => "$" + res.TotalEarned;
template.Get<LabelWidget>("TOTAL_SPENT").GetText = () => "$" + res.TotalSpent;
var numHarvesters = template.Get<LabelWidget>("NUMBER_HARVESTERS");
numHarvesters.GetText = () => world.Actors.Count(a => a.Owner == player && !a.IsDead() && a.HasTrait<Harvester>()).ToString();

View File

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