/// #pkgName FGUI包名
/// #panelName UIPanel名字
/// #UIName = $"{#pkgName}{#panelName}" UIKey名字
/// 该脚本由模板创建
/// created by cb 2024
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 MountDevelopPanelCtrl : UIController
{
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; // 坐骑星阶数据
#region 普通坐骑(坐骑升级UI)
///
/// 通用坐骑数据
///
private void GetMouuntModelData()
{
_universalId = MountData.Instance.universalId;
_curMountInfo = zuoqiInfoTableRepo.Get(MountData.Instance.universalId);
XGame.Framework.Assert.IsNotNull(_curMountInfo, $"坐骑表zuoqiInfo信息不存在,id:{MountData.Instance.universalId}");
var mountBaseInfo = zuoqiBaseTableRepo.Get(_curMountInfo.Zqid);
if (mountBaseInfo != null)
{
ShowMountName(mountBaseInfo.Name);
}
_feedCostItemId = _curMountInfo.StarNeed[0];
ShowFeedCostUI();
_mountModelList.Clear();
int starLv = _curMountInfo.Star;
var cfgInfoList = zuoqiInfoTableRepo.GetAll();
string lastModelName = string.Empty;
foreach (var cfgInfo in cfgInfoList)
{
if (cfgInfo.Icon != lastModelName)
{
lastModelName = cfgInfo.Icon;
_mountModelList.Add(new MountModelParam()
{
tableId = cfgInfo.Id,
unlockStep = cfgInfo.Step,
bLock = _curMountInfo.Step < cfgInfo.Step || starLv < cfgInfo.Star,
spineName = cfgInfo.Picture
});
}
if (cfgInfo.Star == 0 && !_mountStepMap.ContainsKey(cfgInfo.Step))
{
_mountStepMap.Add(cfgInfo.Step, cfgInfo);
}
}
}
///
/// 坐骑升级UI(普通坐骑)
///
private void ShowUniversalMountsUI()
{
ShowSelectMount(_mountIndex);
ShowMountBaseAttr(_curMountInfo.Star);
ShowMountSpecialAttr(_curMountInfo.Star);
VM.ExpBar.max = _curMountInfo.StarNeed[1];
ShowExp();
ShowStar();
}
///
/// 通用坐骑升星经验进度
///
private void ShowExp()
{
VM.ExpBar.value = MountData.Instance.exp;
}
///
/// 通用坐骑的星级
///
private void ShowStar()
{
VM.StarBar.GetController("StarLvCtrl").selectedIndex = _curMountInfo.Star;
}
///
/// 升星消耗
///
private void ShowFeedCostUI()
{
VM.FeedCostItem.Ctrl.ShowCostUI(_feedCostItemId, 1);
}
///
/// (通用坐骑)特殊属性加成
///
///
private void ShowMountSpecialAttr(int starLv)
{
VM.SpecialStarLvLabel.text = starLv.ToString();
var nextInfo = _mountStepMap.ContainsKey(_curMountInfo.Step + 1) ? _mountStepMap[_curMountInfo.Step +1] : null;
bool bMaxStep = nextInfo == null;
VM.SpecialAttrItem.Ctrl.OnRefresh(0, new MountAttrParam()
{
attrType = (EAttributeType)_curMountInfo.StarSkill[0],
curVal = _curMountInfo.StarSkill[1],
nextVal = bMaxStep ? 0 : nextInfo.StarSkill[0]
});
}
///
/// (通用坐骑)基础属性加成UI
///
///
private void ShowMountBaseAttr(int starLv)
{
VM.BaseStarLvLabel.text = starLv.ToString();
_mountBaseAttrList.Clear();
var nextInfo = zuoqiInfoTableRepo.Get(_curMountInfo.Id + 1);
bool bMax = nextInfo == null;
int count = _curMountInfo.StepOwnAttr.Length;
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)
{
ShowMountPicture(param.spineName);
ShowRideUI(!param.bLock);
if (param.bLock)
{
ShowUnlockLv(true);
VM.UnLockModelLabel.text = string.Format(StringDefine.UnlockMountStep, param.unlockStep);
}
else
ShowRideUI(true);
}
ShowSwitchMountBtnState();
}
///
/// 是否显示解锁条件
///
///
private void ShowUnlockLv(bool bShow)
{
VM.UnLockModelLabel.visible = bShow;
}
///
/// 坐骑的立绘
///
///
private void ShowMountPicture(string mountPicture, bool bAdvance = false)
{
VM.MountPicture.icon = mountPicture;
if (!bAdvance)
{
VM.TrainMountPicture.icon = mountPicture;
}
}
///
/// 普通坐骑上一个/下一个切换按钮的状态
///
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) return;
GetMouuntModelData();
ShowUniversalMountsUI();
}
#endregion
}
}