windows can be sorted in main menu

This commit is contained in:
in0finite 2019-07-09 17:22:07 +02:00
parent f400009bcf
commit 5b472d673b
3 changed files with 13 additions and 7 deletions

View file

@ -18,11 +18,11 @@ namespace SanAndreasUnity.UI
public Color backgroundColor = Color.black;
public bool drawLogo = false;
private static List<System.Action> s_registeredMenuItems = new List<System.Action>();
private static GUILayoutOption[] s_buttonOptions = new GUILayoutOption[0];
public static GUILayoutOption[] ButtonLayoutOptions { get { return s_buttonOptions; } }
static MenuEntry s_rootMenuEntry = new MenuEntry();
void Start ()
@ -69,9 +69,10 @@ namespace SanAndreasUnity.UI
GUILayout.FlexibleSpace ();
// draw registered menu items
foreach (var item in s_registeredMenuItems)
foreach (var item in s_rootMenuEntry.children)
{
item ();
if (item.drawAction != null)
item.drawAction();
GUILayout.Space (this.spaceBetweenButtons);
}
@ -92,9 +93,9 @@ namespace SanAndreasUnity.UI
}
public static void RegisterMenuItem (System.Action action)
public static void RegisterMenuItem (MenuEntry menuEntry)
{
s_registeredMenuItems.AddIfNotPresent (action);
s_rootMenuEntry.AddChild (menuEntry);
}
}

View file

@ -8,6 +8,7 @@ namespace SanAndreasUnity.UI
public string name = "";
public int sortPriority = 0;
public List<MenuEntry> children = new List<MenuEntry>();
public System.Action drawAction = null;
public void AddChild(MenuEntry entry)
{

View file

@ -68,6 +68,7 @@ namespace SanAndreasUnity.UI {
[SerializeField] private bool m_registerInMainMenuOnStart = false;
public bool IsRegisteredInMainMenu { get; private set; }
[SerializeField] int m_sortPriorityForMainMenu = 0;
private static GameObject s_windowsContainer;
@ -258,7 +259,10 @@ namespace SanAndreasUnity.UI {
return;
this.IsRegisteredInMainMenu = true;
MainMenu.RegisterMenuItem ( () => this.OnMainMenuGUI() );
MenuEntry menuEntry = new MenuEntry(){name = this.windowName, sortPriority = m_sortPriorityForMainMenu,
drawAction = () => this.OnMainMenuGUI()};
MainMenu.RegisterMenuItem (menuEntry);
}
private void OnMainMenuGUI ()