2
0

4 Incheckningar 506b4e7edc ... e65f7444f9

Upphovsman SHA1 Meddelande Datum
  James Peret e65f7444f9 Bumped package version to 0.2.9 2 år sedan
  James Peret a6b0657c3e Fixed minor bugs 2 år sedan
  James Peret b9ed268efa Bumped package veresion to 0.2.8 2 år sedan
  James Peret 5dd01fc68e Added Encyclopedia auto refresh articles on enable 2 år sedan

+ 7 - 1
Readme.md

@@ -1,4 +1,4 @@
-# 📦 KairoEngine.UI.v0.2.7
+# 📦 KairoEngine.UI.v0.2.9
 
 The **UI** package contains the ``UiSystem`` component and the ``UiSystemModule``. The module loads the Ui System in place which manages canvases with UI data. The system now which canvases are enabled and has a global toggle for all the game UI.
 
@@ -75,6 +75,12 @@ Once you start creating interface elements for your game, you will want to regis
 The UI package adds new functionality for designing game user interfaces and tools for managing those interfaces in runtime. 
 
 ### Changelog
+### v0.2.9
+- Fixed minor bugs
+
+### v0.2.8
+- Added Encyclopedia auto refresh articles on enable
+- Added Singleton to Encyclopedia Controller
 
 #### v0.2.7
 - Fixed tooltip not hiding when parent was hidden or destroyed

+ 8 - 0
Runtime/Encyclopedia/EncyclopediaController.cs

@@ -10,6 +10,8 @@ namespace KairoEngine.UI.Encyclopedia
     [HideMonoScript]
     public class EncyclopediaController : MonoBehaviour, IClickHandler
     {
+        public static EncyclopediaController instance;
+
         [ShowInInspector, HorizontalGroup("IndexLine", 0.7f), LabelText("Index")] public int menuIndex;
         [ShowInInspector, HorizontalGroup("IndexLine", 0.3f), HideLabel] public int subMenuIndex;
 
@@ -17,6 +19,12 @@ namespace KairoEngine.UI.Encyclopedia
         public GameObject categoryButtomPrefab;
         public List<EncyclopediaCategory> categories = new List<EncyclopediaCategory>();
 
+        private void Awake()
+        {
+            if(instance == null) instance = this;
+            else Destroy(this);
+        }
+
         [Button("Build Menu"), ButtonGroup("Buttons")]
         public void BuildMenu()
         {

+ 4 - 3
Runtime/Encyclopedia/EncyclopediaUi.cs

@@ -17,6 +17,7 @@ namespace KairoEngine.UI.Encyclopedia
         public Transform menuContainer;
         public Transform subMenuContainer;
         public bool createOnStart = true;
+        public bool repopulateOnEnable = false;
         public bool showDebug = false;
         public List<EncyclopediaUiView> views;
         private List<SelectedButton> menuButtonSelection;
@@ -34,10 +35,10 @@ namespace KairoEngine.UI.Encyclopedia
             if(createOnStart) Populate();
         }
 
-        private void Update()
+        private void OnEnable()
         {
-            
-        }
+            if(repopulateOnEnable) Populate();
+        } 
 
         [Button("Show Submenu"), ButtonGroup("EditorActions")]
         public void ShowSubmenu() => subMenuGameObject.SetActive(true);

+ 7 - 1
Runtime/InteractionHandler/SelectedButton.cs

@@ -12,7 +12,7 @@ namespace KairoEngine.UI.InteractionHandler
         public Image image;
         public Button button;
         
-        public bool selected = false;
+        [OnValueChanged("Toggle"), OnInspectorInit("Toggle")] public bool selected = false;
         [SerializeField] private Sprite defaultSprite;
         [SerializeField] private Sprite selectedSprite;
         [SerializeField] private Sprite disabledSprite;
@@ -24,6 +24,12 @@ namespace KairoEngine.UI.InteractionHandler
             if(defaultSprite == null) defaultSprite = image.sprite;
         }
 
