feat: enable end buttons only for first player

This commit is contained in:
Fangh 2024-01-31 23:55:35 +01:00
parent 70b9bee50a
commit 3b6d8a8453

View File

@ -39,6 +39,10 @@ public class GameManager : MonoBehaviour
[Header("MakeProposition Component")] [Header("MakeProposition Component")]
public TextMeshProUGUI counterMakeProposition; public TextMeshProUGUI counterMakeProposition;
[Header("EndGame Components")]
[SerializeField] private GameObject endGameFirstPlayer;
[SerializeField] private GameObject endGameOtherPlayers;
[Header("Pages")] [Header("Pages")]
public GameObject HomeConnection; public GameObject HomeConnection;
public GameObject WaitingRoom; public GameObject WaitingRoom;
@ -313,8 +317,11 @@ private void OnRoomUpdate(object sender, ValueChangedEventArgs e)
{ {
case (int)GameState.WaitingForOtherPlayersToJoin: case (int)GameState.WaitingForOtherPlayersToJoin:
{ {
CheckIfIAmTheFirst(myRoom.GetPlayerList()); if(CheckIfIAmTheFirst(myRoom.GetPlayerList()))
UpdateDisplayedListUser(myRoom.GetPlayerList()); {
submitStartGame.SetActive(true);
}
UpdateDisplayedListUser(myRoom.GetOrderedPlayerList());
break; break;
} }
default: default:
@ -382,6 +389,8 @@ private void OnNewGameState()
VotePicture.SetActive(false); VotePicture.SetActive(false);
WaitingOtherPlayers.SetActive(false); WaitingOtherPlayers.SetActive(false);
endGameFirstPlayer.SetActive(CheckIfIAmTheFirst(myRoom.GetPlayerList()));
endGameOtherPlayers.SetActive(CheckIfIAmTheFirst(myRoom.GetPlayerList()));
EndGame.SetActive(true); EndGame.SetActive(true);
} }
break; break;
@ -416,7 +425,12 @@ private void UpdateDisplayedListUser(List<Player> players)
} }
} }
private void CheckIfIAmTheFirst(List<Player> players) /// <summary>
/// return true if you are the fist player
/// </summary>
/// <param name="players"></param>
/// <returns></returns>
private bool CheckIfIAmTheFirst(List<Player> players)
{ {
bool isFirst = false; bool isFirst = false;
if (players.Count > 1) if (players.Count > 1)
@ -429,11 +443,7 @@ private void CheckIfIAmTheFirst(List<Player> players)
isFirst = true; isFirst = true;
} }
} }
return isFirst;
if (isFirst)
{
submitStartGame.SetActive(true);
}
} }
public void SendCurrentState(GameState state, Action callback_oncCurrentStateSent) public void SendCurrentState(GameState state, Action callback_oncCurrentStateSent)
{ {