2024-01-28 01:40:12 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using TMPro;
|
|
|
|
using UnityEngine;
|
2024-01-29 21:10:52 +00:00
|
|
|
using UnityEngine.UI;
|
2024-01-28 01:40:12 +00:00
|
|
|
|
|
|
|
public class QuestionHandler : MonoBehaviour
|
|
|
|
{
|
|
|
|
public GameObject managers;
|
2024-01-29 21:10:52 +00:00
|
|
|
public Button submitButton;
|
2024-01-28 01:40:12 +00:00
|
|
|
public TextMeshProUGUI explainText;
|
|
|
|
public PromptList promptList;
|
2024-01-29 21:10:52 +00:00
|
|
|
|
|
|
|
private GameManager gameManager;
|
2024-01-28 01:40:12 +00:00
|
|
|
private List<Question> player2questions;
|
2024-01-29 19:50:32 +00:00
|
|
|
private int currentQuestion = 0;
|
2024-01-28 01:40:12 +00:00
|
|
|
|
|
|
|
void OnEnable()
|
|
|
|
{
|
2024-01-28 15:28:04 +00:00
|
|
|
gameManager = managers.GetComponent<GameManager>();
|
2024-01-28 01:40:12 +00:00
|
|
|
player2questions = gameManager.myRoom.GetQuestionsByPlayer(gameManager.currentPlayer);
|
2024-01-28 15:19:30 +00:00
|
|
|
Redraw(currentQuestion);
|
2024-01-28 01:40:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OnDisable()
|
|
|
|
{
|
|
|
|
player2questions = null;
|
2024-01-29 19:50:32 +00:00
|
|
|
currentQuestion = 0;
|
2024-01-28 01:40:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Redraw(int currentQuestion)
|
|
|
|
{
|
2024-01-29 19:50:32 +00:00
|
|
|
Prompt prompt = promptList.prompts.Find(x => x.id == player2questions[currentQuestion].promptId);
|
2024-01-29 21:19:22 +00:00
|
|
|
//Debug.Log(JsonUtility.ToJson(prompt));
|
2024-01-28 01:40:12 +00:00
|
|
|
explainText.SetText(prompt.en);
|
|
|
|
|
|
|
|
CameraManager cameraManager = gameObject.GetComponent<CameraManager>();
|
|
|
|
cameraManager.WebcamResume();
|
|
|
|
}
|
|
|
|
|
2024-01-28 14:42:32 +00:00
|
|
|
int GetPropRef(Player player)
|
2024-01-28 01:40:12 +00:00
|
|
|
{
|
2024-01-29 19:50:32 +00:00
|
|
|
return gameManager.myRoom.questions[currentQuestion].propositions.First(x => x.Value.owner.id == player.id).Key;
|
2024-01-28 01:40:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void OnSubmitButton()
|
|
|
|
{
|
2024-01-29 21:10:52 +00:00
|
|
|
submitButton.interactable = false;
|
|
|
|
submitButton.GetComponent<TextMeshProUGUI>().text = "Uploading...";
|
|
|
|
|
2024-01-29 19:50:32 +00:00
|
|
|
managers.GetComponent<StorageManager>().UploadPhoto(
|
2024-01-28 01:40:12 +00:00
|
|
|
gameManager.myRoom.code,
|
|
|
|
gameManager.currentPlayer.id,
|
2024-01-29 19:50:32 +00:00
|
|
|
currentQuestion,
|
2024-01-29 21:19:22 +00:00
|
|
|
GetPropRef(gameManager.currentPlayer),
|
|
|
|
succeed =>
|
2024-01-29 21:10:52 +00:00
|
|
|
{
|
|
|
|
if(!succeed)
|
|
|
|
{
|
|
|
|
Debug.LogError("Photo upload failed. please do something", this);
|
|
|
|
return;
|
|
|
|
}
|
2024-01-28 01:40:12 +00:00
|
|
|
|
2024-01-29 21:10:52 +00:00
|
|
|
if (currentQuestion == 1)
|
|
|
|
{
|
|
|
|
gameManager.myRoom.currentState = (int)GameState.PropositionsSent;
|
|
|
|
gameManager.WaitForPlayers();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
submitButton.interactable = true;
|
|
|
|
submitButton.GetComponent<TextMeshProUGUI>().text = "Submit";
|
|
|
|
currentQuestion++;
|
|
|
|
Redraw(currentQuestion);
|
|
|
|
}
|
|
|
|
});
|
2024-01-28 15:28:04 +00:00
|
|
|
|
2024-01-28 01:40:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|