Remove hardcoded list of palette mod exclusions.

This commit is contained in:
Paul Chote
2013-02-21 18:48:31 +13:00
parent f593807617
commit db7887687b
17 changed files with 29 additions and 37 deletions

View File

@@ -34,7 +34,7 @@ namespace OpenRA.Graphics
} }
foreach (var s in sequences.NodesDict["Palettes"].Nodes) foreach (var s in sequences.NodesDict["Palettes"].Nodes)
Game.modData.Palette.AddPalette(s.Key, new Palette(FileSystem.Open(s.Value.Value), ShadowIndex)); Game.modData.Palette.AddPalette(s.Key, new Palette(FileSystem.Open(s.Value.Value), ShadowIndex), false);
foreach (var s in sequences.NodesDict["Cursors"].Nodes) foreach (var s in sequences.NodesDict["Cursors"].Nodes)
LoadSequencesForCursor(s.Key, s.Value); LoadSequencesForCursor(s.Key, s.Value);

View File

@@ -25,11 +25,13 @@ namespace OpenRA.Graphics
ITexture texture; ITexture texture;
Dictionary<string, Palette> palettes; Dictionary<string, Palette> palettes;
Dictionary<string, int> indices; Dictionary<string, int> indices;
Dictionary<string, bool> allowsMods;
public HardwarePalette() public HardwarePalette()
{ {
palettes = new Dictionary<string, Palette>(); palettes = new Dictionary<string, Palette>();
indices = new Dictionary<string, int>(); indices = new Dictionary<string, int>();
allowsMods = new Dictionary<string, bool>();
texture = Game.Renderer.Device.CreateTexture(); texture = Game.Renderer.Device.CreateTexture();
} }
@@ -49,22 +51,24 @@ namespace OpenRA.Graphics
return ret; return ret;
} }
public void AddPalette(string name, Palette p) public void AddPalette(string name, Palette p, bool allowModifiers)
{ {
if (palettes.ContainsKey(name)) if (palettes.ContainsKey(name))
throw new InvalidOperationException("Palette {0} has already been defined".F(name)); throw new InvalidOperationException("Palette {0} has already been defined".F(name));
palettes.Add(name, p); palettes.Add(name, p);
indices.Add(name, allocated++); indices.Add(name, allocated++);
allowsMods.Add(name, allowModifiers);
} }
uint[,] data = new uint[MaxPalettes, 256]; uint[,] data = new uint[MaxPalettes, 256];
public void Update(IEnumerable<IPaletteModifier> paletteMods) public void Update(IEnumerable<IPaletteModifier> paletteMods)
{ {
var copy = palettes.ToDictionary(p => p.Key, p => new Palette(p.Value)); var copy = palettes.ToDictionary(p => p.Key, p => new Palette(p.Value));
var modifiable = copy.Where(p => allowsMods[p.Key]).ToDictionary(p => p.Key, p => p.Value);
foreach (var mod in paletteMods) foreach (var mod in paletteMods)
mod.AdjustPalette(copy); mod.AdjustPalette(modifiable);
foreach (var pal in copy) foreach (var pal in copy)
{ {

View File

@@ -37,7 +37,7 @@ namespace OpenRA.Graphics
public int GetPaletteIndex(string name) { return palette.GetPaletteIndex(name); } public int GetPaletteIndex(string name) { return palette.GetPaletteIndex(name); }
public Palette GetPalette(string name) { return palette.GetPalette(name); } public Palette GetPalette(string name) { return palette.GetPalette(name); }
public void AddPalette(string name, Palette pal) { palette.AddPalette(name, pal); } public void AddPalette(string name, Palette pal, bool allowModifiers) { palette.AddPalette(name, pal, allowModifiers); }
class SpriteComparer : IComparer<Renderable> class SpriteComparer : IComparer<Renderable>
{ {

View File

@@ -18,6 +18,7 @@ namespace OpenRA.Traits
public readonly string BasePalette = null; public readonly string BasePalette = null;
public readonly string BaseName = "player"; public readonly string BaseName = "player";
public readonly int[] RemapIndex = {}; public readonly int[] RemapIndex = {};
public readonly bool AllowModifiers = true;
public object Create( ActorInitializer init ) { return new PlayerColorPalette( init.self.Owner, this ); } public object Create( ActorInitializer init ) { return new PlayerColorPalette( init.self.Owner, this ); }
} }
@@ -38,7 +39,7 @@ namespace OpenRA.Traits
var paletteName = "{0}{1}".F( info.BaseName, owner.InternalName ); var paletteName = "{0}{1}".F( info.BaseName, owner.InternalName );
var newpal = new Palette(wr.GetPalette(info.BasePalette), var newpal = new Palette(wr.GetPalette(info.BasePalette),
new PlayerColorRemap(info.RemapIndex, owner.ColorRamp)); new PlayerColorRemap(info.RemapIndex, owner.ColorRamp));
wr.AddPalette(paletteName, newpal); wr.AddPalette(paletteName, newpal, info.AllowModifiers);
} }
} }
} }

