diff --git a/OpenRA.FileFormats/Palette.cs b/OpenRA.FileFormats/Palette.cs index 9b96021f6f..08effa4285 100644 --- a/OpenRA.FileFormats/Palette.cs +++ b/OpenRA.FileFormats/Palette.cs @@ -39,6 +39,12 @@ namespace OpenRA.FileFormats get { return colors; } } + public void ApplyRemap(IPaletteRemap r) + { + for(int i = 0; i < 256; i++) + colors[i] = (uint)r.GetRemappedColor(Color.FromArgb((int)colors[i]),i).ToArgb(); + } + public Palette(Stream s, int[] remapShadow) { colors = new uint[256]; @@ -61,9 +67,8 @@ namespace OpenRA.FileFormats public Palette(Palette p, IPaletteRemap r) { - colors = new uint[256]; - for(int i = 0; i < 256; i++) - colors[i] = (uint)r.GetRemappedColor(Color.FromArgb((int)p.colors[i]),i).ToArgb(); + colors = (uint[])p.colors.Clone(); + ApplyRemap(r); } public Palette(Palette p) diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameMenuLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameMenuLogic.cs index b83e0216d4..7d2776a00d 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameMenuLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameMenuLogic.cs @@ -10,6 +10,7 @@ using System; using System.Linq; +using OpenRA.Graphics; using OpenRA.Traits; using OpenRA.Widgets; @@ -20,7 +21,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic Widget menu; [ObjectCreator.UseCtor] - public CncIngameMenuLogic(Widget widget, World world, Action onExit) + public CncIngameMenuLogic(Widget widget, World world, Action onExit, WorldRenderer worldRenderer) { var resumeDisabled = false; menu = widget.Get("INGAME_MENU"); @@ -72,6 +73,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic Ui.OpenWindow("SETTINGS_PANEL", new WidgetArgs() { { "world", world }, + { "worldRenderer", worldRenderer }, { "onExit", () => hideButtons = false }, }); }; diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/CncMenuLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/CncMenuLogic.cs index dabf7b3cdc..64d2152b7c 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/CncMenuLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/CncMenuLogic.cs @@ -85,9 +85,8 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic settingsMenu.Get("SETTINGS_BUTTON").OnClick = () => { Menu = MenuType.None; - Ui.OpenWindow("SETTINGS_PANEL", new WidgetArgs() + Game.OpenWindow("SETTINGS_PANEL", new WidgetArgs() { - { "world", world }, { "onExit", () => Menu = MenuType.Settings }, }); }; diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/CncSettingsLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/CncSettingsLogic.cs index c8641f2b58..8d8fb13bc7 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/CncSettingsLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/CncSettingsLogic.cs @@ -6,6 +6,7 @@ * as published by the Free Software Foundation. For more information, * see COPYING. */ + #endregion using System; @@ -17,6 +18,7 @@ using OpenRA.GameRules; using OpenRA.Mods.RA; using OpenRA.Mods.RA.Widgets.Logic; using OpenRA.Widgets; +using OpenRA.Mods.RA.Widgets; namespace OpenRA.Mods.Cnc.Widgets.Logic { @@ -25,7 +27,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic enum PanelType { General, Input } PanelType Settings = PanelType.General; - ColorPickerPaletteModifier playerPalettePreview; + ColorPreviewManagerWidget colorPreview; World world; [ObjectCreator.UseCtor] @@ -52,8 +54,8 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic var nameTextfield = generalPane.Get("NAME_TEXTFIELD"); nameTextfield.Text = playerSettings.Name; - playerPalettePreview = world.WorldActor.Trait(); - playerPalettePreview.Ramp = playerSettings.ColorRamp; + colorPreview = panel.Get("COLOR_MANAGER"); + colorPreview.Ramp = playerSettings.ColorRamp; var colorDropdown = generalPane.Get("COLOR"); colorDropdown.OnMouseDown = _ => ShowColorPicker(colorDropdown, playerSettings); @@ -153,8 +155,8 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic bool ShowColorPicker(DropDownButtonWidget color, PlayerSettings s) { - Action onSelect = c => { s.ColorRamp = c; color.RemovePanel(); }; - Action onChange = c => { playerPalettePreview.Ramp = c; }; + Action onSelect = c => {s.ColorRamp = c; color.RemovePanel();}; + Action onChange = c => {colorPreview.Ramp = c;}; var colorChooser = Game.LoadWidget(world, "COLOR_CHOOSER", null, new WidgetArgs() { diff --git a/OpenRA.Mods.RA/ColorPickerPaletteModifier.cs b/OpenRA.Mods.RA/ColorPickerPaletteModifier.cs deleted file mode 100644 index ba343c9d53..0000000000 --- a/OpenRA.Mods.RA/ColorPickerPaletteModifier.cs +++ /dev/null @@ -1,47 +0,0 @@ -#region Copyright & License Information -/* - * Copyright 2007-2011 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 COPYING. - */ -#endregion - -using System.Collections.Generic; -using System.Linq; -using OpenRA.FileFormats; -using OpenRA.Graphics; -using OpenRA.Traits; - -namespace OpenRA.Mods.RA -{ - public class ColorPickerPaletteModifierInfo : ITraitInfo - { - public string PlayerPalette = "player"; - public object Create( ActorInitializer init ) { return new ColorPickerPaletteModifier( this ); } - } - - public class ColorPickerPaletteModifier : IPalette, IPaletteModifier - { - ColorPickerPaletteModifierInfo Info; - int[] index; - public ColorRamp Ramp; - - public ColorPickerPaletteModifier(ColorPickerPaletteModifierInfo info) { Info = info; } - - public void InitPalette( WorldRenderer wr ) - { - var info = Rules.Info["player"].Traits.WithInterface() - .First(p => p.BaseName == Info.PlayerPalette); - index = info.RemapIndex; - wr.AddPalette("colorpicker", wr.GetPalette(info.BasePalette)); - } - - public void AdjustPalette(Dictionary palettes) - { - palettes["colorpicker"] = new Palette(palettes["colorpicker"], - new PlayerColorRemap(index, Ramp)); - } - } -} diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index c88eb29ed0..3553a0b857 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -169,7 +169,6 @@ - @@ -407,6 +406,7 @@ + diff --git a/OpenRA.Mods.RA/Widgets/ColorPreviewManagerWidget.cs b/OpenRA.Mods.RA/Widgets/ColorPreviewManagerWidget.cs new file mode 100755 index 0000000000..9b2a144b6d --- /dev/null +++ b/OpenRA.Mods.RA/Widgets/ColorPreviewManagerWidget.cs @@ -0,0 +1,54 @@ +#region Copyright & License Information +/* + * Copyright 2007-2011 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 COPYING. + */ + +#endregion + +using System; +using System.Linq; +using OpenRA.FileFormats; +using OpenRA.Graphics; +using OpenRA.Traits; +using OpenRA.Widgets; + +namespace OpenRA.Mods.RA.Widgets +{ + public class ColorPreviewManagerWidget : Widget + { + public readonly string Palette = "colorpicker"; + public readonly int[] RemapIndices = {}; + public ColorRamp Ramp; + + ColorRamp cachedRamp; + WorldRenderer worldRenderer; + Palette preview; + + [ObjectCreator.UseCtor] + public ColorPreviewManagerWidget(WorldRenderer worldRenderer) + : base() + { + this.worldRenderer = worldRenderer; + } + + public override void Initialize(WidgetArgs args) + { + base.Initialize(args); + preview = worldRenderer.GetPalette(Palette); + } + + public override void Tick() + { + if (cachedRamp == Ramp) + return; + + preview.ApplyRemap(new PlayerColorRemap(RemapIndices, Ramp)); + cachedRamp = Ramp; + } + } +} + diff --git a/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs index 8319f2d033..2cfeb4ec4a 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs @@ -30,7 +30,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic string MapUid; Map Map; - ColorPickerPaletteModifier PlayerPalettePreview; + ColorPreviewManagerWidget colorPreview; readonly Action OnGameStart; readonly Action onExit; @@ -96,8 +96,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic Game.ConnectionStateChanged += ConnectionStateChanged; UpdateCurrentMap(); - PlayerPalettePreview = world.WorldActor.Trait(); - PlayerPalettePreview.Ramp = Game.Settings.Player.ColorRamp; Players = lobby.Get("PLAYERS"); EditablePlayerTemplate = Players.Get("TEMPLATE_EDITABLE_PLAYER"); NonEditablePlayerTemplate = Players.Get("TEMPLATE_NONEDITABLE_PLAYER"); @@ -105,6 +103,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic EditableSpectatorTemplate = Players.Get("TEMPLATE_EDITABLE_SPECTATOR"); NonEditableSpectatorTemplate = Players.Get("TEMPLATE_NONEDITABLE_SPECTATOR"); NewSpectatorTemplate = Players.Get("TEMPLATE_NEW_SPECTATOR"); + colorPreview = lobby.Get("COLOR_MANAGER"); + colorPreview.Ramp = Game.Settings.Player.ColorRamp; var mapPreview = lobby.Get("MAP_PREVIEW"); mapPreview.IsVisible = () => Map != null; @@ -341,7 +341,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic var color = template.Get("COLOR"); color.IsDisabled = () => slot.LockColor || ready; - color.OnMouseDown = _ => LobbyUtils.ShowColorDropDown(color, client, orderManager, PlayerPalettePreview); + color.OnMouseDown = _ => LobbyUtils.ShowColorDropDown(color, client, orderManager, colorPreview); var colorBlock = color.Get("COLORBLOCK"); colorBlock.GetColor = () => client.ColorRamp.GetColor(0); @@ -421,7 +421,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic var color = template.Get("COLOR"); color.IsDisabled = () => ready; - color.OnMouseDown = _ => LobbyUtils.ShowColorDropDown(color, c, orderManager, PlayerPalettePreview); + color.OnMouseDown = _ => LobbyUtils.ShowColorDropDown(color, c, orderManager, colorPreview); var colorBlock = color.Get("COLORBLOCK"); colorBlock.GetColor = () => c.ColorRamp.GetColor(0); diff --git a/OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs b/OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs index fd0ab270f2..d752b16959 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs @@ -121,7 +121,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic } public static void ShowColorDropDown(DropDownButtonWidget color, Session.Client client, - OrderManager orderManager, ColorPickerPaletteModifier preview) + OrderManager orderManager, ColorPreviewManagerWidget preview) { Action onSelect = c => { diff --git a/mods/cnc/chrome/lobby.yaml b/mods/cnc/chrome/lobby.yaml index ae731e3584..ff2cb1bb77 100644 --- a/mods/cnc/chrome/lobby.yaml +++ b/mods/cnc/chrome/lobby.yaml @@ -5,6 +5,8 @@ Container@SERVER_LOBBY: Width:740 Height:535 Children: + ColorPreviewManager@COLOR_MANAGER: + RemapIndices: 176, 178, 180, 182, 184, 186, 189, 191, 177, 179, 181, 183, 185, 187, 188, 190 Label@TITLE: Width:740 Y:0-25 diff --git a/mods/cnc/chrome/settings.yaml b/mods/cnc/chrome/settings.yaml index 7b97795882..64c6adda52 100644 --- a/mods/cnc/chrome/settings.yaml +++ b/mods/cnc/chrome/settings.yaml @@ -5,6 +5,8 @@ Container@SETTINGS_PANEL: Width:740 Height:535 Children: + ColorPreviewManager@COLOR_MANAGER: + RemapIndices: 176, 178, 180, 182, 184, 186, 189, 191, 177, 179, 181, 183, 185, 187, 188, 190 Label@TITLE: Width:740 Y:0-25 diff --git a/mods/cnc/rules/system.yaml b/mods/cnc/rules/system.yaml index dea084e9f2..f968a228b6 100644 --- a/mods/cnc/rules/system.yaml +++ b/mods/cnc/rules/system.yaml @@ -80,6 +80,10 @@ World: Name: effect Filename: temperat.pal ShadowIndex: 4 + PaletteFromFile@colorpicker: + Name: colorpicker + Filename: temperat.pal + ShadowIndex: 4 PaletteFromRGBA@shadow: Name: shadow R: 0 @@ -104,7 +108,6 @@ World: G: 0 B: 0 A: 180 - ColorPickerPaletteModifier: ShroudPalette@shroud: ShroudPalette@fog: IsFog: yes diff --git a/mods/d2k/chrome/lobby.yaml b/mods/d2k/chrome/lobby.yaml index 65d6c6fcee..3e96577e50 100644 --- a/mods/d2k/chrome/lobby.yaml +++ b/mods/d2k/chrome/lobby.yaml @@ -5,6 +5,8 @@ Background@SERVER_LOBBY: Width:800 Height:600 Children: + ColorPreviewManager@COLOR_MANAGER: + RemapIndices: 255, 254, 253, 252, 251, 250, 249, 248, 247, 246, 245, 244, 243, 242, 241, 240 Label@TITLE: X:0 Y:17 diff --git a/mods/d2k/rules/system.yaml b/mods/d2k/rules/system.yaml index e22bd4e6c4..31c6ffc05e 100644 --- a/mods/d2k/rules/system.yaml +++ b/mods/d2k/rules/system.yaml @@ -269,6 +269,10 @@ World: Name: effect Filename: temperat.pal ShadowIndex: 4 + PaletteFromFile@colorpicker: + Name: colorpicker + Filename: d2k.pal + ShadowIndex: 4 PaletteFromRGBA@shadow: Name: shadow R: 0 @@ -299,7 +303,6 @@ World: G: 0 B: 0 A: 180 - ColorPickerPaletteModifier: ShroudPalette@shroud: ShroudPalette@fog: IsFog: yes diff --git a/mods/ra/chrome/lobby.yaml b/mods/ra/chrome/lobby.yaml index a57f11c6d8..15b7d3d92b 100644 --- a/mods/ra/chrome/lobby.yaml +++ b/mods/ra/chrome/lobby.yaml @@ -5,6 +5,8 @@ Background@SERVER_LOBBY: Width:800 Height:600 Children: + ColorPreviewManager@COLOR_MANAGER: + RemapIndices: 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95 Label@TITLE: X:0 Y:17 diff --git a/mods/ra/rules/system.yaml b/mods/ra/rules/system.yaml index d3245ddd48..eb0fd1a1ea 100644 --- a/mods/ra/rules/system.yaml +++ b/mods/ra/rules/system.yaml @@ -224,6 +224,10 @@ World: Name: effect Filename: temperat.pal ShadowIndex: 4 + PaletteFromFile@colorpicker: + Name: colorpicker + Filename: temperat.pal + ShadowIndex: 4 PaletteFromRGBA@shadow: Name: shadow R: 0 @@ -254,7 +258,6 @@ World: G: 0 B: 0 A: 180 - ColorPickerPaletteModifier: ShroudPalette@shroud: ShroudPalette@fog: IsFog: yes