/// #pkgName FGUI包名 /// #panelName UIPanel名字 /// #UIName = $"{#pkgName}{#panelName}" UIKey名字 /// 该脚本由模板创建 /// created by cb 2024 using FairyGUI; using FL.Data; using FL.Network; using System.Collections.Generic; using XGame.Database; using XGame.Framework.UI; namespace FL.FGUI { /// /// UI逻辑处理类 /// /// public partial class MountTrainNestedCtrl : UIController { private bool _bInitData = true; private int _trainCostItemId; // 驯养需要的道具id private int _trainCostNum; // 驯养需要的道具数量 private List _trainPartsList; // 训练部位列表 protected override void OnEnable(object intent) { AddUIListenres(); AddEventListener(); } protected override void OnDisable() { RemoveUIListenres(); RemoveEventListener(); } #region UI事件 private void AddUIListenres() { VM.TrainBtn.onClick.Add(OnClickTrainBtnBtn); VM.OneClickTrainBtn.onClick.Add(OnClickOneClickTrainBtn); } private void RemoveUIListenres() { VM.TrainBtn.onClick.Remove(OnClickTrainBtnBtn); VM.OneClickTrainBtn.onClick.Remove(OnClickOneClickTrainBtn); } private void OnClickTrainBtnBtn(EventContext context) { if (ItemService.Instance.IsEnough(_trainCostItemId, _trainCostNum, true)) { MountService.Instance.SendToTrainingMountPart(); } } private void OnClickOneClickTrainBtn(EventContext context) { if (ItemService.Instance.IsEnough(_trainCostItemId, _trainCostNum, true)) { MountService.Instance.SendToOneKeyTraining(); } } #endregion private void AddEventListener() { Context.AddListener(EventDefine.UpdataItemData, OnUpdateItemNum); Context.AddListener(EventDefine.TrainMountSucessful, TrainMountSucessful); } private void RemoveEventListener() { Context.RemoveListener(EventDefine.UpdataItemData, OnUpdateItemNum); Context.RemoveListener(EventDefine.TrainMountSucessful, TrainMountSucessful); } public void ClearData() { _trainPartsList?.Clear(); _trainPartsList = null; _bInitData = true; } private void Init() { if (_trainPartsList == null) { _trainPartsList = new List() { VM.TrainingTheHead, VM.TrainingTheBody, VM.TrainingFeet }; } } public void ShowTrainMountUI(bool bShowSpine) { if (_bInitData) { Init(); _bInitData = false; } int totalLv = 0; // 驯养总等级 var mountsPartsMap = MountData.Instance.MountsPartsMap; foreach (var item in mountsPartsMap) { totalLv += item.Value; } VM.TrainTotalLvLabel.text = string.Format(StringDefine.TotalTrainLevel, totalLv); var curTrainInfo = zuoqiBuweiProbTableRepo.Get(totalLv); if (curTrainInfo != null) { ShowTrainExp(curTrainInfo.Success); _trainCostItemId = curTrainInfo.LevelUpCost[0]; _trainCostNum = curTrainInfo.LevelUpCost.Length > 1 ? curTrainInfo.LevelUpCost[1] : 1; VM.TrainRateLabel.text = string.Format(StringDefine.TrainSuccessRate, curTrainInfo.Prob.ToRealFloatPercentage()); } ShowTrainAttrUI(mountsPartsMap); if (zuoqiBuweiProbTableRepo.Get(totalLv + 1) == null) { ShowMaxUpgradeStep(true); ShowCostItemNestedUI(false); } else ShowTrainCostUI(); if (bShowSpine) { ShowMountSpine(GetMountAppearance(), true); } } /// /// 优先获取骑乘的坐骑皮肤,其次获取解锁的最高阶的通用坐骑皮肤 /// /// private string GetMountAppearance() { string mountSpine = MountData.Instance.GetRidingAppearance(); if (string.IsNullOrEmpty(mountSpine)) { var mountInfo = zuoqiInfoTableRepo.Get(MountData.Instance.UniversalId); if (mountInfo != null) mountSpine = mountInfo.Spine; } return mountSpine; } /// /// 坐骑的立绘 /// /// private void ShowMountSpine(string spineName, bool bShowTraining = false) { VM.MountSpine.LoadSpine(spineName, "stand", true); } /// /// 幸运值 /// /// private void ShowTrainExp(int total) { VM.TrainLuckyBar.max = total; VM.TrainLuckyBar.value = MountData.Instance.MountPartExp; } /// /// 训练部位等级加成属性 /// /// private void ShowTrainAttrUI(Dictionary mountsPartsMap) { for (int i = 0; i < _trainPartsList.Count; i++) { _trainPartsList[i].Ctrl.ShowUI(GetTrainInfo(i + 1, mountsPartsMap)); } } private TrainParam GetTrainInfo(int part, Dictionary mountsPartsMap) { int trainLv = 0; zuoqiBuweiTable trainInfo = null; if (mountsPartsMap.ContainsKey(part)) { trainLv = mountsPartsMap[part]; //部位*1000+部位等级 trainInfo = zuoqiBuweiTableRepo.Get(part * 1000 + mountsPartsMap[part]); } return new TrainParam() { level = trainLv, trainInfo = trainInfo, }; } /// /// 坐骑驯养消耗 /// private void ShowTrainCostUI() { VM.TrainCostItem.Ctrl.ShowCostUI(_trainCostItemId, _trainCostNum); } /// /// /// /// private void ShowMaxUpgradeStep(bool bShow) { VM.MaxUpgradeStep.selectedIndex = bShow ? 1 : 0; } /// /// /// /// private void ShowCostItemNestedUI(bool bShow) { if (bShow) VM.TrainCostItem.Enable(null); else VM.TrainCostItem.Disable(); } /// /// 道具数据变化 /// /// /// 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 == _trainCostItemId) { // 通用坐骑驯养消耗 ShowTrainCostUI(); } } } } /// /// 坐骑训练成功 /// /// /// private void TrainMountSucessful(int eventId, object args) { ShowTrainMountUI(false); } } }