unify colorpickers across ra and cnc
This commit is contained in:
@@ -1,69 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
{
|
||||
public class CncColorPickerLogic
|
||||
{
|
||||
ColorRamp ramp;
|
||||
[ObjectCreator.UseCtor]
|
||||
public CncColorPickerLogic(Widget widget, ColorRamp initialRamp, Action<ColorRamp> onChange,
|
||||
Action<ColorRamp> onSelect, WorldRenderer worldRenderer)
|
||||
{
|
||||
var panel = widget.GetWidget("COLOR_CHOOSER");
|
||||
ramp = initialRamp;
|
||||
var hueSlider = panel.GetWidget<SliderWidget>("HUE_SLIDER");
|
||||
var satSlider = panel.GetWidget<SliderWidget>("SAT_SLIDER");
|
||||
var lumSlider = panel.GetWidget<SliderWidget>("LUM_SLIDER");
|
||||
|
||||
Action sliderChanged = () =>
|
||||
{
|
||||
ramp = new ColorRamp((byte)(255*hueSlider.Value),
|
||||
(byte)(255*satSlider.Value),
|
||||
(byte)(255*lumSlider.Value),
|
||||
10);
|
||||
onChange(ramp);
|
||||
};
|
||||
|
||||
hueSlider.OnChange += _ => sliderChanged();
|
||||
satSlider.OnChange += _ => sliderChanged();
|
||||
lumSlider.OnChange += _ => sliderChanged();
|
||||
|
||||
Action updateSliders = () =>
|
||||
{
|
||||
hueSlider.Value = ramp.H / 255f;
|
||||
satSlider.Value = ramp.S / 255f;
|
||||
lumSlider.Value = ramp.L / 255f;
|
||||
};
|
||||
|
||||
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();
|
||||
};
|
||||
|
||||
// Set the initial state
|
||||
updateSliders();
|
||||
onChange(ramp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user