diff --git a/OpenRA.Server/Server.cs b/OpenRA.Server/Server.cs
index 679c51bce7..8ee723288f 100644
--- a/OpenRA.Server/Server.cs
+++ b/OpenRA.Server/Server.cs
@@ -58,13 +58,16 @@ namespace OpenRA.Server
throw new InvalidOperationException("Already got 8 players");
}
- static string ChooseFreePalette()
+ static int ChooseFreePalette()
{
- // TODO: FIX
+ // TODO: Query the list of palettes from somewhere, and pick one
+ return 0;
+
+ /*
for (var i = 0; i < 8; i++)
- //if (lobbyInfo.Clients.All(c => c.Palette != i))
+ if (lobbyInfo.Clients.All(c => c.Palette != i))
return "player"+i;
-
+ */
throw new InvalidOperationException("No free palettes");
}
@@ -86,7 +89,7 @@ namespace OpenRA.Server
new Session.Client()
{
Index = newConn.PlayerIndex,
- Palette = ChooseFreePalette(),
+ PaletteIndex = ChooseFreePalette(),
Name = "Player {0}".F(1 + newConn.PlayerIndex),
Race = 1,
State = Session.ClientState.NotReady
@@ -255,15 +258,14 @@ namespace OpenRA.Server
Console.WriteLine("Invalid palette: {0}", s);
return false;
}
- string pal = "player"+pali;
-
- if (lobbyInfo.Clients.Where( c => c != GetClient(conn) ).Any( c => c.Palette == pal ))
+
+ if (lobbyInfo.Clients.Where( c => c != GetClient(conn) ).Any( c => c.PaletteIndex == pali ))
{
SendChatTo( conn, "You can't be the same color as another player" );
return true;
}
- GetClient(conn).Palette = pal;
+ GetClient(conn).PaletteIndex = pali;
SyncLobbyInfo();
return true;
}},
diff --git a/OpenRa.FileFormats/Session.cs b/OpenRa.FileFormats/Session.cs
index 17840142fb..1bf07f5417 100644
--- a/OpenRa.FileFormats/Session.cs
+++ b/OpenRa.FileFormats/Session.cs
@@ -20,7 +20,7 @@ namespace OpenRa.FileFormats
public class Client
{
public int Index;
- public string Palette;
+ public int PaletteIndex;
public int Race;
// public int SpawnPoint;
public string Name;
diff --git a/OpenRa.Game/Chrome.cs b/OpenRa.Game/Chrome.cs
index 7704cafa6a..360111e801 100644
--- a/OpenRa.Game/Chrome.cs
+++ b/OpenRa.Game/Chrome.cs
@@ -350,18 +350,17 @@ namespace OpenRa
AddButton(r, _ => { });
}
- bool PaletteAvailable(string palette) { return Game.LobbyInfo.Clients.All(c => c.Palette != palette); }
-
+ bool PaletteAvailable(int index) { return Game.LobbyInfo.Clients.All(c => c.PaletteIndex != index); }
void CyclePalette(bool left)
{
- var d = left ? 1 : 7;
- // TODO: FIX
- var newpalette = 1;//((int)Game.world.LocalPlayer.Palette + d) % 8;
- //while (!PaletteAvailable(newpalette) && newpalette != (int)Game.world.LocalPlayer.Palette)
- // newpalette = (newpalette + d) % 8;
+ var d = left ? +1 : Player.PlayerColors.Count() - 1;
+
+ var newIndex = ((int)Game.world.LocalPlayer.PaletteIndex + d) % Player.PlayerColors.Count();
+ while (!PaletteAvailable(newIndex) && newIndex != (int)Game.world.LocalPlayer.PaletteIndex)
+ newIndex = (newIndex + d) % Player.PlayerColors.Count();
Game.IssueOrder(
- Order.Chat("/pal " + newpalette));
+ Order.Chat("/pal " + newIndex));
}
void CycleRace(bool left)
@@ -446,8 +445,9 @@ namespace OpenRa
DrawDialogBackground(paletteRect, panelSprites, false);
AddButton(paletteRect, CyclePalette);
+ // TODO: Render using the System.Drawing.Color (Player.PlayerColors[client.PaletteIndex].c)
shpRenderer.DrawSprite(colorBlock, new float2(paletteRect.Left + 4, paletteRect.Top + 4),
- client.Palette);
+ Player.PlayerColors[client.PaletteIndex].a);
var raceRect = new Rectangle(r.Left + 290, y - 2, 65, 22);
DrawDialogBackground(raceRect, panelSprites, false);
@@ -462,9 +462,9 @@ namespace OpenRa
renderer.DrawText(client.Name, new int2(r.Left + 40, y), Color.White);
-
+ // TODO: Render using Player.PlayerColors[client.PaletteIndex].c
shpRenderer.DrawSprite(colorBlock, new float2(paletteRect.Left + 4, paletteRect.Top + 4),
- client.Palette);
+ Player.PlayerColors[client.PaletteIndex].a);
renderer.DrawText(((Race)client.Race).ToString(), new int2(r.Left + 300, y), Color.White);
renderer.DrawText(client.State.ToString(), new int2(r.Left + 370, y), Color.White);
diff --git a/OpenRa.Game/Graphics/WorldRenderer.cs b/OpenRa.Game/Graphics/WorldRenderer.cs
index df24a1238a..60fc661407 100644
--- a/OpenRa.Game/Graphics/WorldRenderer.cs
+++ b/OpenRa.Game/Graphics/WorldRenderer.cs
@@ -32,7 +32,6 @@ namespace OpenRa.Graphics
Log.Write("Created worldrenderer");
}
- // TODO: Implement
public int GetPaletteIndex(string name)
{
return palette.GetPaletteIndex(name);
@@ -43,7 +42,6 @@ namespace OpenRa.Graphics
return palette.GetPalette(name);
}
-
public void AddPalette(string name, Palette pal)
{
palette.AddPalette(name, pal);
diff --git a/OpenRa.Game/OpenRa.Game.csproj b/OpenRa.Game/OpenRa.Game.csproj
index 75ef178d7d..5633fc7070 100644
--- a/OpenRa.Game/OpenRa.Game.csproj
+++ b/OpenRa.Game/OpenRa.Game.csproj
@@ -222,6 +222,7 @@
+
diff --git a/OpenRa.Game/Player.cs b/OpenRa.Game/Player.cs
index a77606da42..9175be8555 100644
--- a/OpenRa.Game/Player.cs
+++ b/OpenRa.Game/Player.cs
@@ -14,7 +14,7 @@ namespace OpenRa
public class Player
{
public Actor PlayerActor;
- public string Palette;
+ public int PaletteIndex;
public int Kills;
public string PlayerName;
public string InternalName;
@@ -28,18 +28,23 @@ namespace OpenRa
public int PowerDrained = 0;
public World World { get { return PlayerActor.World; } }
+
+ public static List> PlayerColors = new List>();
+ public static void RegisterPlayerColor(string palette, string name, Color c)
+ {
+ PlayerColors.Add(new Tuple(palette, name, c));
+ }
+
+ public Color Color
+ {
+ get { return PlayerColors[PaletteIndex].c; }
+ }
- public Color Color;
- /*
- Color.FromArgb(228, 200, 112),
- Color.FromArgb(56, 72, 125),
- Color.FromArgb(238, 0, 0),
- Color.FromArgb(198,97,0),
- Color.FromArgb(28,109,97),
- Color.FromArgb(153,76,53),
- Color.FromArgb(76,101,60),
- Color.FromArgb(133,113,101),
- */
+ public string Palette
+ {
+ get { return PlayerColors[PaletteIndex].a; }
+ }
+
public Shroud Shroud;
public Player( World world, int index, Session.Client client )
@@ -49,7 +54,7 @@ namespace OpenRa
this.Index = index;
this.InternalName = "Multi{0}".F(index);
- this.Palette = client != null ? "player"+client.Palette : "player"+index;
+ this.PaletteIndex = client != null ? client.PaletteIndex : index;
this.PlayerName = client != null ? client.Name : "Player {0}".F(index+1);
this.Race = client != null ? (Race)client.Race : Race.Allies;
}
@@ -172,10 +177,10 @@ namespace OpenRa
Race = (Race)client.Race;
}
- if (Palette != client.Palette)
+ if (PaletteIndex != client.PaletteIndex)
{
- Game.chat.AddLine(this, "has changed color to {0}".F(client.Palette));
- Palette = client.Palette;
+ PaletteIndex = client.PaletteIndex;
+ Game.chat.AddLine(this, "has changed color to {0}".F(PlayerColors[client.PaletteIndex].b));
}
}
}
diff --git a/mods/cnc/system.yaml b/mods/cnc/system.yaml
index 51b4726925..bcde60f592 100644
--- a/mods/cnc/system.yaml
+++ b/mods/cnc/system.yaml
@@ -21,37 +21,53 @@ World:
Name: player
Theatre: temperat
Filename: temperat.pal
- PaletteFromRemap@player0:
+ PlayerColorPalette@player0:
Name: player0
+ DisplayName: Gold
BasePalette: player
- PaletteFromRemap@player1:
+ DisplayColor: 228, 200, 112
+ PlayerColorPalette@player1:
Name: player1
+ DisplayName: Blue
BasePalette: player
Remap: blue.rem
- PaletteFromRemap@player2:
+ DisplayColor: 56, 72, 125
+ PlayerColorPalette@player2:
Name: player2
+ DisplayName: Red
BasePalette: player
Remap: red.rem
- PaletteFromRemap@player3:
+ DisplayColor: 238, 0, 0
+ PlayerColorPalette@player3:
Name: player3
+ DisplayName: Orange
BasePalette: player
Remap: orange.rem
- PaletteFromRemap@player4:
+ DisplayColor: 198,97,0
+ PlayerColorPalette@player4:
Name: player4
+ DisplayName: Teal
BasePalette: player
Remap: teal.rem
- PaletteFromRemap@player5:
+ DisplayColor: 28,109,97
+ PlayerColorPalette@player5:
Name: player5
+ DisplayName: Salmon
BasePalette: player
Remap: salmon.rem
-# PaletteFromRemap@player6:
+ DisplayColor: 153,76,53
+# PlayerColorPalette@player6:
# Name: player6
+# DisplayName: Green
# BasePalette: player
# Remap: green.rem
-# PaletteFromRemap@player7:
+# DisplayColor: 76,101,60
+# PlayerColorPalette@player7:
# Name: player7
+# DisplayName: Gray
# BasePalette: player
# Remap: gray.rem
+# DisplayColor: 133,113,101
PaletteFromFile@chrome:
Name: chrome
Filename: temperat.pal