/// #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
{
///
/// 职业(主|被)技能
///
public struct JobSkillParam
{
public int unlockLv;
public int skillId;
public Action onclickSkillIcon;
}
///
/// UI逻辑处理类
///
///
public partial class PlayerJokSkillNestedCtrl : UIController
{
private int _skillId; // 当前主动技能id
private careerTable _jobInfo; // 当前职业信息
private JobSkillParam[] _passiveSkillDataArray; // 被动技能数据列表
private Dictionary _attributeDescMap;
private Action _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);
}
///
/// 职业(整个线路图)预览
///
///
private void OnClickJobBtn(EventContext context)
{
Context.ShowTips("职业(整个线路图)预览");
Context.UI.OpenAsync(UIKeys.PlayerJobCareerPreviewPanel);
}
private void OnClickSkillBtn(EventContext context)
{
if (_skillId > 0)
{
OnClickSkillIcon(_skillId, -1);
}
}
///
/// 觉醒按钮
///
///
private void OnClickWakeUpBtn(EventContext context)
{
Context.UI.OpenAsync(UIKeys.PlayerAwakePanel);
}
///
/// 转职按钮
///
///
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 clickSkillIcon)
{
_clickSkillIconCallback = clickSkillIcon;
if (_attributeDescMap == null)
{
_attributeDescMap = new Dictionary()
{
{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;
}
///
/// 角色属性变化
///
///
///
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); // (转职需要觉醒印记)显示|隐藏觉醒按钮
}
///
/// 是否显示觉醒按钮
///
///
private void ShowWakeUpBtn(bool bShow)
{
VM.WakeUpBtn.visible = bShow;
}
///
/// 点击技能图标
///
///
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}");
}
///
/// 显示技能弹窗信息UI
///
///
///
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();
}
}
///
/// 职业主动技能UI(解锁等级|技能id|技能等级)
///
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];
}
}
///
/// 职业被动技能UI
///
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);
}
}
}