Decal text input UI
parent
1316dbb553
commit
e87fc48edf
Binary file not shown.
@ -1,3 +1,3 @@
|
|||||||
version https://git-lfs.github.com/spec/v1
|
version https://git-lfs.github.com/spec/v1
|
||||||
oid sha256:c543a58c9bc1ea96e26ce85625ca1fd765f5f1067f0eeca8fbdf68a2fe7e66ab
|
oid sha256:29f1da73b9f5fbd996162fb61f99378b5f05fbc35d93d04907c6025963f8a4c4
|
||||||
size 139184
|
size 347881
|
||||||
|
Binary file not shown.
@ -1,33 +1,52 @@
|
|||||||
|
using System;
|
||||||
using ConformalDecals.Text;
|
using ConformalDecals.Text;
|
||||||
using ConformalDecals.UI;
|
using ConformalDecals.UI;
|
||||||
using ConformalDecals.Util;
|
using ConformalDecals.Util;
|
||||||
using TMPro;
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
|
||||||
|
|
||||||
namespace ConformalDecals {
|
namespace ConformalDecals {
|
||||||
public class ModuleConformalText: ModuleConformalDecal {
|
public class ModuleConformalText : ModuleConformalDecal {
|
||||||
[KSPField(isPersistant = true)] public string text = "Hello World!";
|
[KSPField(isPersistant = true)] public string text = "Hello World!";
|
||||||
|
[KSPField(isPersistant = true)] public string font = "Calibri SDF";
|
||||||
|
[KSPField(isPersistant = true)] public int style;
|
||||||
|
[KSPField(isPersistant = true)] public bool vertical;
|
||||||
|
[KSPField(isPersistant = true)] public Color color = Color.black;
|
||||||
|
[KSPField(isPersistant = true)] public Color outlineColor = Color.white;
|
||||||
|
[KSPField(isPersistant = true)] public float outlineWidth;
|
||||||
|
|
||||||
private GameObject _textEntryGui;
|
private DecalText _text;
|
||||||
|
|
||||||
|
private TextEntryController _textEntryController;
|
||||||
|
|
||||||
public override void OnLoad(ConfigNode node) {
|
public override void OnLoad(ConfigNode node) {
|
||||||
base.OnLoad(node);
|
base.OnLoad(node);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnStart(StartState state) {
|
public override void OnStart(StartState state) {
|
||||||
base.OnStart(state);
|
base.OnStart(state);
|
||||||
|
|
||||||
|
var decalFont = DecalConfig.GetFont(font);
|
||||||
|
|
||||||
|
_text = new DecalText {
|
||||||
|
text = text,
|
||||||
|
font = decalFont,
|
||||||
|
style = (FontStyles) style,
|
||||||
|
vertical = vertical,
|
||||||
|
color = color,
|
||||||
|
outlineColor = outlineColor,
|
||||||
|
outlineWidth = outlineWidth
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnTextUpdate(DecalText newText) {
|
||||||
|
_text = newText;
|
||||||
}
|
}
|
||||||
|
|
||||||
[KSPEvent(guiActive = false, guiActiveEditor = true, guiName = "#LOC_ConformalDecals_gui-select-flag")]
|
[KSPEvent(guiActive = false, guiActiveEditor = true, guiName = "#LOC_ConformalDecals_gui-select-flag")]
|
||||||
public void SetText()
|
public void SetText() {
|
||||||
{
|
if (_textEntryController == null) {
|
||||||
if (_textEntryGui == null) {
|
_textEntryController = TextEntryController.Create(_text, OnTextUpdate);
|
||||||
_textEntryGui = Instantiate(UILoader.textEntryPrefab, MainCanvasUtil.MainCanvas.transform, true);
|
|
||||||
//_textEntryGui.AddComponent<DragPanel>();
|
|
||||||
//MenuNavigation.SpawnMenuNavigation(_textEntryGui, Navigation.Mode.Automatic, true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
using System;
|
||||||
|
using TMPro;
|
||||||
|
|
||||||
|
namespace ConformalDecals.Text {
|
||||||
|
public class DecalFont {
|
||||||
|
public readonly string title;
|
||||||
|
public readonly TMP_FontAsset fontAsset;
|
||||||
|
public readonly FontStyles fontStyle;
|
||||||
|
|
||||||
|
public DecalFont(string title, TMP_FontAsset fontAsset, FontStyles fontStyle) {
|
||||||
|
if (fontAsset == null) throw new ArgumentNullException(nameof(fontAsset));
|
||||||
|
|
||||||
|
this.title = title;
|
||||||
|
this.fontAsset = fontAsset;
|
||||||
|
this.fontStyle = fontStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetupSample(TMP_Text tmp) {
|
||||||
|
if (tmp == null) throw new ArgumentNullException(nameof(tmp));
|
||||||
|
if (fontAsset == null) throw new InvalidOperationException("DecalFont has not been initialized and Font is null.");
|
||||||
|
|
||||||
|
tmp.text = title;
|
||||||
|
tmp.font = fontAsset;
|
||||||
|
tmp.fontStyle = fontStyle;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using TMPro;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace ConformalDecals.Text {
|
||||||
|
public struct DecalText {
|
||||||
|
public string text;
|
||||||
|
public DecalFont font;
|
||||||
|
public FontStyles style;
|
||||||
|
public bool vertical;
|
||||||
|
|
||||||
|
public Color color;
|
||||||
|
public Color outlineColor;
|
||||||
|
public float outlineWidth;
|
||||||
|
}
|
||||||
|
}
|
@ -1,15 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,61 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using ConformalDecals.Text;
|
||||||
|
using UniLinq;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
namespace ConformalDecals.UI {
|
||||||
|
public class FontMenuController : MonoBehaviour {
|
||||||
|
[SerializeField] private GameObject _menuItem;
|
||||||
|
[SerializeField] private GameObject _menuList;
|
||||||
|
|
||||||
|
public DecalFont currentFont;
|
||||||
|
|
||||||
|
public delegate void FontUpdateReceiver(DecalFont font);
|
||||||
|
|
||||||
|
public FontUpdateReceiver fontUpdateCallback;
|
||||||
|
|
||||||
|
public static FontMenuController Create(IEnumerable<DecalFont> fonts, DecalFont currentFont, FontUpdateReceiver fontUpdateCallback) {
|
||||||
|
var menu = Instantiate(UILoader.FontMenuPrefab, MainCanvasUtil.MainCanvas.transform, true);
|
||||||
|
menu.AddComponent<DragPanel>();
|
||||||
|
MenuNavigation.SpawnMenuNavigation(menu, Navigation.Mode.Automatic, true);
|
||||||
|
|
||||||
|
var controller = menu.GetComponent<FontMenuController>();
|
||||||
|
controller.fontUpdateCallback = fontUpdateCallback;
|
||||||
|
controller.currentFont = currentFont;
|
||||||
|
controller.Populate(fonts);
|
||||||
|
return controller;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnClose() {
|
||||||
|
Destroy(gameObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnFontSelected(DecalFont font) {
|
||||||
|
currentFont = font ?? throw new ArgumentNullException(nameof(font));
|
||||||
|
fontUpdateCallback(currentFont);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Populate(IEnumerable<DecalFont> fonts) {
|
||||||
|
if (fonts == null) throw new ArgumentNullException(nameof(fonts));
|
||||||
|
|
||||||
|
Toggle active = null;
|
||||||
|
|
||||||
|
foreach (var font in fonts.OrderBy(x => x.title)) {
|
||||||
|
Debug.Log(font.title);
|
||||||
|
var listItem = GameObject.Instantiate(_menuItem, _menuList.transform);
|
||||||
|
listItem.name = font.title;
|
||||||
|
listItem.SetActive(true);
|
||||||
|
|
||||||
|
var fontItem = listItem.AddComponent<FontMenuItem>();
|
||||||
|
fontItem.Font = font;
|
||||||
|
fontItem.fontSelectionCallback = OnFontSelected;
|
||||||
|
|
||||||
|
if (font == currentFont) active = fontItem.toggle;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (active != null) active.isOn = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
using System;
|
||||||
|
using ConformalDecals.Text;
|
||||||
|
using TMPro;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
namespace ConformalDecals.UI {
|
||||||
|
public class FontMenuItem : MonoBehaviour {
|
||||||
|
public DecalFont Font {
|
||||||
|
get => _font;
|
||||||
|
set {
|
||||||
|
_font = value;
|
||||||
|
_font.SetupSample(_label);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public delegate void FontSelectionReceiver(DecalFont font);
|
||||||
|
|
||||||
|
public FontSelectionReceiver fontSelectionCallback;
|
||||||
|
public Toggle toggle;
|
||||||
|
|
||||||
|
private DecalFont _font;
|
||||||
|
private TMP_Text _label;
|
||||||
|
|
||||||
|
private void Awake() {
|
||||||
|
_label = gameObject.GetComponentInChildren<TextMeshProUGUI>();
|
||||||
|
toggle = gameObject.GetComponent<Toggle>();
|
||||||
|
toggle.isOn = false;
|
||||||
|
toggle.onValueChanged.AddListener(delegate { OnToggle(toggle); });
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnToggle(Toggle change) {
|
||||||
|
if (change.isOn) fontSelectionCallback?.Invoke(_font);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue