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