fix: voter stickers are reset between each vote
This commit is contained in:
parent
580dbbdca8
commit
74f732f1f3
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using Firebase.Extensions;
|
using Firebase.Extensions;
|
||||||
using Firebase.Storage;
|
using Firebase.Storage;
|
||||||
using TMPro;
|
using TMPro;
|
||||||
@ -15,17 +16,23 @@ public class PropositionFrame : MonoBehaviour
|
|||||||
public TextMeshProUGUI playerName;
|
public TextMeshProUGUI playerName;
|
||||||
public Transform playerGrid;
|
public Transform playerGrid;
|
||||||
|
|
||||||
private List<Player> currentVoters = new List<Player>();
|
private Dictionary<Player, GameObject> currentVoters = new Dictionary<Player, GameObject>();
|
||||||
private Proposition proposition;
|
private Proposition proposition;
|
||||||
|
|
||||||
public void Initialize(Proposition _proposition)
|
public void Initialize(Proposition _proposition)
|
||||||
{
|
{
|
||||||
//Debug.Log($"Initializing {_proposition.owner.name}'s proposition", this);
|
Debug.Log($"Initializing {_proposition.owner.name}'s proposition", this);
|
||||||
proposition = _proposition;
|
proposition = _proposition;
|
||||||
playerName.text = proposition.owner.name;
|
playerName.text = proposition.owner.name;
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(proposition.photoUrl))
|
if (!string.IsNullOrEmpty(proposition.photoUrl))
|
||||||
DisplayPicture(proposition.photoUrl);
|
DisplayPicture(proposition.photoUrl);
|
||||||
|
|
||||||
|
foreach(var voters in currentVoters)
|
||||||
|
{
|
||||||
|
Destroy(voters.Value);
|
||||||
|
}
|
||||||
|
currentVoters.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -48,13 +55,15 @@ private void DisplayPicture(string _gsUrl)
|
|||||||
public void UpdateVoters(List<Player> _newVoters)
|
public void UpdateVoters(List<Player> _newVoters)
|
||||||
{
|
{
|
||||||
//Debug.Log($"There are some new voters for {proposition.owner}'s proposition", this);
|
//Debug.Log($"There are some new voters for {proposition.owner}'s proposition", this);
|
||||||
|
int index = 0;
|
||||||
foreach (Player p in _newVoters)
|
foreach (Player p in _newVoters)
|
||||||
{
|
{
|
||||||
if (!currentVoters.Contains(p))
|
index++;
|
||||||
|
if (!currentVoters.Keys.Contains(p))
|
||||||
{
|
{
|
||||||
currentVoters.Add(p);
|
PlayerSticker sticker = Instantiate(voterStickerPrefab, playerGrid).GetComponent<PlayerSticker>();
|
||||||
VoterSticker sticker = Instantiate(voterStickerPrefab, playerGrid).GetComponent<VoterSticker>();
|
sticker.Initialize(p.name, index);
|
||||||
sticker.playerNameLabel.text = p.name;
|
currentVoters.Add(p, sticker.gameObject);
|
||||||
Debug.Log($"{p.name} has just voted for {proposition.owner.name}'s proposition.");
|
Debug.Log($"{p.name} has just voted for {proposition.owner.name}'s proposition.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user