diff --git a/Assets/Shaders/DecalsCommon.cginc b/Assets/Shaders/DecalsCommon.cginc index 878541d..3d9f7b0 100644 --- a/Assets/Shaders/DecalsCommon.cginc +++ b/Assets/Shaders/DecalsCommon.cginc @@ -157,7 +157,6 @@ inline float SDFAA(float dist) { float ddist = length(float2(ddx(dist), ddy(dist))); float pixelDist = dist / ddist; return saturate(0.5-pixelDist); - return saturate(0.5 - dist); } #endif \ No newline at end of file diff --git a/Assets/Shaders/HSL.cginc b/Assets/Shaders/HSL.cginc new file mode 100644 index 0000000..4118ba5 --- /dev/null +++ b/Assets/Shaders/HSL.cginc @@ -0,0 +1,11 @@ +#ifndef HSL_INCLUDED +#define HSL_INCLUDED + +inline float3 HSL2RGB(float3 hsl) { + int3 n = int3(0, 8, 4); + float3 k = (n + hsl.x * 12) % 12; + float a = hsl.y * min(hsl.z, 1 - hsl.z); + return hsl.z - a * max(-1, min(k - 3, min(9 - k, 1))); +} + +#endif \ No newline at end of file diff --git a/Assets/Shaders/HSLSlider.shader b/Assets/Shaders/HSLSlider.shader new file mode 100644 index 0000000..90e0bdb --- /dev/null +++ b/Assets/Shaders/HSLSlider.shader @@ -0,0 +1,99 @@ +Shader "ConformalDecals/UI/HSLSlider" +{ + Properties + { + _StencilComp ("Stencil Comparison", Float) = 8 + _Stencil ("Stencil ID", Float) = 0 + _StencilOp ("Stencil Operation", Float) = 0 + _StencilWriteMask ("Stencil Write Mask", Float) = 255 + _StencilReadMask ("Stencil Read Mask", Float) = 255 + + _ColorMask ("Color Mask", Float) = 15 + + [Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip ("Use Alpha Clip", Float) = 0 + } + SubShader + { + Tags + { + "Queue"="Transparent" + "IgnoreProjector"="True" + "RenderType"="Transparent" + "PreviewType"="Plane" + "CanUseSpriteAtlas"="True" + } + Stencil + { + Ref [_Stencil] + Comp [_StencilComp] + Pass [_StencilOp] + ReadMask [_StencilReadMask] + WriteMask [_StencilWriteMask] + } + + Cull Off + Lighting Off + ZWrite Off + ZTest [unity_GUIZTestMode] + Blend SrcAlpha OneMinusSrcAlpha + ColorMask [_ColorMask] + + Pass + { + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + + #pragma require integers + + #include "UnityCG.cginc" + #include "UnityUI.cginc" + #include "HSL.cginc" + + #pragma multi_compile_local _ UNITY_UI_CLIP_RECT + #pragma multi_compile_local _ UNITY_UI_ALPHACLIP + + float4 _ClipRect; + + struct appdata + { + float4 vertex : POSITION; + float2 uv : TEXCOORD0; + }; + + struct v2f + { + float4 vertex : SV_POSITION; + float2 uv : TEXCOORD0; + float4 worldPosition : TEXCOORD1; + }; + + v2f vert (appdata v) + { + v2f o; + o.vertex = UnityObjectToClipPos(v.vertex); + o.worldPosition = v.vertex; + o.uv = v.uv; + return o; + } + + fixed4 frag (v2f i) : SV_Target + { + // sample the texture + fixed4 color = 1; + color.rgb = HSL2RGB(float3(i.uv.y, 1, 0.5)); + + #ifdef UNITY_UI_CLIP_RECT + color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect); + #endif + + #ifdef UNITY_UI_ALPHACLIP + clip (color.a - 0.001); + #endif + + return color; + } + ENDCG + } + } +} \ No newline at end of file diff --git a/Assets/Shaders/HSLSquare.shader b/Assets/Shaders/HSLSquare.shader new file mode 100644 index 0000000..71327b4 --- /dev/null +++ b/Assets/Shaders/HSLSquare.shader @@ -0,0 +1,102 @@ +Shader "ConformalDecals/UI/HSLSquare" +{ + Properties + { + _Hue("Hue", Range(0,1)) = 0 + + _StencilComp ("Stencil Comparison", Float) = 8 + _Stencil ("Stencil ID", Float) = 0 + _StencilOp ("Stencil Operation", Float) = 0 + _StencilWriteMask ("Stencil Write Mask", Float) = 255 + _StencilReadMask ("Stencil Read Mask", Float) = 255 + + _ColorMask ("Color Mask", Float) = 15 + + [Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip ("Use Alpha Clip", Float) = 0 + } + SubShader + { + Tags + { + "Queue"="Transparent" + "IgnoreProjector"="True" + "RenderType"="Transparent" + "PreviewType"="Plane" + "CanUseSpriteAtlas"="True" + } + Stencil + { + Ref [_Stencil] + Comp [_StencilComp] + Pass [_StencilOp] + ReadMask [_StencilReadMask] + WriteMask [_StencilWriteMask] + } + + Cull Off + Lighting Off + ZWrite Off + ZTest [unity_GUIZTestMode] + Blend SrcAlpha OneMinusSrcAlpha + ColorMask [_ColorMask] + + Pass + { + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + + #pragma require integers + + #include "UnityCG.cginc" + #include "UnityUI.cginc" + #include "HSL.cginc" + + #pragma multi_compile_local _ UNITY_UI_CLIP_RECT + #pragma multi_compile_local _ UNITY_UI_ALPHACLIP + + float _Hue; + float4 _ClipRect; + + struct appdata + { + float4 vertex : POSITION; + float2 uv : TEXCOORD0; + }; + + struct v2f + { + float4 vertex : SV_POSITION; + float2 uv : TEXCOORD0; + float4 worldPosition : TEXCOORD1; + }; + + v2f vert (appdata v) + { + v2f o; + o.vertex = UnityObjectToClipPos(v.vertex); + o.worldPosition = v.vertex; + o.uv = v.uv; + return o; + } + + fixed4 frag (v2f i) : SV_Target + { + // sample the texture + fixed4 color = 1; + color.rgb = HSL2RGB(float3(_Hue, i.uv.x, i.uv.y)); + + #ifdef UNITY_UI_CLIP_RECT + color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect); + #endif + + #ifdef UNITY_UI_ALPHACLIP + clip (color.a - 0.001); + #endif + + return color; + } + ENDCG + } + } +} \ No newline at end of file diff --git a/Assets/Textures/UI.png b/Assets/Textures/UI.png deleted file mode 100644 index 3c1e63a..0000000 Binary files a/Assets/Textures/UI.png and /dev/null differ diff --git a/GameData/ConformalDecals/Plugins/ConformalDecals.dll b/GameData/ConformalDecals/Plugins/ConformalDecals.dll index afc4c2d..76afae2 100644 Binary files a/GameData/ConformalDecals/Plugins/ConformalDecals.dll and b/GameData/ConformalDecals/Plugins/ConformalDecals.dll differ diff --git a/GameData/ConformalDecals/Resources/ui.conformaldecals b/GameData/ConformalDecals/Resources/ui.conformaldecals index 8083a9f..c8c8f29 100644 Binary files a/GameData/ConformalDecals/Resources/ui.conformaldecals and b/GameData/ConformalDecals/Resources/ui.conformaldecals differ diff --git a/Source/ConformalDecals/ConformalDecals.csproj b/Source/ConformalDecals/ConformalDecals.csproj index c66ad9a..2c7ba10 100644 --- a/Source/ConformalDecals/ConformalDecals.csproj +++ b/Source/ConformalDecals/ConformalDecals.csproj @@ -85,7 +85,7 @@ - + diff --git a/Source/ConformalDecals/Text/FormattedText.cs b/Source/ConformalDecals/Text/FormattedText.cs new file mode 100644 index 0000000..e69ab2c --- /dev/null +++ b/Source/ConformalDecals/Text/FormattedText.cs @@ -0,0 +1,15 @@ +using TMPro; +using UnityEngine; + +namespace ConformalDecals.Text { + public struct FormattedText { + public string text; + public TMP_FontAsset font; + public FontStyles style; + public bool vertical; + + public Color32 color; + public Color32 outlineColor; + public float outlineWidth; + } +} \ No newline at end of file diff --git a/Source/ConformalDecals/Text/TextSettings.cs b/Source/ConformalDecals/Text/TextSettings.cs deleted file mode 100644 index 366c02f..0000000 --- a/Source/ConformalDecals/Text/TextSettings.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace ConformalDecals.Text { - public struct TextSettings { - - } -} \ No newline at end of file diff --git a/Source/ConformalDecals/UI/TextEntryController.cs b/Source/ConformalDecals/UI/TextEntryController.cs index 4d4c04b..115e4c8 100644 --- a/Source/ConformalDecals/UI/TextEntryController.cs +++ b/Source/ConformalDecals/UI/TextEntryController.cs @@ -1,9 +1,108 @@ +using System; +using ConformalDecals.Text; +using TMPro; using UnityEngine; +using UnityEngine.UI; namespace ConformalDecals.UI { public class TextEntryController : MonoBehaviour { - public void OnClose() { - Debug.Log("Close!"); + private FormattedText _text; + + [SerializeField] private Selectable _textBox; + [SerializeField] private Toggle _fontColorButton; + [SerializeField] private Toggle _fontButton; + [SerializeField] private Toggle _outlineColorButton; + [SerializeField] private Slider _outlineWidthSlider; + + [SerializeField] private Toggle _boldButton; + [SerializeField] private Toggle _italicButton; + [SerializeField] private Toggle _underlineButton; + [SerializeField] private Toggle _smallCapsButton; + [SerializeField] private Toggle _verticalButton; + + public delegate void TextUpdateReceiver(FormattedText text); + + public delegate void TextCancelReceiver(); + + public TextUpdateReceiver textUpdateCallback; + public TextCancelReceiver textCancelCallback; + + private void Start() { + (_textBox as TMP_InputField).text = _text.text; + + _boldButton.isOn = (_text.style | FontStyles.Bold) != 0; + _italicButton.isOn = (_text.style | FontStyles.Italic) != 0; + _underlineButton.isOn = (_text.style | FontStyles.Underline) != 0; + _smallCapsButton.isOn = (_text.style | FontStyles.SmallCaps) != 0; + _verticalButton.isOn = _text.vertical; + } + + public void Close() { + Destroy(gameObject); + } + + public void OnCancel() { + textCancelCallback(); + Close(); + } + + public void OnApply() { + textUpdateCallback(_text); + Close(); + } + + public void OnTextUpdate(string text) { + _text.text = text; + textUpdateCallback(_text); + + } + + public void OnFontMenu(bool state) { } + public void OnColorMenu(bool state) { } + + public void OnOutlineColorMenu(bool state) { } + + public void OnOutlineUpdate(float value) { + _text.outlineWidth = value; + textUpdateCallback(_text); + + } + + public void OnBoldUpdate(bool state) { + if (state) _text.style |= FontStyles.Bold; + else _text.style &= ~FontStyles.Bold; + + textUpdateCallback(_text); + + } + + public void OnItalicUpdate(bool state) { + if (state) _text.style |= FontStyles.Italic; + else _text.style &= ~FontStyles.Italic; + + textUpdateCallback(_text); + + } + + public void OnUnderlineUpdate(bool state) { + if (state) _text.style |= FontStyles.Underline; + else _text.style &= ~FontStyles.Underline; + + textUpdateCallback(_text); + + } + + public void OnSmallCapsUpdate(bool state) { + if (state) _text.style |= FontStyles.SmallCaps; + else _text.style &= ~FontStyles.SmallCaps; + + textUpdateCallback(_text); + + } + + public void OnVerticalUpdate(bool state) { + _text.vertical = state; + textUpdateCallback(_text); } } } \ No newline at end of file diff --git a/Source/ConformalDecals/UI/UILoader.cs b/Source/ConformalDecals/UI/UILoader.cs index 81ef217..aa6fb8c 100644 --- a/Source/ConformalDecals/UI/UILoader.cs +++ b/Source/ConformalDecals/UI/UILoader.cs @@ -14,11 +14,21 @@ namespace ConformalDecals.UI { var prefabs = AssetBundle.LoadFromFile(Path + "ui.conformaldecals"); textEntryPrefab = prefabs.LoadAsset("TextEntryPanel") as GameObject; - + ProcessWindow(textEntryPrefab); Debug.Log("[ConformalDecals] UI prefabs loaded and modified"); - + Debug.Log($"[ConformalDecals] {MainCanvasUtil.MainCanvas.renderMode}"); + Debug.Log($"[ConformalDecals] {MainCanvasUtil.MainCanvas.sortingOrder}"); + Debug.Log($"[ConformalDecals] {MainCanvasUtil.MainCanvas.sortingLayerID}"); + Debug.Log($"[ConformalDecals] {MainCanvasUtil.MainCanvas.sortingLayerName}"); + foreach (var layer in SortingLayer.layers) { + Debug.Log(layer.name); + Debug.Log(layer.id); + Debug.Log(layer.value); + } + + var window = Instantiate(UILoader.textEntryPrefab, MainCanvasUtil.MainCanvas.transform, true); } @@ -54,7 +64,7 @@ namespace ConformalDecals.UI { ProcessSelectable(tag.gameObject, skin.toggle); break; case UITag.UIType.Slider: - ProcessSlider(tag.gameObject, skin.horizontalScrollbar, skin.horizontalScrollbarThumb, skin.verticalScrollbar, skin.verticalScrollbarThumb); + ProcessSlider(tag.gameObject, skin.horizontalSlider, skin.horizontalSliderThumb, skin.verticalSlider, skin.verticalSliderThumb); break; case UITag.UIType.Box: ProcessSelectable(tag.gameObject, skin.box); @@ -68,7 +78,7 @@ namespace ConformalDecals.UI { case UITag.UIType.Header: ProcessText(tag.GetComponent(), font, new Color(0.718f, 0.996f, 0.000f, 1.000f), 16); break; - } + } } } @@ -79,13 +89,13 @@ namespace ConformalDecals.UI { private static void ProcessImage(Image image, UIStyleState state) { image.sprite = state.background; image.color = Color.white; - image.type = Image.Type.Sliced; + image.type = Image.Type.Sliced; } - + private static void ProcessSelectable(GameObject gameObject, UIStyle style) { var selectable = gameObject.GetComponent(); if (selectable == null) throw new FormatException("No Selectable component present"); - + ProcessImage(selectable.image, style.normal); selectable.transition = Selectable.Transition.SpriteSwap; @@ -94,7 +104,6 @@ namespace ConformalDecals.UI { state.highlightedSprite = style.highlight.background; state.pressedSprite = style.active.background; state.disabledSprite = style.disabled.background; - selectable.spriteState = state; }