+        public void Toggle()
+        {
+            if(selected) Select();
+            else Deselect();
+        }
+
         public void Select()
         {
             //if(selected) return;

+ 67 - 7
Runtime/MenuComponents/ColumnMenuUI.cs

@@ -14,14 +14,19 @@ namespace KairoEngine.UI
     {
         
         [BoxGroup("Settings"), OnInspectorInit("EditorSetup")] public GameObject subMenuPrefab;
+        [BoxGroup("Settings")] public GameObject subMenuButtonPrefab;
         [BoxGroup("Settings")] public RectTransform subMenusParent;
+        [BoxGroup("Settings")] public bool instantiateMainMenuGroup = true;
+        [BoxGroup("Settings")] public bool keepMenuButtonsSelected = false;
+        [BoxGroup("Settings")] public bool keepSubMenuButtonsSelected = false;
         private GameObject mainMenu;
         private List<GameObject> subMenus = new List<GameObject>();
+        private List<SelectedButton> selectButtons = new List<SelectedButton>();
 
         public override void Start()
         {
             useSubMenus = true;
-            if(handler == null) handler = gameObject.GetComponent<IClickHandler>();
+            if(handler == null) handler = gameObject.GetComponents<IClickHandler>()[1];
             if(createMenuOnStart) 
             {
                 DestroyMenu();
@@ -35,11 +40,17 @@ namespace KairoEngine.UI
              {
                  if(buttons[i].title == title)
                  {
-                    if(buttons[i].subMenuParent) OpenSubMenu(title);
+                    if(buttons[i].subMenuParent) 
+                    {
+                        OpenSubMenu(title);
+                        SelectParentButton(i);
+                    }
                     if(buttons[i].action != "" && handler != null)
                     {
+                        SelectChildButton(i);
                         handler.OnClick(buttons[i].action);
                     }
+                    return;
                  }
              }
         }
@@ -48,12 +59,14 @@ namespace KairoEngine.UI
 
         public void CreateMenus()
         {
-            mainMenu = Instantiate(subMenuPrefab, menuParent);
+            if(instantiateMainMenuGroup) mainMenu = Instantiate(subMenuPrefab, menuParent);
+            else mainMenu = menuParent.gameObject;
             for (int i = 0; i < buttons.Count; i++)
             {
                 if(string.IsNullOrEmpty(buttons[i].parent))
                 {
-                    var btn = CreateButton(buttons[i], mainMenu.transform);
+                    var btn = CreateButton(buttons[i], mainMenu.transform, buttonPrefab);
+                    selectButtons.Add(btn.GetComponent<SelectedButton>());
                     buttons[i].button = btn;
                     var subMenu = Instantiate(subMenuPrefab, subMenusParent);
                     subMenu.name = $"SubMenu {buttons[i].title}";
@@ -61,7 +74,8 @@ namespace KairoEngine.UI
                     {
                         if(buttons[a].parent == buttons[i].title)
                         {
-                            var subBtn = CreateButton(buttons[a], subMenu.transform);
+                            var subBtn = CreateButton(buttons[a], subMenu.transform, subMenuButtonPrefab ?? buttonPrefab);
+                            selectButtons.Add(subBtn.GetComponent<SelectedButton>());
                             buttons[a].button = subBtn;
                         }
                     }
@@ -77,13 +91,19 @@ namespace KairoEngine.UI
         {
             for (int i = 0; i < subMenus.Count; i++)
             {
+                 #if UNITY_EDITOR
+                DestroyImmediate(subMenus[i]);
+                #else
                 Destroy(subMenus[i]);
+                #endif
             }
             subMenus = new List<GameObject>();
             #if UNITY_EDITOR
-            DestroyImmediate(mainMenu);
+            if(instantiateMainMenuGroup) DestroyImmediate(mainMenu);
+            else foreach (var btn in buttons) DestroyImmediate(btn.button.gameObject);
             #else
-            Destroy(mainMenu);
+            if(instantiateMainMenuGroup)  Destroy(mainMenu);
+            else foreach (var btn in buttons) Destroy(btn.button.gameObject);
             #endif
             buttons = new List<MenuButtomData>();
         }
@@ -92,14 +112,54 @@ namespace KairoEngine.UI
         {
             for (int i = 0; i < subMenus.Count; i++)
             {
+                if(subMenus[i] == null) continue;
                 if($"SubMenu {title}" == subMenus[i].name) subMenus[i].SetActive(true);
                 else subMenus[i].SetActive(false);
             }
         }
 
+        public void CloseSubMenus()
+        {
+            for (int i = 0; i < subMenus.Count; i++)
+            {
+                if(subMenus[i] != null) subMenus[i].SetActive(false);
+            }
+        }
+
         public void EditorSetup()
         {
             useSubMenus = true;
         }
+
+        public void SelectParentButton(int index)
+        {
+            for (int i = 0; i < buttons.Count; i++)
+            {
+                if(i != index && buttons[i].subMenuParent) selectButtons[i].Deselect();
+                else if(i == index) selectButtons[i].Select();
+            }
+        }
+
+        public void SelectChildButton(int index)
+        {
+            for (int i = 0; i < buttons.Count; i++)
+            {
+                if(i != index && !buttons[i].subMenuParent) selectButtons[i].Deselect();
+                else if(i == index) selectButtons[i].Select();
+            }
+        }
+
+        public void DeselectChildButtons()
+        {
+            for (int i = 0; i < buttons.Count; i++)
+            {
+                if(!buttons[i].subMenuParent) selectButtons[i].Deselect();
+            }
+        }
+
+        public void DeselectAllButtons()
+        {
+            for (int i = 0; i < buttons.Count; i++) selectButtons[i].Deselect();
+        }
     }
 }

+ 4 - 3
Runtime/MenuComponents/MenuUI.cs

@@ -65,7 +65,7 @@ namespace KairoEngine.UI
 
         private void OnEnable()
         {
-            if(menuCanvas != null) UiManager.RegisterElement(elementTitle, this, this.transform, isVisible);
+            if(menuCanvas != null) UiManager.RegisterElement(elementTitle, this, this.transform, visibleOnStart);
         }
 
         public virtual void OnClick(string title)
@@ -101,9 +101,10 @@ namespace KairoEngine.UI
 
         public bool IsVisible() => isVisible;
 
-        public virtual GameObject CreateButton(MenuButtomData data, Transform parent)
+        public virtual GameObject CreateButton(MenuButtomData data, Transform parent, GameObject prefab = null)
         {
-            var btn = Instantiate(buttonPrefab, parent);
+            if(prefab == null) prefab = buttonPrefab;
+            var btn = Instantiate(prefab, parent);
             ClickHandler clickHandler = btn.GetComponent<ClickHandler>();
             if(clickHandler != null) 
             {

+ 2 - 2
package.json

@@ -1,7 +1,7 @@
 {
     "name": "at.kairoscope.kairoengine.ui",
     "displayName" : "KairoEngine UI",
-    "version": "0.2.7",
+    "version": "0.2.9",
     "unity": "2020.3",
     "description": "User Interface library for kairoEngine",
     "repository": {
@@ -10,7 +10,7 @@
     },
     "author": "Kairoscope",
     "dependencies": {
-      "at.kairoscope.kairoengine.core":"0.2.4",
+      "at.kairoscope.kairoengine.core":"0.2.6",
       "at.kairoscope.kairoengine.sfx":"0.2.0",
       "at.kairoscope.thirdparty.leantween":"1.0.0",
       "at.kairoscope.thirdparty.tmpro":"1.0.0"