StockpileView.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using TMPro;
  6. using KairoEngine.Stockpiles;
  7. using KairoEngine.UI.Tooltips;
  8. namespace KairoEngine.Stockpiles.UI
  9. {
  10. public class StockpileView : MonoBehaviour
  11. {
  12. public Image iconImage;
  13. public TextMeshProUGUI ammoutText;
  14. public TextMeshProUGUI capacityText;
  15. public TooltipTrigger tooltipTrigger;
  16. public string tooltipType = "";
  17. public StockpileGroupView viewManager;
  18. public StockpilePreset stockpilePreset;
  19. private int ammount, previousAmmout, capacity, previousCapacity;
  20. private void Update()
  21. {
  22. UpdateValues();
  23. }
  24. public void Setup(StockpileGroupView viewManager, StockpilePreset stockpilePreset)
  25. {
  26. this.viewManager = viewManager;
  27. this.stockpilePreset = stockpilePreset;
  28. iconImage.sprite = this.stockpilePreset.icon;
  29. UpdateValues();
  30. if(tooltipTrigger != null)
  31. {
  32. tooltipTrigger.header = stockpilePreset.title;
  33. tooltipTrigger.content = stockpilePreset.description;
  34. tooltipTrigger.tooltipType = tooltipType;
  35. }
  36. }
  37. private void UpdateValues()
  38. {
  39. ammount = viewManager.manager.GetStockpileAmmount(viewManager.owner, stockpilePreset.title);
  40. capacity = viewManager.manager.GetStockpileCapacity(viewManager.owner, stockpilePreset.title);
  41. if(ammount != previousAmmout || capacity != previousCapacity)
  42. {
  43. ammoutText.text = ammount.ToString();
  44. capacityText.text = capacity.ToString();
  45. viewManager.contentSizeFitter.enabled = false;
  46. }
  47. previousAmmout = ammount;
  48. previousCapacity = capacity;
  49. }
  50. }
  51. }