summaryrefslogtreecommitdiff
path: root/Thronefall_v1.0/Decompile/TFUIEquippable.cs
blob: bb746923ce641f8b27f6f475bb68d75bd0e14a44 (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
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
using System;
using MPUIKIT;
using UnityEngine;
using UnityEngine.UI;

public class TFUIEquippable : ThronefallUIElement
{
	[Serializable]
	public class Style
	{
		public float scale = 1f;

		public Color outlineColor;

		public AnimationCurve animationCurve = AnimationCurve.EaseInOut(0f, 0f, 1f, 1f);

		public float animationDuration = 0.5f;

		public Style(Color outlineColor, AnimationCurve animationCurve, float animationDuration, float scale)
		{
			this.scale = scale;
			this.outlineColor = outlineColor;
			this.animationCurve = animationCurve;
			this.animationDuration = animationDuration;
		}
	}

	public class Animation
	{
		public TFUIEquippable target;

		public Style startStyle;

		public Style endStyle;

		public float clock;

		public Animation(Style startStyle, Style endStyle, TFUIEquippable 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.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 weaponBgColor;

	[SerializeField]
	private Color perkBgColor;

	[SerializeField]
	private Color mutatorBgColor;

	[SerializeField]
	private Color lockedBgColor;

	[SerializeField]
	private Color lockedOutlineColor;

	[SerializeField]
	private Color weaponHighlightColor;

	[SerializeField]
	private Color perkHightlightColor;

	[SerializeField]
	private Color mutatorHighlightColor;

	[SerializeField]
	private Color highlightIconColor;

	[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 bool selectedForLoadout;

	private Animation currentAnimation;

	private Equippable equippableData;

	private Color highlightBGColor;

	private Color defaultBGColor;

	private Color defaultIconColor;

	private bool locked;

	public Equippable Data => equippableData;

	private bool isWeapon => equippableData is EquippableWeapon;

	private bool isPerk => equippableData is EquippablePerk;

	private bool isMutator => equippableData is EquippableMutation;

	public bool Locked => locked;

	public Image IconImg => iconImg;

	public Color GetBackgroundColor
	{
		get
		{
			if (!selectedForLoadout)
			{
				return defaultBGColor;
			}
			return highlightBGColor;
		}
	}

	public Color GetIconColor
	{
		get
		{
			if (!selectedForLoadout)
			{
				return defaultIconColor;
			}
			return highlightIconColor;
		}
	}

	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)
	{
		backgroundImg.OutlineColor = style.outlineColor;
		backgroundImg.transform.localScale = Vector3.one * style.scale;
	}

	private void InitializeDefaultStyle()
	{
		defaultStyle = new Style(backgroundImg.OutlineColor, defaultAnimationCurve, defaultAnimationTime, 1f);
		defaultStyleInitialized = true;
	}

	public void SetData(Equippable e)
	{
		equippableData = e;
		bool flag = PerkManager.instance.UnlockedEquippables.Contains(e);
		bool flag2 = LevelInteractor.lastActivatedLevelInteractor.HasFixedLoadout && !LevelInteractor.lastActivatedLevelInteractor.fixedLoadout.Contains(e);
		if (flag && !flag2)
		{
			iconImg.sprite = e.icon;
			if (isWeapon)
			{
				backgroundImg.color = weaponBgColor;
				highlightBGColor = weaponHighlightColor;
			}
			if (isPerk)
			{
				backgroundImg.color = perkBgColor;
				highlightBGColor = perkHightlightColor;
			}
			if (isMutator)
			{
				backgroundImg.color = mutatorBgColor;
				highlightBGColor = mutatorHighlightColor;
			}
		}
		else if (flag && flag2)
		{
			iconImg.sprite = e.icon;
			iconImg.color = lockedOutlineColor;
			backgroundImg.color = lockedBgColor;
			backgroundImg.OutlineColor = lockedOutlineColor;
		}
		else
		{
			iconImg.sprite = lockIcon;
			iconImg.color = lockedOutlineColor;
			backgroundImg.color = lockedBgColor;
			backgroundImg.OutlineColor = lockedOutlineColor;
			locked = true;
		}
		defaultBGColor = backgroundImg.color;
		defaultIconColor = iconImg.color;
	}

	public void SetDataSimple(Equippable e)
	{
		equippableData = e;
		iconImg.sprite = e.icon;
		if (isWeapon)
		{
			backgroundImg.color = weaponBgColor;
			highlightBGColor = weaponHighlightColor;
		}
		if (isPerk)
		{
			backgroundImg.color = perkBgColor;
			highlightBGColor = perkHightlightColor;
		}
		if (isMutator)
		{
			backgroundImg.color = mutatorBgColor;
			highlightBGColor = mutatorHighlightColor;
		}
		defaultBGColor = backgroundImg.color;
		defaultIconColor = iconImg.color;
	}

	public void Pick()
	{
		backgroundImg.color = highlightBGColor;
		iconImg.color = highlightIconColor;
		selectedForLoadout = true;
	}

	public void UnPick()
	{
		backgroundImg.color = defaultBGColor;
		iconImg.color = defaultIconColor;
		selectedForLoadout = false;
	}
}