CommonItemBaseCtrl.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. if (item is ItemBase itemBase)
  69. {
  70. VM.LvLabel.visible = false;
  71. if (itemBase.Count > 0)
  72. {
  73. VM.CountLabel.text = itemBase.Count.FormatNumber();
  74. VM.CountLabel.visible = true;
  75. }
  76. else
  77. {
  78. VM.CountLabel.visible = false;
  79. }
  80. }
  81. else if (item is EquipItemBase equipItemBase)
  82. {
  83. VM.LvLabel.text = $"LV.{equipItemBase.Level}";
  84. VM.CountLabel.visible = false;
  85. VM.LvLabel.visible = true;
  86. }
  87. else if (item is PartnerItemBase partnerItemBase)
  88. {
  89. VM.LvLabel.text = $"LV.{partnerItemBase.Level}";
  90. VM.CountLabel.visible = false;
  91. VM.LvLabel.visible = true;
  92. }
  93. }
  94. /// <summary>
  95. /// 道具背包中的物品信息
  96. /// </summary>
  97. /// <param name="index"></param>
  98. /// <param name="itemData"></param>
  99. public void OnRefresh(int index, IItemBase itemData)
  100. {
  101. ShowUI(itemData);
  102. }
  103. }
  104. }