123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- /// #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
- {
- /// <summary>
- /// UI逻辑处理类
- /// </summary>
- /// <typeparam name=""></typeparam>
- public partial class PlayerTransferPanelCtrl : UIController<PlayerTransferPanelVM>
- {
- private int _selectJobId; // 当前选择的职业id
- private bool _bNovice; // 是否新手(还未转过职)
- private bool _bResetJob; // 是否职业重置
- private careerTable _jobInfo;
- private Dictionary<int, List<int> > _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;
- }
- /// <summary>
- /// 转职按钮事件
- /// </summary>
- /// <param name="context"></param>
- 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();
- }
- /// <summary>
- /// 是否觉醒符文后才能转职
- /// </summary>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 武师分支选择
- /// </summary>
- /// <param name="context"></param>
- private void OnClickSoldierBtn(EventContext context)
- {
- ShowChoices(1);
- }
- /// <summary>
- /// 斥候分支选择
- /// </summary>
- /// <param name="context"></param>
- private void OnClickScoutsBtn(EventContext context)
- {
- ShowChoices(2);
- }
- /// <summary>
- /// 卜师分支选择
- /// </summary>
- /// <param name="context"></param>
- 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();
- }
- /// <summary>
- /// 是否显示转职按钮
- /// </summary>
- private void ShowTransferBtn()
- {
- bool bShow = true;
- if (_selectJobId == 0 && (_bNovice || _bResetJob))
- {
- bShow = false;
- }
- VM.TransferBtn.visible = bShow;
- VM.TipLabel.visible = _bNovice &&!bShow;
- }
- /// <summary>
- /// 转职按钮名称
- /// </summary>
- /// <param name="unlockLv"></param>
- 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;
- }
- /// <summary>
- /// 转职|觉醒
- /// </summary>
- /// <returns></returns>
- 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<int, List<int>>();
- 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<int>() { item.Id});
- }
- }
- }
- ShowChoices(1);
- }
- /// <summary>
- /// 职业分支选择
- /// </summary>
- 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();
- }
- }
- }
|