WidgetItem.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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);
  40. itemPanel.InitItemPanel(itemInfo);
  41. }
  42. public void InitWidget(ItemInfo itemInfo, Action action = null)
  43. {
  44. this.itemInfo = itemInfo;
  45. this.action = action;
  46. numObj.SetActive(true);
  47. alertRed.SetActive(false);
  48. icon.gameObject.SetActive(true);
  49. num.text = itemInfo.count.Value.ToStringEx();
  50. if (itemInfo.eqInfo != null)
  51. {
  52. icon.icon_name = HeroUITools.GetEquipmentIconName(itemInfo);
  53. lvObj.SetActive(true);
  54. txtLv.text = itemInfo.eqInfo.level + "级";
  55. bg.color = colorConfig.bgColors[itemInfo.eqInfo.quality];
  56. corner.color = colorConfig.cornerColors[itemInfo.eqInfo.quality];
  57. light.color = colorConfig.lightColors[itemInfo.eqInfo.quality];
  58. border.color = colorConfig.borderColors[itemInfo.eqInfo.quality];
  59. glow.color = colorConfig.glowColors[itemInfo.eqInfo.quality];
  60. }
  61. else
  62. {
  63. icon.icon_name = itemInfo.config.icon;
  64. lvObj.SetActive(false);
  65. // switch (itemInfo.eqInfo.quality)
  66. // {
  67. // case 1:
  68. // case 2:
  69. // bg.color = colorConfig.bgColors[1];
  70. // break;
  71. // }
  72. // bg.color = Color.blue;
  73. }
  74. // if (itemInfo.config.itemTyp == 4)
  75. // {
  76. // itemInfo.eqInfo = PlayerManager.Instance.eqController
  77. // .BuildEquipment(itemInfo.config, 1, 1);
  78. // //itemInfo.eqInfo.InitEquipment(itemInfo.config,1,1);
  79. // }
  80. }
  81. public void SetEmpty(Action action = null)
  82. {
  83. itemInfo = null;
  84. this.action = action;
  85. numObj.SetActive(false);
  86. icon.gameObject.SetActive(false);
  87. alertRed.SetActive(false);
  88. corner.gameObject.SetActive(false);
  89. glow.gameObject.SetActive(false);
  90. lvObj.SetActive(false);
  91. bg.color = colorConfig.bgColors[0];
  92. light.color = colorConfig.lightColors[0];
  93. border.color = colorConfig.borderColors[0];
  94. }
  95. }
  96. }