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;
|
2024-01-31 21:05:08 +00:00
|
|
|
using System.Linq;
|
2024-01-28 12:18:40 +00:00
|
|
|
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;
|
2024-02-27 20:25:16 +00:00
|
|
|
public Texture2D defaultTexture;
|
2024-01-28 12:18:40 +00:00
|
|
|
|
2024-01-31 21:05:08 +00:00
|
|
|
private Dictionary<Player, GameObject> currentVoters = new Dictionary<Player, GameObject>();
|
2024-01-28 12:18:40 +00:00
|
|
|
private Proposition proposition;
|
|
|
|
|
2024-02-27 20:25:16 +00:00
|
|
|
private void OnEnable()
|
|
|
|
{
|
|
|
|
picture.texture = defaultTexture;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetProposition(Proposition _proposition)
|
2024-01-28 12:18:40 +00:00
|
|
|
{
|
2024-01-31 21:05:08 +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-02-27 20:25:16 +00:00
|
|
|
else
|
|
|
|
picture.texture = defaultTexture;
|
|
|
|
|
|
|
|
ResetVoters();
|
|
|
|
}
|
2024-01-31 21:05:08 +00:00
|
|
|
|
2024-02-27 20:25:16 +00:00
|
|
|
public void SetNoProposition()
|
|
|
|
{
|
|
|
|
picture.texture = defaultTexture;
|
|
|
|
playerName.text = "Nobody";
|
|
|
|
ResetVoters();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ResetVoters()
|
|
|
|
{
|
|
|
|
foreach (var voters in currentVoters)
|
2024-01-31 21:05:08 +00:00
|
|
|
{
|
|
|
|
Destroy(voters.Value);
|
|
|
|
}
|
|
|
|
currentVoters.Clear();
|
2024-02-27 20:25:16 +00:00
|
|
|
|
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-29 22:00:10 +00:00
|
|
|
//Debug.Log($"Google Storage URL : {_gsUrl}");
|
2024-01-28 21:07:34 +00:00
|
|
|
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-29 22:00:10 +00:00
|
|
|
//Debug.Log("Set texture in the raw image");
|
2024-01-28 21:07:34 +00:00
|
|
|
picture.texture = _texture;
|
|
|
|
}));
|
2024-01-28 12:18:40 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public void UpdateVoters(List<Player> _newVoters)
|
|
|
|
{
|
2024-01-29 22:00:10 +00:00
|
|
|
//Debug.Log($"There are some new voters for {proposition.owner}'s proposition", this);
|
2024-01-28 12:18:40 +00:00
|
|
|
foreach (Player p in _newVoters)
|
|
|
|
{
|
2024-01-31 21:05:08 +00:00
|
|
|
if (!currentVoters.Keys.Contains(p))
|
2024-01-28 12:18:40 +00:00
|
|
|
{
|
2024-01-31 21:05:08 +00:00
|
|
|
PlayerSticker sticker = Instantiate(voterStickerPrefab, playerGrid).GetComponent<PlayerSticker>();
|
2024-02-01 21:45:02 +00:00
|
|
|
sticker.Initialize(p.name, RoomManager.Instance.myRoom.GetPlayerOrder(p));
|
2024-01-31 21:05:08 +00:00
|
|
|
currentVoters.Add(p, sticker.gameObject);
|
2024-01-28 12:18:40 +00:00
|
|
|
Debug.Log($"{p.name} has just voted for {proposition.owner.name}'s proposition.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|