123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308 |
- /// #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
- {
- /// <summary>
- /// UI逻辑处理类
- /// </summary>
- /// <typeparam name=""></typeparam>
- public partial class PlayerMainPanelCtrl : UIController<PlayerMainPanelVM>
- {
- private long _needNum; // 升级需要的经验丹道具数量
- private bool _bHideSkillInfo; // 是否需要隐藏技能信息气泡
- private List<CommonItemBaseView> _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);
- }
- /// <summary>
- /// 隐藏技能信息气泡弹窗
- /// </summary>
- /// <param name="context"></param>
- 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<CommonItemBaseView>()
- {
- 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();
- }
- /// <summary>
- /// 加载主角的spine
- /// </summary>
- /// <param name="spineName"></param>
- private void LoadPlayerSpine(string spineName)
- {
- VM.PlayerSpine.LoadSpine(spineName, "stand", true);
- }
- /// <summary>
- /// 角色称号
- /// </summary>
- /// <param name="title"></param>
- private void ShowTitleIcon(string title)
- {
- VM.TitleIcon.url = title;
- }
- #region 装备UI
- /// <summary>
- /// 显示装备UI
- /// </summary>
- 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++;
- });
- }
- /// <summary>
- /// 更换装备
- /// </summary>
- /// <param name="type"></param>
- /// <param name="id"></param>
- private void OnChangeEquip(int eventId, object args)
- {
- if (args == null)
- {
- return;
- }
- var changeEquipPartList = args as List<EEquipType>;
- 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);
- }
- }
- }
- }
- /// <summary>
- /// 刷新身上穿戴的装备信息
- /// </summary>
- /// <param name="eventId"></param>
- /// <param name="args"></param>
- 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;
- }
- /// <summary>
- /// 角色经验值增加
- /// </summary>
- /// <param name="eventId"></param>
- /// <param name="args"></param>
- private void AddPlayerExp(int eventId, object args)
- {
- ShowExp();
- }
- #endregion
- /// <summary>
- /// 转职成功
- /// </summary>
- /// <param name="eventId"></param>
- /// <param name="args"></param>
- private void TransferSucess(int eventId, object args)
- {
- Context.UI.OpenAsync(UIKeys.PlayerTransferSucessPanel);
- VM.JokSkillNested.Ctrl.ShowJobUI();
- }
- /// <summary>
- /// 重置职业成功
- /// </summary>
- /// <param name="eventId"></param>
- /// <param name="args"></param>
- private void ResetJobSucess(int eventId, object args)
- {
- Context.UI.OpenAsync(UIKeys.PlayerTransferPanel, true);
- VM.JokSkillNested.Ctrl.ShowJobUI();
- }
- }
- }
|