| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- 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 String signedInName;
-
- private void Start() {
- nextPlayerButton.onClick.AddListener(ShowNextPlayerAnswerLine);
- prevPlayerButton.onClick.AddListener(ShowPrevPlayerAnswerLine);
- currentPlayerShown = GameManagerScript.GetCurrentPlayer();
- signedInName = Database.Instance.GetSignedInUser().Value;
- lockedQuestionsText.resizeTextMaxSize = unlockedQuestionsText.resizeTextMaxSize;
- }
- private void Update() {
- UpdateLockedQuestionsText();
- UpdateUnlockedQuestionsText();
- UpdateButtonsText();
- SetQuestionClickable();
- }
- private void SetQuestionClickable() {
- if (GameManagerScript.GetCurrentPlayer().Equals(currentPlayerShown, StringComparison.InvariantCultureIgnoreCase)) {
- 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 = signedInName;
- }
- 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) {
- if (players[i+1].Key.Equals(signedInName, StringComparison.InvariantCultureIgnoreCase)) {
- nextPlayerButton.GetComponent<AnswerLineInfoPlayerButton>().PlayerName = LocalizationManager.Instance.GetText("YOUR");
- } else {
- nextPlayerButton.GetComponent<AnswerLineInfoPlayerButton>().PlayerName = players[i + 1].Key + "s";
- }
- nextPlayerButton.GetComponentInChildren<Text>().text = String.Format(playerBaseText, nextPlayerButton.GetComponent<AnswerLineInfoPlayerButton>().PlayerName);
- if (i - 1 >= 0) {
- if (players[i-1].Key.Equals(signedInName, StringComparison.InvariantCultureIgnoreCase)) {
- prevPlayerButton.GetComponent<AnswerLineInfoPlayerButton>().PlayerName = LocalizationManager.Instance.GetText("YOUR");
- } else {
- prevPlayerButton.GetComponent<AnswerLineInfoPlayerButton>().PlayerName = players[i - 1].Key + "s";
- }
- } else {
- if (players[players.Count - 1].Key.Equals(signedInName, StringComparison.InvariantCultureIgnoreCase)) {
- prevPlayerButton.GetComponent<AnswerLineInfoPlayerButton>().PlayerName = LocalizationManager.Instance.GetText("YOUR");
- } else {
- prevPlayerButton.GetComponent<AnswerLineInfoPlayerButton>().PlayerName = players[players.Count-1].Key + "s";
- }
- }
- prevPlayerButton.GetComponentInChildren<Text>().text = String.Format(playerBaseText, prevPlayerButton.GetComponent<AnswerLineInfoPlayerButton>().PlayerName);
- break;
- } else {
- if (players[0].Key.Equals(signedInName, StringComparison.InvariantCultureIgnoreCase)) {
- nextPlayerButton.GetComponent<AnswerLineInfoPlayerButton>().PlayerName = LocalizationManager.Instance.GetText("YOUR");
- } else {
- nextPlayerButton.GetComponent<AnswerLineInfoPlayerButton>().PlayerName = players[0].Key + "s";
- }
- nextPlayerButton.GetComponentInChildren<Text>().text = String.Format(playerBaseText, nextPlayerButton.GetComponent<AnswerLineInfoPlayerButton>().PlayerName);
-
- if (players[i-1].Key.Equals(signedInName, StringComparison.InvariantCultureIgnoreCase)) {
- prevPlayerButton.GetComponent<AnswerLineInfoPlayerButton>().PlayerName = LocalizationManager.Instance.GetText("YOUR");
- } else {
- prevPlayerButton.GetComponent<AnswerLineInfoPlayerButton>().PlayerName = players[i-1].Key;
- }
- prevPlayerButton.GetComponentInChildren<Text>().text = String.Format(playerBaseText, prevPlayerButton.GetComponent<AnswerLineInfoPlayerButton>().PlayerName);
- 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();
- String playerText;
- if (currentPlayerShown == null || currentPlayerShown.Equals(signedInName, StringComparison.InvariantCultureIgnoreCase)) {
- playerText = LocalizationManager.Instance.GetText("YOU");
- } else {
- playerText = currentPlayerShown;
- }
- if (lockedQuestionsText != null){
- lockedQuestionsText.text = String.Format(
- LocalizationManager.Instance.GetText(
- lockedQuestionsText.GetComponent<TextLocalization>().key),
- playerText,
- lockedQuestionsCount);
- }
- }
- private void ShowNextPlayerAnswerLine()
- {
- GameManagerScript gameManagerScript = gameManager.GetComponent<GameManagerScript>();
- if (nextPlayerButton.GetComponent<AnswerLineInfoPlayerButton>().PlayerName.Equals(LocalizationManager.Instance.GetText("YOUR"))) {
- currentPlayerShown = signedInName;
- } else {
- currentPlayerShown = nextPlayerButton.GetComponent<AnswerLineInfoPlayerButton>().PlayerName;
- currentPlayerShown = currentPlayerShown.Substring(0,currentPlayerShown.Length - 1);
- }
- List<NewQuestionData> playerQuestions = Database.Instance.GetPlayerQuestions(gameManagerScript.GameId, currentPlayerShown, gameManagerScript.GameMode);
- setQuestionFrosting(playerQuestions);
- UpdateButtonsText();
- }
- private void ShowPrevPlayerAnswerLine()
- {
- GameManagerScript gameManagerScript = gameManager.GetComponent<GameManagerScript>();
- if (prevPlayerButton.GetComponent<AnswerLineInfoPlayerButton>().PlayerName.Equals(LocalizationManager.Instance.GetText("YOUR"))) {
- currentPlayerShown = signedInName;
- } else {
- currentPlayerShown = prevPlayerButton.GetComponent<AnswerLineInfoPlayerButton>().PlayerName;
- currentPlayerShown = currentPlayerShown.Substring(0, currentPlayerShown.Length - 1);
- }
-
- List<NewQuestionData> playerQuestions = Database.Instance.GetPlayerQuestions(gameManagerScript.GameId, currentPlayerShown, gameManagerScript.GameMode);
-
- setQuestionFrosting(playerQuestions);
- UpdateButtonsText();
- }
- private void setQuestionFrosting(List<NewQuestionData> questions) {
- ScrollViewScript scrollViewScript = scrollView.GetComponent<ScrollViewScript>();
- scrollViewScript.RemoveEverythingFromAnswerline();
- scrollViewScript.SetQuestionsInAnswerLine(questions);
- //if (GameManagerScript.GetCurrentPlayer().Equals(currentPlayerShown)) {
- if (Database.Instance.GetSignedInUser().Value.Equals(currentPlayerShown, StringComparison.InvariantCultureIgnoreCase)) {
- scrollViewScript.SetQuestionsFrosted(false);
- } else {
- scrollViewScript.SetQuestionsFrosted(true);
- }
- }
- }
|