Resolve WES-95 "User progress"
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
@@ -18,6 +17,11 @@ public class ChangeUserScreen : MonoBehaviour
|
||||
/// </summary>
|
||||
public Transform usersContainer;
|
||||
|
||||
/// <summary>
|
||||
/// UI Reference to the error GameObject to display an error message
|
||||
/// </summary>
|
||||
public GameObject error;
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the user list
|
||||
/// </summary>
|
||||
@@ -38,6 +42,20 @@ public class ChangeUserScreen : MonoBehaviour
|
||||
/// </summary>
|
||||
void Start()
|
||||
{
|
||||
error.SetActive(false);
|
||||
DisplayUsers();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add all users to the container to display them
|
||||
/// </summary>
|
||||
private void DisplayUsers()
|
||||
{
|
||||
foreach (Transform child in usersContainer)
|
||||
{
|
||||
Destroy(child.gameObject);
|
||||
}
|
||||
|
||||
List<User> users = userList.GetUsers();
|
||||
currentUserIndex = userList.GetCurrentUserIndex();
|
||||
for (int i = 0; i < users.Count; i++)
|
||||
@@ -49,18 +67,18 @@ public class ChangeUserScreen : MonoBehaviour
|
||||
|
||||
// Store value of i so we can use it the callback (else it would get the value of sprites.Count)
|
||||
int x = i;
|
||||
// Add onClick callback
|
||||
instance.GetComponent<Button>().onClick.AddListener(() => UpdateSelection(x));
|
||||
// Set username
|
||||
instance.GetComponentInChildren<TMP_Text>().text = user.username;
|
||||
// Add user content
|
||||
UserCard card = instance.GetComponent<UserCard>();
|
||||
card.user = user;
|
||||
card.selectUser = () => UpdateSelection(x);
|
||||
card.updateUserCardContainer = DisplayUsers;
|
||||
card.displayError = () => error.SetActive(true);
|
||||
|
||||
// Store reference to image for fancy coloring
|
||||
Image background = instance.GetComponent<Image>();
|
||||
userBackgrounds.Add(background);
|
||||
// Set background color
|
||||
background.color = i == currentUserIndex ? Color.blue : Color.gray;
|
||||
// Find correct component for setting the sprite
|
||||
instance.transform.Find("Avatar").GetComponent<Image>().sprite = user.avatar;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user