79 lines
1.8 KiB
C#
79 lines
1.8 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>
|
|
/// Reference to the userlist
|
|
/// </summary>
|
|
public UserList userList;
|
|
|
|
/// <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.avatar;
|
|
username.text = user.username;
|
|
button.onClick.AddListener(selectUser);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Delete the user from the userlist
|
|
/// </summary>
|
|
public void DeleteUser()
|
|
{
|
|
if (userList.DeleteUser(user))
|
|
{
|
|
// User is removed, update and save
|
|
userList.Save();
|
|
updateUserCardContainer();
|
|
}
|
|
else
|
|
{
|
|
// User is not removed, display an error
|
|
displayError();
|
|
}
|
|
}
|
|
}
|