From 7ae782bb59f98a0ac86ac6f83ac122c5c68ed165 Mon Sep 17 00:00:00 2001 From: dnqbob Date: Mon, 4 Nov 2024 00:33:40 +0800 Subject: [PATCH] Cloud color function set up --- .../Traits/Palettes/GradientColorsPalette.cs | 64 +++++++++++++++++++ mods/sp/rules/environment/world.yaml | 2 +- mods/sp/rules/palettes/palettesterrain.yaml | 17 +++++ 3 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 OpenRA.Mods.Sp/Traits/Palettes/GradientColorsPalette.cs diff --git a/OpenRA.Mods.Sp/Traits/Palettes/GradientColorsPalette.cs b/OpenRA.Mods.Sp/Traits/Palettes/GradientColorsPalette.cs new file mode 100644 index 000000000..9fca45c4b --- /dev/null +++ b/OpenRA.Mods.Sp/Traits/Palettes/GradientColorsPalette.cs @@ -0,0 +1,64 @@ +#region Copyright & License Information +/* + * Copyright (c) The OpenRA Developers and Contributors + * 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.SP.Traits +{ + [TraitLocation(SystemActors.World | SystemActors.EditorWorld)] + [Desc("Add this to the World actor definition.")] + public class GradientColorsPaletteInfo : TraitInfo + { + [PaletteDefinition] + [Desc("The name of the resulting palette")] + public readonly string Name = "resources"; + + [FieldLoader.Require] + [Desc("Start color for gradient")] + public readonly Color StartColor; + + [FieldLoader.Require] + [Desc("End color for gradient.")] + public readonly Color EndColor; + + [Desc("Index set to be fully transparent/invisible.")] + public readonly int TransparentIndex = 0; + + [Desc("Allow palette modifiers to change the palette.")] + public readonly bool AllowModifiers = true; + + public override object Create(ActorInitializer init) { return new GradientColorsPalette(this); } + } + + public class GradientColorsPalette : ILoadsPalettes + { + readonly GradientColorsPaletteInfo info; + + public GradientColorsPalette(GradientColorsPaletteInfo info) + { + this.info = info; + } + + public void LoadPalettes(WorldRenderer wr) + { + var da = (info.EndColor.A - info.StartColor.A) / 254f; + var dr = (info.EndColor.R - info.StartColor.R) / 254f; + var dg = (info.EndColor.G - info.StartColor.G) / 254f; + var db = (info.EndColor.B - info.StartColor.B) / 254f; + var d = 0; + wr.AddPalette(info.Name, new ImmutablePalette(Enumerable.Range(0, Palette.Size). + Select(i => (i == info.TransparentIndex) ? 0 : Color.FromArgb(info.StartColor.A + (int)(++d * da), info.StartColor.R + (int)(d * dr), info.StartColor.G + (int)(d * dg), info.StartColor.B + (int)(d * db)).ToArgb())), info.AllowModifiers); + } + } +} diff --git a/mods/sp/rules/environment/world.yaml b/mods/sp/rules/environment/world.yaml index 63a1d2aee..f4ff56355 100644 --- a/mods/sp/rules/environment/world.yaml +++ b/mods/sp/rules/environment/world.yaml @@ -599,7 +599,7 @@ World: Image: smoothclouds ## duplicatd the idle0, idle17 to save a trait Sequences: idle1, idle2, idle3, idle4, idle5, idle6, idle7, idle8, idle9, idle10, idle11, idle12, idle13, idle14, idle15, idle16, idle18, idle0, idle17, idle0, idle17, idle0, idle17, idle0, idle17, idle0, idle17, idle0, idle17, idle0, idle17, idle0, idle17 - Palette: jascgrey + Palette: cloud Speed: 6 SpawnInterval: 1000 CruiseAltitude: 3c0 diff --git a/mods/sp/rules/palettes/palettesterrain.yaml b/mods/sp/rules/palettes/palettesterrain.yaml index 9a781cd35..ffe07e5f4 100644 --- a/mods/sp/rules/palettes/palettesterrain.yaml +++ b/mods/sp/rules/palettes/palettesterrain.yaml @@ -113,3 +113,20 @@ AllowModifiers: true ShadowIndex: 1 #RBGSwapMode: None #None #GRB #BGR #RBG #BRG #GBR + + ## Change color of clouds + GradientColorsPalette@cloud: + Name: cloud + AllowModifiers: false + # Jascgrey + StartColor: 010101 + EndColor: FFFFFF + + # snow normal green cloud (best) + #StartColor: 000100 + #EndColor: F1FFF1 + + # temp normal green cloud (not good) + #StartColor: 000F00 + #EndColor: E0FFE0 +