123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307 |
- /// #pkgName FGUI包名
- /// #panelName UIPanel名字
- /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
- /// 该脚本由模板创建
- /// created by cb 2024
- using FairyGUI;
- using FL.Network;
- using System.Collections.Generic;
- using XGame.Database;
- using XGame.Framework.UI;
- namespace FL.FGUI
- {
- /// <summary>
- /// UI逻辑处理类
- /// </summary>
- /// <typeparam name=""></typeparam>
- public partial class MountDevelopPanelCtrl : UIController<MountDevelopPanelVM>
- {
- private int _pageIndex; // 当前显示的页签索引
- protected override void OnEnable(object intent)
- {
- AddUIListenres();
- AddEventListener();
- Init();
- }
- protected override void OnDisable()
- {
- RemoveUIListenres();
- RemoveEventListener();
- }
- #region UI事件
- private void AddUIListenres()
- {
- VM.UpgradeBtn.onClick.Add(OnClickUpgradeBtn);
- VM.TrainBtn.onClick.Add(OnClickTrainBtn);
- VM.AdvancedMountBtn.onClick.Add(OnClickAdvancedMountBtn);
- VM.LastBtn.onClick.Add(OnClickLastBtn);
- VM.NextBtn.onClick.Add(OnClickNextBtn);
- VM.RideBtn.onClick.Add(OnClickRideBtn);
- VM.FeedBtn.onClick.Add(OnClickFeedBtn);
- VM.OneClickFeedingBtn.onClick.Add(OnClickOneClickFeedingBtn);
- VM.UpgradePreviewBtn.onClick.Add(OnClickUpgradePreviewBtn);
- VM.EnableSkillBtn.onClick.Add(OnClickEnableSkillBtn);
- VM.UpgradeMountBtn.onClick.Add(OnClickUpgradeMountBtn);
- VM.UnlockMountBtn.onClick.Add(OnClickUnlockMountBtn);
- VM.AdvancedMountList.ItemClickEvent += ClickAdvancedMountItem;
- }
- private void RemoveUIListenres()
- {
- VM.UpgradeBtn.onClick.Remove(OnClickUpgradeBtn);
- VM.TrainBtn.onClick.Remove(OnClickTrainBtn);
- VM.AdvancedMountBtn.onClick.Remove(OnClickAdvancedMountBtn);
- VM.LastBtn.onClick.Remove(OnClickLastBtn);
- VM.NextBtn.onClick.Remove(OnClickNextBtn);
- VM.RideBtn.onClick.Remove(OnClickRideBtn);
- VM.FeedBtn.onClick.Remove(OnClickFeedBtn);
- VM.OneClickFeedingBtn.onClick.Remove(OnClickOneClickFeedingBtn);
- VM.UpgradePreviewBtn.onClick.Remove(OnClickUpgradePreviewBtn);
- VM.EnableSkillBtn.onClick.Remove(OnClickEnableSkillBtn);
- VM.UpgradeMountBtn.onClick.Remove(OnClickUpgradeMountBtn);
- VM.UnlockMountBtn.onClick.Remove(OnClickUnlockMountBtn);
- VM.AdvancedMountList.ItemClickEvent -= ClickAdvancedMountItem;
- }
- /// <summary>
- /// 坐骑升级页签按钮
- /// </summary>
- /// <param name="context"></param>
- private void OnClickUpgradeBtn(EventContext context)
- {
- ShowPage(0);
- }
- /// <summary>
- /// 坐骑驯养页签按钮
- /// </summary>
- /// <param name="context"></param>
- private void OnClickTrainBtn(EventContext context)
- {
- ShowPage(1);
- }
- /// <summary>
- /// 高级坐骑页签按钮
- /// </summary>
- /// <param name="context"></param>
- private void OnClickAdvancedMountBtn(EventContext context)
- {
- ShowPage(2);
- }
- private void OnClickLastBtn(EventContext context)
- {
- if (_mountIndex > 0) ShowSelectMount(_mountIndex - 1);
- }
- private void OnClickNextBtn(EventContext context)
- {
- if (_mountIndex < _mountModelList.Count - 1) ShowSelectMount(_mountIndex + 1);
- }
- private void OnClickRideBtn(EventContext context)
- {
- int mountId = _mountModelList[_mountIndex].tableId;
- if (mountId == MountData.Instance.mountModelId)
- {
- MountService.Instance.SendToRideDown();
- }
- else
- MountService.Instance.SendToRideMount(mountId);
- }
- private void OnClickFeedBtn(EventContext context)
- {
- if (_pageIndex == 0)
- MountService.Instance.SendToFeedMount();
- else if (_pageIndex == 1)
- MountService.Instance.SendToTrainingMountPart();
- }
- private void OnClickOneClickFeedingBtn(EventContext context)
- {
- if (_pageIndex == 0)
- MountService.Instance.SendToOneKeyFeedMount();
- else if (_pageIndex == 1)
- MountService.Instance.SendToOneKeyTraining();
- }
- private void OnClickUpgradePreviewBtn(EventContext context)
- {
- }
- private void OnClickEnableSkillBtn(EventContext context)
- {
- MountService.Instance.SendToEnableAdvancedSkill(_advancedMountsInfoList[_curAdvancedIndex].Id);
- }
- private void OnClickUpgradeMountBtn(EventContext context)
- {
- MountService.Instance.SendToUpgradeStar(_advancedMountsInfoList[_curAdvancedIndex].Id);
- }
- private void OnClickUnlockMountBtn(EventContext context)
- {
- MountService.Instance.SendToUnlockAdvancedMount(_advancedMountsInfoList[_curAdvancedIndex].Id);
- }
- #endregion
- private void AddEventListener()
- {
- EventSingle.Instance.AddListener(EventDefine.RefreshMountInfo, RefreshMountInfo);
- EventSingle.Instance.AddListener(EventDefine.ChangeRideState, ChangeRideState);
- EventSingle.Instance.AddListener(EventDefine.UpdataItemData, OnUpdateItemNum);
- EventSingle.Instance.AddListener(EventDefine.FeedMountSucessful, FeedMountSucessful);
- EventSingle.Instance.AddListener(EventDefine.TrainMountSucessful, TrainMountSucessful);
- EventSingle.Instance.AddListener(EventDefine.UnlockAdvancedMountSucessful, UnlockAdvancedMountSucessful);
- EventSingle.Instance.AddListener(EventDefine.UseMountSkillSucessful, UseMountSkillSucessful);
- EventSingle.Instance.AddListener(EventDefine.UpgradeAdvancedMountSucessful, UpgradeAdvancedMountSucessful);
- }
- private void RemoveEventListener()
- {
- EventSingle.Instance.RemoveListener(EventDefine.RefreshMountInfo, RefreshMountInfo);
- EventSingle.Instance.RemoveListener(EventDefine.ChangeRideState, ChangeRideState);
- EventSingle.Instance.RemoveListener(EventDefine.UpdataItemData, OnUpdateItemNum);
- EventSingle.Instance.RemoveListener(EventDefine.FeedMountSucessful, FeedMountSucessful);
- EventSingle.Instance.RemoveListener(EventDefine.TrainMountSucessful, TrainMountSucessful);
- EventSingle.Instance.RemoveListener(EventDefine.UnlockAdvancedMountSucessful, UnlockAdvancedMountSucessful);
- EventSingle.Instance.RemoveListener(EventDefine.UseMountSkillSucessful, UseMountSkillSucessful);
- EventSingle.Instance.RemoveListener(EventDefine.UpgradeAdvancedMountSucessful, UpgradeAdvancedMountSucessful);
- }
- private void Init()
- {
- if (_mountStepMap == null)_mountStepMap = new Dictionary<int, zuoqiInfoTable>();
- if (_mountModelList == null)_mountModelList = new List<MountModelParam>();
- if (_advancedMountsInfoList == null) _advancedMountsInfoList = new List<zuoqiBaseTable> ();
- if (_mountBaseAttrList == null) _mountBaseAttrList = new List<MountAttrParam> ();
- if (_mountSpecialAttrList == null) _mountSpecialAttrList = new List<MountAttrParam>();
- if (_trainPartsList == null)
- {
- _trainPartsList = new List<MountTrainingAreaNestedView>() { VM.TrainingTheHead, VM.TrainingTheBody, VM.TrainingFeet };
- }
- _mountIndex = 0;
- _pageIndex = 0;
- MountService.Instance.SendToMountData();
- }
- /// <summary>
- /// 道具数据变化
- /// </summary>
- /// <param name="eventId"></param>
- /// <param name="args"></param>
- private void OnUpdateItemNum(int eventId, object args)
- {
- var itemDataList = args as List<ActItem>;
- if (itemDataList?.Count > 0)
- {
- for (int i = 0; i < itemDataList.Count; i++)
- {
- if (_pageIndex == 0 && itemDataList[i].id == _feedCostItemId)
- {
- // 通用坐骑升星消耗
- ShowFeedCostUI();
- }
- else if (_pageIndex == 1 && itemDataList[i].id == _trainCostItemId)
- {
- // 通用坐骑驯养消耗
- ShowTrainCostUI();
- }
- }
- }
- }
- /// <summary>
- /// 返回坐骑数据,刷新坐骑界面UI
- /// </summary>
- /// <param name="eventId"></param>
- /// <param name="args"></param>
- private void RefreshMountInfo(int eventId, object args)
- {
- GetAdvanceMountData();
- GetMouuntModelData();
- if (_pageIndex == 0)
- {
- ShowPage(0);
- }
- }
- /// <summary>
- /// 页签切换事件
- /// </summary>
- /// <param name="pageIndex"></param>
- private void ShowPage(int pageIndex)
- {
- _pageIndex = pageIndex;
- VM.PageCtrl.selectedIndex = pageIndex;
- ShowAdvancedMountBtn(false);
- ShowUnlockLv(false);
- ShowEnableSkillBtn(false);
- ShowUpgradePreviewBtn(false);
- ShowMountStar(false);
- ShowTrainPartUI(pageIndex == 1);
- if (pageIndex == 0)
- {
- ShowUniversalMountsUI();
- }
- else if(pageIndex == 1)
- {
- ShowTrainMountsUI();
- ShowRideUI(false);
- }
- else if (pageIndex == 2)
- {
- ShowAdvancedMountUI();
- }
- }
- /// <summary>
- /// 是否显示高级坐骑的星级
- /// </summary>
- /// <param name="bShow"></param>
- private void ShowMountStar(bool bShow)
- {
- VM.MountStar.visible = bShow;
- }
- /// <summary>
- /// 显示坐骑名称
- /// </summary>
- /// <param name="name"></param>
- private void ShowMountName(string name)
- {
- VM.MountNameLabel.text = name;
- }
- /// <summary>
- /// 骑乘状态UI
- /// </summary>
- /// <param name="bShow"></param>
- /// <param name="bRide"></param>
- private void ShowRideUI(bool bShow, bool bRide = false)
- {
- VM.RideBtn.visible = bShow;
- if (bShow)
- {
- VM.RideCtrl.selectedIndex = bRide ? 1 : 0;
- }
- }
- /// <summary>
- /// 坐骑骑乘状态变化
- /// </summary>
- /// <param name="eventId"></param>
- /// <param name="args"></param>
- private void ChangeRideState(int eventId, object args)
- {
- if (_pageIndex == 0)
- {
- var param = _mountModelList[_mountIndex];
- if (param.tableId > 0)
- {
- ShowRideUI(!param.bLock, param.tableId == MountData.Instance.mountModelId);
- }
- }
- else if (_pageIndex == 2)
- {
- int mountId = _advancedMountsInfoList[_curAdvancedIndex].Id;
- ShowRideUI(MountData.Instance.IsUnLock(mountId), mountId == MountData.Instance.mountModelId);
- }
- }
- }
- }
|