mirror of
https://github.com/drewcassidy/KSP-Conformal-Decals.git
synced 2024-09-01 18:23:54 +00:00
Better UI and shaders
This commit is contained in:
@ -10,22 +10,25 @@ namespace ConformalDecals {
|
||||
[KSPField(isPersistant = true)] public Color fillColor = Color.black;
|
||||
[KSPField(isPersistant = true)] public Color outlineColor = Color.white;
|
||||
|
||||
[KSPField] public Vector2 lineSpacingRange = new Vector2(-20, 50);
|
||||
[KSPField] public Vector2 charSpacingRange = new Vector2(-20, 50);
|
||||
|
||||
// serialization-only fields. do not use except in serialization functions
|
||||
[KSPField(isPersistant = true)] public string fontName = "Calibri SDF";
|
||||
[KSPField(isPersistant = true)] public int style;
|
||||
[KSPField(isPersistant = true)] public bool vertical;
|
||||
[KSPField(isPersistant = true)] public float lineSpacing;
|
||||
[KSPField(isPersistant = true)] public float characterSpacing;
|
||||
[KSPField(isPersistant = true)] public float charSpacing;
|
||||
|
||||
// KSP TWEAKABLES
|
||||
|
||||
[KSPEvent(guiName = "#LOC_ConformalDecals_gui-set-text", guiActive = false, guiActiveEditor = true)]
|
||||
public void SetText() {
|
||||
if (_textEntryController == null) {
|
||||
_textEntryController = TextEntryController.Create(text, _font, _style, OnTextUpdate);
|
||||
_textEntryController = TextEntryController.Create(text, _font, _style, lineSpacingRange, charSpacingRange, OnTextUpdate);
|
||||
}
|
||||
else {
|
||||
_textEntryController.OnClose();
|
||||
_textEntryController.Close();
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,7 +46,7 @@ namespace ConformalDecals {
|
||||
_fillColorPickerController = ColorPickerController.Create(fillColor, OnFillColorUpdate);
|
||||
}
|
||||
else {
|
||||
_fillColorPickerController.OnClose();
|
||||
_fillColorPickerController.Close();
|
||||
}
|
||||
}
|
||||
|
||||
@ -66,7 +69,7 @@ namespace ConformalDecals {
|
||||
_outlineColorPickerController = ColorPickerController.Create(outlineColor, OnOutlineColorUpdate);
|
||||
}
|
||||
else {
|
||||
_outlineColorPickerController.OnClose();
|
||||
_outlineColorPickerController.Close();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ namespace ConformalDecals.Text {
|
||||
private FontStyles _fontStyle;
|
||||
private bool _vertical;
|
||||
private float _lineSpacing;
|
||||
private float _characterSpacing;
|
||||
private float _charSpacing;
|
||||
|
||||
public FontStyles FontStyle {
|
||||
get => _fontStyle;
|
||||
@ -57,24 +57,22 @@ namespace ConformalDecals.Text {
|
||||
set => _lineSpacing = value;
|
||||
}
|
||||
|
||||
public float CharacterSpacing {
|
||||
get => _characterSpacing;
|
||||
set => _characterSpacing = value;
|
||||
public float CharSpacing {
|
||||
get => _charSpacing;
|
||||
set => _charSpacing = value;
|
||||
}
|
||||
|
||||
|
||||
public DecalTextStyle(FontStyles fontStyle, bool vertical, float lineSpacing, float characterSpacing) {
|
||||
public DecalTextStyle(FontStyles fontStyle, bool vertical, float lineSpacing, float charSpacing) {
|
||||
_fontStyle = fontStyle;
|
||||
_vertical = vertical;
|
||||
_lineSpacing = lineSpacing;
|
||||
_characterSpacing = characterSpacing;
|
||||
_charSpacing = charSpacing;
|
||||
}
|
||||
|
||||
|
||||
public bool Equals(DecalTextStyle other) {
|
||||
return FontStyle == other.FontStyle && Vertical == other.Vertical &&
|
||||
Mathf.Approximately(LineSpacing, other.LineSpacing) &&
|
||||
Mathf.Approximately(CharacterSpacing, other.CharacterSpacing);
|
||||
Mathf.Approximately(CharSpacing, other.CharSpacing);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj) {
|
||||
@ -86,7 +84,7 @@ namespace ConformalDecals.Text {
|
||||
var hashCode = (int) FontStyle;
|
||||
hashCode = (hashCode * 397) ^ Vertical.GetHashCode();
|
||||
hashCode = (hashCode * 397) ^ LineSpacing.GetHashCode();
|
||||
hashCode = (hashCode * 397) ^ CharacterSpacing.GetHashCode();
|
||||
hashCode = (hashCode * 397) ^ CharSpacing.GetHashCode();
|
||||
return hashCode;
|
||||
}
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ namespace ConformalDecals.UI {
|
||||
return controller;
|
||||
}
|
||||
|
||||
public void OnClose() {
|
||||
public void Close() {
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ namespace ConformalDecals.UI {
|
||||
return controller;
|
||||
}
|
||||
|
||||
public void OnClose() {
|
||||
public void Close() {
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,12 @@ namespace ConformalDecals.UI {
|
||||
[SerializeField] private Selectable _textBox;
|
||||
[SerializeField] private Button _fontButton;
|
||||
|
||||
[SerializeField] private Slider _lineSpacingSlider;
|
||||
[SerializeField] private Selectable _lineSpacingTextBox;
|
||||
|
||||
[SerializeField] private Slider _charSpacingSlider;
|
||||
[SerializeField] private Selectable _charSpacingTextBox;
|
||||
|
||||
[SerializeField] private Toggle _boldButton;
|
||||
[SerializeField] private Toggle _italicButton;
|
||||
[SerializeField] private Toggle _underlineButton;
|
||||
@ -24,12 +30,17 @@ namespace ConformalDecals.UI {
|
||||
private string _text;
|
||||
private DecalFont _font;
|
||||
private DecalTextStyle _style;
|
||||
private Vector2 _lineSpacingRange;
|
||||
private Vector2 _charSpacingRange;
|
||||
|
||||
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,
|
||||
Vector2 lineSpacingRange, Vector2 charSpacingRange,
|
||||
UnityAction<string, DecalFont, DecalTextStyle> textUpdateCallback) {
|
||||
|
||||
var window = Instantiate(UILoader.TextEntryPrefab, MainCanvasUtil.MainCanvas.transform, true);
|
||||
window.AddComponent<DragPanel>();
|
||||
@ -39,13 +50,15 @@ namespace ConformalDecals.UI {
|
||||
controller._text = text;
|
||||
controller._font = font;
|
||||
controller._style = style;
|
||||
controller._lineSpacingRange = lineSpacingRange;
|
||||
controller._charSpacingRange = charSpacingRange;
|
||||
controller.onValueChanged.AddListener(textUpdateCallback);
|
||||
|
||||
return controller;
|
||||
}
|
||||
|
||||
public void OnClose() {
|
||||
if (_fontMenu != null) _fontMenu.OnClose();
|
||||
public void Close() {
|
||||
if (_fontMenu != null) _fontMenu.Close();
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
@ -73,6 +86,52 @@ namespace ConformalDecals.UI {
|
||||
OnValueChanged();
|
||||
}
|
||||
|
||||
public void OnLineSpacingUpdate(float value) {
|
||||
if (_ignoreUpdates) return;
|
||||
|
||||
_style.LineSpacing = Mathf.Lerp(_lineSpacingRange.x, _lineSpacingRange.y, value);
|
||||
|
||||
UpdateLineSpacing();
|
||||
OnValueChanged();
|
||||
}
|
||||
|
||||
public void OnLineSpacingUpdate(string text) {
|
||||
if (_ignoreUpdates) return;
|
||||
|
||||
if (float.TryParse(text, out var value)) {
|
||||
_style.LineSpacing = Mathf.Clamp(value, _lineSpacingRange.x, _lineSpacingRange.y);
|
||||
}
|
||||
else {
|
||||
Debug.LogWarning("[ConformalDecals] line spacing value '{text}' could not be parsed.");
|
||||
}
|
||||
|
||||
UpdateLineSpacing();
|
||||
OnValueChanged();
|
||||
}
|
||||
|
||||
public void OnCharSpacingUpdate(float value) {
|
||||
if (_ignoreUpdates) return;
|
||||
|
||||
_style.CharSpacing = Mathf.Lerp(_charSpacingRange.x, _charSpacingRange.y, value);
|
||||
|
||||
UpdateCharSpacing();
|
||||
OnValueChanged();
|
||||
}
|
||||
|
||||
public void OnCharSpacingUpdate(string text) {
|
||||
if (_ignoreUpdates) return;
|
||||
|
||||
if (float.TryParse(text, out var value)) {
|
||||
_style.CharSpacing = Mathf.Clamp(value, _charSpacingRange.x, _charSpacingRange.y);
|
||||
}
|
||||
else {
|
||||
Debug.LogWarning("[ConformalDecals] char spacing value '{text}' could not be parsed.");
|
||||
}
|
||||
|
||||
UpdateCharSpacing();
|
||||
OnValueChanged();
|
||||
}
|
||||
|
||||
public void OnBoldUpdate(bool state) {
|
||||
if (_ignoreUpdates) return;
|
||||
|
||||
@ -85,7 +144,6 @@ namespace ConformalDecals.UI {
|
||||
|
||||
_style.Italic = state;
|
||||
OnValueChanged();
|
||||
|
||||
}
|
||||
|
||||
public void OnUnderlineUpdate(bool state) {
|
||||
@ -93,7 +151,6 @@ namespace ConformalDecals.UI {
|
||||
|
||||
_style.Underline = state;
|
||||
OnValueChanged();
|
||||
|
||||
}
|
||||
|
||||
public void OnSmallCapsUpdate(bool state) {
|
||||
@ -101,7 +158,6 @@ namespace ConformalDecals.UI {
|
||||
|
||||
_style.SmallCaps = state;
|
||||
OnValueChanged();
|
||||
|
||||
}
|
||||
|
||||
public void OnVerticalUpdate(bool state) {
|
||||
@ -118,6 +174,8 @@ namespace ConformalDecals.UI {
|
||||
_font.SetupSample(_fontButton.GetComponentInChildren<TextMeshProUGUI>());
|
||||
|
||||
UpdateStyleButtons();
|
||||
UpdateLineSpacing();
|
||||
UpdateCharSpacing();
|
||||
}
|
||||
|
||||
private void OnValueChanged() {
|
||||
@ -183,5 +241,23 @@ namespace ConformalDecals.UI {
|
||||
|
||||
_ignoreUpdates = false;
|
||||
}
|
||||
|
||||
private void UpdateLineSpacing() {
|
||||
_ignoreUpdates = true;
|
||||
|
||||
_lineSpacingSlider.value = Mathf.InverseLerp(_lineSpacingRange.x, _lineSpacingRange.y, _style.LineSpacing);
|
||||
((TMP_InputField) _lineSpacingTextBox).text = $"{_style.LineSpacing:F1}";
|
||||
|
||||
_ignoreUpdates = false;
|
||||
}
|
||||
|
||||
private void UpdateCharSpacing() {
|
||||
_ignoreUpdates = true;
|
||||
|
||||
_charSpacingSlider.value = Mathf.InverseLerp(_charSpacingRange.x, _charSpacingRange.y, _style.CharSpacing);
|
||||
((TMP_InputField) _charSpacingTextBox).text = $"{_style.CharSpacing:F1}";
|
||||
|
||||
_ignoreUpdates = false;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user