diff options
| author | chai <215380520@qq.com> | 2024-05-19 16:46:27 +0800 |
|---|---|---|
| committer | chai <215380520@qq.com> | 2024-05-19 16:46:27 +0800 |
| commit | 8b1fc7063b387542803c6bc214ccf8acb32870bd (patch) | |
| tree | d310eb99872c8215f1c1f67731ec21f0915cd778 /Thronefall_1_0/GameCode/TFUISlider.cs | |
| parent | 8e13e7e2874adc8982e16d1d2ed2e28d7480b45f (diff) | |
* rename
Diffstat (limited to 'Thronefall_1_0/GameCode/TFUISlider.cs')
| -rw-r--r-- | Thronefall_1_0/GameCode/TFUISlider.cs | 141 |
1 files changed, 0 insertions, 141 deletions
diff --git a/Thronefall_1_0/GameCode/TFUISlider.cs b/Thronefall_1_0/GameCode/TFUISlider.cs deleted file mode 100644 index f48ea9e..0000000 --- a/Thronefall_1_0/GameCode/TFUISlider.cs +++ /dev/null @@ -1,141 +0,0 @@ -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); - } - } -} |
