Przeglądaj źródła

Ytterligare lite refaktorering av onlineGameList

Axel Nordh 5 lat temu
rodzic
commit
90a184e899

+ 6 - 7
Assets/Scripts/Database/OnlineDatabase.cs

@@ -307,24 +307,23 @@ public class OnlineDatabase : MonoBehaviour {
             if (gameId != currentGameId) { // Spel ej i listan
                 if (ogs != null) { // lägg till spel i listan, inte första gången
                     SetGlobalGameInfo(userName, ogs, gameId, game);
+                    if (game.currentPlayer.Equals(Database.Instance.GetSignedInUser().Value, StringComparison.InvariantCultureIgnoreCase)) {
+                        ogs.SetGameStatus("YOUR_TURN");
+                    }
                     games.Add(ogs);
                 }
                 onlineGameObject = Instantiate(prefab, new Vector2(0, 0), Quaternion.identity) as GameObject;
                 ogs = onlineGameObject.GetComponent<OnlineGameScript>();
                 gameId = currentGameId;
 
-                /*    if (game.currentPlayer.Equals(userId.ToString())) { // Inloggad spelares tur att agera
-                        ogs.CurrentPlayer = game.username;
-                        ogs.addPlayer(game.username);
-                    } else */
                 if (game.currentPlayer.Equals(game.userId)) { // om första raden i spelinfo är annan spelare och det är dennes tur att agera
                     ogs.CurrentPlayer = game.username;
                     ogs.addPlayer(game.username);
-                    ogs.PlayerInfos.Add(new KeyValuePair<string, string>(game.username, game.playerStatus));
+                    ogs.addPlayerInfo(game.username, game.playerStatus);
                 }
             } else { // Spel redan i listan, fyll på med info
                 ogs.addPlayer(game.username);
-                ogs.PlayerInfos.Add(new KeyValuePair<string, string>(game.username, game.playerStatus));
+                ogs.addPlayerInfo(game.username, game.playerStatus);
                 if (game.currentPlayer.Equals(game.userId)) {
                     ogs.CurrentPlayer = game.username;
                 }
@@ -332,7 +331,7 @@ public class OnlineDatabase : MonoBehaviour {
 
   
         }
-        SetGlobalGameInfo(userName, ogs, gameId, og.onlineGamesList[og.onlineGamesList.Count]);
+        SetGlobalGameInfo(userName, ogs, gameId, og.onlineGamesList[og.onlineGamesList.Count - 1]);
         games.Add(ogs);
         
         return games;

+ 15 - 4
Assets/Scripts/NewGameScene/OnlineGameScript.cs

@@ -45,7 +45,11 @@ public class OnlineGameScript : MonoBehaviour {
     public string GameStatus {
         get { return gameStatus; }
         set {
-            gameStatus = value;
+            if (value.Equals("Avtive") && CurrentPlayer.Equals(Database.Instance.GetSignedInUser().Value, StringComparison.InvariantCultureIgnoreCase)) {
+                gameStatus = "YOUR_TURN";
+            } else {
+                gameStatus = value;
+            }
             SetColor(gameStatus);
             SetGameStatusText();
         }
@@ -77,6 +81,7 @@ public class OnlineGameScript : MonoBehaviour {
     private void Start() {
         gameInfoButton = this.GetComponent<Button>();
         gameInfoButton.onClick.AddListener(ShowInfoPanel);
+        PlayerInfos = new List<KeyValuePair<string, string>>();
     }
 
     private void ShowInfoPanel() {
@@ -93,6 +98,13 @@ public class OnlineGameScript : MonoBehaviour {
         Players.Add(playerName);
     }
 
+    public void addPlayerInfo(string playerName, string playerStatus) {
+        if (PlayerInfos == null) {
+            PlayerInfos = new List<KeyValuePair<string, string>>();
+        }
+        PlayerInfos.Add(new KeyValuePair<string, string>(playerName, playerStatus));
+    }
+
     public string gameStatus;
 
     private void SetColor(string status) {
@@ -123,7 +135,6 @@ public class OnlineGameScript : MonoBehaviour {
     }
 
     public void SetGameStatusText() {
-        String extraInfo = ""; // TODO
         if ("PENDING".Equals(GameStatus)) {
             gameStatusText.gameObject.GetComponent<TextLocalization>().key = PENDING;
             gameStatusText.text = LocalizationManager.Instance.GetText(PENDING);
@@ -137,7 +148,7 @@ public class OnlineGameScript : MonoBehaviour {
         } else if ("OTHERS_TURN".Equals(GameStatus)) {
             gameStatusText.gameObject.GetComponent<TextLocalization>().key = OTHERS_TURN;
             string message = LocalizationManager.Instance.GetText(OTHERS_TURN);
-            gameStatusText.text = String.Format(message, extraInfo);
+            gameStatusText.text = String.Format(message, CurrentPlayer);
             gameTitleText.gameObject.GetComponent<TextLocalization>().key = "NOT_YOUR_TURN";
             SetTitleText(LocalizationManager.Instance.GetText("NOT_YOUR_TURN"));
         } else if ("DECLINED".Equals(GameStatus)) {
@@ -153,7 +164,7 @@ public class OnlineGameScript : MonoBehaviour {
         } else if ("ACTIVE".Equals(GameStatus)) {
             TextLocalization textLocalization = gameStatusText.gameObject.GetComponent<TextLocalization>();
             textLocalization.key = ACTIVE;
-            textLocalization.SetReplaceText(extraInfo);
+            textLocalization.SetReplaceText(CurrentPlayer);
             gameTitleText.gameObject.GetComponent<TextLocalization>().key = ACTIVE_TITLE;
             gameTitleText.text = LocalizationManager.Instance.GetText(ACTIVE_TITLE);
         } else {