CommonItemBaseCtrl.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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;
  9. using XGame.Database;
  10. using XGame.Framework.UI;
  11. namespace FL.FGUI
  12. {
  13. public class UiParam
  14. {
  15. public bool bShowName;
  16. public bool bShowCount;
  17. public bool bShowBtn; // 是否可点击
  18. public bool bShowMask;
  19. public bool bShowLevel;
  20. public bool bShowBaseInfo; // 点击道具是否只显示物品简易信息
  21. }
  22. /// <summary>
  23. /// UI逻辑处理类
  24. /// </summary>
  25. /// <typeparam name=""></typeparam>
  26. public partial class CommonItemBaseCtrl : UIController<CommonItemBaseVM>
  27. {
  28. private IItem data;
  29. private bool bShowBaseInfo;
  30. protected override void OnEnable(object intent)
  31. {
  32. AddUIListenres();
  33. }
  34. protected override void OnDisable()
  35. {
  36. RemoveUIListenres();
  37. }
  38. #region UI事件
  39. private void AddUIListenres()
  40. {
  41. if (VM.ItemBtn != null)
  42. {
  43. VM.ItemBtn.onClick.Add(OnClickBtn);
  44. }
  45. }
  46. private void RemoveUIListenres()
  47. {
  48. if (VM.ItemBtn != null)
  49. {
  50. VM.ItemBtn.onClick.Remove(OnClickBtn);
  51. }
  52. }
  53. #endregion
  54. private void OnClickBtn(EventContext context)
  55. {
  56. if (data == null)
  57. {
  58. return;
  59. }
  60. else if (bShowBaseInfo)
  61. {
  62. ShowItemInfoPanel();
  63. }
  64. else if (data?.ItemType == EItemType.Equip)
  65. {
  66. Context.UI.OpenAsync(UIKeys.EquipEquipPanel, data);
  67. }
  68. else
  69. {
  70. ShowItemInfoPanel();
  71. }
  72. }
  73. private void ShowItemInfoPanel()
  74. {
  75. Log.Debug($"显示道具:{data.Name}详情界面");
  76. Context.UI.OpenAsync(UIKeys.ItemInformationPanel, new ItemInfoParam
  77. {
  78. itemInfo = ItemTableRepo.Get(data.TableId),
  79. numDesc = data?.ItemType == EItemType.Equip ? $"LV.{data.Level}" : (int.Parse(data.Count) > 1 ? data.Count : null),
  80. });
  81. }
  82. public void ShowUI(IItem item, UiParam uiParam)
  83. {
  84. data = item;
  85. bShowBaseInfo = uiParam.bShowBaseInfo;
  86. if (VM.QualityImg != null)
  87. {
  88. VM.QualityImg.icon = AddressableDefine.ItemFrame(item.Quality);
  89. }
  90. if (VM.ItemIcon != null)
  91. {
  92. VM.ItemIcon.icon = item.Icon;
  93. }
  94. if (VM.NameLabel != null)
  95. {
  96. VM.NameLabel.visible = uiParam.bShowName;
  97. if (uiParam.bShowName)
  98. {
  99. VM.NameLabel.text = item.Name;
  100. }
  101. }
  102. if (VM.LvLabel != null)
  103. {
  104. VM.LvLabel.visible = uiParam.bShowLevel;
  105. if (uiParam.bShowLevel)
  106. {
  107. VM.LvLabel.text = $"LV.{item.Level}";
  108. }
  109. }
  110. if (VM.CountLabel != null)
  111. {
  112. VM.CountLabel.visible = uiParam.bShowCount;
  113. if (uiParam.bShowCount)
  114. {
  115. VM.CountLabel.text = item.Count;
  116. }
  117. }
  118. if (VM.MaskImg != null)
  119. {
  120. VM.MaskImg.visible = uiParam.bShowMask;
  121. }
  122. if (VM.ItemBtn != null)
  123. {
  124. VM.ItemBtn.visible = uiParam.bShowBtn;
  125. }
  126. }
  127. }
  128. }