Snaparazzi/Assets/Scripts/PropositionHandler.cs

49 lines
1.8 KiB
C#
Raw Normal View History

2024-01-28 21:42:02 +00:00
using Firebase.Database;
using Newtonsoft.Json;
2024-01-28 16:34:11 +00:00
using System.Collections.Generic;
using System.Linq;
2024-02-27 20:25:16 +00:00
using System.Security.Policy;
2024-01-28 21:42:02 +00:00
using TMPro;
2024-01-28 16:34:11 +00:00
using UnityEngine;
using UnityEngine.UI;
2024-01-28 21:42:02 +00:00
public class PropositionHandler : MonoBehaviour
2024-01-28 16:34:11 +00:00
{
public GameManager gameManager;
public StorageManager storageManager;
2024-01-28 21:42:02 +00:00
public TextMeshProUGUI promptLabel;
public PromptList prompts;
2024-02-27 20:25:16 +00:00
public Sprite defaultImage;
2024-01-28 16:34:11 +00:00
public Image[] btns;
2024-02-27 20:25:16 +00:00
public void ShowPlayersProposition(Question currentQuestion)
2024-01-28 16:34:11 +00:00
{
2024-01-28 21:42:02 +00:00
List<Proposition> props = currentQuestion.propositions.Values.ToList();
string prompt = GameManager.Instance.myRoom.promptsLanguage == "en" ? prompts.GetPromptById(currentQuestion.promptId).en : prompts.GetPromptById(currentQuestion.promptId).fr;
promptLabel.text = prompt;
Debug.Log($"Showing Question ({currentQuestion.index}) : {prompt}");
2024-01-28 16:35:11 +00:00
for (int i = 0; i < 2; i++)
{
2024-01-29 20:01:09 +00:00
int index = i; // Capture la valeur de i pour cette it<69>ration
2024-02-27 20:40:21 +00:00
if(string.IsNullOrEmpty(props[i].photoUrl))
{
Debug.Log("One player did not send a proposition !", this);
2024-02-27 20:25:16 +00:00
btns[index].sprite = defaultImage; // Utilise l'index local au lieu de i
}
else
2024-01-28 16:35:11 +00:00
{
StorageManager.ConvertGoogleStorageURLToHttpsUrl(props[i].photoUrl, _httpURL =>
{
StartCoroutine(StorageManager.DownloadImage_Coroutine(_httpURL, (Texture texture) =>
{
Sprite sprite = Sprite.Create(texture as Texture2D, new Rect(0, 0, texture.width, texture.height), Vector2.zero);
btns[index].sprite = sprite; // Utilise l'index local au lieu de i
}));
});
}
2024-01-28 16:34:11 +00:00
}
2024-01-29 20:01:09 +00:00
2024-01-28 16:34:11 +00:00
}
}