AchievementEncyclopediaArticleUi.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. Debug.Log(article.unlocked);
  22. Sprite icon = null;
  23. if(article.unlocked)
  24. {
  25. titleText.color = unlockedTextColor;
  26. descriptionText.color = unlockedTextColor;
  27. article.images.TryGetValue("unlocked-icon", out icon);
  28. }
  29. else
  30. {
  31. titleText.color = lockedTextColor;
  32. descriptionText.color = lockedTextColor;
  33. article.images.TryGetValue("locked-icon", out icon);
  34. }
  35. article.booleans.TryGetValue("use-statistic", out bool useStatistic);
  36. iconContainer.sprite = icon;
  37. titleText.text = article.title;
  38. descriptionText.text = article.description;
  39. if(progressBar != null && useStatistic)
  40. {
  41. progressBar.gameObject.SetActive(true);
  42. article.integers.TryGetValue("current-value", out int value);
  43. article.integers.TryGetValue("max-value", out int max);
  44. if(value > max) value = max;
  45. progressBar.maxValue = max;
  46. progressBar.value = value;
  47. }
  48. else progressBar.gameObject.SetActive(false);
  49. }
  50. }
  51. }