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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
using System;
using MPUIKIT;
using UnityEngine;
using UnityEngine.UI;
public class TFUIUpgradeChoice : ThronefallUIElement
{
[Serializable]
public class Style
{
public float scale = 1f;
public Color outlineColor;
public Color bgColor;
public AnimationCurve animationCurve = AnimationCurve.EaseInOut(0f, 0f, 1f, 1f);
public float animationDuration = 0.5f;
public Style(Color outlineColor, Color bgColor, AnimationCurve animationCurve, float animationDuration, float scale)
{
this.scale = scale;
this.bgColor = bgColor;
this.outlineColor = outlineColor;
this.animationCurve = animationCurve;
this.animationDuration = animationDuration;
}
}
public class Animation
{
public TFUIUpgradeChoice target;
public Style startStyle;
public Style endStyle;
public float clock;
public Animation(Style startStyle, Style endStyle, TFUIUpgradeChoice target)
{
this.startStyle = startStyle;
this.endStyle = endStyle;
this.target = target;
target.ApplyStyle(startStyle);
target.currentAnimation = this;
}
public void Tick()
{
clock += Time.unscaledDeltaTime;
float num = Mathf.InverseLerp(0f, endStyle.animationDuration, clock);
float t = endStyle.animationCurve.Evaluate(num);
target.iconImg.color = Color.Lerp(startStyle.outlineColor, endStyle.outlineColor, t);
target.backgroundImg.color = Color.Lerp(startStyle.bgColor, endStyle.bgColor, t);
target.backgroundImg.OutlineColor = Color.Lerp(startStyle.outlineColor, endStyle.outlineColor, t);
target.backgroundImg.transform.localScale = Vector3.one * Mathf.LerpUnclamped(startStyle.scale, endStyle.scale, t);
if (num >= 1f)
{
target.ApplyStyle(endStyle);
target.currentAnimation = null;
}
}
}
[SerializeField]
private Color lockedBgColor;
[SerializeField]
private Color lockedOutlineColor;
[SerializeField]
private MPImageBasic backgroundImg;
[SerializeField]
private Image iconImg;
[SerializeField]
private Sprite lockIcon;
public AnimationCurve defaultAnimationCurve = AnimationCurve.EaseInOut(0f, 0f, 1f, 1f);
public float defaultAnimationTime = 0.3f;
public Style focussedStyle;
public Style selectedStyle;
public Style focussedAndSelectedStyle;
private Style defaultStyle;
private bool defaultStyleInitialized;
private Animation currentAnimation;
private Choice choiceData;
private Color defaultBgColor;
private Color defaultIconColor;
private bool locked;
public Choice Data => choiceData;
public bool Locked => locked;
public Image IconImg => iconImg;
private void Update()
{
if (currentAnimation != null)
{
currentAnimation.Tick();
}
}
protected override void OnApply()
{
}
protected override void OnClear()
{
new Animation(GetStyle(previousState), defaultStyle, this);
}
protected override void OnFocus()
{
new Animation(GetStyle(previousState), focussedStyle, this);
}
protected override void OnSelect()
{
new Animation(GetStyle(previousState), selectedStyle, this);
}
protected override void OnFocusAndSelect()
{
new Animation(GetStyle(previousState), focussedAndSelectedStyle, this);
}
protected override void OnHardStateSet(SelectionState selectionState)
{
currentAnimation = null;
ApplyStyle(GetStyle(selectionState));
}
protected Style GetStyle(SelectionState state)
{
if (!defaultStyleInitialized)
{
InitializeDefaultStyle();
}
return state switch
{
SelectionState.Default => defaultStyle,
SelectionState.Focussed => focussedStyle,
SelectionState.Selected => selectedStyle,
SelectionState.FocussedAndSelected => focussedAndSelectedStyle,
_ => defaultStyle,
};
}
private void ApplyStyle(Style style)
{
iconImg.color = style.outlineColor;
backgroundImg.color = style.bgColor;
backgroundImg.OutlineColor = style.outlineColor;
backgroundImg.transform.localScale = Vector3.one * style.scale;
}
private void InitializeDefaultStyle()
{
defaultBgColor = backgroundImg.color;
defaultIconColor = iconImg.color;
defaultStyle = new Style(backgroundImg.OutlineColor, backgroundImg.color, defaultAnimationCurve, defaultAnimationTime, 1f);
defaultStyleInitialized = true;
}
public void SetData(Choice _choice)
{
choiceData = _choice;
bool flag = true;
if (_choice.requiresUnlocked != null && !PerkManager.instance.UnlockedEquippables.Contains(_choice.requiresUnlocked))
{
flag = false;
}
if (flag)
{
iconImg.sprite = _choice.icon;
return;
}
iconImg.sprite = lockIcon;
iconImg.color = lockedOutlineColor;
backgroundImg.color = lockedBgColor;
backgroundImg.OutlineColor = lockedOutlineColor;
selectedStyle.bgColor = lockedBgColor;
selectedStyle.outlineColor = lockedOutlineColor;
locked = true;
}
}
|