using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
///
/// Class to display user info in the ChangeUserScreen scene
///
public class UserCard : MonoBehaviour
{
///
/// User to upload info into this card
///
public User user;
///
/// Callback to the UpdateSelection in the ChangeUserScreen
///
public UnityAction selectUser;
///
/// Callback to the update hte users container in the ChangeUserScreen scene
///
public UnityAction updateUserCardContainer;
///
/// Callback to display an error message in the ChangeUserScreen scene
///
public UnityAction displayError;
///
/// UI reference to the selectio button
///
public Button button;
///
/// UI reference to the avatar
///
public Image avatar;
///
/// UI reference to the username
///
public TMP_Text username;
///
/// Start is called before the first frame update
///
void Start()
{
avatar.sprite = user.GetAvatar();
username.text = user.GetUsername();
button.onClick.AddListener(selectUser);
}
///
/// Delete the user from the userlist
///
public void DeleteUser()
{
if (UserList.DeleteUser(user.GetUsername()))
{
// User is removed, update and save
updateUserCardContainer();
}
else
{
// User is not removed, display an error
displayError();
}
}
}