Remove unnecessary indirection from palette creation.
This commit is contained in:
@@ -76,6 +76,13 @@ namespace OpenRA.FileFormats
|
|||||||
colors = (uint[])p.colors.Clone();
|
colors = (uint[])p.colors.Clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Palette(uint[] data)
|
||||||
|
{
|
||||||
|
if (data.Length != 256)
|
||||||
|
throw new InvalidDataException("Attempting to create palette with incorrect array size");
|
||||||
|
colors = (uint[])data.Clone();
|
||||||
|
}
|
||||||
|
|
||||||
public ColorPalette AsSystemPalette()
|
public ColorPalette AsSystemPalette()
|
||||||
{
|
{
|
||||||
ColorPalette pal;
|
ColorPalette pal;
|
||||||
|
|||||||
44
OpenRA.Mods.RA/FogPalette.cs
Normal file
44
OpenRA.Mods.RA/FogPalette.cs
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2013 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.Drawing;
|
||||||
|
using OpenRA.FileFormats;
|
||||||
|
using OpenRA.Graphics;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.RA
|
||||||
|
{
|
||||||
|
class FogPaletteInfo : ITraitInfo
|
||||||
|
{
|
||||||
|
public readonly string Name = "fog";
|
||||||
|
public object Create(ActorInitializer init) { return new FogPalette(this); }
|
||||||
|
}
|
||||||
|
|
||||||
|
class FogPalette : IPalette
|
||||||
|
{
|
||||||
|
readonly FogPaletteInfo info;
|
||||||
|
|
||||||
|
public FogPalette(FogPaletteInfo info) { this.info = info; }
|
||||||
|
|
||||||
|
public void InitPalette(WorldRenderer wr)
|
||||||
|
{
|
||||||
|
var c = new[] {
|
||||||
|
Color.Transparent, Color.Green,
|
||||||
|
Color.Blue, Color.Yellow,
|
||||||
|
Color.FromArgb(128,0,0,0),
|
||||||
|
Color.FromArgb(128,0,0,0),
|
||||||
|
Color.FromArgb(128,0,0,0),
|
||||||
|
Color.FromArgb(64,0,0,0)
|
||||||
|
};
|
||||||
|
|
||||||
|
wr.AddPalette(info.Name, new Palette(Exts.MakeArray(256, i => (uint)c[i % 8].ToArgb())), false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -407,6 +407,7 @@
|
|||||||
<Compile Include="Widgets\Logic\CheatsLogic.cs" />
|
<Compile Include="Widgets\Logic\CheatsLogic.cs" />
|
||||||
<Compile Include="CloakPaletteEffect.cs" />
|
<Compile Include="CloakPaletteEffect.cs" />
|
||||||
<Compile Include="Widgets\ColorPreviewManagerWidget.cs" />
|
<Compile Include="Widgets\ColorPreviewManagerWidget.cs" />
|
||||||
|
<Compile Include="FogPalette.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||||
|
|||||||
@@ -38,28 +38,14 @@ namespace OpenRA.Mods.RA
|
|||||||
this.info = info;
|
this.info = info;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void InitPalette( WorldRenderer wr )
|
public void InitPalette(WorldRenderer wr)
|
||||||
{
|
{
|
||||||
if (info.Tileset == null || info.Tileset.ToLowerInvariant() == world.Map.Tileset.ToLowerInvariant())
|
// Enable palette only for a specific tileset
|
||||||
{
|
if (info.Tileset != null && info.Tileset.ToLowerInvariant() != world.Map.Tileset.ToLowerInvariant())
|
||||||
// TODO: This shouldn't rely on a base palette
|
return;
|
||||||
var pal = wr.GetPalette("terrain");
|
|
||||||
wr.AddPalette(info.Name, new Palette(pal, new SingleColorRemap(Color.FromArgb(info.A, info.R, info.G, info.B))), info.AllowModifiers);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class SingleColorRemap : IPaletteRemap
|
var c = (uint)((info.A << 24) | (info.R << 16) | (info.G << 8) | info.B);
|
||||||
{
|
wr.AddPalette(info.Name, new Palette(Exts.MakeArray(256, i => (i == 0) ? 0 : c)), info.AllowModifiers);
|
||||||
Color c;
|
|
||||||
public SingleColorRemap(Color c)
|
|
||||||
{
|
|
||||||
this.c = c;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Color GetRemappedColor(Color original, int index)
|
|
||||||
{
|
|
||||||
return original.A > 0 ? c : original;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,8 +18,6 @@ namespace OpenRA.Mods.RA
|
|||||||
class ShroudPaletteInfo : ITraitInfo
|
class ShroudPaletteInfo : ITraitInfo
|
||||||
{
|
{
|
||||||
public readonly string Name = "shroud";
|
public readonly string Name = "shroud";
|
||||||
public readonly bool IsFog = false;
|
|
||||||
|
|
||||||
public object Create(ActorInitializer init) { return new ShroudPalette(this); }
|
public object Create(ActorInitializer init) { return new ShroudPalette(this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,34 +29,16 @@ namespace OpenRA.Mods.RA
|
|||||||
|
|
||||||
public void InitPalette(WorldRenderer wr)
|
public void InitPalette(WorldRenderer wr)
|
||||||
{
|
{
|
||||||
var pal = wr.GetPalette("terrain");
|
var c = new[] {
|
||||||
wr.AddPalette(info.Name, new Palette(pal, new ShroudPaletteRemap(info.IsFog)), false);
|
Color.Transparent, Color.Green,
|
||||||
}
|
Color.Blue, Color.Yellow,
|
||||||
}
|
Color.Black,
|
||||||
|
Color.FromArgb(128,0,0,0),
|
||||||
|
Color.Transparent,
|
||||||
|
Color.Transparent
|
||||||
|
};
|
||||||
|
|
||||||
class ShroudPaletteRemap : IPaletteRemap
|
wr.AddPalette(info.Name, new Palette(Exts.MakeArray(256, i => (uint)c[i % 8].ToArgb())), false);
|
||||||
{
|
|
||||||
bool isFog;
|
|
||||||
|
|
||||||
public ShroudPaletteRemap(bool isFog) { this.isFog = isFog; }
|
|
||||||
public Color GetRemappedColor(Color original, int index)
|
|
||||||
{
|
|
||||||
if (isFog)
|
|
||||||
return new[] {
|
|
||||||
Color.Transparent, Color.Green,
|
|
||||||
Color.Blue, Color.Yellow,
|
|
||||||
Color.FromArgb(128,0,0,0),
|
|
||||||
Color.FromArgb(128,0,0,0),
|
|
||||||
Color.FromArgb(128,0,0,0),
|
|
||||||
Color.FromArgb(64,0,0,0)}[index % 8];
|
|
||||||
else
|
|
||||||
return new[] {
|
|
||||||
Color.Transparent, Color.Green,
|
|
||||||
Color.Blue, Color.Yellow,
|
|
||||||
Color.Black,
|
|
||||||
Color.FromArgb(128,0,0,0),
|
|
||||||
Color.Transparent,
|
|
||||||
Color.Transparent}[index % 8];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -109,10 +109,8 @@ World:
|
|||||||
G: 0
|
G: 0
|
||||||
B: 0
|
B: 0
|
||||||
A: 180
|
A: 180
|
||||||
ShroudPalette@shroud:
|
ShroudPalette:
|
||||||
ShroudPalette@fog:
|
FogPalette:
|
||||||
IsFog: yes
|
|
||||||
Name: fog
|
|
||||||
Country@gdi:
|
Country@gdi:
|
||||||
Name: GDI
|
Name: GDI
|
||||||
Race: gdi
|
Race: gdi
|
||||||
|
|||||||
@@ -304,10 +304,8 @@ World:
|
|||||||
G: 0
|
G: 0
|
||||||
B: 0
|
B: 0
|
||||||
A: 180
|
A: 180
|
||||||
ShroudPalette@shroud:
|
ShroudPalette:
|
||||||
ShroudPalette@fog:
|
FogPalette:
|
||||||
IsFog: yes
|
|
||||||
Name: fog
|
|
||||||
Country@Atreides:
|
Country@Atreides:
|
||||||
Name: Atreides
|
Name: Atreides
|
||||||
Race: atreides
|
Race: atreides
|
||||||
|
|||||||
@@ -259,10 +259,8 @@ World:
|
|||||||
G: 0
|
G: 0
|
||||||
B: 0
|
B: 0
|
||||||
A: 180
|
A: 180
|
||||||
ShroudPalette@shroud:
|
ShroudPalette:
|
||||||
ShroudPalette@fog:
|
FogPalette:
|
||||||
IsFog: yes
|
|
||||||
Name: fog
|
|
||||||
Country@0:
|
Country@0:
|
||||||
Name: Allies
|
Name: Allies
|
||||||
Race: allies
|
Race: allies
|
||||||
|
|||||||
Reference in New Issue
Block a user