RoundButtonsScript.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. svs.CheckActiveUserLoggedIn();
  30. HidePanel();
  31. }
  32. public void HidePanel() {
  33. CanvasGroup cg = this.GetComponent<CanvasGroup>();
  34. cg.alpha = 0F;
  35. cg.blocksRaycasts = false;
  36. cg.interactable = false;
  37. }
  38. public void ShowPanel() {
  39. if (svs == null) {
  40. svs = GameObject.Find("Scroll View").GetComponent<ScrollViewScript>();
  41. }
  42. NewQuestion q = Database.Instance.GetNewQuestion(svs.GetQuestionIdsInAnswerLine(), svs.currentPlayer, svs.GetGameMode());
  43. q.SetAnswerText("???? - ????");
  44. svs.SetNewQuestion(q);
  45. Text nqct = GameObject.Find("NextQuestionCategoryText").GetComponent<Text>();
  46. CategoryPanel cp = GameObject.Find("Categories").GetComponent<CategoryPanel>();
  47. CategoryPanel.Category cat = cp.GetCategoryById(q.GetCategoryId());
  48. nqct.text = cat.name;
  49. CanvasGroup cg = this.GetComponent<CanvasGroup>();
  50. cg.alpha = 1f;
  51. cg.interactable = true;
  52. cg.blocksRaycasts = true;
  53. }
  54. internal void DeactivateNextPlayer() {
  55. nextPlayerButton.interactable = false;
  56. newQuestionButton.GetComponentInChildren<Text>().text = LocalizationManager.Instance.GetText("START_ROUND_TEXT");
  57. }
  58. internal void ActivateNextPlayer() {
  59. nextPlayerButton.interactable = true;
  60. newQuestionButton.GetComponentInChildren<Text>().text = LocalizationManager.Instance.GetText("NEW_QUESTION");
  61. }
  62. public void SetGameOver() {
  63. nextPlayerButton.interactable = false;
  64. newQuestionButton.interactable = false;
  65. }
  66. }