diff --git a/OpenRA.FileFormats/FieldLoader.cs b/OpenRA.FileFormats/FieldLoader.cs index 6663c99047..d5aee56c49 100644 --- a/OpenRA.FileFormats/FieldLoader.cs +++ b/OpenRA.FileFormats/FieldLoader.cs @@ -20,9 +20,9 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.Linq; using System.Reflection; - namespace OpenRA.FileFormats { public static class FieldLoader @@ -102,13 +102,14 @@ namespace OpenRA.FileFormats else if (fieldType == typeof(string)) return x; - else if (fieldType == typeof(System.Drawing.Color)) + else if (fieldType == typeof(Color)) { var parts = x.Split(','); - if (parts.Length != 3) - return InvalidValueAction(x,fieldType, field); - - return System.Drawing.Color.FromArgb(int.Parse(parts[0]), int.Parse(parts[1]), int.Parse(parts[2])); + if (parts.Length == 3) + return Color.FromArgb(int.Parse(parts[0]), int.Parse(parts[1]), int.Parse(parts[2])); + if (parts.Length == 4) + return Color.FromArgb(int.Parse(parts[0]), int.Parse(parts[1]), int.Parse(parts[2]), int.Parse(parts[3])); + return InvalidValueAction(x,fieldType, field); } else if (fieldType.IsEnum) @@ -183,6 +184,13 @@ namespace OpenRA.FileFormats if (v == null) return ""; + // Color.ToString() does the wrong thing; force it to format as an array + if (f.FieldType == typeof(Color)) + { + var c = (Color)v; + return "{0},{1},{2},{3}".F(c.A,c.R,c.G,c.B); + } + return f.FieldType.IsArray ? string.Join(",", ((Array)v).OfType().Select(a => a.ToString()).ToArray()) : v.ToString(); diff --git a/OpenRA.FileFormats/Session.cs b/OpenRA.FileFormats/Session.cs index 39c224f0a7..f58f4e3da8 100644 --- a/OpenRA.FileFormats/Session.cs +++ b/OpenRA.FileFormats/Session.cs @@ -37,7 +37,7 @@ namespace OpenRA.FileFormats public class Client { public int Index; - public int PaletteIndex; + public System.Drawing.Color Color; public string Country; public int SpawnPoint; public string Name; diff --git a/OpenRA.Game/Graphics/WorldRenderer.cs b/OpenRA.Game/Graphics/WorldRenderer.cs index 425b74d4db..a834033442 100644 --- a/OpenRA.Game/Graphics/WorldRenderer.cs +++ b/OpenRA.Game/Graphics/WorldRenderer.cs @@ -65,6 +65,8 @@ namespace OpenRA.Graphics public void AddPalette(string name, Palette pal) { + System.Console.WriteLine("Registering Palette "+name); + palette.AddPalette(name, pal); } diff --git a/OpenRA.Game/Network/UnitOrders.cs b/OpenRA.Game/Network/UnitOrders.cs index 4edbd807be..a440049512 100755 --- a/OpenRA.Game/Network/UnitOrders.cs +++ b/OpenRA.Game/Network/UnitOrders.cs @@ -34,7 +34,7 @@ namespace OpenRA.Network { var client = Game.LobbyInfo.Clients.FirstOrDefault(c => c.Index == clientId); if (client != null) - Game.AddChatLine(Game.world.PlayerColors()[client.PaletteIndex].Color, + Game.AddChatLine(client.Color, client.Name, order.TargetString); break; } @@ -49,7 +49,7 @@ namespace OpenRA.Network client == Game.LocalClient || (client.Team == Game.LocalClient.Team && client.Team != 0); if (isAlly) - Game.AddChatLine(Game.world.PlayerColors()[client.PaletteIndex].Color, client.Name + " (Team)", order.TargetString); + Game.AddChatLine(client.Color, client.Name + " (Team)", order.TargetString); } break; } diff --git a/OpenRA.Game/Player.cs b/OpenRA.Game/Player.cs index 60d53971eb..2d087df1da 100644 --- a/OpenRA.Game/Player.cs +++ b/OpenRA.Game/Player.cs @@ -36,7 +36,8 @@ namespace OpenRA public readonly string Palette; public readonly Color Color; - + public readonly Color Color2; + public readonly string PlayerName; public readonly string InternalName; public readonly CountryInfo Country; @@ -52,14 +53,18 @@ namespace OpenRA Shroud = new ShroudRenderer(this, world.Map); PlayerActor = world.CreateActor("Player", new int2(int.MaxValue, int.MaxValue), this); - + Index = index; - Palette = pr.Palette; - Color = world.PlayerColors().Where(c => c.Name == pr.Palette).FirstOrDefault().Color; + Palette = "player"+index; + Color = Util.ArrayToColor(new int[] {93,194,165}); + Color2 = Util.ArrayToColor(new int[] {0,32,32}); + PlayerName = InternalName = pr.Name; NonCombatant = pr.NonCombatant; Country = world.GetCountries() .FirstOrDefault(c => pr.Race == c.Race); + + RegisterPlayerColor(world, Palette); } public Player( World world, Session.Client client ) @@ -70,15 +75,26 @@ namespace OpenRA PlayerActor = world.CreateActor("Player", new int2(int.MaxValue, int.MaxValue), this); Index = client.Index; - Palette = world.PlayerColors()[client.PaletteIndex % world.PlayerColors().Count()].Name; - Color = world.PlayerColors()[client.PaletteIndex % world.PlayerColors().Count()].Color; + Palette = "player"+client.Index; + Color = Util.ArrayToColor(new int[] {93,194,165}); + Color2 = Util.ArrayToColor(new int[] {0,32,32}); PlayerName = client.Name; InternalName = "Multi{0}".F(client.Index); Country = world.GetCountries() .FirstOrDefault(c => client != null && client.Country == c.Race) ?? world.GetCountries().Random(world.SharedRandom); + + RegisterPlayerColor(world, Palette); } - + + public void RegisterPlayerColor(World world, string palette) + { + var info = Rules.Info["world"].Traits.Get(); + var newpal = new Palette(world.WorldRenderer.GetPalette(info.BasePalette), + new PlayerColorRemap(Color, Color2, info.SplitRamp)); + world.WorldRenderer.AddPalette(palette, newpal); + } + public void GiveAdvice(string advice) { // todo: store the condition or something. diff --git a/OpenRA.Game/Server/Server.cs b/OpenRA.Game/Server/Server.cs index 91157e1480..04095fbcba 100644 --- a/OpenRA.Game/Server/Server.cs +++ b/OpenRA.Game/Server/Server.cs @@ -148,7 +148,7 @@ namespace OpenRA.Server new Session.Client() { Index = newConn.PlayerIndex, - PaletteIndex = ChooseFreePalette(), + Color = System.Drawing.Color.FromArgb(93,194,165), Name = "Player {0}".F(1 + newConn.PlayerIndex), Country = "random", State = Session.ClientState.NotReady, @@ -323,6 +323,8 @@ namespace OpenRA.Server { "pal", s => { + return true; + /* int pali; if (!int.TryParse(s, out pali)) @@ -340,6 +342,7 @@ namespace OpenRA.Server GetClient(conn).PaletteIndex = pali; SyncLobbyInfo(); return true; + */ }}, { "map", s => diff --git a/OpenRA.Game/Traits/World/PlayerColorPalette.cs b/OpenRA.Game/Traits/World/PlayerColorPalette.cs index 57babb8b46..a1c2002a63 100644 --- a/OpenRA.Game/Traits/World/PlayerColorPalette.cs +++ b/OpenRA.Game/Traits/World/PlayerColorPalette.cs @@ -23,38 +23,11 @@ using OpenRA.FileFormats; namespace OpenRA.Traits { - public class PlayerColorPaletteInfo : ITraitInfo + public class PlayerColorPaletteInfo : TraitInfo { - public readonly string Name = null; - public readonly string DisplayName = null; public readonly string BasePalette = null; - - public readonly int[] Color1 = { 255, 255, 255 }; - public readonly int[] Color2 = { 0, 0, 0 }; public readonly bool SplitRamp = false; - - public readonly int[] DisplayColor = null; - public readonly bool Playable = true; - - public object Create(ActorInitializer init) { return new PlayerColorPalette(init.world, this); } - - public Color Color { get { return Util.ArrayToColor(DisplayColor); } } } - public class PlayerColorPalette - { - public PlayerColorPalette(World world, PlayerColorPaletteInfo info) - { - var wr = world.WorldRenderer; - var pal = wr.GetPalette(info.BasePalette); - var newpal = new Palette(pal, new PlayerColorRemap( - Util.ArrayToColor(info.Color1), - Util.ArrayToColor(info.Color2), - info.SplitRamp)); - - wr.AddPalette(info.Name, newpal); - } - - - } + public class PlayerColorPalette {} } diff --git a/OpenRA.Game/Widgets/Delegates/LobbyDelegate.cs b/OpenRA.Game/Widgets/Delegates/LobbyDelegate.cs index ce0b44456b..efc15efdbe 100644 --- a/OpenRA.Game/Widgets/Delegates/LobbyDelegate.cs +++ b/OpenRA.Game/Widgets/Delegates/LobbyDelegate.cs @@ -58,7 +58,6 @@ namespace OpenRA.Widgets.Delegates mapPreview.SpawnColors = () => { var spawns = Map.SpawnPoints; - var playerColors = Game.world.PlayerColors(); var sc = new Dictionary(); for (int i = 1; i <= spawns.Count(); i++) @@ -66,7 +65,7 @@ namespace OpenRA.Widgets.Delegates var client = Game.LobbyInfo.Clients.FirstOrDefault(c => c.SpawnPoint == i); if (client == null) continue; - sc.Add(spawns.ElementAt(i - 1), playerColors[client.PaletteIndex % playerColors.Count()].Color); + sc.Add(spawns.ElementAt(i - 1), client.Color); } return sc; }; @@ -170,10 +169,10 @@ namespace OpenRA.Widgets.Delegates name.OnLoseFocus = () => name.OnEnterKey(); var color = template.GetWidget("COLOR"); - color.OnMouseUp = CyclePalette; + //color.OnMouseUp = CyclePalette; var colorBlock = color.GetWidget("COLORBLOCK"); - colorBlock.GetColor = () => Game.world.PlayerColors()[c.PaletteIndex % Game.world.PlayerColors().Count].Color; + colorBlock.GetColor = () => c.Color; var faction = template.GetWidget("FACTION"); faction.OnMouseUp = CycleRace; @@ -196,7 +195,7 @@ namespace OpenRA.Widgets.Delegates template = RemotePlayerTemplate.Clone(); template.GetWidget("NAME").GetText = () => c.Name; var color = template.GetWidget("COLOR"); - color.GetColor = () => Game.world.PlayerColors()[c.PaletteIndex % Game.world.PlayerColors().Count].Color; + color.GetColor = () => c.Color; var faction = template.GetWidget("FACTION"); var factionname = faction.GetWidget("FACTIONNAME"); @@ -224,24 +223,7 @@ namespace OpenRA.Widgets.Delegates } } - bool PaletteAvailable(int index) { return Game.LobbyInfo.Clients.All(c => c.PaletteIndex != index) && Game.world.PlayerColors()[index % Game.world.PlayerColors().Count].Playable; } bool SpawnPointAvailable(int index) { return (index == 0) || Game.LobbyInfo.Clients.All(c => c.SpawnPoint != index); } - - bool CyclePalette(MouseInput mi) - { - var d = (mi.Button == MouseButton.Left) ? +1 : Game.world.PlayerColors().Count() - 1; - - var newIndex = ((int)Game.LocalClient.PaletteIndex + d) % Game.world.PlayerColors().Count(); - - while (!PaletteAvailable(newIndex) && newIndex != (int)Game.LocalClient.PaletteIndex) - newIndex = (newIndex + d) % Game.world.PlayerColors().Count(); - - Game.IssueOrder( - Order.Command("pal " + newIndex)); - - return true; - } - bool CycleRace(MouseInput mi) { var countries = CountryNames.Select(a => a.Key); diff --git a/OpenRA.Game/WorldUtils.cs b/OpenRA.Game/WorldUtils.cs index 1cb5380422..69284db80b 100755 --- a/OpenRA.Game/WorldUtils.cs +++ b/OpenRA.Game/WorldUtils.cs @@ -210,11 +210,6 @@ namespace OpenRA return new float2(Gauss1D(r, samples), Gauss1D(r, samples)); } - public static List PlayerColors(this World world) - { - return world.WorldActor.Info.Traits.WithInterface().ToList(); - } - public static string FormatTime(int ticks) { var seconds = ticks / 25; diff --git a/OpenRA.Mods.RA/PaletteFromRGBA.cs b/OpenRA.Mods.RA/PaletteFromRGBA.cs index 219f088d6c..8055e1b1bb 100644 --- a/OpenRA.Mods.RA/PaletteFromRGBA.cs +++ b/OpenRA.Mods.RA/PaletteFromRGBA.cs @@ -45,7 +45,7 @@ namespace OpenRA.Mods.RA { // TODO: This shouldn't rely on a base palette var wr = world.WorldRenderer; - var pal = wr.GetPalette("player0"); + var pal = wr.GetPalette("terrain"); wr.AddPalette(info.Name, new Palette(pal, new SingleColorRemap(Color.FromArgb(info.A, info.R, info.G, info.B)))); } } diff --git a/mods/ra/system.yaml b/mods/ra/system.yaml index 1fae31fe74..f049a3b4f3 100644 --- a/mods/ra/system.yaml +++ b/mods/ra/system.yaml @@ -103,77 +103,8 @@ World: WaterChance: .2 PaletteFromCurrentTheatre: Name: terrain - PlayerColorPalette@player0: - Name: player0 - DisplayName: Gold + PlayerColorPalette: BasePalette: terrain - DisplayColor: 228, 200, 112 - Color1: 246,214,121 - Color2: 40,32,8 - PlayerColorPalette@player1: - Name: player1 - DisplayName: Blue - BasePalette: terrain - DisplayColor: 56, 72, 125 - Color1: 30,85,204 - Color2: 8,20,52 - PlayerColorPalette@player2: - Name: player2 - DisplayName: Red - BasePalette: terrain - DisplayColor: 238,0,0 - Color1: 255,20,0 - Color2: 56,0,0 - PlayerColorPalette@player3: - Name: player3 - DisplayName: Orange - BasePalette: terrain - DisplayColor: 198,97,0 - Color1: 255,107,0 - Color2: 56,0,0 - PlayerColorPalette@player4: - Name: player4 - DisplayName: Teal - BasePalette: terrain - DisplayColor: 28,109,97 - Color1: 93,194,165 - Color2: 0,32,32 - PlayerColorPalette@player5: - Name: player5 - DisplayName: Salmon - BasePalette: terrain - DisplayColor: 153,76,53 - Color1: 210,153,125 - Color2: 56,0,0 - PlayerColorPalette@player6: - Name: player6 - DisplayName: Green - BasePalette: terrain - DisplayColor: 76,101,60 - Color1: 160,240,140 - Color2: 20,20,20 - PlayerColorPalette@player7: - Name: player7 - DisplayName: White - BasePalette: terrain - DisplayColor: 255,255,255 - Color1: 255,255,255 - Color2: 75,75,75 - PlayerColorPalette@player8: - Name: player8 - DisplayName: Black - BasePalette: terrain - DisplayColor: 30,30,30 - Color1: 80,80,80 - Color2: 5,5,5 - PlayerColorPalette@neutral: - Name: neutral - DisplayName: Neutral - BasePalette: terrain - DisplayColor: 133,113,101 - Color1: 238,238,238 - Color2: 44,28,24 - Playable: no PaletteFromFile@chrome: Name: chrome Filename: temperat.pal