From c290bbd1cbe0063dd6ba5e51b16f3bbf7319c48d Mon Sep 17 00:00:00 2001 From: Fangh Date: Tue, 27 Feb 2024 21:25:16 +0100 Subject: [PATCH] fix(#11] --- Assets/Prefabs/PropositionFrame.prefab | 1 + Assets/Scenes/PhoneView.unity | 1 + Assets/Scripts/GameManager.cs | 2 +- Assets/Scripts/PropositionFrame.cs | 25 +++++++++++++++++++++++-- Assets/Scripts/PropositionHandler.cs | 5 ++++- Assets/Scripts/VotingPage.cs | 4 ++-- 6 files changed, 32 insertions(+), 6 deletions(-) diff --git a/Assets/Prefabs/PropositionFrame.prefab b/Assets/Prefabs/PropositionFrame.prefab index 59ccd3a..1254493 100644 --- a/Assets/Prefabs/PropositionFrame.prefab +++ b/Assets/Prefabs/PropositionFrame.prefab @@ -321,3 +321,4 @@ MonoBehaviour: voterStickerPrefab: {fileID: 4312846972391547553, guid: 69942fa558cf34dfc91982c6bccef840, type: 3} playerName: {fileID: 782069874130417341} playerGrid: {fileID: 4509981124141486577} + defaultTexture: {fileID: 2800000, guid: 57d7dffbdddc24c959c3c072208cbafe, type: 3} diff --git a/Assets/Scenes/PhoneView.unity b/Assets/Scenes/PhoneView.unity index 176abde..116bf43 100644 --- a/Assets/Scenes/PhoneView.unity +++ b/Assets/Scenes/PhoneView.unity @@ -1388,6 +1388,7 @@ MonoBehaviour: storageManager: {fileID: 429358652} promptLabel: {fileID: 1545657113} prompts: {fileID: 11400000, guid: 21907abc84e40403ca34c4fb9ab30b06, type: 2} + defaultImage: {fileID: 21300000, guid: 49c6da5c3a35a6b47a96d6e9c2353c1e, type: 3} btns: - {fileID: 456700976} - {fileID: 589915591} diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index 1e80709..c6abf53 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -546,7 +546,7 @@ private void OnCurrentQuestionChanged(object sender, ValueChangedEventArgs onlin VotePicture.SetActive(true); WaitingOtherPlayers.SetActive(false); endOfViewDate = DateTime.Now.AddSeconds(20); - VotePicture.GetComponent().ShowQuestion(q); + VotePicture.GetComponent().ShowPlayersProposition(q); } } diff --git a/Assets/Scripts/PropositionFrame.cs b/Assets/Scripts/PropositionFrame.cs index c6d3d4a..c51b52c 100644 --- a/Assets/Scripts/PropositionFrame.cs +++ b/Assets/Scripts/PropositionFrame.cs @@ -15,11 +15,17 @@ public class PropositionFrame : MonoBehaviour public GameObject voterStickerPrefab; public TextMeshProUGUI playerName; public Transform playerGrid; + public Texture2D defaultTexture; private Dictionary currentVoters = new Dictionary(); private Proposition proposition; - public void Initialize(Proposition _proposition) + private void OnEnable() + { + picture.texture = defaultTexture; + } + + public void SetProposition(Proposition _proposition) { Debug.Log($"Initializing {_proposition.owner.name}'s proposition", this); proposition = _proposition; @@ -27,12 +33,27 @@ public void Initialize(Proposition _proposition) if (!string.IsNullOrEmpty(proposition.photoUrl)) DisplayPicture(proposition.photoUrl); + else + picture.texture = defaultTexture; - foreach(var voters in currentVoters) + ResetVoters(); + } + + public void SetNoProposition() + { + picture.texture = defaultTexture; + playerName.text = "Nobody"; + ResetVoters(); + } + + private void ResetVoters() + { + foreach (var voters in currentVoters) { Destroy(voters.Value); } currentVoters.Clear(); + } /// diff --git a/Assets/Scripts/PropositionHandler.cs b/Assets/Scripts/PropositionHandler.cs index 2e80919..c1a0457 100644 --- a/Assets/Scripts/PropositionHandler.cs +++ b/Assets/Scripts/PropositionHandler.cs @@ -2,6 +2,7 @@ using Newtonsoft.Json; using System.Collections.Generic; using System.Linq; +using System.Security.Policy; using TMPro; using UnityEngine; using UnityEngine.UI; @@ -12,9 +13,10 @@ public class PropositionHandler : MonoBehaviour public StorageManager storageManager; public TextMeshProUGUI promptLabel; public PromptList prompts; + public Sprite defaultImage; public Image[] btns; - public void ShowQuestion(Question currentQuestion) + public void ShowPlayersProposition(Question currentQuestion) { List props = currentQuestion.propositions.Values.ToList(); string enPrompt = prompts.GetPromptById(currentQuestion.promptId).en; @@ -26,6 +28,7 @@ public void ShowQuestion(Question currentQuestion) if(props[i].photoUrl == null) { Debug.Log("One player did not send a proposition !", this); + btns[index].sprite = defaultImage; // Utilise l'index local au lieu de i } else { diff --git a/Assets/Scripts/VotingPage.cs b/Assets/Scripts/VotingPage.cs index 0894796..65de99d 100644 --- a/Assets/Scripts/VotingPage.cs +++ b/Assets/Scripts/VotingPage.cs @@ -152,12 +152,12 @@ private void InitializeProposition(PropositionFrame proposition, Proposition pro { if (propositionData != null) { - proposition.Initialize(propositionData); + proposition.SetProposition(propositionData); } else { Debug.Log("User has given no proposition", this); - // Handle the case when there is no proposition + proposition.SetNoProposition(); } }