/// #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; } /// /// UI逻辑处理类 /// /// public partial class MountUpgradeNestedCtrl : UIController { private bool _bInitData = true; private int _mountIndex; // 当前显示的坐骑的索引 private int _universalId; private int _feedCostItemId; // 升星需要的道具id private zuoqiInfoTable _curMountInfo; private List _mountModelList; // 普通坐骑模型列表 private List _mountBaseAttrList; private List _mountSpecialAttrList; private Dictionary _mountStepMap; // 坐骑星阶数据 /// /// 通用坐骑每阶的最大升星等级 /// 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(); if (_mountModelList == null) _mountModelList = new List(); if (_mountBaseAttrList == null) _mountBaseAttrList = new List(); if (_mountSpecialAttrList == null) _mountSpecialAttrList = new List(); } /// /// 通用坐骑数据 /// 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); } } } } /// /// 优先获取骑乘的普通坐骑索引,如果骑乘的不是普通坐骑,则显示当前解锁的最高阶坐骑索引 /// 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; } } } /// /// 通用坐骑升级界面 /// 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(); } /// /// 通用坐骑升星经验进度 /// private void ShowExp() { VM.ExpBar.value = VM.MaxUpgradeStep.selectedIndex == 1 ? VM.ExpBar.max : MountData.Instance.UniversalExp; } /// /// 通用坐骑的星级 /// private void ShowStar() { VM.StarBar.GetController("StarLvCtrl").selectedIndex = _curMountInfo.Star; } /// /// 升星消耗 /// private void ShowFeedCostUI() { VM.FeedCostItem.Ctrl.ShowCostUI(_feedCostItemId, 1); } /// /// (通用坐骑)特殊属性加成 /// /// 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); } } /// /// 满星阶 /// /// private void ShowMaxUpgradeStep(bool bShow) { VM.MaxUpgradeStep.selectedIndex = bShow ? 1 : 0; } /// /// 通用坐骑升级消耗 /// /// private void ShowCostItemNestedUI(bool bShow) { if (bShow) VM.FeedCostItem.Enable(null); else VM.FeedCostItem.Disable(); } /// /// (通用坐骑)基础属性加成UI /// /// 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); } /// /// 显示选择的普通坐骑立绘 /// 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(); } /// /// 是否显示解锁条件 /// /// private void ShowUnlockLv(bool bShow) { VM.UnLockModelLabel.visible = bShow; } /// /// 坐骑的立绘 /// /// private void ShowMountSpine(string spineName, bool bShowTraining = false) { VM.MountSpine.LoadSpine(spineName, "stand", true); } /// /// 普通坐骑上一个/下一个切换按钮的状态 /// private void ShowSwitchMountBtnState() { VM.LastBtn.visible = _mountIndex > 0; VM.NextBtn.visible = _mountIndex < _mountModelList.Count - 1; } /// /// 坐骑成功喂养 /// /// /// private void FeedMountSucessful(int eventId, object args) { if (_universalId == MountData.Instance.UniversalId) { ShowExp(); return; } GetMouuntModelData(); ShowUpgradeMountUI(); } /// /// 坐骑骑乘状态变化 /// /// /// private void ChangeRideState(int eventId, object args) { var param = _mountModelList[_mountIndex]; if (param.tableId > 0) { ShowRideUI(!param.bLock, param.tableId == MountData.Instance.MountModelId); } } /// /// 骑乘状态UI /// /// /// private void ShowRideUI(bool bShow, bool bRide = false) { VM.RideBtn.visible = bShow; if (bShow) { VM.RideCtrl.selectedIndex = bRide ? 1 : 0; } } /// /// 道具数据变化 /// /// /// private void OnUpdateItemNum(int eventId, object args) { var itemDataList = args as List; if (itemDataList?.Count > 0) { for (int i = 0; i < itemDataList.Count; i++) { if (itemDataList[i].id == _feedCostItemId) { // 通用坐骑升星消耗 ShowFeedCostUI(); } } } } } }