OnlineGameScript.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class OnlineGameScript : MonoBehaviour {
  6. // Status color Pending, not your turn, your turn, declined
  7. List<Color32> statusColors = new List<Color32>() { new Color32(234, 164, 17, 100), new Color32(255, 255, 24, 175), new Color32(0, 255, 0, 100), new Color32(219, 12, 65, 100) };
  8. public Text gameStatusText;
  9. public Text gameTitleText;
  10. private int id;
  11. private int winNumber;
  12. private int answerTimer;
  13. private int roundTimeLimit;
  14. private string currentPlayer;
  15. private int round;
  16. private string startDate;
  17. private string LastPlayedDate;
  18. private string finishedDate;
  19. public int Id { get => id; set => id = value; }
  20. public int WinNumber { get => winNumber; set => winNumber = value; }
  21. public int AnswerTimer { get => answerTimer; set => answerTimer = value; }
  22. public int RoundTimeLimit { get => roundTimeLimit; set => roundTimeLimit = value; }
  23. public string CurrentPlayer { get => currentPlayer; set => currentPlayer = value; }
  24. public int Round { get => round; set => round = value; }
  25. public string StartDate { get => startDate; set => startDate = value; }
  26. public string LastPlayedDate1 { get => LastPlayedDate; set => LastPlayedDate = value; }
  27. public string FinishedDate { get => finishedDate; set => finishedDate = value; }
  28. public string GameStatus {
  29. get { return gameStatus; }
  30. set {
  31. gameStatus = value;
  32. SetColor(gameStatus);
  33. }
  34. }
  35. private string PENDING = "ONLINE_GAME_STATUS_VALUE_PENDING";
  36. private string OTHERS_TURN = "ONLINE_GAME_STATUS_VALUE_OTHERS_TURN";
  37. private string DECLINED = "ONLINE_GAME_STATUS_VALUE_DECLINED";
  38. private string YOUR_TURN = "ONLINE_GAME_STATUS_VALUE_YOUR_TURN";
  39. // behövs nog en partialy declined status också, om en av fyra tackar nej kanske man viss spela ändå.
  40. // behövs också en med dina inbjudningar.
  41. public string gameStatus;
  42. // Start is called before the first frame update
  43. void Start() {
  44. }
  45. // Update is called once per frame
  46. void Update() {
  47. }
  48. private void SetColor(string status) {
  49. Image image = this.GetComponent<Image>();
  50. Debug.Log(status);
  51. if ("PENDING".Equals(status)) {
  52. image.color = statusColors[0];
  53. } else if ("YOUR_TURN".Equals(status)) {
  54. image.color = statusColors[1];
  55. } else if ("OTHERS_TURN".Equals(status)) {
  56. image.color = statusColors[2];
  57. } else if ("DECLINED".Equals(status)) {
  58. image.color = statusColors[3];
  59. } else {
  60. image.color = new Color32(100, 100, 100, 100);
  61. }
  62. }
  63. public void SetTitleText(string text) {
  64. gameTitleText.text = text;
  65. }
  66. public void SetGameStatusText() {
  67. SetGameStatusText("");
  68. }
  69. public void SetGameStatusText(string extraInfo) {
  70. if ("PENDING".Equals(GameStatus)) {
  71. gameStatusText.text = LocalizationManager.Instance.GetText(PENDING);
  72. } else if ("YOUR_TURN".Equals(GameStatus)) {
  73. gameStatusText.text = LocalizationManager.Instance.GetText(YOUR_TURN);
  74. } else if ("OTHERS_TURN".Equals(GameStatus)) {
  75. string message = LocalizationManager.Instance.GetText(OTHERS_TURN);
  76. gameStatusText.text = String.Format(message, extraInfo);
  77. } else if ("DECLINED".Equals(GameStatus)) {
  78. gameStatusText.text = LocalizationManager.Instance.GetText(DECLINED);
  79. } else {
  80. gameStatusText.text = "SOMETHING WRONG WITH STATUS TITLE FROM TEXT " + GameStatus;
  81. }
  82. }
  83. public void SetId(string id) {
  84. Int32.TryParse(id, out int intId);
  85. Id = intId;
  86. }
  87. public void SetWinNumber(string winNumber) {
  88. Int32.TryParse(winNumber, out int intWinNumber);
  89. WinNumber = intWinNumber;
  90. }
  91. public void SetAnswerTimer(string answerTimer) {
  92. Int32.TryParse(answerTimer, out int intAnswerTimer);
  93. AnswerTimer = intAnswerTimer;
  94. }
  95. public void SetRoundTimeLimit(string roundTimeLimit) {
  96. Int32.TryParse(roundTimeLimit, out int intRoundTimelimit);
  97. RoundTimeLimit = intRoundTimelimit;
  98. }
  99. public void SetRound(string round) {
  100. Int32.TryParse(round, out int intRound);
  101. Round = intRound;
  102. }
  103. public void SetGameStatus(string status) {
  104. GameStatus = status;
  105. }
  106. }