Replace Cash + Resources with GetCashAndResources()

This commit is contained in:
dnqbob
2023-09-07 07:17:54 +08:00
committed by Gustas
parent 931118e1d8
commit 19c8c36030
5 changed files with 8 additions and 8 deletions

View File

@@ -50,7 +50,7 @@ namespace OpenRA.Mods.Common.Traits
public override int GetSelectionShares(Actor collector) public override int GetSelectionShares(Actor collector)
{ {
var pr = collector.Owner.PlayerActor.Trait<PlayerResources>(); var pr = collector.Owner.PlayerActor.Trait<PlayerResources>();
if (info.Amount < 0 && pr.Cash + pr.Resources == 0) if (info.Amount < 0 && pr.GetCashAndResources() == 0)
return 0; return 0;
return base.GetSelectionShares(collector); return base.GetSelectionShares(collector);

View File

@@ -113,7 +113,7 @@ namespace OpenRA.Mods.Common.Traits
else else
{ {
// Don't put the player into negative funds // Don't put the player into negative funds
amount = Math.Max(-(Cash + Resources), amount); amount = Math.Max(-GetCashAndResources(), amount);
TakeCash(-amount); TakeCash(-amount);
} }
@@ -182,7 +182,7 @@ namespace OpenRA.Mods.Common.Traits
public bool TakeCash(int num, bool notifyLowFunds = false) public bool TakeCash(int num, bool notifyLowFunds = false)
{ {
if (Cash + Resources < num) if (GetCashAndResources() < num)
{ {
if (notifyLowFunds && Game.RunTime > lastNotificationTime + Info.InsufficientFundsNotificationInterval) if (notifyLowFunds && Game.RunTime > lastNotificationTime + Info.InsufficientFundsNotificationInterval)
{ {

View File

@@ -41,7 +41,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
this.world = world; this.world = world;
player = world.LocalPlayer; player = world.LocalPlayer;
playerResources = player.PlayerActor.Trait<PlayerResources>(); playerResources = player.PlayerActor.Trait<PlayerResources>();
displayResources = playerResources.Cash + playerResources.Resources; displayResources = playerResources.GetCashAndResources();
siloUsageTooltipCache = new CachedTransform<(int Resources, int Capacity), string>(x => siloUsageTooltipCache = new CachedTransform<(int Resources, int Capacity), string>(x =>
TranslationProvider.GetString(SiloUsage, Translation.Arguments("usage", x.Resources, "capacity", x.Capacity))); TranslationProvider.GetString(SiloUsage, Translation.Arguments("usage", x.Resources, "capacity", x.Capacity)));
@@ -54,7 +54,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
if (nextCashTickTime > 0) if (nextCashTickTime > 0)
nextCashTickTime--; nextCashTickTime--;
var actual = playerResources.Cash + playerResources.Resources; var actual = playerResources.GetCashAndResources();
var diff = Math.Abs(actual - displayResources); var diff = Math.Abs(actual - displayResources);
var move = Math.Min(Math.Max((int)(diff * DisplayFracPerFrame), DisplayDeltaPerFrame), diff); var move = Math.Min(Math.Max((int)(diff * DisplayFracPerFrame), DisplayDeltaPerFrame), diff);

View File

@@ -432,7 +432,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var res = player.PlayerActor.Trait<PlayerResources>(); var res = player.PlayerActor.Trait<PlayerResources>();
var cashText = new CachedTransform<int, string>(i => "$" + i); var cashText = new CachedTransform<int, string>(i => "$" + i);
template.Get<LabelWidget>("CASH").GetText = () => cashText.Update(res.Cash + res.Resources); template.Get<LabelWidget>("CASH").GetText = () => cashText.Update(res.GetCashAndResources());
var incomeText = new CachedTransform<int, string>(i => "$" + i); var incomeText = new CachedTransform<int, string>(i => "$" + i);
template.Get<LabelWidget>("INCOME").GetText = () => incomeText.Update(stats.DisplayIncome); template.Get<LabelWidget>("INCOME").GetText = () => incomeText.Update(stats.DisplayIncome);
@@ -477,7 +477,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var res = player.PlayerActor.Trait<PlayerResources>(); var res = player.PlayerActor.Trait<PlayerResources>();
var cashText = new CachedTransform<int, string>(i => "$" + i); var cashText = new CachedTransform<int, string>(i => "$" + i);
template.Get<LabelWidget>("CASH").GetText = () => cashText.Update(res.Cash + res.Resources); template.Get<LabelWidget>("CASH").GetText = () => cashText.Update(res.GetCashAndResources());
var powerRes = player.PlayerActor.TraitOrDefault<PowerManager>(); var powerRes = player.PlayerActor.TraitOrDefault<PowerManager>();
if (powerRes != null) if (powerRes != null)

View File

@@ -134,7 +134,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var timeSize = font.Measure(timeLabel.Text); var timeSize = font.Measure(timeLabel.Text);
costLabel.Text = cost.ToString(NumberFormatInfo.CurrentInfo); costLabel.Text = cost.ToString(NumberFormatInfo.CurrentInfo);
costLabel.GetColor = () => pr.Cash + pr.Resources >= cost ? Color.White : Color.Red; costLabel.GetColor = () => pr.GetCashAndResources() >= cost ? Color.White : Color.Red;
var costSize = font.Measure(costLabel.Text); var costSize = font.Measure(costLabel.Text);
descLabel.Text = buildable.Description.Replace("\\n", "\n"); descLabel.Text = buildable.Description.Replace("\\n", "\n");