summaryrefslogtreecommitdiff
path: root/GameCode/UIHandler.cs
diff options
context:
space:
mode:
authorchai <215380520@qq.com>2023-10-27 11:05:14 +0800
committerchai <215380520@qq.com>2023-10-27 11:05:14 +0800
commit766cdff5ffa72b65d7f106658d1603f47739b2ba (patch)
tree34d7799a94dfa9be182825577583c0fa6dc935f7 /GameCode/UIHandler.cs
+ init
Diffstat (limited to 'GameCode/UIHandler.cs')
-rw-r--r--GameCode/UIHandler.cs177
1 files changed, 177 insertions, 0 deletions
diff --git a/GameCode/UIHandler.cs b/GameCode/UIHandler.cs
new file mode 100644
index 0000000..72d0b63
--- /dev/null
+++ b/GameCode/UIHandler.cs
@@ -0,0 +1,177 @@
+using System;
+using System.Collections;
+using Sonigon;
+using TMPro;
+using UnityEngine;
+
+public class UIHandler : MonoBehaviour
+{
+ [Header("Sounds")]
+ public SoundEvent soundTextAppear;
+
+ public SoundEvent soundTextDisappear;
+
+ public static UIHandler instance;
+
+ [Header("Settings")]
+ public TextMeshProUGUI gameOverText;
+
+ public GeneralParticleSystem gameOverTextPart;
+
+ public GeneralParticleSystem roundBackgroundPart;
+
+ public GeneralParticleSystem roundTextPart;
+
+ public CodeAnimation roundCounterAnim;
+
+ public RoundCounter roundCounter;
+
+ public RoundCounter roundCounterSmall;
+
+ public CodeAnimation roundCounterAnimSmall;
+
+ public GameObject pickerObject;
+
+ public GeneralParticleSystem pickerPart;
+
+ public GeneralParticleSystem joinGamePart;
+
+ public TextMeshProUGUI jointGameText;
+
+ public PopUpHandler popUpHandler;
+
+ private void Awake()
+ {
+ instance = this;
+ popUpHandler = base.transform.root.GetComponentInChildren<PopUpHandler>();
+ }
+
+ public void ShowJoinGameText(string text, Color color)
+ {
+ SoundManager.Instance.Play(soundTextAppear, base.transform);
+ if (text != "")
+ {
+ jointGameText.text = text;
+ }
+ if (color != Color.black)
+ {
+ joinGamePart.particleSettings.color = color;
+ }
+ joinGamePart.loop = true;
+ joinGamePart.Play();
+ }
+
+ internal void SetNumberOfRounds(int roundsToWinGame)
+ {
+ roundCounter.SetNumberOfRounds(roundsToWinGame);
+ roundCounterSmall.SetNumberOfRounds(roundsToWinGame);
+ }
+
+ public void HideJoinGameText()
+ {
+ SoundManager.Instance.Play(soundTextDisappear, base.transform);
+ joinGamePart.Stop();
+ }
+
+ public void DisplayScreenText(Color color, string text, float speed)
+ {
+ gameOverTextPart.particleSettings.color = color;
+ gameOverTextPart.duration = 60f / speed;
+ gameOverTextPart.Play();
+ gameOverText.text = text;
+ }
+
+ public void DisplayScreenTextLoop(string text)
+ {
+ gameOverTextPart.duration = 60f;
+ gameOverTextPart.loop = true;
+ gameOverTextPart.Play();
+ gameOverText.text = text;
+ }
+
+ public void DisplayScreenTextLoop(Color color, string text)
+ {
+ gameOverTextPart.particleSettings.color = color;
+ gameOverTextPart.duration = 60f;
+ gameOverTextPart.loop = true;
+ gameOverTextPart.Play();
+ gameOverText.text = text;
+ }
+
+ public void StopScreenTextLoop()
+ {
+ gameOverTextPart.loop = false;
+ }
+
+ public void ShowAddPoint(Color color, string winTextBefore, string text, float speed)
+ {
+ gameOverTextPart.particleSettings.color = color;
+ gameOverTextPart.duration = 60f / speed;
+ gameOverTextPart.Play();
+ StartCoroutine(DoShowAddPoint(winTextBefore, text));
+ }
+
+ private IEnumerator DoShowAddPoint(string winTextBefore, string text)
+ {
+ gameOverText.text = winTextBefore;
+ yield return new WaitForSecondsRealtime(0.7f);
+ gameOverText.text = text;
+ }
+
+ public void ShowRoundOver(int p1Rounds, int p2Rounds)
+ {
+ roundCounter.gameObject.SetActive(value: true);
+ roundBackgroundPart.Play();
+ roundTextPart.Play();
+ roundCounterAnim.PlayIn();
+ roundCounter.UpdateRounds(p1Rounds, p2Rounds);
+ }
+
+ public void ShowRoundCounterSmall(int p1Rounds, int p2Rounds, int p1Points, int p2Points)
+ {
+ roundCounterSmall.gameObject.SetActive(value: true);
+ roundCounterSmall.UpdateRounds(p1Rounds, p2Rounds);
+ roundCounterSmall.UpdatePoints(p1Points, p2Points);
+ if (roundCounterAnimSmall.currentState != 0)
+ {
+ roundCounterAnimSmall.PlayIn();
+ }
+ }
+
+ public void HideRoundCounterSmall()
+ {
+ roundCounterAnimSmall.PlayOut();
+ }
+
+ public void ShowPicker(int pickerID, PickerType pickerType = PickerType.Team)
+ {
+ pickerObject.SetActive(value: true);
+ if (pickerType == PickerType.Team)
+ {
+ pickerPart.particleSettings.color = PlayerManager.instance.GetColorFromTeam(pickerID).winText;
+ }
+ if (pickerType == PickerType.Player)
+ {
+ pickerPart.particleSettings.color = PlayerManager.instance.GetColorFromPlayer(pickerID).winText;
+ }
+ pickerPart.loop = true;
+ pickerPart.Play();
+ }
+
+ public void StopShowPicker()
+ {
+ StartCoroutine(DoStopShowPicker());
+ }
+
+ private IEnumerator DoStopShowPicker()
+ {
+ pickerPart.loop = false;
+ yield return new WaitForSeconds(0.3f);
+ pickerObject.SetActive(value: false);
+ }
+
+ internal void DisplayYesNoLoop(Player pickingPlayer, Action<PopUpHandler.YesNo> functionToCall)
+ {
+ popUpHandler.StartPicking(pickingPlayer, functionToCall);
+ }
+}