mirror of
https://github.com/drewcassidy/KSP-Conformal-Decals.git
synced 2024-09-01 18:23:54 +00:00
Add input locks for text entry
This commit is contained in:
parent
98f774b2ae
commit
121428414c
Binary file not shown.
@ -11,7 +11,6 @@ namespace ConformalDecals.UI {
|
|||||||
[Serializable]
|
[Serializable]
|
||||||
public delegate void TextUpdateDelegate(string newText, DecalFont newFont, FontStyles style, bool vertical, float linespacing, float charspacing);
|
public delegate void TextUpdateDelegate(string newText, DecalFont newFont, FontStyles style, bool vertical, float linespacing, float charspacing);
|
||||||
|
|
||||||
|
|
||||||
[SerializeField] private Selectable _textBox;
|
[SerializeField] private Selectable _textBox;
|
||||||
[SerializeField] private Button _fontButton;
|
[SerializeField] private Button _fontButton;
|
||||||
|
|
||||||
@ -41,6 +40,9 @@ namespace ConformalDecals.UI {
|
|||||||
private FontMenuController _fontMenu;
|
private FontMenuController _fontMenu;
|
||||||
|
|
||||||
private bool _ignoreUpdates;
|
private bool _ignoreUpdates;
|
||||||
|
private bool _isLocked;
|
||||||
|
private string _lockString;
|
||||||
|
private static int _lockCounter;
|
||||||
|
|
||||||
public static TextEntryController Create(
|
public static TextEntryController Create(
|
||||||
string text, DecalFont font, FontStyles style, bool vertical, float linespacing, float charspacing,
|
string text, DecalFont font, FontStyles style, bool vertical, float linespacing, float charspacing,
|
||||||
@ -70,6 +72,18 @@ namespace ConformalDecals.UI {
|
|||||||
Destroy(gameObject);
|
Destroy(gameObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetControlLock(string value = null) {
|
||||||
|
if (_isLocked) return;
|
||||||
|
InputLockManager.SetControlLock(_lockString);
|
||||||
|
_isLocked = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemoveControlLock(string value = null) {
|
||||||
|
if (!_isLocked) return;
|
||||||
|
InputLockManager.RemoveControlLock(_lockString);
|
||||||
|
_isLocked = false;
|
||||||
|
}
|
||||||
|
|
||||||
public void OnTextUpdate(string newText) {
|
public void OnTextUpdate(string newText) {
|
||||||
this._text = newText;
|
this._text = newText;
|
||||||
|
|
||||||
@ -195,12 +209,15 @@ namespace ConformalDecals.UI {
|
|||||||
OnValueChanged();
|
OnValueChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void Start() {
|
private void Start() {
|
||||||
|
_lockString = $"ConformalDecals_TextEditor_{_lockCounter++}";
|
||||||
|
|
||||||
_textBoxTMP = ((TMP_InputField) _textBox);
|
_textBoxTMP = ((TMP_InputField) _textBox);
|
||||||
_textBoxTMP.text = _text;
|
_textBoxTMP.text = _text;
|
||||||
_textBoxTMP.textComponent.fontStyle = _style | _font.FontStyle & ~_font.FontStyleMask;
|
_textBoxTMP.textComponent.fontStyle = _style | _font.FontStyle & ~_font.FontStyleMask;
|
||||||
_textBoxTMP.fontAsset = _font.FontAsset;
|
_textBoxTMP.fontAsset = _font.FontAsset;
|
||||||
|
_textBoxTMP.onSelect.AddListener(SetControlLock);
|
||||||
|
_textBoxTMP.onDeselect.AddListener(RemoveControlLock);
|
||||||
|
|
||||||
_font.SetupSample(_fontButton.GetComponentInChildren<TextMeshProUGUI>());
|
_font.SetupSample(_fontButton.GetComponentInChildren<TextMeshProUGUI>());
|
||||||
|
|
||||||
@ -209,6 +226,10 @@ namespace ConformalDecals.UI {
|
|||||||
UpdateCharSpacing();
|
UpdateCharSpacing();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnDestroy() {
|
||||||
|
RemoveControlLock();
|
||||||
|
}
|
||||||
|
|
||||||
private void OnValueChanged() {
|
private void OnValueChanged() {
|
||||||
_onValueChanged(_text, _font, _style, _vertical, _lineSpacing, _charSpacing);
|
_onValueChanged(_text, _font, _style, _vertical, _lineSpacing, _charSpacing);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user