Made PowerManager optional for traits who do not require it.

This commit is contained in:
Andre Mohren
2018-07-22 12:08:58 +02:00
committed by Paul Chote
parent dcf93203ea
commit 81e1b39bb9
6 changed files with 38 additions and 26 deletions

View File

@@ -255,10 +255,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic
template.Get<LabelWidget>("CASH").GetText = () => "$" + (res.Cash + res.Resources);
template.Get<LabelWidget>("EARNED_MIN").GetText = () => AverageEarnedPerMinute(res.Earned);
var powerRes = player.PlayerActor.Trait<PowerManager>();
var power = template.Get<LabelWidget>("POWER");
power.GetText = () => powerRes.PowerDrained + "/" + powerRes.PowerProvided;
power.GetColor = () => GetPowerColor(powerRes.PowerState);
var powerRes = player.PlayerActor.TraitOrDefault<PowerManager>();
if (powerRes != null)
{
var power = template.Get<LabelWidget>("POWER");
power.GetText = () => powerRes.PowerDrained + "/" + powerRes.PowerProvided;
power.GetColor = () => GetPowerColor(powerRes.PowerState);
}
var stats = player.PlayerActor.TraitOrDefault<PlayerStatistics>();
if (stats == null) return template;