From 27c4512ec7bb9b87a32872a8a790df3527ba6e47 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 5 Apr 2015 19:01:33 +0100 Subject: [PATCH 1/2] Import lighting parameters for TS maps. --- mods/ts/maps/arivruns/map.yaml | 3 +++ mods/ts/maps/tread_l/map.yaml | 3 +++ 2 files changed, 6 insertions(+) diff --git a/mods/ts/maps/arivruns/map.yaml b/mods/ts/maps/arivruns/map.yaml index 2246df4448..4d10c931a2 100644 --- a/mods/ts/maps/arivruns/map.yaml +++ b/mods/ts/maps/arivruns/map.yaml @@ -174,6 +174,9 @@ Actors: Smudges: Rules: + World: + GlobalLightingPaletteEffect: + Ambient: 0.72 Sequences: diff --git a/mods/ts/maps/tread_l/map.yaml b/mods/ts/maps/tread_l/map.yaml index 5518691410..515929957e 100644 --- a/mods/ts/maps/tread_l/map.yaml +++ b/mods/ts/maps/tread_l/map.yaml @@ -1171,6 +1171,9 @@ Actors: Smudges: Rules: + World: + GlobalLightingPaletteEffect: + Ambient: 0.75 Sequences: From 56405f42ab2b501284d226f179c26f57fe66c6b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sat, 4 Apr 2015 21:36:49 +0200 Subject: [PATCH 2/2] add a global palette effect for day/night ambient --- OpenRA.Mods.Common/OpenRA.Mods.Common.csproj | 1 + .../GlobalLightingPaletteEffect.cs | 67 +++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 OpenRA.Mods.Common/Traits/PaletteEffects/GlobalLightingPaletteEffect.cs diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index 3bb01cbe2c..f1d2a74520 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -332,6 +332,7 @@ + diff --git a/OpenRA.Mods.Common/Traits/PaletteEffects/GlobalLightingPaletteEffect.cs b/OpenRA.Mods.Common/Traits/PaletteEffects/GlobalLightingPaletteEffect.cs new file mode 100644 index 0000000000..e59d1e106a --- /dev/null +++ b/OpenRA.Mods.Common/Traits/PaletteEffects/GlobalLightingPaletteEffect.cs @@ -0,0 +1,67 @@ +#region Copyright & License Information +/* + * Copyright 2007-2015 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 System.Linq; +using OpenRA.Graphics; +using OpenRA.Traits; + +namespace OpenRA.Mods.Common.Traits +{ + [Desc("Used for day/night effects.")] + class GlobalLightingPaletteEffectInfo : ITraitInfo + { + [Desc("Do not modify graphics that use any palette in this list.")] + public readonly string[] ExcludePalettes = { "cursor", "chrome", "colorpicker", "fog", "shroud", "alpha" }; + + [Desc("Do not modify graphics that start with these letters.")] + public readonly string[] ExcludePalettePrefixes = { }; + + public readonly float Red = 1f; + public readonly float Green = 1f; + public readonly float Blue = 1f; + public readonly float Ambient = 1f; + + public object Create(ActorInitializer init) { return new GlobalLightingPaletteEffect(this); } + } + + class GlobalLightingPaletteEffect : IPaletteModifier + { + readonly GlobalLightingPaletteEffectInfo info; + + public GlobalLightingPaletteEffect(GlobalLightingPaletteEffectInfo info) + { + this.info = info; + } + + public void AdjustPalette(IReadOnlyDictionary palettes) + { + foreach (var kvp in palettes) + { + if (info.ExcludePalettes.Contains(kvp.Key)) + continue; + + if (info.ExcludePalettePrefixes.Any(kvp.Key.StartsWith)) + continue; + + var palette = kvp.Value; + + for (var x = 0; x < Palette.Size; x++) + { + var from = palette.GetColor(x); + var red = (int)(from.R * info.Ambient * info.Red).Clamp(0, 255); + var green = (int)(from.G * info.Ambient * info.Green).Clamp(0, 255); + var blue = (int)(from.B * info.Ambient * info.Blue).Clamp(0, 255); + palette.SetColor(x, Color.FromArgb(from.A, red, green, blue)); + } + } + } + } +}