/// #pkgName FGUI包名
/// #panelName UIPanel名字
/// #UIName = $"{#pkgName}{#panelName}" UIKey名字
/// 该脚本由模板创建
/// created by cb 2024
using FairyGUI;
using FL.Data;
using FL.Data.Items;
using System.Collections.Generic;
using XGame.Database;
using XGame.Framework.UI;
namespace FL.FGUI
{
///
/// UI逻辑处理类
///
///
public partial class PlayerMainPanelCtrl : UIController
{
private bool _bHideSkillInfo; // 是否需要隐藏技能信息气泡
private List _equipItemList;
protected override void OnEnable(object intent)
{
AddUIListenres();
AddEventListener();
Init();
ShowUI();
}
protected override void OnDisable()
{
RemoveUIListenres();
RemoveEventListener();
if (_equipItemList != null)
{
_equipItemList.Clear();
_equipItemList = null;
}
VM.PlayerSpine.url = string.Empty;
}
#region UI事件
private void AddUIListenres()
{
VM.MountBtn.onClick.Add(OnClickMountBtn);
VM.ArtifactBtn.onClick.Add(OnClickArtifactBtn);
VM.ContractBtn.onClick.Add(OnClickContractBtn);
VM.JewelryBtn.onClick.Add(OnClickJewelryBtn);
VM.NotOpenBtn1.onClick.Add(OnClickNotOpenBtn1);
VM.NotOpenBtn2.onClick.Add(OnClickNotOpenBtn2);
VM.UpgradeLvBtn.onClick.Add(OnClickUpgradeLvBtn);
VM.PanelEvent.Add(OnCllickPanel);
}
private void RemoveUIListenres()
{
VM.MountBtn.onClick.Remove(OnClickMountBtn);
VM.ArtifactBtn.onClick.Remove(OnClickArtifactBtn);
VM.ContractBtn.onClick.Remove(OnClickContractBtn);
VM.JewelryBtn.onClick.Remove(OnClickJewelryBtn);
VM.NotOpenBtn1.onClick.Remove(OnClickNotOpenBtn1);
VM.NotOpenBtn2.onClick.Remove(OnClickNotOpenBtn2);
VM.UpgradeLvBtn.onClick.Remove(OnClickUpgradeLvBtn);
VM.PanelEvent.Remove(OnCllickPanel);
}
///
/// 隐藏技能信息气泡弹窗
///
///
private void OnCllickPanel(EventContext context)
{
if (_bHideSkillInfo)
{
VM.JokSkillNested.Ctrl.ShowSkillInfoGroup(false);
}
_bHideSkillInfo = true;
}
private void OnClickUpgradeLvBtn(EventContext context)
{
Context.ShowTips("一键使用经验道具进行升级事件");
}
private void OnClickChangeBtn(EventContext context)
{
Context.ShowTips("更换契约技能");
}
private void OnClickMountBtn(EventContext context)
{
Context.ShowTips("打开坐骑界面");
}
private void OnClickArtifactBtn(EventContext context)
{
Context.ShowTips("打开神器界面");
}
private void OnClickContractBtn(EventContext context)
{
Context.ShowTips("打开锲约界面");
}
private void OnClickJewelryBtn(EventContext context)
{
Context.ShowTips("打开饰品装扮界面");
}
private void OnClickNotOpenBtn1(EventContext context)
{
Context.ShowTips(StringDefine.notOpen);
}
private void OnClickNotOpenBtn2(EventContext context)
{
Context.ShowTips(StringDefine.notOpen);
}
#endregion
private void AddEventListener()
{
EventSingle.Instance.AddListener(EventDefine.OnChangeEquip, OnChangeEquip);
EventSingle.Instance.AddListener(EventDefine.PlayerExpAdd, AddPlayerExp);
EventSingle.Instance.AddListener(EventDefine.RefreshWearEquipUI, RefreshWearEquipUI);
EventSingle.Instance.AddListener(EventDefine.TransferSucess, TransferSucess);
EventSingle.Instance.AddListener(EventDefine.ResetJobSucess, ResetJobSucess);
}
private void RemoveEventListener()
{
EventSingle.Instance.RemoveListener(EventDefine.OnChangeEquip, OnChangeEquip);
EventSingle.Instance.RemoveListener(EventDefine.PlayerExpAdd, AddPlayerExp);
EventSingle.Instance.RemoveListener(EventDefine.RefreshWearEquipUI, RefreshWearEquipUI);
EventSingle.Instance.RemoveListener(EventDefine.TransferSucess, TransferSucess);
EventSingle.Instance.RemoveListener(EventDefine.ResetJobSucess, ResetJobSucess);
}
private void Init()
{
if (_equipItemList == null)
{
_equipItemList = new List()
{
VM.Weapon,VM.Helmet,VM.Clothes,VM.Hand,VM.Pants,VM.Boots
};
}
_bHideSkillInfo = true;
VM.JokSkillNested.Ctrl.Init((bool bHideSkillInfo) =>
{
_bHideSkillInfo = bHideSkillInfo;
});
PlayerService.Instance.SendToEquipInto();
}
private void ShowUI()
{
ShowEquipUI();
ShowTitleIcon(PlayerData.Instance.Title);
ShowAttributeUI();
//ShowContractSkills(201711);
LoadPlayerSpine("info_job_1001_1_SkeletonData");
VM.JokSkillNested.Ctrl.ShowJobUI();
}
///
/// 加载主角的spine
///
///
private void LoadPlayerSpine(string spineName)
{
VM.PlayerSpine.LoadSpine(spineName, "stand", true);
}
///
/// 角色称号
///
///
private void ShowTitleIcon(string title)
{
VM.TitleIcon.url = title;
}
#region 装备UI
///
/// 显示装备UI
///
private void ShowEquipUI()
{
UiParam _uiParam = new UiParam();
_uiParam.bShowBtn = true;
_uiParam.bShowLevel = true;
int index = 1;
_equipItemList.ForEach((item) =>
{
EquipItem equipData = EquipData.Instance.GetWearEquipData((EEquipType)index);
if (equipData != null)
{
item.Ctrl.ShowUI(equipData, _uiParam);
}
else
{
item.Ctrl.ShowEmptyUI();
}
index++;
});
}
///
/// 更换装备
///
///
///
private void OnChangeEquip(int eventId, object args)
{
if (args == null)
{
return;
}
var changeEquipPartList = args as List;
if (changeEquipPartList?.Count > 0)
{
foreach (var equipPart in changeEquipPartList)
{
CommonItemBaseView equipItem = _equipItemList[(int)equipPart - 1];
if (equipItem != null)
{
UiParam _uiParam = new UiParam();
_uiParam.bShowBtn = true;
_uiParam.bShowLevel = true;
equipItem.Ctrl.ShowUI(EquipData.Instance.GetWearEquipData(equipPart), _uiParam);
}
}
}
}
///
/// 刷新身上穿戴的装备信息
///
///
///
private void RefreshWearEquipUI(int eventId, object args)
{
XGame.Log.Info("刷新身上穿戴的装备信息");
ShowEquipUI();
}
#endregion
#region 角色属性信息
private void ShowAttributeUI()
{
VM.NameLabel.text = PlayerData.Instance.Name;
ShowPlayerLevel();
ShowExp(false);
VM.JokSkillNested.Ctrl.ShowAttributeUI();
}
private void ShowPlayerLevel()
{
VM.LvLabl.text = $"LV.{PlayerData.Instance.Level}";
}
private void ShowExp(bool bShowAni = true)
{
var expInfo = LevelTableRepo.Get(PlayerData.Instance.Level + 1);
if (expInfo == null)
{
// 等级上限
expInfo = LevelTableRepo.Get(PlayerData.Instance.Level);
}
VM.ExpBar.max = expInfo.Exp;
if (bShowAni)
VM.ExpBar.TweenValue(PlayerData.Instance.Exp, 0.5f);
else
VM.ExpBar.value = PlayerData.Instance.Exp;
}
///
/// 角色经验值增加
///
///
///
private void AddPlayerExp(int eventId, object args)
{
ShowExp();
}
#endregion
///
/// 转职成功
///
///
///
private void TransferSucess(int eventId, object args)
{
Context.UI.OpenAsync(UIKeys.PlayerTransferSucessPanel);
VM.JokSkillNested.Ctrl.ShowJobUI();
}
///
/// 重置职业成功
///
///
///
private void ResetJobSucess(int eventId, object args)
{
Context.UI.OpenAsync(UIKeys.PlayerTransferPanel, true);
VM.JokSkillNested.Ctrl.ShowJobUI();
}
}
}