From 8b3f15155edcee03a06293a76e3994c5d25ce39f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sat, 3 May 2014 08:18:56 +0200 Subject: [PATCH] remappable resource types --- OpenRA.Game/Graphics/PlayerColorRemap.cs | 2 +- OpenRA.Game/OpenRA.Game.csproj | 1 + .../Traits/Player/FixedColorPalette.cs | 50 +++++++++++++++++++ OpenRA.Game/Traits/World/ResourceType.cs | 4 +- mods/ts/rules/world.yaml | 7 ++- 5 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 OpenRA.Game/Traits/Player/FixedColorPalette.cs diff --git a/OpenRA.Game/Graphics/PlayerColorRemap.cs b/OpenRA.Game/Graphics/PlayerColorRemap.cs index 2aa9ddda69..78cd48b9f3 100755 --- a/OpenRA.Game/Graphics/PlayerColorRemap.cs +++ b/OpenRA.Game/Graphics/PlayerColorRemap.cs @@ -41,7 +41,7 @@ namespace OpenRA.Graphics for (var i = 15; i > 0; i--) remapRamp = ramp.Select(r => r - ramp[15]).ToArray(); } - + remapColors = remapRamp.Select((x, i) => Pair.New(baseIndex + i, Exts.ColorLerp(x / 16f, c1, c2))) .ToDictionary(u => u.First, u => u.Second); } diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index 14e6702f1b..2216860c0f 100644 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -246,6 +246,7 @@ + diff --git a/OpenRA.Game/Traits/Player/FixedColorPalette.cs b/OpenRA.Game/Traits/Player/FixedColorPalette.cs new file mode 100644 index 0000000000..dd2abc304d --- /dev/null +++ b/OpenRA.Game/Traits/Player/FixedColorPalette.cs @@ -0,0 +1,50 @@ +#region Copyright & License Information +/* + * Copyright 2007-2014 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 OpenRA.FileFormats; +using OpenRA.Graphics; + +namespace OpenRA.Traits +{ + [Desc("Add this to the World actor definition.")] + public class FixedColorPaletteInfo : ITraitInfo + { + [Desc("The name of the palette to base off.")] + public readonly string Base = "terrain"; + [Desc("The name of the resulting palette")] + public readonly string Name = "resources"; + [Desc("Remap these indices to pre-defined colors.")] + public readonly int[] RemapIndex = { }; + [Desc("The fixed color to remap.")] + public readonly HSLColor Color; + [Desc("Luminosity range to span.")] + public readonly float Ramp = 0.05f; + [Desc("Allow palette modifiers to change the palette.")] + public readonly bool AllowModifiers = true; + + public object Create(ActorInitializer init) { return new FixedColorPalette(this); } + } + + public class FixedColorPalette : IPalette + { + readonly FixedColorPaletteInfo info; + + public FixedColorPalette(FixedColorPaletteInfo info) + { + this.info = info; + } + + public void InitPalette(WorldRenderer wr) + { + var remap = new PlayerColorRemap(info.RemapIndex, info.Color, info.Ramp); + wr.AddPalette(info.Name, new Palette(wr.Palette(info.Base).Palette, remap), info.AllowModifiers); + } + } +} diff --git a/OpenRA.Game/Traits/World/ResourceType.cs b/OpenRA.Game/Traits/World/ResourceType.cs index d477f25c5e..fc41e476b3 100644 --- a/OpenRA.Game/Traits/World/ResourceType.cs +++ b/OpenRA.Game/Traits/World/ResourceType.cs @@ -1,6 +1,6 @@ #region Copyright & License Information /* - * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) + * Copyright 2007-2014 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, @@ -16,7 +16,7 @@ namespace OpenRA.Traits { public class ResourceTypeInfo : ITraitInfo { - // Hack: The editor is getting really unmaintanable... + // HACK: The editor is getting really unmaintanable... public readonly string EditorSprite; public readonly string[] Variants = { }; public readonly string Palette = "terrain"; diff --git a/mods/ts/rules/world.yaml b/mods/ts/rules/world.yaml index 1c2bc200e1..3fe037c8ef 100644 --- a/mods/ts/rules/world.yaml +++ b/mods/ts/rules/world.yaml @@ -82,9 +82,14 @@ World: Race: nod ResourceLayer: ResourceClaimLayer: + FixedColorPalette@GreenTiberium: + Base: player + Name: greentiberium + Color: 57, 201, 128 + RemapIndex: 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 ResourceType@Tiberium: ResourceType: 1 - Palette: player # TODO: this has to remap to green + Palette: greentiberium EditorSprite: waypoint # TODO: editor can't handle the real ones Variants: tib01, tib02, tib03, tib04, tib05, tib06, tib07, tib08, tib09, tib10, tib11, tib12, tib13, tib14, tib15, tib16, tib17, tib18, tib19, tib20 MaxDensity: 12