Working on stats

This commit is contained in:
in0finite 2019-05-26 01:40:05 +02:00
parent 54c44a89a7
commit eedc0f1e62
2 changed files with 80 additions and 0 deletions

View file

@ -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();
}
}
}
}
}

View file

@ -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};
}
}
}