| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- using UnityEngine.UI;
- public class GameInfoScript : MonoBehaviour {
- public Button cancelButton;
- public Button acceptButton;
- public GameObject playerInfoPrefab;
- public Transform playersPanel;
- public Transform gameSettingsPanel;
- private int gameId;
- private int questionTimer;
- private int winNumber;
- [SerializeField] Text answerTimeValueText;
- [SerializeField] Text questionsToWinValueText;
- [SerializeField] Text DaysToStartRoundValueText;
- [SerializeField] Text GameIdText;
- // Start is called before the first frame update
- void Start() {
- cancelButton.onClick.AddListener(Hide);
- acceptButton.onClick.AddListener(OpenGame);
- }
- // Update is called once per frame
- void Update() {
- }
- internal void SetOnlineData(OnlineGameScript onlineGameScript) {
- String currentPlayer = Database.Instance.GetSignedInUser().Value;
- gameId = onlineGameScript.GetId();
- questionTimer = onlineGameScript.AnswerTimer;
- winNumber = onlineGameScript.WinNumber;
- answerTimeValueText.text = onlineGameScript.AnswerTimer.ToString();
- questionsToWinValueText.text = onlineGameScript.WinNumber.ToString();
- DaysToStartRoundValueText.text = onlineGameScript.RoundTimeLimit.ToString();
- foreach (KeyValuePair<string, string> player in onlineGameScript.PlayerInfos) {
- GameObject slp = Instantiate(playerInfoPrefab, new Vector2(0, 0), Quaternion.identity) as GameObject;
- OnlinePlayerInfoScript opi = slp.GetComponent<OnlinePlayerInfoScript>();
- opi.GameId = gameId;
- opi.SetPlayerName(player.Key);
- if (currentPlayer.Equals(player.Key, StringComparison.InvariantCultureIgnoreCase) && player.Value.Equals("WAITING")) {
- opi.ShowDecitionButtons();
- } else {
- opi.SetPlayerStatus(player.Value);
- }
- opi.transform.SetParent(playersPanel, false);
- }
- GameIdText.text = onlineGameScript.GetId().ToString();
- acceptButton.enabled = false;
- acceptButton.interactable = false;
- if (onlineGameScript.GameStatus.Equals("ACTIVE") || onlineGameScript.GameStatus.Equals(OnlineGameScript.GAME_STATUS_YOUR_TURN) || onlineGameScript.GameStatus.Equals(OnlineGameScript.GAME_STATUS_OTHERS_TURN)) {
- acceptButton.enabled = true;
- acceptButton.interactable = true;
- }
- }
- private void OpenGame() {
- PlayerPrefs.SetString(Constants.GAME_MODE, Constants.ONLINE);
- PlayerPrefs.SetInt(Constants.GAME_ID, gameId);
- PlayerPrefs.SetInt(Constants.GAME_QUESTION_TIMER, questionTimer);
- PlayerPrefs.SetInt(Constants.GAME_TO_WIN, winNumber);
- SceneManager.LoadSceneAsync(Constants.SCENE_NAR_KAMPEN);
- }
- public void Show() {
- CanvasGroup cg = this.GetComponent<CanvasGroup>();
- cg.alpha = 1;
- cg.interactable = true;
- cg.blocksRaycasts = true;
- }
- public void Hide() {
- CanvasGroup cg = this.GetComponent<CanvasGroup>();
- cg.alpha = 0;
- cg.interactable = false;
- cg.blocksRaycasts = false;
- foreach (OnlinePlayerInfoScript opis in playersPanel.GetComponentsInChildren<OnlinePlayerInfoScript>()) {
- Destroy(opis);
- Destroy(opis.gameObject);
- }
- GameObject.Find("Main Panel").GetComponent<MainMenu>().UpdateOnlineGamesLists();
- }
- }
|