81 lines
2.3 KiB
C#
81 lines
2.3 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class QuestionHandler : MonoBehaviour
|
|
{
|
|
public GameObject managers;
|
|
public Button submitButton;
|
|
public TextMeshProUGUI explainText;
|
|
public PromptList promptList;
|
|
|
|
private GameManager gameManager;
|
|
private List<Question> player2questions;
|
|
private int currentQuestion = 0;
|
|
|
|
void OnEnable()
|
|
{
|
|
gameManager = managers.GetComponent<GameManager>();
|
|
player2questions = gameManager.myRoom.GetQuestionsByPlayer(gameManager.currentPlayer);
|
|
Redraw(currentQuestion);
|
|
}
|
|
|
|
void OnDisable()
|
|
{
|
|
player2questions = null;
|
|
currentQuestion = 0;
|
|
}
|
|
|
|
void Redraw(int currentQuestion)
|
|
{
|
|
Prompt prompt = promptList.prompts.Find(x => x.id == player2questions[currentQuestion].promptId);
|
|
//Debug.Log(JsonUtility.ToJson(prompt));
|
|
explainText.SetText(prompt.en);
|
|
|
|
CameraManager cameraManager = gameObject.GetComponent<CameraManager>();
|
|
cameraManager.WebcamResume();
|
|
}
|
|
|
|
int GetPropRef(Player player)
|
|
{
|
|
return gameManager.myRoom.questions[currentQuestion].propositions.First(x => x.Value.owner.id == player.id).Key;
|
|
}
|
|
|
|
public void OnSubmitButton()
|
|
{
|
|
submitButton.interactable = false;
|
|
submitButton.GetComponent<TextMeshProUGUI>().text = "Uploading...";
|
|
|
|
managers.GetComponent<StorageManager>().UploadPhoto(
|
|
gameManager.myRoom.code,
|
|
gameManager.currentPlayer.id,
|
|
currentQuestion,
|
|
GetPropRef(gameManager.currentPlayer),
|
|
succeed =>
|
|
{
|
|
if(!succeed)
|
|
{
|
|
Debug.LogError("Photo upload failed. please do something", this);
|
|
return;
|
|
}
|
|
|
|
if (currentQuestion == 1)
|
|
{
|
|
gameManager.WaitForPlayers();
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
submitButton.interactable = true;
|
|
submitButton.GetComponent<TextMeshProUGUI>().text = "Submit";
|
|
currentQuestion++;
|
|
Redraw(currentQuestion);
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
}
|