Remove HSLColor.
This commit is contained in:
@@ -228,7 +228,7 @@ namespace OpenRA
|
||||
else if (fieldType == typeof(Color))
|
||||
{
|
||||
Color color;
|
||||
if (value != null && HSLColor.TryParseRGB(value, out color))
|
||||
if (value != null && Color.TryParse(value, out color))
|
||||
return color;
|
||||
|
||||
return InvalidValueAction(value, fieldType, fieldName);
|
||||
@@ -241,7 +241,7 @@ namespace OpenRA
|
||||
var colors = new Color[parts.Length];
|
||||
|
||||
for (var i = 0; i < colors.Length; i++)
|
||||
if (!HSLColor.TryParseRGB(parts[i], out colors[i]))
|
||||
if (!Color.TryParse(parts[i], out colors[i]))
|
||||
return InvalidValueAction(value, fieldType, fieldName);
|
||||
|
||||
return colors;
|
||||
@@ -249,25 +249,6 @@ namespace OpenRA
|
||||
|
||||
return InvalidValueAction(value, fieldType, fieldName);
|
||||
}
|
||||
else if (fieldType == typeof(HSLColor))
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
Color rgb;
|
||||
if (HSLColor.TryParseRGB(value, out rgb))
|
||||
return new HSLColor(rgb);
|
||||
|
||||
// Allow old HSLColor/ColorRamp formats to be parsed as HSLColor
|
||||
var parts = value.Split(',');
|
||||
if (parts.Length == 3 || parts.Length == 4)
|
||||
return new HSLColor(
|
||||
(byte)Exts.ParseIntegerInvariant(parts[0]).Clamp(0, 255),
|
||||
(byte)Exts.ParseIntegerInvariant(parts[1]).Clamp(0, 255),
|
||||
(byte)Exts.ParseIntegerInvariant(parts[2]).Clamp(0, 255));
|
||||
}
|
||||
|
||||
return InvalidValueAction(value, fieldType, fieldName);
|
||||
}
|
||||
else if (fieldType == typeof(Hotkey))
|
||||
{
|
||||
Hotkey res;
|
||||
|
||||
@@ -74,16 +74,9 @@ namespace OpenRA
|
||||
|
||||
var t = v.GetType();
|
||||
|
||||
// Color.ToString() does the wrong thing; force it to format as rgb[a] hex
|
||||
if (t == typeof(Color))
|
||||
{
|
||||
return HSLColor.ToHexString((Color)v);
|
||||
}
|
||||
|
||||
// HSLColor.ToString() does the wrong thing; force it to format as rgb[a] hex
|
||||
if (t == typeof(HSLColor))
|
||||
{
|
||||
return ((HSLColor)v).ToHexString();
|
||||
return ((Color)v).ToString();
|
||||
}
|
||||
|
||||
if (t == typeof(Rectangle))
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Network;
|
||||
using OpenRA.Primitives;
|
||||
|
||||
namespace OpenRA
|
||||
{
|
||||
@@ -155,7 +155,7 @@ namespace OpenRA
|
||||
|
||||
/// <summary>The faction ID, a.k.a. the faction's internal name.</summary>
|
||||
public string FactionId;
|
||||
public HSLColor Color;
|
||||
public Color Color;
|
||||
|
||||
/// <summary>The team ID on start-up, or 0 if the player is not part of a team.</summary>
|
||||
public int Team;
|
||||
|
||||
@@ -1,147 +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 System.Globalization;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Scripting;
|
||||
|
||||
namespace OpenRA.Graphics
|
||||
{
|
||||
public struct HSLColor : IScriptBindable
|
||||
{
|
||||
public readonly byte H;
|
||||
public readonly byte S;
|
||||
public readonly byte L;
|
||||
public readonly Color RGB;
|
||||
|
||||
public static HSLColor FromHSV(float h, float s, float v)
|
||||
{
|
||||
var ll = 0.5f * (2 - s) * v;
|
||||
var ss = (ll >= 1 || v <= 0) ? 0 : 0.5f * s * v / (ll <= 0.5f ? ll : 1 - ll);
|
||||
return new HSLColor((byte)(255 * h), (byte)(255 * ss), (byte)(255 * ll));
|
||||
}
|
||||
|
||||
public HSLColor(Color color)
|
||||
{
|
||||
RGB = color;
|
||||
H = (byte)((color.GetHue() / 360.0f) * 255);
|
||||
S = (byte)(color.GetSaturation() * 255);
|
||||
L = (byte)(color.GetBrightness() * 255);
|
||||
}
|
||||
|
||||
public static HSLColor FromRGB(int r, int g, int b)
|
||||
{
|
||||
return new HSLColor(Color.FromArgb(r, g, b));
|
||||
}
|
||||
|
||||
public static Color RGBFromHSL(float h, float s, float l)
|
||||
{
|
||||
// Convert from HSL to RGB
|
||||
var q = (l < 0.5f) ? l * (1 + s) : l + s - (l * s);
|
||||
var p = 2 * l - q;
|
||||
|
||||
float[] trgb = { h + 1 / 3.0f, h, h - 1 / 3.0f };
|
||||
float[] rgb = { 0, 0, 0 };
|
||||
|
||||
for (var k = 0; k < 3; k++)
|
||||
{
|
||||
while (trgb[k] < 0) trgb[k] += 1.0f;
|
||||
while (trgb[k] > 1) trgb[k] -= 1.0f;
|
||||
}
|
||||
|
||||
for (var k = 0; k < 3; k++)
|
||||
{
|
||||
if (trgb[k] < 1 / 6.0f)
|
||||
rgb[k] = p + ((q - p) * 6 * trgb[k]);
|
||||
else if (trgb[k] >= 1 / 6.0f && trgb[k] < 0.5)
|
||||
rgb[k] = q;
|
||||
else if (trgb[k] >= 0.5f && trgb[k] < 2.0f / 3)
|
||||
rgb[k] = p + ((q - p) * 6 * (2.0f / 3 - trgb[k]));
|
||||
else
|
||||
rgb[k] = p;
|
||||
}
|
||||
|
||||
return Color.FromArgb((int)(rgb[0] * 255), (int)(rgb[1] * 255), (int)(rgb[2] * 255));
|
||||
}
|
||||
|
||||
public static bool TryParseRGB(string value, out Color color)
|
||||
{
|
||||
color = new Color();
|
||||
value = value.Trim();
|
||||
if (value.Length != 6 && value.Length != 8)
|
||||
return false;
|
||||
|
||||
byte red, green, blue, alpha = 255;
|
||||
if (!byte.TryParse(value.Substring(0, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out red)
|
||||
|| !byte.TryParse(value.Substring(2, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out green)
|
||||
|| !byte.TryParse(value.Substring(4, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out blue))
|
||||
return false;
|
||||
|
||||
if (value.Length == 8
|
||||
&& !byte.TryParse(value.Substring(6, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out alpha))
|
||||
return false;
|
||||
|
||||
color = Color.FromArgb(alpha, red, green, blue);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool operator ==(HSLColor me, HSLColor other)
|
||||
{
|
||||
// Binary floating point numbers (float, double) calculations can yield the same RGB color created by different functions with little different HSL representation
|
||||
return (me.H == other.H && me.S == other.S && me.L == other.L) || me.RGB == other.RGB;
|
||||
}
|
||||
|
||||
public static bool operator !=(HSLColor me, HSLColor other) { return !(me == other); }
|
||||
|
||||
public HSLColor(byte h, byte s, byte l)
|
||||
{
|
||||
H = h;
|
||||
S = s;
|
||||
L = l;
|
||||
RGB = RGBFromHSL(H / 255f, S / 255f, L / 255f);
|
||||
}
|
||||
|
||||
public void ToHSV(out float h, out float s, out float v)
|
||||
{
|
||||
var ll = 2 * L / 255f;
|
||||
var ss = S / 255f * ((ll <= 1) ? ll : 2 - ll);
|
||||
|
||||
h = H / 255f;
|
||||
s = (2 * ss) / (ll + ss);
|
||||
v = (ll + ss) / 2;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "{0},{1},{2}".F(H, S, L);
|
||||
}
|
||||
|
||||
public static string ToHexString(Color color)
|
||||
{
|
||||
if (color.A == 255)
|
||||
return color.R.ToString("X2") + color.G.ToString("X2") + color.B.ToString("X2");
|
||||
return color.R.ToString("X2") + color.G.ToString("X2") + color.B.ToString("X2") + color.A.ToString("X2");
|
||||
}
|
||||
|
||||
public string ToHexString()
|
||||
{
|
||||
return ToHexString(RGB);
|
||||
}
|
||||
|
||||
public override int GetHashCode() { return H.GetHashCode() ^ S.GetHashCode() ^ L.GetHashCode(); }
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
var o = obj as HSLColor?;
|
||||
return o != null && o == this;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,12 +25,16 @@ namespace OpenRA.Graphics
|
||||
return ramp[i];
|
||||
}
|
||||
|
||||
public PlayerColorRemap(int[] ramp, HSLColor c, float rampFraction)
|
||||
public PlayerColorRemap(int[] ramp, Color c, float rampFraction)
|
||||
{
|
||||
var h = c.GetHue() / 360.0f;
|
||||
var s = c.GetSaturation();
|
||||
var l = c.GetBrightness();
|
||||
|
||||
// Increase luminosity if required to represent the full ramp
|
||||
var rampRange = (byte)((1 - rampFraction) * c.L);
|
||||
var c1 = new HSLColor(c.H, c.S, Math.Max(rampRange, c.L)).RGB;
|
||||
var c2 = new HSLColor(c.H, c.S, (byte)Math.Max(0, c.L - rampRange)).RGB;
|
||||
var rampRange = (byte)((1 - rampFraction) * l);
|
||||
var c1 = Color.FromAhsl(h, s, Math.Max(rampRange, l));
|
||||
var c2 = Color.FromAhsl(h, s, (byte)Math.Max(0, l - rampRange));
|
||||
var baseIndex = ramp[0];
|
||||
var remapRamp = ramp.Select(r => r - ramp[0]);
|
||||
var rampMaxIndex = ramp.Length - 1;
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace OpenRA.Graphics
|
||||
debugVis = Exts.Lazy(() => world.WorldActor.TraitOrDefault<DebugVisualizations>());
|
||||
}
|
||||
|
||||
public void UpdatePalettesForPlayer(string internalName, HSLColor color, bool replaceExisting)
|
||||
public void UpdatePalettesForPlayer(string internalName, Color color, bool replaceExisting)
|
||||
{
|
||||
foreach (var pal in World.WorldActor.TraitsImplementing<ILoadsPlayerPalettes>())
|
||||
pal.LoadPlayerPalettes(this, internalName, color, replaceExisting);
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Primitives;
|
||||
|
||||
namespace OpenRA
|
||||
{
|
||||
@@ -30,7 +30,7 @@ namespace OpenRA
|
||||
public string Faction;
|
||||
|
||||
public bool LockColor = false;
|
||||
public HSLColor Color = new HSLColor(0, 0, 238);
|
||||
public Color Color = Color.FromAhsl(0, 0, 238);
|
||||
|
||||
public bool LockSpawn = false;
|
||||
public int Spawn = 0;
|
||||
|
||||
@@ -13,7 +13,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Primitives;
|
||||
|
||||
namespace OpenRA.Network
|
||||
{
|
||||
@@ -21,7 +21,7 @@ namespace OpenRA.Network
|
||||
{
|
||||
public readonly string Name;
|
||||
public readonly string Fingerprint;
|
||||
public readonly HSLColor Color;
|
||||
public readonly Color Color;
|
||||
public readonly string Faction;
|
||||
public readonly int Team;
|
||||
public readonly int SpawnPoint;
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Primitives;
|
||||
|
||||
namespace OpenRA.Network
|
||||
{
|
||||
@@ -110,8 +110,8 @@ namespace OpenRA.Network
|
||||
}
|
||||
|
||||
public int Index;
|
||||
public HSLColor PreferredColor; // Color that the client normally uses from settings.yaml.
|
||||
public HSLColor Color; // Actual color that the client is using. Usually the same as PreferredColor but can be different on maps with locked colors.
|
||||
public Color PreferredColor; // Color that the client normally uses from settings.yaml.
|
||||
public Color Color; // Actual color that the client is using. Usually the same as PreferredColor but can be different on maps with locked colors.
|
||||
public string Faction;
|
||||
public int SpawnPoint;
|
||||
public string Name;
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace OpenRA.Network
|
||||
if (orderManager.LocalClient != null && client != orderManager.LocalClient && client.Team > 0 && client.Team == orderManager.LocalClient.Team)
|
||||
suffix += " (Ally)";
|
||||
|
||||
Game.AddChatLine(client.Color.RGB, client.Name + suffix, message);
|
||||
Game.AddChatLine(client.Color, client.Name + suffix, message);
|
||||
}
|
||||
else
|
||||
Game.AddChatLine(Color.White, "(player {0})".F(clientId), message);
|
||||
@@ -86,17 +86,17 @@ namespace OpenRA.Network
|
||||
if (world == null)
|
||||
{
|
||||
if (orderManager.LocalClient != null && client.Team == orderManager.LocalClient.Team)
|
||||
Game.AddChatLine(client.Color.RGB, "[Team] " + client.Name, order.TargetString);
|
||||
Game.AddChatLine(client.Color, "[Team] " + client.Name, order.TargetString);
|
||||
}
|
||||
else
|
||||
{
|
||||
var player = world.FindPlayerByClient(client);
|
||||
if (player != null && player.WinState == WinState.Lost)
|
||||
Game.AddChatLine(client.Color.RGB, client.Name + " (Dead)", order.TargetString);
|
||||
Game.AddChatLine(client.Color, client.Name + " (Dead)", order.TargetString);
|
||||
else if ((player != null && world.LocalPlayer != null && player.Stances[world.LocalPlayer] == Stance.Ally) || (world.IsReplay && player != null))
|
||||
Game.AddChatLine(client.Color.RGB, "[Team" + (world.IsReplay ? " " + client.Team : "") + "] " + client.Name, order.TargetString);
|
||||
Game.AddChatLine(client.Color, "[Team" + (world.IsReplay ? " " + client.Team : "") + "] " + client.Name, order.TargetString);
|
||||
else if ((orderManager.LocalClient != null && orderManager.LocalClient.IsObserver && client.IsObserver) || (world.IsReplay && client.IsObserver))
|
||||
Game.AddChatLine(client.Color.RGB, "[Spectators] " + client.Name, order.TargetString);
|
||||
Game.AddChatLine(client.Color, "[Spectators] " + client.Name, order.TargetString);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -296,7 +296,6 @@
|
||||
<Compile Include="Map\Map.cs" />
|
||||
<Compile Include="Map\MapCache.cs" />
|
||||
<Compile Include="Map\MapPreview.cs" />
|
||||
<Compile Include="Graphics\HSLColor.cs" />
|
||||
<Compile Include="CPos.cs" />
|
||||
<Compile Include="CVec.cs" />
|
||||
<Compile Include="WAngle.cs" />
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace OpenRA
|
||||
}
|
||||
|
||||
public readonly Actor PlayerActor;
|
||||
public readonly HSLColor Color;
|
||||
public readonly Color Color;
|
||||
|
||||
public readonly string PlayerName;
|
||||
public readonly string InternalName;
|
||||
|
||||
@@ -378,7 +378,7 @@ namespace OpenRA.Server
|
||||
if (client.Slot != null)
|
||||
SyncClientToPlayerReference(client, Map.Players.Players[client.Slot]);
|
||||
else
|
||||
client.Color = HSLColor.FromRGB(255, 255, 255);
|
||||
client.Color = Color.White;
|
||||
|
||||
// Promote connection to a valid client
|
||||
PreConns.Remove(newConn);
|
||||
|
||||
@@ -14,6 +14,7 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA
|
||||
@@ -186,9 +187,9 @@ namespace OpenRA
|
||||
{
|
||||
[Desc("Sets the player nickname for in-game and IRC chat.")]
|
||||
public string Name = "Newbie";
|
||||
public HSLColor Color = new HSLColor(75, 255, 180);
|
||||
public Color Color = Color.FromAhsl(75, 255, 180);
|
||||
public string LastServer = "localhost:1234";
|
||||
public HSLColor[] CustomColors = { };
|
||||
public Color[] CustomColors = { };
|
||||
}
|
||||
|
||||
public class GameSettings
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#endregion
|
||||
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Primitives;
|
||||
|
||||
namespace OpenRA.Traits
|
||||
{
|
||||
@@ -26,7 +27,7 @@ namespace OpenRA.Traits
|
||||
public readonly int[] RemapIndex = { };
|
||||
|
||||
[Desc("The fixed color to remap.")]
|
||||
public readonly HSLColor Color;
|
||||
public readonly Color Color;
|
||||
|
||||
[Desc("Luminosity range to span.")]
|
||||
public readonly float Ramp = 0.05f;
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace OpenRA.Traits
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public void LoadPlayerPalettes(WorldRenderer wr, string playerName, HSLColor color, bool replaceExisting)
|
||||
public void LoadPlayerPalettes(WorldRenderer wr, string playerName, Color color, bool replaceExisting)
|
||||
{
|
||||
var basePalette = wr.Palette(info.BasePalette).Palette;
|
||||
ImmutablePalette pal;
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#endregion
|
||||
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Primitives;
|
||||
|
||||
namespace OpenRA.Traits
|
||||
{
|
||||
@@ -43,7 +44,7 @@ namespace OpenRA.Traits
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public void LoadPlayerPalettes(WorldRenderer wr, string playerName, HSLColor color, bool replaceExisting)
|
||||
public void LoadPlayerPalettes(WorldRenderer wr, string playerName, Color color, bool replaceExisting)
|
||||
{
|
||||
var remap = new PlayerColorRemap(info.RemapIndex, color, info.Ramp);
|
||||
var pal = new ImmutablePalette(wr.Palette(info.BasePalette).Palette, remap);
|
||||
|
||||
@@ -33,9 +33,9 @@ namespace OpenRA.Traits
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public void LoadPlayerPalettes(WorldRenderer wr, string playerName, HSLColor color, bool replaceExisting)
|
||||
public void LoadPlayerPalettes(WorldRenderer wr, string playerName, Color color, bool replaceExisting)
|
||||
{
|
||||
var argb = (uint)Color.FromArgb(128, color.RGB).ToArgb();
|
||||
var argb = (uint)Color.FromArgb(128, color).ToArgb();
|
||||
var pal = new ImmutablePalette(Enumerable.Range(0, Palette.Size).Select(i => i == 0 ? 0 : argb));
|
||||
wr.AddPalette(info.BaseName + playerName, pal, false, replaceExisting);
|
||||
}
|
||||
|
||||
@@ -278,7 +278,7 @@ namespace OpenRA.Traits
|
||||
}
|
||||
|
||||
public interface ILoadsPalettes { void LoadPalettes(WorldRenderer wr); }
|
||||
public interface ILoadsPlayerPalettes { void LoadPlayerPalettes(WorldRenderer wr, string playerName, HSLColor playerColor, bool replaceExisting); }
|
||||
public interface ILoadsPlayerPalettes { void LoadPlayerPalettes(WorldRenderer wr, string playerName, Color playerColor, bool replaceExisting); }
|
||||
public interface IPaletteModifier { void AdjustPalette(IReadOnlyDictionary<string, MutablePalette> b); }
|
||||
public interface IPips { IEnumerable<PipType> GetPips(Actor self); }
|
||||
|
||||
|
||||
@@ -256,8 +256,7 @@ namespace OpenRA.Widgets
|
||||
|
||||
public static Color GetContrastColor(Color fgColor, Color bgDark, Color bgLight)
|
||||
{
|
||||
var fg = new HSLColor(fgColor);
|
||||
return fg.RGB == Color.White || fg.L > 80 ? bgDark : bgLight;
|
||||
return fgColor == Color.White || fgColor.GetBrightness() > 0.33 ? bgDark : bgLight;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
playerRadarPing = radarPings.Add(
|
||||
() => self.Owner.IsAlliedWith(self.World.RenderPlayer),
|
||||
pos,
|
||||
self.Owner.Color.RGB,
|
||||
self.Owner.Color,
|
||||
info.Duration);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -169,7 +169,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
if (!Disguised || self.Owner.IsAlliedWith(self.World.RenderPlayer))
|
||||
return color;
|
||||
|
||||
return color = Game.Settings.Game.UsePlayerStanceColors ? AsPlayer.PlayerStanceColor(self) : AsPlayer.Color.RGB;
|
||||
return color = Game.Settings.Game.UsePlayerStanceColors ? AsPlayer.PlayerStanceColor(self) : AsPlayer.Color;
|
||||
}
|
||||
|
||||
public void DisguiseAs(Actor target)
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", info.Notification, self.Owner.Faction.InternalName);
|
||||
|
||||
if (info.ShowTicks)
|
||||
self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, infiltrator.Owner.Color.RGB, FloatingText.FormatCashTick(toGive), 30)));
|
||||
self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, infiltrator.Owner.Color, FloatingText.FormatCashTick(toGive), 30)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
exp.GiveExperience(playerExperience);
|
||||
|
||||
if (self.Owner.IsAlliedWith(self.World.RenderPlayer))
|
||||
self.World.AddFrameEndTask(w => w.Add(new FloatingText(targetActor.CenterPosition, targetOwner.Color.RGB, FloatingText.FormatCashTick(donated), 30)));
|
||||
self.World.AddFrameEndTask(w => w.Add(new FloatingText(targetActor.CenterPosition, targetOwner.Color, FloatingText.FormatCashTick(donated), 30)));
|
||||
|
||||
foreach (var nct in targetActor.TraitsImplementing<INotifyCashTransfer>())
|
||||
nct.OnAcceptingCash(targetActor, self);
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
ns.Sold(self);
|
||||
|
||||
if (showTicks && refund > 0 && self.Owner.IsAlliedWith(self.World.RenderPlayer))
|
||||
self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, self.Owner.Color.RGB, FloatingText.FormatCashTick(refund), 30)));
|
||||
self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, self.Owner.Color, FloatingText.FormatCashTick(refund), 30)));
|
||||
|
||||
self.Dispose();
|
||||
return this;
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace OpenRA.Mods.Common
|
||||
public readonly int Threshold = 0x50;
|
||||
public readonly float[] HsvSaturationRange = new[] { 0.25f, 1f };
|
||||
public readonly float[] HsvValueRange = new[] { 0.2f, 1.0f };
|
||||
public readonly HSLColor[] TeamColorPresets = { };
|
||||
public readonly Color[] TeamColorPresets = { };
|
||||
|
||||
double GetColorDelta(Color colorA, Color colorB)
|
||||
{
|
||||
@@ -59,7 +59,9 @@ namespace OpenRA.Mods.Common
|
||||
{
|
||||
// Validate color against HSV
|
||||
float h, s, v;
|
||||
new HSLColor(askedColor).ToHSV(out h, out s, out v);
|
||||
int a;
|
||||
|
||||
askedColor.ToAhsv(out a, out h, out s, out v);
|
||||
if (s < HsvSaturationRange[0] || s > HsvSaturationRange[1] || v < HsvValueRange[0] || v > HsvValueRange[1])
|
||||
{
|
||||
onError("Color was adjusted to be inside the allowed range.");
|
||||
@@ -87,23 +89,23 @@ namespace OpenRA.Mods.Common
|
||||
return true;
|
||||
}
|
||||
|
||||
public HSLColor RandomPresetColor(MersenneTwister random, IEnumerable<Color> terrainColors, IEnumerable<Color> playerColors)
|
||||
public Color RandomPresetColor(MersenneTwister random, IEnumerable<Color> terrainColors, IEnumerable<Color> playerColors)
|
||||
{
|
||||
if (TeamColorPresets.Any())
|
||||
{
|
||||
Color forbidden;
|
||||
Action<string> ignoreError = _ => { };
|
||||
foreach (var c in TeamColorPresets.Shuffle(random))
|
||||
if (IsValid(c.RGB, out forbidden, terrainColors, playerColors, ignoreError))
|
||||
if (IsValid(c, out forbidden, terrainColors, playerColors, ignoreError))
|
||||
return c;
|
||||
}
|
||||
|
||||
return RandomValidColor(random, terrainColors, playerColors);
|
||||
}
|
||||
|
||||
public HSLColor RandomValidColor(MersenneTwister random, IEnumerable<Color> terrainColors, IEnumerable<Color> playerColors)
|
||||
public Color RandomValidColor(MersenneTwister random, IEnumerable<Color> terrainColors, IEnumerable<Color> playerColors)
|
||||
{
|
||||
HSLColor color;
|
||||
Color color;
|
||||
Color forbidden;
|
||||
Action<string> ignoreError = _ => { };
|
||||
do
|
||||
@@ -111,17 +113,17 @@ namespace OpenRA.Mods.Common
|
||||
var h = random.Next(255) / 255f;
|
||||
var s = float2.Lerp(HsvSaturationRange[0], HsvSaturationRange[1], random.NextFloat());
|
||||
var v = float2.Lerp(HsvValueRange[0], HsvValueRange[1], random.NextFloat());
|
||||
color = HSLColor.FromHSV(h, s, v);
|
||||
} while (!IsValid(color.RGB, out forbidden, terrainColors, playerColors, ignoreError));
|
||||
color = Color.FromAhsv(h, s, v);
|
||||
} while (!IsValid(color, out forbidden, terrainColors, playerColors, ignoreError));
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
public HSLColor MakeValid(Color askedColor, MersenneTwister random, IEnumerable<Color> terrainColors, IEnumerable<Color> playerColors, Action<string> onError)
|
||||
public Color MakeValid(Color askedColor, MersenneTwister random, IEnumerable<Color> terrainColors, IEnumerable<Color> playerColors, Action<string> onError)
|
||||
{
|
||||
Color forbiddenColor;
|
||||
if (IsValid(askedColor, out forbiddenColor, terrainColors, playerColors, onError))
|
||||
return new HSLColor(askedColor);
|
||||
return askedColor;
|
||||
|
||||
// Vector between the 2 colors
|
||||
var vector = new double[]
|
||||
@@ -151,7 +153,7 @@ namespace OpenRA.Mods.Common
|
||||
|
||||
var attempt = 1;
|
||||
var allForbidden = terrainColors.Concat(playerColors);
|
||||
HSLColor color;
|
||||
Color color;
|
||||
do
|
||||
{
|
||||
// If we reached the limit (The ii >= 255 prevents too much calculations)
|
||||
@@ -167,10 +169,10 @@ namespace OpenRA.Mods.Common
|
||||
var b = (forbiddenColor.B + (int)(vector[2] * weightVector[2] * attempt)).Clamp(0, 255);
|
||||
|
||||
// Get the alternative color attempt
|
||||
color = new HSLColor(Color.FromArgb(r, g, b));
|
||||
color = Color.FromArgb(r, g, b);
|
||||
|
||||
attempt++;
|
||||
} while (!IsValid(color.RGB, allForbidden, out forbiddenColor));
|
||||
} while (!IsValid(color, allForbidden, out forbiddenColor));
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ namespace OpenRA.Mods.Common.Effects
|
||||
IEnumerable<IRenderable> RenderInner(WorldRenderer wr)
|
||||
{
|
||||
if (Game.Settings.Game.DrawTargetLine)
|
||||
yield return new TargetLineRenderable(targetLine, building.Owner.Color.RGB);
|
||||
yield return new TargetLineRenderable(targetLine, building.Owner.Color);
|
||||
|
||||
if (circles != null || flag != null)
|
||||
{
|
||||
|
||||
@@ -108,7 +108,7 @@ namespace OpenRA.Mods.Common.Graphics
|
||||
|
||||
public static Color ChooseColor(Actor self)
|
||||
{
|
||||
var ownerColor = Color.FromArgb(255, self.Owner.Color.RGB);
|
||||
var ownerColor = Color.FromArgb(255, self.Owner.Color);
|
||||
return Exts.ColorLerp(0.5f, ownerColor, Color.White);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -238,7 +238,7 @@
|
||||
<Compile Include="Scripting\Global\CoordinateGlobals.cs" />
|
||||
<Compile Include="Scripting\Global\DateTimeGlobal.cs" />
|
||||
<Compile Include="Scripting\Global\FacingGlobal.cs" />
|
||||
<Compile Include="Scripting\Global\HSLColorGlobal.cs" />
|
||||
<Compile Include="Scripting\Global\ColorGlobal.cs" />
|
||||
<Compile Include="Scripting\Global\MapGlobal.cs" />
|
||||
<Compile Include="Scripting\Global\MediaGlobal.cs" />
|
||||
<Compile Include="Scripting\Global\PlayerGlobal.cs" />
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace OpenRA.Mods.Common.Projectiles
|
||||
|
||||
public IProjectile Create(ProjectileArgs args)
|
||||
{
|
||||
var c = UsePlayerColor ? args.SourceActor.Owner.Color.RGB : Color;
|
||||
var c = UsePlayerColor ? args.SourceActor.Owner.Color : Color;
|
||||
return new AreaBeam(this, args, c);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ namespace OpenRA.Mods.Common.Projectiles
|
||||
|
||||
public IProjectile Create(ProjectileArgs args)
|
||||
{
|
||||
var c = UsePlayerColor ? args.SourceActor.Owner.Color.RGB : Color;
|
||||
var c = UsePlayerColor ? args.SourceActor.Owner.Color : Color;
|
||||
return new LaserZap(this, args, c);
|
||||
}
|
||||
}
|
||||
@@ -115,7 +115,7 @@ namespace OpenRA.Mods.Common.Projectiles
|
||||
this.args = args;
|
||||
this.info = info;
|
||||
this.color = color;
|
||||
secondaryColor = info.SecondaryBeamUsePlayerColor ? args.SourceActor.Owner.Color.RGB : info.SecondaryBeamColor;
|
||||
secondaryColor = info.SecondaryBeamUsePlayerColor ? args.SourceActor.Owner.Color : info.SecondaryBeamColor;
|
||||
target = args.PassiveTarget;
|
||||
source = args.Source;
|
||||
|
||||
|
||||
@@ -92,8 +92,8 @@ namespace OpenRA.Mods.Common.Projectiles
|
||||
|
||||
public IProjectile Create(ProjectileArgs args)
|
||||
{
|
||||
var bc = BeamPlayerColor ? Color.FromArgb(BeamColor.A, args.SourceActor.Owner.Color.RGB) : BeamColor;
|
||||
var hc = HelixPlayerColor ? Color.FromArgb(HelixColor.A, args.SourceActor.Owner.Color.RGB) : HelixColor;
|
||||
var bc = BeamPlayerColor ? Color.FromArgb(BeamColor.A, args.SourceActor.Owner.Color) : BeamColor;
|
||||
var hc = HelixPlayerColor ? Color.FromArgb(HelixColor.A, args.SourceActor.Owner.Color) : HelixColor;
|
||||
return new Railgun(args, this, bc, hc);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
radarPings.Add(
|
||||
() => owner.IsAlliedWith(owner.World.RenderPlayer),
|
||||
position,
|
||||
owner.Color.RGB,
|
||||
owner.Color,
|
||||
duration);
|
||||
}
|
||||
|
||||
|
||||
93
OpenRA.Mods.Common/Scripting/Global/ColorGlobal.cs
Normal file
93
OpenRA.Mods.Common/Scripting/Global/ColorGlobal.cs
Normal 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; } }
|
||||
}
|
||||
}
|
||||
@@ -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); } }
|
||||
}
|
||||
}
|
||||
@@ -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)));
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Eluant;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Scripting;
|
||||
|
||||
namespace OpenRA.Mods.Common.Scripting
|
||||
@@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
public string Name { get { return Player.PlayerName; } }
|
||||
|
||||
[Desc("The player's color.")]
|
||||
public HSLColor Color { get { return Player.Color; } }
|
||||
public Color Color { get { return Player.Color; } }
|
||||
|
||||
[Desc("The player's faction.")]
|
||||
public string Faction { get { return Player.Faction.InternalName; } }
|
||||
|
||||
@@ -15,6 +15,7 @@ using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Network;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Server;
|
||||
using OpenRA.Traits;
|
||||
using S = OpenRA.Server.Server;
|
||||
@@ -43,7 +44,7 @@ namespace OpenRA.Mods.Common.Server
|
||||
{ "faction", Faction },
|
||||
{ "team", Team },
|
||||
{ "spawn", Spawn },
|
||||
{ "color", Color },
|
||||
{ "color", PlayerColor },
|
||||
{ "sync_lobby", SyncLobby }
|
||||
};
|
||||
|
||||
@@ -212,7 +213,7 @@ namespace OpenRA.Mods.Common.Server
|
||||
client.Slot = null;
|
||||
client.SpawnPoint = 0;
|
||||
client.Team = 0;
|
||||
client.Color = HSLColor.FromRGB(255, 255, 255);
|
||||
client.Color = Color.White;
|
||||
server.SyncLobbyClients();
|
||||
CheckAutoStart(server);
|
||||
return true;
|
||||
@@ -345,8 +346,8 @@ namespace OpenRA.Mods.Common.Server
|
||||
var validator = server.ModData.Manifest.Get<ColorValidator>();
|
||||
var tileset = server.Map.Rules.TileSet;
|
||||
var terrainColors = tileset.TerrainInfo.Where(ti => ti.RestrictPlayerColor).Select(ti => ti.Color);
|
||||
var playerColors = server.LobbyInfo.Clients.Select(c => c.Color.RGB)
|
||||
.Concat(server.Map.Players.Players.Values.Select(p => p.Color.RGB));
|
||||
var playerColors = server.LobbyInfo.Clients.Select(c => c.Color)
|
||||
.Concat(server.Map.Players.Players.Values.Select(p => p.Color));
|
||||
bot.Color = bot.PreferredColor = validator.RandomPresetColor(server.Random, terrainColors, playerColors);
|
||||
|
||||
server.LobbyInfo.Clients.Add(bot);
|
||||
@@ -653,7 +654,7 @@ namespace OpenRA.Mods.Common.Server
|
||||
targetClient.Slot = null;
|
||||
targetClient.SpawnPoint = 0;
|
||||
targetClient.Team = 0;
|
||||
targetClient.Color = HSLColor.FromRGB(255, 255, 255);
|
||||
targetClient.Color = Color.White;
|
||||
targetClient.State = Session.ClientState.NotReady;
|
||||
server.SendMessage("{0} moved {1} to spectators.".F(client.Name, targetClient.Name));
|
||||
Log.Write("server", "{0} moved {1} to spectators.".F(client.Name, targetClient.Name));
|
||||
@@ -785,7 +786,7 @@ namespace OpenRA.Mods.Common.Server
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool Color(S server, Connection conn, Session.Client client, string s)
|
||||
static bool PlayerColor(S server, Connection conn, Session.Client client, string s)
|
||||
{
|
||||
var parts = s.Split(' ');
|
||||
var targetClient = server.LobbyInfo.ClientWithIndex(Exts.ParseIntegerInvariant(parts[0]));
|
||||
@@ -799,7 +800,7 @@ namespace OpenRA.Mods.Common.Server
|
||||
return true;
|
||||
|
||||
// Validate if color is allowed and get an alternative it isn't
|
||||
var newColor = FieldLoader.GetValue<HSLColor>("(value)", parts[1]);
|
||||
var newColor = FieldLoader.GetValue<Color>("(value)", parts[1]);
|
||||
targetClient.Color = SanitizePlayerColor(server, newColor, targetClient.Index, conn);
|
||||
|
||||
// Only update player's preferred color if new color is valid
|
||||
@@ -906,7 +907,7 @@ namespace OpenRA.Mods.Common.Server
|
||||
}
|
||||
}
|
||||
|
||||
static HSLColor SanitizePlayerColor(S server, HSLColor askedColor, int playerIndex, Connection connectionToEcho = null)
|
||||
static Color SanitizePlayerColor(S server, Color askedColor, int playerIndex, Connection connectionToEcho = null)
|
||||
{
|
||||
var validator = server.ModData.Manifest.Get<ColorValidator>();
|
||||
var askColor = askedColor;
|
||||
@@ -919,10 +920,10 @@ namespace OpenRA.Mods.Common.Server
|
||||
|
||||
var tileset = server.Map.Rules.TileSet;
|
||||
var terrainColors = tileset.TerrainInfo.Where(ti => ti.RestrictPlayerColor).Select(ti => ti.Color).ToList();
|
||||
var playerColors = server.LobbyInfo.Clients.Where(c => c.Index != playerIndex).Select(c => c.Color.RGB)
|
||||
.Concat(server.Map.Players.Players.Values.Select(p => p.Color.RGB)).ToList();
|
||||
var playerColors = server.LobbyInfo.Clients.Where(c => c.Index != playerIndex).Select(c => c.Color)
|
||||
.Concat(server.Map.Players.Players.Values.Select(p => p.Color)).ToList();
|
||||
|
||||
return validator.MakeValid(askColor.RGB, server.Random, terrainColors, playerColors, onError);
|
||||
return validator.MakeValid(askColor, server.Random, terrainColors, playerColors, onError);
|
||||
}
|
||||
|
||||
static string MissionBriefingOrDefault(S server)
|
||||
|
||||
@@ -127,7 +127,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
var temp = currentDisplayValue;
|
||||
if (self.Owner.IsAlliedWith(self.World.RenderPlayer))
|
||||
self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, self.Owner.Color.RGB, FloatingText.FormatCashTick(temp), 30)));
|
||||
self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, self.Owner.Color, FloatingText.FormatCashTick(temp), 30)));
|
||||
currentDisplayTick = info.TickRate;
|
||||
currentDisplayValue = 0;
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
void AddCashTick(Actor self, int amount)
|
||||
{
|
||||
self.World.AddFrameEndTask(w => w.Add(
|
||||
new FloatingText(self.CenterPosition, self.Owner.Color.RGB, FloatingText.FormatCashTick(amount), info.DisplayDuration)));
|
||||
new FloatingText(self.CenterPosition, self.Owner.Color, FloatingText.FormatCashTick(amount), info.DisplayDuration)));
|
||||
}
|
||||
|
||||
void ModifyCash(Actor self, Player newOwner, int amount)
|
||||
|
||||
@@ -142,7 +142,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var maxHP = healthInfo.MaxHP > 0 ? healthInfo.MaxHP : 1;
|
||||
var damageText = "{0} ({1}%)".F(-e.Damage.Value, e.Damage.Value * 100 / maxHP);
|
||||
|
||||
self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, e.Attacker.Owner.Color.RGB, damageText, 30)));
|
||||
self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, e.Attacker.Owner.Color, damageText, 30)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var amount = collector.Owner.PlayerActor.Trait<PlayerResources>().ChangeCash(info.Amount);
|
||||
|
||||
if (info.UseCashTick)
|
||||
w.Add(new FloatingText(collector.CenterPosition, collector.Owner.Color.RGB, FloatingText.FormatCashTick(amount), 30));
|
||||
w.Add(new FloatingText(collector.CenterPosition, collector.Owner.Color, FloatingText.FormatCashTick(amount), 30));
|
||||
});
|
||||
|
||||
base.Activate(collector);
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
foreach (var exitCell in exitCells)
|
||||
{
|
||||
var color = self.Owner.Color.RGB;
|
||||
var color = self.Owner.Color;
|
||||
var vec = exitCell - self.Location;
|
||||
var center = wr.World.Map.CenterOfCell(exitCell);
|
||||
new TextRenderable(manager.Font, center, 0, color, vec.ToString()).Render(wr);
|
||||
@@ -97,7 +97,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
continue;
|
||||
|
||||
var exitCellCenter = self.World.Map.CenterOfCell(exitCells[i]);
|
||||
rgbaRenderer.DrawLine(wr.Screen3DPosition(spawnPos), wr.Screen3DPosition(exitCellCenter), 1f, self.Owner.Color.RGB);
|
||||
rgbaRenderer.DrawLine(wr.Screen3DPosition(spawnPos), wr.Screen3DPosition(exitCellCenter), 1f, self.Owner.Color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
var displayedBounty = GetDisplayedBountyValue(self);
|
||||
if (Info.ShowBounty && self.IsInWorld && displayedBounty != 0 && e.Attacker.Owner.IsAlliedWith(self.World.RenderPlayer))
|
||||
e.Attacker.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, e.Attacker.Owner.Color.RGB, FloatingText.FormatCashTick(displayedBounty), 30)));
|
||||
e.Attacker.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, e.Attacker.Owner.Color, FloatingText.FormatCashTick(displayedBounty), 30)));
|
||||
|
||||
e.Attacker.Owner.PlayerActor.Trait<PlayerResources>().ChangeCash(GetBountyValue(self));
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return;
|
||||
|
||||
self.World.AddFrameEndTask(w => w.Add(
|
||||
new FloatingText(self.CenterPosition, self.Owner.Color.RGB, FloatingText.FormatCashTick(amount), info.DisplayDuration)));
|
||||
new FloatingText(self.CenterPosition, self.Owner.Color, FloatingText.FormatCashTick(amount), info.DisplayDuration)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
playerRadarPing = radarPings.Add(
|
||||
() => self.Owner.IsAlliedWith(self.World.RenderPlayer),
|
||||
order.Target.CenterPosition,
|
||||
self.Owner.Color.RGB,
|
||||
self.Owner.Color,
|
||||
info.Duration);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace OpenRA.Mods.Common.Traits.Radar
|
||||
if (IsTraitDisabled || (viewer != null && !Info.ValidStances.HasStance(self.Owner.Stances[viewer])))
|
||||
return;
|
||||
|
||||
var color = Game.Settings.Game.UsePlayerStanceColors ? self.Owner.PlayerStanceColor(self) : self.Owner.Color.RGB;
|
||||
var color = Game.Settings.Game.UsePlayerStanceColors ? self.Owner.PlayerStanceColor(self) : self.Owner.Color;
|
||||
if (modifier != null)
|
||||
color = modifier.RadarColorOverride(self, color);
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
|
||||
Color GetColor()
|
||||
{
|
||||
return self.EffectiveOwner != null && self.EffectiveOwner.Disguised ? self.EffectiveOwner.Owner.Color.RGB : self.Owner.Color.RGB;
|
||||
return self.EffectiveOwner != null && self.EffectiveOwner.Disguised ? self.EffectiveOwner.Owner.Color : self.Owner.Color;
|
||||
}
|
||||
|
||||
IEnumerable<IRenderable> IRenderAboveShroudWhenSelected.RenderAboveShroud(Actor self, WorldRenderer wr)
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
public RenderNameTag(Actor self, RenderNameTagInfo info)
|
||||
{
|
||||
font = Game.Renderer.Fonts[info.Font];
|
||||
color = self.Owner.Color.RGB;
|
||||
color = self.Owner.Color;
|
||||
|
||||
if (self.Owner.PlayerName.Length > info.MaxLength)
|
||||
name = self.Owner.PlayerName.Substring(0, info.MaxLength);
|
||||
|
||||
@@ -86,7 +86,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
self.CenterPosition,
|
||||
Info.Range,
|
||||
0,
|
||||
Info.UsePlayerColor ? self.Owner.Color.RGB : Info.Color,
|
||||
Info.UsePlayerColor ? self.Owner.Color : Info.Color,
|
||||
Color.FromArgb(96, Color.Black));
|
||||
|
||||
yield break;
|
||||
@@ -107,7 +107,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
self.CenterPosition,
|
||||
Info.Range,
|
||||
1,
|
||||
Info.UsePlayerColor ? self.Owner.Color.RGB : Info.Color,
|
||||
Info.UsePlayerColor ? self.Owner.Color : Info.Color,
|
||||
3,
|
||||
Color.FromArgb(96, Color.Black));
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
throw new YamlException("Font '{0}' is not listed in the mod.yaml's Fonts section".F(info.Font));
|
||||
|
||||
decorationBounds = self.TraitsImplementing<IDecorationBounds>().ToArray();
|
||||
color = info.UsePlayerColor ? self.Owner.Color.RGB : info.Color;
|
||||
color = info.UsePlayerColor ? self.Owner.Color : info.Color;
|
||||
}
|
||||
|
||||
IEnumerable<IRenderable> IRenderAboveShroudWhenSelected.RenderAboveShroud(Actor self, WorldRenderer wr)
|
||||
@@ -123,7 +123,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
|
||||
{
|
||||
if (info.UsePlayerColor)
|
||||
color = newOwner.Color.RGB;
|
||||
color = newOwner.Color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
{
|
||||
font = Game.Renderer.Fonts[info.Font];
|
||||
decorationBounds = self.TraitsImplementing<IDecorationBounds>().ToArray();
|
||||
color = Info.UsePlayerColor ? self.Owner.Color.RGB : Info.Color;
|
||||
color = Info.UsePlayerColor ? self.Owner.Color : Info.Color;
|
||||
}
|
||||
|
||||
public virtual bool ShouldRender(Actor self) { return true; }
|
||||
@@ -137,7 +137,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
|
||||
{
|
||||
if (Info.UsePlayerColor)
|
||||
color = newOwner.Color.RGB;
|
||||
color = newOwner.Color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
ping = manager.RadarPings.Value.Add(
|
||||
() => order.Player.IsAlliedWith(self.World.RenderPlayer),
|
||||
order.Target.CenterPosition,
|
||||
order.Player.Color.RGB,
|
||||
order.Player.Color,
|
||||
Info.RadarPingDuration);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -280,7 +280,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
foreach (var previewsForCell in cellMap)
|
||||
foreach (var preview in previewsForCell.Value)
|
||||
destinationBuffer.Add(Pair.New(previewsForCell.Key, preview.Owner.Color.RGB));
|
||||
destinationBuffer.Add(Pair.New(previewsForCell.Key, preview.Owner.Color));
|
||||
}
|
||||
|
||||
public EditorActorPreview this[string id]
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#endregion
|
||||
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
@@ -43,7 +44,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public PaletteFromPlayerPaletteWithAlpha(PaletteFromPlayerPaletteWithAlphaInfo info) { this.info = info; }
|
||||
|
||||
public void LoadPlayerPalettes(WorldRenderer wr, string playerName, HSLColor color, bool replaceExisting)
|
||||
public void LoadPlayerPalettes(WorldRenderer wr, string playerName, Color color, bool replaceExisting)
|
||||
{
|
||||
var remap = new AlphaPaletteRemap(info.Alpha, info.Premultiply);
|
||||
var pal = new ImmutablePalette(wr.Palette(info.BasePalette + playerName).Palette, remap);
|
||||
|
||||
@@ -235,7 +235,7 @@ namespace OpenRA.Mods.Common
|
||||
if (t == typeof(WVec))
|
||||
return "3D World Vector";
|
||||
|
||||
if (t == typeof(HSLColor) || t == typeof(Color))
|
||||
if (t == typeof(Color))
|
||||
return "Color (RRGGBB[AA] notation)";
|
||||
|
||||
if (t == typeof(IProjectileInfo))
|
||||
|
||||
@@ -329,18 +329,18 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
}
|
||||
|
||||
// TODO: fix this -- will have bitrotted pretty badly.
|
||||
static Dictionary<string, HSLColor> namedColorMapping = new Dictionary<string, HSLColor>()
|
||||
static Dictionary<string, Color> namedColorMapping = new Dictionary<string, Color>()
|
||||
{
|
||||
{ "gold", HSLColor.FromRGB(246, 214, 121) },
|
||||
{ "blue", HSLColor.FromRGB(226, 230, 246) },
|
||||
{ "red", HSLColor.FromRGB(255, 20, 0) },
|
||||
{ "neutral", HSLColor.FromRGB(238, 238, 238) },
|
||||
{ "orange", HSLColor.FromRGB(255, 230, 149) },
|
||||
{ "teal", HSLColor.FromRGB(93, 194, 165) },
|
||||
{ "salmon", HSLColor.FromRGB(210, 153, 125) },
|
||||
{ "green", HSLColor.FromRGB(160, 240, 140) },
|
||||
{ "white", HSLColor.FromRGB(255, 255, 255) },
|
||||
{ "black", HSLColor.FromRGB(80, 80, 80) },
|
||||
{ "gold", Color.FromArgb(246, 214, 121) },
|
||||
{ "blue", Color.FromArgb(226, 230, 246) },
|
||||
{ "red", Color.FromArgb(255, 20, 0) },
|
||||
{ "neutral", Color.FromArgb(238, 238, 238) },
|
||||
{ "orange", Color.FromArgb(255, 230, 149) },
|
||||
{ "teal", Color.FromArgb(93, 194, 165) },
|
||||
{ "salmon", Color.FromArgb(210, 153, 125) },
|
||||
{ "green", Color.FromArgb(160, 240, 140) },
|
||||
{ "white", Color.FromArgb(255, 255, 255) },
|
||||
{ "black", Color.FromArgb(80, 80, 80) },
|
||||
};
|
||||
|
||||
public static void SetMapPlayers(string section, string faction, string color, IniFile file, List<string> players, MapPlayers mapPlayers)
|
||||
|
||||
@@ -134,7 +134,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
var c = (int*)cc;
|
||||
for (var v = 0; v < 256; v++)
|
||||
for (var s = 0; s < 256; s++)
|
||||
*(c + (v * 256) + s) = HSLColor.FromHSV(hue, s / 255f, (255 - v) / 255f).RGB.ToArgb();
|
||||
*(c + (v * 256) + s) = Color.FromAhsv(hue, s / 255f, (255 - v) / 255f).ToArgb();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
|
||||
var sprite = ChromeProvider.GetImage("lobby-bits", "colorpicker");
|
||||
var pos = RenderOrigin + PxFromValue() - new int2(sprite.Bounds.Width, sprite.Bounds.Height) / 2;
|
||||
WidgetUtils.FillEllipseWithColor(new Rectangle(pos.X + 1, pos.Y + 1, sprite.Bounds.Width - 2, sprite.Bounds.Height - 2), Color.RGB);
|
||||
WidgetUtils.FillEllipseWithColor(new Rectangle(pos.X + 1, pos.Y + 1, sprite.Bounds.Width - 2, sprite.Bounds.Height - 2), Color);
|
||||
Game.Renderer.RgbaSpriteRenderer.DrawSprite(sprite, pos);
|
||||
}
|
||||
|
||||
@@ -221,7 +221,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
return true;
|
||||
}
|
||||
|
||||
public HSLColor Color { get { return HSLColor.FromHSV(H, S, V); } }
|
||||
public Color Color { get { return Color.FromAhsv(H, S, V); } }
|
||||
|
||||
public void Set(float hue)
|
||||
{
|
||||
@@ -233,10 +233,11 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
}
|
||||
}
|
||||
|
||||
public void Set(HSLColor color)
|
||||
public void Set(Color color)
|
||||
{
|
||||
float h, s, v;
|
||||
color.ToHSV(out h, out s, out v);
|
||||
int a;
|
||||
color.ToAhsv(out a, out h, out s, out v);
|
||||
|
||||
if (H != h || S != s || V != v)
|
||||
{
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#endregion
|
||||
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Common.Widgets
|
||||
@@ -19,9 +20,9 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
public readonly string PaletteName = "colorpicker";
|
||||
public readonly int[] RemapIndices = ChromeMetrics.Get<int[]>("ColorPickerRemapIndices");
|
||||
public readonly float Ramp = 0.05f;
|
||||
public HSLColor Color;
|
||||
public Color Color;
|
||||
|
||||
HSLColor cachedColor;
|
||||
Color cachedColor;
|
||||
WorldRenderer worldRenderer;
|
||||
IPalette preview;
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
|
||||
var hueData = new uint[1, 256];
|
||||
for (var x = 0; x < 256; x++)
|
||||
hueData[0, x] = (uint)HSLColor.FromHSV(x / 255f, 1, 1).RGB.ToArgb();
|
||||
hueData[0, x] = (uint)Color.FromAhsv(x / 255f, 1, 1).ToArgb();
|
||||
|
||||
hueSheet.GetTexture().SetData(hueData);
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
colorDropdown.IsDisabled = () => currentPalette != colorPreview.PaletteName;
|
||||
colorDropdown.OnMouseDown = _ => ColorPickerLogic.ShowColorDropDown(colorDropdown, colorPreview, world);
|
||||
panel.Get<ColorBlockWidget>("COLORBLOCK").GetColor = () => Game.Settings.Player.Color.RGB;
|
||||
panel.Get<ColorBlockWidget>("COLORBLOCK").GetColor = () => Game.Settings.Player.Color;
|
||||
}
|
||||
|
||||
filenameInput = panel.Get<TextFieldWidget>("FILENAME_INPUT");
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
int paletteTabHighlighted = 0;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public ColorPickerLogic(Widget widget, ModData modData, World world, HSLColor initialColor, string initialFaction, Action<HSLColor> onChange,
|
||||
public ColorPickerLogic(Widget widget, ModData modData, World world, Color initialColor, string initialFaction, Action<Color> onChange,
|
||||
Dictionary<string, MiniYaml> logicArgs)
|
||||
{
|
||||
string actorType;
|
||||
@@ -61,7 +61,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
var sat = (byte)Game.CosmeticRandom.Next(70, 255);
|
||||
var lum = (byte)Game.CosmeticRandom.Next(70, 255);
|
||||
|
||||
mixer.Set(new HSLColor(hue, sat, lum));
|
||||
mixer.Set(Color.FromAhsl(hue, sat, lum));
|
||||
hueSlider.Value = hue / 255f;
|
||||
};
|
||||
}
|
||||
@@ -71,7 +71,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
mixer.SetPaletteRange(validator.HsvSaturationRange[0], validator.HsvSaturationRange[1], validator.HsvValueRange[0], validator.HsvValueRange[1]);
|
||||
mixer.Set(initialColor);
|
||||
|
||||
hueSlider.Value = initialColor.H / 255f;
|
||||
hueSlider.Value = initialColor.GetHue() / 360f;
|
||||
onChange(mixer.Color);
|
||||
|
||||
// Setup tab controls
|
||||
@@ -117,10 +117,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
break;
|
||||
|
||||
var color = validator.TeamColorPresets[colorIndex];
|
||||
var rgbColor = color.RGB;
|
||||
|
||||
var newSwatch = (ColorBlockWidget)presetColorTemplate.Clone();
|
||||
newSwatch.GetColor = () => rgbColor;
|
||||
newSwatch.GetColor = () => color;
|
||||
newSwatch.IsVisible = () => true;
|
||||
newSwatch.Bounds.X = i * newSwatch.Bounds.Width;
|
||||
newSwatch.Bounds.Y = j * newSwatch.Bounds.Height;
|
||||
@@ -141,7 +140,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
var colorIndex = j * paletteCols + i;
|
||||
|
||||
var newSwatch = (ColorBlockWidget)customColorTemplate.Clone();
|
||||
newSwatch.GetColor = () => Game.Settings.Player.CustomColors[colorIndex].RGB;
|
||||
newSwatch.GetColor = () => Game.Settings.Player.CustomColors[colorIndex];
|
||||
newSwatch.IsVisible = () => Game.Settings.Player.CustomColors.Length > colorIndex;
|
||||
newSwatch.Bounds.X = i * newSwatch.Bounds.Width;
|
||||
newSwatch.Bounds.Y = j * newSwatch.Bounds.Height;
|
||||
@@ -190,7 +189,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
color.RemovePanel();
|
||||
|
||||
Action<HSLColor> onChange = c => preview.Color = c;
|
||||
Action<Color> onChange = c => preview.Color = c;
|
||||
|
||||
var colorChooser = Game.LoadWidget(world, "COLOR_CHOOSER", null, new WidgetArgs()
|
||||
{
|
||||
|
||||
@@ -212,12 +212,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
});
|
||||
|
||||
item.Get<LabelWidget>("LABEL").GetText = () => option.Name;
|
||||
item.GetColor = () => option.Color.RGB;
|
||||
item.GetColor = () => option.Color;
|
||||
return item;
|
||||
};
|
||||
|
||||
ownerDropdown.GetText = () => selectedOwner.Name;
|
||||
ownerDropdown.GetColor = () => selectedOwner.Color.RGB;
|
||||
ownerDropdown.GetColor = () => selectedOwner.Color;
|
||||
ownerDropdown.OnClick = () =>
|
||||
{
|
||||
var owners = editorActorLayer.Players.Players.Values.OrderBy(p => p.Name);
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
var item = ScrollItemWidget.Setup(template, () => selectedOwner == option, () => SelectOwner(option));
|
||||
|
||||
item.Get<LabelWidget>("LABEL").GetText = () => option.Name;
|
||||
item.GetColor = () => option.Color.RGB;
|
||||
item.GetColor = () => option.Color;
|
||||
|
||||
return item;
|
||||
};
|
||||
@@ -76,7 +76,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
};
|
||||
|
||||
ownersDropDown.Text = selectedOwner.Name;
|
||||
ownersDropDown.TextColor = selectedOwner.Color.RGB;
|
||||
ownersDropDown.TextColor = selectedOwner.Color;
|
||||
|
||||
var tileSetId = world.Map.Rules.TileSet.Id;
|
||||
var allActorsTemp = new List<ActorSelectorActor>();
|
||||
@@ -152,7 +152,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
selectedOwner = option;
|
||||
ownersDropDown.Text = option.Name;
|
||||
ownersDropDown.TextColor = option.Color.RGB;
|
||||
ownersDropDown.TextColor = option.Color;
|
||||
InitializePreviews();
|
||||
}
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
return name.Update(Pair.New(pp.PlayerName, suffix));
|
||||
};
|
||||
nameLabel.GetColor = () => pp.Color.RGB;
|
||||
nameLabel.GetColor = () => pp.Color;
|
||||
|
||||
var flag = item.Get<ImageWidget>("FACTIONFLAG");
|
||||
flag.GetImageCollection = () => "flags";
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
Player = p;
|
||||
Label = p.PlayerName;
|
||||
Color = p.Color.RGB;
|
||||
Color = p.Color;
|
||||
Faction = p.Faction.InternalName;
|
||||
IsSelected = () => p.World.RenderPlayer == p;
|
||||
OnClick = () => { p.World.RenderPlayer = p; logic.selected = this; p.World.Selection.Clear(); };
|
||||
|
||||
@@ -168,7 +168,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
graph.GetSeries = () =>
|
||||
players.Select(p => new LineGraphSeries(
|
||||
p.PlayerName,
|
||||
p.Color.RGB,
|
||||
p.Color,
|
||||
(p.PlayerActor.TraitOrDefault<PlayerStatistics>() ?? new PlayerStatistics(p.PlayerActor)).EarnedSamples.Select(s => (float)s)));
|
||||
|
||||
playerStatsPanel.AddChild(template);
|
||||
@@ -184,7 +184,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
graph.GetSeries = () =>
|
||||
players.Select(p => new LineGraphSeries(
|
||||
p.PlayerName,
|
||||
p.Color.RGB,
|
||||
p.Color,
|
||||
(p.PlayerActor.TraitOrDefault<PlayerStatistics>() ?? new PlayerStatistics(p.PlayerActor)).ArmySamples.Select(s => (float)s)));
|
||||
|
||||
playerStatsPanel.AddChild(template);
|
||||
|
||||
@@ -107,7 +107,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
flagFaction = o.Faction.InternalName;
|
||||
ownerName = o.PlayerName;
|
||||
ownerColor = o.Color.RGB;
|
||||
ownerColor = o.Color;
|
||||
widget.Bounds.Height = doubleHeight;
|
||||
widget.Bounds.Width = Math.Max(widget.Bounds.Width,
|
||||
owner.Bounds.X + ownerFont.Measure(ownerName).X + label.Bounds.X);
|
||||
|
||||
@@ -211,7 +211,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
orderManager.IssueOrder(Order.Command("color {0} {1}".F(client.Index, preview.Color)));
|
||||
};
|
||||
|
||||
Action<HSLColor> onChange = c => preview.Color = c;
|
||||
Action<Color> onChange = c => preview.Color = c;
|
||||
|
||||
var colorChooser = Game.LoadWidget(world, "COLOR_CHOOSER", null, new WidgetArgs()
|
||||
{
|
||||
@@ -484,7 +484,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
public static void SetupColorWidget(Widget parent, Session.Slot s, Session.Client c)
|
||||
{
|
||||
var color = parent.Get<ColorBlockWidget>("COLORBLOCK");
|
||||
color.GetColor = () => c.Color.RGB;
|
||||
color.GetColor = () => c.Color;
|
||||
}
|
||||
|
||||
public static void SetupEditableFactionWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager,
|
||||
@@ -604,7 +604,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
return name.Update(Pair.New(player.PlayerName, sl)) + suffix;
|
||||
};
|
||||
|
||||
playerName.GetColor = () => player.Color.RGB;
|
||||
playerName.GetColor = () => player.Color;
|
||||
}
|
||||
|
||||
public static string GetExternalIP(Session.Client client, OrderManager orderManager)
|
||||
|
||||
@@ -648,7 +648,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
var o = option;
|
||||
|
||||
var color = o.Color.RGB;
|
||||
var color = o.Color;
|
||||
|
||||
var item = ScrollItemWidget.Setup(playerTemplate, () => false, () => { });
|
||||
|
||||
|
||||
@@ -470,7 +470,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
var font = Game.Renderer.Fonts[label.Font];
|
||||
var name = WidgetUtils.TruncateText(o.Name, label.Bounds.Width, font);
|
||||
label.GetText = () => name;
|
||||
label.GetColor = () => o.Color.RGB;
|
||||
label.GetColor = () => o.Color;
|
||||
|
||||
var flag = item.Get<ImageWidget>("FLAG");
|
||||
flag.IsVisible = () => true;
|
||||
@@ -484,7 +484,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
var name = WidgetUtils.TruncateText(o.Name, label.Bounds.Width, font);
|
||||
|
||||
// Force spectator color to prevent spoofing by the server
|
||||
var color = o.IsSpectator ? Color.White : o.Color.RGB;
|
||||
var color = o.IsSpectator ? Color.White : o.Color;
|
||||
label.GetText = () => name;
|
||||
label.GetColor = () => color;
|
||||
}
|
||||
|
||||
@@ -266,7 +266,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
var colorDropdown = panel.Get<DropDownButtonWidget>("PLAYERCOLOR");
|
||||
colorDropdown.IsDisabled = () => worldRenderer.World.Type != WorldType.Shellmap;
|
||||
colorDropdown.OnMouseDown = _ => ColorPickerLogic.ShowColorDropDown(colorDropdown, colorPreview, worldRenderer.World);
|
||||
colorDropdown.Get<ColorBlockWidget>("COLORBLOCK").GetColor = () => ps.Color.RGB;
|
||||
colorDropdown.Get<ColorBlockWidget>("COLORBLOCK").GetColor = () => ps.Color;
|
||||
|
||||
return () =>
|
||||
{
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
{
|
||||
public class SpawnOccupant
|
||||
{
|
||||
public readonly HSLColor Color;
|
||||
public readonly Color Color;
|
||||
public readonly string PlayerName;
|
||||
public readonly int Team;
|
||||
public readonly string Faction;
|
||||
@@ -182,7 +182,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
TooltipSpawnIndex = -1;
|
||||
if (ShowSpawnPoints)
|
||||
{
|
||||
var colors = SpawnOccupants().ToDictionary(c => c.Key, c => c.Value.Color.RGB);
|
||||
var colors = SpawnOccupants().ToDictionary(c => c.Key, c => c.Value.Color);
|
||||
|
||||
var spawnPoints = preview.SpawnPoints;
|
||||
var gridType = preview.GridType;
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
var time = WidgetUtils.FormatTime(p.RemainingTime, false, timestep);
|
||||
var text = Format.F(p.Info.Description, time);
|
||||
var self = p.Instances[0].Self;
|
||||
var playerColor = self.Owner.Color.RGB;
|
||||
var playerColor = self.Owner.Color;
|
||||
|
||||
if (Game.Settings.Game.UsePlayerStanceColors)
|
||||
playerColor = self.Owner.PlayerStanceColor(self);
|
||||
|
||||
Reference in New Issue
Block a user