View File

@@ -61,8 +61,6 @@ namespace OpenRA.Mods.Cnc
} }
} }
static Set<string> excludePalettes = new Set<string>("cursor", "chrome", "colorpicker", "shroud", "fog");
public void AdjustPalette(Dictionary<string,Palette> palettes) public void AdjustPalette(Dictionary<string,Palette> palettes)
{ {
if (to == EffectType.None && remainingFrames == 0) if (to == EffectType.None && remainingFrames == 0)
@@ -70,9 +68,6 @@ namespace OpenRA.Mods.Cnc
foreach (var pal in palettes) foreach (var pal in palettes)
{ {
if (excludePalettes.Contains(pal.Key))
continue;
for (var x = 0; x < 256; x++) for (var x = 0; x < 256; x++)
{ {
var orig = pal.Value.GetColor(x); var orig = pal.Value.GetColor(x);

View File

@@ -33,8 +33,6 @@ namespace OpenRA.Mods.RA
remainingFrames--; remainingFrames--;
} }
static List<string> excludePalettes = new List<string>{"cursor", "chrome", "colorpicker", "shroud", "fog"};
public void AdjustPalette(Dictionary<string,Palette> palettes) public void AdjustPalette(Dictionary<string,Palette> palettes)
{ {
if (remainingFrames == 0) if (remainingFrames == 0)
@@ -44,9 +42,6 @@ namespace OpenRA.Mods.RA
foreach (var pal in palettes) foreach (var pal in palettes)
{ {
if (excludePalettes.Contains(pal.Key))
continue;
for (var x = 0; x < 256; x++) for (var x = 0; x < 256; x++)
{ {
var orig = pal.Value.GetColor(x); var orig = pal.Value.GetColor(x);

View File

@@ -24,15 +24,10 @@ namespace OpenRA.Mods.RA
t += .5f; t += .5f;
} }
static readonly string[] ExcludePalettes = { "cursor", "chrome", "colorpicker", "terrain" };
public void AdjustPalette(Dictionary<string,Palette> palettes) public void AdjustPalette(Dictionary<string,Palette> palettes)
{ {
foreach (var pal in palettes) foreach (var pal in palettes)
{ {
if (ExcludePalettes.Contains(pal.Key))
continue;
var rotate = (int)t % 18; var rotate = (int)t % 18;
if (rotate > 9) if (rotate > 9)
rotate = 18 - rotate; rotate = 18 - rotate;

View File

@@ -33,8 +33,6 @@ namespace OpenRA.Mods.RA
remainingFrames--; remainingFrames--;
} }
static List<string> excludePalettes = new List<string>{ "cursor", "chrome", "colorpicker", "shroud", "fog" };
public void AdjustPalette(Dictionary<string,Palette> palettes) public void AdjustPalette(Dictionary<string,Palette> palettes)
{ {
if (remainingFrames == 0) if (remainingFrames == 0)
@@ -44,9 +42,6 @@ namespace OpenRA.Mods.RA
foreach (var pal in palettes) foreach (var pal in palettes)
{ {
if (excludePalettes.Contains(pal.Key))
continue;
for (var x = 0; x < 256; x++) for (var x = 0; x < 256; x++)
{ {
var orig = pal.Value.GetColor(x); var orig = pal.Value.GetColor(x);

View File

@@ -17,6 +17,7 @@ namespace OpenRA.Mods.RA
{ {
public readonly string Name = null; public readonly string Name = null;
public readonly int[] ShadowIndex = { }; public readonly int[] ShadowIndex = { };
public readonly bool AllowModifiers = true;
public object Create(ActorInitializer init) { return new PaletteFromCurrentTileset(init.world, this); } public object Create(ActorInitializer init) { return new PaletteFromCurrentTileset(init.world, this); }
} }
@@ -34,7 +35,7 @@ namespace OpenRA.Mods.RA
public void InitPalette(OpenRA.Graphics.WorldRenderer wr) public void InitPalette(OpenRA.Graphics.WorldRenderer wr)
{ {
wr.AddPalette( info.Name, new Palette( FileSystem.Open( world.TileSet.Palette ), info.ShadowIndex ) ); wr.AddPalette(info.Name, new Palette(FileSystem.Open(world.TileSet.Palette), info.ShadowIndex), info.AllowModifiers);
} }
} }
} }

View File

@@ -20,6 +20,7 @@ namespace OpenRA.Mods.RA
public readonly string Tileset = null; public readonly string Tileset = null;
public readonly string Filename = null; public readonly string Filename = null;
public readonly int[] ShadowIndex = { }; public readonly int[] ShadowIndex = { };
public readonly bool AllowModifiers = true;
public object Create(ActorInitializer init) { return new PaletteFromFile(init.world, this); } public object Create(ActorInitializer init) { return new PaletteFromFile(init.world, this); }
} }
@@ -37,7 +38,7 @@ namespace OpenRA.Mods.RA
public void InitPalette(WorldRenderer wr) public void InitPalette(WorldRenderer wr)
{ {
if (info.Tileset == null || info.Tileset.ToLowerInvariant() == world.Map.Tileset.ToLowerInvariant()) if (info.Tileset == null || info.Tileset.ToLowerInvariant() == world.Map.Tileset.ToLowerInvariant())
wr.AddPalette( info.Name, new Palette( FileSystem.Open( info.Filename ), info.ShadowIndex ) ); wr.AddPalette(info.Name, new Palette(FileSystem.Open(info.Filename), info.ShadowIndex), info.AllowModifiers);
} }
} }
} }

View File

@@ -23,6 +23,7 @@ namespace OpenRA.Mods.RA
public readonly int G = 0; public readonly int G = 0;
public readonly int B = 0; public readonly int B = 0;
public readonly int A = 255; public readonly int A = 255;
public readonly bool AllowModifiers = true;
public object Create(ActorInitializer init) { return new PaletteFromRGBA(init.world, this); } public object Create(ActorInitializer init) { return new PaletteFromRGBA(init.world, this); }
} }
@@ -43,7 +44,7 @@ namespace OpenRA.Mods.RA
{ {
// TODO: This shouldn't rely on a base palette // TODO: This shouldn't rely on a base palette
var pal = wr.GetPalette("terrain"); var pal = wr.GetPalette("terrain");
wr.AddPalette(info.Name, new Palette(pal, new SingleColorRemap(Color.FromArgb(info.A, info.R, info.G, info.B)))); wr.AddPalette(info.Name, new Palette(pal, new SingleColorRemap(Color.FromArgb(info.A, info.R, info.G, info.B))), info.AllowModifiers);
} }
} }
} }

