Implement player stance colors

Adds an option to display actors on radar and
support weapon timers in colors denoting the
diplomatic stance toward the player.
This commit is contained in:
DArcy Rush
2015-10-29 15:06:51 +00:00
committed by Oliver Brakmann
parent ce8b03a276
commit eb795909da
17 changed files with 97 additions and 40 deletions

View File

@@ -85,29 +85,8 @@ namespace OpenRA.Graphics
Color GetHealthColor(IHealth health)
{
var player = actor.World.RenderPlayer ?? actor.World.LocalPlayer;
if (Game.Settings.Game.TeamHealthColors && player != null && !player.Spectating)
{
var apparentOwner = actor.EffectiveOwner != null && actor.EffectiveOwner.Disguised
? actor.EffectiveOwner.Owner
: actor.Owner;
// For friendly spies, treat the unit's owner as the actual owner
if (actor.Owner.IsAlliedWith(actor.World.RenderPlayer))
apparentOwner = actor.Owner;
if (apparentOwner == player)
return Color.LimeGreen;
if (apparentOwner.IsAlliedWith(player))
return Color.Yellow;
if (apparentOwner.NonCombatant)
return Color.Tan;
return Color.Red;
}
if (Game.Settings.Game.UsePlayerStanceColors)
return actor.Owner.PlayerStanceColor(actor);
else
return health.DamageState == DamageState.Critical ? Color.Red :
health.DamageState == DamageState.Heavy ? Color.Yellow : Color.LimeGreen;

View File

@@ -10,6 +10,7 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using Eluant;
using Eluant.ObjectBinding;
@@ -18,6 +19,7 @@ using OpenRA.Network;
using OpenRA.Primitives;
using OpenRA.Scripting;
using OpenRA.Traits;
using OpenRA.Widgets;
namespace OpenRA
{
@@ -26,6 +28,14 @@ namespace OpenRA
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 HSLColor Color;
@@ -50,6 +60,7 @@ namespace OpenRA
public World World { get; private set; }
readonly IFogVisibilityModifier[] fogVisibilities;
readonly StanceColors stanceColors;
static FactionInfo ChooseFaction(World world, string name, bool requireSelectable = true)
{
@@ -127,6 +138,11 @@ namespace OpenRA
else
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");
}
public override string ToString()
@@ -181,6 +197,31 @@ namespace OpenRA
}
}
public Color PlayerStanceColor(Actor a)
{
var player = a.World.RenderPlayer ?? a.World.LocalPlayer;
if (player != null && !player.Spectating)
{
var apparentOwner = a.EffectiveOwner != null && a.EffectiveOwner.Disguised
? a.EffectiveOwner.Owner
: a.Owner;
if (a.Owner.IsAlliedWith(a.World.RenderPlayer))
apparentOwner = a.Owner;
if (apparentOwner == player)
return stanceColors.Self;
if (apparentOwner.IsAlliedWith(player))
return stanceColors.Allies;
if (!apparentOwner.NonCombatant)
return stanceColors.Enemies;
}
return stanceColors.Neutrals;
}
#region Scripting interface
Lazy<ScriptPlayerInterface> luaInterface;

View File

@@ -168,7 +168,7 @@ namespace OpenRA
public bool UseClassicMouseStyle = false;
public StatusBarsType StatusBars = StatusBarsType.Standard;
public bool TeamHealthColors = false;
public bool UsePlayerStanceColors = false;
public bool DrawTargetLine = true;
public bool AllowDownloading = true;
@@ -213,6 +213,7 @@ namespace OpenRA
public Hotkey CycleStatusBarsKey = new Hotkey(Keycode.COMMA, Modifiers.None);
public Hotkey TogglePixelDoubleKey = new Hotkey(Keycode.PERIOD, Modifiers.None);
public Hotkey TogglePlayerStanceColorsKey = new Hotkey(Keycode.COMMA, Modifiers.Ctrl);
public Hotkey DevReloadChromeKey = new Hotkey(Keycode.C, Modifiers.Ctrl | Modifiers.Shift);
public Hotkey HideUserInterfaceKey = new Hotkey(Keycode.H, Modifiers.Ctrl | Modifiers.Shift);

View File

@@ -203,7 +203,7 @@ namespace OpenRA.Traits
bool HasFogVisibility();
}
public interface IRadarColorModifier { Color RadarColorOverride(Actor self); }
public interface IRadarColorModifier { Color RadarColorOverride(Actor self, Color color); }
public interface IOccupySpaceInfo : ITraitInfoInterface
{

View File

@@ -286,6 +286,8 @@ namespace OpenRA.Widgets
return TogglePixelDouble();
else if (key == Game.Settings.Keys.ToggleMuteKey)
return ToggleMute();
else if (key == Game.Settings.Keys.TogglePlayerStanceColorsKey)
return TogglePlayerStanceColors();
}
return false;
@@ -342,6 +344,7 @@ namespace OpenRA.Widgets
{
Game.Settings.Graphics.PixelDouble ^= true;
worldRenderer.Viewport.Zoom = Game.Settings.Graphics.PixelDouble ? 2 : 1;
return true;
}
@@ -362,5 +365,12 @@ namespace OpenRA.Widgets
return true;
}
bool TogglePlayerStanceColors()
{
Game.Settings.Game.UsePlayerStanceColors ^= true;
return true;
}
}
}