AchievementEncyclopediaArticleUi.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using TMPro;
  6. using KairoEngine.UI.Encyclopedia;
  7. using Sirenix.OdinInspector;
  8. namespace KairoEngine.Achievements
  9. {
  10. [HideMonoScript]
  11. public class AchievementEncyclopediaArticleUi : MonoBehaviour, IEncyclopediaArticleDataView
  12. {
  13. public Image iconContainer;
  14. public TextMeshProUGUI titleText;
  15. public TextMeshProUGUI descriptionText;
  16. public Slider progressBar;
  17. public Color unlockedTextColor = Color.white;
  18. public Color lockedTextColor = Color.gray;
  19. public void Setup(EncyclopediaArticle article)
  20. {
  21. article.booleans.TryGetValue("unlocked", out bool unlocked);
  22. if(unlocked)
  23. {
  24. titleText.color = unlockedTextColor;
  25. descriptionText.color = unlockedTextColor;
  26. }
  27. else
  28. {
  29. titleText.color = lockedTextColor;
  30. descriptionText.color = lockedTextColor;
  31. }
  32. article.booleans.TryGetValue("use-statistic", out bool useStatistic);
  33. iconContainer.sprite = article.icon;
  34. titleText.text = article.title;
  35. descriptionText.text = article.description;
  36. if(progressBar != null && useStatistic)
  37. {
  38. progressBar.gameObject.SetActive(true);
  39. article.integers.TryGetValue("current-value", out int value);
  40. article.integers.TryGetValue("max-value", out int max);
  41. if(value > max) value = max;
  42. progressBar.maxValue = max;
  43. progressBar.value = value;
  44. }
  45. else progressBar.gameObject.SetActive(false);
  46. }
  47. }
  48. }