Skip to content

Commit

Permalink
Cloud color function set up
Browse files Browse the repository at this point in the history
  • Loading branch information
dnqbob committed Nov 3, 2024
1 parent 66ecbe0 commit 7ae782b
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 1 deletion.
64 changes: 64 additions & 0 deletions OpenRA.Mods.Sp/Traits/Palettes/GradientColorsPalette.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
2 changes: 1 addition & 1 deletion mods/sp/rules/environment/world.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions mods/sp/rules/palettes/palettesterrain.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7ae782b

Please sign in to comment.