123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475 |
- /// #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
- {
- public struct MountModelParam
- {
- public int tableId; //序号ID(坐骑id*10000+阶级*100+星级)
- public int unlockStep;
- public bool bLock; // 是否未解锁状态
- public string spineName;
- }
- public struct MountAttrParam
- {
- public EAttributeType attrType;
- public int curVal; // 当前星阶的属性值
- public int nextVal;
- }
- /// <summary>
- /// UI逻辑处理类
- /// </summary>
- /// <typeparam name=""></typeparam>
- public partial class MountUpgradeNestedCtrl : UIController<MountUpgradeNestedVM>
- {
- private bool _bInitData = true;
- private int _mountIndex; // 当前显示的坐骑的索引
- private int _universalId;
- private int _feedCostItemId; // 升星需要的道具id
- private zuoqiInfoTable _curMountInfo;
- private List<MountModelParam> _mountModelList; // 普通坐骑模型列表
- private List<MountAttrParam> _mountBaseAttrList;
- private List<MountAttrParam> _mountSpecialAttrList;
- private Dictionary<int, zuoqiInfoTable> _mountStepMap; // 坐骑星阶数据
- /// <summary>
- /// 通用坐骑每阶的最大升星等级
- /// </summary>
- private const int MaxStarLv = 10;
- protected override void OnEnable(object intent)
- {
- AddUIListenres();
- AddEventListener();
- }
- protected override void OnDisable()
- {
- RemoveUIListenres();
- RemoveEventListener();
- VM.MountSpine.url = string.Empty;
- }
- private void AddEventListener()
- {
- Context.AddListener(EventDefine.ChangeRideState, ChangeRideState);
- Context.AddListener(EventDefine.UpdataItemData, OnUpdateItemNum);
- Context.AddListener(EventDefine.FeedMountSucessful, FeedMountSucessful);
- }
- private void RemoveEventListener()
- {
- Context.RemoveListener(EventDefine.ChangeRideState, ChangeRideState);
- Context.RemoveListener(EventDefine.UpdataItemData, OnUpdateItemNum);
- Context.RemoveListener(EventDefine.FeedMountSucessful, FeedMountSucessful);
- }
- public void ClearData()
- {
- _mountModelList?.Clear();
- _mountModelList = null;
- _mountBaseAttrList?.Clear();
- _mountBaseAttrList = null;
- _mountSpecialAttrList?.Clear();
- _mountSpecialAttrList = null;
- _mountStepMap?.Clear();
- _mountStepMap = null;
- _bInitData = true;
- }
- #region UI事件
- private void AddUIListenres()
- {
- 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);
- }
- private void RemoveUIListenres()
- {
- 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);
- }
- 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)
- {
- MountService.Instance.SendToFeedMount();
- }
- private void OnClickOneClickFeedingBtn(EventContext context)
- {
- MountService.Instance.SendToOneKeyFeedMount();
- }
- #endregion
- private void Init()
- {
- if (_mountStepMap == null) _mountStepMap = new Dictionary<int, zuoqiInfoTable>();
- if (_mountModelList == null) _mountModelList = new List<MountModelParam>();
- if (_mountBaseAttrList == null) _mountBaseAttrList = new List<MountAttrParam>();
- if (_mountSpecialAttrList == null) _mountSpecialAttrList = new List<MountAttrParam>();
- }
- /// <summary>
- /// 通用坐骑数据
- /// </summary>
- private void GetMouuntModelData()
- {
- _universalId = MountData.Instance.UniversalId;
- _curMountInfo = zuoqiInfoTableRepo.Get(MountData.Instance.UniversalId);
- if (_curMountInfo == null)
- {
- XGame.Log.Error($"坐骑表zuoqiInfo信息不存在,id:{MountData.Instance.UniversalId}");
- return;
- }
- var mountBaseInfo = zuoqiBaseTableRepo.Get(_curMountInfo.Zqid);
- if (mountBaseInfo != null)
- {
- VM.MountNameLabel.text = mountBaseInfo.Name;
- }
- _feedCostItemId = _curMountInfo.StarNeed[0];
- _mountModelList.Clear();
- int starLv = _curMountInfo.Star;
- var cfgInfoList = zuoqiInfoTableRepo.GetAll();
- var first = cfgInfoList[0];
- var last = cfgInfoList[cfgInfoList.Length - 1];
- int mountId = first.Zqid;
- string lastModelName = string.Empty;
- int paramId = mountId * 10000;
- for (var step = first.Step; step <= last.Step; step++)
- {
- var mountInfo = zuoqiInfoTableRepo.Get(paramId + step * 100);
- if (mountInfo != null)
- {
- if (mountInfo.Spine != lastModelName)
- {
- lastModelName = mountInfo.Spine;
- _mountModelList.Add(new MountModelParam()
- {
- tableId = mountInfo.Id,
- unlockStep = mountInfo.Step,
- bLock = _curMountInfo.Step < mountInfo.Step || starLv < mountInfo.Star,
- spineName = mountInfo.Spine
- });
- }
- if (mountInfo.Star == 0 && !_mountStepMap.ContainsKey(mountInfo.Step))
- {
- _mountStepMap.Add(mountInfo.Step, mountInfo);
- }
- }
- }
- }
- /// <summary>
- /// 优先获取骑乘的普通坐骑索引,如果骑乘的不是普通坐骑,则显示当前解锁的最高阶坐骑索引
- /// </summary>
- private void SetMountIndex()
- {
- _mountIndex = 0;
- int showMountModelId = 0;
- var advanceMountInfo = zuoqiBaseTableRepo.Get(MountData.Instance.MountModelId);
- if (advanceMountInfo == null)
- {
- var mountModelInfo = zuoqiInfoTableRepo.Get(MountData.Instance.MountModelId);
- if (mountModelInfo != null)
- {
- showMountModelId = mountModelInfo.Id;
- }
- }
-
- for (int i = 0; i < _mountModelList.Count; i++)
- {
- if (showMountModelId == 0)
- {
- if (_mountModelList[i].unlockStep > _curMountInfo.Step)
- {
- return;
- }
- else
- {
- _mountIndex = i;
- }
- }
- else if (_mountModelList[i].tableId == showMountModelId)
- {
- _mountIndex = i;
- return;
- }
- }
- }
- /// <summary>
- /// 通用坐骑升级界面
- /// </summary>
- public void ShowUpgradeMountUI()
- {
- if (_bInitData)
- {
- Init();
- GetMouuntModelData();
- SetMountIndex();
- _bInitData = false;
- }
- ShowSelectMount(_mountIndex);
- ShowMountBaseAttr(_curMountInfo.Star);
- ShowMountSpecialAttr(_curMountInfo.Step);
- VM.ExpBar.max = _curMountInfo.StarNeed[1];
- ShowExp();
- ShowStar();
- ShowFeedCostUI();
- }
- /// <summary>
- /// 通用坐骑升星经验进度
- /// </summary>
- private void ShowExp()
- {
- VM.ExpBar.value = VM.MaxUpgradeStep.selectedIndex == 1 ? VM.ExpBar.max : MountData.Instance.UniversalExp;
- }
- /// <summary>
- /// 通用坐骑的星级
- /// </summary>
- private void ShowStar()
- {
- VM.StarBar.GetController("StarLvCtrl").selectedIndex = _curMountInfo.Star;
- }
- /// <summary>
- /// 升星消耗
- /// </summary>
- private void ShowFeedCostUI()
- {
- VM.FeedCostItem.Ctrl.ShowCostUI(_feedCostItemId, 1);
- }
- /// <summary>
- /// (通用坐骑)特殊属性加成
- /// </summary>
- /// <param name="starLv"></param>
- private void ShowMountSpecialAttr(int stepLv)
- {
- VM.MountStepLvLabel.text = stepLv.ToString();
- var nextInfo = _mountStepMap.ContainsKey(_curMountInfo.Step + 1) ? _mountStepMap[_curMountInfo.Step + 1] : null;
- bool bMaxStep = nextInfo == null;
- if (bMaxStep && _curMountInfo.Star == MaxStarLv)
- {
- ShowMaxUpgradeStep(true);//满星阶状态
- ShowCostItemNestedUI(false);
- }
- VM.SpecialAttrItem.Ctrl.OnRefresh(0, new MountAttrParam()
- {
- attrType = (EAttributeType)_curMountInfo.StarSkill[0],
- curVal = _curMountInfo.StarSkill[1],
- nextVal = bMaxStep ? 0 : nextInfo.StarSkill[1]
- });
- if (!bMaxStep)
- {
- VM.NextStepLvLabel.text = string.Format(StringDefine.UnlockNextMountStep, nextInfo.Step);
- }
- }
- /// <summary>
- /// 满星阶
- /// </summary>
- /// <param name="bShow"></param>
- private void ShowMaxUpgradeStep(bool bShow)
- {
- VM.MaxUpgradeStep.selectedIndex = bShow ? 1 : 0;
- }
- /// <summary>
- /// 通用坐骑升级消耗
- /// </summary>
- /// <param name="bShow"></param>
- private void ShowCostItemNestedUI(bool bShow)
- {
- if (bShow)
- VM.FeedCostItem.Enable(null);
- else
- VM.FeedCostItem.Disable();
- }
- /// <summary>
- /// (通用坐骑)基础属性加成UI
- /// </summary>
- /// <param name="starLv"></param>
- private void ShowMountBaseAttr(int starLv)
- {
- VM.BaseStarLvLabel.text = string.Format(StringDefine.MountStarLevel, _curMountInfo.Step, starLv);
- _mountBaseAttrList.Clear();
- zuoqiInfoTable nextInfo;
- if (starLv < MaxStarLv)
- nextInfo = zuoqiInfoTableRepo.Get(_curMountInfo.Id + 1);
- else
- {
- //坐骑id*10000+阶级*100+星级
- nextInfo = zuoqiInfoTableRepo.Get(_curMountInfo.Zqid * 10000 + (_curMountInfo.Step + 1)*100);
- }
- bool bMax = nextInfo == null;
- int count = _curMountInfo.StepOwnAttr.Length;
- if (!bMax)
- {
- VM.NextStarLvLabel.text = string.Format(StringDefine.MountStarLevel, nextInfo.Step, nextInfo.Star);
- }
- for (int i = 0; i < count; i += 2)
- {
- _mountBaseAttrList.Add(new MountAttrParam()
- {
- attrType = (EAttributeType)_curMountInfo.StepOwnAttr[i],
- curVal = _curMountInfo.StepOwnAttr[i + 1],
- nextVal = bMax ? 0 : nextInfo.StepOwnAttr[i + 1]
- });
- }
- VM.BaseAttrList.BindDatas(_mountBaseAttrList);
- }
- /// <summary>
- /// 显示选择的普通坐骑立绘
- /// </summary>
- private void ShowSelectMount(int selectIndex)
- {
- _mountIndex = selectIndex;
- var param = _mountModelList[_mountIndex];
- if (param.tableId > 0)
- {
- ShowMountSpine(param.spineName, true);
- ShowRideUI(!param.bLock);
- ShowUnlockLv(param.bLock);
- if (param.bLock)
- {
- VM.UnLockModelLabel.text = string.Format(StringDefine.UnlockMountStep, param.unlockStep);
- }
- else
- ShowRideUI(true, param.tableId == MountData.Instance.MountModelId);
- }
- ShowSwitchMountBtnState();
- }
- /// <summary>
- /// 是否显示解锁条件
- /// </summary>
- /// <param name="bShow"></param>
- private void ShowUnlockLv(bool bShow)
- {
- VM.UnLockModelLabel.visible = bShow;
- }
- /// <summary>
- /// 坐骑的立绘
- /// </summary>
- /// <param name="mountPicture"></param>
- private void ShowMountSpine(string spineName, bool bShowTraining = false)
- {
- VM.MountSpine.LoadSpine(spineName, "stand", true);
- }
- /// <summary>
- /// 普通坐骑上一个/下一个切换按钮的状态
- /// </summary>
- private void ShowSwitchMountBtnState()
- {
- VM.LastBtn.visible = _mountIndex > 0;
- VM.NextBtn.visible = _mountIndex < _mountModelList.Count - 1;
- }
- /// <summary>
- /// 坐骑成功喂养
- /// </summary>
- /// <param name="eventId"></param>
- /// <param name="args"></param>
- private void FeedMountSucessful(int eventId, object args)
- {
- if (_universalId == MountData.Instance.UniversalId)
- {
- ShowExp();
- return;
- }
- GetMouuntModelData();
- ShowUpgradeMountUI();
- }
- /// <summary>
- /// 坐骑骑乘状态变化
- /// </summary>
- /// <param name="eventId"></param>
- /// <param name="args"></param>
- private void ChangeRideState(int eventId, object args)
- {
- var param = _mountModelList[_mountIndex];
- if (param.tableId > 0)
- {
- ShowRideUI(!param.bLock, param.tableId == MountData.Instance.MountModelId);
- }
- }
- /// <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 OnUpdateItemNum(int eventId, object args)
- {
- var itemDataList = args as List<ActItem>;
- if (itemDataList?.Count > 0)
- {
- for (int i = 0; i < itemDataList.Count; i++)
- {
- if (itemDataList[i].id == _feedCostItemId)
- {
- // 通用坐骑升星消耗
- ShowFeedCostUI();
- }
- }
- }
- }
- }
- }
|