fix(playerjoin): player are displayed in the correct order

This commit is contained in:
Morgan - 6 Freedom 2024-01-28 01:49:40 +01:00
parent 684c4f98af
commit 781b7d88c9
2 changed files with 28 additions and 16 deletions

View File

@ -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

View File

@ -16,6 +16,7 @@ public class RoomManager : MonoBehaviour
/// </summary>
public TextMeshProUGUI roomCodeLabel;
public List<TextMeshProUGUI> waitingForPlayersLabels = new List<TextMeshProUGUI>();
private Dictionary<string, TextMeshProUGUI> waitingPlayersById = new Dictionary<string, TextMeshProUGUI>();
public PromptList promptList;
[Header("Explanation Page")]
@ -31,6 +32,7 @@ public class RoomManager : MonoBehaviour
public float propositionTime = 60;
public List<TextMeshProUGUI> waitingForPropositionsLabels = new List<TextMeshProUGUI>();
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)
/// <summary>
/// Called when the first player clicked "Start"
/// </summary>
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);
}
}
/// <summary>
@ -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<Player> _players)
ResetAllPlayerLabels();
Debug.Log($"players count = {_players.Count}");
for (int i = 0; i < _players.Count; i++)
List<Player> 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");
}
}