mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-14 00:07:15 +00:00
Working on stats
This commit is contained in:
parent
54c44a89a7
commit
eedc0f1e62
2 changed files with 80 additions and 0 deletions
|
@ -0,0 +1,51 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using SanAndreasUnity.Utilities;
|
||||
using System.Linq;
|
||||
|
||||
namespace SanAndreasUnity.UI
|
||||
{
|
||||
|
||||
public class StatsWindow : PauseMenuWindow
|
||||
{
|
||||
int m_tabIndex = 0;
|
||||
|
||||
|
||||
StatsWindow()
|
||||
{
|
||||
// set default parameters
|
||||
|
||||
this.windowName = "Stats";
|
||||
this.useScrollView = true;
|
||||
|
||||
}
|
||||
|
||||
void Start ()
|
||||
{
|
||||
this.RegisterButtonInPauseMenu ();
|
||||
|
||||
// adjust rect
|
||||
this.windowRect = Utilities.GUIUtils.GetCenteredRectPerc(new Vector2(0.8f, 0.8f));
|
||||
}
|
||||
|
||||
|
||||
protected override void OnWindowGUI ()
|
||||
{
|
||||
var categories = Stats.Categories.ToArray();
|
||||
m_tabIndex = GUIUtils.TabsControl(m_tabIndex, categories);
|
||||
if (m_tabIndex >= 0)
|
||||
{
|
||||
var stats = Stats.Entries.ElementAt(m_tabIndex).Value;
|
||||
foreach (var stat in stats)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(stat.text))
|
||||
GUILayout.Label(stat.text);
|
||||
if (stat.onGUI != null)
|
||||
stat.onGUI();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace SanAndreasUnity.Utilities
|
||||
{
|
||||
public class Stats
|
||||
{
|
||||
public class Entry
|
||||
{
|
||||
public string category = "";
|
||||
public string text = null;
|
||||
public System.Action onGUI = null;
|
||||
}
|
||||
|
||||
static Dictionary<string, List<Entry>> s_entries = new Dictionary<string, List<Entry>>();
|
||||
public static IEnumerable<KeyValuePair<string, List<Entry>>> Entries => s_entries;
|
||||
public static IEnumerable<string> Categories => s_entries.Select(pair => pair.Key);
|
||||
|
||||
|
||||
public static void RegisterStat(Entry entry)
|
||||
{
|
||||
if (s_entries.ContainsKey(entry.category))
|
||||
s_entries[entry.category].Add(entry);
|
||||
else
|
||||
s_entries[entry.category] = new List<Entry>(){entry};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue