diff --git a/Assets/Scenes/PhoneView.unity b/Assets/Scenes/PhoneView.unity index 2d8549f..0f604a3 100644 --- a/Assets/Scenes/PhoneView.unity +++ b/Assets/Scenes/PhoneView.unity @@ -2644,8 +2644,8 @@ MonoBehaviour: m_fontMaterials: [] m_fontColor32: serializedVersion: 2 - rgba: 4294967295 - m_fontColor: {r: 1, g: 1, b: 1, a: 1} + rgba: 4278253567 + m_fontColor: {r: 1, g: 0.97053784, b: 0, a: 1} m_enableVertexGradient: 0 m_colorMode: 3 m_fontColorGradient: @@ -4193,6 +4193,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: managers: {fileID: 429358648} + submitButton: {fileID: 885941125} explainText: {fileID: 2139867527} promptList: {fileID: 11400000, guid: 21907abc84e40403ca34c4fb9ab30b06, type: 2} --- !u!1 &1202782726 diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index 105a8f9..9dcccee 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -281,8 +281,11 @@ public void StartGame() private void OnRoomUpdate(object sender, ValueChangedEventArgs e) { Debug.Log("begin OnRoomUpdate"); + GameState lastState = (GameState)myRoom.currentState; + try { + if (e?.Snapshot?.GetRawJsonValue() != null) { string JSON = e.Snapshot.GetRawJsonValue(); @@ -299,6 +302,33 @@ private void OnRoomUpdate(object sender, ValueChangedEventArgs e) Debug.Log("myroom is null"); return; } + + if(myRoom.currentState != (int)lastState) + { + OnNewGameState(); + } + else + { + //call this every time we are on this state + switch (myRoom.currentState) + { + case (int)GameState.WaitingForOtherPlayersToJoin: + { + CheckIfIAmTheFirst(myRoom.GetPlayerList()); + UpdateDisplayedListUser(myRoom.GetPlayerList()); + break; + } + default: + break; + } + } + } + + /// + /// Call this when Game state change + /// + private void OnNewGameState() + { switch (myRoom.currentState) { case (int)GameState.EnteringName: @@ -309,14 +339,6 @@ private void OnRoomUpdate(object sender, ValueChangedEventArgs e) HomeConnection.SetActive(true); } - break; - } - case (int)GameState.WaitingForOtherPlayersToJoin: - { - - CheckIfIAmTheFirst(myRoom.GetPlayerList()); - UpdateDisplayedListUser(myRoom.GetPlayerList()); - break; } case (int)GameState.Explanation: @@ -328,7 +350,6 @@ private void OnRoomUpdate(object sender, ValueChangedEventArgs e) WaitingRoom.SetActive(false); BeforeStart.SetActive(true); endOfViewDate = DateTime.Now.AddSeconds(4); - break; } case (int)GameState.MakeProposition: @@ -338,9 +359,7 @@ private void OnRoomUpdate(object sender, ValueChangedEventArgs e) BeforeStart.SetActive(false); TakePicture.SetActive(true); endOfViewDate = DateTime.Now.AddSeconds(60); - } - break; } case (int)GameState.PropositionsSent: @@ -477,7 +496,10 @@ public void onClickNewPlayers() private void OnCurrentQuestionChanged(object sender, ValueChangedEventArgs onlineValue) { - Question q = myRoom.questions[onlineValue.Snapshot.Value.ConvertTo()]; + int questionId = onlineValue.Snapshot.Value.ConvertTo(); + Debug.Log($"new question ! Q{(onlineValue.Snapshot.Value.ConvertTo())}"); + + Question q = myRoom.questions[questionId]; if (WaitingOtherPlayers.activeInHierarchy) { diff --git a/Assets/Scripts/PropositionHandler.cs b/Assets/Scripts/PropositionHandler.cs index 2495f70..5542af2 100644 --- a/Assets/Scripts/PropositionHandler.cs +++ b/Assets/Scripts/PropositionHandler.cs @@ -16,8 +16,11 @@ public class PropositionHandler : MonoBehaviour public void ShowQuestion(Question currentQuestion) { + List props = currentQuestion.propositions.Values.ToList(); - promptLabel.text = prompts.GetPromptById(currentQuestion.promptId).en; + string enPrompt = prompts.GetPromptById(currentQuestion.promptId).en; + promptLabel.text = enPrompt; + Debug.Log($"Showing Question ({currentQuestion.index}) : {enPrompt}"); for (int i = 0; i < 2; i++) { int index = i; // Capture la valeur de i pour cette itération diff --git a/Assets/Scripts/QuestionHandler.cs b/Assets/Scripts/QuestionHandler.cs index 5ed7fbe..e141cd3 100644 --- a/Assets/Scripts/QuestionHandler.cs +++ b/Assets/Scripts/QuestionHandler.cs @@ -2,13 +2,16 @@ using System.Linq; using TMPro; using UnityEngine; +using UnityEngine.UI; public class QuestionHandler : MonoBehaviour { public GameObject managers; - private GameManager gameManager; + public Button submitButton; public TextMeshProUGUI explainText; public PromptList promptList; + + private GameManager gameManager; private List player2questions; private int currentQuestion = 0; @@ -42,34 +45,36 @@ int GetPropRef(Player player) public void OnSubmitButton() { + submitButton.interactable = false; + submitButton.GetComponent().text = "Uploading..."; + managers.GetComponent().UploadPhoto( gameManager.myRoom.code, gameManager.currentPlayer.id, currentQuestion, - GetPropRef(gameManager.currentPlayer)); + GetPropRef(gameManager.currentPlayer), succeed => + { + if(!succeed) + { + Debug.LogError("Photo upload failed. please do something", this); + return; + } - if (currentQuestion == 1) - { - gameManager.myRoom.currentState = (int)GameState.PropositionsSent; - gameManager.WaitForPlayers(); - return; - } - else - { - currentQuestion++; - Redraw(currentQuestion); - } - } - - // Start is called before the first frame update - void Start() - { + if (currentQuestion == 1) + { + gameManager.myRoom.currentState = (int)GameState.PropositionsSent; + gameManager.WaitForPlayers(); + return; + } + else + { + submitButton.interactable = true; + submitButton.GetComponent().text = "Submit"; + currentQuestion++; + Redraw(currentQuestion); + } + }); } - // Update is called once per frame - void Update() - { - - } } diff --git a/Assets/Scripts/StorageManager.cs b/Assets/Scripts/StorageManager.cs index fb02a5e..9f5c8d2 100644 --- a/Assets/Scripts/StorageManager.cs +++ b/Assets/Scripts/StorageManager.cs @@ -39,7 +39,7 @@ void Update() } - public void UploadPhoto(string roomCode, string playerId, int question, int proposition) + public void UploadPhoto(string roomCode, string playerId, int question, int proposition, Action callback_OnPhotoUploaded) { Texture2D photo = cameraManager.GetPhoto(); byte[] photoBytes = ImageConversion.EncodeToJPG(photo); @@ -53,11 +53,13 @@ public void UploadPhoto(string roomCode, string playerId, int question, int prop { if (task.IsFaulted || task.IsCanceled) { + callback_OnPhotoUploaded?.Invoke(false); Debug.LogException(task.Exception); // Uh-oh, an error occurred! } else { + callback_OnPhotoUploaded?.Invoke(true); realtimeDB .Child("rooms") .Child(roomCode)