123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520 |
- /// #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 System.Linq;
- using UnityEngine;
- using XGame.Database;
- using XGame.Framework.UI;
- namespace FL.FGUI
- {
- /// <summary>
- /// 高级坐骑升级预览
- /// </summary>
- public struct UpgradePreviewParam
- {
- public int mountId;
- public int level;
- public int skillId;
- }
- /// <summary>
- /// UI逻辑处理类
- /// </summary>
- /// <typeparam name=""></typeparam>
- public partial class MountAdvancedNestedCtrl : UIController<MountAdvancedNestedVM>
- {
- private bool _bInitData = true;
- private int _curAdvancedIndex; // 当前选择的高级坐骑索引
- private int[] _costData; // 解锁|升级消耗的道具id和数量
- private List<zuoqiBaseTable> _advancedMountsInfoList; // 高级坐骑信息列表数据
- private Dictionary<int, List<UpgradePreviewParam>> _upgradePreviewMap; // 坐骑升级预览数据
- protected override void OnEnable(object intent)
- {
- AddUIListenres();
- AddEventListener();
- }
- protected override void OnDisable()
- {
- RemoveUIListenres();
- RemoveEventListener();
- }
- #region UI事件
- private void AddUIListenres()
- {
- VM.RideBtn.onClick.Add(OnClickRideBtn);
- VM.UpgradePreviewBtn.onClick.Add(OnClickUpgradePreviewBtn);
- VM.EnableSkillBtn.onClick.Add(OnClickEnableSkillBtn);
- VM.UpgradeMountBtn.onClick.Add(OnClickUpgradeMountBtn);
- VM.UnlockMountBtn.onClick.Add(OnClickUnlockMountBtn);
- }
- private void RemoveUIListenres()
- {
- VM.RideBtn.onClick.Remove(OnClickRideBtn);
- VM.UpgradePreviewBtn.onClick.Remove(OnClickUpgradePreviewBtn);
- VM.EnableSkillBtn.onClick.Remove(OnClickEnableSkillBtn);
- VM.UpgradeMountBtn.onClick.Remove(OnClickUpgradeMountBtn);
- VM.UnlockMountBtn.onClick.Remove(OnClickUnlockMountBtn);
- }
- private void OnClickRideBtn(EventContext context)
- {
- int mountId = _advancedMountsInfoList[_curAdvancedIndex].Id;
- if (mountId == 0)
- {
- XGame.Framework.Assert.IsNotNull(mountId);
- }
- if (mountId == MountData.Instance.MountModelId)
- {
- MountService.Instance.SendToRideDown();
- }
- else
- MountService.Instance.SendToRideMount(mountId);
- }
- private void OnClickUpgradePreviewBtn(EventContext context)
- {
- int mountId = _advancedMountsInfoList[_curAdvancedIndex].Id;
- var dataList = _upgradePreviewMap.ContainsKey(mountId) ? _upgradePreviewMap[mountId] : null;
- Context.UI.OpenAsync(UIKeys.MountUpgradePreviewPanel, dataList);
- }
- private void OnClickEnableSkillBtn(EventContext context)
- {
- if (VM.SkillCtrl.selectedIndex == 0)
- MountService.Instance.SendToEnableAdvancedSkill(_advancedMountsInfoList[_curAdvancedIndex].Id);
- else
- MountService.Instance.SendToCancelAdvancedSkill();
- }
- private void OnClickUpgradeMountBtn(EventContext context)
- {
- MountService.Instance.SendToUpgradeStar(_advancedMountsInfoList[_curAdvancedIndex].Id);
- }
- private void OnClickUnlockMountBtn(EventContext context)
- {
- if (_advancedMountsInfoList[_curAdvancedIndex]?.Unlock.Length > 1)
- {
- int itemId = _advancedMountsInfoList[_curAdvancedIndex].Unlock[0];
- int needNum = _advancedMountsInfoList[_curAdvancedIndex].Unlock[1];
- if (ItemService.Instance.IsEnough(itemId, needNum, true))
- {
- MountService.Instance.SendToUnlockAdvancedMount(_advancedMountsInfoList[_curAdvancedIndex].Id);
- }
- }
- }
- #endregion
- private void AddEventListener()
- {
- Context.AddListener(EventDefine.ChangeRideState, ChangeRideState);
- Context.AddListener(EventDefine.UpdataItemData, OnUpdateItemNum);
- Context.AddListener(EventDefine.UnlockAdvancedMountSucessful, UnlockAdvancedMountSucessful);
- Context.AddListener(EventDefine.UseMountSkillSucessful, UseMountSkillSucessful);
- Context.AddListener(EventDefine.UpgradeAdvancedMountSucessful, UpgradeAdvancedMountSucessful);
- VM.AdvancedMountList.ItemClickEvent += ClickAdvancedMountItem;
- }
- private void RemoveEventListener()
- {
- Context.RemoveListener(EventDefine.ChangeRideState, ChangeRideState);
- Context.RemoveListener(EventDefine.UpdataItemData, OnUpdateItemNum);
- Context.RemoveListener(EventDefine.UnlockAdvancedMountSucessful, UnlockAdvancedMountSucessful);
- Context.RemoveListener(EventDefine.UseMountSkillSucessful, UseMountSkillSucessful);
- Context.RemoveListener(EventDefine.UpgradeAdvancedMountSucessful, UpgradeAdvancedMountSucessful);
- VM.AdvancedMountList.ItemClickEvent -= ClickAdvancedMountItem;
- }
- public void ClearData()
- {
- _advancedMountsInfoList?.Clear();
- _advancedMountsInfoList = null;
- _upgradePreviewMap?.Clear();
- _upgradePreviewMap = null;
- _bInitData = true;
- }
- /// <summary>
- /// 高级坐骑
- /// </summary>
- private void GetAdvanceMountData()
- {
- if (_advancedMountsInfoList == null) _advancedMountsInfoList = new List<zuoqiBaseTable>();
- var dataList = zuoqiBaseTableRepo.GetAll();
- foreach (var item in dataList)
- {
- if (item.Type == 2) // 高级坐骑
- {
- _advancedMountsInfoList.Add(item);
- }
- }
- }
- private void Init()
- {
- GetAdvanceMountData();
- InitUpgradePreviewData();
- }
- private void InitUpgradePreviewData()
- {
- if (_upgradePreviewMap == null)
- {
- _upgradePreviewMap = new Dictionary<int, List<UpgradePreviewParam>>();
- }
- var cfgDataList = zuoqiStarTableRepo.GetAll();
- UpgradePreviewParam upgradePreviewData;
- foreach (var item in cfgDataList)
- {
- if (item.Preview > 0)
- {
- upgradePreviewData = new UpgradePreviewParam()
- {
- mountId = item.Zqid,
- level = item.Level,
- skillId = item.StarSkill
- };
- if (_upgradePreviewMap.ContainsKey(item.Zqid))
- {
- _upgradePreviewMap[item.Zqid].Add(upgradePreviewData);
- }
- else
- {
- _upgradePreviewMap.Add(item.Zqid, new List<UpgradePreviewParam>()
- {
- upgradePreviewData
- });
- }
- }
- }
- }
- private void ShowAdvancedNestedUI(bool bShow, bool bHideList = true)
- {
- if (!bShow)
- {
- bHideList = !bHideList;
- }
- VM.AdvancedMountList.visible = bHideList;
- if (bShow)
- {
- VM.UnlockMountItem.Enable(null);
- }
- else
- {
- VM.UnlockMountItem.Disable();
- }
- }
- /// <summary>
- /// 显示高级坐骑界面UI
- /// </summary>
- public void ShowAdvancedMountUI(bool bSelectAdvancedIndex)
- {
- if (_bInitData)
- {
- Init();
- _bInitData = false;
- }
- _advancedMountsInfoList.Sort((a, b) =>
- {
- int aUnlcok = MountData.Instance.IsUnLock(a.Id) ? 1 : 0;
- int bUnlcok = MountData.Instance.IsUnLock(b.Id) ? 1 : 0;
- if (aUnlcok == bUnlcok)
- {
- int aLevel = MountData.Instance.GetAdvancedMountLv(a.Id);
- int bLevel = MountData.Instance.GetAdvancedMountLv(b.Id);
- if (aLevel == bLevel)
- {
- return a.Id - b.Id;
- }
- return bLevel - aLevel;
- }
- return bUnlcok - aUnlcok;
- });
- if (bSelectAdvancedIndex)
- {
- int index = _advancedMountsInfoList.FindIndex(item => item.Id == MountData.Instance.MountModelId);
- if (index != -1) _curAdvancedIndex = index;
- else _curAdvancedIndex = 0;
- }
- ShowMountsListUI();
- }
- private void ShowMountsListUI()
- {
- VM.AdvancedMountList.BindDatas(_advancedMountsInfoList);
- ClickAdvancedMountItem(_curAdvancedIndex);
- }
- /// <summary>
- /// 高级坐骑的升级预览和启用技能按钮状态
- /// </summary>
- /// <param name="bSHow"></param>
- private void ShowAdvancedMountBtn(bool bShow)
- {
- VM.UpgradePreviewBtn.visible = bShow;
- VM.EnableSkillBtn.visible = bShow;
- }
- /// <summary>
- /// 选择的高级坐骑
- /// </summary>
- /// <param name="selectIndex"></param>
- private void ShowSelectAdvancedMount(int selectIndex)
- {
- _curAdvancedIndex = selectIndex;
- var advancedMountInfo = _advancedMountsInfoList[selectIndex];
- if (advancedMountInfo != null)
- {
- VM.MountNameLabel.text = advancedMountInfo.Name;
- bool bUnlock = MountData.Instance.IsUnLock(advancedMountInfo.Id);
- int lv = MountData.Instance.GetAdvancedMountLv(advancedMountInfo.Id);
- ShowMountSpine(advancedMountInfo.Spine);
- ShowAttrUI(lv, advancedMountInfo.Id, bUnlock);
- ShowRideUI(bUnlock, advancedMountInfo.Id == MountData.Instance.MountModelId);
- ShowEnableSkillBtn(bUnlock, advancedMountInfo.Id == MountData.Instance.UseSkillMountId);
- VM.MountStar.visible = lv > 0;
- ShowAdvanceMountStarUI(lv);
- }
- }
- /// <summary>
- /// 坐骑的立绘
- /// </summary>
- /// <param name="mountPicture"></param>
- private void ShowMountSpine(string spineName)
- {
- VM.MountSpine.LoadSpine(spineName, "stand", true);
- }
- /// <summary>
- /// 高级坐骑的技能id
- /// </summary>
- /// <param name="skillId"></param>
- private void ShowMountSkillUI(int skillId)
- {
- var skillInfo = SkillTableRepo.Get(skillId);
- if (skillInfo != null)
- {
- VM.SkillIcon.icon = skillInfo.Icon;
- VM.SkillNameLabel.text = skillInfo.Name;
- VM.SkillDescLabel.text = skillInfo.Desc;
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="bShow"></param>
- private void ShowEnableSkillBtn(bool bShow, bool bEnable = false)
- {
- VM.EnableSkillBtn.visible = bShow;
- if (bShow)
- {
- VM.SkillCtrl.selectedIndex = bEnable ? 1 : 0;
- }
- }
- /// <summary>
- /// 是否显示高级坐骑升级预览
- /// </summary>
- /// <param name="bShow"></param>
- private void ShowUpgradePreviewBtn(bool bShow)
- {
- VM.UpgradePreviewBtn.visible = bShow;
- }
- /// <summary>
- /// 高级坐骑拥有的效果
- /// </summary>
- /// <param name="curLv"></param>
- /// <param name="mountId"></param>
- private void ShowAttrUI(int curLv, int mountId, bool bUnlock)
- {
- if (curLv == 0)
- {
- var mountBaseInfo = zuoqiBaseTableRepo.Get(mountId);
- XGame.Framework.Assert.IsNotNull(mountBaseInfo, $"坐骑表zuoqiBase中不存在id:{mountId}");
- ShowCostUI(mountBaseInfo.Unlock);
- }
- //10000*坐骑id+等级
- var mountStarInfo = zuoqiStarTableRepo.Get(mountId * 10000 + curLv);
- if (mountStarInfo == null)
- {
- XGame.Log.Error($"坐骑表zuoqiStar中不存在id:{mountId * 10000 + curLv}");
- return;
- }
- if (bUnlock)
- ShowCostUI(mountStarInfo.StarUpCost);
- ShowMountSkillUI(mountStarInfo.StarSkill);
- int attrType = mountStarInfo.LevelOwnAttr[0];
- int attrVal = mountStarInfo.LevelOwnAttr.Length > 1 ? mountStarInfo.LevelOwnAttr[1] : 0;
- ShowCurAtrrDesc(attrType, attrVal);
- var nextMountStarInfo = zuoqiStarTableRepo.Get(mountId * 10000 + curLv + 1);
- if (nextMountStarInfo != null)
- {
- if (nextMountStarInfo?.LevelOwnAttr?.Length > 1)
- {
- VM.NextMountAttrDescLabel.text = nextMountStarInfo.LevelOwnAttr[1].ToRealFloatPercentage();
- }
- if (curLv == 0)
- {
- ShowMountSkillUI(nextMountStarInfo.StarSkill);
- }
- ShowAdvancedNestedUI(true);
- }
- else
- ShowAdvancedNestedUI(false, false);
- VM.AdvanceMountStateCtrl.selectedIndex = bUnlock ? (nextMountStarInfo == null ? 2 : 1) : 0;
- if (bUnlock) ShowUpgradePreviewBtn(nextMountStarInfo != null);
- }
- private void ShowCurAtrrDesc(int attrType, int attrValue)
- {
- var attributeInfo = AttrDescTableRepo.Get(attrType);
- if (attributeInfo != null)
- {
- VM.MountAttrDescLabel.text = attributeInfo.ShowName + attrValue.ToRealFloatPercentage();
- }
- }
- /// <summary>
- /// 高级坐骑解锁|升级消耗UI
- /// </summary>
- /// <param name="cost"></param>
- private void ShowCostUI(int[] costData)
- {
- _costData = costData;
- long num = ItemData.Instance.GetItemNum(costData[0]);
- var item = ItemService.Instance.GetItemBase(costData[0], num, 0);
- VM.UnlockMountItem.Ctrl.ShowUI(item);
- VM.UnlockMountItem.VM.CountLabel.visible = true;
- VM.UnlockMountItem.VM.CountLabel.text = $"{num.FormatNumber()}/{((long)costData[1]).FormatNumber()}";
- }
- /// <summary>
- /// 显示高级坐骑的星级
- /// </summary>
- /// <param name="starLevel"></param>
- private void ShowAdvanceMountStarUI(int starLevel)
- {
- int starNum = starLevel == 0 ? 0 : starLevel % MountData.MaxStarNum;
- if (starLevel > 0 && starNum == 0)
- starNum = MountData.MaxStarNum;
- // 获取星星的色阶
- int starStep = Mathf.FloorToInt((starLevel - 1) / MountData.MaxStarNum) + 1;
- int[] array = Enumerable.Repeat(starStep, starNum).ToArray();
- VM.MountStar.BindDatas(array);
- }
- /// <summary>
- /// 选择某个高级坐骑
- /// </summary>
- /// <param name="index"></param>
- private void ClickAdvancedMountItem(int index)
- {
- ShowSelectAdvancedMount(index);
- var mountItemList = VM.AdvancedMountList.GetChildren();
- for (int i = 0; i < mountItemList.Length; i++)
- {
- if (mountItemList[i] != null)
- {
- (mountItemList[i].asCom).GetController("SelectCtrl").selectedIndex = i == index ? 1 : 0;
- }
- }
- }
- /// <summary>
- /// 解锁某个高级坐骑成功
- /// </summary>
- /// <param name="eventId"></param>
- /// <param name="args"></param>
- private void UnlockAdvancedMountSucessful(int eventId, object args)
- {
- ShowAdvancedMountUI(false);
- }
- /// <summary>
- /// 成功启用某个高级坐骑技能
- /// </summary>
- /// <param name="eventId"></param>
- /// <param name="args"></param>
- private void UseMountSkillSucessful(int eventId, object args)
- {
- ShowEnableSkillBtn(true, _advancedMountsInfoList[_curAdvancedIndex].Id == MountData.Instance.UseSkillMountId);
- }
- /// <summary>
- /// 高级坐骑升级成功
- /// </summary>
- /// <param name="eventId"></param>
- /// <param name="args"></param>
- private void UpgradeAdvancedMountSucessful(int eventId, object args)
- {
- ShowSelectAdvancedMount(_curAdvancedIndex);
- Context.UI.OpenAsync(UIKeys.MountUpgradeSuccessfulPanel);
- }
- /// <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)
- {
- int mountId = _advancedMountsInfoList[_curAdvancedIndex].Id;
- ShowRideUI(MountData.Instance.IsUnLock(mountId), mountId == MountData.Instance.MountModelId);
- ShowMountsListUI();
- }
- /// <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 == _costData[0])
- {
- ShowCostUI(_costData);
- }
- }
- }
- }
- }
- }
|