Color picker UI integration

feature-better-tweakables
Andrew Cassidy 4 years ago
parent b1d6e43512
commit d5702ee0e7

@ -0,0 +1,21 @@
using ConformalDecals.Util;
using UnityEngine;
using UnityEngine.UI;
namespace ConformalDecals.UI {
public class ColorBoxSlider : MonoBehaviour {
[SerializeField] private ColorPickerController.ChannelUpdateEvent _onXChannelChanged = new ColorPickerController.ChannelUpdateEvent();
[SerializeField] private ColorPickerController.ChannelUpdateEvent _onYChannelChanged = new ColorPickerController.ChannelUpdateEvent();
[SerializeField] private Vector2 _value;
[SerializeField] private Vector2Int _channel;
[SerializeField] private bool _hsl;
[SerializeField] private BoxSlider _slider;
[SerializeField] private Image _image;
public void OnSliderUpdate(Vector2 value) { }
public void OnColorUpdate(Color rgb, ColorHSL hsl) { }
}
}

@ -0,0 +1,23 @@
using ConformalDecals.Util;
using UnityEngine;
using UnityEngine.UI;
namespace ConformalDecals.UI {
public class ColorChannelSlider : MonoBehaviour {
[SerializeField] private ColorPickerController.ChannelUpdateEvent _onChannelChanged = new ColorPickerController.ChannelUpdateEvent();
[SerializeField] private float _value;
[SerializeField] private int _channel;
[SerializeField] private bool _hsl;
[SerializeField] private Selectable _textBox;
[SerializeField] private Slider _slider;
[SerializeField] private Image _image;
public void OnTextBoxUpdate(string text) { }
public void OnSliderUpdate(float value) { }
public void OnColorUpdate(Color rgb, ColorHSL hsl) { }
}
}

@ -0,0 +1,12 @@
using System;
using System.Globalization;
using UnityEngine;
namespace ConformalDecals.Util {
public struct ColorHSL {
public float h;
public float s;
public float l;
public float a;
}
}

@ -0,0 +1,27 @@
using System;
using ConformalDecals.Util;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
namespace ConformalDecals.UI {
public class ColorPickerController : MonoBehaviour {
[Serializable]
public class ColorUpdateEvent : UnityEvent<Color, ColorHSL> { }
[Serializable]
public class ChannelUpdateEvent : UnityEvent<float, int, bool> { }
[SerializeField] private ColorUpdateEvent _onColorChanged = new ColorUpdateEvent();
[SerializeField] private Color _value;
[SerializeField] private Image _previewImage;
[SerializeField] private Selectable _hexTextBox;
public void OnClose() { }
public void OnHexColorUpdate(string text) { }
public void OnChannelUpdate(float value, int channel, bool hsl) { }
}
}

@ -2,11 +2,9 @@ using UnityEngine;
namespace ConformalDecals.UI {
public class FontMenuController : MonoBehaviour {
[SerializeField] private GameObject _menuItem;
[SerializeField] private GameObject _menuList;
public void OnClose() {
}
public void OnClose() { }
}
}

@ -109,7 +109,7 @@ Shader "ConformalDecals/UI/ColorSlider"
#endif //BLUE
#ifdef UNITY_UI_CLIP_RECT
color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
color.a *= UnityGet2DClipping(i.worldPosition.xy, _ClipRect);
#endif
#ifdef UNITY_UI_ALPHACLIP

@ -87,7 +87,7 @@ Shader "ConformalDecals/UI/HSLSquare"
color.rgb = HSL2RGB(float3(_Hue, i.uv.x, i.uv.y));
#ifdef UNITY_UI_CLIP_RECT
color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
color.a *= UnityGet2DClipping(i.worldPosition.xy, _ClipRect);
#endif
#ifdef UNITY_UI_ALPHACLIP

File diff suppressed because it is too large Load Diff

