blob: f48ea9e831769dab41d8888b5173ee648787f3bc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
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);
}
}
}
|