support d2k remap range

This commit is contained in:
Paul Chote
2010-09-12 00:55:05 +12:00
parent 7e5b861caf
commit 629e73ac29
6 changed files with 13 additions and 10 deletions

View File

@@ -15,15 +15,16 @@ using System.Linq;
namespace OpenRA.FileFormats namespace OpenRA.FileFormats
{ {
// TODO: ship this out of here. // TODO: ship this out of here.
public enum PaletteFormat { ra, cnc, d2k }
public class PlayerColorRemap : IPaletteRemap public class PlayerColorRemap : IPaletteRemap
{ {
Dictionary<int, Color> remapColors; Dictionary<int, Color> remapColors;
public PlayerColorRemap(Color c1, Color c2, bool useSplitRamp) public PlayerColorRemap(Color c1, Color c2, PaletteFormat fmt)
{ {
var baseIndex = useSplitRamp ? 0xb0 : 80; var baseIndex = (fmt == PaletteFormat.cnc) ? 0xb0 : (fmt == PaletteFormat.d2k) ? 240 : 80;
var ramp = useSplitRamp var ramp = (fmt == PaletteFormat.cnc)
? new[] { 0, 2, 4, 6, 8, 10, 13, 15, 1, 3, 5, 7, 9, 11, 12, 14 } ? new[] { 0, 2, 4, 6, 8, 10, 13, 15, 1, 3, 5, 7, 9, 11, 12, 14 }
: new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; : new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };

View File

@@ -93,7 +93,7 @@ namespace OpenRA
{ {
var info = Rules.Info["world"].Traits.Get<PlayerColorPaletteInfo>(); var info = Rules.Info["world"].Traits.Get<PlayerColorPaletteInfo>();
var newpal = new Palette(world.WorldRenderer.GetPalette(info.BasePalette), var newpal = new Palette(world.WorldRenderer.GetPalette(info.BasePalette),
new PlayerColorRemap(Color, Color2, info.SplitRamp)); new PlayerColorRemap(Color, Color2, info.PaletteFormat));
world.WorldRenderer.AddPalette(palette, newpal); world.WorldRenderer.AddPalette(palette, newpal);
} }

View File

@@ -8,12 +8,13 @@
*/ */
#endregion #endregion
using OpenRA.FileFormats;
namespace OpenRA.Traits namespace OpenRA.Traits
{ {
public class PlayerColorPaletteInfo : TraitInfo<PlayerColorPalette> public class PlayerColorPaletteInfo : TraitInfo<PlayerColorPalette>
{ {
public readonly string BasePalette = null; public readonly string BasePalette = null;
public readonly bool SplitRamp = false; public readonly PaletteFormat PaletteFormat = PaletteFormat.ra;
} }
public class PlayerColorPalette {} public class PlayerColorPalette {}

View File

@@ -19,12 +19,12 @@ namespace OpenRA.Mods.RA
class ColorPickerPaletteModifier : IPaletteModifier, IWorldLoaded class ColorPickerPaletteModifier : IPaletteModifier, IWorldLoaded
{ {
bool SplitPlayerPalette; PaletteFormat format;
public void WorldLoaded(World w) public void WorldLoaded(World w)
{ {
// Copy the base palette for the colorpicker // Copy the base palette for the colorpicker
var info = Rules.Info["world"].Traits.Get<PlayerColorPaletteInfo>(); var info = Rules.Info["world"].Traits.Get<PlayerColorPaletteInfo>();
SplitPlayerPalette = info.SplitRamp; format = info.PaletteFormat;
w.WorldRenderer.AddPalette("colorpicker", w.WorldRenderer.GetPalette(info.BasePalette)); w.WorldRenderer.AddPalette("colorpicker", w.WorldRenderer.GetPalette(info.BasePalette));
} }
@@ -32,7 +32,7 @@ namespace OpenRA.Mods.RA
{ {
palettes["colorpicker"] = new Palette(palettes["colorpicker"], palettes["colorpicker"] = new Palette(palettes["colorpicker"],
new PlayerColorRemap(LobbyDelegate.CurrentColorPreview1, new PlayerColorRemap(LobbyDelegate.CurrentColorPreview1,
LobbyDelegate.CurrentColorPreview2, SplitPlayerPalette)); LobbyDelegate.CurrentColorPreview2, format));
} }
} }
} }

View File

@@ -54,7 +54,7 @@ World:
Name: terrain Name: terrain
PlayerColorPalette: PlayerColorPalette:
BasePalette: terrain BasePalette: terrain
SplitRamp: yes PaletteFormat: cnc
PaletteFromFile@chrome: PaletteFromFile@chrome:
Name: chrome Name: chrome
Filename: temperat.pal Filename: temperat.pal

View File

@@ -15,6 +15,7 @@ World:
Name: terrain Name: terrain
PlayerColorPalette: PlayerColorPalette:
BasePalette: units BasePalette: units
PaletteFormat: d2k
PaletteFromFile@units: PaletteFromFile@units:
Name: units Name: units
Filename: units.pal Filename: units.pal