2024-01-28 16:07:54 +00:00
|
|
|
using System;
|
2024-01-28 12:18:40 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using Firebase.Extensions;
|
|
|
|
using Firebase.Storage;
|
|
|
|
using TMPro;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.Networking;
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
public class PropositionFrame : MonoBehaviour
|
|
|
|
{
|
|
|
|
public RawImage picture;
|
|
|
|
public GameObject voterStickerPrefab;
|
|
|
|
public TextMeshProUGUI playerName;
|
|
|
|
public Transform playerGrid;
|
|
|
|
|
|
|
|
private List<Player> currentVoters = new List<Player>();
|
|
|
|
private Proposition proposition;
|
|
|
|
|
|
|
|
public void Initialize(Proposition _proposition)
|
|
|
|
{
|
2024-01-28 17:12:05 +00:00
|
|
|
Debug.Log($"Initializing {_proposition.owner.name}'s proposition", this);
|
2024-01-28 12:18:40 +00:00
|
|
|
proposition = _proposition;
|
|
|
|
playerName.text = proposition.owner.name;
|
2024-01-28 15:23:53 +00:00
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(proposition.photoUrl))
|
|
|
|
DisplayPicture(proposition.photoUrl);
|
2024-01-28 12:18:40 +00:00
|
|
|
}
|
|
|
|
|
2024-01-28 21:07:34 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Url is Google bucket URL. We
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="_gsUrl"></param>
|
|
|
|
private void DisplayPicture(string _gsUrl)
|
2024-01-28 12:18:40 +00:00
|
|
|
{
|
2024-01-28 21:07:34 +00:00
|
|
|
Debug.Log($"Google Storage URL : {_gsUrl}");
|
|
|
|
StorageManager.ConvertGoogleStorageURLToHttpsUrl(_gsUrl, _url =>
|
2024-01-28 12:18:40 +00:00
|
|
|
{
|
2024-01-28 21:07:34 +00:00
|
|
|
StartCoroutine(StorageManager.DownloadImage_Coroutine(_url, _texture =>
|
2024-01-28 12:18:40 +00:00
|
|
|
{
|
2024-01-28 21:07:34 +00:00
|
|
|
Debug.Log("Set texture in the raw image");
|
|
|
|
picture.texture = _texture;
|
|
|
|
}));
|
2024-01-28 12:18:40 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public void UpdateVoters(List<Player> _newVoters)
|
|
|
|
{
|
|
|
|
Debug.Log($"There are some new voters for {proposition.owner}'s proposition", this);
|
|
|
|
foreach (Player p in _newVoters)
|
|
|
|
{
|
|
|
|
if (!currentVoters.Contains(p))
|
|
|
|
{
|
|
|
|
currentVoters.Add(p);
|
|
|
|
VoterSticker sticker = Instantiate(voterStickerPrefab, playerGrid).GetComponent<VoterSticker>();
|
|
|
|
sticker.playerNameLabel.text = p.name;
|
|
|
|
Debug.Log($"{p.name} has just voted for {proposition.owner.name}'s proposition.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-01-28 21:07:34 +00:00
|
|
|
|
|
|
|
[ContextMenu("Debug Download image")]
|
|
|
|
private void Debug_DownloadImage()
|
|
|
|
{
|
|
|
|
StartCoroutine(DownloadImage("https://firebasestorage.googleapis.com/v0/b/ggj2024-5cb41.appspot.com/o/0278%2F63ae32b0-8371-4a7a-84a0-e1a97328fc09%2F10a5127b-12d4-48ca-b94c-1cb920a43529.png?alt=media&token=d7e53d8a-d5b4-40f9-847d-224ed2d683dc",
|
|
|
|
texture =>
|
|
|
|
{
|
|
|
|
Debug.Log(texture.dimension);
|
|
|
|
}));
|
|
|
|
|
|
|
|
}
|
2024-01-28 12:18:40 +00:00
|
|
|
}
|