CommonItemBaseCtrl.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /// #pkgName FGUI包名
  2. /// #panelName UIPanel名字
  3. /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
  4. /// 该脚本由模板创建
  5. /// created by cb 2024
  6. using FairyGUI;
  7. using FL.Data.Items;
  8. using XGame.Framework.UI;
  9. namespace FL.FGUI
  10. {
  11. /// <summary>
  12. /// UI逻辑处理类
  13. /// </summary>
  14. /// <typeparam name=""></typeparam>
  15. public partial class CommonItemBaseCtrl : UIController<CommonItemBaseVM>
  16. {
  17. private IItemBase _data;
  18. private bool _bShowBaseInfo;
  19. protected override void OnEnable(object intent)
  20. {
  21. AddUIListenres();
  22. }
  23. protected override void OnDisable()
  24. {
  25. RemoveUIListenres();
  26. }
  27. #region UI事件
  28. private void AddUIListenres()
  29. {
  30. VM.ItemBtn.onClick.Add(OnClickBtn);
  31. }
  32. private void RemoveUIListenres()
  33. {
  34. VM.ItemBtn.onClick.Remove(OnClickBtn);
  35. }
  36. #endregion
  37. private void OnClickBtn(EventContext context)
  38. {
  39. if (_data == null)
  40. return;
  41. if (_data is ItemBase)
  42. {
  43. ShowItemInfoPanel();
  44. }
  45. else
  46. {
  47. Context.UI.OpenAsync(UIKeys.EquipEquipPanel, _data);
  48. }
  49. }
  50. /// <summary>
  51. /// 简易的道具物品信息
  52. /// </summary>
  53. private void ShowItemInfoPanel()
  54. {
  55. //Log.Debug($"显示道具:{data.Name}详情界面");
  56. Context.UI.OpenAsync(UIKeys.ItemInformationPanel, _data);
  57. }
  58. public void ShowEmptyUI()
  59. {
  60. _data = null;
  61. VM.QualityImg.icon = "daojukuang1";
  62. }
  63. public void ShowUI(IItemBase item)
  64. {
  65. _data = item;
  66. VM.QualityImg.icon = AddressableDefine.ItemFrame(item.Quality);
  67. VM.ItemIcon.icon = item.Icon;
  68. VM.IsGetImg.visible = false;
  69. if (item is ItemBase itemBase)
  70. {
  71. VM.LvLabel.visible = false;
  72. if (itemBase.Count > 0)
  73. {
  74. VM.CountLabel.text = itemBase.Count.FormatNumber();
  75. VM.CountLabel.visible = true;
  76. }
  77. else
  78. {
  79. VM.CountLabel.visible = false;
  80. }
  81. VM.IsGetImg.visible = itemBase.IsGet == true;
  82. }
  83. else if (item is EquipItemBase equipItemBase)
  84. {
  85. VM.LvLabel.text = $"LV.{equipItemBase.Level}";
  86. VM.CountLabel.visible = false;
  87. VM.LvLabel.visible = true;
  88. }
  89. else if (item is PartnerItemBase partnerItemBase)
  90. {
  91. VM.LvLabel.text = $"LV.{partnerItemBase.Level}";
  92. VM.CountLabel.visible = false;
  93. VM.LvLabel.visible = true;
  94. }
  95. }
  96. /// <summary>
  97. /// 道具背包中的物品信息
  98. /// </summary>
  99. /// <param name="index"></param>
  100. /// <param name="itemData"></param>
  101. public void OnRefresh(int index, IItemBase itemData)
  102. {
  103. ShowUI(itemData);
  104. }
  105. }
  106. }