/// #pkgName FGUI包名
/// #panelName UIPanel名字
/// #UIName = $"{#pkgName}{#panelName}" UIKey名字
/// 该脚本由模板创建
/// created by cb 2024
using FairyGUI;
using FL.Data;
using FL.FGUI;
using System.Collections.Generic;
using XGame.Database;
using XGame.Framework.UI;
namespace FL.FGUIP
{
///
/// UI逻辑处理类
///
///
public partial class PlayerJobCareerPreviewPanelCtrl : UIController
{
private ScrollPane _scrollPanel;
protected override void OnEnable(object intent)
{
_scrollPanel = VM.JobCareerScrollNested.VM.Scroll;
AddUIListenres();
ShowUI();
}
protected override void OnDisable()
{
RemoveUIListenres();
}
#region UI事件
private void AddUIListenres()
{
VM.BackBtn.onClick.Add(OnClickBackBtn);
VM.ResetBtn.onClick.Add(OnClickResetBtn);
_scrollPanel.onScroll.Add(OnScrollPaneScroll);
}
private void RemoveUIListenres()
{
VM.BackBtn.onClick.Remove(OnClickBackBtn);
VM.ResetBtn.onClick.Remove(OnClickResetBtn);
_scrollPanel.onScroll.Remove(OnScrollPaneScroll);
}
private void OnClickBackBtn(EventContext context)
{
Context.ClosePanel();
}
private void OnClickResetBtn(EventContext context)
{
ConfirmationBoxParam dialogParam = new ConfirmationBoxParam()
{
cnt = StringDefine.resetCareer,
onPromiseCallback = ()=>
{
PlayerService.Instance.SendToResetJob();
Context.ClosePanel();
}
};
Context.UI.OpenAsync(UIKeys.CommonConfirmationBox, dialogParam);
}
#endregion
private void ShowUI()
{
var curJobInfo = careerTableRepo.Get(PlayerData.Instance.JobId);
if (curJobInfo != null)
{
var lvList = new HashSet();
var dataList = careerTableRepo.GetAll();
var preDataList = new List(); // 前置数据(初始职业和10级转职数据)
var soldierDataMap = new Dictionary>();
var shooterDataMap = new Dictionary>();
var magicianDataMap = new Dictionary>();
foreach (var item in dataList)
{
lvList.Add(item.Unlock);
if (item.Change_times < 2)
{
preDataList.Add(item);
}
else
{
eAdvanceType advanceType = (eAdvanceType)item.Type;
if (item.Careertype == (int)eCareerType.Soldier)
{
if (soldierDataMap.ContainsKey(advanceType))
{
soldierDataMap[advanceType].Add(item);
}
else
{
soldierDataMap.Add(advanceType, new List() { item });
}
}
else if (item.Careertype == (int)eCareerType.Shooter)
{
if (shooterDataMap.ContainsKey(advanceType))
{
shooterDataMap[advanceType].Add(item);
}
else
{
shooterDataMap.Add(advanceType, new List() { item });
}
}
else if (item.Careertype == (int)eCareerType.Magician)
{
if (magicianDataMap.ContainsKey(advanceType))
{
magicianDataMap[advanceType].Add(item);
}
else
{
magicianDataMap.Add(advanceType, new List() { item });
}
}
}
}
ShowLvTitle(curJobInfo.Unlock, lvList);
VM.JobCareerScrollNested.Ctrl.ShowUI(curJobInfo, preDataList, soldierDataMap, shooterDataMap, magicianDataMap);
_scrollPanel.SetPercX(0,false);
_scrollPanel.SetPercY(0, false);
}
}
///
/// 等级阶段
///
private void ShowLvTitle(int jobLv, HashSet lvList)
{
var jobLvParamList = new List();
foreach (var item in lvList)
{
jobLvParamList.Add(new JobLvParam()
{
lv = item,
curJobLv = jobLv
});
}
VM.LvList.BindDatas(jobLvParamList);
}
///
/// 职业阶段等级UI滚动
///
private void OnScrollPaneScroll()
{
// 获取当前滚动位置
if (VM.LvList.scrollPane.percX != _scrollPanel.percX)
VM.LvList.scrollPane.percX = _scrollPanel.percX;
}
}
}