-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters