HiddenContainer.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. namespace SoftKitty.InventoryEngine
  6. {
  7. public class HiddenContainer : UiWindow
  8. {
  9. #region Variables
  10. public Text TitleText;
  11. public int CategoryID;
  12. public RectTransform HoverInfoAnchorPoint;
  13. public InventoryItem ItemPrefab;
  14. public Image BlockImage;
  15. protected InventoryHolder Holder;
  16. protected bool inited = false;
  17. protected List<InventoryItem> Items=new List<InventoryItem>();
  18. #endregion
  19. #region MonoBehaviour
  20. public override void Update()
  21. {
  22. if (!inited) return;
  23. base.Update();
  24. CheckBlock();
  25. }
  26. #endregion
  27. public override void Initialize(InventoryHolder _inventoryHolder, InventoryHolder _equipHolder, string _name = "Inventory")//Initialize this interface
  28. {
  29. Holder = _inventoryHolder;
  30. TitleText.text = _name.ToUpper();
  31. ItemPrefab.Outline.color = InventorySkin.instance.ItemSelectedColor;
  32. ItemPrefab.Hover.color = InventorySkin.instance.ItemHoverColor;
  33. ItemPrefab.Fav.GetComponent<Image>().color = InventorySkin.instance.FavoriteColor;
  34. ShowList();
  35. inited = true;
  36. }
  37. protected void ShowList()//Show Item List
  38. {
  39. for (int i = 0; i < Holder.HiddenStacks.Count; i++)
  40. {
  41. if (Holder.HiddenStacks[i].GetType(-1) == CategoryID)
  42. {
  43. GameObject _newItem = Instantiate(ItemPrefab.gameObject, ItemPrefab.transform.parent);
  44. _newItem.transform.localScale = Vector3.one;
  45. _newItem.GetComponent<InventoryItem>().Initialize(Holder.HiddenStacks[i]);
  46. _newItem.GetComponent<InventoryItem>().SetHolder(Holder);
  47. _newItem.GetComponent<InventoryItem>().HoverInfoAnchorPoint = HoverInfoAnchorPoint;
  48. _newItem.GetComponent<InventoryItem>().RegisterClickCallback(i, OnItemClick);
  49. _newItem.gameObject.SetActive(true);
  50. Items.Add(_newItem.GetComponent<InventoryItem>());
  51. }
  52. }
  53. }
  54. public virtual void OnItemClick(int _index, int _button)//Callback for when player click an item
  55. {
  56. }
  57. private void CheckBlock() //Check if the interface should be blocked.
  58. {
  59. if (NumberInput.instance != null)
  60. {
  61. BlockImage.gameObject.SetActive(true);
  62. BlockImage.color = new Color(0F, 0F, 0F, Mathf.Lerp(BlockImage.color.a, 0.94F, Time.deltaTime * 3F));
  63. }
  64. else
  65. {
  66. if (BlockImage.color.a > 0F)
  67. {
  68. BlockImage.color = new Color(0F, 0F, 0F, Mathf.MoveTowards(BlockImage.color.a, 0F, Time.deltaTime * 2F));
  69. }
  70. else
  71. {
  72. if (BlockImage.gameObject.activeSelf) BlockImage.gameObject.SetActive(false);
  73. }
  74. }
  75. }
  76. }
  77. }