summaryrefslogtreecommitdiff
path: root/Thronefall_v1.0/Decompile/NightscoreUI.cs
blob: 7150c48445289066cbf1b0198d2bfde9d2933bfd (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
using System.Collections;
using I2.Loc;
using MPUIKIT;
using TMPro;
using UnityEngine;

public class NightscoreUI : MonoBehaviour
{
	public GameObject nightScorePanel;

	public TextMeshProUGUI baseScore;

	public TextMeshProUGUI timeBonus;

	public TextMeshProUGUI protectionPercentage;

	public TextMeshProUGUI protectionScore;

	public TextMeshProUGUI overallScore;

	public AudioSource pointSFXSource;

	[Header("ANIMATION")]
	public MPImage backgroundImage;

	public RectTransform content;

	public RectTransform nightSurviveText;

	public RectTransform nightSurviveNumber;

	public RectTransform timeText;

	public RectTransform timeNumber;

	public RectTransform protectionText;

	public RectTransform protectionNumber;

	public RectTransform overallScoreBG;

	public RectTransform overallScoreNumber;

	public AnimationCurve popCurve;

	public AnimationCurve expandCurve;

	public AnimationCurve bumpCurve;

	public AnimationCurve simpleQuad;

	public static NightscoreUI instance;

	private float initialWaitTime = 3f;

	private float completeWaitTime = 3f;

	private float buildUpSFXVol = 0.8f;

	private float clock;

	private bool shown;

	private void Awake()
	{
		instance = this;
	}

	private void Start()
	{
		nightScorePanel.SetActive(value: false);
		ScoreManager.Instance.OnNightScoreAdd.AddListener(ShowNightScore);
		UIFrameManager.instance.onFrameOpen.AddListener(StopPointFillSoundOnPause);
	}

	private void StopPointFillSoundOnPause()
	{
		pointSFXSource.Stop();
	}

	public void ShowNightScore(int _baseScore, int _timeBonus, float _protectionPercentage, int _protectionBonus)
	{
		if (EnemySpawner.instance.Wavenumber < EnemySpawner.instance.waves.Count - 1)
		{
			shown = true;
			StopAllCoroutines();
			clock = 0f;
			StartCoroutine(PlayPopUpAnimation(_baseScore, _timeBonus, _protectionPercentage, _protectionBonus));
		}
	}

	public void HideNightScore()
	{
		shown = false;
		pointSFXSource.Stop();
		StopAllCoroutines();
		StartCoroutine(PlayHideAnimation());
	}

	private IEnumerator PlayPopUpAnimation(int basescore, int timebonus, float protectionpercent, int protectionbonus)
	{
		nightScorePanel.SetActive(value: true);
		Vector2 contentSizeDelta = content.sizeDelta;
		int currentScore = ScoreManager.Instance.CurrentScore - basescore - timebonus - protectionbonus;
		int nextScore = currentScore;
		baseScore.text = "+" + basescore;
		timeBonus.text = "+" + timebonus;
		protectionPercentage.text = LocalizationManager.GetTranslation("Menu/Realm") + " " + Mathf.RoundToInt(protectionpercent * 100f) + "% " + LocalizationManager.GetTranslation("Menu/Protected");
		protectionScore.text = "+" + protectionbonus;
		overallScore.text = currentScore.ToString();
		contentSizeDelta.y = 0f;
		content.sizeDelta = contentSizeDelta;
		nightSurviveText.localScale = Vector3.zero;
		nightSurviveNumber.localScale = Vector3.zero;
		timeText.localScale = Vector3.zero;
		timeNumber.localScale = Vector3.zero;
		protectionText.localScale = Vector3.zero;
		protectionNumber.localScale = Vector3.zero;
		overallScoreBG.localScale = Vector3.zero;
		overallScoreNumber.localScale = Vector3.zero;
		yield return new WaitForSeconds(initialWaitTime);
		float animTime2 = 0.5f;
		float timer2 = 0f;
		while (timer2 < animTime2)
		{
			timer2 += Time.deltaTime;
			overallScoreBG.localScale = Vector3.one * popCurve.Evaluate(Mathf.InverseLerp(0f, animTime2, timer2));
			overallScoreNumber.localScale = Vector3.one * popCurve.Evaluate(Mathf.InverseLerp(0f, animTime2, timer2));
			yield return null;
		}
		overallScoreBG.localScale = Vector3.one;
		overallScoreNumber.localScale = Vector3.one;
		yield return new WaitForSeconds(0.25f);
		pointSFXSource.PlayOneShot(ThronefallAudioManager.Instance.audioContent.PointScreenBuildB, buildUpSFXVol);
		animTime2 = 0.5f;
		timer2 = 0f;
		while (timer2 < animTime2)
		{
			timer2 += Time.deltaTime;
			content.sizeDelta = contentSizeDelta + Vector2.up * 55f * expandCurve.Evaluate(Mathf.InverseLerp(0f, animTime2, timer2));
			yield return null;
		}
		content.sizeDelta = contentSizeDelta + Vector2.up * 55f;
		contentSizeDelta = content.sizeDelta;
		pointSFXSource.PlayOneShot(ThronefallAudioManager.Instance.audioContent.PointScreenBuildC, buildUpSFXVol);
		animTime2 = 0.5f;
		timer2 = 0f;
		while (timer2 < animTime2)
		{
			timer2 += Time.deltaTime;
			nightSurviveText.localScale = Vector3.one * popCurve.Evaluate(Mathf.InverseLerp(0f, animTime2, timer2));
			nightSurviveNumber.localScale = Vector3.one * popCurve.Evaluate(Mathf.InverseLerp(0f, animTime2, timer2));
			yield return null;
		}
		nightSurviveText.localScale = Vector3.one;
		nightSurviveNumber.localScale = Vector3.one;
		pointSFXSource.PlayOneShot(ThronefallAudioManager.Instance.audioContent.PointScreenBuildB, buildUpSFXVol);
		animTime2 = 0.5f;
		timer2 = 0f;
		while (timer2 < animTime2)
		{
			timer2 += Time.deltaTime;
			content.sizeDelta = contentSizeDelta + Vector2.up * 30f * expandCurve.Evaluate(Mathf.InverseLerp(0f, animTime2, timer2));
			yield return null;
		}
		content.sizeDelta = contentSizeDelta + Vector2.up * 30f;
		contentSizeDelta = content.sizeDelta;
		pointSFXSource.PlayOneShot(ThronefallAudioManager.Instance.audioContent.PointScreenBuildC, buildUpSFXVol);
		animTime2 = 0.5f;
		timer2 = 0f;
		while (timer2 < animTime2)
		{
			timer2 += Time.deltaTime;
			protectionText.localScale = Vector3.one * popCurve.Evaluate(Mathf.InverseLerp(0f, animTime2, timer2));
			protectionNumber.localScale = Vector3.one * popCurve.Evaluate(Mathf.InverseLerp(0f, animTime2, timer2));
			yield return null;
		}
		protectionText.localScale = Vector3.one;
		protectionNumber.localScale = Vector3.one;
		pointSFXSource.PlayOneShot(ThronefallAudioManager.Instance.audioContent.PointScreenBuildB, buildUpSFXVol);
		animTime2 = 0.5f;
		timer2 = 0f;
		while (timer2 < animTime2)
		{
			timer2 += Time.deltaTime;
			content.sizeDelta = contentSizeDelta + Vector2.up * 30f * expandCurve.Evaluate(Mathf.InverseLerp(0f, animTime2, timer2));
			yield return null;
		}
		content.sizeDelta = contentSizeDelta + Vector2.up * 30f;
		_ = content.sizeDelta;
		pointSFXSource.PlayOneShot(ThronefallAudioManager.Instance.audioContent.PointScreenBuildC, buildUpSFXVol);
		animTime2 = 0.5f;
		timer2 = 0f;
		while (timer2 < animTime2)
		{
			timer2 += Time.deltaTime;
			timeText.localScale = Vector3.one * popCurve.Evaluate(Mathf.InverseLerp(0f, animTime2, timer2));
			timeNumber.localScale = Vector3.one * popCurve.Evaluate(Mathf.InverseLerp(0f, animTime2, timer2));
			yield return null;
		}
		timeText.localScale = Vector3.one;
		timeNumber.localScale = Vector3.one;
		pointSFXSource.Play();
		animTime2 = 1.5f;
		timer2 = 0f;
		nextScore += basescore + protectionbonus + timebonus;
		while (timer2 < animTime2)
		{
			timer2 += Time.deltaTime;
			overallScore.text = Mathf.RoundToInt(Mathf.Lerp(currentScore, nextScore, Mathf.InverseLerp(0f, animTime2, timer2))).ToString();
			yield return null;
		}
		currentScore = nextScore;
		overallScore.text = currentScore.ToString();
		pointSFXSource.Stop();
		pointSFXSource.PlayOneShot(ThronefallAudioManager.Instance.audioContent.PointLockInMinor);
		animTime2 = 0.5f;
		timer2 = 0f;
		while (timer2 < animTime2)
		{
			timer2 += Time.deltaTime;
			overallScoreBG.localScale = Vector3.one * bumpCurve.Evaluate(Mathf.InverseLerp(0f, animTime2, timer2));
			yield return null;
		}
		overallScoreBG.localScale = Vector3.one;
		yield return new WaitForSeconds(completeWaitTime);
		HideNightScore();
	}

	private IEnumerator PlayHideAnimation()
	{
		pointSFXSource.PlayOneShot(ThronefallAudioManager.Instance.audioContent.PointScreenBuildB, buildUpSFXVol);
		Vector2 contentSizeDelta3 = content.sizeDelta;
		nightSurviveText.localScale = Vector3.one;
		nightSurviveNumber.localScale = Vector3.one;
		timeText.localScale = Vector3.one;
		timeNumber.localScale = Vector3.one;
		protectionText.localScale = Vector3.one;
		protectionNumber.localScale = Vector3.one;
		overallScoreBG.localScale = Vector3.one;
		overallScoreNumber.localScale = Vector3.one;
		timeText.localScale = Vector3.zero;
		timeNumber.localScale = Vector3.zero;
		float animTime4 = 0.4f;
		float timer4 = 0f;
		while (timer4 < animTime4)
		{
			timer4 += Time.deltaTime;
			content.sizeDelta = contentSizeDelta3 - Vector2.up * 30f * expandCurve.Evaluate(Mathf.InverseLerp(0f, animTime4, timer4));
			yield return null;
		}
		content.sizeDelta = contentSizeDelta3 - Vector2.up * 30f;
		contentSizeDelta3 = content.sizeDelta;
		protectionText.localScale = Vector3.zero;
		protectionNumber.localScale = Vector3.zero;
		animTime4 = 0.4f;
		timer4 = 0f;
		while (timer4 < animTime4)
		{
			timer4 += Time.deltaTime;
			content.sizeDelta = contentSizeDelta3 - Vector2.up * 30f * expandCurve.Evaluate(Mathf.InverseLerp(0f, animTime4, timer4));
			yield return null;
		}
		content.sizeDelta = contentSizeDelta3 - Vector2.up * 30f;
		contentSizeDelta3 = content.sizeDelta;
		nightSurviveText.localScale = Vector3.zero;
		nightSurviveNumber.localScale = Vector3.zero;
		animTime4 = 0.4f;
		timer4 = 0f;
		while (timer4 < animTime4)
		{
			timer4 += Time.deltaTime;
			if (Mathf.InverseLerp(0f, animTime4, timer4) > 0.425f)
			{
				backgroundImage.enabled = false;
			}
			content.sizeDelta = contentSizeDelta3 - Vector2.up * 55f * expandCurve.Evaluate(Mathf.InverseLerp(0f, animTime4, timer4));
			yield return null;
		}
		content.sizeDelta = contentSizeDelta3 - Vector2.up * 55f;
		backgroundImage.enabled = true;
		animTime4 = 0.2f;
		timer4 = 0f;
		while (timer4 < animTime4)
		{
			timer4 += Time.deltaTime;
			overallScoreNumber.localScale = Vector3.one * simpleQuad.Evaluate(Mathf.InverseLerp(animTime4, 0f, timer4));
			overallScoreBG.localScale = Vector3.one * simpleQuad.Evaluate(Mathf.InverseLerp(animTime4, 0f, timer4));
			yield return null;
		}
		overallScoreNumber.localScale = Vector3.zero;
		overallScoreBG.localScale = Vector2.zero;
		nightScorePanel.SetActive(value: false);
	}
}