From 239891070d8be92fe86c04cf973b98d10d44779e Mon Sep 17 00:00:00 2001 From: Gustas <37534529+PunkPun@users.noreply.github.com> Date: Fri, 11 Aug 2023 11:29:31 +0300 Subject: [PATCH] Make sure palettes are updated if colors are toggled in game runtime And fix MutablePalette's not getting updated --- OpenRA.Game/Graphics/HardwarePalette.cs | 3 +++ OpenRA.Game/Graphics/WorldRenderer.cs | 5 +---- OpenRA.Game/Player.cs | 6 +++++- .../Ingame/Hotkeys/TogglePlayerStanceColorHotkeyLogic.cs | 7 +++++-- .../Widgets/Logic/Settings/DisplaySettingsLogic.cs | 2 +- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/OpenRA.Game/Graphics/HardwarePalette.cs b/OpenRA.Game/Graphics/HardwarePalette.cs index f8e67bc234..4c111eb2bc 100644 --- a/OpenRA.Game/Graphics/HardwarePalette.cs +++ b/OpenRA.Game/Graphics/HardwarePalette.cs @@ -85,7 +85,10 @@ namespace OpenRA.Graphics public void ReplacePalette(string name, IPalette p) { if (mutablePalettes.ContainsKey(name)) + { + palettes[name] = new ImmutablePalette(p); CopyPaletteToBuffer(indices[name], mutablePalettes[name] = new MutablePalette(p)); + } else if (palettes.ContainsKey(name)) CopyPaletteToBuffer(indices[name], palettes[name] = new ImmutablePalette(p)); else diff --git a/OpenRA.Game/Graphics/WorldRenderer.cs b/OpenRA.Game/Graphics/WorldRenderer.cs index d1012316d4..4df9e491dd 100644 --- a/OpenRA.Game/Graphics/WorldRenderer.cs +++ b/OpenRA.Game/Graphics/WorldRenderer.cs @@ -62,10 +62,7 @@ namespace OpenRA.Graphics foreach (var pal in world.TraitDict.ActorsWithTrait()) pal.Trait.LoadPalettes(this); - foreach (var p in world.Players) - UpdatePalettesForPlayer(p.InternalName, p.Color, false); - - Player.SetupRelationshipColors(world.Players, world.LocalPlayer); + Player.SetupRelationshipColors(world.Players, world.LocalPlayer, this, true); palette.Initialize(); diff --git a/OpenRA.Game/Player.cs b/OpenRA.Game/Player.cs index 7b5c2c94c6..ee6e576170 100644 --- a/OpenRA.Game/Player.cs +++ b/OpenRA.Game/Player.cs @@ -14,6 +14,7 @@ using System.Collections.Generic; using System.Linq; using Eluant; using Eluant.ObjectBinding; +using OpenRA.Graphics; using OpenRA.Network; using OpenRA.Primitives; using OpenRA.Scripting; @@ -252,10 +253,13 @@ namespace OpenRA /// Returns , ignoring player relationship colors. public static Color GetColor(Player p) => p.color; - public static void SetupRelationshipColors(Player[] players, Player viewer) + public static void SetupRelationshipColors(Player[] players, Player viewer, WorldRenderer worldRenderer, bool firstRun) { foreach (var p in players) + { p.Color = PlayerRelationshipColor(p, viewer); + worldRenderer.UpdatePalettesForPlayer(p.InternalName, p.Color, !firstRun); + } } public static Color PlayerRelationshipColor(Player player, Player viewer) diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/TogglePlayerStanceColorHotkeyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/TogglePlayerStanceColorHotkeyLogic.cs index ce7d85c71e..c54b0112d4 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/TogglePlayerStanceColorHotkeyLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/TogglePlayerStanceColorHotkeyLogic.cs @@ -10,6 +10,7 @@ #endregion using System.Collections.Generic; +using OpenRA.Graphics; using OpenRA.Mods.Common.Lint; using OpenRA.Widgets; @@ -19,18 +20,20 @@ namespace OpenRA.Mods.Common.Widgets.Logic.Ingame public class TogglePlayerStanceColorHotkeyLogic : SingleHotkeyBaseLogic { readonly World world; + readonly WorldRenderer worldRenderer; [ObjectCreator.UseCtor] - public TogglePlayerStanceColorHotkeyLogic(Widget widget, World world, ModData modData, Dictionary logicArgs) + public TogglePlayerStanceColorHotkeyLogic(Widget widget, World world, WorldRenderer worldRenderer, ModData modData, Dictionary logicArgs) : base(widget, modData, "TogglePlayerStanceColorKey", "WORLD_KEYHANDLER", logicArgs) { this.world = world; + this.worldRenderer = worldRenderer; } protected override bool OnHotkeyActivated(KeyInput e) { Game.Settings.Game.UsePlayerStanceColors ^= true; - Player.SetupRelationshipColors(world.Players, world.LocalPlayer); + Player.SetupRelationshipColors(world.Players, world.LocalPlayer, worldRenderer, false); return true; } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Settings/DisplaySettingsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Settings/DisplaySettingsLogic.cs index 897ae9bb1f..37e1fa031f 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Settings/DisplaySettingsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Settings/DisplaySettingsLogic.cs @@ -152,7 +152,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic cb.OnClick = () => { gs.UsePlayerStanceColors = cb.IsChecked() ^ true; - Player.SetupRelationshipColors(world.Players, world.LocalPlayer); + Player.SetupRelationshipColors(world.Players, world.LocalPlayer, worldRenderer, false); }; if (panel.GetOrNull("PAUSE_SHELLMAP_CHECKBOX") != null)