WidgetItem.cs 4.0 KB

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