WidgetItem.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. using System;
  2. using Core.Language;
  3. using Fort23.UTool;
  4. using GameLogic.Bag;
  5. using GameLogic.Equipment;
  6. using UnityEngine;
  7. using Utility;
  8. namespace Fort23.Mono
  9. {
  10. [UIBinding(prefab = "WidgetItem")]
  11. public partial class WidgetItem : UIComponent
  12. {
  13. public ItemInfo itemInfo;
  14. private void Init()
  15. {
  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 onClickItem;
  28. private async void OnclickItem()
  29. {
  30. if (onClickItem != null)
  31. {
  32. onClickItem.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 onClickItem = null)
  43. {
  44. this.itemInfo = itemInfo;
  45. this.onClickItem = onClickItem;
  46. border.gameObject.SetActive(false);
  47. light.gameObject.SetActive(false);
  48. heroShards.SetActive(false);
  49. alertRed.SetActive(false);
  50. icon.gameObject.SetActive(true);
  51. if (itemInfo.count.Value > 0)
  52. {
  53. numObj.SetActive(true);
  54. num.text = itemInfo.count.Value.ToStringEx();
  55. }
  56. else
  57. {
  58. numObj.SetActive(false);
  59. }
  60. if (itemInfo.eqInfo != null)
  61. {
  62. // icon.icon_name = HeroUITools.GetEquipmentIconName(itemInfo);
  63. lvObj.SetActive(true);
  64. // txtLv.text = itemInfo.eqInfo.level + "级";
  65. txtLv.text = LanguageManager.Instance.Text(161, itemInfo.eqInfo.level);
  66. }
  67. else if (itemInfo.config.itemTyp == 5)
  68. {
  69. heroShards.SetActive(true);
  70. icon.gameObject.SetActive(false);
  71. heroShardsIcon.icon_name = itemInfo.config.icon;
  72. lvObj.SetActive(false);
  73. }
  74. else
  75. {
  76. icon.icon_name = itemInfo.config.icon;
  77. lvObj.SetActive(false);
  78. }
  79. }
  80. /// <summary>
  81. /// 设置单个装备的小红点
  82. /// </summary>
  83. /// <param name="oldEq"></param>
  84. public bool SetEqItemRedPoint(ItemInfo best, int bwIdx)
  85. {
  86. //有更好的装备,且装备类型相同
  87. if (best != null && best.eqInfo.basicEquipConfig.Type == bwIdx)
  88. {
  89. alertRed.SetActive(true);
  90. // if (itemInfo == null)
  91. // {
  92. // alertRed.SetActive(true);
  93. // }
  94. // //有装备,且装备类型相同,且装备等级更高
  95. // if (itemInfo != null && best.eqInfo.basicEquipConfig.Type == eqTypIdx)
  96. // {
  97. // alertRed.SetActive(true);
  98. // }
  99. return true;
  100. }
  101. else
  102. {
  103. alertRed.SetActive(false);
  104. }
  105. return false;
  106. }
  107. public void SetEmpty(Action onClickItem = null)
  108. {
  109. itemInfo = null;
  110. this.onClickItem = onClickItem;
  111. border.gameObject.SetActive(false);
  112. light.gameObject.SetActive(false);
  113. numObj.SetActive(false);
  114. icon.gameObject.SetActive(false);
  115. corner.gameObject.SetActive(false);
  116. glow.gameObject.SetActive(false);
  117. lvObj.SetActive(false);
  118. heroShards.SetActive(false);
  119. alertRed.SetActive(false);
  120. }
  121. public override void DormancyObj()
  122. {
  123. base.DormancyObj();
  124. }
  125. }
  126. }