RoundButtonsScript.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine.UI;
  4. using UnityEngine;
  5. using System;
  6. public class RoundButtonsScript : MonoBehaviour
  7. {
  8. public Button newQuestionButton;
  9. public Button nextPlayerButton;
  10. private ScrollViewScript svs;
  11. private TimerScript ts;
  12. // Start is called before the first frame update
  13. void Start()
  14. {
  15. newQuestionButton.onClick.AddListener(NewQuestion);
  16. nextPlayerButton.onClick.AddListener(NextPlayer);
  17. svs = GameObject.Find("Scroll View").GetComponent<ScrollViewScript>();
  18. ts = GameObject.Find("TimerCircle").GetComponent<TimerScript>();
  19. }
  20. void NewQuestion() {
  21. HidePanel();
  22. ts.ResetTimer();
  23. ts.StartTimer();
  24. svs.HideRoundButtons();
  25. }
  26. void NextPlayer() {
  27. svs.SetAllQuestionsLocked(true);
  28. svs.NextPlayer();
  29. HidePanel();
  30. }
  31. public void HidePanel() {
  32. CanvasGroup cg = this.GetComponent<CanvasGroup>();
  33. cg.alpha = 0F;
  34. cg.blocksRaycasts = false;
  35. cg.interactable = false;
  36. }
  37. public void ShowPanel() {
  38. if (svs == null) {
  39. svs = GameObject.Find("Scroll View").GetComponent<ScrollViewScript>();
  40. }
  41. NewQuestion q = Database.Instance.GetNewQuestion(svs.GetQuestionIdsInAnswerLine(), svs.currentPlayer, svs.GetGameMode());
  42. q.SetAnswerText("???? - ????");
  43. svs.SetNewQuestion(q);
  44. Text nqct = GameObject.Find("NextQuestionCategoryText").GetComponent<Text>();
  45. CategoryPanel cp = GameObject.Find("Categories").GetComponent<CategoryPanel>();
  46. CategoryPanel.Category cat = cp.GetCategoryById(q.GetCategoryId());
  47. nqct.text = cat.name;
  48. CanvasGroup cg = this.GetComponent<CanvasGroup>();
  49. cg.alpha = 1f;
  50. cg.interactable = true;
  51. cg.blocksRaycasts = true;
  52. }
  53. internal void DeactivateNextPlayer() {
  54. nextPlayerButton.interactable = false;
  55. newQuestionButton.GetComponentInChildren<Text>().text = LocalizationManager.Instance.GetText("START_ROUND_TEXT");
  56. }
  57. internal void ActivateNextPlayer() {
  58. nextPlayerButton.interactable = true;
  59. newQuestionButton.GetComponentInChildren<Text>().text = LocalizationManager.Instance.GetText("NEW_QUESTION");
  60. }
  61. public void SetGameOver() {
  62. nextPlayerButton.interactable = false;
  63. newQuestionButton.interactable = false;
  64. }
  65. }