Resolve WES-192 "Fix progress screen"

This commit is contained in:
Dries Van Schuylenbergh
2023-05-04 09:09:49 +00:00
parent 259259ac9c
commit 89f343780a
34 changed files with 4330 additions and 496 deletions

View File

@@ -1,5 +1,3 @@
using System;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
@@ -25,60 +23,24 @@ public class UserProgressScreen : MonoBehaviour
public Image avatar;
/// <summary>
/// UI reference to the user total playtime
/// Reference to the courses panel
/// </summary>
public TMP_Text playtime;
public GameObject coursesPanel;
/// <summary>
/// Prefab of the highscore marker to display on the graph
/// Reference to the minigame panel
/// </summary>
public GameObject highscoreMarker;
public GameObject minigamesPanel;
/// <summary>
/// Prefab of a course card
/// Reference to the courses tab button (to set nice color)
/// </summary>
public GameObject courseCardPrefab;
public Image coursesTabButton;
/// <summary>
/// UI reference to the container holding all course cards
/// Reference to the minigames tab button (to set nice color)
/// </summary>
public GameObject coursesContainer;
/// <summary>
/// UI reference to the message that displays when no course progress is present
/// </summary>
public GameObject emptyCourses;
/// <summary>
/// Prefab of a minigame card
/// </summary>
public GameObject minigameCardPrefab;
/// <summary>
/// UI reference to the container holding all the minigame cards
/// </summary>
public GameObject minigamesContainer;
/// <summary>
/// UI reference to the message that displays when no minigame progress is present
/// </summary>
public GameObject emptyMinigames;
/// <summary>
/// UI reference to the plot
/// </summary>
public RawImage progressGraph;
/// <summary>
/// Current selected activity draw to the graph
/// </summary>
private int selectedActivity = -1;
/// <summary>
/// List of activity backgrounds and indices
/// </summary>
private List<Tuple<Image, int>> activities = new List<Tuple<Image, int>>();
public Image minigamesTabButton;
/// <summary>
/// Start is called before the first frame update
@@ -92,98 +54,29 @@ public class UserProgressScreen : MonoBehaviour
// Set correct displayed items
username.text = user.GetUsername();
avatar.sprite = user.GetAvatar();
playtime.text = $"Totale speeltijd: {user.GetPlaytime().ToString("0.00")}";
// Set graph inactive
progressGraph.gameObject.SetActive(false);
int i = 0;
// Display courses
var courses = user.GetCourses();
coursesContainer.SetActive(courses.Count > 0);
emptyCourses.SetActive(courses.Count <= 0);
foreach (var courseProgress in courses)
{
// Create instance of prefab
GameObject instance = GameObject.Instantiate(courseCardPrefab, coursesContainer.transform.Find("Viewport").Find("Content").transform);
int j = i++;
// Initialize card
CourseProgressCard cpc = instance.GetComponent<CourseProgressCard>();
cpc.courseProgress = courseProgress;
cpc.selectActivity = () => UpdateSelection(j);
// Store reference to background so we can apply fancy coloring
Image background = instance.GetComponent<Image>();
background.color = Color.gray;
activities.Add(Tuple.Create(background, (int)courseProgress.courseIndex));
}
// Display minigames
var minigames = user.GetMinigames();
minigamesContainer.SetActive(minigames.Count > 0);
emptyMinigames.SetActive(minigames.Count <= 0);
foreach (var minigameProgress in minigames)
{
// Create instance of prefab
GameObject instance = GameObject.Instantiate(minigameCardPrefab, minigamesContainer.transform.Find("Viewport").Find("Content").transform);
int j = i++;
// Initialize card
MinigameProgressCard mpc = instance.GetComponent<MinigameProgressCard>();
mpc.minigameProgress = minigameProgress;
mpc.selectActivity = () => UpdateSelection(j);
// Store reference to background so we can apply fancy coloring
Image background = instance.GetComponent<Image>();
background.color = Color.gray;
activities.Add(Tuple.Create(background, (int)minigameProgress.minigameIndex));
}
DisplayCourses();
}
/// <summary>
/// Update the current selected activity
/// Switch to displaying the courses
/// </summary>
/// <param name="newActivity">Index to the new activity</param>
private void UpdateSelection(int newActivity)
public void DisplayCourses()
{
if (selectedActivity < 0)
{
progressGraph.gameObject.SetActive(true);
}
else
{
activities[selectedActivity].Item1.color = Color.gray;
}
selectedActivity = newActivity;
activities[selectedActivity].Item1.color = Color.blue;
if (selectedActivity < user.GetCourses().Count)
{
// TODO: create a better graph
//DisplayCourseGraph((CourseIndex)activities[selectedActivity].Item2);
// For now: just deactivate graph rendering
progressGraph.gameObject.SetActive(false);
}
else
{
DisplayMinigameGraph((MinigameIndex)activities[selectedActivity].Item2);
// TODO: remove line, this is only because courses deactivates the graph
progressGraph.gameObject.SetActive(true);
}
coursesPanel.SetActive(true);
coursesTabButton.color = Color.blue;
minigamesPanel.SetActive(false);
minigamesTabButton.color = Color.gray;
}
/// <summary>
/// Plot the graph of a course
/// Switch to displaying the minigames
/// </summary>
/// <param name="index">Index of the course</param>
/// <remarks>TODO: create a better plot</remarks>
private void DisplayCourseGraph(CourseIndex index) { }
/// <summary>
/// Plot the graph of a minigame
/// </summary>
/// <param name="minigameIndex">Index of the minigame</param>
/// <remarks>TODO: reworking </remarks>
private void DisplayMinigameGraph(MinigameIndex minigameIndex) { }
public void DisplayMinigames()
{
coursesPanel.SetActive(false);
coursesTabButton.color = Color.gray;
minigamesPanel.SetActive(true);
minigamesTabButton.color = Color.blue;
}
}