/// #pkgName FGUI包名
/// #panelName UIPanel名字
/// #UIName = $"{#pkgName}{#panelName}" UIKey名字
/// 该脚本由模板创建
/// created by cb 2024
using FairyGUI;
using XGame.Framework.UI;
namespace FL.FGUI
{
///
/// UI逻辑处理类
///
///
public partial class MountMainPanelCtrl : UIController
{
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);
}
///
/// 页签按钮切换事件
///
///
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();
}
///
/// 页签切换事件
///
///
private void ShowPage(int pageIndex)
{
_pageIndex = pageIndex;
ShowUpgradeMountsUI(pageIndex == 0);
ShowTrainMountsUI(pageIndex == 1);
ShowAdvancedMountUI(pageIndex == 2);
}
///
/// 通用坐骑升级界面
///
///
private void ShowUpgradeMountsUI(bool bShow)
{
if (bShow)
{
VM.UpgradeNestedItem.Enable(null);
VM.UpgradeNestedItem.Ctrl.ShowUpgradeMountUI();
}
else
VM.UpgradeNestedItem.Disable();
}
///
/// 坐骑驯养界面
///
///
private void ShowTrainMountsUI(bool bShow)
{
if (bShow)
{
VM.TrainNestedItem.Enable(null);
VM.TrainNestedItem.Ctrl.ShowTrainMountUI(true);
}
else
VM.TrainNestedItem.Disable();
}
///
/// 高级坐骑界面
///
///
private void ShowAdvancedMountUI(bool bShow)
{
if (bShow)
{
VM.AdvancedNestedItem.Enable(null);
VM.AdvancedNestedItem.Ctrl.ShowAdvancedMountUI(true);
}
else
VM.AdvancedNestedItem.Disable();
}
///
/// 返回坐骑数据,刷新坐骑界面UI
///
///
///
private void RefreshMountInfo(int eventId, object args)
{
ShowPage(_pageIndex);
}
}
}