123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328 |
- /// #pkgName FGUI包名
- /// #panelName UIPanel名字
- /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
- /// 该脚本由模板创建
- /// created by cb 2024
- using FairyGUI;
- using FL.Data;
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- using XGame;
- using XGame.Database;
- using XGame.Framework.UI;
- namespace FL.FGUI
- {
- /// <summary>
- /// 职业(主|被)技能
- /// </summary>
- public struct JobSkillParam
- {
- public int unlockLv;
- public int skillId;
- public Action<int, int> onclickSkillIcon;
- }
- /// <summary>
- /// UI逻辑处理类
- /// </summary>
- /// <typeparam name=""></typeparam>
- public partial class PlayerJokSkillNestedCtrl : UIController<PlayerJokSkillNestedVM>
- {
- private int _skillId; // 当前主动技能id
- private careerTable _jobInfo; // 当前职业信息
- private JobSkillParam[] _passiveSkillDataArray; // 被动技能数据列表
- private Dictionary<EAttributeType, string> _attributeDescMap;
- private Action<bool> _clickSkillIconCallback;
- protected override void OnEnable(object intent)
- {
- AddUIListenres();
- AddEventListener();
- }
- protected override void OnDisable()
- {
- RemoveUIListenres();
- RemoveEventListener();
- ShowSkillInfoGroup(false);
- if (_attributeDescMap != null)
- {
- _attributeDescMap.Clear();
- _attributeDescMap = null;
- }
- _jobInfo = null;
- if (_passiveSkillDataArray != null) _passiveSkillDataArray = null;
- }
- #region UI事件
- private void AddUIListenres()
- {
- VM.AttrInfoBtn.onClick.Add(OnClickAttrInfoBtn);
- VM.JobBtn.onClick.Add(OnClickJobBtn);
- VM.SkillBtn.onClick.Add(OnClickSkillBtn);
- VM.WakeUpBtn.onClick.Add(OnClickWakeUpBtn);
- VM.TransferBtn.onClick.Add(OnClickTransferBtn);
- }
- private void RemoveUIListenres()
- {
- VM.AttrInfoBtn.onClick.Remove(OnClickAttrInfoBtn);
- VM.JobBtn.onClick.Remove(OnClickJobBtn);
- VM.SkillBtn.onClick.Remove(OnClickSkillBtn);
- VM.WakeUpBtn.onClick.Remove(OnClickWakeUpBtn);
- VM.TransferBtn.onClick.Remove(OnClickTransferBtn);
- }
- private void OnClickAttrInfoBtn(EventContext context)
- {
- Context.UI.OpenAsync(UIKeys.PlayerDetailsAttribute);
- }
- /// <summary>
- /// 职业(整个线路图)预览
- /// </summary>
- /// <param name="context"></param>
- private void OnClickJobBtn(EventContext context)
- {
- Context.ShowTips("职业(整个线路图)预览");
- Context.UI.OpenAsync(UIKeys.PlayerJobCareerPreviewPanel);
- }
- private void OnClickSkillBtn(EventContext context)
- {
- if (_skillId > 0)
- {
- OnClickSkillIcon(_skillId, -1);
- }
- }
- /// <summary>
- /// 觉醒按钮
- /// </summary>
- /// <param name="context"></param>
- private void OnClickWakeUpBtn(EventContext context)
- {
- Context.UI.OpenAsync(UIKeys.PlayerAwakePanel);
- }
- /// <summary>
- /// 转职按钮
- /// </summary>
- /// <param name="context"></param>
- private void OnClickTransferBtn(EventContext context)
- {
- // 分条件满足和不满足的(相当于展示下阶职业的预览ui)显示
- // 当前是否最高级职业
- if (_jobInfo.Job_change?.Length > 0)
- {
- Context.UI.OpenAsync(UIKeys.PlayerTransferPanel, false);
- }
- else
- {
- OnClickJobBtn(null);
- }
- }
- #endregion
- private void AddEventListener()
- {
- Context.AddListener(EventDefine.AttributeChange, OnChangeAttribute); // 角色属性变化
- }
- private void RemoveEventListener()
- {
- Context.RemoveListener(EventDefine.AttributeChange, OnChangeAttribute); // 角色属性变化
- }
- public void Init(Action<bool> clickSkillIcon)
- {
- _clickSkillIconCallback = clickSkillIcon;
- if (_attributeDescMap == null)
- {
- _attributeDescMap = new Dictionary<EAttributeType, string>()
- {
- {EAttributeType.AtkTotal, GetAttributeDesc(EAttributeType.AtkTotal)},
- {EAttributeType.HpTotal, GetAttributeDesc(EAttributeType.HpTotal)},
- {EAttributeType.DefTotal, GetAttributeDesc(EAttributeType.DefTotal)},
- { EAttributeType.AtkSpeedTotal, GetAttributeDesc(EAttributeType.AtkSpeedTotal)}
- };
- }
- InitPassiveSkillDataList();
- ShowSkillInfoGroup(false);
- }
- public void ShowAttributeUI()
- {
- ShowAtrributeVal(VM.AtkLabel, EAttributeType.AtkTotal);
- ShowAtrributeVal(VM.HpLabel, EAttributeType.HpTotal);
- ShowAtrributeVal(VM.DefLabel, EAttributeType.DefTotal);
- ShowAtrributeVal(VM.AtkSpeedLabel, EAttributeType.AtkSpeedTotal, true);
- }
- private string GetAttributeDesc(EAttributeType attrType)
- {
- var attrInfo = AttrDescTableRepo.Get((int)attrType);
- return attrInfo?.ShowName ?? string.Empty;
- }
- /// <summary>
- /// 角色属性变化
- /// </summary>
- /// <param name="eventId"></param>
- /// <param name="args"></param>
- private void OnChangeAttribute(int eventId, object args)
- {
- //EAttributeType attrType = (EAttributeType)args;
- //if (attrType == EAttributeType.AtkTotal)
- //{
- // ShowAtrributeVal(VM.AtkLabel, EAttributeType.AtkTotal);
- //}
- //else if (attrType == EAttributeType.HpTotal)
- //{
- // ShowAtrributeVal(VM.HpLabel, EAttributeType.HpTotal);
- //}
- //else if (attrType == EAttributeType.DefTotal)
- //{
- // ShowAtrributeVal(VM.DefLabel, EAttributeType.DefTotal);
- //}
- //else if (attrType == EAttributeType.AtkSpeedTotal)
- //{
- // ShowAtrributeVal(VM.AtkSpeedLabel, EAttributeType.AtkSpeedTotal, true);
- //}
- ShowAttributeUI();
- }
-
- private void ShowAtrributeVal(GTextField attrLabel, EAttributeType attrType, bool bAtkSpeed = false)
- {
- var attrVal = PlayerData.Instance.Attr.GetValue(attrType);
- attrLabel.text = $"{_attributeDescMap[attrType]}:{(bAtkSpeed ? attrVal.ToRealDoublePercentage() : attrVal.ToString())}";
- }
- public void ShowJobUI()
- {
- _jobInfo = careerTableRepo.Get(PlayerData.Instance.JobId);
- if (_jobInfo == null) return;
- int playerLv = PlayerData.Instance.Level;
- VM.JobNameLabel.text = _jobInfo.Name;
- VM.TransfersCountLabel.text = _jobInfo.Change_times.ToString(); // 转职次数
- // 当前是否最高级职业
- bool bSuperlative = _jobInfo.Job_change.Length == 0;
- if (!bSuperlative)
- {
- var advanceInfo = careerTableRepo.Get(_jobInfo.Job_change[0]);
- if (advanceInfo == null)
- {
- bSuperlative = true;
- }
- else
- {
- VM.UnlockLabel.text = string.Format(StringDefine.UnlockAdvanceJob, playerLv, advanceInfo.Unlock);
- }
- }
- VM.SuperlativeCtrl.selectedIndex = bSuperlative ? 1 : 0;
- ShowJobSkillUI(_jobInfo.Skill);
- ShowJobPassiveSkillUI(_jobInfo.Passive_skill);
- ShowWakeUpBtn(_jobInfo?.Passive_imprint.Length > 4); // (转职需要觉醒印记)显示|隐藏觉醒按钮
- }
- /// <summary>
- /// 是否显示觉醒按钮
- /// </summary>
- /// <param name="bShow"></param>
- private void ShowWakeUpBtn(bool bShow)
- {
- VM.WakeUpBtn.visible = bShow;
- }
- /// <summary>
- /// 点击技能图标
- /// </summary>
- /// <param name="skillId"></param>
- private void OnClickSkillIcon(int skillId, int index)
- {
- var skillInfo = SkillTableRepo.Get(skillId);
- if (skillInfo == null) return;
- if (_clickSkillIconCallback != null) _clickSkillIconCallback(false);
- ShowSkillInfoGroup(true, index, skillInfo);
- //Log.Info($"OnClickSkillIcon.点击技能图标id:{skillId}");
- }
- /// <summary>
- /// 显示技能弹窗信息UI
- /// </summary>
- /// <param name="Show"></param>
- /// <param name="bPassive"></param>
- public void ShowSkillInfoGroup(bool bShow, int index = 0, SkillTable skillInfo = null)
- {
- Log.Debug($"ShowSkillInfoGroup bShow:{bShow} info:{skillInfo != null} Frame:{Time.frameCount}");
- if (bShow && skillInfo != null)
- {
- var skillParam = new SkillInfoParam()
- {
- bShowRightBubble = index > 1,
- skillInfo = skillInfo
- };
- if (VM.SkillInfoNested.Active)
- VM.SkillInfoNested.Ctrl.ShowSkillInfo(skillParam);
- else
- VM.SkillInfoNested.Enable(skillParam);
- VM.SkillInfoTipCtrl.selectedIndex = index == -1 ? 0 : (index + 1);
-
- }
- else if (VM.SkillInfoNested.Active)
- {
- VM.SkillInfoNested.Disable();
- }
- }
- /// <summary>
- /// 职业主动技能UI(解锁等级|技能id|技能等级)
- /// </summary>
- private void ShowJobSkillUI(int[] skillIds)
- {
- if (skillIds.Length > 1)
- {
- _skillId = skillIds[1];
- var skillInfo = SkillTableRepo.Get(skillIds[1]);
- if (skillInfo != null)
- {
- VM.JobSkillLabel.text = skillInfo.Name;
- VM.SkillBtn.icon = skillInfo.Icon;
- }
- }
- else
- {
- _skillId = 0;
- }
- }
- private void InitPassiveSkillDataList()
- {
- if (_passiveSkillDataArray == null || _passiveSkillDataArray.Length == 0)
- {
- _passiveSkillDataArray = new JobSkillParam[5];
- }
- }
- /// <summary>
- /// 职业被动技能UI
- /// </summary>
- private void ShowJobPassiveSkillUI(int[] skillIds)
- {
- int index = 0;
- for (int i = 0; i < skillIds.Length; i += 2)
- {
- _passiveSkillDataArray[index] = new JobSkillParam()
- {
- unlockLv = skillIds[i],
- skillId = skillIds[i + 1],
- onclickSkillIcon = OnClickSkillIcon
- };
- index++;
- }
- VM.PassiveSkillList.BindDatas(_passiveSkillDataArray);
- }
-
- }
- }
|