WidgetItem.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. using System;
  2. using GameLogic.Bag;
  3. using GameLogic.Equipment;
  4. using UnityEngine;
  5. using Utility;
  6. namespace Fort23.Mono
  7. {
  8. [UIBinding(prefab = "WidgetItem" )]
  9. public partial class WidgetItem : UIComponent
  10. {
  11. public ItemInfo itemInfo;
  12. private WidgetItemColorConfig colorConfig;
  13. private void Init()
  14. {
  15. colorConfig = btnClick.gameObject.GetComponent<WidgetItemColorConfig>();
  16. }
  17. public override void AddEvent()
  18. {
  19. }
  20. public override void DelEvent()
  21. {
  22. }
  23. public override void AddButtonEvent()
  24. {
  25. btnClick.onClick.AddListener(OnclickItem);
  26. }
  27. private Action action;
  28. private async void OnclickItem()
  29. {
  30. if (action != null)
  31. {
  32. action.Invoke();
  33. return;
  34. }
  35. if (itemInfo == null)
  36. {
  37. return;
  38. }
  39. ItemPanel itemPanel = await UIManager.Instance.LoadAndOpenPanel<ItemPanel>(null, layer: UILayer.Top);
  40. itemPanel.InitItemPanel(itemInfo);
  41. }
  42. public void InitWidget(ItemInfo itemInfo, Action action = null)
  43. {
  44. this.itemInfo = itemInfo;
  45. this.action = action;
  46. bg.color = colorConfig.bgColors[3];
  47. corner.color = colorConfig.cornerColors[3];
  48. // light.color = colorConfig.lightColors[itemInfo.eqInfo.quality];
  49. // border.color = colorConfig.borderColors[itemInfo.eqInfo.quality];
  50. glow.color = colorConfig.glowColors[3];
  51. border.gameObject.SetActive(false);
  52. light.gameObject.SetActive(false);
  53. heroShards.SetActive(false);
  54. numObj.SetActive(true);
  55. alertRed.SetActive(false);
  56. icon.gameObject.SetActive(true);
  57. num.text = itemInfo.count.Value.ToStringEx();
  58. if (itemInfo.eqInfo != null)
  59. {
  60. icon.icon_name = HeroUITools.GetEquipmentIconName(itemInfo);
  61. lvObj.SetActive(true);
  62. txtLv.text = itemInfo.eqInfo.level + "级";
  63. bg.color = colorConfig.bgColors[itemInfo.eqInfo.quality];
  64. corner.color = colorConfig.cornerColors[itemInfo.eqInfo.quality];
  65. // light.color = colorConfig.lightColors[itemInfo.eqInfo.quality];
  66. // border.color = colorConfig.borderColors[itemInfo.eqInfo.quality];
  67. glow.color = colorConfig.glowColors[itemInfo.eqInfo.quality];
  68. }
  69. if (itemInfo.config.itemTyp == 5)
  70. {
  71. heroShards.SetActive(true);
  72. icon.gameObject.SetActive(false);
  73. heroShardsIcon.icon_name = itemInfo.config.icon;
  74. }
  75. else
  76. {
  77. icon.icon_name = itemInfo.config.icon;
  78. lvObj.SetActive(false);
  79. }
  80. }
  81. public void SetEmpty(Action action = null)
  82. {
  83. itemInfo = null;
  84. this.action = action;
  85. border.gameObject.SetActive(false);
  86. light.gameObject.SetActive(false);
  87. numObj.SetActive(false);
  88. icon.gameObject.SetActive(false);
  89. alertRed.SetActive(false);
  90. corner.gameObject.SetActive(false);
  91. glow.gameObject.SetActive(false);
  92. lvObj.SetActive(false);
  93. heroShards.SetActive(false);
  94. bg.color = colorConfig.bgColors[0];
  95. // light.color = colorConfig.lightColors[0];
  96. // border.color = colorConfig.borderColors[0];
  97. }
  98. }
  99. }