From 694fd8418803109505165b44c7119a3d538a697d Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 15 Aug 2010 00:15:23 +1200 Subject: [PATCH] Clean up custom color palette --- OpenRA.FileFormats/Graphics/VqaReader.cs | 2 - OpenRA.Game/Game.cs | 2 +- OpenRA.Game/Graphics/HardwarePalette.cs | 6 --- OpenRA.Game/Graphics/WorldRenderer.cs | 1 - .../Widgets/Delegates/LobbyDelegate.cs | 26 ++++++------- OpenRA.Mods.RA/ChronoshiftPaletteEffect.cs | 1 - OpenRA.Mods.RA/ColorPickerPaletteModifier.cs | 38 +++++++++++++++++++ OpenRA.Mods.RA/OpenRA.Mods.RA.csproj | 1 + mods/cnc/system.yaml | 1 + mods/ra/system.yaml | 1 + 10 files changed, 53 insertions(+), 26 deletions(-) create mode 100644 OpenRA.Mods.RA/ColorPickerPaletteModifier.cs diff --git a/OpenRA.FileFormats/Graphics/VqaReader.cs b/OpenRA.FileFormats/Graphics/VqaReader.cs index 285905a63b..c2d9b33741 100644 --- a/OpenRA.FileFormats/Graphics/VqaReader.cs +++ b/OpenRA.FileFormats/Graphics/VqaReader.cs @@ -93,14 +93,12 @@ namespace OpenRA.FileFormats frameData = new uint[frameSize,frameSize]; var type = new String(reader.ReadChars(4)); - Console.WriteLine(type); if (type != "FINF") { reader.ReadBytes(27); type = new String(reader.ReadChars(4)); } - Console.WriteLine(type); /*var length = */reader.ReadUInt16(); /*var unknown4 = */reader.ReadUInt16(); diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index fd61b714e5..fc4d6ad08b 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -37,7 +37,7 @@ namespace OpenRA public static World world; public static Viewport viewport; - internal static UserSettings Settings; + public static UserSettings Settings; internal static OrderManager orderManager; diff --git a/OpenRA.Game/Graphics/HardwarePalette.cs b/OpenRA.Game/Graphics/HardwarePalette.cs index aae51e669d..d146f9fc85 100644 --- a/OpenRA.Game/Graphics/HardwarePalette.cs +++ b/OpenRA.Game/Graphics/HardwarePalette.cs @@ -52,16 +52,10 @@ namespace OpenRA.Graphics public void AddPalette(string name, Palette p) { - Console.WriteLine("Adding palette "+name); palettes.Add(name, p); indices.Add(name, allocated++); } - public void UpdatePalette(string name, Palette p) - { - palettes[name] = p; - } - public void Update(IEnumerable paletteMods) { var copy = palettes.ToDictionary(p => p.Key, p => new Palette(p.Value)); diff --git a/OpenRA.Game/Graphics/WorldRenderer.cs b/OpenRA.Game/Graphics/WorldRenderer.cs index e6eafa315e..6780e2ff40 100644 --- a/OpenRA.Game/Graphics/WorldRenderer.cs +++ b/OpenRA.Game/Graphics/WorldRenderer.cs @@ -36,7 +36,6 @@ namespace OpenRA.Graphics public int GetPaletteIndex(string name) { return palette.GetPaletteIndex(name); } public Palette GetPalette(string name) { return palette.GetPalette(name); } public void AddPalette(string name, Palette pal) { palette.AddPalette(name, pal); } - public void UpdatePalette(string name, Palette pal) { palette.UpdatePalette(name, pal); } class SpriteComparer : IComparer { diff --git a/OpenRA.Game/Widgets/Delegates/LobbyDelegate.cs b/OpenRA.Game/Widgets/Delegates/LobbyDelegate.cs index fdeee84d9d..2256b4b198 100644 --- a/OpenRA.Game/Widgets/Delegates/LobbyDelegate.cs +++ b/OpenRA.Game/Widgets/Delegates/LobbyDelegate.cs @@ -20,18 +20,21 @@ namespace OpenRA.Widgets.Delegates public class LobbyDelegate : IWidgetDelegate { Widget Players, LocalPlayerTemplate, RemotePlayerTemplate; - + Dictionary CountryNames; - string MapUid; MapStub Map; - - bool SplitPlayerPalette = false; - Palette BasePlayerPalette = null; + + public static Color CurrentColorPreview1; + public static Color CurrentColorPreview2; + public LobbyDelegate() { Game.LobbyInfoChanged += UpdateCurrentMap; UpdateCurrentMap(); + + CurrentColorPreview1 = Game.Settings.PlayerColor1; + CurrentColorPreview2 = Game.Settings.PlayerColor2; var r = Widget.RootWidget; var lobby = r.GetWidget("SERVER_LOBBY"); @@ -151,13 +154,7 @@ namespace OpenRA.Widgets.Delegates UpdateColorPreview(hueSlider.GetOffset(), satSlider.GetOffset(), lumSlider.GetOffset(), rangeSlider.GetOffset()); UpdatePlayerColor(hueSlider.GetOffset(), satSlider.GetOffset(), lumSlider.GetOffset(), rangeSlider.GetOffset()); return true; - }; - - // Copy the base palette for the colorpicker - var info = Rules.Info["world"].Traits.Get(); - BasePlayerPalette = Game.world.WorldRenderer.GetPalette(info.BasePalette); - SplitPlayerPalette = info.SplitRamp; - Game.world.WorldRenderer.AddPalette("colorpicker",BasePlayerPalette); + }; } void UpdatePlayerColor(float hf, float sf, float lf, float r) @@ -173,9 +170,8 @@ namespace OpenRA.Widgets.Delegates void UpdateColorPreview(float hf, float sf, float lf, float r) { - var c1 = ColorFromHSL(hf, sf, lf); - var c2 = ColorFromHSL(hf, sf, r*lf); - Game.world.WorldRenderer.UpdatePalette("colorpicker", new Palette(BasePlayerPalette, new PlayerColorRemap(c1, c2, SplitPlayerPalette))); + CurrentColorPreview1 = ColorFromHSL(hf, sf, lf); + CurrentColorPreview2 = ColorFromHSL(hf, sf, r*lf); Game.viewport.RefreshPalette(); } diff --git a/OpenRA.Mods.RA/ChronoshiftPaletteEffect.cs b/OpenRA.Mods.RA/ChronoshiftPaletteEffect.cs index 717b5e659c..993983f2b1 100644 --- a/OpenRA.Mods.RA/ChronoshiftPaletteEffect.cs +++ b/OpenRA.Mods.RA/ChronoshiftPaletteEffect.cs @@ -39,7 +39,6 @@ namespace OpenRA.Mods.RA return; var frac = (float)remainingFrames / chronoEffectLength; - System.Console.WriteLine("{0}",frac); var excludePalettes = new List(){"cursor", "chrome", "colorpicker"}; foreach (var pal in palettes) { diff --git a/OpenRA.Mods.RA/ColorPickerPaletteModifier.cs b/OpenRA.Mods.RA/ColorPickerPaletteModifier.cs new file mode 100644 index 0000000000..280ed8d019 --- /dev/null +++ b/OpenRA.Mods.RA/ColorPickerPaletteModifier.cs @@ -0,0 +1,38 @@ +#region Copyright & License Information +/* + * Copyright 2007-2010 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation. For more information, + * see LICENSE. + */ +#endregion + +using System.Drawing; +using OpenRA.Traits; +using System.Collections.Generic; +using OpenRA.FileFormats; +using OpenRA.Widgets.Delegates; + +namespace OpenRA.Mods.RA +{ + class ColorPickerPaletteModifierInfo : TraitInfo {} + + class ColorPickerPaletteModifier : IPaletteModifier, ILoadWorldHook + { + bool SplitPlayerPalette; + public void WorldLoaded(World w) + { + // Copy the base palette for the colorpicker + var info = Rules.Info["world"].Traits.Get(); + SplitPlayerPalette = info.SplitRamp; + w.WorldRenderer.AddPalette("colorpicker", w.WorldRenderer.GetPalette(info.BasePalette)); + } + + public void AdjustPalette(Dictionary palettes) + { + palettes["colorpicker"] = new Palette(palettes["colorpicker"], + new PlayerColorRemap(LobbyDelegate.CurrentColorPreview1, LobbyDelegate.CurrentColorPreview2, SplitPlayerPalette)); + } + } +} diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index cd6fd9a037..de6aeeadfe 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -232,6 +232,7 @@ + diff --git a/mods/cnc/system.yaml b/mods/cnc/system.yaml index 8af3932364..871ddb9dee 100644 --- a/mods/cnc/system.yaml +++ b/mods/cnc/system.yaml @@ -44,6 +44,7 @@ Player: World: ScreenShaker: + ColorPickerPaletteModifier: WaterPaletteRotation: CncMode: true BuildingInfluence: diff --git a/mods/ra/system.yaml b/mods/ra/system.yaml index 3a39c2e59b..576889f487 100644 --- a/mods/ra/system.yaml +++ b/mods/ra/system.yaml @@ -87,6 +87,7 @@ Player: World: ScreenShaker: + ColorPickerPaletteModifier: WaterPaletteRotation: ChronoshiftPaletteEffect: NukePaletteEffect: