Fix styles updating textbox

feature-better-tweakables
Andrew Cassidy 4 years ago
parent d1029ca0c1
commit ddce97ee05

@ -33,6 +33,7 @@ namespace ConformalDecals.UI {
private DecalTextStyle _style; private DecalTextStyle _style;
private Vector2 _lineSpacingRange; private Vector2 _lineSpacingRange;
private Vector2 _charSpacingRange; private Vector2 _charSpacingRange;
private TMP_InputField _textBoxTMP;
private FontMenuController _fontMenu; private FontMenuController _fontMenu;
@ -79,9 +80,9 @@ namespace ConformalDecals.UI {
_font = font; _font = font;
font.SetupSample(_fontButton.GetComponentInChildren<TextMeshProUGUI>()); font.SetupSample(_fontButton.GetComponentInChildren<TextMeshProUGUI>());
var textBox = ((TMP_InputField) _textBox); _textBoxTMP.text = _text;
textBox.textComponent.fontStyle = _style.FontStyle | _font.FontStyle; _textBoxTMP.textComponent.fontStyle = _style.FontStyle | _font.FontStyle & ~_font.FontStyleMask;
textBox.fontAsset = _font.FontAsset; _textBoxTMP.fontAsset = _font.FontAsset;
UpdateStyleButtons(); UpdateStyleButtons();
OnValueChanged(); OnValueChanged();
@ -91,11 +92,11 @@ namespace ConformalDecals.UI {
if (_ignoreUpdates) return; if (_ignoreUpdates) return;
_style.LineSpacing = Mathf.Lerp(_lineSpacingRange.x, _lineSpacingRange.y, value); _style.LineSpacing = Mathf.Lerp(_lineSpacingRange.x, _lineSpacingRange.y, value);
UpdateLineSpacing(); UpdateLineSpacing();
OnValueChanged(); OnValueChanged();
} }
public void OnLineSpacingUpdate(string text) { public void OnLineSpacingUpdate(string text) {
if (_ignoreUpdates) return; if (_ignoreUpdates) return;
@ -105,7 +106,7 @@ namespace ConformalDecals.UI {
else { else {
Logging.LogWarning("Line spacing value '{text}' could not be parsed."); Logging.LogWarning("Line spacing value '{text}' could not be parsed.");
} }
UpdateLineSpacing(); UpdateLineSpacing();
OnValueChanged(); OnValueChanged();
} }
@ -114,11 +115,11 @@ namespace ConformalDecals.UI {
if (_ignoreUpdates) return; if (_ignoreUpdates) return;
_style.CharSpacing = Mathf.Lerp(_charSpacingRange.x, _charSpacingRange.y, value); _style.CharSpacing = Mathf.Lerp(_charSpacingRange.x, _charSpacingRange.y, value);
UpdateCharSpacing(); UpdateCharSpacing();
OnValueChanged(); OnValueChanged();
} }
public void OnCharSpacingUpdate(string text) { public void OnCharSpacingUpdate(string text) {
if (_ignoreUpdates) return; if (_ignoreUpdates) return;
@ -128,7 +129,7 @@ namespace ConformalDecals.UI {
else { else {
Logging.LogWarning("Char spacing value '{text}' could not be parsed."); Logging.LogWarning("Char spacing value '{text}' could not be parsed.");
} }
UpdateCharSpacing(); UpdateCharSpacing();
OnValueChanged(); OnValueChanged();
} }
@ -137,6 +138,7 @@ namespace ConformalDecals.UI {
if (_ignoreUpdates) return; if (_ignoreUpdates) return;
_style.Bold = state; _style.Bold = state;
_textBoxTMP.textComponent.fontStyle = _style.FontStyle | _font.FontStyle & ~_font.FontStyleMask;
OnValueChanged(); OnValueChanged();
} }
@ -144,6 +146,7 @@ namespace ConformalDecals.UI {
if (_ignoreUpdates) return; if (_ignoreUpdates) return;
_style.Italic = state; _style.Italic = state;
_textBoxTMP.textComponent.fontStyle = _style.FontStyle | _font.FontStyle & ~_font.FontStyleMask;
OnValueChanged(); OnValueChanged();
} }
@ -151,26 +154,31 @@ namespace ConformalDecals.UI {
if (_ignoreUpdates) return; if (_ignoreUpdates) return;
_style.Underline = state; _style.Underline = state;
_textBoxTMP.textComponent.fontStyle = _style.FontStyle | _font.FontStyle & ~_font.FontStyleMask;
OnValueChanged(); OnValueChanged();
} }
public void OnSmallCapsUpdate(bool state) { public void OnSmallCapsUpdate(bool state) {
if (_ignoreUpdates) return; if (_ignoreUpdates) return;
_style.SmallCaps = state; _style.SmallCaps = state;
_textBoxTMP.textComponent.fontStyle = _style.FontStyle | _font.FontStyle & ~_font.FontStyleMask;
OnValueChanged(); OnValueChanged();
} }
public void OnVerticalUpdate(bool state) { public void OnVerticalUpdate(bool state) {
if (_ignoreUpdates) return; if (_ignoreUpdates) return;
_style.Vertical = state; _style.Vertical = state;
OnValueChanged(); OnValueChanged();
} }
private void Start() { private void Start() {
((TMP_InputField) _textBox).text = _text; _textBoxTMP = ((TMP_InputField) _textBox);
_textBoxTMP.text = _text;
_textBoxTMP.textComponent.fontStyle = _style.FontStyle | _font.FontStyle & ~_font.FontStyleMask;
_textBoxTMP.fontAsset = _font.FontAsset;
_font.SetupSample(_fontButton.GetComponentInChildren<TextMeshProUGUI>()); _font.SetupSample(_fontButton.GetComponentInChildren<TextMeshProUGUI>());
@ -245,19 +253,19 @@ namespace ConformalDecals.UI {
private void UpdateLineSpacing() { private void UpdateLineSpacing() {
_ignoreUpdates = true; _ignoreUpdates = true;
_lineSpacingSlider.value = Mathf.InverseLerp(_lineSpacingRange.x, _lineSpacingRange.y, _style.LineSpacing); _lineSpacingSlider.value = Mathf.InverseLerp(_lineSpacingRange.x, _lineSpacingRange.y, _style.LineSpacing);
((TMP_InputField) _lineSpacingTextBox).text = $"{_style.LineSpacing:F1}"; ((TMP_InputField) _lineSpacingTextBox).text = $"{_style.LineSpacing:F1}";
_ignoreUpdates = false; _ignoreUpdates = false;
} }
private void UpdateCharSpacing() { private void UpdateCharSpacing() {
_ignoreUpdates = true; _ignoreUpdates = true;
_charSpacingSlider.value = Mathf.InverseLerp(_charSpacingRange.x, _charSpacingRange.y, _style.CharSpacing); _charSpacingSlider.value = Mathf.InverseLerp(_charSpacingRange.x, _charSpacingRange.y, _style.CharSpacing);
((TMP_InputField) _charSpacingTextBox).text = $"{_style.CharSpacing:F1}"; ((TMP_InputField) _charSpacingTextBox).text = $"{_style.CharSpacing:F1}";
_ignoreUpdates = false; _ignoreUpdates = false;
} }
} }

Loading…
Cancel
Save