123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- /// #pkgName FGUI包名
- /// #panelName UIPanel名字
- /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
- /// 该脚本由模板创建
- /// created by cb 2024
- using FairyGUI;
- using XGame.Framework.UI;
- namespace FL.FGUI
- {
- /// <summary>
- /// UI逻辑处理类
- /// </summary>
- /// <typeparam name=""></typeparam>
- public partial class MountMainPanelCtrl : UIController<MountMainPanelVM>
- {
- private int _pageIndex; // 当前显示的页签索引
- protected override void OnEnable(object intent)
- {
- AddUIListenres();
- AddEventListener();
- if (intent != null && intent is int)
- {
- _pageIndex = (int)intent;
- }
- else
- _pageIndex = 0;
- Init();
- }
- protected override void OnDisable()
- {
- RemoveUIListenres();
- RemoveEventListener();
- VM.UpgradeNestedItem.Ctrl.ClearData();
- VM.AdvancedNestedItem.Ctrl.ClearData();
- VM.TrainNestedItem.Ctrl.ClearData();
- }
- #region UI事件
- private void AddUIListenres()
- {
- VM.PageCtrl.onChanged.Add(OnPageCtrlChange);
- }
- private void RemoveUIListenres()
- {
- VM.PageCtrl.onChanged.Remove(OnPageCtrlChange);
- }
-
- /// <summary>
- /// 页签按钮切换事件
- /// </summary>
- /// <param name="context"></param>
- private void OnPageCtrlChange(EventContext context)
- {
- ShowPage(VM.PageCtrl.selectedIndex);
- }
- #endregion
- private void AddEventListener()
- {
- Context.AddListener(EventDefine.RefreshMountInfo, RefreshMountInfo);
- }
- private void RemoveEventListener()
- {
- Context.RemoveListener(EventDefine.RefreshMountInfo, RefreshMountInfo);
- }
- private void Init()
- {
- MountService.Instance.SendToMountData();
- }
- /// <summary>
- /// 页签切换事件
- /// </summary>
- /// <param name="pageIndex"></param>
- private void ShowPage(int pageIndex)
- {
- _pageIndex = pageIndex;
- ShowUpgradeMountsUI(pageIndex == 0);
- ShowTrainMountsUI(pageIndex == 1);
- ShowAdvancedMountUI(pageIndex == 2);
- }
- /// <summary>
- /// 通用坐骑升级界面
- /// </summary>
- /// <param name="bShow"></param>
- private void ShowUpgradeMountsUI(bool bShow)
- {
- if (bShow)
- {
- VM.UpgradeNestedItem.Enable(null);
- VM.UpgradeNestedItem.Ctrl.ShowUpgradeMountUI();
- }
- else
- VM.UpgradeNestedItem.Disable();
- }
- /// <summary>
- /// 坐骑驯养界面
- /// </summary>
- /// <param name="bShow"></param>
- private void ShowTrainMountsUI(bool bShow)
- {
- if (bShow)
- {
- VM.TrainNestedItem.Enable(null);
- VM.TrainNestedItem.Ctrl.ShowTrainMountUI(true);
- }
- else
- VM.TrainNestedItem.Disable();
- }
- /// <summary>
- /// 高级坐骑界面
- /// </summary>
- /// <param name="bShow"></param>
- private void ShowAdvancedMountUI(bool bShow)
- {
- if (bShow)
- {
- VM.AdvancedNestedItem.Enable(null);
- VM.AdvancedNestedItem.Ctrl.ShowAdvancedMountUI(true);
- }
- else
- VM.AdvancedNestedItem.Disable();
- }
- /// <summary>
- /// 返回坐骑数据,刷新坐骑界面UI
- /// </summary>
- /// <param name="eventId"></param>
- /// <param name="args"></param>
- private void RefreshMountInfo(int eventId, object args)
- {
- ShowPage(_pageIndex);
- }
- }
- }
|