|
@@ -0,0 +1,47 @@
|
|
|
+using System.Collections;
|
|
|
+using System.Collections.Generic;
|
|
|
+using UnityEngine;
|
|
|
+using UnityEngine.UI;
|
|
|
+using Sirenix.OdinInspector;
|
|
|
+using TMPro;
|
|
|
+using KairoEngine.Core;
|
|
|
+using KairoEngine.UI.Encyclopedia;
|
|
|
+using KairoEngine.Stockpiles;
|
|
|
+
|
|
|
+namespace KairoEngine.Grids
|
|
|
+{
|
|
|
+ public class PlacedObjectEncyclopediaArticleUi : MonoBehaviour, IEncyclopediaArticleDataView
|
|
|
+ {
|
|
|
+ public GameObject resourceUiPrefab;
|
|
|
+ public TextMeshProUGUI titleText;
|
|
|
+ public TextMeshProUGUI categoryText;
|
|
|
+ public TextMeshProUGUI descriptionText;
|
|
|
+ public Image iconImage;
|
|
|
+ public Transform resourcesContainer;
|
|
|
+
|
|
|
+ public void Setup(EncyclopediaArticle article)
|
|
|
+ {
|
|
|
+ if(titleText != null) titleText.text = article.title;
|
|
|
+ article.content.TryGetValue("category", out string category);
|
|
|
+ if(categoryText != null) categoryText.text = category;
|
|
|
+ if(descriptionText != null) descriptionText.text = article.description;
|
|
|
+ article.images.TryGetValue("image", out Sprite image);
|
|
|
+ if(iconImage != null) iconImage.sprite = image;
|
|
|
+ article.integers.TryGetValue("cost-slots", out int resourceCount);
|
|
|
+ foreach (var item in resourcesContainer.transform.GetComponentsInChildren<VerticalLayoutGroup>())
|
|
|
+ {
|
|
|
+ if(item.transform != resourcesContainer) DestroyImmediate(item.gameObject);
|
|
|
+ }
|
|
|
+ for (int i = 0; i < resourceCount; i++)
|
|
|
+ {
|
|
|
+ article.content.TryGetValue($"cost-{i}-type", out string resourceName);
|
|
|
+ article.images.TryGetValue($"cost-{i}-icon", out Sprite resourceSprite);
|
|
|
+ article.integers.TryGetValue($"cost-{i}-value", out int resourceValue);
|
|
|
+ var obj = Instantiate(resourceUiPrefab, resourcesContainer);
|
|
|
+ obj.GetComponentInChildren<Image>().sprite = resourceSprite;
|
|
|
+ obj.GetComponentInChildren<TextMeshProUGUI>().text = resourceValue.ToString();
|
|
|
+ obj.name = resourceName;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|