Fix most of the player color regressions

This commit is contained in:
Paul Chote
2010-02-04 23:54:16 +13:00
parent 6c99b33364
commit 2a7f52edc7
7 changed files with 69 additions and 47 deletions

View File

@@ -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);

View File

@@ -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);

View File

@@ -222,6 +222,7 @@
<Compile Include="Traits\PaletteFromRGBA.cs" />
<Compile Include="Traits\Passenger.cs" />
<Compile Include="Traits\PlaceBuilding.cs" />
<Compile Include="Traits\PlayerColorPalette.cs" />
<Compile Include="Traits\ShroudPalette.cs" />
<Compile Include="Traits\SupportPower.cs" />
<Compile Include="Traits\ProvidesRadar.cs" />

View File

@@ -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<Tuple<string, string, Color>> PlayerColors = new List<Tuple<string, string, Color>>();
public static void RegisterPlayerColor(string palette, string name, Color c)
{
PlayerColors.Add(new Tuple<string, string, Color>(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));
}
}
}