if all players push there 2 propositions, it goes to next page auto

This commit is contained in:
Fangh 2024-01-29 20:18:09 +01:00
parent dec3b18a0e
commit 8ed7abbba2
4 changed files with 36 additions and 16 deletions

View File

@ -2719,7 +2719,7 @@ MonoBehaviour:
is asked.\n\n Are you Ready ?"
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 72af27804d5aa49408430b4b2500f877, type: 2}
m_sharedMaterial: {fileID: 8890805173838430465, guid: 72af27804d5aa49408430b4b2500f877, type: 2}
m_sharedMaterial: {fileID: 2100000, guid: 9fb4d071241c54841ab116886c83b585, type: 2}
m_fontSharedMaterials: []
m_fontMaterial: {fileID: 0}
m_fontMaterials: []
@ -5997,7 +5997,7 @@ MonoBehaviour:
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 21300000, guid: 93cf115964d3bfa45ba83a1f465565f0, type: 3}
m_Sprite: {fileID: 21300000, guid: c61e5b2ecf71bd44fa029b05c6f7d0b2, type: 3}
m_Type: 0
m_PreserveAspect: 0
m_FillCenter: 1
@ -7937,7 +7937,7 @@ MonoBehaviour:
m_text: 3
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 72af27804d5aa49408430b4b2500f877, type: 2}
m_sharedMaterial: {fileID: 8890805173838430465, guid: 72af27804d5aa49408430b4b2500f877, type: 2}
m_sharedMaterial: {fileID: 2100000, guid: 9fb4d071241c54841ab116886c83b585, type: 2}
m_fontSharedMaterials: []
m_fontMaterial: {fileID: 0}
m_fontMaterials: []
@ -9079,7 +9079,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 75, y: 15.000061}
m_AnchoredPosition: {x: 75, y: 15}
m_SizeDelta: {x: 150, y: 512}
m_Pivot: {x: 0.5, y: 1}
--- !u!114 &1901141296

View File

@ -3,6 +3,7 @@
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using UnityEngine;
[Serializable]
[JsonObject]
@ -54,9 +55,9 @@ public List<Question> GetQuestionsByPlayer(Player player)
{
List<Question> playerQuestions = new();
foreach (Question question in new List<Question>(questions.Values))
foreach (Question question in questions.Values.ToList())
{
foreach (Proposition proposition in new List<Proposition>(question.propositions.Values))
foreach (Proposition proposition in question.propositions.Values.ToList())
{
if (proposition.owner.id == player.id)
{
@ -79,9 +80,9 @@ public List<Proposition> GetPropositionsByPlayer(Player player)
{
List<Proposition> playerPropositions = new();
foreach (Question question in new List<Question>(questions.Values))
foreach (Question question in questions.Values.ToList())
{
foreach (Proposition proposition in new List<Proposition>(question.propositions.Values))
foreach (Proposition proposition in question.propositions.Values.ToList())
{
if (proposition.owner.id == player.id)
{

View File

@ -244,6 +244,7 @@ private void OnRoomUpdate(object sender, ValueChangedEventArgs value)
case (int)GameState.Explanation:
break;
case (int)GameState.MakeProposition:
waitForPropositionsPage.OnRoomUpdate(myRoom);
break;
default:
break;

View File

@ -27,17 +27,12 @@ public void Initialize(Room _myRoom, Action _onPropositionFinish)
ShowPlayerLabels();
}
private void ShowPlayerLabels()
public void OnRoomUpdate(Room _myRoom)
{
//display only correct numbers of labels
for (int i = 0; i < playerLabels.Count; i++)
{
TextMeshProUGUI tmp = playerLabels[i];
tmp.gameObject.SetActive(i < myRoom.players.Count);
Debug.Log($"toggling {tmp.gameObject.name} accordingly to its player connection");
}
myRoom = _myRoom;
}
// Update is called once per frame
void Update()
{
@ -58,6 +53,24 @@ void Update()
propositionCounter.text = ((int)duration.TotalSeconds).ToString("D1");
}
}
private void ShowPlayerLabels()
{
//display only correct numbers of labels and set names
List<Player> players = myRoom.GetOrderedPlayerList();
for (int i = 0; i < playerLabels.Count; i++)
{
if (i < players.Count)
{
playerLabels[i].gameObject.SetActive(true);
playerLabels[i].text = players[i].name;
}
else
{
playerLabels[i].gameObject.SetActive(false);
}
//Debug.Log($"toggling {playerLabels[i].gameObject.name} accordingly to its player connection");
}
}
private void CheckPlayersWhoHaveProposed()
{
@ -68,6 +81,8 @@ private void CheckPlayersWhoHaveProposed()
bool playerHasAnsweredBothProposition = true;
Proposition[] propositions = myRoom.GetPropositionsByPlayer(player).ToArray();
//Debug.Log($"I found {propositions.Length} propositions for {player.name}", this);
if (propositions.Length < 2)
playerHasAnsweredBothProposition = false;
else
@ -76,6 +91,7 @@ private void CheckPlayersWhoHaveProposed()
{
if (string.IsNullOrEmpty(propositions[i].photoUrl))
{
//Debug.Log($"{player.name}'s proposition {i} has no photoURL", this);
playerHasAnsweredBothProposition = false;
}
}
@ -83,9 +99,11 @@ private void CheckPlayersWhoHaveProposed()
if (playerHasAnsweredBothProposition)
{
Debug.Log($"{player.name}'s has answered both propositions !", this);
playerLabels.Find(x => x.text == player.name).color = Color.green;
playersIdWhoHaveProposed.Add(player.id);
}
Debug.Log($"{playersIdWhoHaveProposed.Count}/{myRoom.players.Count} players have answered.", this);
if(playersIdWhoHaveProposed.Count == myRoom.players.Count)
{
allPlayersHasProposedTwoPictures = true;