made palette shadowindex configurable

This commit is contained in:
Matthias Mailänder
2012-06-26 23:21:30 +02:00
committed by Chris Forbes
parent 007b2c5434
commit c75c72b525
14 changed files with 62 additions and 36 deletions

View File

@@ -138,7 +138,8 @@ namespace OpenRA.Editor
Rules.LoadRules(manifest, map); Rules.LoadRules(manifest, map);
tileset = Rules.TileSets[map.Tileset]; tileset = Rules.TileSets[map.Tileset];
tileset.LoadTiles(); tileset.LoadTiles();
var palette = new Palette(FileSystem.Open(tileset.Palette), true); int[] ShadowIndex = { 3, 4 };
var palette = new Palette(FileSystem.Open(tileset.Palette), ShadowIndex);
surface1.Bind(map, tileset, palette); surface1.Bind(map, tileset, palette);
// construct the palette of tiles // construct the palette of tiles

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information #region Copyright & License Information
/* /*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS) * Copyright 2007-2012 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made * 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 * available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information, * as published by the Free Software Foundation. For more information,
@@ -39,7 +39,7 @@ namespace OpenRA.FileFormats
get { return colors; } get { return colors; }
} }
public Palette(Stream s, bool remapTransparent) public Palette(Stream s, int[] remapShadow)
{ {
colors = new uint[256]; colors = new uint[256];
@@ -54,13 +54,9 @@ namespace OpenRA.FileFormats
} }
} }
colors[0] = 0; colors[0] = 0; //convert black background to transparency
if (remapTransparent) foreach (int i in remapShadow)
{ colors[i] = 140u << 24;
colors[1] = 178u << 24; // Hack for d2k; may have side effects
colors[3] = 178u << 24;
colors[4] = 140u << 24;
}
} }
public Palette(Palette p, IPaletteRemap r) public Palette(Palette p, IPaletteRemap r)
@@ -92,12 +88,12 @@ namespace OpenRA.FileFormats
return pal; return pal;
} }
public static Palette Load( string filename, bool remap ) public static Palette Load(string filename, int[] remap)
{ {
using(var s = File.OpenRead(filename)) using(var s = File.OpenRead(filename))
return new Palette(s, remap); return new Palette(s, remap);
} }
} }
public interface IPaletteRemap { Color GetRemappedColor(Color original, int index); } public interface IPaletteRemap { Color GetRemappedColor(Color original, int index); }
} }

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information #region Copyright & License Information
/* /*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS) * Copyright 2007-2012 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made * 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 * available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information, * as published by the Free Software Foundation. For more information,
@@ -25,13 +25,16 @@ namespace OpenRA.Graphics
{ {
cursors = new Dictionary<string, CursorSequence>(); cursors = new Dictionary<string, CursorSequence>();
var sequences = new MiniYaml(null, sequenceFiles.Select(s => MiniYaml.FromFile(s)).Aggregate(MiniYaml.MergeLiberal)); var sequences = new MiniYaml(null, sequenceFiles.Select(s => MiniYaml.FromFile(s)).Aggregate(MiniYaml.MergeLiberal));
var transparent = false; int[] ShadowIndex = { };
if (sequences.NodesDict.ContainsKey("Transparent")) if (sequences.NodesDict.ContainsKey("ShadowIndex"))
transparent = true; {
Array.Resize(ref ShadowIndex, ShadowIndex.Length + 1);
ShadowIndex[ShadowIndex.Length - 1] = Convert.ToInt32(sequences.NodesDict["ShadowIndex"].Value);
}
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), transparent)); Game.modData.Palette.AddPalette(s.Key, new Palette(FileSystem.Open(s.Value.Value), ShadowIndex));
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

@@ -267,7 +267,7 @@ namespace OpenRA.Mods.D2k.Widgets.Logic
new string[] {"--r8", PathToDataR8, PathToPalette, "4463", "4477", Path.Combine(PathToSHPs, "craneo"), "--building"}, new string[] {"--r8", PathToDataR8, PathToPalette, "4463", "4477", Path.Combine(PathToSHPs, "craneo"), "--building"},
new string[] {"--r8", PathToDataR8, PathToPalette, "4760", "4819", Path.Combine(PathToSHPs, "windtrap_anim"), "--building"}, //? new string[] {"--r8", PathToDataR8, PathToPalette, "4760", "4819", Path.Combine(PathToSHPs, "windtrap_anim"), "--building"}, //?
new string[] {"--r8", PathToDataR8, PathToPalette, "4820", "4840", Path.Combine(PathToSHPs, "missile_launch"), "--building"}, new string[] {"--r8", PathToDataR8, PathToPalette, "4820", "4840", Path.Combine(PathToSHPs, "missile_launch"), "--building"},
new string[] {"--r8", Path.Combine(Platform.SupportDir, "Content/d2k/MOUSE.R8"), PathToPalette, "0", "264", Path.Combine(PathToSHPs, "mouse"), "--transparent"}, new string[] {"--r8", Path.Combine(Platform.SupportDir, "Content/d2k/MOUSE.R8"), PathToPalette, "0", "264", Path.Combine(PathToSHPs, "mouse")},
new string[] {"--r8", Path.Combine(Platform.SupportDir, "Content/d2k/BLOXBASE.R8"), PathToPalette, "0", "799", Path.Combine(PathToTilesets, "BASE"), "--tileset"}, new string[] {"--r8", Path.Combine(Platform.SupportDir, "Content/d2k/BLOXBASE.R8"), PathToPalette, "0", "799", Path.Combine(PathToTilesets, "BASE"), "--tileset"},
new string[] {"--r8", Path.Combine(Platform.SupportDir, "Content/d2k/BLOXBASE.R8"), PathToPalette, "748", "749", Path.Combine(PathToSHPs, "spice0")}, new string[] {"--r8", Path.Combine(Platform.SupportDir, "Content/d2k/BLOXBASE.R8"), PathToPalette, "748", "749", Path.Combine(PathToSHPs, "spice0")},
new string[] {"--r8", Path.Combine(Platform.SupportDir, "Content/d2k/BLOXBAT.R8"), PathToPalette, "0", "799", Path.Combine(PathToTilesets, "BAT"), "--tileset"}, new string[] {"--r8", Path.Combine(Platform.SupportDir, "Content/d2k/BLOXBAT.R8"), PathToPalette, "0", "799", Path.Combine(PathToTilesets, "BAT"), "--tileset"},

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information #region Copyright & License Information
/* /*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS) * Copyright 2007-2012 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made * 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 * available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information, * as published by the Free Software Foundation. For more information,
@@ -16,7 +16,7 @@ namespace OpenRA.Mods.RA
class PaletteFromCurrentTilesetInfo : ITraitInfo class PaletteFromCurrentTilesetInfo : ITraitInfo
{ {
public readonly string Name = null; public readonly string Name = null;
public readonly bool Transparent = true; public readonly int[] ShadowIndex = { };
public object Create(ActorInitializer init) { return new PaletteFromCurrentTileset(init.world, this); } public object Create(ActorInitializer init) { return new PaletteFromCurrentTileset(init.world, this); }
} }
@@ -34,7 +34,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.Transparent ) ); wr.AddPalette( info.Name, new Palette( FileSystem.Open( world.TileSet.Palette ), info.ShadowIndex ) );
} }
} }
} }

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information #region Copyright & License Information
/* /*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS) * Copyright 2007-2012 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made * 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 * available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information, * as published by the Free Software Foundation. For more information,
@@ -19,7 +19,7 @@ namespace OpenRA.Mods.RA
public readonly string Name = null; public readonly string Name = null;
public readonly string Tileset = null; public readonly string Tileset = null;
public readonly string Filename = null; public readonly string Filename = null;
public readonly bool Transparent = true; public readonly int[] ShadowIndex = { };
public object Create(ActorInitializer init) { return new PaletteFromFile(init.world, this); } public object Create(ActorInitializer init) { return new PaletteFromFile(init.world, this); }
} }
@@ -37,7 +37,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.Transparent ) ); wr.AddPalette( info.Name, new Palette( FileSystem.Open( info.Filename ), info.ShadowIndex ) );
} }
} }
} }

View File

@@ -56,9 +56,11 @@ namespace OpenRA.TilesetBuilder
Bitmap rbitmap = fbitmap.Clone(new Rectangle(0, 0, fbitmap.Width, fbitmap.Height), Bitmap rbitmap = fbitmap.Clone(new Rectangle(0, 0, fbitmap.Width, fbitmap.Height),
fbitmap.PixelFormat); fbitmap.PixelFormat);
int[] ShadowIndex = { };
if (!PaletteFromImage) if (!PaletteFromImage)
{ {
tpal = Palette.Load(PaletteFile, false); tpal = Palette.Load(PaletteFile, ShadowIndex);
rbitmap.Palette = tpal.AsSystemPalette(); rbitmap.Palette = tpal.AsSystemPalette();
} }

View File

@@ -81,8 +81,15 @@ namespace OpenRA.Utility
var dest = Path.ChangeExtension(src, ".png"); var dest = Path.ChangeExtension(src, ".png");
var srcImage = ShpReader.Load(src); var srcImage = ShpReader.Load(src);
var shouldRemap = args.Contains( "--transparent" ); int[] ShadowIndex = { };
var palette = Palette.Load(args[2], shouldRemap); if (args.Contains("--noshadow"))
{
Array.Resize(ref ShadowIndex, ShadowIndex.Length + 3);
ShadowIndex[ShadowIndex.Length - 1] = 1;
ShadowIndex[ShadowIndex.Length - 2] = 3;
ShadowIndex[ShadowIndex.Length - 1] = 4;
}
var palette = Palette.Load(args[2], ShadowIndex);
using (var bitmap = new Bitmap(srcImage.ImageCount * srcImage.Width, srcImage.Height, PixelFormat.Format8bppIndexed)) using (var bitmap = new Bitmap(srcImage.ImageCount * srcImage.Width, srcImage.Height, PixelFormat.Format8bppIndexed))
{ {
@@ -110,8 +117,13 @@ namespace OpenRA.Utility
public static void ConvertR8ToPng(string[] args) public static void ConvertR8ToPng(string[] args)
{ {
var srcImage = new R8Reader(File.OpenRead(args[1])); var srcImage = new R8Reader(File.OpenRead(args[1]));
var shouldRemap = args.Contains("--transparent"); int[] ShadowIndex = { };
var palette = Palette.Load(args[2], shouldRemap); if (args.Contains("--noshadow"))
{
Array.Resize(ref ShadowIndex, ShadowIndex.Length + 1);
ShadowIndex[ShadowIndex.Length - 1] = 3;
}
var palette = Palette.Load(args[2], ShadowIndex);
var startFrame = int.Parse(args[3]); var startFrame = int.Parse(args[3]);
var endFrame = int.Parse(args[4]) + 1; var endFrame = int.Parse(args[4]) + 1;
var filename = args[5]; var filename = args[5];
@@ -319,6 +331,7 @@ namespace OpenRA.Utility
var mods = args[1].Split(','); var mods = args[1].Split(',');
var theater = args[2]; var theater = args[2];
var templateNames = args.Skip(3); var templateNames = args.Skip(3);
int[] ShadowIndex = { 3, 4 };
var manifest = new Manifest(mods); var manifest = new Manifest(mods);
FileSystem.LoadFromManifest(manifest); FileSystem.LoadFromManifest(manifest);
@@ -330,7 +343,7 @@ namespace OpenRA.Utility
throw new InvalidOperationException("No theater named '{0}'".F(theater)); throw new InvalidOperationException("No theater named '{0}'".F(theater));
tileset.LoadTiles(); tileset.LoadTiles();
var palette = new Palette(FileSystem.Open(tileset.Palette), true); var palette = new Palette(FileSystem.Open(tileset.Palette), ShadowIndex);
foreach( var templateName in templateNames ) foreach( var templateName in templateNames )
{ {
@@ -413,14 +426,15 @@ namespace OpenRA.Utility
var destPaletteInfo = Rules.Info["player"].Traits.Get<PlayerColorPaletteInfo>(); var destPaletteInfo = Rules.Info["player"].Traits.Get<PlayerColorPaletteInfo>();
int[] destRemapIndex = destPaletteInfo.RemapIndex; int[] destRemapIndex = destPaletteInfo.RemapIndex;
int[] ShadowIndex = { };
// the remap range is always 16 entries, but their location and order changes // the remap range is always 16 entries, but their location and order changes
for (var i = 0; i < 16; i++) for (var i = 0; i < 16; i++)
remap[PlayerColorRemap.GetRemapIndex(srcRemapIndex, i)] remap[PlayerColorRemap.GetRemapIndex(srcRemapIndex, i)]
= PlayerColorRemap.GetRemapIndex(destRemapIndex, i); = PlayerColorRemap.GetRemapIndex(destRemapIndex, i);
// map everything else to the best match based on channel-wise distance // map everything else to the best match based on channel-wise distance
var srcPalette = Palette.Load(args[1].Split(':')[1], false); var srcPalette = Palette.Load(args[1].Split(':')[1], ShadowIndex);
var destPalette = Palette.Load(args[2].Split(':')[1], false); var destPalette = Palette.Load(args[2].Split(':')[1], ShadowIndex);
var fullIndexRange = Exts.MakeArray<int>(256, x => x); var fullIndexRange = Exts.MakeArray<int>(256, x => x);

View File

@@ -57,11 +57,11 @@ namespace OpenRA.Utility
Console.WriteLine(); Console.WriteLine();
Console.WriteLine(" --settings-value KEY Get value of KEY from settings.yaml"); Console.WriteLine(" --settings-value KEY Get value of KEY from settings.yaml");
Console.WriteLine(" --shp PNGFILE FRAMEWIDTH Convert a single PNG with multiple frames appended after another to a SHP"); Console.WriteLine(" --shp PNGFILE FRAMEWIDTH Convert a single PNG with multiple frames appended after another to a SHP");
Console.WriteLine(" --png SHPFILE PALETTE [--transparent] Convert a SHP to a PNG containing all of its frames, optionally setting up transparency"); Console.WriteLine(" --png SHPFILE PALETTE [--noshadow] Convert a SHP to a PNG containing all of its frames, optionally removing the shadow");
Console.WriteLine(" --extract MOD[,MOD]* FILES Extract files from mod packages"); Console.WriteLine(" --extract MOD[,MOD]* FILES Extract files from mod packages");
Console.WriteLine(" --tmp-png MOD[,MOD]* THEATER FILES Extract terrain tiles to PNG"); Console.WriteLine(" --tmp-png MOD[,MOD]* THEATER FILES Extract terrain tiles to PNG");
Console.WriteLine(" --remap SRCMOD:PAL DESTMOD:PAL SRCSHP DESTSHP Remap SHPs to another palette"); Console.WriteLine(" --remap SRCMOD:PAL DESTMOD:PAL SRCSHP DESTSHP Remap SHPs to another palette");
Console.WriteLine(" --r8 R8FILE PALETTE START END FILENAME [--transparent] [--infrantry] [--vehicle] [--projectile] [--building] [--wall] [--tileset] Convert Dune 2000 DATA.R8 to PNGs choosing start- and endframe as well as type for correct offset to append multiple frames to one PNG named by filename optionally setting up transparency."); Console.WriteLine(" --r8 R8FILE PALETTE START END FILENAME [--noshadow] [--infrantry] [--vehicle] [--projectile] [--building] [--wall] [--tileset] Convert Dune 2000 DATA.R8 to PNGs choosing start- and endframe as well as type for correct offset to append multiple frames to one PNG named by filename optionally removing the shadow.");
Console.WriteLine(" --transpose SRCSHP DESTSHP START N M [START N M ...] Transpose the N*M block of frames starting at START."); Console.WriteLine(" --transpose SRCSHP DESTSHP START N M [START N M ...] Transpose the N*M block of frames starting at START.");
} }

View File

@@ -1 +0,0 @@
http://nyerguds.arsaneus-design.com/cnc95upd/inirules/

View File

@@ -68,14 +68,18 @@ World:
Bridges: bridge1, bridge2, bridge3, bridge4 Bridges: bridge1, bridge2, bridge3, bridge4
PaletteFromCurrentTileset@terrain: PaletteFromCurrentTileset@terrain:
Name: terrain Name: terrain
ShadowIndex: 4
PaletteFromCurrentTileset@static: PaletteFromCurrentTileset@static:
Name: staticterrain Name: staticterrain
ShadowIndex: 4
PaletteFromFile@chrome: PaletteFromFile@chrome:
Name: chrome Name: chrome
Filename: temperat.pal Filename: temperat.pal
ShadowIndex: 3
PaletteFromFile@effect: PaletteFromFile@effect:
Name: effect Name: effect
Filename: temperat.pal Filename: temperat.pal
ShadowIndex: 4
PaletteFromRGBA@shadow: PaletteFromRGBA@shadow:
Name: shadow Name: shadow
R: 0 R: 0

View File

@@ -1,4 +1,4 @@
Transparent: ShadowIndex: 1
Palettes: Palettes:
cursor: cursor.pal cursor: cursor.pal

View File

@@ -73,15 +73,19 @@ World:
ValidGround: Sand, Dune, Rock ValidGround: Sand, Dune, Rock
PaletteFromCurrentTileset: PaletteFromCurrentTileset:
Name: terrain Name: terrain
ShadowIndex: 1
PaletteFromFile@d2k: PaletteFromFile@d2k:
Name: d2k Name: d2k
Filename: d2k.pal Filename: d2k.pal
ShadowIndex: 1
PaletteFromFile@chrome: PaletteFromFile@chrome:
Name: chrome Name: chrome
Filename: d2k.pal Filename: d2k.pal
ShadowIndex: 3
PaletteFromFile@effect: PaletteFromFile@effect:
Name: effect Name: effect
Filename: temperat.pal Filename: temperat.pal
ShadowIndex: 4
PaletteFromRGBA@shadow: PaletteFromRGBA@shadow:
Name: shadow Name: shadow
R: 0 R: 0

View File

@@ -210,12 +210,15 @@ World:
WaterChance: .2 WaterChance: .2
PaletteFromCurrentTileset: PaletteFromCurrentTileset:
Name: terrain Name: terrain
ShadowIndex: 4
PaletteFromFile@chrome: PaletteFromFile@chrome:
Name: chrome Name: chrome
Filename: temperat.pal Filename: temperat.pal
ShadowIndex: 3
PaletteFromFile@effect: PaletteFromFile@effect:
Name: effect Name: effect
Filename: temperat.pal Filename: temperat.pal
ShadowIndex: 4
PaletteFromRGBA@shadow: PaletteFromRGBA@shadow:
Name: shadow Name: shadow
R: 0 R: 0