Remove HSLColor.

This commit is contained in:
Paul Chote
2018-12-31 08:41:23 +00:00
parent ab4a7e3558
commit 3e404f6ac2
76 changed files with 256 additions and 416 deletions

View File

@@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Scripting
radarPings.Add(
() => owner.IsAlliedWith(owner.World.RenderPlayer),
position,
owner.Color.RGB,
owner.Color,
duration);
}

View File

@@ -0,0 +1,93 @@
#region Copyright & License Information
/*
* Copyright 2007-2019 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, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using Eluant;
using OpenRA.Graphics;
using OpenRA.Primitives;
using OpenRA.Scripting;
namespace OpenRA.Mods.Common.Scripting.Global
{
// Kept as HSLColor for backwards compatibility
[ScriptGlobal("HSLColor")]
public class ColorGlobal : ScriptGlobal
{
public ColorGlobal(ScriptContext context)
: base(context) { }
[Desc("Create a new color with the specified hue/saturation/luminosity.")]
public Color New(int hue, int saturation, int luminosity)
{
var h = (byte)hue.Clamp(0, 255);
var s = (byte)saturation.Clamp(0, 255);
var l = (byte)luminosity.Clamp(0, 255);
return Color.FromAhsl(h, s, l);
}
[Desc("Create a new color with the specified red/green/blue/[alpha] values.")]
public Color FromRGB(int red, int green, int blue, int alpha = 255)
{
return Color.FromArgb(
alpha.Clamp(0, 255),
red.Clamp(0, 255),
green.Clamp(0, 255),
blue.Clamp(0, 255));
}
[Desc("Create a new color with the specified red/green/blue/[alpha] hex string (rrggbb[aa]).")]
public Color FromHex(string value)
{
Color color;
if (Color.TryParse(value, out color))
return color;
throw new LuaException("Invalid rrggbb[aa] hex string.");
}
public Color Aqua { get { return Color.Aqua; } }
public Color Black { get { return Color.Black; } }
public Color Blue { get { return Color.Blue; } }
public Color Brown { get { return Color.Brown; } }
public Color Cyan { get { return Color.Cyan; } }
public Color DarkBlue { get { return Color.DarkBlue; } }
public Color DarkCyan { get { return Color.DarkCyan; } }
public Color DarkGray { get { return Color.DarkGray; } }
public Color DarkGreen { get { return Color.DarkGreen; } }
public Color DarkOrange { get { return Color.DarkOrange; } }
public Color DarkRed { get { return Color.DarkRed; } }
public Color Fuchsia { get { return Color.Fuchsia; } }
public Color Gold { get { return Color.Gold; } }
public Color Gray { get { return Color.Gray; } }
public Color Green { get { return Color.Green; } }
public Color LawnGreen { get { return Color.LawnGreen; } }
public Color LightBlue { get { return Color.LightBlue; } }
public Color LightCyan { get { return Color.LightCyan; } }
public Color LightGray { get { return Color.LightGray; } }
public Color LightGreen { get { return Color.LightGreen; } }
public Color LightYellow { get { return Color.LightYellow; } }
public Color Lime { get { return Color.Lime; } }
public Color LimeGreen { get { return Color.LimeGreen; } }
public Color Magenta { get { return Color.Magenta; } }
public Color Maroon { get { return Color.Maroon; } }
public Color Navy { get { return Color.Navy; } }
public Color Olive { get { return Color.Olive; } }
public Color Orange { get { return Color.Orange; } }
public Color OrangeRed { get { return Color.OrangeRed; } }
public Color Purple { get { return Color.Purple; } }
public Color Red { get { return Color.Red; } }
public Color Salmon { get { return Color.Salmon; } }
public Color SkyBlue { get { return Color.SkyBlue; } }
public Color Teal { get { return Color.Teal; } }
public Color Yellow { get { return Color.Yellow; } }
public Color White { get { return Color.White; } }
}
}

View File

@@ -1,90 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007-2019 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, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using Eluant;
using OpenRA.Graphics;
using OpenRA.Primitives;
using OpenRA.Scripting;
namespace OpenRA.Mods.Common.Scripting.Global
{
[ScriptGlobal("HSLColor")]
public class HSLColorGlobal : ScriptGlobal
{
public HSLColorGlobal(ScriptContext context)
: base(context) { }
[Desc("Create a new HSL color with the specified hue/saturation/luminosity.")]
public HSLColor New(int hue, int saturation, int luminosity)
{
var h = (byte)hue.Clamp(0, 255);
var s = (byte)saturation.Clamp(0, 255);
var l = (byte)luminosity.Clamp(0, 255);
return new HSLColor(h, s, l);
}
[Desc("Create a new HSL color with the specified red/green/blue/[alpha] values.")]
public HSLColor FromRGB(int red, int green, int blue, int alpha = 255)
{
return new HSLColor(
Color.FromArgb(
alpha.Clamp(0, 255), red.Clamp(0, 255), green.Clamp(0, 255), blue.Clamp(0, 255)));
}
[Desc("Create a new HSL color with the specified red/green/blue/[alpha] hex string (rrggbb[aa]).")]
public HSLColor FromHex(string value)
{
Color rgb;
if (HSLColor.TryParseRGB(value, out rgb))
return new HSLColor(rgb);
throw new LuaException("Invalid rrggbb[aa] hex string.");
}
public HSLColor Aqua { get { return new HSLColor(Color.Aqua); } }
public HSLColor Black { get { return new HSLColor(Color.Black); } }
public HSLColor Blue { get { return new HSLColor(Color.Blue); } }
public HSLColor Brown { get { return new HSLColor(Color.Brown); } }
public HSLColor Cyan { get { return new HSLColor(Color.Cyan); } }
public HSLColor DarkBlue { get { return new HSLColor(Color.DarkBlue); } }
public HSLColor DarkCyan { get { return new HSLColor(Color.DarkCyan); } }
public HSLColor DarkGray { get { return new HSLColor(Color.DarkGray); } }
public HSLColor DarkGreen { get { return new HSLColor(Color.DarkGreen); } }
public HSLColor DarkOrange { get { return new HSLColor(Color.DarkOrange); } }
public HSLColor DarkRed { get { return new HSLColor(Color.DarkRed); } }
public HSLColor Fuchsia { get { return new HSLColor(Color.Fuchsia); } }
public HSLColor Gold { get { return new HSLColor(Color.Gold); } }
public HSLColor Gray { get { return new HSLColor(Color.Gray); } }
public HSLColor Green { get { return new HSLColor(Color.Green); } }
public HSLColor LawnGreen { get { return new HSLColor(Color.LawnGreen); } }
public HSLColor LightBlue { get { return new HSLColor(Color.LightBlue); } }
public HSLColor LightCyan { get { return new HSLColor(Color.LightCyan); } }
public HSLColor LightGray { get { return new HSLColor(Color.LightGray); } }
public HSLColor LightGreen { get { return new HSLColor(Color.LightGreen); } }
public HSLColor LightYellow { get { return new HSLColor(Color.LightYellow); } }
public HSLColor Lime { get { return new HSLColor(Color.Lime); } }
public HSLColor LimeGreen { get { return new HSLColor(Color.LimeGreen); } }
public HSLColor Magenta { get { return new HSLColor(Color.Magenta); } }
public HSLColor Maroon { get { return new HSLColor(Color.Maroon); } }
public HSLColor Navy { get { return new HSLColor(Color.Navy); } }
public HSLColor Olive { get { return new HSLColor(Color.Olive); } }
public HSLColor Orange { get { return new HSLColor(Color.Orange); } }
public HSLColor OrangeRed { get { return new HSLColor(Color.OrangeRed); } }
public HSLColor Purple { get { return new HSLColor(Color.Purple); } }
public HSLColor Red { get { return new HSLColor(Color.Red); } }
public HSLColor Salmon { get { return new HSLColor(Color.Salmon); } }
public HSLColor SkyBlue { get { return new HSLColor(Color.SkyBlue); } }
public HSLColor Teal { get { return new HSLColor(Color.Teal); } }
public HSLColor Yellow { get { return new HSLColor(Color.Yellow); } }
public HSLColor White { get { return new HSLColor(Color.White); } }
}
}

View File

@@ -189,12 +189,12 @@ namespace OpenRA.Mods.Common.Scripting
}
[Desc("Display a text message to the player.")]
public void DisplayMessage(string text, string prefix = "Mission", HSLColor? color = null)
public void DisplayMessage(string text, string prefix = "Mission", Color? color = null)
{
if (string.IsNullOrEmpty(text))
return;
Color c = color.HasValue ? HSLColor.RGBFromHSL(color.Value.H / 255f, color.Value.S / 255f, color.Value.L / 255f) : Color.White;
var c = color.HasValue ? color.Value : Color.White;
Game.AddChatLine(c, prefix, text);
}
@@ -208,12 +208,12 @@ namespace OpenRA.Mods.Common.Scripting
}
[Desc("Display a text message at the specified location.")]
public void FloatingText(string text, WPos position, int duration = 30, HSLColor? color = null)
public void FloatingText(string text, WPos position, int duration = 30, Color? color = null)
{
if (string.IsNullOrEmpty(text) || !world.Map.Contains(world.Map.CellContaining(position)))
return;
Color c = color.HasValue ? HSLColor.RGBFromHSL(color.Value.H / 255f, color.Value.S / 255f, color.Value.L / 255f) : Color.White;
var c = color.HasValue ? color.Value : Color.White;
world.AddFrameEndTask(w => w.Add(new FloatingText(position, c, text, duration)));
}

View File

@@ -9,8 +9,8 @@
*/
#endregion
using OpenRA.Graphics;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Scripting;
namespace OpenRA.Mods.Common.Scripting
@@ -26,14 +26,14 @@ namespace OpenRA.Mods.Common.Scripting
}
[Desc("Creates a new radar ping that stays for the specified time at the specified WPos.")]
public void Ping(Player player, WPos position, HSLColor color, int duration = 30 * 25)
public void Ping(Player player, WPos position, Color color, int duration = 30 * 25)
{
if (radarPings != null)
{
radarPings.Add(
() => player.World.RenderPlayer == player,
position,
color.RGB,
color,
duration);
}
}

View File

@@ -24,12 +24,12 @@ namespace OpenRA.Mods.Common.Scripting.Global
: base(context) { }
[Desc("Displays a text message at the top center of the screen.")]
public void SetMissionText(string text, HSLColor? color = null)
public void SetMissionText(string text, Color? color = null)
{
var luaLabel = Ui.Root.Get("INGAME_ROOT").Get<LabelWidget>("MISSION_TEXT");
luaLabel.GetText = () => text;
Color c = color.HasValue ? HSLColor.RGBFromHSL(color.Value.H / 255f, color.Value.S / 255f, color.Value.L / 255f) : Color.White;
var c = color.HasValue ? color.Value : Color.White;
luaLabel.GetColor = () => c;
}
}