summaryrefslogtreecommitdiff
path: root/Thronefall_v1.0/Decompile/TFUISlider.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Thronefall_v1.0/Decompile/TFUISlider.cs')
-rw-r--r--Thronefall_v1.0/Decompile/TFUISlider.cs141
1 files changed, 141 insertions, 0 deletions
diff --git a/Thronefall_v1.0/Decompile/TFUISlider.cs b/Thronefall_v1.0/Decompile/TFUISlider.cs
new file mode 100644
index 0000000..f48ea9e
--- /dev/null
+++ b/Thronefall_v1.0/Decompile/TFUISlider.cs
@@ -0,0 +1,141 @@
+using MPUIKIT;
+using Rewired;
+using TMPro;
+using UnityEngine;
+using UnityEngine.Events;
+
+public class TFUISlider : MonoBehaviour
+{
+ public float minValue;
+
+ public float maxValue = 1f;
+
+ public float value = 1f;
+
+ public float increments = 0.1f;
+
+ public int displayFPPrecision = 1;
+
+ public ThronefallUIElement target;
+
+ public ThronefallUIElement.NavigationDirection increase;
+
+ public ThronefallUIElement.NavigationDirection decrease = ThronefallUIElement.NavigationDirection.Left;
+
+ public TextMeshProUGUI display;
+
+ public GameObject knob;
+
+ public GameObject tooltip;
+
+ public RectTransform backgroundRect;
+
+ public RectTransform fillRect;
+
+ public MPImageBasic fillImg;
+
+ public MPImageBasic knobImg;
+
+ public UnityEvent onChange;
+
+ public UnityEvent onNavigate;
+
+ private Player input;
+
+ private void Start()
+ {
+ target.onEmptyNavigate.AddListener(Navigate);
+ target.onSelectionStateChange.AddListener(ToggleSelectionUI);
+ input = ReInput.players.GetPlayer(0);
+ }
+
+ private void OnEnable()
+ {
+ ToggleSelectionUI();
+ }
+
+ private void UpdateDisplay()
+ {
+ fillRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, backgroundRect.sizeDelta.x * Mathf.InverseLerp(minValue, maxValue, value));
+ display.text = value.ToString("F" + displayFPPrecision);
+ }
+
+ public void Navigate(ThronefallUIElement.NavigationDirection direction)
+ {
+ onNavigate.Invoke();
+ if (direction == increase)
+ {
+ value += increments;
+ }
+ else if (direction == decrease)
+ {
+ value -= increments;
+ }
+ if (value > maxValue)
+ {
+ value = maxValue;
+ }
+ if (value < minValue)
+ {
+ value = minValue;
+ }
+ UpdateDisplay();
+ onChange.Invoke();
+ }
+
+ public void Increase()
+ {
+ Navigate(increase);
+ }
+
+ public void Decrease()
+ {
+ Navigate(decrease);
+ }
+
+ public void OnTFUIStateChange()
+ {
+ }
+
+ public void SetValue(float v)
+ {
+ value = v;
+ if (value > maxValue)
+ {
+ value = maxValue;
+ }
+ if (value < minValue)
+ {
+ value = minValue;
+ }
+ UpdateDisplay();
+ }
+
+ public void SetValueByScreenPoint(Vector2 point)
+ {
+ RectTransformUtility.ScreenPointToLocalPointInRectangle(fillRect, input.controllers.Mouse.screenPosition, null, out point);
+ if (point.x < 0f)
+ {
+ point.x = 0f;
+ }
+ if (point.x > backgroundRect.sizeDelta.x)
+ {
+ point.x = backgroundRect.sizeDelta.x;
+ }
+ float t = Mathf.InverseLerp(0f, backgroundRect.sizeDelta.x, point.x);
+ int num = Mathf.RoundToInt(Mathf.Lerp(minValue, maxValue, t) / increments);
+ value = increments * (float)num;
+ UpdateDisplay();
+ onChange.Invoke();
+ }
+
+ private void ToggleSelectionUI()
+ {
+ bool active = target.CurrentState == ThronefallUIElement.SelectionState.FocussedAndSelected || target.CurrentState == ThronefallUIElement.SelectionState.Selected;
+ knob.SetActive(active);
+ if (tooltip != null)
+ {
+ tooltip.SetActive(active);
+ }
+ }
+}