Added PaletteFromGrayscale.
This commit is contained in:
58
OpenRA.Mods.Common/Traits/Palettes/PaletteFromGrayscale.cs
Normal file
58
OpenRA.Mods.Common/Traits/Palettes/PaletteFromGrayscale.cs
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2021 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, either version 3 of
|
||||||
|
* the License, or (at your option) any later version. For more
|
||||||
|
* information, see COPYING.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
|
using OpenRA.Graphics;
|
||||||
|
using OpenRA.Primitives;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.Common.Traits
|
||||||
|
{
|
||||||
|
[TraitLocation(SystemActors.World | SystemActors.EditorWorld)]
|
||||||
|
[Desc("Creates a greyscale palette without any base palette file.")]
|
||||||
|
class PaletteFromGrayscaleInfo : TraitInfo
|
||||||
|
{
|
||||||
|
[PaletteDefinition]
|
||||||
|
[FieldLoader.Require]
|
||||||
|
[Desc("internal palette name")]
|
||||||
|
public readonly string Name = null;
|
||||||
|
|
||||||
|
[Desc("If defined, load the palette only for this tileset.")]
|
||||||
|
public readonly string Tileset = null;
|
||||||
|
|
||||||
|
public readonly bool AllowModifiers = true;
|
||||||
|
|
||||||
|
[Desc("Index set to be fully transparent/invisible.")]
|
||||||
|
public readonly int TransparentIndex = 0;
|
||||||
|
|
||||||
|
public override object Create(ActorInitializer init) { return new PaletteFromGrayscale(init.World, this); }
|
||||||
|
}
|
||||||
|
|
||||||
|
class PaletteFromGrayscale : ILoadsPalettes
|
||||||
|
{
|
||||||
|
readonly World world;
|
||||||
|
readonly PaletteFromGrayscaleInfo info;
|
||||||
|
public PaletteFromGrayscale(World world, PaletteFromGrayscaleInfo info)
|
||||||
|
{
|
||||||
|
this.world = world;
|
||||||
|
this.info = info;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LoadPalettes(WorldRenderer wr)
|
||||||
|
{
|
||||||
|
// Enable palette only for a specific tileset
|
||||||
|
if (info.Tileset != null && !string.Equals(info.Tileset, world.Map.Tileset, System.StringComparison.InvariantCultureIgnoreCase))
|
||||||
|
return;
|
||||||
|
|
||||||
|
wr.AddPalette(info.Name, new ImmutablePalette(Enumerable.Range(0, Palette.Size).Select(i => (i == info.TransparentIndex) ? 0 : (uint)Color.FromArgb(255, i, i, i).ToArgb())), info.AllowModifiers);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user