/// #pkgName FGUI包名 /// #panelName UIPanel名字 /// #UIName = $"{#pkgName}{#panelName}" UIKey名字 /// 该脚本由模板创建 /// created by cb 2024 using FairyGUI; using FL.Data; using System.Collections.Generic; using XGame.Database; using XGame.Framework.UI; namespace FL.FGUI { /// /// UI逻辑处理类 /// /// public partial class PlayerTransferPanelCtrl : UIController { private int _selectJobId; // 当前选择的职业id private bool _bNovice; // 是否新手(还未转过职) private bool _bResetJob; // 是否职业重置 private careerTable _jobInfo; private Dictionary > _jobTypeMap;//重置后可选择的职业分支选择 protected override void OnEnable(object intent) { AddUIListenres(); _bResetJob = intent == null ? false : (bool)intent; ShowUI(); } protected override void OnDisable() { RemoveUIListenres(); if (_jobTypeMap != null ) _jobTypeMap.Clear(); } #region UI事件 private void AddUIListenres() { VM.TransferBtn.onClick.Add(OnClickTransferBtn); VM.SoldierBtn.onClick.Add(OnClickSoldierBtn); VM.ScoutsBtn.onClick.Add(OnClickScoutsBtn); VM.MagicBtn.onClick.Add(OnClickMagicBtn); VM.BackBtn.onClick.Add(OnClickBackBtn); VM.JobList.ItemClickEvent += onClickJobItem; } private void RemoveUIListenres() { VM.TransferBtn.onClick.Remove(OnClickTransferBtn); VM.SoldierBtn.onClick.Remove(OnClickSoldierBtn); VM.ScoutsBtn.onClick.Remove(OnClickScoutsBtn); VM.MagicBtn.onClick.Remove(OnClickMagicBtn); VM.BackBtn.onClick.Remove(OnClickBackBtn); VM.JobList.ItemClickEvent -= onClickJobItem; } /// /// 转职按钮事件 /// /// private void OnClickTransferBtn(EventContext context) { if (IsNeedAwakeRune()) { Context.UI.OpenAsync(UIKeys.PlayerAwakePanel); Context.ClosePanel(); return; } else if (_selectJobId == 0) { Context.ShowTips(StringDefine.TransferNoSelect); return; } PlayerService.Instance.SendToTransfer(_selectJobId); Context.ClosePanel(); } /// /// 是否觉醒符文后才能转职 /// /// private bool IsNeedAwakeRune() { var jobIofo = careerTableRepo.Get(PlayerData.Instance.JobId); if (jobIofo?.Passive_imprint?.Length > 0 ) { var runePlanData = PlayerData.Instance.RunePlanMap[PlayerData.Instance.CurPlanIndex]; if (runePlanData.slot == null || runePlanData.slot.Count == 0) return true; int num = jobIofo.Passive_imprint.Length / 2; for ( int i = 0;i < num; i++) { if (runePlanData.slot[i] == null) { return true; } else if (runePlanData.slot[i].runeId == 0) { return true; } } } return false; } /// /// 武师分支选择 /// /// private void OnClickSoldierBtn(EventContext context) { ShowChoices(1); } /// /// 斥候分支选择 /// /// private void OnClickScoutsBtn(EventContext context) { ShowChoices(2); } /// /// 卜师分支选择 /// /// private void OnClickMagicBtn(EventContext context) { ShowChoices(3); } private void OnClickBackBtn(EventContext context) { Context.ClosePanel(); } private void onClickJobItem(int index) { var jobItemList = VM.JobList.GetChildren(); for (int i = 0; i < jobItemList.Length; i++) { if (i == index) { jobItemList[i].SetScale(1.08f, 1.08f); _selectJobId = _jobInfo.Job_change[i]; } else { jobItemList[i].SetScale(1f, 1f); } } ShowTransferBtn(); } #endregion private void ShowUI() { _selectJobId = 0; _jobInfo = careerTableRepo.Get(PlayerData.Instance.JobId); _bNovice = !_bResetJob && _jobInfo.Front_job == 0; VM.JobCtrl.selectedIndex = _bResetJob ? 2 : (_bNovice ? 0 : 1); // 0_新手 1_职业提升 2_职业重置 if (!_bNovice && !_bResetJob) _selectJobId = _jobInfo.Job_change[0]; // 进阶职业id VM.JobList.BindDatas(_jobInfo.Job_change); ShowTransferBtn(); var advanceJobInfo = careerTableRepo.Get(_jobInfo.Job_change[0]); int unlockLv = advanceJobInfo == null ? _jobInfo.Unlock : advanceJobInfo.Unlock; ShowTransferBtnName(unlockLv); if (_bResetJob) { ShowResetUI(); } else ResetSelectJobItemUI(); } /// /// 是否显示转职按钮 /// private void ShowTransferBtn() { bool bShow = true; if (_selectJobId == 0 && (_bNovice || _bResetJob)) { bShow = false; } VM.TransferBtn.visible = bShow; VM.TipLabel.visible = _bNovice &&!bShow; } /// /// 转职按钮名称 /// /// private void ShowTransferBtnName(int unlockLv) { bool bShowAwakeLabel = false; bool bLock = unlockLv > PlayerData.Instance.Level; VM.TransferBtn.enabled = !bLock; VM.TransferBtn.title = bLock ? string.Format(StringDefine.TransferUnlockLv, unlockLv) : GetTransferBtnName(ref bShowAwakeLabel); VM.AwakeTipsLabel.visible = bShowAwakeLabel; } /// /// 转职|觉醒 /// /// private string GetTransferBtnName(ref bool bShowAwakeLabel) { var jobInfo = careerTableRepo.Get(PlayerData.Instance.JobId); bool bNeedAwake = jobInfo?.Passive_imprint?.Length > 0; string btnName = bNeedAwake ? StringDefine.AwakeBtnName : StringDefine.TransferBtnName; if (bNeedAwake) { if (IsNeedAwakeRune()) { bShowAwakeLabel = true; btnName = StringDefine.GoToAwake; } } return btnName; } private void ShowResetUI() { // 重置会在最接近阶的分支线 var resetJobInfo = careerTableRepo.Get(PlayerData.Instance.ResetJobId); if (resetJobInfo == null) return; if (_jobTypeMap == null) _jobTypeMap = new Dictionary>(); else _jobTypeMap.Clear(); var dataList = careerTableRepo.GetAll(); foreach (var item in dataList) { if (item.Change_times == resetJobInfo.Change_times) { if (_jobTypeMap.ContainsKey(item.Careertype)) { _jobTypeMap[item.Careertype].Add(item.Id); } else { _jobTypeMap.Add(item.Careertype, new List() { item.Id}); } } } ShowChoices(1); } /// /// 职业分支选择 /// private void ShowChoices(int index) { VM.JobList.BindDatas(_jobTypeMap[index]); ResetSelectJobItemUI(); } private void ResetSelectJobItemUI() { if (_selectJobId != 0)_selectJobId = 0; var jobItemList = VM.JobList.GetChildren(); for (int i = 0; i < jobItemList.Length; i++) { jobItemList[i].SetScale(1f, 1f); } ShowTransferBtn(); } } }