Browse Source

Added encyclopedia category ui component

James Peret 2 years ago
parent
commit
91dfa10ace

+ 74 - 0
Runtime/Encyclopedia/EncyclopediaCategoryUi.cs

@@ -0,0 +1,74 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using UnityEngine.UI;
+using KairoEngine.UI.Encyclopedia;
+using Sirenix.OdinInspector;
+using TMPro;
+
+namespace KairoEngine.UI.Encyclopedia
+{
+    public class EncyclopediaCategoryUi : MonoBehaviour, IEncyclopediaCategoryDataView
+    {
+        public enum UiType
+        {
+            Title,
+            Id,
+            Icon,
+            Image,
+            Layout,
+            Articles
+        }
+        
+        public UiType uiType = UiType.Title;
+        [ShowIf("@!IsImage()")] public TextMeshProUGUI textMeshPro;
+        [ShowIf("@IsImage()")] public Image imageComponent;
+
+        public bool IsImage() => uiType == UiType.Image || uiType == UiType.Icon;
+
+        public void Setup(EncyclopediaCategory category)
+        {
+            string result = "";
+            Sprite spriteImage = null;
+            switch(uiType)
+            {
+                case UiType.Title:
+                    result = category.title;
+                    break;
+                case UiType.Id:
+                    result = category.id;
+                    break;
+                case UiType.Icon:
+                    spriteImage = category.icon;
+                    break;
+                case UiType.Image:
+                    spriteImage = category.image;
+                    break;
+                case UiType.Layout:
+                    result = category.layoutName;
+                    break;
+                case UiType.Articles:
+                    result = $"{category.GetArticles().Count} {(category.GetArticles().Count == 1 ? category.titleSingle : category.titlePlural)}";
+                    break;
+                default:
+                    break;
+            }
+            if (!IsImage() && textMeshPro != null) 
+            {
+                textMeshPro.text = result;
+                if(imageComponent != null) imageComponent.gameObject.SetActive(false);
+            }
+            else if(IsImage() && imageComponent != null) 
+            {
+                if(spriteImage != null)
+                {
+                    imageComponent.sprite = spriteImage;
+                    imageComponent.gameObject.SetActive(true);
+                }
+                else imageComponent.gameObject.SetActive(false);
+                
+            }
+        }
+    }
+}
+

+ 11 - 0
Runtime/Encyclopedia/EncyclopediaCategoryUi.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 227e1729418ea7445be12620ff40b923
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 11 - 0
Runtime/Encyclopedia/IEncyclopediaCategoryDataView.cs

@@ -0,0 +1,11 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+namespace KairoEngine.UI.Encyclopedia
+{
+    public interface IEncyclopediaCategoryDataView
+    {
+        void Setup(EncyclopediaCategory category);
+    }
+}

+ 11 - 0
Runtime/Encyclopedia/IEncyclopediaCategoryDataView.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 7d534556667390244828692b6499bee9
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: