CommonItemBaseCtrl.cs 2.8 KB

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