BagSourceOfPropsPanelCtrl.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 BagSourceOfPropsPanelCtrl : UIController<BagSourceOfPropsPanelVM>
  17. {
  18. private ItemTable _itemInfo;
  19. protected override void OnEnable(object intent)
  20. {
  21. AddUIListenres();
  22. if (intent != null)
  23. {
  24. ShowUI(intent as IItemBase);
  25. }
  26. }
  27. protected override void OnDisable()
  28. {
  29. RemoveUIListenres();
  30. }
  31. #region UI事件
  32. private void AddUIListenres()
  33. {
  34. VM.UseBtn.onClick.Add(OnClickUseBtn);
  35. }
  36. private void RemoveUIListenres()
  37. {
  38. VM.UseBtn.onClick.Remove(OnClickUseBtn);
  39. }
  40. private void OnClickUseBtn(EventContext context)
  41. {
  42. Context.UI.OpenAsync(UIKeys.BagUsePanel, _itemInfo);
  43. Context.ClosePanel();
  44. }
  45. #endregion
  46. private void ShowUI(IItemBase data)
  47. {
  48. _itemInfo = ItemTableRepo.Get(data.TableId);
  49. VM.NameLabel.text = _itemInfo.Name;
  50. VM.DescLabel.text = _itemInfo.Desc;
  51. if (data is ItemBase itemBase)
  52. {
  53. VM.CountLabel.visible = true;
  54. VM.CountLabel.text = itemBase.Count.ToString();
  55. }
  56. else
  57. {
  58. VM.CountLabel.visible = false;
  59. }
  60. VM.QualityIcon.icon = AddressableDefine.ItemFrame(_itemInfo.Quality);
  61. VM.ItemIcon.icon = _itemInfo.Icon;
  62. VM.UseBtn.visible =
  63. _itemInfo.Type == (int)EItemType.Gift
  64. || _itemInfo.Type == (int)EItemType.RedEnvelope;
  65. bool bHideJumpUI = _itemInfo.Jump?.Length == 0;
  66. VM.JumpUICtrl.selectedIndex = bHideJumpUI ? 1 : 0;
  67. if (!bHideJumpUI)
  68. {
  69. ShowJumpUI(_itemInfo.Jump);
  70. }
  71. }
  72. /// <summary>
  73. /// 显示来源跳转UI
  74. /// </summary>
  75. private void ShowJumpUI(int[] jumpIds)
  76. {
  77. VM.JumpList.BindDatas(jumpIds);
  78. }
  79. }
  80. }