From 3b6d8a8453a05c93d9dd4bef75e4ec1507ff2a75 Mon Sep 17 00:00:00 2001 From: Fangh Date: Wed, 31 Jan 2024 23:55:35 +0100 Subject: [PATCH] feat: enable end buttons only for first player --- Assets/Scripts/GameManager.cs | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index 94f105f..be02ebd 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -39,6 +39,10 @@ public class GameManager : MonoBehaviour [Header("MakeProposition Component")] public TextMeshProUGUI counterMakeProposition; + [Header("EndGame Components")] + [SerializeField] private GameObject endGameFirstPlayer; + [SerializeField] private GameObject endGameOtherPlayers; + [Header("Pages")] public GameObject HomeConnection; public GameObject WaitingRoom; @@ -313,8 +317,11 @@ private void OnRoomUpdate(object sender, ValueChangedEventArgs e) { case (int)GameState.WaitingForOtherPlayersToJoin: { - CheckIfIAmTheFirst(myRoom.GetPlayerList()); - UpdateDisplayedListUser(myRoom.GetPlayerList()); + if(CheckIfIAmTheFirst(myRoom.GetPlayerList())) + { + submitStartGame.SetActive(true); + } + UpdateDisplayedListUser(myRoom.GetOrderedPlayerList()); break; } default: @@ -382,6 +389,8 @@ private void OnNewGameState() VotePicture.SetActive(false); WaitingOtherPlayers.SetActive(false); + endGameFirstPlayer.SetActive(CheckIfIAmTheFirst(myRoom.GetPlayerList())); + endGameOtherPlayers.SetActive(CheckIfIAmTheFirst(myRoom.GetPlayerList())); EndGame.SetActive(true); } break; @@ -416,7 +425,12 @@ private void UpdateDisplayedListUser(List players) } } - private void CheckIfIAmTheFirst(List players) + /// + /// return true if you are the fist player + /// + /// + /// + private bool CheckIfIAmTheFirst(List players) { bool isFirst = false; if (players.Count > 1) @@ -429,11 +443,7 @@ private void CheckIfIAmTheFirst(List players) isFirst = true; } } - - if (isFirst) - { - submitStartGame.SetActive(true); - } + return isFirst; } public void SendCurrentState(GameState state, Action callback_oncCurrentStateSent) {