12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using TMPro;
- using KairoEngine.Stockpiles;
- using KairoEngine.UI.Tooltips;
- namespace KairoEngine.Stockpiles.UI
- {
- public class StockpileView : MonoBehaviour
- {
- public Image iconImage;
- public TextMeshProUGUI ammoutText;
- public TextMeshProUGUI capacityText;
- public TooltipTrigger tooltipTrigger;
- public string tooltipType = "";
- public StockpileGroupView viewManager;
- public StockpilePreset stockpilePreset;
- private int ammount, previousAmmout, capacity, previousCapacity;
- private void Update()
- {
- UpdateValues();
- }
- public void Setup(StockpileGroupView viewManager, StockpilePreset stockpilePreset)
- {
- this.viewManager = viewManager;
- this.stockpilePreset = stockpilePreset;
- iconImage.sprite = this.stockpilePreset.icon;
- UpdateValues();
- if(tooltipTrigger != null)
- {
- tooltipTrigger.header = stockpilePreset.title;
- tooltipTrigger.content = stockpilePreset.description;
- tooltipTrigger.tooltipType = tooltipType;
- }
- }
- private void UpdateValues()
- {
- ammount = viewManager.manager.GetStockpileAmmount(viewManager.owner, stockpilePreset.title);
- capacity = viewManager.manager.GetStockpileCapacity(viewManager.owner, stockpilePreset.title);
- if(ammount != previousAmmout || capacity != previousCapacity)
- {
- ammoutText.text = ammount.ToString();
- capacityText.text = capacity.ToString();
- viewManager.contentSizeFitter.enabled = false;
- }
- previousAmmout = ammount;
- previousCapacity = capacity;
- }
- }
- }
|