mirror of
https://github.com/drewcassidy/KSP-Conformal-Decals.git
synced 2024-09-01 18:23:54 +00:00
Only update text once per frame
Fixed text re-rendering several times in a single frame when pasting in text
This commit is contained in:
parent
bf8e98caf0
commit
5feb16dcfb
Binary file not shown.
@ -9,7 +9,7 @@ namespace ConformalDecals.Text {
|
|||||||
/// The rectangle that the rendered text takes up within the texture
|
/// The rectangle that the rendered text takes up within the texture
|
||||||
public Rect Window { get; private set; }
|
public Rect Window { get; private set; }
|
||||||
|
|
||||||
/// The number of users for this render output. If 0, it can be discarded from the cache and the texture reused
|
/// The number of users for this render output. If 0, it can be discarded from the cache
|
||||||
public int UserCount { get; set; }
|
public int UserCount { get; set; }
|
||||||
|
|
||||||
public TextRenderOutput(Texture2D texture, Rect window) {
|
public TextRenderOutput(Texture2D texture, Rect window) {
|
||||||
|
@ -3,7 +3,6 @@ using ConformalDecals.Text;
|
|||||||
using ConformalDecals.Util;
|
using ConformalDecals.Util;
|
||||||
using TMPro;
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Events;
|
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
||||||
namespace ConformalDecals.UI {
|
namespace ConformalDecals.UI {
|
||||||
@ -35,14 +34,15 @@ namespace ConformalDecals.UI {
|
|||||||
private Vector2 _lineSpacingRange;
|
private Vector2 _lineSpacingRange;
|
||||||
private Vector2 _charSpacingRange;
|
private Vector2 _charSpacingRange;
|
||||||
private TMP_InputField _textBoxTMP;
|
private TMP_InputField _textBoxTMP;
|
||||||
|
private FontMenuController _fontMenu;
|
||||||
private TextUpdateDelegate _onValueChanged;
|
private TextUpdateDelegate _onValueChanged;
|
||||||
|
|
||||||
private FontMenuController _fontMenu;
|
private static int _lockCounter;
|
||||||
|
|
||||||
private bool _ignoreUpdates;
|
|
||||||
private bool _isLocked;
|
private bool _isLocked;
|
||||||
private string _lockString;
|
private string _lockString;
|
||||||
private static int _lockCounter;
|
private bool _ignoreUpdates;
|
||||||
|
private bool _textUpdated;
|
||||||
|
|
||||||
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,
|
||||||
@ -74,7 +74,7 @@ namespace ConformalDecals.UI {
|
|||||||
|
|
||||||
public void SetControlLock(string value = null) {
|
public void SetControlLock(string value = null) {
|
||||||
if (_isLocked) return;
|
if (_isLocked) return;
|
||||||
InputLockManager.SetControlLock(_lockString);
|
InputLockManager.SetControlLock(ControlTypes.EDITOR_UI, _lockString);
|
||||||
_isLocked = true;
|
_isLocked = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,8 +86,7 @@ namespace ConformalDecals.UI {
|
|||||||
|
|
||||||
public void OnTextUpdate(string newText) {
|
public void OnTextUpdate(string newText) {
|
||||||
this._text = newText;
|
this._text = newText;
|
||||||
|
_textUpdated = true;
|
||||||
OnValueChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnFontMenu() {
|
public void OnFontMenu() {
|
||||||
@ -105,7 +104,7 @@ namespace ConformalDecals.UI {
|
|||||||
_textBoxTMP.fontAsset = _font.FontAsset;
|
_textBoxTMP.fontAsset = _font.FontAsset;
|
||||||
|
|
||||||
UpdateStyleButtons();
|
UpdateStyleButtons();
|
||||||
OnValueChanged();
|
_textUpdated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnLineSpacingUpdate(float value) {
|
public void OnLineSpacingUpdate(float value) {
|
||||||
@ -114,7 +113,7 @@ namespace ConformalDecals.UI {
|
|||||||
_lineSpacing = Mathf.Lerp(_lineSpacingRange.x, _lineSpacingRange.y, value);
|
_lineSpacing = Mathf.Lerp(_lineSpacingRange.x, _lineSpacingRange.y, value);
|
||||||
|
|
||||||
UpdateLineSpacing();
|
UpdateLineSpacing();
|
||||||
OnValueChanged();
|
_textUpdated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnLineSpacingUpdate(string text) {
|
public void OnLineSpacingUpdate(string text) {
|
||||||
@ -128,7 +127,7 @@ namespace ConformalDecals.UI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
UpdateLineSpacing();
|
UpdateLineSpacing();
|
||||||
OnValueChanged();
|
_textUpdated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnCharSpacingUpdate(float value) {
|
public void OnCharSpacingUpdate(float value) {
|
||||||
@ -137,7 +136,7 @@ namespace ConformalDecals.UI {
|
|||||||
_charSpacing = Mathf.Lerp(_charSpacingRange.x, _charSpacingRange.y, value);
|
_charSpacing = Mathf.Lerp(_charSpacingRange.x, _charSpacingRange.y, value);
|
||||||
|
|
||||||
UpdateCharSpacing();
|
UpdateCharSpacing();
|
||||||
OnValueChanged();
|
_textUpdated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnCharSpacingUpdate(string text) {
|
public void OnCharSpacingUpdate(string text) {
|
||||||
@ -151,7 +150,7 @@ namespace ConformalDecals.UI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
UpdateCharSpacing();
|
UpdateCharSpacing();
|
||||||
OnValueChanged();
|
_textUpdated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnBoldUpdate(bool state) {
|
public void OnBoldUpdate(bool state) {
|
||||||
@ -163,7 +162,7 @@ namespace ConformalDecals.UI {
|
|||||||
_style &= ~FontStyles.Bold;
|
_style &= ~FontStyles.Bold;
|
||||||
|
|
||||||
_textBoxTMP.textComponent.fontStyle = _style | _font.FontStyle & ~_font.FontStyleMask;
|
_textBoxTMP.textComponent.fontStyle = _style | _font.FontStyle & ~_font.FontStyleMask;
|
||||||
OnValueChanged();
|
_textUpdated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnItalicUpdate(bool state) {
|
public void OnItalicUpdate(bool state) {
|
||||||
@ -175,7 +174,7 @@ namespace ConformalDecals.UI {
|
|||||||
_style &= ~FontStyles.Italic;
|
_style &= ~FontStyles.Italic;
|
||||||
|
|
||||||
_textBoxTMP.textComponent.fontStyle = _style | _font.FontStyle & ~_font.FontStyleMask;
|
_textBoxTMP.textComponent.fontStyle = _style | _font.FontStyle & ~_font.FontStyleMask;
|
||||||
OnValueChanged();
|
_textUpdated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnUnderlineUpdate(bool state) {
|
public void OnUnderlineUpdate(bool state) {
|
||||||
@ -187,7 +186,7 @@ namespace ConformalDecals.UI {
|
|||||||
_style &= ~FontStyles.Underline;
|
_style &= ~FontStyles.Underline;
|
||||||
|
|
||||||
_textBoxTMP.textComponent.fontStyle = _style | _font.FontStyle & ~_font.FontStyleMask;
|
_textBoxTMP.textComponent.fontStyle = _style | _font.FontStyle & ~_font.FontStyleMask;
|
||||||
OnValueChanged();
|
_textUpdated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnSmallCapsUpdate(bool state) {
|
public void OnSmallCapsUpdate(bool state) {
|
||||||
@ -199,19 +198,19 @@ namespace ConformalDecals.UI {
|
|||||||
_style &= ~FontStyles.SmallCaps;
|
_style &= ~FontStyles.SmallCaps;
|
||||||
|
|
||||||
_textBoxTMP.textComponent.fontStyle = _style | _font.FontStyle & ~_font.FontStyleMask;
|
_textBoxTMP.textComponent.fontStyle = _style | _font.FontStyle & ~_font.FontStyleMask;
|
||||||
OnValueChanged();
|
_textUpdated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnVerticalUpdate(bool state) {
|
public void OnVerticalUpdate(bool state) {
|
||||||
if (_ignoreUpdates) return;
|
if (_ignoreUpdates) return;
|
||||||
|
|
||||||
_vertical = state;
|
_vertical = state;
|
||||||
OnValueChanged();
|
_textUpdated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Start() {
|
private void Start() {
|
||||||
_lockString = $"ConformalDecals_TextEditor_{_lockCounter++}";
|
_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;
|
||||||
@ -229,9 +228,12 @@ namespace ConformalDecals.UI {
|
|||||||
private void OnDestroy() {
|
private void OnDestroy() {
|
||||||
RemoveControlLock();
|
RemoveControlLock();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnValueChanged() {
|
private void LateUpdate() {
|
||||||
_onValueChanged(_text, _font, _style, _vertical, _lineSpacing, _charSpacing);
|
if (_textUpdated) {
|
||||||
|
_onValueChanged(_text, _font, _style, _vertical, _lineSpacing, _charSpacing);
|
||||||
|
_textUpdated = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateStyleButtons() {
|
private void UpdateStyleButtons() {
|
||||||
|
Loading…
Reference in New Issue
Block a user