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