mirror of
https://github.com/drewcassidy/KSP-Conformal-Decals.git
synced 2024-09-01 18:23:54 +00:00
Decal text input UI
This commit is contained in:
parent
1316dbb553
commit
e87fc48edf
Binary file not shown.
@ -20,4 +20,39 @@ CONFORMALDECALS {
|
|||||||
shader = KSP/Specular (Transparent)
|
shader = KSP/Specular (Transparent)
|
||||||
shader = Solid Color (Alpha)
|
shader = Solid Color (Alpha)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FONT {
|
||||||
|
name = LiberationSans SDF
|
||||||
|
title = Liberation Sans
|
||||||
|
}
|
||||||
|
|
||||||
|
FONT {
|
||||||
|
name = Calibri SDF
|
||||||
|
title = Calibri
|
||||||
|
}
|
||||||
|
|
||||||
|
FONT {
|
||||||
|
name = NotoSans-Regular SDF
|
||||||
|
title = Noto Sans
|
||||||
|
}
|
||||||
|
|
||||||
|
FONT {
|
||||||
|
name = Dited SDF
|
||||||
|
title = Dited
|
||||||
|
}
|
||||||
|
|
||||||
|
FONT {
|
||||||
|
name = Waukegan LDO Extended SDF
|
||||||
|
title = Waukegan Extended
|
||||||
|
}
|
||||||
|
|
||||||
|
FONT {
|
||||||
|
name = Nasalization SDF
|
||||||
|
title = Nasalization
|
||||||
|
}
|
||||||
|
|
||||||
|
FONT {
|
||||||
|
name = Helvetica SDF
|
||||||
|
title = Helvetica
|
||||||
|
}
|
||||||
}
|
}
|
@ -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.
@ -30,7 +30,7 @@
|
|||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<DocumentationFile>bin\Release\ConformalDecals.xml</DocumentationFile>
|
<DocumentationFile>bin\Release\ConformalDecals.xml</DocumentationFile>
|
||||||
<NoWarn>CS1591</NoWarn>
|
<NoWarn>CS1591,CS0649</NoWarn>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
<Reference Include="Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||||
@ -83,10 +83,13 @@
|
|||||||
<Compile Include="ProjectionTarget.cs" />
|
<Compile Include="ProjectionTarget.cs" />
|
||||||
<Compile Include="ModuleConformalDecal.cs" />
|
<Compile Include="ModuleConformalDecal.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="Text\DecalFont.cs" />
|
||||||
<Compile Include="Text\FontLoader.cs" />
|
<Compile Include="Text\FontLoader.cs" />
|
||||||
<Compile Include="Text\TextRenderer.cs" />
|
<Compile Include="Text\TextRenderer.cs" />
|
||||||
<Compile Include="Text\FormattedText.cs" />
|
<Compile Include="Text\DecalText.cs" />
|
||||||
<Compile Include="Test\TestLayers.cs" />
|
<Compile Include="Test\TestLayers.cs" />
|
||||||
|
<Compile Include="UI\FontMenuController.cs" />
|
||||||
|
<Compile Include="UI\FontMenuItem.cs" />
|
||||||
<Compile Include="UI\TextEntryController.cs" />
|
<Compile Include="UI\TextEntryController.cs" />
|
||||||
<Compile Include="UI\UILoader.cs" />
|
<Compile Include="UI\UILoader.cs" />
|
||||||
<Compile Include="UI\UITag.cs" />
|
<Compile Include="UI\UITag.cs" />
|
||||||
|
@ -1,13 +1,17 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using ConformalDecals.Text;
|
||||||
using ConformalDecals.Util;
|
using ConformalDecals.Util;
|
||||||
|
using TMPro;
|
||||||
|
using UniLinq;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace ConformalDecals {
|
namespace ConformalDecals {
|
||||||
public static class DecalConfig {
|
public static class DecalConfig {
|
||||||
private static Texture2D _blankNormal;
|
private static Texture2D _blankNormal;
|
||||||
private static List<string> _shaderBlacklist;
|
private static List<string> _shaderBlacklist;
|
||||||
private static int _decalLayer = 31;
|
private static Dictionary<string, DecalFont> _fontList;
|
||||||
private static bool _selectableInFlight;
|
private static int _decalLayer = 31;
|
||||||
|
private static bool _selectableInFlight;
|
||||||
|
|
||||||
private struct LegacyShaderEntry {
|
private struct LegacyShaderEntry {
|
||||||
public string name;
|
public string name;
|
||||||
@ -37,12 +41,17 @@ namespace ConformalDecals {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
public static Texture2D BlankNormal => _blankNormal;
|
public static Texture2D BlankNormal => _blankNormal;
|
||||||
|
|
||||||
public static int DecalLayer => _decalLayer;
|
public static int DecalLayer => _decalLayer;
|
||||||
|
|
||||||
public static bool SelectableInFlight => _selectableInFlight;
|
public static bool SelectableInFlight => _selectableInFlight;
|
||||||
|
|
||||||
|
public static IEnumerable<DecalFont> Fonts => _fontList.Values;
|
||||||
|
|
||||||
|
public static DecalFont FallbackFont { get; private set; }
|
||||||
|
|
||||||
public static bool IsBlacklisted(Shader shader) {
|
public static bool IsBlacklisted(Shader shader) {
|
||||||
return IsBlacklisted(shader.name);
|
return IsBlacklisted(shader.name);
|
||||||
}
|
}
|
||||||
@ -63,14 +72,40 @@ namespace ConformalDecals {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static DecalFont GetFont(string name) {
|
||||||
|
if (_fontList.TryGetValue(name, out var font)) {
|
||||||
|
return font;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new KeyNotFoundException($"Font {name} not found");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void ParseConfig(ConfigNode node) {
|
private static void ParseConfig(ConfigNode node) {
|
||||||
|
|
||||||
|
ParseUtil.ParseIntIndirect(ref _decalLayer, node, "decalLayer");
|
||||||
|
ParseUtil.ParseBoolIndirect(ref _selectableInFlight, node, "selectableInFlight");
|
||||||
|
|
||||||
foreach (var blacklist in node.GetNodes("SHADERBLACKLIST")) {
|
foreach (var blacklist in node.GetNodes("SHADERBLACKLIST")) {
|
||||||
foreach (var shaderName in blacklist.GetValuesList("shader")) {
|
foreach (var shaderName in blacklist.GetValuesList("shader")) {
|
||||||
_shaderBlacklist.Add(shaderName);
|
_shaderBlacklist.Add(shaderName);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var allFonts = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
|
||||||
|
|
||||||
|
foreach (var fontNode in node.GetNodes("FONT")) {
|
||||||
|
var name = ParseUtil.ParseString(fontNode, "name");
|
||||||
|
var title = ParseUtil.ParseString(fontNode, "title", true, name);
|
||||||
|
var style = ParseUtil.ParseInt(fontNode, "style", true);
|
||||||
|
|
||||||
ParseUtil.ParseIntIndirect(ref _decalLayer, node, "decalLayer");
|
var font = allFonts.First(o => o.name == name);
|
||||||
ParseUtil.ParseBoolIndirect(ref _selectableInFlight, node, "selectableInFlight");
|
if (font == null) {
|
||||||
|
Debug.LogWarning($"[ConformalDecals] Could not found named {name}");
|
||||||
|
}
|
||||||
|
|
||||||
|
Debug.Log($"Adding font named {name}");
|
||||||
|
_fontList.Add(name, new DecalFont(title, font, (FontStyles) style));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,6 +131,7 @@ namespace ConformalDecals {
|
|||||||
// ReSharper disable once UnusedMember.Global
|
// ReSharper disable once UnusedMember.Global
|
||||||
public static void ModuleManagerPostLoad() {
|
public static void ModuleManagerPostLoad() {
|
||||||
_shaderBlacklist = new List<string>();
|
_shaderBlacklist = new List<string>();
|
||||||
|
_fontList = new Dictionary<string, DecalFont>();
|
||||||
|
|
||||||
var configs = GameDatabase.Instance.GetConfigs("CONFORMALDECALS");
|
var configs = GameDatabase.Instance.GetConfigs("CONFORMALDECALS");
|
||||||
|
|
||||||
|
@ -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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
27
Source/ConformalDecals/Text/DecalFont.cs
Normal file
27
Source/ConformalDecals/Text/DecalFont.cs
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
16
Source/ConformalDecals/Text/DecalText.cs
Normal file
16
Source/ConformalDecals/Text/DecalText.cs
Normal file
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
61
Source/ConformalDecals/UI/FontMenuController.cs
Normal file
61
Source/ConformalDecals/UI/FontMenuController.cs
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
36
Source/ConformalDecals/UI/FontMenuItem.cs
Normal file
36
Source/ConformalDecals/UI/FontMenuItem.cs
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,3 @@
|
|||||||
using System;
|
|
||||||
using ConformalDecals.Text;
|
using ConformalDecals.Text;
|
||||||
using TMPro;
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@ -6,12 +5,15 @@ using UnityEngine.UI;
|
|||||||
|
|
||||||
namespace ConformalDecals.UI {
|
namespace ConformalDecals.UI {
|
||||||
public class TextEntryController : MonoBehaviour {
|
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 Selectable _textBox;
|
||||||
[SerializeField] private Toggle _fontColorButton;
|
[SerializeField] private Button _fontButton;
|
||||||
[SerializeField] private Toggle _fontButton;
|
|
||||||
[SerializeField] private Toggle _outlineColorButton;
|
|
||||||
[SerializeField] private Slider _outlineWidthSlider;
|
[SerializeField] private Slider _outlineWidthSlider;
|
||||||
|
|
||||||
[SerializeField] private Toggle _boldButton;
|
[SerializeField] private Toggle _boldButton;
|
||||||
@ -20,89 +22,123 @@ namespace ConformalDecals.UI {
|
|||||||
[SerializeField] private Toggle _smallCapsButton;
|
[SerializeField] private Toggle _smallCapsButton;
|
||||||
[SerializeField] private Toggle _verticalButton;
|
[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;
|
return controller;
|
||||||
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() {
|
private void Start() {
|
||||||
|
((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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnClose() {
|
||||||
|
if (_fontMenu != null) _fontMenu.OnClose();
|
||||||
Destroy(gameObject);
|
Destroy(gameObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnCancel() {
|
public void OnAnyUpdate() {
|
||||||
textCancelCallback();
|
textUpdateCallback(decalText);
|
||||||
Close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnApply() {
|
public void OnTextUpdate(string newText) {
|
||||||
textUpdateCallback(_text);
|
this.decalText.text = newText;
|
||||||
Close();
|
|
||||||
|
OnAnyUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnTextUpdate(string text) {
|
public void OnFontMenu() {
|
||||||
_text.text = text;
|
if (_fontMenu == null) _fontMenu = FontMenuController.Create(DecalConfig.Fonts, decalText.font, OnFontUpdate);
|
||||||
textUpdateCallback(_text);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnFontMenu(bool state) { }
|
public void OnFontUpdate(DecalFont font) {
|
||||||
public void OnColorMenu(bool state) { }
|
decalText.font = font;
|
||||||
|
font.SetupSample(_fontButton.GetComponentInChildren<TextMeshProUGUI>());
|
||||||
|
|
||||||
public void OnOutlineColorMenu(bool state) { }
|
var textBox = ((TMP_InputField) _textBox);
|
||||||
|
textBox.textComponent.fontStyle = decalText.style | decalText.font.fontStyle;
|
||||||
|
textBox.fontAsset = decalText.font.fontAsset;
|
||||||
|
|
||||||
|
OnAnyUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnColorMenu() { }
|
||||||
|
|
||||||
|
public void OnColorUpdate(Color color) {
|
||||||
|
decalText.color = color;
|
||||||
|
OnAnyUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnOutlineColorMenu() { }
|
||||||
|
|
||||||
|
public void OnOutlineColorUpdate(Color color) {
|
||||||
|
decalText.outlineColor = color;
|
||||||
|
OnAnyUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
public void OnOutlineUpdate(float value) {
|
public void OnOutlineUpdate(float value) {
|
||||||
_text.outlineWidth = value;
|
decalText.outlineWidth = value;
|
||||||
textUpdateCallback(_text);
|
OnAnyUpdate();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnBoldUpdate(bool state) {
|
public void OnBoldUpdate(bool state) {
|
||||||
if (state) _text.style |= FontStyles.Bold;
|
if (state) decalText.style |= FontStyles.Bold;
|
||||||
else _text.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) {
|
public void OnItalicUpdate(bool state) {
|
||||||
if (state) _text.style |= FontStyles.Italic;
|
if (state) decalText.style |= FontStyles.Italic;
|
||||||
else _text.style &= ~FontStyles.Italic;
|
else decalText.style &= ~FontStyles.Italic;
|
||||||
|
|
||||||
textUpdateCallback(_text);
|
((TMP_InputField) _textBox).textComponent.fontStyle = decalText.style | decalText.font.fontStyle;
|
||||||
|
|
||||||
|
OnAnyUpdate();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnUnderlineUpdate(bool state) {
|
public void OnUnderlineUpdate(bool state) {
|
||||||
if (state) _text.style |= FontStyles.Underline;
|
if (state) decalText.style |= FontStyles.Underline;
|
||||||
else _text.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) {
|
public void OnSmallCapsUpdate(bool state) {
|
||||||
if (state) _text.style |= FontStyles.SmallCaps;
|
if (state) decalText.style |= FontStyles.SmallCaps;
|
||||||
else _text.style &= ~FontStyles.SmallCaps;
|
else decalText.style &= ~FontStyles.SmallCaps;
|
||||||
|
|
||||||
textUpdateCallback(_text);
|
((TMP_InputField) _textBox).textComponent.fontStyle = decalText.style | decalText.font.fontStyle;
|
||||||
|
|
||||||
|
OnAnyUpdate();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnVerticalUpdate(bool state) {
|
public void OnVerticalUpdate(bool state) {
|
||||||
_text.vertical = state;
|
decalText.vertical = state;
|
||||||
textUpdateCallback(_text);
|
OnAnyUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -8,30 +8,22 @@ namespace ConformalDecals.UI {
|
|||||||
public class UILoader : MonoBehaviour {
|
public class UILoader : MonoBehaviour {
|
||||||
private static readonly string Path = KSPUtil.ApplicationRootPath + "GameData/ConformalDecals/Resources/";
|
private static readonly string Path = KSPUtil.ApplicationRootPath + "GameData/ConformalDecals/Resources/";
|
||||||
|
|
||||||
public static GameObject textEntryPrefab;
|
private static GameObject _textEntryPrefab;
|
||||||
|
private static GameObject _fontMenuPrefab;
|
||||||
|
|
||||||
|
public static GameObject FontMenuPrefab => _fontMenuPrefab;
|
||||||
|
public static GameObject TextEntryPrefab => _textEntryPrefab;
|
||||||
|
|
||||||
private void Awake() {
|
private void Awake() {
|
||||||
var prefabs = AssetBundle.LoadFromFile(Path + "ui.conformaldecals");
|
var prefabs = AssetBundle.LoadFromFile(Path + "ui.conformaldecals");
|
||||||
|
|
||||||
textEntryPrefab = prefabs.LoadAsset("TextEntryPanel") as GameObject;
|
_textEntryPrefab = prefabs.LoadAsset("TextEntryPanel") as GameObject;
|
||||||
|
_fontMenuPrefab = prefabs.LoadAsset("FontMenuPanel") as GameObject;
|
||||||
|
|
||||||
ProcessWindow(textEntryPrefab);
|
ProcessWindow(_textEntryPrefab);
|
||||||
|
ProcessWindow(_fontMenuPrefab);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ProcessWindow(GameObject window) {
|
private static void ProcessWindow(GameObject window) {
|
||||||
var skin = UISkinManager.defaultSkin;
|
var skin = UISkinManager.defaultSkin;
|
||||||
var font = UISkinManager.TMPFont;
|
var font = UISkinManager.TMPFont;
|
||||||
|
Loading…
Reference in New Issue
Block a user