123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 |
- /// #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
- {
- /// <summary>
- /// UI逻辑处理类
- /// </summary>
- /// <typeparam name=""></typeparam>
- public partial class MountTrainNestedCtrl : UIController<MountTrainNestedVM>
- {
- private bool _bInitData = true;
- private int _trainCostItemId; // 驯养需要的道具id
- private int _trainCostNum; // 驯养需要的道具数量
- private List<MountTrainingAreaNestedView> _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<MountTrainingAreaNestedView>() { 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);
- }
- }
- /// <summary>
- /// 优先获取骑乘的坐骑皮肤,其次获取解锁的最高阶的通用坐骑皮肤
- /// </summary>
- /// <returns></returns>
- 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;
-
- }
- /// <summary>
- /// 坐骑的立绘
- /// </summary>
- /// <param name="mountPicture"></param>
- private void ShowMountSpine(string spineName, bool bShowTraining = false)
- {
- VM.MountSpine.LoadSpine(spineName, "stand", true);
- }
- /// <summary>
- /// 幸运值
- /// </summary>
- /// <param name="total"></param>
- private void ShowTrainExp(int total)
- {
- VM.TrainLuckyBar.max = total;
- VM.TrainLuckyBar.value = MountData.Instance.MountPartExp;
- }
- /// <summary>
- /// 训练部位等级加成属性
- /// </summary>
- /// <param name="mountsPartsMap"></param>
- private void ShowTrainAttrUI(Dictionary<int, int> mountsPartsMap)
- {
- for (int i = 0; i < _trainPartsList.Count; i++)
- {
- _trainPartsList[i].Ctrl.ShowUI(GetTrainInfo(i + 1, mountsPartsMap));
- }
- }
- private TrainParam GetTrainInfo(int part, Dictionary<int, int> 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,
- };
- }
- /// <summary>
- /// 坐骑驯养消耗
- /// </summary>
- private void ShowTrainCostUI()
- {
- VM.TrainCostItem.Ctrl.ShowCostUI(_trainCostItemId, _trainCostNum);
- }
- /// <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.TrainCostItem.Enable(null);
- else
- VM.TrainCostItem.Disable();
- }
- /// <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 == _trainCostItemId)
- {
- // 通用坐骑驯养消耗
- ShowTrainCostUI();
- }
- }
- }
- }
- /// <summary>
- /// 坐骑训练成功
- /// </summary>
- /// <param name="eventId"></param>
- /// <param name="args"></param>
- private void TrainMountSucessful(int eventId, object args)
- {
- ShowTrainMountUI(false);
- }
- }
- }
|