Replace ColorRamp with HSLColor everywhere.
Fixes: * Nuclear-purple color exploit. * #3247. * Removes a bunch of unnecessary color conversions every frame. Caveats: * The ramp range is now defined on the palette, so ramps can no longer be set per-player (may impact maps which define custom colors). * It's no longer possible to perfectly recreate the original WW color ramps (I doubt we care). * The old ColorRamp setting isn't migrated, so players will lose their color settings.
This commit is contained in:
@@ -110,7 +110,7 @@ namespace OpenRA.GameRules
|
||||
public class PlayerSettings
|
||||
{
|
||||
public string Name = "Newbie";
|
||||
public ColorRamp ColorRamp = new ColorRamp(75, 255, 180, 25);
|
||||
public HSLColor Color = new HSLColor(75, 255, 180);
|
||||
public string LastServer = "localhost:1234";
|
||||
}
|
||||
|
||||
|
||||
@@ -47,9 +47,9 @@ namespace OpenRA.Network
|
||||
public class Client
|
||||
{
|
||||
public int Index;
|
||||
public ColorRamp PreferredColorRamp; // Color that the client normally uses from settings.yaml.
|
||||
public ColorRamp ColorRamp; // Actual color that the client is using.
|
||||
// Usually the same as PreferredColorRamp but can be different on maps with locked colors.
|
||||
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 string Country;
|
||||
public int SpawnPoint;
|
||||
public string Name;
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace OpenRA.Network
|
||||
var player = world != null ? world.FindPlayerByClient(client) : null;
|
||||
var suffix = (player != null && player.WinState == WinState.Lost) ? " (Dead)" : "";
|
||||
suffix = client.IsObserver ? " (Spectator)" : suffix;
|
||||
Game.AddChatLine(client.ColorRamp.GetColor(0), client.Name + suffix, order.TargetString);
|
||||
Game.AddChatLine(client.Color.RGB, client.Name + suffix, order.TargetString);
|
||||
}
|
||||
else
|
||||
Game.AddChatLine(Color.White, "(player {0})".F(clientId), order.TargetString);
|
||||
@@ -71,7 +71,7 @@ namespace OpenRA.Network
|
||||
if (world == null)
|
||||
{
|
||||
if (orderManager.LocalClient != null && client.Team == orderManager.LocalClient.Team)
|
||||
Game.AddChatLine(client.ColorRamp.GetColor(0), client.Name + " (Team)",
|
||||
Game.AddChatLine(client.Color.RGB, client.Name + " (Team)",
|
||||
order.TargetString);
|
||||
}
|
||||
else
|
||||
@@ -82,7 +82,7 @@ namespace OpenRA.Network
|
||||
if (world.LocalPlayer != null && player.Stances[world.LocalPlayer] == Stance.Ally || player.WinState == WinState.Lost)
|
||||
{
|
||||
var suffix = player.WinState == WinState.Lost ? " (Dead)" : " (Team)";
|
||||
Game.AddChatLine(client.ColorRamp.GetColor(0), client.Name + suffix, order.TargetString);
|
||||
Game.AddChatLine(client.Color.RGB, client.Name + suffix, order.TargetString);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -133,8 +133,8 @@ namespace OpenRA.Network
|
||||
var info = new Session.Client()
|
||||
{
|
||||
Name = Game.Settings.Player.Name,
|
||||
PreferredColorRamp = Game.Settings.Player.ColorRamp,
|
||||
ColorRamp = Game.Settings.Player.ColorRamp,
|
||||
PreferredColor = Game.Settings.Player.Color,
|
||||
Color = Game.Settings.Player.Color,
|
||||
Country = "random",
|
||||
SpawnPoint = 0,
|
||||
Team = 0,
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace OpenRA
|
||||
public int Deaths;
|
||||
public WinState WinState = WinState.Undefined;
|
||||
|
||||
public readonly ColorRamp ColorRamp;
|
||||
public readonly HSLColor Color;
|
||||
|
||||
public readonly string PlayerName;
|
||||
public readonly string InternalName;
|
||||
@@ -60,7 +60,7 @@ namespace OpenRA
|
||||
if (client != null)
|
||||
{
|
||||
ClientIndex = client.Index;
|
||||
ColorRamp = client.ColorRamp;
|
||||
Color = client.Color;
|
||||
PlayerName = client.Name;
|
||||
botType = client.Bot;
|
||||
Country = ChooseCountry(world, client.Country);
|
||||
@@ -69,7 +69,7 @@ namespace OpenRA
|
||||
{
|
||||
// Map player
|
||||
ClientIndex = 0; // Owned by the host (TODO: fix this)
|
||||
ColorRamp = pr.ColorRamp;
|
||||
Color = pr.Color;
|
||||
PlayerName = pr.Name;
|
||||
NonCombatant = pr.NonCombatant;
|
||||
botType = pr.Bot;
|
||||
|
||||
@@ -337,9 +337,9 @@ namespace OpenRA.Server
|
||||
if (pr == null)
|
||||
return;
|
||||
if (pr.LockColor)
|
||||
c.ColorRamp = pr.ColorRamp;
|
||||
c.Color = pr.Color;
|
||||
else
|
||||
c.ColorRamp = c.PreferredColorRamp;
|
||||
c.Color = c.PreferredColor;
|
||||
if (pr.LockRace)
|
||||
c.Country = pr.Race;
|
||||
if (pr.LockSpawn)
|
||||
|
||||
@@ -16,15 +16,18 @@ namespace OpenRA.Traits
|
||||
[Desc("Add this to the Player actor definition.")]
|
||||
public class PlayerColorPaletteInfo : ITraitInfo
|
||||
{
|
||||
[Desc("The Name of the palette to base off.")]
|
||||
[Desc("The name of the palette to base off.")]
|
||||
public readonly string BasePalette = null;
|
||||
[Desc("The prefix for the resulting player palettes")]
|
||||
public readonly string BaseName = "player";
|
||||
[Desc("Remap these indices to player colors.")]
|
||||
public readonly int[] RemapIndex = {};
|
||||
[Desc("Luminosity range to span.")]
|
||||
public readonly float Ramp = 0.05f;
|
||||
[Desc("Allow palette modifiers to change the palette.")]
|
||||
public readonly bool AllowModifiers = true;
|
||||
|
||||
public object Create( ActorInitializer init ) { return new PlayerColorPalette( init.self.Owner, this ); }
|
||||
public object Create(ActorInitializer init) { return new PlayerColorPalette(init.self.Owner, this); }
|
||||
}
|
||||
|
||||
public class PlayerColorPalette : IPalette
|
||||
@@ -32,18 +35,16 @@ namespace OpenRA.Traits
|
||||
readonly Player owner;
|
||||
readonly PlayerColorPaletteInfo info;
|
||||
|
||||
public PlayerColorPalette( Player owner, PlayerColorPaletteInfo info )
|
||||
public PlayerColorPalette(Player owner, PlayerColorPaletteInfo info)
|
||||
{
|
||||
this.owner = owner;
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public void InitPalette( WorldRenderer wr )
|
||||
public void InitPalette(WorldRenderer wr)
|
||||
{
|
||||
var paletteName = "{0}{1}".F( info.BaseName, owner.InternalName );
|
||||
var newpal = new Palette(wr.Palette(info.BasePalette).Palette,
|
||||
new PlayerColorRemap(info.RemapIndex, owner.ColorRamp));
|
||||
wr.AddPalette(paletteName, newpal, info.AllowModifiers);
|
||||
var remap = new PlayerColorRemap(info.RemapIndex, owner.Color, info.Ramp);
|
||||
wr.AddPalette(info.BaseName+owner.InternalName, new Palette(wr.Palette(info.BasePalette).Palette, remap), info.AllowModifiers);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ namespace OpenRA.Widgets
|
||||
TooltipSpawnIndex = -1;
|
||||
if (ShowSpawnPoints)
|
||||
{
|
||||
var colors = SpawnClients().ToDictionary(c => c.Key, c => c.Value.ColorRamp.GetColor(0));
|
||||
var colors = SpawnClients().ToDictionary(c => c.Key, c => c.Value.Color.RGB);
|
||||
|
||||
var spawnPoints = map.GetSpawnPoints().ToList();
|
||||
foreach (var p in spawnPoints)
|
||||
|
||||
Reference in New Issue
Block a user