Resolve WES-54 "Info"
This commit is contained in:
committed by
Jelle De Geest
parent
0e8203e5fa
commit
194b53c0f4
@@ -68,6 +68,6 @@ public class CourseItem : MonoBehaviour
|
||||
slider.GetComponent<Slider>().value = progress;
|
||||
|
||||
// Add click functionality
|
||||
button.onClick.AddListener(() => SceneManager.LoadScene("Courses/Scenes/Course_0"));
|
||||
button.onClick.AddListener(() => SceneManager.LoadScene("Common/Scenes/InfoCourse"));
|
||||
}
|
||||
}
|
||||
|
||||
71
Assets/Common/Scripts/InfoCourse.cs
Normal file
71
Assets/Common/Scripts/InfoCourse.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro; // For text
|
||||
|
||||
/// <summary>
|
||||
/// Manager infopage for the Courses
|
||||
/// </summary>
|
||||
public class InfoCourse : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// Reference to the courses
|
||||
/// </summary>
|
||||
public CourseList list;
|
||||
// private float maxvalue; In case we want to change progress e.g. amount of words correct, then change maxvalue amount of words etc.
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the users
|
||||
/// </summary>
|
||||
public UserList userList;
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the course progress
|
||||
/// </summary>
|
||||
private Progress progress;
|
||||
|
||||
/// <summary>
|
||||
/// Title Display
|
||||
/// </summary>
|
||||
public TMP_Text title;
|
||||
|
||||
/// <summary>
|
||||
/// Description Display
|
||||
/// </summary>
|
||||
public TMP_Text description;
|
||||
|
||||
/// <summary>
|
||||
/// Image Display (Thumbnail)
|
||||
/// </summary>
|
||||
public Image courseImage;
|
||||
|
||||
/// <summary>
|
||||
/// Progress bar Display
|
||||
/// </summary>
|
||||
public Slider slider;
|
||||
|
||||
|
||||
// Start is called before the first frame update
|
||||
/// <summary>
|
||||
/// Sets the infopage for a given course
|
||||
/// </summary>
|
||||
void Start()
|
||||
{
|
||||
int index = list.currentCourseIndex;
|
||||
Course course = list.courses[index];
|
||||
|
||||
title.text = course.title;
|
||||
description.text = course.description;
|
||||
courseImage.sprite = course.thumbnail;
|
||||
//slider.value = progressValue;
|
||||
|
||||
// Set progress
|
||||
progress = userList.GetCurrentUser().GetCourseProgress(course.index);
|
||||
if (progress != null)
|
||||
slider.value = progress.Get<float>("courseProgress");
|
||||
else
|
||||
slider.value = 0.0f;
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/Common/Scripts/InfoCourse.cs.meta
Normal file
11
Assets/Common/Scripts/InfoCourse.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4ee87f3cdcccf934b82f9531c90f3457
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
143
Assets/Common/Scripts/InfoMinigame.cs
Normal file
143
Assets/Common/Scripts/InfoMinigame.cs
Normal file
@@ -0,0 +1,143 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
using static GameController;
|
||||
|
||||
/// <summary>
|
||||
/// Manager infopage for the Minigames
|
||||
/// </summary>
|
||||
public class InfoMinigame : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// Reference to the Minigames
|
||||
/// </summary>
|
||||
public MinigameList list;
|
||||
|
||||
/// <summary>
|
||||
/// Title Display
|
||||
/// </summary>
|
||||
public TMP_Text title;
|
||||
|
||||
/// <summary>
|
||||
/// Description Display
|
||||
/// </summary>
|
||||
public TMP_Text description;
|
||||
|
||||
/// <summary>
|
||||
/// Image Display (Thumbnail)
|
||||
/// </summary>
|
||||
public Image gameImage;
|
||||
|
||||
/// <summary>
|
||||
/// PlayButton to get to the Minigame
|
||||
/// </summary>
|
||||
public Button button;
|
||||
|
||||
/// <summary>
|
||||
/// Control explanation for the Display
|
||||
/// </summary>
|
||||
public TMP_Text controls;
|
||||
|
||||
// Scores for each user
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the users
|
||||
/// </summary>
|
||||
public UserList userList;
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the Minigame progress
|
||||
/// </summary>
|
||||
private Progress progress;
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the users-high-scores container object
|
||||
/// </summary>
|
||||
public Transform userContainer;
|
||||
|
||||
/// <summary>
|
||||
/// Prefab for the high-score-entries
|
||||
/// </summary>
|
||||
public GameObject prefab;
|
||||
|
||||
// Start is called before the first frame update
|
||||
/// <summary>
|
||||
/// Sets the infopage for a given minigame
|
||||
/// </summary>
|
||||
void Start()
|
||||
{
|
||||
GenerateContent();
|
||||
GenerateHighScores();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates all content accept for the HighScores
|
||||
/// </summary>
|
||||
private void GenerateContent()
|
||||
{
|
||||
// Get current minigame
|
||||
int index = list.currentMinigameIndex;
|
||||
Minigame minigame = list.minigames[index];
|
||||
|
||||
// Set main screen
|
||||
title.text = minigame.title;
|
||||
description.text = minigame.description;
|
||||
gameImage.sprite = minigame.thumbnail;
|
||||
controls.text = minigame.controls;
|
||||
|
||||
// Add click functionality
|
||||
button.onClick.AddListener(() => SceneManager.LoadScene(minigame.minigameEntryPoint));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the High Scores (Top 3)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// TODO: Maybe write a getter for the sorted scores as this is just a copy of the logic implemented in SpellingBee/.../GameController
|
||||
/// </remarks>
|
||||
private void GenerateHighScores()
|
||||
{
|
||||
// Get current minigame
|
||||
int index = list.currentMinigameIndex;
|
||||
Minigame minigame = list.minigames[index];
|
||||
|
||||
List<Tuple<string, Sprite, Score>> allScores = new List<Tuple<string, Sprite, Score>>();
|
||||
foreach (User user in userList.GetUsers())
|
||||
{
|
||||
// Get user's progress for this minigame
|
||||
progress = user.minigames.Find((p) => p != null && p.Get<MinigameIndex>("minigameIndex") == minigame.index);
|
||||
if (progress != null)
|
||||
{
|
||||
// Add scores to dictionary
|
||||
List<Score> scores = progress.Get<List<Score>>("scores");
|
||||
foreach (Score score in scores)
|
||||
{
|
||||
allScores.Add(new Tuple<string, Sprite, Score>(user.username, user.avatar, score));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sort allScores based on Score.scoreValue
|
||||
allScores.Sort((a, b) => b.Item3.scoreValue.CompareTo(a.Item3.scoreValue));
|
||||
|
||||
// Instantiate scoreboard entries
|
||||
foreach (Tuple<string, Sprite, Score> tup in allScores.Take(3))
|
||||
{
|
||||
string username = tup.Item1;
|
||||
Sprite sprite = tup.Item2;
|
||||
Score score = tup.Item3;
|
||||
|
||||
GameObject instance = GameObject.Instantiate(prefab, userContainer);
|
||||
instance.transform.Find("Title").GetComponent<TMP_Text>().text = username;
|
||||
instance.transform.Find("Avatar").GetComponent<Image>().sprite = sprite;
|
||||
instance.transform.Find("Score").GetComponent<TMP_Text>().text = score.scoreValue.ToString();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Common/Scripts/InfoMinigame.cs.meta
Normal file
11
Assets/Common/Scripts/InfoMinigame.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 90de9a5c57c2189429073f8aadc9e9b7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -30,4 +30,10 @@ public class Minigame : ScriptableObject
|
||||
/// The path to the minigame starting scene (<c>path == $"Assets/{minigameEntryPoint}"</c>)
|
||||
/// </summary>
|
||||
public string minigameEntryPoint;
|
||||
|
||||
/// <summary>
|
||||
/// An explanation on how to play the game and score points
|
||||
/// </summary>
|
||||
public string controls;
|
||||
|
||||
}
|
||||
|
||||
@@ -47,6 +47,6 @@ public class MinigameItem : MonoBehaviour
|
||||
title.text = minigame.title;
|
||||
|
||||
// Add click functionality
|
||||
button.onClick.AddListener(() => SceneManager.LoadScene(minigame.minigameEntryPoint));
|
||||
button.onClick.AddListener(() => SceneManager.LoadScene("Common/Scenes/InfoMinigame"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user