From eb795909da73a8b6b97b54872b5f925309e6a2c1 Mon Sep 17 00:00:00 2001 From: DArcy Rush Date: Thu, 29 Oct 2015 15:06:51 +0000 Subject: [PATCH] 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. --- .../Graphics/SelectionBarsRenderable.cs | 25 +---------- OpenRA.Game/Player.cs | 41 +++++++++++++++++++ OpenRA.Game/Settings.cs | 3 +- OpenRA.Game/Traits/TraitsInterfaces.cs | 2 +- .../WorldInteractionControllerWidget.cs | 10 +++++ OpenRA.Mods.Common/Traits/AppearsOnRadar.cs | 4 +- OpenRA.Mods.Common/Traits/Cloak.cs | 8 ++-- .../Traits/RadarColorFromTerrain.cs | 2 +- .../Widgets/Logic/SettingsLogic.cs | 3 +- .../Widgets/SupportPowerTimerWidget.cs | 9 +++- OpenRA.Mods.RA/Traits/Disguise.cs | 6 +-- mods/cnc/chrome/settings.yaml | 4 +- mods/cnc/metrics.yaml | 4 ++ mods/d2k/metrics.yaml | 4 ++ mods/ra/chrome/settings.yaml | 4 +- mods/ra/metrics.yaml | 4 ++ mods/ts/metrics.yaml | 4 ++ 17 files changed, 97 insertions(+), 40 deletions(-) diff --git a/OpenRA.Game/Graphics/SelectionBarsRenderable.cs b/OpenRA.Game/Graphics/SelectionBarsRenderable.cs index 339cae94f4..b2d3fd2e34 100644 --- a/OpenRA.Game/Graphics/SelectionBarsRenderable.cs +++ b/OpenRA.Game/Graphics/SelectionBarsRenderable.cs @@ -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; diff --git a/OpenRA.Game/Player.cs b/OpenRA.Game/Player.cs index 1e21983465..353498888d 100644 --- a/OpenRA.Game/Player.cs +++ b/OpenRA.Game/Player.cs @@ -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("PlayerStanceColorSelf"); + stanceColors.Allies = ChromeMetrics.Get("PlayerStanceColorAllies"); + stanceColors.Enemies = ChromeMetrics.Get("PlayerStanceColorEnemies"); + stanceColors.Neutrals = ChromeMetrics.Get("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 luaInterface; diff --git a/OpenRA.Game/Settings.cs b/OpenRA.Game/Settings.cs index f69a9ee4d7..7a46459fd9 100644 --- a/OpenRA.Game/Settings.cs +++ b/OpenRA.Game/Settings.cs @@ -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); diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index e346d4191a..c1b9ec5313 100644 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -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 { diff --git a/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs b/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs index 0035fffc80..3abc490d30 100644 --- a/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs +++ b/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs @@ -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; + } } } diff --git a/OpenRA.Mods.Common/Traits/AppearsOnRadar.cs b/OpenRA.Mods.Common/Traits/AppearsOnRadar.cs index ad2ec15534..86667bc195 100644 --- a/OpenRA.Mods.Common/Traits/AppearsOnRadar.cs +++ b/OpenRA.Mods.Common/Traits/AppearsOnRadar.cs @@ -40,7 +40,9 @@ namespace OpenRA.Mods.Common.Traits public IEnumerable> RadarSignatureCells(Actor self) { - var color = modifier != null ? modifier.RadarColorOverride(self) : self.Owner.Color.RGB; + var color = Game.Settings.Game.UsePlayerStanceColors ? self.Owner.PlayerStanceColor(self) : self.Owner.Color.RGB; + if (modifier != null) + color = modifier.RadarColorOverride(self, color); if (info.UseLocation) return new[] { Pair.New(self.Location, color) }; diff --git a/OpenRA.Mods.Common/Traits/Cloak.cs b/OpenRA.Mods.Common/Traits/Cloak.cs index 1283298b20..e4c38a4166 100644 --- a/OpenRA.Mods.Common/Traits/Cloak.cs +++ b/OpenRA.Mods.Common/Traits/Cloak.cs @@ -156,12 +156,12 @@ namespace OpenRA.Mods.Common.Traits && (self.CenterPosition - a.Actor.CenterPosition).LengthSquared <= a.Trait.Info.Range.LengthSquared); } - Color IRadarColorModifier.RadarColorOverride(Actor self) + Color IRadarColorModifier.RadarColorOverride(Actor self, Color color) { - var c = self.Owner.Color.RGB; if (self.Owner == self.World.LocalPlayer && Cloaked) - c = Color.FromArgb(128, c); - return c; + color = Color.FromArgb(128, color); + + return color; } void GrantUpgrades(Actor self) diff --git a/OpenRA.Mods.Common/Traits/RadarColorFromTerrain.cs b/OpenRA.Mods.Common/Traits/RadarColorFromTerrain.cs index ae47345680..08b9cdf7c9 100644 --- a/OpenRA.Mods.Common/Traits/RadarColorFromTerrain.cs +++ b/OpenRA.Mods.Common/Traits/RadarColorFromTerrain.cs @@ -29,6 +29,6 @@ namespace OpenRA.Mods.Common.Traits } public bool VisibleOnRadar(Actor self) { return true; } - public Color RadarColorOverride(Actor self) { return c; } + public Color RadarColorOverride(Actor self, Color color) { return c; } } } \ No newline at end of file diff --git a/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs index 2d3b5b69c9..0f7ca6c48c 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs @@ -154,7 +154,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic BindCheckboxPref(panel, "FRAME_LIMIT_CHECKBOX", ds, "CapFramerate"); BindCheckboxPref(panel, "SHOW_SHELLMAP", gs, "ShowShellmap"); BindCheckboxPref(panel, "DISPLAY_TARGET_LINES_CHECKBOX", gs, "DrawTargetLine"); - BindCheckboxPref(panel, "TEAM_HEALTH_COLORS_CHECKBOX", gs, "TeamHealthColors"); + BindCheckboxPref(panel, "PLAYER_STANCE_COLORS_CHECKBOX", gs, "UsePlayerStanceColors"); var languageDropDownButton = panel.Get("LANGUAGE_DROPDOWNBUTTON"); languageDropDownButton.OnMouseDown = _ => ShowLanguageDropdown(languageDropDownButton); @@ -436,6 +436,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic { "CycleStatusBarsKey", "Cycle status bars display" }, { "TogglePixelDoubleKey", "Toggle pixel doubling" }, { "ToggleMuteKey", "Toggle audio mute" }, + { "TogglePlayerStanceColorsKey", "Toggle player stance colors" }, { "MapScrollUp", "Map scroll up" }, { "MapScrollDown", "Map scroll down" }, diff --git a/OpenRA.Mods.Common/Widgets/SupportPowerTimerWidget.cs b/OpenRA.Mods.Common/Widgets/SupportPowerTimerWidget.cs index 0fc8037baa..e00a4387e1 100644 --- a/OpenRA.Mods.Common/Widgets/SupportPowerTimerWidget.cs +++ b/OpenRA.Mods.Common/Widgets/SupportPowerTimerWidget.cs @@ -52,7 +52,14 @@ namespace OpenRA.Mods.Common.Widgets { var time = WidgetUtils.FormatTime(p.RemainingTime, false, timestep); var text = Format.F(p.Info.Description, time); - var color = !p.Ready || Game.LocalTick % 50 < 25 ? p.Instances[0].Self.Owner.Color.RGB : Color.White; + var self = p.Instances[0].Self; + var playerColor = self.Owner.Color.RGB; + + if (Game.Settings.Game.UsePlayerStanceColors) + playerColor = self.Owner.PlayerStanceColor(self); + + var color = !p.Ready || Game.LocalTick % 50 < 25 ? playerColor : Color.White; + return Pair.New(text, color); }).ToArray(); } diff --git a/OpenRA.Mods.RA/Traits/Disguise.cs b/OpenRA.Mods.RA/Traits/Disguise.cs index 05a4dab353..9efc528c7b 100644 --- a/OpenRA.Mods.RA/Traits/Disguise.cs +++ b/OpenRA.Mods.RA/Traits/Disguise.cs @@ -120,12 +120,12 @@ namespace OpenRA.Mods.RA.Traits return order.OrderString == "Disguise" ? info.Voice : null; } - public Color RadarColorOverride(Actor self) + public Color RadarColorOverride(Actor self, Color color) { if (!Disguised || self.Owner.IsAlliedWith(self.World.RenderPlayer)) - return self.Owner.Color.RGB; + return color; - return AsPlayer.Color.RGB; + return color = Game.Settings.Game.UsePlayerStanceColors ? AsPlayer.PlayerStanceColor(self) : AsPlayer.Color.RGB; } public void DisguiseAs(Actor target) diff --git a/mods/cnc/chrome/settings.yaml b/mods/cnc/chrome/settings.yaml index c6747644cd..43e788b99d 100644 --- a/mods/cnc/chrome/settings.yaml +++ b/mods/cnc/chrome/settings.yaml @@ -145,13 +145,13 @@ Container@SETTINGS_PANEL: Y: 152 Height: 25 Text: FPS - Checkbox@TEAM_HEALTH_COLORS_CHECKBOX: + Checkbox@PLAYER_STANCE_COLORS_CHECKBOX: X: 310 Y: 185 Width: 200 Height: 20 Font: Regular - Text: Team Health Colors + Text: Player Stance Colors Checkbox@SHOW_SHELLMAP: X: 15 Y: 185 diff --git a/mods/cnc/metrics.yaml b/mods/cnc/metrics.yaml index 0159d0c826..f859de38ed 100644 --- a/mods/cnc/metrics.yaml +++ b/mods/cnc/metrics.yaml @@ -36,3 +36,7 @@ Metrics: IncompatibleGameStartedColor: D2691E GlobalChatTextColor: FFFFFF GlobalChatNotificationColor: D3D3D3 + PlayerStanceColorSelf: 32CD32 + PlayerStanceColorAllies: FFFF00 + PlayerStanceColorEnemies: FF0000 + PlayerStanceColorNeutrals: D2B48C diff --git a/mods/d2k/metrics.yaml b/mods/d2k/metrics.yaml index b0b4e7383b..4361d1ac9c 100644 --- a/mods/d2k/metrics.yaml +++ b/mods/d2k/metrics.yaml @@ -35,3 +35,7 @@ Metrics: IncompatibleGameStartedColor: D2691E GlobalChatTextColor: FFFFFF GlobalChatNotificationColor: D3D3D3 + PlayerStanceColorSelf: 32CD32 + PlayerStanceColorAllies: FFFF00 + PlayerStanceColorEnemies: FF0000 + PlayerStanceColorNeutrals: D2B48C diff --git a/mods/ra/chrome/settings.yaml b/mods/ra/chrome/settings.yaml index f495390ac9..a9c16b85ed 100644 --- a/mods/ra/chrome/settings.yaml +++ b/mods/ra/chrome/settings.yaml @@ -158,13 +158,13 @@ Background@SETTINGS_PANEL: Y: 157 Height: 25 Text: FPS - Checkbox@TEAM_HEALTH_COLORS_CHECKBOX: + Checkbox@PLAYER_STANCE_COLORS_CHECKBOX: X: 310 Y: 195 Width: 200 Height: 20 Font: Regular - Text: Team Health Colors + Text: Player Stance Colors Checkbox@SHOW_SHELLMAP: X: 15 Y: 195 diff --git a/mods/ra/metrics.yaml b/mods/ra/metrics.yaml index 9d73c28919..b249946a3e 100644 --- a/mods/ra/metrics.yaml +++ b/mods/ra/metrics.yaml @@ -43,3 +43,7 @@ Metrics: IncompatibleGameStartedColor: D2691E GlobalChatTextColor: FFFFFF GlobalChatNotificationColor: D3D3D3 + PlayerStanceColorSelf: 32CD32 + PlayerStanceColorAllies: FFFF00 + PlayerStanceColorEnemies: FF0000 + PlayerStanceColorNeutrals: D2B48C diff --git a/mods/ts/metrics.yaml b/mods/ts/metrics.yaml index 21628461b8..e752867d5c 100644 --- a/mods/ts/metrics.yaml +++ b/mods/ts/metrics.yaml @@ -35,3 +35,7 @@ Metrics: IncompatibleGameStartedColor: D2691E GlobalChatTextColor: FFFFFF GlobalChatNotificationColor: D3D3D3 + PlayerStanceColorSelf: 32CD32 + PlayerStanceColorAllies: FFFF00 + PlayerStanceColorEnemies: FF0000 + PlayerStanceColorNeutrals: D2B48C