| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using System.Linq;
- public class AnswerLineInfoScript : MonoBehaviour
- {
- [SerializeField] Button nextPlayerButton;
- [SerializeField] Button prevPlayerButton;
- [SerializeField] Text lockedQuestionsText;
- [SerializeField] Text unlockedQuestionsText;
- [SerializeField] GameObject scrollView;
- [SerializeField] GameObject answerLine;
- [SerializeField] GameObject newQuestion;
- [SerializeField] GameObject gameManager;
- private List<KeyValuePair<string, int>> players;
- private string currentPlayerShown;
- private void Start() {
- nextPlayerButton.onClick.AddListener(ShowNextPlayerAnswerLine);
- prevPlayerButton.onClick.AddListener(ShowPrevPlayerAnswerLine);
- currentPlayerShown = GameManagerScript.GetCurrentPlayer();
- }
- private void Update() {
- UpdateLockedQuestionsText();
- UpdateUnlockedQuestionsText();
- UpdateButtonsText();
- SetQuestionClickable();
- }
- private void SetQuestionClickable() {
- if (GameManagerScript.GetCurrentPlayer().Equals(currentPlayerShown)) {
- newQuestion.GetComponent<NewQuestionCardController>().BackClickable = true;
- } else {
- newQuestion.GetComponent<NewQuestionCardController>().BackClickable = false;
- }
- }
- public void UpdateButtonsText() {
- if (players == null) {
- players = gameManager.GetComponent<GameManagerScript>().GetPlayers();
- }
- if (players.Count <= 1) {
- nextPlayerButton.gameObject.SetActive(false);
- prevPlayerButton.gameObject.SetActive(false);
- } else {
- nextPlayerButton.gameObject.SetActive(true);
- prevPlayerButton.gameObject.SetActive(true);
- if (currentPlayerShown == null) {
- currentPlayerShown = GameManagerScript.GetCurrentPlayer();
- }
- string playerBaseText = LocalizationManager.Instance.GetText("ANSWERLINE_OTHER_PLAYER");
- for (int i = 0; i < players.Count; i++) {
- if (players[i].Key.Equals(currentPlayerShown, StringComparison.InvariantCultureIgnoreCase)) {
- if (i + 1 < players.Count) {
- nextPlayerButton.GetComponent<AnswerLineInfoPlayerButton>().PlayerName = players[i+1].Key;
- nextPlayerButton.GetComponentInChildren<Text>().text = String.Format(playerBaseText ,players[i + 1].Key);
- if (i - 1 > 0) {
-
- prevPlayerButton.GetComponent<AnswerLineInfoPlayerButton>().PlayerName = players[i-1].Key;
- prevPlayerButton.GetComponentInChildren<Text>().text = String.Format(playerBaseText ,players[i - 1].Key);
- } else {
- prevPlayerButton.GetComponent<AnswerLineInfoPlayerButton>().PlayerName = players[players.Count-1].Key;
- prevPlayerButton.GetComponentInChildren<Text>().text = String.Format(playerBaseText ,players[players.Count - 1].Key);
- }
- break;
- } else {
- nextPlayerButton.GetComponent<AnswerLineInfoPlayerButton>().PlayerName = players[0].Key;
- nextPlayerButton.GetComponentInChildren<Text>().text = String.Format(playerBaseText ,players[0].Key);
-
- prevPlayerButton.GetComponent<AnswerLineInfoPlayerButton>().PlayerName = players[i-1].Key;
- prevPlayerButton.GetComponentInChildren<Text>().text = String.Format(playerBaseText ,players[i - 1].Key);
- break;
- }
- }
- }
- }
- }
- private void UpdateUnlockedQuestionsText() {
- int unlockedQuestionCount = scrollView.GetComponent<ScrollViewScript>().GetUnlockedQuestionCount();
- if (unlockedQuestionCount <= 0) {
- unlockedQuestionsText.gameObject.SetActive(false);
- } else {
- unlockedQuestionsText.gameObject.SetActive(true);
- unlockedQuestionsText.text = String.Format(
- LocalizationManager.Instance.GetText(
- unlockedQuestionsText.GetComponent<TextLocalization>().key),
- unlockedQuestionCount);
- }
- }
- private void UpdateLockedQuestionsText() {
- ScrollViewScript scrollViewScript = scrollView.GetComponent<ScrollViewScript>();
- int lockedQuestionsCount = scrollViewScript.GetQuestionIdsInAnswerLine().Count - scrollViewScript.GetUnlockedQuestionCount();
- lockedQuestionsText.text = String.Format(
- LocalizationManager.Instance.GetText(
- lockedQuestionsText.GetComponent<TextLocalization>().key),
- lockedQuestionsCount);
- }
- private void ShowNextPlayerAnswerLine()
- {
- GameManagerScript gameManagerScript = gameManager.GetComponent<GameManagerScript>();
- List<NewQuestionData> playerQuestions = Database.Instance.GetPlayerQuestions(gameManagerScript.GameId, nextPlayerButton.GetComponent<AnswerLineInfoPlayerButton>().PlayerName, gameManagerScript.GameMode);
- currentPlayerShown = nextPlayerButton.GetComponent<AnswerLineInfoPlayerButton>().PlayerName;
- setQuestionFrosting(playerQuestions);
- UpdateButtonsText();
- }
- private void ShowPrevPlayerAnswerLine()
- {
- GameManagerScript gameManagerScript = gameManager.GetComponent<GameManagerScript>();
- List<NewQuestionData> playerQuestions = Database.Instance.GetPlayerQuestions(gameManagerScript.GameId, prevPlayerButton.GetComponent<AnswerLineInfoPlayerButton>().PlayerName, gameManagerScript.GameMode);
-
- currentPlayerShown = prevPlayerButton.GetComponent<AnswerLineInfoPlayerButton>().PlayerName;
- setQuestionFrosting(playerQuestions);
- UpdateButtonsText();
- }
- private void setQuestionFrosting(List<NewQuestionData> questions) {
- ScrollViewScript scrollViewScript = scrollView.GetComponent<ScrollViewScript>();
- scrollViewScript.RemoveEverythingFromAnswerline();
- scrollViewScript.SetQuestionsInAnswerLine(questions);
- if (GameManagerScript.GetCurrentPlayer().Equals(currentPlayerShown)) {
- scrollViewScript.SetQuestionsFrosted(false);
- } else {
- scrollViewScript.SetQuestionsFrosted(true);
- }
- }
- }
|