WidgetItem.cs 3.3 KB

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