summaryrefslogtreecommitdiff
path: root/GameCode/PointVisualizer.cs
blob: dc2e55b8199efe21e1d7d839d0d7c28703402b20 (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
using System.Collections;
using Sirenix.OdinInspector;
using Sonigon;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class PointVisualizer : MonoBehaviour
{
	public SoundEvent soundWinRound;

	public SoundEvent sound_UI_Arms_Race_A_Ball_Shrink_Go_To_Left_Corner;

	public SoundEvent sound_UI_Arms_Race_B_Ball_Go_Down_Then_Expand;

	public SoundEvent sound_UI_Arms_Race_C_Ball_Pop_Shake;

	public static PointVisualizer instance;

	public AnimationCurve moveCurve;

	public AnimationCurve scaleCurve;

	public float timeBetween;

	public float timeToMove = 0.2f;

	public float timeToScale = 0.2f;

	public TextMeshProUGUI text;

	public GameObject bg;

	public Transform orangeBall;

	public Transform blueBall;

	private RectTransform orangeBallRT;

	private RectTransform blueBallRT;

	public Image orangeFill;

	public Image blueFill;

	private Vector3 orangeVel;

	private Vector3 blueVel;

	private Vector3 orangeSP;

	private Vector3 blueSP;

	private float ballBaseSize = 200f;

	private float ballSmallSize = 20f;

	private float bigBallScale = 900f;

	private void Awake()
	{
		instance = this;
	}

	private void Start()
	{
		orangeBallRT = orangeBall.GetComponent<RectTransform>();
		blueBallRT = blueBall.GetComponent<RectTransform>();
		orangeSP = orangeBall.GetComponent<RectTransform>().anchoredPosition;
		blueSP = blueBall.GetComponent<RectTransform>().anchoredPosition;
		Close();
	}

	[Button]
	private void TestWinSequence()
	{
		StartCoroutine(DoWinSequence(2, 1, 2, 1, orangeWinner: true));
	}

	[Button]
	private void TestPoint()
	{
		StartCoroutine(DoSequence(1, 0, orangeWinner: true));
	}

	[Button]
	private void Reset()
	{
		StartCoroutine(DoSequence(0, 0, orangeWinner: true));
	}

	public void ResetPoints()
	{
		orangeFill.fillAmount = 0f;
		blueFill.fillAmount = 0f;
	}

	private void ResetBalls()
	{
		orangeBallRT.sizeDelta = Vector2.one * ballBaseSize;
		blueBallRT.sizeDelta = Vector2.one * ballBaseSize;
		orangeBall.GetComponent<RectTransform>().anchoredPosition = orangeSP;
		blueBall.GetComponent<RectTransform>().anchoredPosition = blueSP;
		orangeVel = Vector3.zero;
		blueVel = Vector3.zero;
	}

	public IEnumerator DoWinSequence(int orangePoints, int bluePoints, int orangeRounds, int blueRounds, bool orangeWinner)
	{
		yield return new WaitForSecondsRealtime(0.35f);
		SoundManager.Instance.Play(soundWinRound, base.transform);
		ResetBalls();
		bg.SetActive(value: true);
		blueBall.gameObject.SetActive(value: true);
		orangeBall.gameObject.SetActive(value: true);
		yield return new WaitForSecondsRealtime(0.2f);
		GamefeelManager.instance.AddUIGameFeelOverTime(10f, 0.1f);
		DoShowPoints(orangePoints, bluePoints, orangeWinner);
		yield return new WaitForSecondsRealtime(0.35f);
		SoundManager.Instance.Play(sound_UI_Arms_Race_A_Ball_Shrink_Go_To_Left_Corner, base.transform);
		float c3 = 0f;
		while (c3 < timeToScale)
		{
			if (orangeWinner)
			{
				orangeBallRT.sizeDelta = Vector2.LerpUnclamped(orangeBallRT.sizeDelta, Vector2.one * ballSmallSize, scaleCurve.Evaluate(c3 / timeToScale));
			}
			else
			{
				blueBallRT.sizeDelta = Vector2.LerpUnclamped(blueBallRT.sizeDelta, Vector2.one * ballSmallSize, scaleCurve.Evaluate(c3 / timeToScale));
			}
			c3 += Time.unscaledDeltaTime;
			yield return null;
		}
		yield return new WaitForSecondsRealtime(timeBetween);
		c3 = 0f;
		while (c3 < timeToMove)
		{
			if (orangeWinner)
			{
				orangeBall.position = Vector3.LerpUnclamped(orangeBall.position, UIHandler.instance.roundCounterSmall.GetPointPos(0), scaleCurve.Evaluate(c3 / timeToMove));
			}
			else
			{
				blueBall.position = Vector3.LerpUnclamped(blueBall.position, UIHandler.instance.roundCounterSmall.GetPointPos(1), scaleCurve.Evaluate(c3 / timeToMove));
			}
			c3 += Time.unscaledDeltaTime;
			yield return null;
		}
		SoundManager.Instance.Play(sound_UI_Arms_Race_B_Ball_Go_Down_Then_Expand, base.transform);
		if (orangeWinner)
		{
			orangeBall.position = UIHandler.instance.roundCounterSmall.GetPointPos(0);
		}
		else
		{
			blueBall.position = UIHandler.instance.roundCounterSmall.GetPointPos(1);
		}
		yield return new WaitForSecondsRealtime(timeBetween);
		c3 = 0f;
		while (c3 < timeToMove)
		{
			if (!orangeWinner)
			{
				orangeBall.position = Vector3.LerpUnclamped(orangeBall.position, CardChoiceVisuals.instance.transform.position, scaleCurve.Evaluate(c3 / timeToMove));
			}
			else
			{
				blueBall.position = Vector3.LerpUnclamped(blueBall.position, CardChoiceVisuals.instance.transform.position, scaleCurve.Evaluate(c3 / timeToMove));
			}
			c3 += Time.unscaledDeltaTime;
			yield return null;
		}
		if (!orangeWinner)
		{
			orangeBall.position = CardChoiceVisuals.instance.transform.position;
		}
		else
		{
			blueBall.position = CardChoiceVisuals.instance.transform.position;
		}
		yield return new WaitForSecondsRealtime(timeBetween);
		c3 = 0f;
		while (c3 < timeToScale)
		{
			if (!orangeWinner)
			{
				orangeBallRT.sizeDelta = Vector2.LerpUnclamped(orangeBallRT.sizeDelta, Vector2.one * bigBallScale, scaleCurve.Evaluate(c3 / timeToScale));
			}
			else
			{
				blueBallRT.sizeDelta = Vector2.LerpUnclamped(blueBallRT.sizeDelta, Vector2.one * bigBallScale, scaleCurve.Evaluate(c3 / timeToScale));
			}
			c3 += Time.unscaledDeltaTime;
			yield return null;
		}
		SoundManager.Instance.Play(sound_UI_Arms_Race_C_Ball_Pop_Shake, base.transform);
		GamefeelManager.instance.AddUIGameFeelOverTime(10f, 0.2f);
		CardChoiceVisuals.instance.Show(orangeWinner ? 1 : 0);
		UIHandler.instance.roundCounterSmall.UpdateRounds(orangeRounds, blueRounds);
		UIHandler.instance.roundCounterSmall.UpdatePoints(0, 0);
		DoShowPoints(0, 0, orangeWinner);
		Close();
	}

	private void MoveTowards()
	{
	}

	public IEnumerator DoSequence(int currentOrange, int currentBlue, bool orangeWinner)
	{
		yield return new WaitForSecondsRealtime(0.45f);
		SoundManager.Instance.Play(soundWinRound, base.transform);
		ResetBalls();
		bg.SetActive(value: true);
		blueBall.gameObject.SetActive(value: true);
		orangeBall.gameObject.SetActive(value: true);
		yield return new WaitForSecondsRealtime(0.2f);
		GamefeelManager.instance.AddUIGameFeelOverTime(10f, 0.1f);
		DoShowPoints(currentOrange, currentBlue, orangeWinner);
		yield return new WaitForSecondsRealtime(1.8f);
		orangeBall.GetComponent<CurveAnimation>().PlayOut();
		blueBall.GetComponent<CurveAnimation>().PlayOut();
		yield return new WaitForSecondsRealtime(0.25f);
		Close();
	}

	public void DoShowPoints(int currentOrange, int currentBlue, bool orangeWinner)
	{
		orangeFill.fillAmount = (float)currentOrange * 0.5f;
		blueFill.fillAmount = (float)currentBlue * 0.5f;
		if (orangeWinner)
		{
			text.color = PlayerSkinBank.GetPlayerSkinColors(0).winText;
		}
		else
		{
			text.color = PlayerSkinBank.GetPlayerSkinColors(1).winText;
		}
		if (orangeWinner)
		{
			if (currentOrange > 1)
			{
				RoundOrange();
			}
			else
			{
				HalfOrange();
			}
		}
		else if (currentBlue > 1)
		{
			RoundOBlue();
		}
		else
		{
			HalfBlue();
		}
	}

	private void Close()
	{
		text.text = "";
		bg.SetActive(value: false);
		blueBall.gameObject.SetActive(value: false);
		orangeBall.gameObject.SetActive(value: false);
	}

	private void HalfOrange()
	{
		text.text = "HALF ORANGE";
	}

	private void RoundOrange()
	{
		text.text = "ROUND ORANGE";
	}

	private void HalfBlue()
	{
		text.text = "HALF BLUE";
	}

	private void RoundOBlue()
	{
		text.text = "ROUND BLUE";
	}

	private void Update()
	{
	}
}