Shift player palette definitions onto the player/client. Needs ui; for now everyone is teal.
This commit is contained in:
@@ -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<object>().Select(a => a.ToString()).ToArray())
|
||||
: v.ToString();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -65,6 +65,8 @@ namespace OpenRA.Graphics
|
||||
|
||||
public void AddPalette(string name, Palette pal)
|
||||
{
|
||||
System.Console.WriteLine("Registering Palette "+name);
|
||||
|
||||
palette.AddPalette(name, pal);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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 =>
|
||||
|
||||
@@ -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 {}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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))));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user