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:
parent
93c3ff8a49
commit
f3aea02da7
@ -10,7 +10,7 @@ namespace ConformalDecals.UI {
|
||||
[SerializeField] private Image _previewImage;
|
||||
[SerializeField] private Selectable _hexTextBox;
|
||||
|
||||
public void OnClose() { }
|
||||
public void Close() { }
|
||||
|
||||
public void OnHexColorUpdate(string text) { }
|
||||
}
|
||||
|
@ -5,6 +5,6 @@ namespace ConformalDecals.UI {
|
||||
[SerializeField] private GameObject _menuItem;
|
||||
[SerializeField] private GameObject _menuList;
|
||||
|
||||
public void OnClose() { }
|
||||
public void Close() { }
|
||||
}
|
||||
}
|
@ -5,24 +5,29 @@ namespace ConformalDecals.UI {
|
||||
public class TextEntryController : MonoBehaviour {
|
||||
[SerializeField] private Selectable _textBox;
|
||||
[SerializeField] private Button _fontButton;
|
||||
[SerializeField] private Slider _outlineWidthSlider;
|
||||
|
||||
[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;
|
||||
[SerializeField] private Toggle _smallCapsButton;
|
||||
[SerializeField] private Toggle _verticalButton;
|
||||
|
||||
public void OnClose() { }
|
||||
public void Close() { }
|
||||
|
||||
public void OnTextUpdate(string text) { }
|
||||
|
||||
public void OnFontMenu() { }
|
||||
public void OnColorMenu() { }
|
||||
public void OnOutlineColorMenu() { }
|
||||
|
||||
public void OnOutlineUpdate(float value) { }
|
||||
|
||||
public void OnLineSpacingUpdate(float value) { }
|
||||
public void OnLineSpacingUpdate(string text) { }
|
||||
public void OnCharSpacingUpdate(float value) { }
|
||||
public void OnCharSpacingUpdate(string text) { }
|
||||
public void OnBoldUpdate(bool state) { }
|
||||
public void OnItalicUpdate(bool state) { }
|
||||
public void OnUnderlineUpdate(bool state) { }
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 8.4 KiB After Width: | Height: | Size: 6.2 KiB |
@ -303,7 +303,7 @@ MonoBehaviour:
|
||||
m_fontStyle: 0
|
||||
m_textAlignment: 257
|
||||
m_isAlignmentEnumConverted: 1
|
||||
m_characterSpacing: 0
|
||||
m_characterSpacing: 5
|
||||
m_wordSpacing: 0
|
||||
m_lineSpacing: 0
|
||||
m_lineSpacingMax: 0
|
||||
@ -778,8 +778,8 @@ RectTransform:
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0, y: 0}
|
||||
m_AnchorMax: {x: 0, y: 0}
|
||||
m_AnchoredPosition: {x: 100, y: 0}
|
||||
m_SizeDelta: {x: 184, y: 0}
|
||||
m_AnchoredPosition: {x: 0, y: 0}
|
||||
m_SizeDelta: {x: 0, y: 0}
|
||||
m_Pivot: {x: 0.5, y: 1}
|
||||
--- !u!114 &1102500227528487793
|
||||
MonoBehaviour:
|
||||
@ -4189,7 +4189,7 @@ RectTransform:
|
||||
m_AnchorMin: {x: 0, y: 0}
|
||||
m_AnchorMax: {x: 1, y: 1}
|
||||
m_AnchoredPosition: {x: 58, y: 0}
|
||||
m_SizeDelta: {x: -124, y: 0}
|
||||
m_SizeDelta: {x: -124, y: -2}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!222 &1102500229012921285
|
||||
CanvasRenderer:
|
||||
@ -5142,7 +5142,7 @@ MonoBehaviour:
|
||||
m_PersistentCalls:
|
||||
m_Calls:
|
||||
- m_Target: {fileID: 2127733108409970602}
|
||||
m_MethodName: OnClose
|
||||
m_MethodName: Close
|
||||
m_Mode: 1
|
||||
m_Arguments:
|
||||
m_ObjectArgument: {fileID: 0}
|
||||
|
@ -198,7 +198,7 @@ MonoBehaviour:
|
||||
m_PersistentCalls:
|
||||
m_Calls:
|
||||
- m_Target: {fileID: 8967514022049253907}
|
||||
m_MethodName: OnClose
|
||||
m_MethodName: Close
|
||||
m_Mode: 1
|
||||
m_Arguments:
|
||||
m_ObjectArgument: {fileID: 0}
|
||||
@ -632,10 +632,10 @@ RectTransform:
|
||||
m_Father: {fileID: 6167128440300046879}
|
||||
m_RootOrder: 1
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0, y: 1}
|
||||
m_AnchorMax: {x: 0, y: 1}
|
||||
m_AnchoredPosition: {x: 125, y: -32}
|
||||
m_SizeDelta: {x: 234, y: 0}
|
||||
m_AnchorMin: {x: 0, y: 0}
|
||||
m_AnchorMax: {x: 0, y: 0}
|
||||
m_AnchoredPosition: {x: 150, y: 0}
|
||||
m_SizeDelta: {x: 284, y: 0}
|
||||
m_Pivot: {x: 0.5, y: 1}
|
||||
--- !u!114 &6074357789468271286
|
||||
MonoBehaviour:
|
||||
|
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@ -1,3 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:fe7efdec2d12a1bad8b4661cbb53b092d8082c2a704bb7c2cf18e5c9ab555184
|
||||
size 364850
|
||||
oid sha256:4812aa47676df9378cf10c393f50aa7717018bff8605c592cc3b0fba4b241eaf
|
||||
size 364943
|
||||
|
Binary file not shown.
Binary file not shown.
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user