CommonItemBaseCtrl.cs 4.5 KB

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