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

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