/// #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 long _needNum; // 升级需要的经验丹道具数量 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) { if (ItemService.Instance.IsEnough(KeyValue.PlayerUpItemId, _needNum, true)) { PlayerService.Instance.SendToUpgradeLv(); } } private void OnClickChangeBtn(EventContext context) { Context.ShowTips("更换契约技能"); } private void OnClickMountBtn(EventContext context) { Context.UI.OpenAsync(UIKeys.MountMainPanel); } 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() { Context.AddListener(EventDefine.OnChangeEquip, OnChangeEquip); Context.AddListener(EventDefine.PlayerExpAdd, AddPlayerExp); Context.AddListener(EventDefine.RefreshWearEquipUI, RefreshWearEquipUI); Context.AddListener(EventDefine.TransferSucess, TransferSucess); Context.AddListener(EventDefine.ResetJobSucess, ResetJobSucess); } private void RemoveEventListener() { Context.RemoveListener(EventDefine.OnChangeEquip, OnChangeEquip); Context.RemoveListener(EventDefine.PlayerExpAdd, AddPlayerExp); Context.RemoveListener(EventDefine.RefreshWearEquipUI, RefreshWearEquipUI); Context.RemoveListener(EventDefine.TransferSucess, TransferSucess); Context.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() { int index = 1; _equipItemList.ForEach((item) => { EquipAttr equipData = EquipData.Instance.GetWearEquipData((EEquipType)index); if (equipData != null) { var equipBase = new EquipItemBase(); equipBase.InitByEquipPart(equipData.EquipType); item.Ctrl.ShowUI(equipBase); } 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) { var equipItemBase = new EquipItemBase(); equipItemBase.InitByEquipPart(equipPart); equipItem.Ctrl.ShowUI(equipItemBase); } } } } /// /// 刷新身上穿戴的装备信息 /// /// /// private void RefreshWearEquipUI(int eventId, object args) { 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) { ShowPlayerLevel(); var expInfo = LevelTableRepo.Get(PlayerData.Instance.Level); if (expInfo == null) { // 等级上限 expInfo = LevelTableRepo.Get(PlayerData.Instance.Level-1); } _needNum = expInfo.Exp; 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(); } } }