Shift player palette definitions onto the player/client. Needs ui; for now everyone is teal.

This commit is contained in:
Paul Chote
2010-07-16 20:51:20 +12:00
parent 84ac8d9d16
commit 8abc8e03cb
11 changed files with 54 additions and 144 deletions

View File

@@ -65,6 +65,8 @@ namespace OpenRA.Graphics
public void AddPalette(string name, Palette pal)
{
System.Console.WriteLine("Registering Palette "+name);
palette.AddPalette(name, pal);
}

View File

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

View File

@@ -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<PlayerColorPaletteInfo>();
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.

View File

@@ -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 =>

View File

@@ -23,38 +23,11 @@ using OpenRA.FileFormats;
namespace OpenRA.Traits
{
public class PlayerColorPaletteInfo : ITraitInfo
public class PlayerColorPaletteInfo : TraitInfo<PlayerColorPalette>
{
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 {}
}

View File

@@ -58,7 +58,6 @@ namespace OpenRA.Widgets.Delegates
mapPreview.SpawnColors = () =>
{
var spawns = Map.SpawnPoints;
var playerColors = Game.world.PlayerColors();
var sc = new Dictionary<int2, Color>();
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<ButtonWidget>("COLOR");
color.OnMouseUp = CyclePalette;
//color.OnMouseUp = CyclePalette;
var colorBlock = color.GetWidget<ColorBlockWidget>("COLORBLOCK");
colorBlock.GetColor = () => Game.world.PlayerColors()[c.PaletteIndex % Game.world.PlayerColors().Count].Color;
colorBlock.GetColor = () => c.Color;
var faction = template.GetWidget<ButtonWidget>("FACTION");
faction.OnMouseUp = CycleRace;
@@ -196,7 +195,7 @@ namespace OpenRA.Widgets.Delegates
template = RemotePlayerTemplate.Clone();
template.GetWidget<LabelWidget>("NAME").GetText = () => c.Name;
var color = template.GetWidget<ColorBlockWidget>("COLOR");
color.GetColor = () => Game.world.PlayerColors()[c.PaletteIndex % Game.world.PlayerColors().Count].Color;
color.GetColor = () => c.Color;
var faction = template.GetWidget<LabelWidget>("FACTION");
var factionname = faction.GetWidget<LabelWidget>("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);

View File

@@ -210,11 +210,6 @@ namespace OpenRA
return new float2(Gauss1D(r, samples), Gauss1D(r, samples));
}
public static List<PlayerColorPaletteInfo> PlayerColors(this World world)
{
return world.WorldActor.Info.Traits.WithInterface<PlayerColorPaletteInfo>().ToList();
}
public static string FormatTime(int ticks)
{
var seconds = ticks / 25;