Add TransparentIndex to PaletteFromFile.
This commit is contained in:
@@ -64,18 +64,18 @@ namespace OpenRA.Graphics
|
|||||||
Buffer.BlockCopy(colors, 0, destination, destinationOffset * 4, Palette.Size * 4);
|
Buffer.BlockCopy(colors, 0, destination, destinationOffset * 4, Palette.Size * 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ImmutablePalette(string filename, int[] remap)
|
public ImmutablePalette(string filename, int[] remapTransparent, int[] remap)
|
||||||
{
|
{
|
||||||
using (var s = File.OpenRead(filename))
|
using (var s = File.OpenRead(filename))
|
||||||
LoadFromStream(s, remap);
|
LoadFromStream(s, remapTransparent, remap);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ImmutablePalette(Stream s, int[] remapShadow)
|
public ImmutablePalette(Stream s, int[] remapTransparent, int[] remapShadow)
|
||||||
{
|
{
|
||||||
LoadFromStream(s, remapShadow);
|
LoadFromStream(s, remapTransparent, remapShadow);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadFromStream(Stream s, int[] remapShadow)
|
void LoadFromStream(Stream s, int[] remapTransparent, int[] remapShadow)
|
||||||
{
|
{
|
||||||
using (var reader = new BinaryReader(s))
|
using (var reader = new BinaryReader(s))
|
||||||
for (var i = 0; i < Palette.Size; i++)
|
for (var i = 0; i < Palette.Size; i++)
|
||||||
@@ -92,7 +92,9 @@ namespace OpenRA.Graphics
|
|||||||
colors[i] = (uint)((255 << 24) | (r << 16) | (g << 8) | b);
|
colors[i] = (uint)((255 << 24) | (r << 16) | (g << 8) | b);
|
||||||
}
|
}
|
||||||
|
|
||||||
colors[0] = 0; // Convert black background to transparency.
|
foreach (var i in remapTransparent)
|
||||||
|
colors[i] = 0;
|
||||||
|
|
||||||
foreach (var i in remapShadow)
|
foreach (var i in remapShadow)
|
||||||
colors[i] = 140u << 24;
|
colors[i] = 140u << 24;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,8 +58,8 @@ namespace OpenRA.Mods.Cnc.UtilityCommands
|
|||||||
= 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 = new ImmutablePalette(args[1].Split(':')[1], shadowIndex);
|
var srcPalette = new ImmutablePalette(args[1].Split(':')[1], new[] { 0 }, shadowIndex);
|
||||||
var destPalette = new ImmutablePalette(args[2].Split(':')[1], shadowIndex);
|
var destPalette = new ImmutablePalette(args[2].Split(':')[1], new[] { 0 }, shadowIndex);
|
||||||
|
|
||||||
for (var i = 0; i < Palette.Size; i++)
|
for (var i = 0; i < Palette.Size; i++)
|
||||||
if (!remap.ContainsKey(i))
|
if (!remap.ContainsKey(i))
|
||||||
|
|||||||
@@ -31,6 +31,9 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
[Desc("filename to load")]
|
[Desc("filename to load")]
|
||||||
public readonly string Filename = null;
|
public readonly string Filename = null;
|
||||||
|
|
||||||
|
[Desc("Map listed indices to transparent. Ignores previous color.")]
|
||||||
|
public readonly int[] TransparentIndex = { 0 };
|
||||||
|
|
||||||
[Desc("Map listed indices to shadow. Ignores previous color.")]
|
[Desc("Map listed indices to shadow. Ignores previous color.")]
|
||||||
public readonly int[] ShadowIndex = { };
|
public readonly int[] ShadowIndex = { };
|
||||||
|
|
||||||
@@ -45,7 +48,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
ImmutablePalette IProvidesCursorPaletteInfo.ReadPalette(IReadOnlyFileSystem fileSystem)
|
ImmutablePalette IProvidesCursorPaletteInfo.ReadPalette(IReadOnlyFileSystem fileSystem)
|
||||||
{
|
{
|
||||||
return new ImmutablePalette(fileSystem.Open(Filename), ShadowIndex);
|
return new ImmutablePalette(fileSystem.Open(Filename), TransparentIndex, ShadowIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
shadowIndex[shadowIndex.Length - 3] = 4;
|
shadowIndex[shadowIndex.Length - 3] = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
var palette = new ImmutablePalette(args[2], shadowIndex);
|
var palette = new ImmutablePalette(args[2], new[] { 0 }, shadowIndex);
|
||||||
var palColors = new Color[Palette.Size];
|
var palColors = new Color[Palette.Size];
|
||||||
for (var i = 0; i < Palette.Size; i++)
|
for (var i = 0; i < Palette.Size; i++)
|
||||||
palColors[i] = palette.GetColor(i);
|
palColors[i] = palette.GetColor(i);
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
// HACK: The engine code assumes that Game.modData is set.
|
// HACK: The engine code assumes that Game.modData is set.
|
||||||
var modData = Game.ModData = utility.ModData;
|
var modData = Game.ModData = utility.ModData;
|
||||||
|
|
||||||
var palette = new ImmutablePalette(args[1], new int[0]);
|
var palette = new ImmutablePalette(args[1], new[] { 0 }, new int[0]);
|
||||||
|
|
||||||
SequenceProvider sequences = null;
|
SequenceProvider sequences = null;
|
||||||
var mapPackage = new Folder(Platform.EngineDir).OpenPackage(args[2], modData.ModFiles);
|
var mapPackage = new Folder(Platform.EngineDir).OpenPackage(args[2], modData.ModFiles);
|
||||||
|
|||||||
Reference in New Issue
Block a user