CommonConfirmationBoxCtrl.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /// #pkgName FGUI包名
  2. /// #panelName UIPanel名字
  3. /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
  4. /// 该脚本由模板创建
  5. /// created by cb 2024
  6. using FairyGUI;
  7. using FL.Data;
  8. using System;
  9. using XGame.Framework.UI;
  10. namespace FL.FGUI
  11. {
  12. /// <summary>
  13. /// 今日不再提醒key
  14. /// </summary>
  15. public enum EDayTipsKey : uint
  16. {
  17. SellEquip = 1, // 出售比穿戴装备高战力
  18. }
  19. public class ConfirmationBoxParam
  20. {
  21. public string cnt;
  22. public EDayTipsKey tipsKey;
  23. public Action onPromiseCallback; // 确定按钮回调函数
  24. public Action onCancelCallback;
  25. }
  26. /// <summary>
  27. /// UI逻辑处理类
  28. /// </summary>
  29. /// <typeparam name=""></typeparam>
  30. public partial class CommonConfirmationBoxCtrl : UIController<CommonConfirmationBoxVM>
  31. {
  32. private ConfirmationBoxParam _data;
  33. protected override void OnEnable(object intent)
  34. {
  35. AddUIListenres();
  36. _data = intent as ConfirmationBoxParam;
  37. ShowUI();
  38. }
  39. protected override void OnDisable()
  40. {
  41. _data = null;
  42. RemoveUIListenres();
  43. }
  44. #region UI事件
  45. private void AddUIListenres()
  46. {
  47. VM.CancelBtn.onClick.Add(OnClickCancelBtn);
  48. VM.SureBtn.onClick.Add(OnClickSureBtn);
  49. VM.ToggleBtn.onClick.Add(OnClickToggleBtn);
  50. }
  51. private void RemoveUIListenres()
  52. {
  53. VM.CancelBtn.onClick.Remove(OnClickCancelBtn);
  54. VM.SureBtn.onClick.Remove(OnClickSureBtn);
  55. VM.ToggleBtn.onClick.Remove(OnClickToggleBtn);
  56. }
  57. private void OnClickCancelBtn(EventContext context)
  58. {
  59. if (_data?.onCancelCallback != null)
  60. {
  61. _data.onCancelCallback();
  62. }
  63. Context.ClosePanel();
  64. }
  65. private void OnClickSureBtn(EventContext context)
  66. {
  67. if (_data?.onPromiseCallback != null)
  68. {
  69. _data.onPromiseCallback();
  70. }
  71. Context.ClosePanel();
  72. }
  73. private void OnClickToggleBtn(EventContext context)
  74. {
  75. // 测试出售高战力装备不再提示
  76. if (_data?.tipsKey > 0 && _data.tipsKey == EDayTipsKey.SellEquip)
  77. {
  78. DragonEggData.Instance.CheckDayTipsKey = VM.ToggleBtn.selected;
  79. }
  80. }
  81. #endregion
  82. private void ShowUI()
  83. {
  84. if (_data?.cnt != null)
  85. {
  86. VM.CntLabel.text = _data.cnt;
  87. }
  88. VM.ShowToggleUI.selectedIndex = _data?.tipsKey > 0 ? 1 : 0;
  89. }
  90. }
  91. }