CommonItemBaseCtrl.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. }
  21. /// <summary>
  22. /// UI逻辑处理类
  23. /// </summary>
  24. /// <typeparam name=""></typeparam>
  25. public partial class CommonItemBaseCtrl : UIController<CommonItemBaseVM>
  26. {
  27. private IItem data;
  28. protected override void OnEnable(object intent)
  29. {
  30. AddUIListenres();
  31. }
  32. protected override void OnDisable()
  33. {
  34. RemoveUIListenres();
  35. }
  36. #region UI事件
  37. private void AddUIListenres()
  38. {
  39. if (VM.ItemBtn != null)
  40. {
  41. VM.ItemBtn.onClick.Add(OnClickBtn);
  42. }
  43. }
  44. private void RemoveUIListenres()
  45. {
  46. if (VM.ItemBtn != null)
  47. {
  48. VM.ItemBtn.onClick.Remove(OnClickBtn);
  49. }
  50. }
  51. #endregion
  52. private void OnClickBtn(EventContext context)
  53. {
  54. if (data == null)
  55. {
  56. return;
  57. }
  58. else if (data?.ItemType == EItemType.Equip)
  59. {
  60. var _uiParam = new EquipParam();
  61. _uiParam.id = data.Id;
  62. _uiParam.equipType = (data as EquipItem).Table.Part;
  63. Context.UI.OpenAsync(UIKeys.DragonEggEquip, _uiParam);
  64. }
  65. else
  66. {
  67. Log.Debug($"显示道具:{data.Name}详情界面");
  68. }
  69. }
  70. /// <summary>
  71. /// UI显示数据
  72. /// </summary>
  73. /// <param name="id"></param>
  74. /// <returns></returns>
  75. private Item GetItemUIData(int id)
  76. {
  77. ItemTable _itemTable = ItemTableRepo.Get(id);// 模拟
  78. Item _item = new Item();
  79. _item.Init(_itemTable, UIDDefine.New());
  80. return _item;
  81. }
  82. public void ShowUI(IItem item, UiParam uiParam)
  83. {
  84. data = item;
  85. if (VM.QualityImg != null)
  86. {
  87. VM.QualityImg.icon = AddressableDefine.ItemFrame(item.Quality);
  88. }
  89. if (VM.ItemIcon != null)
  90. {
  91. VM.ItemIcon.icon = item.Icon;
  92. }
  93. if (VM.NameLabel != null)
  94. {
  95. VM.NameLabel.visible = uiParam.bShowName;
  96. if (uiParam.bShowName)
  97. {
  98. VM.NameLabel.text = item.Name;
  99. }
  100. }
  101. if (VM.LvLabel != null)
  102. {
  103. VM.NameLabel.visible = uiParam.bShowLevel;
  104. if (uiParam.bShowLevel)
  105. {
  106. VM.LvLabel.text = $"lv.{item.Level}";
  107. }
  108. }
  109. if (VM.CountLabel != null)
  110. {
  111. VM.CountLabel.visible = uiParam.bShowCount;
  112. if (uiParam.bShowCount)
  113. {
  114. VM.CountLabel.text = item.Count;
  115. }
  116. }
  117. if (VM.MaskImg != null)
  118. {
  119. VM.MaskImg.visible = uiParam.bShowMask;
  120. }
  121. if (VM.ItemBtn != null)
  122. {
  123. VM.ItemBtn.visible = uiParam.bShowBtn;
  124. }
  125. }
  126. /// <summary>
  127. /// 模拟的道具数据展示
  128. /// </summary>
  129. /// <param name="tableId"></param>
  130. public void ShowAnalogData(int tableId, UiParam _uiParam)
  131. {
  132. ShowUI(GetItemUIData(tableId), _uiParam);
  133. }
  134. }
  135. }