Make PlayerRelationShipColor static

This commit is contained in:
Gustas
2023-06-11 17:09:29 +03:00
committed by Matthias Mailänder
parent fa0254cb27
commit 34262fb33c
6 changed files with 10 additions and 29 deletions

View File

@@ -37,14 +37,6 @@ namespace OpenRA
public class Player : IScriptBindable, IScriptNotifyBind, ILuaTableBinding, ILuaEqualityBinding, ILuaToStringBinding public class Player : IScriptBindable, IScriptNotifyBind, ILuaTableBinding, ILuaEqualityBinding, ILuaToStringBinding
{ {
struct StanceColors
{
public Color Self;
public Color Allies;
public Color Enemies;
public Color Neutrals;
}
public readonly Actor PlayerActor; public readonly Actor PlayerActor;
public readonly Color Color; public readonly Color Color;
@@ -101,8 +93,6 @@ namespace OpenRA
} }
} }
readonly StanceColors stanceColors;
public static FactionInfo ResolveFaction(string factionName, IEnumerable<FactionInfo> factionInfos, MersenneTwister playerRandom, bool requireSelectable = true) public static FactionInfo ResolveFaction(string factionName, IEnumerable<FactionInfo> factionInfos, MersenneTwister playerRandom, bool requireSelectable = true)
{ {
var selectableFactions = factionInfos var selectableFactions = factionInfos
@@ -221,11 +211,6 @@ namespace OpenRA
logic.Activate(this); logic.Activate(this);
} }
stanceColors.Self = ChromeMetrics.Get<Color>("PlayerStanceColorSelf");
stanceColors.Allies = ChromeMetrics.Get<Color>("PlayerStanceColorAllies");
stanceColors.Enemies = ChromeMetrics.Get<Color>("PlayerStanceColorEnemies");
stanceColors.Neutrals = ChromeMetrics.Get<Color>("PlayerStanceColorNeutrals");
unlockRenderPlayer = PlayerActor.TraitsImplementing<IUnlocksRenderPlayer>().ToArray(); unlockRenderPlayer = PlayerActor.TraitsImplementing<IUnlocksRenderPlayer>().ToArray();
notifyDisconnected = PlayerActor.TraitsImplementing<INotifyPlayerDisconnected>().ToArray(); notifyDisconnected = PlayerActor.TraitsImplementing<INotifyPlayerDisconnected>().ToArray();
} }
@@ -259,7 +244,7 @@ namespace OpenRA
return RelationshipWith(p) == PlayerRelationship.Ally; return RelationshipWith(p) == PlayerRelationship.Ally;
} }
public Color PlayerRelationshipColor(Actor a) public static Color PlayerRelationshipColor(Actor a)
{ {
var renderPlayer = a.World.RenderPlayer; var renderPlayer = a.World.RenderPlayer;
var player = renderPlayer ?? a.World.LocalPlayer; var player = renderPlayer ?? a.World.LocalPlayer;
@@ -271,16 +256,16 @@ namespace OpenRA
apparentOwner = effectiveOwner.Owner; apparentOwner = effectiveOwner.Owner;
if (apparentOwner == player) if (apparentOwner == player)
return stanceColors.Self; return ChromeMetrics.Get<Color>("PlayerStanceColorSelf");
if (apparentOwner.IsAlliedWith(player)) if (apparentOwner.IsAlliedWith(player))
return stanceColors.Allies; return ChromeMetrics.Get<Color>("PlayerStanceColorAllies");
if (!apparentOwner.NonCombatant) if (!apparentOwner.NonCombatant)
return stanceColors.Enemies; return ChromeMetrics.Get<Color>("PlayerStanceColorEnemies");
} }
return stanceColors.Neutrals; return ChromeMetrics.Get<Color>("PlayerStanceColorNeutrals");
} }
internal void PlayerDisconnected(Player p) internal void PlayerDisconnected(Player p)

View File

