diff --git a/ColourMeOKGame/Assets/Scripts/LeaderboardUI.cs b/ColourMeOKGame/Assets/Scripts/LeaderboardUI.cs
new file mode 100644
index 0000000..9717a71
--- /dev/null
+++ b/ColourMeOKGame/Assets/Scripts/LeaderboardUI.cs
@@ -0,0 +1,69 @@
+using System;
+using System.Collections.Generic;
+using Unity.VisualScripting;
+using UnityEngine;
+
+///
+/// class that loads leaderboard data and displays it in the UI
+///
+public class LeaderboardUI : MonoBehaviour
+{
+ ///
+ /// maximum number of entries to display in the leaderboard
+ ///
+ private const int MaxEntries = 10;
+
+ ///
+ /// leaderboard data
+ ///
+ private List _leaderboardData = new(MaxEntries);
+
+ ///
+ /// register callbacks
+ ///
+ private void OnEnable()
+ {
+ UIManager.Instance.RegisterOnDisplayStateChangeCallback((_, newState) =>
+ {
+ if (newState == UIManager.DisplayState.LeaderboardView)
+ {
+ LoadLeaderboardData();
+ }
+ });
+ }
+
+ ///
+ /// load leaderboard data from the backend
+ ///
+ private void LoadLeaderboardData()
+ {
+ if (GameManager.Instance.Backend.Status != Backend.FirebaseConnectionStatus.Connected)
+ {
+ Debug.LogError("attempted to load leaderboard data without a connection to the backend");
+ RenderLeaderboardData("Not connected to the backend, can't load leaderboard data.");
+ return;
+ }
+
+ GameManager.Instance.Backend.GetLeaderboard((result, entries) =>
+ {
+ if (result == Backend.TransactionResult.Ok)
+ {
+ _leaderboardData = entries;
+ RenderLeaderboardData();
+ }
+ else
+ {
+ Debug.LogError("failed to load leaderboard data");
+ RenderLeaderboardData("An error occured, couldn't load leaderboard data.");
+ }
+ });
+ }
+
+ ///
+ /// render leaderboard data
+ ///
+ private void RenderLeaderboardData(string message = "")
+ {
+ // render leaderboard data
+ }
+}
diff --git a/ColourMeOKGame/Assets/Scripts/LeaderboardUI.cs.meta b/ColourMeOKGame/Assets/Scripts/LeaderboardUI.cs.meta
new file mode 100644
index 0000000..0106c18
--- /dev/null
+++ b/ColourMeOKGame/Assets/Scripts/LeaderboardUI.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: f58221274607ad145b45792b8649c87f
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/ColourMeOKGame/Assets/Scripts/UIManager.cs b/ColourMeOKGame/Assets/Scripts/UIManager.cs
index 6386337..1ae5f82 100644
--- a/ColourMeOKGame/Assets/Scripts/UIManager.cs
+++ b/ColourMeOKGame/Assets/Scripts/UIManager.cs
@@ -3,6 +3,9 @@
using UnityEngine;
using UnityEngine.UIElements;
+///
+/// class to handles overall game ui state and transitions
+///
public class UIManager : MonoBehaviour
{
///
@@ -81,6 +84,30 @@ private void OnEnable()
UI = GetComponent().rootVisualElement;
}
+ ///
+ /// function to register a callback to be invoked when the display state changes
+ ///
+ ///
+ /// callback function that takes two DisplayState parameters:
+ ///
+ public void RegisterOnDisplayStateChangeCallback(Action callback)
+ {
+ _onDisplayStateChangeCallbacks.Add(callback);
+ }
+
+ private void FireOnDisplayStateChange(DisplayState oldState, DisplayState newState)
+ {
+ foreach (var callback in _onDisplayStateChangeCallbacks)
+ try
+ {
+ callback.Invoke(oldState, newState);
+ }
+ catch (Exception e)
+ {
+ Debug.LogError($"error invoking OnSignOutCallback: {e.Message}");
+ }
+ }
+
///
/// function to show a menu based on the enum passed,
/// and any other necessary actions
@@ -160,5 +187,8 @@ public void SetDisplayState(DisplayState newDisplayState)
UI.Q("AccountSection").style.display = DisplayStyle.Flex;
UI.Q("ConnectionStatus").style.display = DisplayStyle.Flex;
}
+
+ FireOnDisplayStateChange(state, newDisplayState);
+ state = newDisplayState;
}
}
\ No newline at end of file
diff --git a/ColourMeOKGame/Assets/UI/GameUI.uxml b/ColourMeOKGame/Assets/UI/GameUI.uxml
index 00cc0cd..9ea0c74 100644
--- a/ColourMeOKGame/Assets/UI/GameUI.uxml
+++ b/ColourMeOKGame/Assets/UI/GameUI.uxml
@@ -108,7 +108,7 @@
-
+
@@ -120,7 +120,7 @@
-
+