From 781b7d88c993866df77f390a82f634a0e5eca531 Mon Sep 17 00:00:00 2001 From: Morgan - 6 Freedom Date: Sun, 28 Jan 2024 01:49:40 +0100 Subject: [PATCH] fix(playerjoin): player are displayed in the correct order --- Assets/Scenes/ComputerView.unity | 2 +- Assets/Scripts/RoomManager.cs | 42 ++++++++++++++++++++------------ 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/Assets/Scenes/ComputerView.unity b/Assets/Scenes/ComputerView.unity index 8c417b0..561ceb2 100644 --- a/Assets/Scenes/ComputerView.unity +++ b/Assets/Scenes/ComputerView.unity @@ -1382,7 +1382,7 @@ MonoBehaviour: explanationPage: {fileID: 45150984} explanationCounter: {fileID: 1798182259} explanationTime: 4 - counterSFX: {fileID: 8300000, guid: 3beaa7f0d20a77649ba21959c91856f8, type: 3} + counterSFX: {fileID: 8300000, guid: 2ff45dbe56b6a4d08bfa7b103fa4effb, type: 3} waitingForPropositionsPage: {fileID: 1730465902} propositionCounter: {fileID: 1996258852} propositionTime: 60 diff --git a/Assets/Scripts/RoomManager.cs b/Assets/Scripts/RoomManager.cs index f280767..7ff3c24 100644 --- a/Assets/Scripts/RoomManager.cs +++ b/Assets/Scripts/RoomManager.cs @@ -16,6 +16,7 @@ public class RoomManager : MonoBehaviour /// public TextMeshProUGUI roomCodeLabel; public List waitingForPlayersLabels = new List(); + private Dictionary waitingPlayersById = new Dictionary(); public PromptList promptList; [Header("Explanation Page")] @@ -31,6 +32,7 @@ public class RoomManager : MonoBehaviour public float propositionTime = 60; public List waitingForPropositionsLabels = new List(); private DateTime endOfPropositionDate = DateTime.MinValue; + private bool allPlayersHasProposedTwoPictures = false; [Header("Other")] private Room myRoom = null; @@ -72,6 +74,7 @@ private void Update() if (myRoom == null) return; + //While Explanation State if (myRoom.currentState == (int)GameState.Explanation && endOfExplanationDate != DateTime.MinValue) { TimeSpan duration = endOfExplanationDate - DateTime.Now; @@ -85,11 +88,19 @@ private void Update() } } + //while MakeProposition State if (myRoom.currentState == (int)GameState.MakeProposition && endOfPropositionDate != DateTime.MinValue) { TimeSpan duration = endOfPropositionDate - DateTime.Now; propositionCounter.text = ((int)duration.TotalSeconds).ToString("D1"); + foreach (TextMeshProUGUI tmp in waitingForPropositionsLabels) + { + if (tmp.gameObject.activeSelf) + { + + } + } } } @@ -100,6 +111,7 @@ private void SendRoomState(GameState _newState) private void ResetAllPlayerLabels() { + waitingPlayersById.Clear(); for (int i = 0; i < waitingForPlayersLabels.Count; i++) { waitingForPlayersLabels[i].text = $"Waiting for P{i + 1}"; @@ -222,12 +234,18 @@ public void PlayerSendProposition(Proposition _proposition) /// /// Called when the first player clicked "Start" /// - public void HostStartGame() + public void HostHasStartedGame() { waitingForPropositionsPage.SetActive(true); waitingForPlayersPage.SetActive(false); endOfPropositionDate = DateTime.Now.AddSeconds(propositionTime); - AudioSource.PlayClipAtPoint(counterSFX, Vector3.zero); + + for (int i = 0; i < waitingForPropositionsLabels.Count; i++) + { + TextMeshProUGUI tmp = waitingForPropositionsLabels[i]; + tmp.gameObject.SetActive(i < myRoom.players.Count); + } + } /// @@ -350,9 +368,10 @@ private void OnRoomUpdate(object sender, ValueChangedEventArgs value) waitingForPlayersPage.SetActive(false); explanationPage.SetActive(true); endOfExplanationDate = DateTime.Now.AddSeconds(explanationTime); + AudioSource.PlayClipAtPoint(counterSFX, Vector3.zero); break; case (int)GameState.MakeProposition: - HostStartGame(); + HostHasStartedGame(); break; default: break; @@ -368,19 +387,12 @@ private void UpdateConnectedPlayerList(List _players) ResetAllPlayerLabels(); Debug.Log($"players count = {_players.Count}"); - for (int i = 0; i < _players.Count; i++) + List orderedPlayers = _players.OrderBy(x => x.creationDate).ToList(); + for (int i = 0; i < orderedPlayers.Count; i++) { - Debug.Log($"player {i} = {_players[i].name}"); - waitingForPlayersLabels[i].text = _players[i].name; + waitingPlayersById.Add(orderedPlayers[i].id, waitingForPlayersLabels[i]); + Debug.Log($"player {i} = {orderedPlayers[i].name}"); + waitingForPlayersLabels[i].text = orderedPlayers[i].name; } } - - [ContextMenu("Fake Player Connection")] - private void FakePlayerConnection() - { - Player temp = new Player("Momo"); - temp.id = Guid.NewGuid().ToString(); - temp.SetName("Momo"); - } - }