Make player stance colours universally respected

This commit is contained in:
Gustas
2023-02-25 13:42:43 +02:00
committed by Matthias Mailänder
parent 2f331548e1
commit 5fc36bd45f
38 changed files with 110 additions and 88 deletions

View File

@@ -38,8 +38,6 @@ namespace OpenRA
public class Player : IScriptBindable, IScriptNotifyBind, ILuaTableBinding, ILuaEqualityBinding, ILuaToStringBinding
{
public readonly Actor PlayerActor;
public readonly Color Color;
public readonly string PlayerName;
public readonly string InternalName;
public readonly FactionInfo Faction;
@@ -54,6 +52,11 @@ namespace OpenRA
public readonly Shroud Shroud;
public readonly FrozenActorLayer FrozenActorLayer;
readonly Color color;
/// <summary>Returns player color with relationship colors applied.</summary>
public Color Color { get; private set; }
/// <summary>The faction (including Random, etc.) that was selected in the lobby.</summary>
public readonly FactionInfo DisplayFaction;
@@ -152,7 +155,8 @@ namespace OpenRA
if (client != null)
{
ClientIndex = client.Index;
Color = client.Color;
color = client.Color;
Color = color;
PlayerName = ResolvePlayerName(client, world.LobbyInfo.Clients, world.Map.Rules.Actors[SystemActors.Player].TraitInfos<IBotInfo>());
BotType = client.Bot;
@@ -170,6 +174,7 @@ namespace OpenRA
{
// Map player
ClientIndex = world.LobbyInfo.Clients.FirstOrDefault(c => c.IsAdmin)?.Index ?? 0; // Owned by the host (TODO: fix this)
color = pr.Color;
Color = pr.Color;
PlayerName = pr.Name;
NonCombatant = pr.NonCombatant;
@@ -244,28 +249,30 @@ namespace OpenRA
return RelationshipWith(p) == PlayerRelationship.Ally;
}
public static Color PlayerRelationshipColor(Actor a)
/// <summary>Returns <see cref="color"/>, ignoring player relationship colors.</summary>
public static Color GetColor(Player p) => p.color;
public static void SetupRelationshipColors(Player[] players, Player viewer)
{
var renderPlayer = a.World.RenderPlayer;
var player = renderPlayer ?? a.World.LocalPlayer;
if (player != null && !player.Spectating)
{
var effectiveOwner = a.EffectiveOwner;
var apparentOwner = a.Owner;
if (effectiveOwner != null && effectiveOwner.Disguised && !a.Owner.IsAlliedWith(renderPlayer))
apparentOwner = effectiveOwner.Owner;
foreach (var p in players)
p.Color = PlayerRelationshipColor(p, viewer);
}
if (apparentOwner == player)
return ChromeMetrics.Get<Color>("PlayerStanceColorSelf");
public static Color PlayerRelationshipColor(Player player, Player viewer)
{
if (!Game.Settings.Game.UsePlayerStanceColors || viewer == null || viewer.Spectating)
return player.color;
if (apparentOwner.IsAlliedWith(player))
return ChromeMetrics.Get<Color>("PlayerStanceColorAllies");
if (viewer == player)
return ChromeMetrics.Get<Color>("PlayerStanceColorSelf");
if (!apparentOwner.NonCombatant)
return ChromeMetrics.Get<Color>("PlayerStanceColorEnemies");
}
if (player.IsAlliedWith(viewer))
return ChromeMetrics.Get<Color>("PlayerStanceColorAllies");
return ChromeMetrics.Get<Color>("PlayerStanceColorNeutrals");
if (player.NonCombatant)
return ChromeMetrics.Get<Color>("PlayerStanceColorNeutrals");
return ChromeMetrics.Get<Color>("PlayerStanceColorEnemies");
}
internal void PlayerDisconnected(Player p)