@ -55,4 +55,10 @@ CONFORMALDECALS {
name = Helvetica SDF
title = Helvetica
}
FONT {
name = amarurgt SDF
title = Amarillo USAF
style = 16
}
}

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:29f1da73b9f5fbd996162fb61f99378b5f05fbc35d93d04907c6025963f8a4c4
size 347881
oid sha256:282c893d34ca9c703aee8c1af30efe3fcf9fb38d28cee5097a470ddcc2eaaf7a
size 364831

@ -14,7 +14,7 @@ namespace ConformalDecals.UI {
[SerializeField] private BoxSlider _slider;
[SerializeField] private Image _image;
private Material _imageMaterial;
private static readonly int Hue = Shader.PropertyToID("_Hue");
public Vector2 Value {
get => _value;
@ -26,10 +26,6 @@ namespace ConformalDecals.UI {
}
}
public void Awake() {
_imageMaterial = _image.material;
}
public void OnSliderUpdate(Vector2 value) {
_value = value;
OnChannelUpdate();
@ -42,10 +38,11 @@ namespace ConformalDecals.UI {
public void OnColorUpdate(Color rgb, ColorHSL hsl) {
Vector2 newValue;
_imageMaterial.SetColor(PropertyIDs._Color, rgb);
newValue.x = _hsl ? hsl[_channel.x] : rgb[_channel.x];
newValue.y = _hsl ? hsl[_channel.y] : rgb[_channel.y];
Value = newValue;
_image.material.SetFloat(Hue, hsl.h);
}
public void UpdateSlider() {

@ -15,8 +15,6 @@ namespace ConformalDecals.UI {
[SerializeField] private Slider _slider;
[SerializeField] private Image _image;
private Material _imageMaterial;
private bool _ignoreUpdates;
public float Value {
@ -29,10 +27,6 @@ namespace ConformalDecals.UI {
}
}
public void Awake() {
_imageMaterial = _image.material;
}
public void OnTextBoxUpdate(string text) {
if (_ignoreUpdates) return;
@ -60,7 +54,7 @@ namespace ConformalDecals.UI {
}
public void OnColorUpdate(Color rgb, ColorHSL hsl) {
_imageMaterial.SetColor(PropertyIDs._Color, rgb);
_image.material.SetColor(PropertyIDs._Color, rgb);
Value = _hsl ? hsl[_channel] : rgb[_channel];
}

@ -12,9 +12,6 @@ namespace ConformalDecals.UI {
[SerializeField] private TextUpdateEvent _onTextUpdate = new TextUpdateEvent();
private DecalText _decalText;
private FontMenuController _fontMenu;
[SerializeField] private Selectable _textBox;
[SerializeField] private Button _fontButton;
[SerializeField] private Slider _outlineWidthSlider;
@ -24,6 +21,9 @@ namespace ConformalDecals.UI {
[SerializeField] private Toggle _underlineButton;
[SerializeField] private Toggle _smallCapsButton;
[SerializeField] private Toggle _verticalButton;
private DecalText _decalText;
private FontMenuController _fontMenu;
public static TextEntryController Create(DecalText text, UnityAction<DecalText> textUpdateCallback) {
var window = Instantiate(UILoader.TextEntryPrefab, MainCanvasUtil.MainCanvas.transform, true);
@ -33,13 +33,14 @@ namespace ConformalDecals.UI {
var controller = window.GetComponent<TextEntryController>();
controller._decalText = text;
controller._onTextUpdate.AddListener(textUpdateCallback);
text.font.SetupSample(controller._fontButton.GetComponentInChildren<TextMeshProUGUI>());
return controller;
}
private void Start() {
((TMP_InputField) _textBox).text = _decalText.text;
_decalText.font.SetupSample(_fontButton.GetComponentInChildren<TextMeshProUGUI>());
_outlineWidthSlider.value = _decalText.outlineWidth;
_boldButton.isOn = (_decalText.style & FontStyles.Bold) != 0;

@ -59,6 +59,9 @@ namespace ConformalDecals.UI {
case UITag.UIType.RadioToggle:
ProcessSelectable(tag.gameObject, skin.toggle);
break;
case UITag.UIType.BoxSlider:
ProcessBoxSlider(tag.gameObject, skin.horizontalSlider, skin.horizontalSliderThumb);
break;
case UITag.UIType.Slider:
ProcessSlider(tag.gameObject, skin.horizontalSlider, skin.horizontalSliderThumb, skin.verticalSlider, skin.verticalSliderThumb);
break;
@ -90,47 +93,62 @@ namespace ConformalDecals.UI {
private static void ProcessSelectable(GameObject gameObject, UIStyle style) {
var selectable = gameObject.GetComponent<Selectable>();
if (selectable == null) throw new FormatException("No Selectable component present");
ProcessImage(selectable.image, style.normal);
if (selectable == null) {
ProcessImage(gameObject, style);
}
else {
ProcessImage(selectable.image, style.normal);
selectable.transition = Selectable.Transition.SpriteSwap;
selectable.transition = Selectable.Transition.SpriteSwap;
var state = selectable.spriteState;
state.highlightedSprite = style.highlight.background;
state.pressedSprite = style.active.background;
state.disabledSprite = style.disabled.background;
selectable.spriteState = state;
var state = selectable.spriteState;
state.highlightedSprite = style.highlight.background;
state.pressedSprite = style.active.background;
state.disabledSprite = style.disabled.background;
selectable.spriteState = state;
}
}
private static void ProcessToggleButton(GameObject gameObject, UIStyle style) {
ProcessSelectable(gameObject, style);
var toggle = gameObject.GetComponent<Toggle>();
ProcessImage(toggle.graphic as Image, style.active);
if (toggle != null) ProcessImage(toggle.graphic as Image, style.active);
}
private static void ProcessSlider(GameObject gameObject, UIStyle horizontalStyle, UIStyle horizontalThumbStyle, UIStyle verticalStyle, UIStyle verticalThumbStyle) {
var slider = gameObject.GetComponent<Slider>();
if (slider == null) throw new FormatException("No Slider component present");
UIStyle sliderStyle;
UIStyle thumbStyle;
if (slider.direction == Slider.Direction.BottomToTop || slider.direction == Slider.Direction.TopToBottom) {
sliderStyle = verticalStyle;
thumbStyle = verticalThumbStyle;
if (slider == null) {
ProcessImage(gameObject, horizontalThumbStyle);
}
else {
sliderStyle = horizontalStyle;
thumbStyle = horizontalThumbStyle;
UIStyle sliderStyle;
UIStyle thumbStyle;
if (slider.direction == Slider.Direction.BottomToTop || slider.direction == Slider.Direction.TopToBottom) {
sliderStyle = verticalStyle;
thumbStyle = verticalThumbStyle;
}
else {
sliderStyle = horizontalStyle;
thumbStyle = horizontalThumbStyle;
}
ProcessSelectable(gameObject, thumbStyle);
var back = gameObject.transform.Find("Background").GetComponent<Image>();
if (back != null) {
back.sprite = sliderStyle.normal.background;
back.type = Image.Type.Sliced;
}
}
}
private static void ProcessBoxSlider(GameObject gameObject, UIStyle backgroundStyle, UIStyle thumbStyle) {
ProcessSelectable(gameObject, thumbStyle);
var back = gameObject.transform.Find("Background").GetComponent<Image>();
if (back != null) {
back.sprite = sliderStyle.normal.background;
back.type = Image.Type.Sliced;
var background = gameObject.transform.Find("Background").gameObject;
if (background != null) {
ProcessImage(background, backgroundStyle);
}
}
@ -138,7 +156,7 @@ namespace ConformalDecals.UI {
ProcessSelectable(gameObject, buttonStyle);
var template = gameObject.transform.Find("Template").gameObject;
ProcessImage(template, windowStyle);
if (template != null) ProcessImage(template, windowStyle);
}
private static void ProcessText(TextMeshProUGUI text, TMP_FontAsset font, Color color, int size = -1) {

@ -12,7 +12,8 @@ namespace ConformalDecals.UI {
Slider,
Dropdown,
Label,
Header
Header,
BoxSlider
}
[SerializeField] public UIType type = UIType.None;

Loading…
Cancel
Save