unify colorpickers across ra and cnc
This commit is contained in:
@@ -75,7 +75,6 @@
|
||||
<Compile Include="Widgets\LogicTickerWidget.cs" />
|
||||
<Compile Include="Widgets\Logic\ButtonTooltipLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\CncCheatsLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\CncColorPickerLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\CncConnectionLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\CncConquestObjectivesLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\CncIngameChromeLogic.cs" />
|
||||
|
||||
@@ -12,7 +12,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Mods.RA;
|
||||
using OpenRA.Mods.RA.Widgets.Logic;
|
||||
using OpenRA.Network;
|
||||
@@ -255,32 +254,6 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
title.Text = orderManager.LobbyInfo.GlobalSettings.ServerName;
|
||||
}
|
||||
|
||||
void ShowColorDropDown(DropDownButtonWidget color, Session.Client client)
|
||||
{
|
||||
Action<ColorRamp> onSelect = c =>
|
||||
{
|
||||
if (client.Bot == null)
|
||||
{
|
||||
Game.Settings.Player.ColorRamp = c;
|
||||
Game.Settings.Save();
|
||||
}
|
||||
|
||||
color.RemovePanel();
|
||||
orderManager.IssueOrder(Order.Command("color {0} {1}".F(client.Index, c)));
|
||||
};
|
||||
|
||||
Action<ColorRamp> onChange = c => PlayerPalettePreview.Ramp = c;
|
||||
|
||||
var colorChooser = Game.LoadWidget(orderManager.world, "COLOR_CHOOSER", null, new WidgetArgs()
|
||||
{
|
||||
{ "onSelect", onSelect },
|
||||
{ "onChange", onChange },
|
||||
{ "initialRamp", client.ColorRamp }
|
||||
});
|
||||
|
||||
color.AttachPanel(colorChooser);
|
||||
}
|
||||
|
||||
void UpdatePlayerList()
|
||||
{
|
||||
// This causes problems for people who are in the process of editing their names (the widgets vanish from beneath them)
|
||||
@@ -347,7 +320,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
|
||||
var color = template.GetWidget<DropDownButtonWidget>("COLOR");
|
||||
color.IsDisabled = () => slot.LockColor || ready;
|
||||
color.OnMouseDown = _ => ShowColorDropDown(color, client);
|
||||
color.OnMouseDown = _ => LobbyUtils.ShowColorDropDown(color, client, orderManager, PlayerPalettePreview);
|
||||
|
||||
var colorBlock = color.GetWidget<ColorBlockWidget>("COLORBLOCK");
|
||||
colorBlock.GetColor = () => client.ColorRamp.GetColor(0);
|
||||
@@ -425,7 +398,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
|
||||
var color = template.GetWidget<DropDownButtonWidget>("COLOR");
|
||||
color.IsDisabled = () => ready;
|
||||
color.OnMouseDown = _ => ShowColorDropDown(color, c);
|
||||
color.OnMouseDown = _ => LobbyUtils.ShowColorDropDown(color, c, orderManager, PlayerPalettePreview);
|
||||
|
||||
var colorBlock = color.GetWidget<ColorBlockWidget>("COLORBLOCK");
|
||||
colorBlock.GetColor = () => c.ColorRamp.GetColor(0);
|
||||
|
||||
@@ -364,6 +364,7 @@
|
||||
<Compile Include="World\ChooseBuildTabOnSelect.cs" />
|
||||
<Compile Include="World\PlayMusicOnMapLoad.cs" />
|
||||
<Compile Include="World\SmudgeLayer.cs" />
|
||||
<Compile Include="Widgets\Logic\ColorPickerLogic.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||
|
||||
@@ -13,13 +13,14 @@ using OpenRA.FileFormats;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
{
|
||||
public class CncColorPickerLogic
|
||||
public class ColorPickerLogic
|
||||
{
|
||||
ColorRamp ramp;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public CncColorPickerLogic(Widget widget, ColorRamp initialRamp, Action<ColorRamp> onChange,
|
||||
public ColorPickerLogic(Widget widget, ColorRamp initialRamp, Action<ColorRamp> onChange,
|
||||
Action<ColorRamp> onSelect, WorldRenderer worldRenderer)
|
||||
{
|
||||
var panel = widget.GetWidget("COLOR_CHOOSER");
|
||||
@@ -49,16 +50,19 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
};
|
||||
|
||||
panel.GetWidget<ButtonWidget>("SAVE_BUTTON").OnClick = () => onSelect(ramp);
|
||||
panel.GetWidget<ButtonWidget>("RANDOM_BUTTON").OnClick = () =>
|
||||
{
|
||||
var hue = (byte)Game.CosmeticRandom.Next(255);
|
||||
var sat = (byte)Game.CosmeticRandom.Next(255);
|
||||
var lum = (byte)Game.CosmeticRandom.Next(51,255);
|
||||
|
||||
ramp = new ColorRamp(hue, sat, lum, 10);
|
||||
updateSliders();
|
||||
sliderChanged();
|
||||
};
|
||||
var randomButton = panel.GetWidget<ButtonWidget>("RANDOM_BUTTON");
|
||||
if (randomButton != null)
|
||||
randomButton.OnClick = () =>
|
||||
{
|
||||
var hue = (byte)Game.CosmeticRandom.Next(255);
|
||||
var sat = (byte)Game.CosmeticRandom.Next(255);
|
||||
var lum = (byte)Game.CosmeticRandom.Next(51,255);
|
||||
|
||||
ramp = new ColorRamp(hue, sat, lum, 10);
|
||||
updateSliders();
|
||||
sliderChanged();
|
||||
};
|
||||
|
||||
// Set the initial state
|
||||
updateSliders();
|
||||
@@ -12,8 +12,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Network;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Widgets;
|
||||
@@ -33,13 +31,11 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
ColorPickerPaletteModifier PlayerPalettePreview;
|
||||
|
||||
readonly OrderManager orderManager;
|
||||
readonly WorldRenderer worldRenderer;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
internal LobbyLogic(Widget widget, World world, OrderManager orderManager, WorldRenderer worldRenderer)
|
||||
internal LobbyLogic(Widget widget, World world, OrderManager orderManager)
|
||||
{
|
||||
this.orderManager = orderManager;
|
||||
this.worldRenderer = worldRenderer;
|
||||
this.lobby = widget;
|
||||
Game.BeforeGameStart += CloseWindow;
|
||||
Game.LobbyInfoChanged += UpdateCurrentMap;
|
||||
@@ -155,22 +151,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
lobby.GetWidget<ChatDisplayWidget>("CHAT_DISPLAY").AddLine(c, from, text);
|
||||
}
|
||||
|
||||
void UpdatePlayerColor(Session.Client client, float hf, float sf, float lf, float r)
|
||||
{
|
||||
var ramp = new ColorRamp((byte)(hf * 255), (byte)(sf * 255), (byte)(lf * 255), (byte)(r * 255));
|
||||
if (client == orderManager.LocalClient)
|
||||
{
|
||||
Game.Settings.Player.ColorRamp = ramp;
|
||||
Game.Settings.Save();
|
||||
}
|
||||
orderManager.IssueOrder(Order.Command("color {0} {1}".F(client.Index, ramp)));
|
||||
}
|
||||
|
||||
void UpdateColorPreview(float hf, float sf, float lf, float r)
|
||||
{
|
||||
PlayerPalettePreview.Ramp = new ColorRamp((byte)(hf * 255), (byte)(sf * 255), (byte)(lf * 255), (byte)(r * 255));
|
||||
}
|
||||
|
||||
void UpdateCurrentMap()
|
||||
{
|
||||
if (MapUid == orderManager.LobbyInfo.GlobalSettings.Map) return;
|
||||
@@ -181,39 +161,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
title.Text = "OpenRA Multiplayer Lobby - " + orderManager.LobbyInfo.GlobalSettings.ServerName + " - " + Map.Title;
|
||||
}
|
||||
|
||||
void ShowColorDropDown(DropDownButtonWidget color, Session.Client client)
|
||||
{
|
||||
var colorChooser = Game.modData.WidgetLoader.LoadWidget(new WidgetArgs() { { "worldRenderer", worldRenderer } }, null, "COLOR_CHOOSER");
|
||||
var hueSlider = colorChooser.GetWidget<SliderWidget>("HUE_SLIDER");
|
||||
hueSlider.Value = client.ColorRamp.H / 255f;
|
||||
|
||||
var satSlider = colorChooser.GetWidget<SliderWidget>("SAT_SLIDER");
|
||||
satSlider.Value = client.ColorRamp.S / 255f;
|
||||
|
||||
var lumSlider = colorChooser.GetWidget<SliderWidget>("LUM_SLIDER");
|
||||
lumSlider.Value = client.ColorRamp.L / 255f;
|
||||
|
||||
var rangeSlider = colorChooser.GetWidget<SliderWidget>("RANGE_SLIDER");
|
||||
rangeSlider.Value = client.ColorRamp.R / 255f;
|
||||
|
||||
Action updateColorPreview = () => UpdateColorPreview(hueSlider.Value, satSlider.Value, lumSlider.Value, rangeSlider.Value);
|
||||
|
||||
hueSlider.OnChange += _ => updateColorPreview();
|
||||
satSlider.OnChange += _ => updateColorPreview();
|
||||
lumSlider.OnChange += _ => updateColorPreview();
|
||||
rangeSlider.OnChange += _ => updateColorPreview();
|
||||
updateColorPreview();
|
||||
|
||||
colorChooser.GetWidget<ButtonWidget>("BUTTON_OK").OnClick = () =>
|
||||
{
|
||||
updateColorPreview();
|
||||
UpdatePlayerColor(client, hueSlider.Value, satSlider.Value, lumSlider.Value, rangeSlider.Value);
|
||||
color.RemovePanel();
|
||||
};
|
||||
|
||||
color.AttachPanel(colorChooser);
|
||||
}
|
||||
|
||||
void UpdatePlayerList()
|
||||
{
|
||||
// This causes problems for people who are in the process of editing their names (the widgets vanish from beneath them)
|
||||
@@ -273,7 +220,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
|
||||
var color = template.GetWidget<DropDownButtonWidget>("COLOR");
|
||||
color.IsDisabled = () => s.LockColor;
|
||||
color.OnMouseDown = _ => ShowColorDropDown(color, c);
|
||||
color.OnMouseDown = _ => LobbyUtils.ShowColorDropDown(color, c, orderManager, PlayerPalettePreview);
|
||||
|
||||
var colorBlock = color.GetWidget<ColorBlockWidget>("COLORBLOCK");
|
||||
colorBlock.GetColor = () => c.ColorRamp.GetColor(0);
|
||||
@@ -342,7 +289,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
LobbyUtils.SetupNameWidget(orderManager, c, template.GetWidget<TextFieldWidget>("NAME"));
|
||||
|
||||
var color = template.GetWidget<DropDownButtonWidget>("COLOR");
|
||||
color.OnMouseDown = _ => ShowColorDropDown(color, c);
|
||||
color.OnMouseDown = _ => LobbyUtils.ShowColorDropDown(color, c, orderManager, PlayerPalettePreview);
|
||||
|
||||
var colorBlock = color.GetWidget<ColorBlockWidget>("COLORBLOCK");
|
||||
colorBlock.GetColor = () => c.ColorRamp.GetColor(0);
|
||||
|
||||
@@ -120,6 +120,33 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
dropdown.ShowDropDown("RACE_DROPDOWN_TEMPLATE", 150, countryNames.Keys, setupItem);
|
||||
}
|
||||
|
||||
public static void ShowColorDropDown(DropDownButtonWidget color, Session.Client client,
|
||||
OrderManager orderManager, ColorPickerPaletteModifier preview)
|
||||
{
|
||||
Action<ColorRamp> onSelect = c =>
|
||||
{
|
||||
if (client.Bot == null)
|
||||
{
|
||||
Game.Settings.Player.ColorRamp = c;
|
||||
Game.Settings.Save();
|
||||
}
|
||||
|
||||
color.RemovePanel();
|
||||
orderManager.IssueOrder(Order.Command("color {0} {1}".F(client.Index, c)));
|
||||
};
|
||||
|
||||
Action<ColorRamp> onChange = c => preview.Ramp = c;
|
||||
|
||||
var colorChooser = Game.LoadWidget(orderManager.world, "COLOR_CHOOSER", null, new WidgetArgs()
|
||||
{
|
||||
{ "onSelect", onSelect },
|
||||
{ "onChange", onChange },
|
||||
{ "initialRamp", client.ColorRamp }
|
||||
});
|
||||
|
||||
color.AttachPanel(colorChooser);
|
||||
}
|
||||
|
||||
public static Dictionary<int2, Color> GetSpawnColors(OrderManager orderManager, Map map)
|
||||
{
|
||||
var spawns = map.GetSpawnPoints();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
Background@COLOR_CHOOSER:
|
||||
Id:COLOR_CHOOSER
|
||||
Logic:CncColorPickerLogic
|
||||
Logic:ColorPickerLogic
|
||||
Background:panel-black
|
||||
Width:315
|
||||
Height:130
|
||||
|
||||
@@ -415,17 +415,26 @@ Background@SERVER_LOBBY:
|
||||
Text: Allow Cheats
|
||||
Background@COLOR_CHOOSER:
|
||||
Id:COLOR_CHOOSER
|
||||
Logic:ColorPickerLogic
|
||||
Background:dialog2
|
||||
Width:310
|
||||
Height:120
|
||||
Children:
|
||||
Button@BUTTON_OK:
|
||||
Id:BUTTON_OK
|
||||
Button@SAVE_BUTTON:
|
||||
Id:SAVE_BUTTON
|
||||
X:210
|
||||
Y:85
|
||||
Width:90
|
||||
Height:25
|
||||
Text:Ok
|
||||
Text:Save
|
||||
Font:Bold
|
||||
Button@RANDOM_BUTTON:
|
||||
Id:RANDOM_BUTTON
|
||||
X:115
|
||||
Y:85
|
||||
Width:90
|
||||
Height:25
|
||||
Text:Random
|
||||
Font:Bold
|
||||
ShpImage@FACT:
|
||||
Id:FACT
|
||||
@@ -477,19 +486,3 @@ Background@COLOR_CHOOSER:
|
||||
Ticks:5
|
||||
MinimumValue: 0.2
|
||||
MaximumValue: 1
|
||||
Label@RANGE_LABEL:
|
||||
X:0
|
||||
Y:80
|
||||
Width:40
|
||||
Height:20
|
||||
Align: Right
|
||||
Text: Ran:
|
||||
Slider@RANGE:
|
||||
Id:RANGE_SLIDER
|
||||
X:43
|
||||
Y:85
|
||||
Width:160
|
||||
Height:20
|
||||
Ticks:5
|
||||
MinimumValue: 0
|
||||
MaximumValue: 0.25
|
||||
|
||||
Reference in New Issue
Block a user