|
|
|
@ -1,4 +1,3 @@
|
|
|
|
|
using System;
|
|
|
|
|
using ConformalDecals.Text;
|
|
|
|
|
using TMPro;
|
|
|
|
|
using UnityEngine;
|
|
|
|
@ -6,12 +5,15 @@ using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
namespace ConformalDecals.UI {
|
|
|
|
|
public class TextEntryController : MonoBehaviour {
|
|
|
|
|
private FormattedText _text;
|
|
|
|
|
public delegate void TextUpdateReceiver(DecalText text);
|
|
|
|
|
|
|
|
|
|
public TextUpdateReceiver textUpdateCallback;
|
|
|
|
|
|
|
|
|
|
public DecalText decalText;
|
|
|
|
|
private FontMenuController _fontMenu;
|
|
|
|
|
|
|
|
|
|
[SerializeField] private Selectable _textBox;
|
|
|
|
|
[SerializeField] private Toggle _fontColorButton;
|
|
|
|
|
[SerializeField] private Toggle _fontButton;
|
|
|
|
|
[SerializeField] private Toggle _outlineColorButton;
|
|
|
|
|
[SerializeField] private Button _fontButton;
|
|
|
|
|
[SerializeField] private Slider _outlineWidthSlider;
|
|
|
|
|
|
|
|
|
|
[SerializeField] private Toggle _boldButton;
|
|
|
|
@ -20,89 +22,123 @@ namespace ConformalDecals.UI {
|
|
|
|
|
[SerializeField] private Toggle _smallCapsButton;
|
|
|
|
|
[SerializeField] private Toggle _verticalButton;
|
|
|
|
|
|
|
|
|
|
public delegate void TextUpdateReceiver(FormattedText text);
|
|
|
|
|
public static TextEntryController Create(DecalText text, TextUpdateReceiver textUpdateCallback) {
|
|
|
|
|
var window = Instantiate(UILoader.TextEntryPrefab, MainCanvasUtil.MainCanvas.transform, true);
|
|
|
|
|
window.AddComponent<DragPanel>();
|
|
|
|
|
MenuNavigation.SpawnMenuNavigation(window, Navigation.Mode.Automatic, true);
|
|
|
|
|
|
|
|
|
|
public delegate void TextCancelReceiver();
|
|
|
|
|
var controller = window.GetComponent<TextEntryController>();
|
|
|
|
|
controller.decalText = text;
|
|
|
|
|
controller.textUpdateCallback = textUpdateCallback;
|
|
|
|
|
text.font.SetupSample(controller._fontButton.GetComponentInChildren<TextMeshProUGUI>());
|
|
|
|
|
|
|
|
|
|
public TextUpdateReceiver textUpdateCallback;
|
|
|
|
|
public TextCancelReceiver textCancelCallback;
|
|
|
|
|
return controller;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Start() {
|
|
|
|
|
(_textBox as TMP_InputField).text = _text.text;
|
|
|
|
|
((TMP_InputField) _textBox).text = decalText.text;
|
|
|
|
|
|
|
|
|
|
_outlineWidthSlider.value = decalText.outlineWidth;
|
|
|
|
|
_boldButton.isOn = (decalText.style & FontStyles.Bold) != 0;
|
|
|
|
|
_italicButton.isOn = (decalText.style & FontStyles.Italic) != 0;
|
|
|
|
|
_underlineButton.isOn = (decalText.style & FontStyles.Underline) != 0;
|
|
|
|
|
_smallCapsButton.isOn = (decalText.style & FontStyles.SmallCaps) != 0;
|
|
|
|
|
_verticalButton.isOn = decalText.vertical;
|
|
|
|
|
|
|
|
|
|
_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() {
|
|
|
|
|
public void OnClose() {
|
|
|
|
|
if (_fontMenu != null) _fontMenu.OnClose();
|
|
|
|
|
Destroy(gameObject);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnCancel() {
|
|
|
|
|
textCancelCallback();
|
|
|
|
|
Close();
|
|
|
|
|
public void OnAnyUpdate() {
|
|
|
|
|
textUpdateCallback(decalText);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnApply() {
|
|
|
|
|
textUpdateCallback(_text);
|
|
|
|
|
Close();
|
|
|
|
|
public void OnTextUpdate(string newText) {
|
|
|
|
|
this.decalText.text = newText;
|
|
|
|
|
|
|
|
|
|
OnAnyUpdate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnTextUpdate(string text) {
|
|
|
|
|
_text.text = text;
|
|
|
|
|
textUpdateCallback(_text);
|
|
|
|
|
public void OnFontMenu() {
|
|
|
|
|
if (_fontMenu == null) _fontMenu = FontMenuController.Create(DecalConfig.Fonts, decalText.font, OnFontUpdate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnFontUpdate(DecalFont font) {
|
|
|
|
|
decalText.font = font;
|
|
|
|
|
font.SetupSample(_fontButton.GetComponentInChildren<TextMeshProUGUI>());
|
|
|
|
|
|
|
|
|
|
var textBox = ((TMP_InputField) _textBox);
|
|
|
|
|
textBox.textComponent.fontStyle = decalText.style | decalText.font.fontStyle;
|
|
|
|
|
textBox.fontAsset = decalText.font.fontAsset;
|
|
|
|
|
|
|
|
|
|
OnAnyUpdate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnFontMenu(bool state) { }
|
|
|
|
|
public void OnColorMenu(bool state) { }
|
|
|
|
|
public void OnColorMenu() { }
|
|
|
|
|
|
|
|
|
|
public void OnOutlineColorMenu(bool state) { }
|
|
|
|
|
public void OnColorUpdate(Color color) {
|
|
|
|
|
decalText.color = color;
|
|
|
|
|
OnAnyUpdate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnOutlineUpdate(float value) {
|
|
|
|
|
_text.outlineWidth = value;
|
|
|
|
|
textUpdateCallback(_text);
|
|
|
|
|
public void OnOutlineColorMenu() { }
|
|
|
|
|
|
|
|
|
|
public void OnOutlineColorUpdate(Color color) {
|
|
|
|
|
decalText.outlineColor = color;
|
|
|
|
|
OnAnyUpdate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnOutlineUpdate(float value) {
|
|
|
|
|
decalText.outlineWidth = value;
|
|
|
|
|
OnAnyUpdate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnBoldUpdate(bool state) {
|
|
|
|
|
if (state) _text.style |= FontStyles.Bold;
|
|
|
|
|
else _text.style &= ~FontStyles.Bold;
|
|
|
|
|
if (state) decalText.style |= FontStyles.Bold;
|
|
|
|
|
else decalText.style &= ~FontStyles.Bold;
|
|
|
|
|
|
|
|
|
|
textUpdateCallback(_text);
|
|
|
|
|
((TMP_InputField) _textBox).textComponent.fontStyle = decalText.style | decalText.font.fontStyle;
|
|
|
|
|
|
|
|
|
|
OnAnyUpdate();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnItalicUpdate(bool state) {
|
|
|
|
|
if (state) _text.style |= FontStyles.Italic;
|
|
|
|
|
else _text.style &= ~FontStyles.Italic;
|
|
|
|
|
if (state) decalText.style |= FontStyles.Italic;
|
|
|
|
|
else decalText.style &= ~FontStyles.Italic;
|
|
|
|
|
|
|
|
|
|
((TMP_InputField) _textBox).textComponent.fontStyle = decalText.style | decalText.font.fontStyle;
|
|
|
|
|
|
|
|
|
|
textUpdateCallback(_text);
|
|
|
|
|
OnAnyUpdate();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnUnderlineUpdate(bool state) {
|
|
|
|
|
if (state) _text.style |= FontStyles.Underline;
|
|
|
|
|
else _text.style &= ~FontStyles.Underline;
|
|
|
|
|
if (state) decalText.style |= FontStyles.Underline;
|
|
|
|
|
else decalText.style &= ~FontStyles.Underline;
|
|
|
|
|
|
|
|
|
|
textUpdateCallback(_text);
|
|
|
|
|
((TMP_InputField) _textBox).textComponent.fontStyle = decalText.style | decalText.font.fontStyle;
|
|
|
|
|
|
|
|
|
|
OnAnyUpdate();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnSmallCapsUpdate(bool state) {
|
|
|
|
|
if (state) _text.style |= FontStyles.SmallCaps;
|
|
|
|
|
else _text.style &= ~FontStyles.SmallCaps;
|
|
|
|
|
if (state) decalText.style |= FontStyles.SmallCaps;
|
|
|
|
|
else decalText.style &= ~FontStyles.SmallCaps;
|
|
|
|
|
|
|
|
|
|
((TMP_InputField) _textBox).textComponent.fontStyle = decalText.style | decalText.font.fontStyle;
|
|
|
|
|
|
|
|
|
|
textUpdateCallback(_text);
|
|
|
|
|
OnAnyUpdate();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnVerticalUpdate(bool state) {
|
|
|
|
|
_text.vertical = state;
|
|
|
|
|
textUpdateCallback(_text);
|
|
|
|
|
decalText.vertical = state;
|
|
|
|
|
OnAnyUpdate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|