Rework color picker palette modification.

The old method had the lobby code dig around inside
the palette modification machinery, which was a giant
hack preventing necessary streamlining.
This commit is contained in:
Paul Chote
2013-02-21 18:48:31 +13:00
parent 750bdb7bba
commit f593807617
16 changed files with 100 additions and 68 deletions

View File

@@ -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)

View File

@@ -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 },
});
};

View File

@@ -85,9 +85,8 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
settingsMenu.Get<ButtonWidget>("SETTINGS_BUTTON").OnClick = () =>
{
Menu = MenuType.None;
Ui.OpenWindow("SETTINGS_PANEL", new WidgetArgs()
Game.OpenWindow("SETTINGS_PANEL", new WidgetArgs()
{
{ "world", world },
{ "onExit", () => Menu = MenuType.Settings },
});
};

View File

@@ -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<TextFieldWidget>("NAME_TEXTFIELD");
nameTextfield.Text = playerSettings.Name;
playerPalettePreview = world.WorldActor.Trait<ColorPickerPaletteModifier>();
playerPalettePreview.Ramp = playerSettings.ColorRamp;
colorPreview = panel.Get<ColorPreviewManagerWidget>("COLOR_MANAGER");
colorPreview.Ramp = playerSettings.ColorRamp;
var colorDropdown = generalPane.Get<DropDownButtonWidget>("COLOR");
colorDropdown.OnMouseDown = _ => ShowColorPicker(colorDropdown, playerSettings);
@@ -154,7 +156,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
bool ShowColorPicker(DropDownButtonWidget color, PlayerSettings s)
{
Action<ColorRamp> onSelect = c => {s.ColorRamp = c; color.RemovePanel();};
Action<ColorRamp> onChange = c => { playerPalettePreview.Ramp = c; };
Action<ColorRamp> onChange = c => {colorPreview.Ramp = c;};
var colorChooser = Game.LoadWidget(world, "COLOR_CHOOSER", null, new WidgetArgs()
{

View File

@@ -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<PlayerColorPaletteInfo>()
.First(p => p.BaseName == Info.PlayerPalette);
index = info.RemapIndex;
wr.AddPalette("colorpicker", wr.GetPalette(info.BasePalette));
}
public void AdjustPalette(Dictionary<string, Palette> palettes)
{
palettes["colorpicker"] = new Palette(palettes["colorpicker"],
new PlayerColorRemap(index, Ramp));
}
}
}

View File

@@ -169,7 +169,6 @@
<Compile Include="ChronoshiftPaletteEffect.cs" />
<Compile Include="Chronoshiftable.cs" />
<Compile Include="Cloak.cs" />
<Compile Include="ColorPickerPaletteModifier.cs" />
<Compile Include="Combat.cs" />
<Compile Include="ConquestVictoryConditions.cs" />
<Compile Include="ContainsCrate.cs" />
@@ -407,6 +406,7 @@
<Compile Include="RenderShroudCircle.cs" />
<Compile Include="Widgets\Logic\CheatsLogic.cs" />
<Compile Include="CloakPaletteEffect.cs" />
<Compile Include="Widgets\ColorPreviewManagerWidget.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">

View File

@@ -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;
}
}
}

View File

@@ -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<ColorPickerPaletteModifier>();
PlayerPalettePreview.Ramp = Game.Settings.Player.ColorRamp;
Players = lobby.Get<ScrollPanelWidget>("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<ColorPreviewManagerWidget>("COLOR_MANAGER");
colorPreview.Ramp = Game.Settings.Player.ColorRamp;
var mapPreview = lobby.Get<MapPreviewWidget>("MAP_PREVIEW");
mapPreview.IsVisible = () => Map != null;
@@ -341,7 +341,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
var color = template.Get<DropDownButtonWidget>("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<ColorBlockWidget>("COLORBLOCK");
colorBlock.GetColor = () => client.ColorRamp.GetColor(0);
@@ -421,7 +421,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
var color = template.Get<DropDownButtonWidget>("COLOR");
color.IsDisabled = () => ready;
color.OnMouseDown = _ => LobbyUtils.ShowColorDropDown(color, c, orderManager, PlayerPalettePreview);
color.OnMouseDown = _ => LobbyUtils.ShowColorDropDown(color, c, orderManager, colorPreview);
var colorBlock = color.Get<ColorBlockWidget>("COLORBLOCK");
colorBlock.GetColor = () => c.ColorRamp.GetColor(0);

View File

@@ -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<ColorRamp> onSelect = c =>
{

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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