View File

@@ -17,6 +17,7 @@ namespace OpenRA.Mods.RA
{ {
public readonly string Name = null; public readonly string Name = null;
public readonly int[] ShadowIndex = { }; public readonly int[] ShadowIndex = { };
public readonly bool AllowModifiers = true;
public object Create(ActorInitializer init) { return new PlayerPaletteFromCurrentTileset(init.world, this); } public object Create(ActorInitializer init) { return new PlayerPaletteFromCurrentTileset(init.world, this); }
} }
@@ -35,7 +36,7 @@ namespace OpenRA.Mods.RA
public void InitPalette (OpenRA.Graphics.WorldRenderer wr) public void InitPalette (OpenRA.Graphics.WorldRenderer wr)
{ {
string Filename = world.TileSet.PlayerPalette == null ? world.TileSet.Palette : world.TileSet.PlayerPalette; string Filename = world.TileSet.PlayerPalette == null ? world.TileSet.Palette : world.TileSet.PlayerPalette;
wr.AddPalette(info.Name, new Palette(FileSystem.Open(Filename), info.ShadowIndex)); wr.AddPalette(info.Name, new Palette(FileSystem.Open(Filename), info.ShadowIndex), info.AllowModifiers);
} }
} }
} }

View File

@@ -32,7 +32,7 @@ namespace OpenRA.Mods.RA
public void InitPalette(WorldRenderer wr) public void InitPalette(WorldRenderer wr)
{ {
var pal = wr.GetPalette("terrain"); var pal = wr.GetPalette("terrain");
wr.AddPalette( info.Name, new Palette( pal, new ShroudPaletteRemap( info.IsFog ) ) ); wr.AddPalette(info.Name, new Palette(pal, new ShroudPaletteRemap(info.IsFog)), false);
} }
} }

View File

@@ -17,7 +17,7 @@ namespace OpenRA.Mods.RA
{ {
class WaterPaletteRotationInfo : ITraitInfo class WaterPaletteRotationInfo : ITraitInfo
{ {
public readonly string[] ExcludePalettes = { "cursor", "chrome", "colorpicker", "player" }; public readonly string[] ExcludePalettes = {};
public object Create(ActorInitializer init) { return new WaterPaletteRotation(init.world, this); } public object Create(ActorInitializer init) { return new WaterPaletteRotation(init.world, this); }
} }

View File

@@ -84,6 +84,7 @@ World:
Name: colorpicker Name: colorpicker
Filename: temperat.pal Filename: temperat.pal
ShadowIndex: 4 ShadowIndex: 4
AllowModifiers: false
PaletteFromRGBA@shadow: PaletteFromRGBA@shadow:
Name: shadow Name: shadow
R: 0 R: 0

View File

@@ -273,6 +273,7 @@ World:
Name: colorpicker Name: colorpicker
Filename: d2k.pal Filename: d2k.pal
ShadowIndex: 4 ShadowIndex: 4
AllowModifiers: false
PaletteFromRGBA@shadow: PaletteFromRGBA@shadow:
Name: shadow Name: shadow
R: 0 R: 0

View File

@@ -228,6 +228,7 @@ World:
Name: colorpicker Name: colorpicker
Filename: temperat.pal Filename: temperat.pal
ShadowIndex: 4 ShadowIndex: 4
AllowModifiers: false
PaletteFromRGBA@shadow: PaletteFromRGBA@shadow:
Name: shadow Name: shadow
R: 0 R: 0