diff --git a/Assets/Prefabs/MainMenuButton.prefab b/Assets/Prefabs/MainMenuButton.prefab index afc230f2..3497ab5e 100644 --- a/Assets/Prefabs/MainMenuButton.prefab +++ b/Assets/Prefabs/MainMenuButton.prefab @@ -91,6 +91,7 @@ GameObject: - component: {fileID: 9138667228417146571} - component: {fileID: 4141083121869060371} - component: {fileID: 7115660482297094336} + - component: {fileID: 1044688121435195929} m_Layer: 5 m_Name: MainMenuButton m_TagString: Untagged @@ -197,3 +198,16 @@ MonoBehaviour: m_Calls: [] m_TypeName: UnityEngine.UI.Button+ButtonClickedEvent, UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null +--- !u!114 &1044688121435195929 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 9144763033384219215} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 3c256f83f853fb44a8c14709ac6cf436, type: 3} + m_Name: + m_EditorClassIdentifier: + sortPriority: 0 diff --git a/Assets/Prefabs/UI.prefab b/Assets/Prefabs/UI.prefab index 2524022d..33a505f4 100644 --- a/Assets/Prefabs/UI.prefab +++ b/Assets/Prefabs/UI.prefab @@ -684,11 +684,9 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 4f5b556e077dc4e268ae212027bb0276, type: 3} m_Name: m_EditorClassIdentifier: + menuBar: {fileID: 8469116886705650871} openedWindowTextColor: {r: 0, g: 1, b: 0, a: 1} canvas: {fileID: 4580190521452898284} - buttonsContainer: {fileID: 8593699161208457630} - buttonPrefab: {fileID: 9144763033384219215, guid: c5e7e3e4ef714514090db34e6278e452, - type: 3} --- !u!1 &1594478129176806 GameObject: m_ObjectHideFlags: 0 @@ -6753,6 +6751,7 @@ GameObject: - component: {fileID: 8593699161208457630} - component: {fileID: 8945428129181930115} - component: {fileID: 87587368906071952} + - component: {fileID: 8469116886705650871} m_Layer: 5 m_Name: ButtonsContainer m_TagString: Untagged @@ -6810,6 +6809,21 @@ MonoBehaviour: m_ChildForceExpandHeight: 1 m_ChildControlWidth: 1 m_ChildControlHeight: 0 +--- !u!114 &8469116886705650871 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7440295692224049306} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 3009b992d8a5e69499f649956b583a0c, type: 3} + m_Name: + m_EditorClassIdentifier: + buttonsContainer: {fileID: 8593699161208457630} + buttonPrefab: {fileID: 9144763033384219215, guid: c5e7e3e4ef714514090db34e6278e452, + type: 3} --- !u!1 &7884037108542363516 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/UI/MainMenu.cs b/Assets/Scripts/UI/MainMenu.cs index 76997ec3..a3f20baf 100644 --- a/Assets/Scripts/UI/MainMenu.cs +++ b/Assets/Scripts/UI/MainMenu.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using UnityEngine; using SanAndreasUnity.Behaviours; -using UnityEngine.UI; +using SanAndreasUnity.Utilities; namespace SanAndreasUnity.UI { @@ -10,14 +10,12 @@ namespace SanAndreasUnity.UI public static MainMenu Instance { get; private set; } - public Color openedWindowTextColor = Color.green; - public Color ClosedWindowTextColor => this.buttonPrefab.GetComponentInChildren().color; + public MenuBar menuBar; - static MenuEntry s_rootMenuEntry = new MenuEntry(); + public Color openedWindowTextColor = Color.green; + public Color ClosedWindowTextColor => this.menuBar.DefaultMenuEntryTextColor; public Canvas canvas; - public RectTransform buttonsContainer; - public GameObject buttonPrefab; @@ -27,8 +25,7 @@ namespace SanAndreasUnity.UI Instance = this; // add Exit button - RegisterMenuEntry(new MenuEntry { name = "Exit", sortPriority = int.MaxValue, - clickAction = () => GameManager.ExitApplication() }); + this.menuBar.RegisterMenuEntry("Exit", int.MaxValue, () => GameManager.ExitApplication()); } void OnSceneChanged(SceneChangedMessage sceneChangedMessage) @@ -36,37 +33,6 @@ namespace SanAndreasUnity.UI this.canvas.enabled = GameManager.IsInStartupScene; } - - public static void RegisterMenuEntry (MenuEntry menuEntry) - { - int indexOfMenuEntry = s_rootMenuEntry.AddChild (menuEntry); - - GameObject buttonGo = Instantiate(Instance.buttonPrefab); - - buttonGo.name = menuEntry.name; - - buttonGo.GetComponentInChildren().text = menuEntry.name; - - buttonGo.transform.SetParent(Instance.buttonsContainer.transform, false); - buttonGo.transform.SetSiblingIndex(indexOfMenuEntry); - - buttonGo.GetComponent