Sliders change the preview palette and update client data; Need a better algorithm for picking color2
This commit is contained in:
@@ -37,7 +37,8 @@ namespace OpenRA.FileFormats
|
|||||||
public class Client
|
public class Client
|
||||||
{
|
{
|
||||||
public int Index;
|
public int Index;
|
||||||
public System.Drawing.Color Color;
|
public System.Drawing.Color Color1;
|
||||||
|
public System.Drawing.Color Color2;
|
||||||
public string Country;
|
public string Country;
|
||||||
public int SpawnPoint;
|
public int SpawnPoint;
|
||||||
public string Name;
|
public string Name;
|
||||||
|
|||||||
@@ -73,6 +73,17 @@ namespace OpenRA.Graphics
|
|||||||
return allocated++;
|
return allocated++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void UpdatePalette(string name, Palette p)
|
||||||
|
{
|
||||||
|
palettes[name] = p;
|
||||||
|
var j = indices[name];
|
||||||
|
|
||||||
|
for (int i = 0; i < 256; i++)
|
||||||
|
{
|
||||||
|
this[new Point(i, j)] = p.GetColor(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void Update(IEnumerable<IPaletteModifier> paletteMods)
|
public void Update(IEnumerable<IPaletteModifier> paletteMods)
|
||||||
{
|
{
|
||||||
var b = new Bitmap(Bitmap);
|
var b = new Bitmap(Bitmap);
|
||||||
|
|||||||
@@ -70,6 +70,11 @@ namespace OpenRA.Graphics
|
|||||||
palette.AddPalette(name, pal);
|
palette.AddPalette(name, pal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void UpdatePalette(string name, Palette pal)
|
||||||
|
{
|
||||||
|
palette.UpdatePalette(name, pal);
|
||||||
|
}
|
||||||
|
|
||||||
void DrawSpriteList(IEnumerable<Renderable> images)
|
void DrawSpriteList(IEnumerable<Renderable> images)
|
||||||
{
|
{
|
||||||
foreach (var image in images)
|
foreach (var image in images)
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace OpenRA.Network
|
|||||||
{
|
{
|
||||||
var client = Game.LobbyInfo.Clients.FirstOrDefault(c => c.Index == clientId);
|
var client = Game.LobbyInfo.Clients.FirstOrDefault(c => c.Index == clientId);
|
||||||
if (client != null)
|
if (client != null)
|
||||||
Game.AddChatLine(client.Color,
|
Game.AddChatLine(client.Color1,
|
||||||
client.Name, order.TargetString);
|
client.Name, order.TargetString);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -49,7 +49,7 @@ namespace OpenRA.Network
|
|||||||
client == Game.LocalClient || (client.Team == Game.LocalClient.Team && client.Team != 0);
|
client == Game.LocalClient || (client.Team == Game.LocalClient.Team && client.Team != 0);
|
||||||
|
|
||||||
if (isAlly)
|
if (isAlly)
|
||||||
Game.AddChatLine(client.Color, client.Name + " (Team)", order.TargetString);
|
Game.AddChatLine(client.Color1, client.Name + " (Team)", order.TargetString);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -148,7 +148,8 @@ namespace OpenRA.Server
|
|||||||
new Session.Client()
|
new Session.Client()
|
||||||
{
|
{
|
||||||
Index = newConn.PlayerIndex,
|
Index = newConn.PlayerIndex,
|
||||||
Color = System.Drawing.Color.FromArgb(93,194,165),
|
Color1 = System.Drawing.Color.FromArgb(246,214,121),
|
||||||
|
Color2 = System.Drawing.Color.FromArgb(40,32,8),
|
||||||
Name = "Player {0}".F(1 + newConn.PlayerIndex),
|
Name = "Player {0}".F(1 + newConn.PlayerIndex),
|
||||||
Country = "random",
|
Country = "random",
|
||||||
State = Session.ClientState.NotReady,
|
State = Session.ClientState.NotReady,
|
||||||
@@ -324,7 +325,8 @@ namespace OpenRA.Server
|
|||||||
s =>
|
s =>
|
||||||
{
|
{
|
||||||
var c = s.Split(',').Select(cc => int.Parse(cc)).ToArray();
|
var c = s.Split(',').Select(cc => int.Parse(cc)).ToArray();
|
||||||
GetClient(conn).Color = System.Drawing.Color.FromArgb(c[0],c[1],c[2]);
|
GetClient(conn).Color1 = System.Drawing.Color.FromArgb(c[0],c[1],c[2]);
|
||||||
|
GetClient(conn).Color2 = System.Drawing.Color.FromArgb(c[3],c[4],c[5]);
|
||||||
SyncLobbyInfo();
|
SyncLobbyInfo();
|
||||||
return true;
|
return true;
|
||||||
}},
|
}},
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ using System.Collections.Generic;
|
|||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.FileFormats;
|
using OpenRA.FileFormats;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Widgets.Delegates
|
namespace OpenRA.Widgets.Delegates
|
||||||
{
|
{
|
||||||
@@ -33,6 +34,9 @@ namespace OpenRA.Widgets.Delegates
|
|||||||
|
|
||||||
string MapUid;
|
string MapUid;
|
||||||
MapStub Map;
|
MapStub Map;
|
||||||
|
|
||||||
|
bool SplitPlayerPalette = false;
|
||||||
|
Palette BasePlayerPalette = null;
|
||||||
public LobbyDelegate()
|
public LobbyDelegate()
|
||||||
{
|
{
|
||||||
Game.LobbyInfoChanged += UpdateCurrentMap;
|
Game.LobbyInfoChanged += UpdateCurrentMap;
|
||||||
@@ -65,7 +69,7 @@ namespace OpenRA.Widgets.Delegates
|
|||||||
var client = Game.LobbyInfo.Clients.FirstOrDefault(c => c.SpawnPoint == i);
|
var client = Game.LobbyInfo.Clients.FirstOrDefault(c => c.SpawnPoint == i);
|
||||||
if (client == null)
|
if (client == null)
|
||||||
continue;
|
continue;
|
||||||
sc.Add(spawns.ElementAt(i - 1), client.Color);
|
sc.Add(spawns.ElementAt(i - 1), client.Color1);
|
||||||
}
|
}
|
||||||
return sc;
|
return sc;
|
||||||
};
|
};
|
||||||
@@ -130,18 +134,36 @@ namespace OpenRA.Widgets.Delegates
|
|||||||
var satSlider = colorChooser.GetWidget<SliderWidget>("SAT_SLIDER");
|
var satSlider = colorChooser.GetWidget<SliderWidget>("SAT_SLIDER");
|
||||||
var lumSlider = colorChooser.GetWidget<SliderWidget>("LUM_SLIDER");
|
var lumSlider = colorChooser.GetWidget<SliderWidget>("LUM_SLIDER");
|
||||||
|
|
||||||
|
hueSlider.OnChange += _ => UpdateColorPreview(360*hueSlider.GetOffset(), satSlider.GetOffset(), lumSlider.GetOffset());
|
||||||
|
satSlider.OnChange += _ => UpdateColorPreview(360*hueSlider.GetOffset(), satSlider.GetOffset(), lumSlider.GetOffset());
|
||||||
|
lumSlider.OnChange += _ => UpdateColorPreview(360*hueSlider.GetOffset(), satSlider.GetOffset(), lumSlider.GetOffset());
|
||||||
|
|
||||||
colorChooser.GetWidget<ButtonWidget>("BUTTON_OK").OnMouseUp = mi =>
|
colorChooser.GetWidget<ButtonWidget>("BUTTON_OK").OnMouseUp = mi =>
|
||||||
{
|
{
|
||||||
colorChooser.IsVisible = () => false;
|
colorChooser.IsVisible = () => false;
|
||||||
UpdatePlayerColor(hueSlider.GetOffset(), satSlider.GetOffset(), lumSlider.GetOffset());
|
UpdatePlayerColor(360*hueSlider.GetOffset(), satSlider.GetOffset(), lumSlider.GetOffset());
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Copy the base palette for the colorpicker
|
||||||
|
var info = Rules.Info["world"].Traits.Get<PlayerColorPaletteInfo>();
|
||||||
|
BasePlayerPalette = Game.world.WorldRenderer.GetPalette(info.BasePalette);
|
||||||
|
SplitPlayerPalette = info.SplitRamp;
|
||||||
|
Game.world.WorldRenderer.AddPalette("colorpicker",BasePlayerPalette);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdatePlayerColor(float hf, float sf, float lf)
|
void UpdatePlayerColor(float hf, float sf, float lf)
|
||||||
{
|
{
|
||||||
var c = ColorFromHSL(hf*360, sf, lf);
|
var c1 = ColorFromHSL(hf, sf, lf);
|
||||||
Game.IssueOrder(Order.Command("color {0},{1},{2}".F(c.R,c.G,c.B)));
|
var c2 = ColorFromHSL(hf, sf, 0.5f*lf);
|
||||||
|
Game.IssueOrder(Order.Command("color {0},{1},{2},{3},{4},{5}".F(c1.R,c1.G,c1.B,c2.R,c2.G,c2.B)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpdateColorPreview(float hf, float sf, float lf)
|
||||||
|
{
|
||||||
|
var c1 = ColorFromHSL(hf, sf, lf);
|
||||||
|
var c2 = ColorFromHSL(hf, sf, 0.5f*lf);
|
||||||
|
Game.world.WorldRenderer.UpdatePalette("colorpicker", new Palette(BasePlayerPalette, new PlayerColorRemap(c1, c2, SplitPlayerPalette)));
|
||||||
}
|
}
|
||||||
|
|
||||||
Color ColorFromHSL(float h, float s, float l)
|
Color ColorFromHSL(float h, float s, float l)
|
||||||
@@ -220,20 +242,21 @@ namespace OpenRA.Widgets.Delegates
|
|||||||
{
|
{
|
||||||
var colorChooser = Chrome.rootWidget.GetWidget("SERVER_LOBBY").GetWidget("COLOR_CHOOSER");
|
var colorChooser = Chrome.rootWidget.GetWidget("SERVER_LOBBY").GetWidget("COLOR_CHOOSER");
|
||||||
var hueSlider = colorChooser.GetWidget<SliderWidget>("HUE_SLIDER");
|
var hueSlider = colorChooser.GetWidget<SliderWidget>("HUE_SLIDER");
|
||||||
hueSlider.Offset = Game.LocalClient.Color.GetHue()/360f;
|
hueSlider.Offset = Game.LocalClient.Color1.GetHue()/360f;
|
||||||
|
|
||||||
var satSlider = colorChooser.GetWidget<SliderWidget>("SAT_SLIDER");
|
var satSlider = colorChooser.GetWidget<SliderWidget>("SAT_SLIDER");
|
||||||
satSlider.Offset = Game.LocalClient.Color.GetSaturation();
|
satSlider.Offset = Game.LocalClient.Color1.GetSaturation();
|
||||||
|
|
||||||
var lumSlider = colorChooser.GetWidget<SliderWidget>("LUM_SLIDER");
|
var lumSlider = colorChooser.GetWidget<SliderWidget>("LUM_SLIDER");
|
||||||
lumSlider.Offset = Game.LocalClient.Color.GetBrightness();
|
lumSlider.Offset = Game.LocalClient.Color1.GetBrightness();
|
||||||
|
|
||||||
|
UpdateColorPreview(360*hueSlider.GetOffset(), satSlider.GetOffset(), lumSlider.GetOffset());
|
||||||
colorChooser.IsVisible = () => true;
|
colorChooser.IsVisible = () => true;
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
var colorBlock = color.GetWidget<ColorBlockWidget>("COLORBLOCK");
|
var colorBlock = color.GetWidget<ColorBlockWidget>("COLORBLOCK");
|
||||||
colorBlock.GetColor = () => c.Color;
|
colorBlock.GetColor = () => c.Color1;
|
||||||
|
|
||||||
var faction = template.GetWidget<ButtonWidget>("FACTION");
|
var faction = template.GetWidget<ButtonWidget>("FACTION");
|
||||||
faction.OnMouseUp = CycleRace;
|
faction.OnMouseUp = CycleRace;
|
||||||
@@ -256,7 +279,7 @@ namespace OpenRA.Widgets.Delegates
|
|||||||
template = RemotePlayerTemplate.Clone();
|
template = RemotePlayerTemplate.Clone();
|
||||||
template.GetWidget<LabelWidget>("NAME").GetText = () => c.Name;
|
template.GetWidget<LabelWidget>("NAME").GetText = () => c.Name;
|
||||||
var color = template.GetWidget<ColorBlockWidget>("COLOR");
|
var color = template.GetWidget<ColorBlockWidget>("COLOR");
|
||||||
color.GetColor = () => c.Color;
|
color.GetColor = () => c.Color1;
|
||||||
|
|
||||||
var faction = template.GetWidget<LabelWidget>("FACTION");
|
var faction = template.GetWidget<LabelWidget>("FACTION");
|
||||||
var factionname = faction.GetWidget<LabelWidget>("FACTIONNAME");
|
var factionname = faction.GetWidget<LabelWidget>("FACTIONNAME");
|
||||||
|
|||||||
@@ -273,11 +273,13 @@ Container@ROOT:
|
|||||||
Y:20
|
Y:20
|
||||||
Image:mcv
|
Image:mcv
|
||||||
Frame:8
|
Frame:8
|
||||||
|
Palette:colorpicker
|
||||||
ShpImage@FACT:
|
ShpImage@FACT:
|
||||||
Id:FACT
|
Id:FACT
|
||||||
X:PARENT_RIGHT - 100
|
X:PARENT_RIGHT - 100
|
||||||
Y:70
|
Y:70
|
||||||
Image:fact
|
Image:fact
|
||||||
|
Palette:colorpicker
|
||||||
Label@HUE_LABEL:
|
Label@HUE_LABEL:
|
||||||
X:0
|
X:0
|
||||||
Y:30
|
Y:30
|
||||||
|
|||||||
Reference in New Issue
Block a user