mirror of
https://github.com/drewcassidy/KSP-Conformal-Decals.git
synced 2024-09-01 18:23:54 +00:00
text input changes
This commit is contained in:
parent
f367a30dec
commit
da3bcf7819
@ -97,7 +97,7 @@ namespace ConformalDecals {
|
|||||||
|
|
||||||
foreach (var fontNode in node.GetNodes("FONT")) {
|
foreach (var fontNode in node.GetNodes("FONT")) {
|
||||||
try {
|
try {
|
||||||
var font = new DecalFont(node, allFonts);
|
var font = new DecalFont(fontNode, allFonts);
|
||||||
_fontList.Add(font.Name, font);
|
_fontList.Add(font.Name, font);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using ConformalDecals.Util;
|
using ConformalDecals.Util;
|
||||||
using JetBrains.Annotations;
|
|
||||||
using TMPro;
|
using TMPro;
|
||||||
using UniLinq;
|
using UniLinq;
|
||||||
|
|
||||||
@ -36,7 +35,7 @@ namespace ConformalDecals.Text {
|
|||||||
public bool SmallCapsMask => (FontStyleMask & FontStyles.SmallCaps) != 0;
|
public bool SmallCapsMask => (FontStyleMask & FontStyles.SmallCaps) != 0;
|
||||||
|
|
||||||
|
|
||||||
public DecalFont([NotNull] ConfigNode node, [NotNull] IEnumerable<TMP_FontAsset> fontAssets) {
|
public DecalFont(ConfigNode node, IEnumerable<TMP_FontAsset> fontAssets) {
|
||||||
if (node == null) throw new ArgumentNullException(nameof(node));
|
if (node == null) throw new ArgumentNullException(nameof(node));
|
||||||
if (fontAssets == null) throw new ArgumentNullException(nameof(fontAssets));
|
if (fontAssets == null) throw new ArgumentNullException(nameof(fontAssets));
|
||||||
|
|
||||||
|
@ -1,16 +1,14 @@
|
|||||||
using System;
|
using System;
|
||||||
using ConformalDecals.Util;
|
|
||||||
using TMPro;
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
// ReSharper disable NonReadonlyMemberInGetHashCode
|
// ReSharper disable NonReadonlyMemberInGetHashCode
|
||||||
|
|
||||||
namespace ConformalDecals.Text {
|
namespace ConformalDecals.Text {
|
||||||
public class DecalTextStyle : ScriptableObject, IEquatable<DecalTextStyle> {
|
public struct DecalTextStyle : IEquatable<DecalTextStyle> {
|
||||||
private FontStyles _fontStyle;
|
private FontStyles _fontStyle;
|
||||||
private bool _vertical;
|
private bool _vertical;
|
||||||
private float _lineSpacing;
|
private float _lineSpacing;
|
||||||
private float _characterSpacing;
|
private float _characterSpacing;
|
||||||
|
|
||||||
public FontStyles FontStyle {
|
public FontStyles FontStyle {
|
||||||
get => _fontStyle;
|
get => _fontStyle;
|
||||||
@ -63,55 +61,42 @@ namespace ConformalDecals.Text {
|
|||||||
get => _characterSpacing;
|
get => _characterSpacing;
|
||||||
set => _characterSpacing = value;
|
set => _characterSpacing = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DecalTextStyle Load(ConfigNode node) {
|
|
||||||
var style = CreateInstance<DecalTextStyle>();
|
public DecalTextStyle(FontStyles fontStyle, bool vertical, float lineSpacing, float characterSpacing) {
|
||||||
style._fontStyle = (FontStyles) ParseUtil.ParseInt(node, "fontStyle", true);
|
_fontStyle = fontStyle;
|
||||||
style._vertical = ParseUtil.ParseBool(node, "vertical", true);
|
_vertical = vertical;
|
||||||
style._lineSpacing = ParseUtil.ParseFloat(node, "lineSpacing", true);
|
_lineSpacing = lineSpacing;
|
||||||
style._characterSpacing = ParseUtil.ParseFloat(node, "characterSpacing", true);
|
_characterSpacing = characterSpacing;
|
||||||
return style;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConfigNode Save() {
|
|
||||||
var node = new ConfigNode("STYLE");
|
|
||||||
node.AddValue("fontStyle", (int) _fontStyle);
|
|
||||||
node.AddValue("vertical", _vertical);
|
|
||||||
node.AddValue("lineSpacing", _lineSpacing);
|
|
||||||
node.AddValue("characterSpacing", _characterSpacing);
|
|
||||||
return node;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public bool Equals(DecalTextStyle other) {
|
public bool Equals(DecalTextStyle other) {
|
||||||
if (ReferenceEquals(null, other)) return false;
|
return FontStyle == other.FontStyle && Vertical == other.Vertical &&
|
||||||
if (ReferenceEquals(this, other)) return true;
|
Mathf.Approximately(LineSpacing, other.LineSpacing) &&
|
||||||
return base.Equals(other) && _fontStyle == other._fontStyle && _vertical == other._vertical && _lineSpacing.Equals(other._lineSpacing) && _characterSpacing.Equals(other._characterSpacing);
|
Mathf.Approximately(CharacterSpacing, other.CharacterSpacing);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool Equals(object obj) {
|
public override bool Equals(object obj) {
|
||||||
if (ReferenceEquals(null, obj)) return false;
|
return obj is DecalTextStyle other && Equals(other);
|
||||||
if (ReferenceEquals(this, obj)) return true;
|
|
||||||
if (obj.GetType() != this.GetType()) return false;
|
|
||||||
return Equals((DecalTextStyle) obj);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int GetHashCode() {
|
public override int GetHashCode() {
|
||||||
unchecked {
|
unchecked {
|
||||||
int hashCode = base.GetHashCode();
|
var hashCode = (int) FontStyle;
|
||||||
hashCode = (hashCode * 397) ^ (int) _fontStyle;
|
hashCode = (hashCode * 397) ^ Vertical.GetHashCode();
|
||||||
hashCode = (hashCode * 397) ^ _vertical.GetHashCode();
|
hashCode = (hashCode * 397) ^ LineSpacing.GetHashCode();
|
||||||
hashCode = (hashCode * 397) ^ _lineSpacing.GetHashCode();
|
hashCode = (hashCode * 397) ^ CharacterSpacing.GetHashCode();
|
||||||
hashCode = (hashCode * 397) ^ _characterSpacing.GetHashCode();
|
|
||||||
return hashCode;
|
return hashCode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool operator ==(DecalTextStyle left, DecalTextStyle right) {
|
public static bool operator ==(DecalTextStyle left, DecalTextStyle right) {
|
||||||
return Equals(left, right);
|
return left.Equals(right);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool operator !=(DecalTextStyle left, DecalTextStyle right) {
|
public static bool operator !=(DecalTextStyle left, DecalTextStyle right) {
|
||||||
return !Equals(left, right);
|
return !left.Equals(right);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -27,6 +27,8 @@ namespace ConformalDecals.UI {
|
|||||||
|
|
||||||
private FontMenuController _fontMenu;
|
private FontMenuController _fontMenu;
|
||||||
|
|
||||||
|
private bool _ignoreUpdates;
|
||||||
|
|
||||||
public static TextEntryController Create(string text, DecalFont font, DecalTextStyle style, UnityAction<string, DecalFont, DecalTextStyle> textUpdateCallback) {
|
public static TextEntryController Create(string text, DecalFont font, DecalTextStyle style, UnityAction<string, DecalFont, DecalTextStyle> textUpdateCallback) {
|
||||||
|
|
||||||
var window = Instantiate(UILoader.TextEntryPrefab, MainCanvasUtil.MainCanvas.transform, true);
|
var window = Instantiate(UILoader.TextEntryPrefab, MainCanvasUtil.MainCanvas.transform, true);
|
||||||
@ -42,7 +44,6 @@ namespace ConformalDecals.UI {
|
|||||||
return controller;
|
return controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void OnClose() {
|
public void OnClose() {
|
||||||
if (_fontMenu != null) _fontMenu.OnClose();
|
if (_fontMenu != null) _fontMenu.OnClose();
|
||||||
Destroy(gameObject);
|
Destroy(gameObject);
|
||||||
@ -59,6 +60,8 @@ namespace ConformalDecals.UI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void OnFontUpdate(DecalFont font) {
|
public void OnFontUpdate(DecalFont font) {
|
||||||
|
if (_ignoreUpdates) return;
|
||||||
|
|
||||||
_font = font;
|
_font = font;
|
||||||
font.SetupSample(_fontButton.GetComponentInChildren<TextMeshProUGUI>());
|
font.SetupSample(_fontButton.GetComponentInChildren<TextMeshProUGUI>());
|
||||||
|
|
||||||
@ -71,45 +74,49 @@ namespace ConformalDecals.UI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void OnBoldUpdate(bool state) {
|
public void OnBoldUpdate(bool state) {
|
||||||
_style.Bold = state;
|
if (_ignoreUpdates) return;
|
||||||
|
|
||||||
|
_style.Bold = state;
|
||||||
OnValueChanged();
|
OnValueChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnItalicUpdate(bool state) {
|
public void OnItalicUpdate(bool state) {
|
||||||
|
if (_ignoreUpdates) return;
|
||||||
|
|
||||||
_style.Italic = state;
|
_style.Italic = state;
|
||||||
OnValueChanged();
|
OnValueChanged();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnUnderlineUpdate(bool state) {
|
public void OnUnderlineUpdate(bool state) {
|
||||||
|
if (_ignoreUpdates) return;
|
||||||
|
|
||||||
_style.Underline = state;
|
_style.Underline = state;
|
||||||
OnValueChanged();
|
OnValueChanged();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnSmallCapsUpdate(bool state) {
|
public void OnSmallCapsUpdate(bool state) {
|
||||||
|
if (_ignoreUpdates) return;
|
||||||
|
|
||||||
_style.SmallCaps = state;
|
_style.SmallCaps = state;
|
||||||
OnValueChanged();
|
OnValueChanged();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnVerticalUpdate(bool state) {
|
public void OnVerticalUpdate(bool state) {
|
||||||
|
if (_ignoreUpdates) return;
|
||||||
|
|
||||||
_style.Vertical = state;
|
_style.Vertical = state;
|
||||||
OnValueChanged();
|
OnValueChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void Start() {
|
private void Start() {
|
||||||
((TMP_InputField) _textBox).text = _text;
|
((TMP_InputField) _textBox).text = _text;
|
||||||
|
|
||||||
_font.SetupSample(_fontButton.GetComponentInChildren<TextMeshProUGUI>());
|
_font.SetupSample(_fontButton.GetComponentInChildren<TextMeshProUGUI>());
|
||||||
|
|
||||||
_boldButton.isOn = _style.Bold;
|
|
||||||
_italicButton.isOn = _style.Italic;
|
|
||||||
_underlineButton.isOn = _style.Underline;
|
|
||||||
_smallCapsButton.isOn = _style.SmallCaps;
|
|
||||||
_verticalButton.isOn = _style.Vertical;
|
|
||||||
UpdateStyleButtons();
|
UpdateStyleButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,10 +125,63 @@ namespace ConformalDecals.UI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateStyleButtons() {
|
private void UpdateStyleButtons() {
|
||||||
_boldButton.interactable = !_font.Bold && !_font.BoldMask;
|
_ignoreUpdates = true;
|
||||||
_italicButton.interactable = !_font.Italic && !_font.ItalicMask;
|
|
||||||
_underlineButton.interactable = !_font.Underline && !_font.UnderlineMask;
|
if (_font.Bold) {
|
||||||
_smallCapsButton.interactable = !_font.SmallCaps && !_font.SmallCapsMask;
|
_boldButton.interactable = false;
|
||||||
|
_boldButton.isOn = true;
|
||||||
|
}
|
||||||
|
else if (_font.BoldMask) {
|
||||||
|
_boldButton.interactable = false;
|
||||||
|
_boldButton.isOn = false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
_boldButton.interactable = true;
|
||||||
|
_boldButton.isOn = _style.Bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_font.Italic) {
|
||||||
|
_italicButton.interactable = false;
|
||||||
|
_italicButton.isOn = true;
|
||||||
|
}
|
||||||
|
else if (_font.ItalicMask) {
|
||||||
|
_italicButton.interactable = false;
|
||||||
|
_italicButton.isOn = false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
_italicButton.interactable = true;
|
||||||
|
_italicButton.isOn = _style.Italic;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_font.Underline) {
|
||||||
|
_underlineButton.interactable = false;
|
||||||
|
_underlineButton.isOn = true;
|
||||||
|
}
|
||||||
|
else if (_font.UnderlineMask) {
|
||||||
|
_underlineButton.interactable = false;
|
||||||
|
_underlineButton.isOn = false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
_underlineButton.interactable = true;
|
||||||
|
_underlineButton.isOn = _style.Underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_font.SmallCaps) {
|
||||||
|
_smallCapsButton.interactable = false;
|
||||||
|
_smallCapsButton.isOn = true;
|
||||||
|
}
|
||||||
|
else if (_font.SmallCapsMask) {
|
||||||
|
_smallCapsButton.interactable = false;
|
||||||
|
_smallCapsButton.isOn = false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
_smallCapsButton.interactable = true;
|
||||||
|
_smallCapsButton.isOn = _style.SmallCaps;
|
||||||
|
}
|
||||||
|
|
||||||
|
_verticalButton.isOn = _style.Vertical;
|
||||||
|
|
||||||
|
_ignoreUpdates = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user