mirror of
https://github.com/drewcassidy/KSP-Conformal-Decals.git
synced 2024-09-01 18:23:54 +00:00
Add basic ui controller
This commit is contained in:
@ -85,7 +85,7 @@
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Text\FontLoader.cs" />
|
||||
<Compile Include="Text\TextRenderer.cs" />
|
||||
<Compile Include="Text\TextSettings.cs" />
|
||||
<Compile Include="Text\FormattedText.cs" />
|
||||
<Compile Include="Test\TestLayers.cs" />
|
||||
<Compile Include="UI\TextEntryController.cs" />
|
||||
<Compile Include="UI\UILoader.cs" />
|
||||
|
15
Source/ConformalDecals/Text/FormattedText.cs
Normal file
15
Source/ConformalDecals/Text/FormattedText.cs
Normal file
@ -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;
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
namespace ConformalDecals.Text {
|
||||
public struct TextSettings {
|
||||
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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<TextMeshProUGUI>(), 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<Selectable>();
|
||||
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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user