diff --git a/OpenRA.Game/Widgets/DropDownButtonWidget.cs b/OpenRA.Game/Widgets/DropDownButtonWidget.cs index 21fd88d1ab..4bd5ef4e3b 100644 --- a/OpenRA.Game/Widgets/DropDownButtonWidget.cs +++ b/OpenRA.Game/Widgets/DropDownButtonWidget.cs @@ -62,7 +62,8 @@ namespace OpenRA.Widgets panel = fullscreenMask = null; } - public void AttachPanel(Widget p) + public void AttachPanel(Widget p) { AttachPanel(p, null); } + public void AttachPanel(Widget p, Action onCancel) { if (panel != null) throw new InvalidOperationException("Attempted to attach a panel to an open dropdown"); @@ -71,7 +72,10 @@ namespace OpenRA.Widgets // Mask to prevent any clicks from being sent to other widgets fullscreenMask = new MaskWidget(); fullscreenMask.Bounds = new Rectangle(0, 0, Game.viewport.Width, Game.viewport.Height); - fullscreenMask.OnMouseDown = mi => RemovePanel(); + fullscreenMask.OnMouseDown += mi => RemovePanel(); + if (onCancel != null) + fullscreenMask.OnMouseDown += _ => onCancel(); + Ui.Root.AddChild(fullscreenMask); var oldBounds = panel.Bounds; @@ -105,7 +109,7 @@ namespace OpenRA.Widgets public class MaskWidget : Widget { - public Action OnMouseDown = _ => {}; + public event Action OnMouseDown = _ => {}; public MaskWidget() : base() { } public MaskWidget(MaskWidget other) : base(other) diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/CncSettingsLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/CncSettingsLogic.cs index 413ce4b5aa..57a9d266b2 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/CncSettingsLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/CncSettingsLogic.cs @@ -155,12 +155,12 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic bool ShowColorPicker(DropDownButtonWidget color, PlayerSettings s) { - Action onSelect = c => {s.ColorRamp = c; color.RemovePanel();}; + Action onExit = c => {s.ColorRamp = c; color.RemovePanel();}; Action onChange = c => {colorPreview.Ramp = c;}; var colorChooser = Game.LoadWidget(world, "COLOR_CHOOSER", null, new WidgetArgs() { - { "onSelect", onSelect }, + { "onExit", onExit }, { "onChange", onChange }, { "initialRamp", s.ColorRamp } }); diff --git a/OpenRA.Mods.RA/Widgets/Logic/ColorPickerLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/ColorPickerLogic.cs index f373e37a8e..9ebb8231b1 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/ColorPickerLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/ColorPickerLogic.cs @@ -17,56 +17,32 @@ namespace OpenRA.Mods.RA.Widgets.Logic { public class ColorPickerLogic { - ColorRamp ramp; - [ObjectCreator.UseCtor] - public ColorPickerLogic(Widget widget, ColorRamp initialRamp, Action onChange, - Action onSelect, WorldRenderer worldRenderer) + public ColorPickerLogic(Widget widget, HSLColor initialColor, Action onChange, WorldRenderer worldRenderer) { - var panel = widget; - ramp = initialRamp; - var hueSlider = panel.Get("HUE"); - var satSlider = panel.Get("SAT"); - var lumSlider = panel.Get("LUM"); + var hueSlider = widget.Get("HUE"); + var mixer = widget.Get("MIXER"); + var randomButton = widget.GetOrNull("RANDOM_BUTTON"); - Action sliderChanged = () => - { - ramp = new ColorRamp((byte)(255*hueSlider.Value), - (byte)(255*satSlider.Value), - (byte)(255*lumSlider.Value), - 10); - onChange(ramp); - }; + hueSlider.OnChange += _ => mixer.Set(hueSlider.Value); + mixer.OnChange += () => onChange(mixer.Color); - hueSlider.OnChange += _ => sliderChanged(); - satSlider.OnChange += _ => sliderChanged(); - lumSlider.OnChange += _ => sliderChanged(); - - Action updateSliders = () => - { - hueSlider.Value = ramp.Color.H / 255f; - satSlider.Value = ramp.Color.S / 255f; - lumSlider.Value = ramp.Color.L / 255f; - }; - - panel.Get("SAVE_BUTTON").OnClick = () => onSelect(ramp); - - var randomButton = panel.Get("RANDOM_BUTTON"); if (randomButton != null) randomButton.OnClick = () => { + // Avoid colors with low sat or lum var hue = (byte)Game.CosmeticRandom.Next(255); - var sat = (byte)Game.CosmeticRandom.Next(255); - var lum = (byte)Game.CosmeticRandom.Next(51,255); + var sat = (byte)Game.CosmeticRandom.Next(70, 255); + var lum = (byte)Game.CosmeticRandom.Next(70, 255); - ramp = new ColorRamp(hue, sat, lum, 10); - updateSliders(); - sliderChanged(); + mixer.Set(new HSLColor(hue, sat, lum)); + hueSlider.Value = hue / 255f; }; // Set the initial state - updateSliders(); - onChange(ramp); + mixer.Set(initialColor); + hueSlider.Value = initialColor.H / 255f; + onChange(mixer.Color); } } } diff --git a/OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs b/OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs index 09659d261e..378162fa7a 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs @@ -103,28 +103,27 @@ namespace OpenRA.Mods.RA.Widgets.Logic public static void ShowColorDropDown(DropDownButtonWidget color, Session.Client client, OrderManager orderManager, ColorPreviewManagerWidget preview) { - Action onSelect = c => + Action onExit = () => { if (client.Bot == null) { - Game.Settings.Player.ColorRamp = c; + Game.Settings.Player.ColorRamp = preview.Ramp; Game.Settings.Save(); } color.RemovePanel(); - orderManager.IssueOrder(Order.Command("color {0} {1}".F(client.Index, c))); + orderManager.IssueOrder(Order.Command("color {0} {1}".F(client.Index, preview.Ramp))); }; - Action onChange = c => preview.Ramp = c; + Action onChange = c => preview.Ramp = new ColorRamp(c, 10); var colorChooser = Game.LoadWidget(orderManager.world, "COLOR_CHOOSER", null, new WidgetArgs() { - { "onSelect", onSelect }, { "onChange", onChange }, - { "initialRamp", client.ColorRamp } + { "initialColor", client.ColorRamp.Color } }); - color.AttachPanel(colorChooser); + color.AttachPanel(colorChooser, onExit); } public static Dictionary GetSpawnClients(OrderManager orderManager, Map map) diff --git a/artsrc/cnc/chrome.svg b/artsrc/cnc/chrome.svg index 6ee015901a..ddf793e3ac 100644 --- a/artsrc/cnc/chrome.svg +++ b/artsrc/cnc/chrome.svg @@ -61,9 +61,9 @@ borderopacity="1.0" inkscape:pageopacity="0.0" inkscape:pageshadow="2" - inkscape:zoom="11.313708" - inkscape:cx="352.22285" - inkscape:cy="474.91804" + inkscape:zoom="5.656854" + inkscape:cx="366.7043" + inkscape:cy="471.90817" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="false" @@ -1276,11 +1276,23 @@ inkscape:export-ydpi="90" /> + + diff --git a/mods/cnc/chrome.yaml b/mods/cnc/chrome.yaml index 32f97902ac..077ca66bff 100644 --- a/mods/cnc/chrome.yaml +++ b/mods/cnc/chrome.yaml @@ -390,6 +390,8 @@ lobby-bits: chrome.png spawn-claimed: 256,32,16,16 spawn-unclaimed: 256,48,16,16 admin: 340,39,7,5 + colorpicker: 256,32,16,16 + huepicker: 388,96,7,15 checkbox-bits: chrome.png checked: 272,32,16,16 diff --git a/mods/cnc/chrome/dialogs.yaml b/mods/cnc/chrome/dialogs.yaml index 8465d33fc7..44925da0ee 100644 --- a/mods/cnc/chrome/dialogs.yaml +++ b/mods/cnc/chrome/dialogs.yaml @@ -1,71 +1,46 @@ Background@COLOR_CHOOSER: Logic:ColorPickerLogic Background:panel-black - Width:315 - Height:130 + Width:234 + Height:105 Children: - Button@SAVE_BUTTON: - Key:return - X:210 - Y:90 - Width:90 - Height:25 - Text:Save - Button@RANDOM_BUTTON: - X:15 - Y:90 - Width:90 - Height:25 - Text:Random - ShpImage@FACT: - X:220 - Y:15 - Image:fact - Palette:colorpicker - Label@HUE_LABEL: + Background@HUEBG: + Background:panel-black X:5 Y:5 - Width:40 - Height:20 - Align:Right - Text:Hue: - Font:Bold - Slider@HUE: - X:43 - Y:10 - Width:160 - Height:20 - Ticks:5 - Label@SAT_LABEL: + Width:148 + Height:13 + Children: + HueSlider@HUE: + X:2 + Y:2 + Width:144 + Height:9 + Ticks:5 + Background@MIXERBG: + Background:panel-black X:5 - Y:30 - Width:40 - Height:20 - Align:Right - Text:Sat: - Font:Bold - Slider@SAT: - X:43 - Y:35 - Width:160 - Height:20 - Ticks:5 - Label@LUM_LABEL: - X:5 - Y:55 - Width:40 - Height:20 - Align:Right - Text:Lum: - Font:Bold - Slider@LUM: - X:43 - Y:60 - Width:160 - Height:20 - Ticks:5 - MinimumValue: 0.2 - MaximumValue: 1 + Y:23 + Width:148 + Height:76 + Children: + ColorMixer@MIXER: + X:2 + Y:2 + Width:144 + Height:72 + ShpImage@FACT: + X:160 + Y:13 + Image:fact + Palette:colorpicker + Button@RANDOM_BUTTON: + Key:tab + X:158 + Y:74 + Width:70 + Height:25 + Text:Random ScrollPanel@LABEL_DROPDOWN_TEMPLATE: Width:DROPDOWN_WIDTH diff --git a/mods/cnc/uibits/chrome.png b/mods/cnc/uibits/chrome.png index 5a0df4224e..09e23d92d4 100644 Binary files a/mods/cnc/uibits/chrome.png and b/mods/cnc/uibits/chrome.png differ diff --git a/mods/d2k/chrome.yaml b/mods/d2k/chrome.yaml index fbee0faecc..ce73263ac1 100644 --- a/mods/d2k/chrome.yaml +++ b/mods/d2k/chrome.yaml @@ -240,6 +240,8 @@ lobby-bits: spawnpoints.png spawn-unclaimed: 528,128,16,16 spawn-claimed: 512,128,16,16 admin: 37,5,7,5 + colorpicker: 512,128,16,16 + huepicker: 45,0,7,15 strategic: strategic.png unowned: 0,0,32,32 diff --git a/mods/d2k/chrome/color-picker.yaml b/mods/d2k/chrome/color-picker.yaml index a51f95e9b9..3a4d93c0c5 100644 --- a/mods/d2k/chrome/color-picker.yaml +++ b/mods/d2k/chrome/color-picker.yaml @@ -1,66 +1,44 @@ Background@COLOR_CHOOSER: Logic:ColorPickerLogic Background:dialog2 - Width:310 - Height:120 + Width:234 + Height:105 Children: - Button@SAVE_BUTTON: - X:210 - Y:85 - Width:90 - Height:25 - Text:Save - Font:Bold - Button@RANDOM_BUTTON: - X:115 - Y:85 - Width:90 - Height:25 - Text:Random - Font:Bold - ShpImage@CARRYALL: - X:220 - Y:10 - Image:carryall - Palette:colorpicker - Label@HUE_LABEL: - X:0 + Background@HUEBG: + Background:dialog3 + X:5 Y:5 - Width:40 - Height:20 - Align: Right - Text: Hue: - Slider@HUE: - X:43 - Y:10 - Width:160 - Height:20 - Ticks:5 - Label@SAT_LABEL: - X:0 - Y:30 - Width:40 - Height:20 - Align: Right - Text: Sat: - Slider@SAT: - X:43 - Y:35 - Width:160 - Height:20 - Ticks:5 - Label@LUM_LABEL: - X:0 - Y:55 - Width:40 - Height:20 - Align: Right - Text: Lum: - Slider@LUM: - X:43 - Y:60 - Width:160 - Height:20 - Ticks:5 - MinimumValue: 0.2 - MaximumValue: 1 + Width:148 + Height:13 + Children: + HueSlider@HUE: + X:2 + Y:2 + Width:144 + Height:9 + Ticks:5 + Background@MIXERBG: + Background:dialog3 + X:5 + Y:23 + Width:148 + Height:76 + Children: + ColorMixer@MIXER: + X:2 + Y:2 + Width:144 + Height:72 + ShpImage@FACT: + X:160 + Y:8 + Image:carryall + Frame:13 + Palette:colorpicker + Button@RANDOM_BUTTON: + Key:tab + X:158 + Y:74 + Width:70 + Height:25 + Text:Random \ No newline at end of file diff --git a/mods/ra/chrome.yaml b/mods/ra/chrome.yaml index fdb3ed3762..0707efdef4 100644 --- a/mods/ra/chrome.yaml +++ b/mods/ra/chrome.yaml @@ -173,6 +173,8 @@ lobby-bits: spawnpoints.png spawn-unclaimed: 528,128,16,16 spawn-claimed: 512,128,16,16 admin: 37,5,7,5 + colorpicker: 512,128,16,16 + huepicker: 45,0,7,15 strategic: strategic.png unowned: 0,0,32,32 diff --git a/mods/ra/chrome/color-picker.yaml b/mods/ra/chrome/color-picker.yaml index 6de1830ecd..543e01b5c3 100644 --- a/mods/ra/chrome/color-picker.yaml +++ b/mods/ra/chrome/color-picker.yaml @@ -1,66 +1,43 @@ Background@COLOR_CHOOSER: Logic:ColorPickerLogic Background:dialog2 - Width:310 - Height:120 + Width:234 + Height:105 Children: - Button@SAVE_BUTTON: - X:210 - Y:85 - Width:90 - Height:25 - Text:Save - Font:Bold - Button@RANDOM_BUTTON: - X:115 - Y:85 - Width:90 - Height:25 - Text:Random - Font:Bold + Background@HUEBG: + Background:dialog3 + X:5 + Y:5 + Width:148 + Height:13 + Children: + HueSlider@HUE: + X:2 + Y:2 + Width:144 + Height:9 + Ticks:5 + Background@MIXERBG: + Background:dialog3 + X:5 + Y:23 + Width:148 + Height:76 + Children: + ColorMixer@MIXER: + X:2 + Y:2 + Width:144 + Height:72 ShpImage@FACT: - X:220 - Y:10 + X:156 + Y:1 Image:fact Palette:colorpicker - Label@HUE_LABEL: - X:0 - Y:5 - Width:40 - Height:20 - Align: Right - Text: Hue: - Slider@HUE: - X:43 - Y:10 - Width:160 - Height:20 - Ticks:5 - Label@SAT_LABEL: - X:0 - Y:30 - Width:40 - Height:20 - Align: Right - Text: Sat: - Slider@SAT: - X:43 - Y:35 - Width:160 - Height:20 - Ticks:5 - Label@LUM_LABEL: - X:0 - Y:55 - Width:40 - Height:20 - Align: Right - Text: Lum: - Slider@LUM: - X:43 - Y:60 - Width:160 - Height:20 - Ticks:5 - MinimumValue: 0.2 - MaximumValue: 1 + Button@RANDOM_BUTTON: + Key:tab + X:158 + Y:74 + Width:70 + Height:25 + Text:Random \ No newline at end of file diff --git a/mods/ra/uibits/spawnpoints.png b/mods/ra/uibits/spawnpoints.png index 1e34011111..058dfc523a 100644 Binary files a/mods/ra/uibits/spawnpoints.png and b/mods/ra/uibits/spawnpoints.png differ