@@ -163,7 +163,7 @@ namespace OpenRA.Mods.Cnc.Traits
if (!Disguised || self.Owner.IsAlliedWith(self.World.RenderPlayer)) if (!Disguised || self.Owner.IsAlliedWith(self.World.RenderPlayer))
return color; return color;
return Game.Settings.Game.UsePlayerStanceColors ? AsPlayer.PlayerRelationshipColor(self) : AsPlayer.Color; return Game.Settings.Game.UsePlayerStanceColors ? Player.PlayerRelationshipColor(self) : AsPlayer.Color;
} }
public void DisguiseAs(Actor target) public void DisguiseAs(Actor target)

View File

@@ -127,7 +127,7 @@ namespace OpenRA.Mods.Common.Graphics
Color GetHealthColor(IHealth health) Color GetHealthColor(IHealth health)
{ {
if (Game.Settings.Game.UsePlayerStanceColors) if (Game.Settings.Game.UsePlayerStanceColors)
return actor.Owner.PlayerRelationshipColor(actor); return Player.PlayerRelationshipColor(actor);
return health.DamageState == DamageState.Critical ? Color.Red : return health.DamageState == DamageState.Critical ? Color.Red :
health.DamageState == DamageState.Heavy ? Color.Yellow : Color.LimeGreen; health.DamageState == DamageState.Heavy ? Color.Yellow : Color.LimeGreen;

View File

@@ -84,7 +84,7 @@ namespace OpenRA.Mods.Common.Graphics
Color GetHealthColor(IHealth health) Color GetHealthColor(IHealth health)
{ {
if (Game.Settings.Game.UsePlayerStanceColors) if (Game.Settings.Game.UsePlayerStanceColors)
return actor.Owner.PlayerRelationshipColor(actor); return Player.PlayerRelationshipColor(actor);
return health.DamageState == DamageState.Critical ? Color.Red : return health.DamageState == DamageState.Critical ? Color.Red :
health.DamageState == DamageState.Heavy ? Color.Yellow : Color.LimeGreen; health.DamageState == DamageState.Heavy ? Color.Yellow : Color.LimeGreen;

View File

@@ -47,7 +47,7 @@ namespace OpenRA.Mods.Common.Traits.Radar
if (IsTraitDisabled || (viewer != null && !Info.ValidRelationships.HasRelationship(self.Owner.RelationshipWith(viewer)))) if (IsTraitDisabled || (viewer != null && !Info.ValidRelationships.HasRelationship(self.Owner.RelationshipWith(viewer))))
return; return;
var color = Game.Settings.Game.UsePlayerStanceColors ? self.Owner.PlayerRelationshipColor(self) : self.Owner.Color; var color = Game.Settings.Game.UsePlayerStanceColors ? Player.PlayerRelationshipColor(self) : self.Owner.Color;
if (modifier != null) if (modifier != null)
color = modifier.RadarColorOverride(self, color); color = modifier.RadarColorOverride(self, color);

View File

@@ -61,11 +61,7 @@ namespace OpenRA.Mods.Common.Widgets
var time = WidgetUtils.FormatTime(p.RemainingTicks, false, self.World.Timestep); var time = WidgetUtils.FormatTime(p.RemainingTicks, false, self.World.Timestep);
var text = TranslationProvider.GetString(Format, Translation.Arguments("player", self.Owner.PlayerName, "support-power", p.Name, "time", time)); var text = TranslationProvider.GetString(Format, Translation.Arguments("player", self.Owner.PlayerName, "support-power", p.Name, "time", time));
var playerColor = self.Owner.Color; var playerColor = Game.Settings.Game.UsePlayerStanceColors ? Player.PlayerRelationshipColor(self) : self.Owner.Color;
if (Game.Settings.Game.UsePlayerStanceColors)
playerColor = self.Owner.PlayerRelationshipColor(self);
var color = !p.Ready || Game.LocalTick % 50 < 25 ? playerColor : Color.White; var color = !p.Ready || Game.LocalTick % 50 < 25 ? playerColor : Color.White;
return (text, color); return (text, color);