123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- using System.Collections.Generic;
- using System.Linq;
- using Core.Audio;
- using Core.UI.UTool;
- using Excel2Json;
- using Fort23.Core;
- using Fort23.UTool;
- using GameLogic.Bag;
- using UnityEngine;
- using Utility.CTween;
- namespace Fort23.Mono
- {
- [UIBinding(prefab = "UseExpElixirPanel")]
- public partial class UseExpElixirPanel : UIPanel
- {
- List<ExpElixirItemWidget> _expElixirItemWidgets = new List<ExpElixirItemWidget>();
- private void Init()
- {
- // isPopUi = true;
- isAddStack = true;
- }
- public override CTask GetFocus()
- {
- AppBarPanel.OpenPanel(this);
- return base.GetFocus();
- }
- protected override void AddEvent()
- {
- }
- protected override void DelEvent()
- {
- }
- public override void AddButtonEvent()
- {
- Btn_Close.onClick.AddListener(() => { UIManager.Instance.HideUIUIPanel(this); });
- }
- public async void CustomInit()
- {
- List<ItemConfig> itemConfigs = ConfigComponent.Instance.GetAll<ItemConfig>().ToList();
- List<ItemConfig> itemConfigs2 = itemConfigs
- .Where(i => i.itemTag == 5 && PlayerManager.Instance.BagController.IsEnough(i.ID, 1)).ToList();
- foreach (var itemConfig in itemConfigs2)
- {
- ExpElixirItemWidget elixirItemWidget =
- await UIManager.Instance.CreateGComponent<ExpElixirItemWidget>(null, Content);
- elixirItemWidget.CustomInit(itemConfig.ID);
- elixirItemWidget.OnClick = OnClick;
- _expElixirItemWidgets.Add(elixirItemWidget);
- }
- Text_UseCount.text = $"今日\n{AccountFileInfo.Instance.playerData.todayUseExpElixrPanelCount}/20";
- }
- private async void OnClick(ItemWidgetBasic obj)
- {
- ExpElixirItemWidget elixirItemWidget = obj as ExpElixirItemWidget;
- if (AccountFileInfo.Instance.playerData.todayUseExpElixrPanelCount >= 20)
- {
- TipMessagePanel.OpenTipMessagePanel("今日使用经验已达上限!");
- return;
- }
- if (PlayerManager.Instance.BagController.DeductItem(elixirItemWidget.ItemConfig.ID, 1))
- {
- // PlayerManager.Instance.myHero.heroData.exp += elixirItemWidget.ItemConfig.associateVlaue[0];
- AccountFileInfo.Instance.playerData.todayUseExpElixrPanelCount++;
- AccountFileInfo.Instance.SavePlayerData();
- AudioManager.Instance.PlayAudio("ui_shiyonghuode");
- }
- else
- {
- TipMessagePanel.OpenTipMessagePanel("道具不足!");
- return;
- }
- elixirItemWidget.fx_ui_danyao_qi.gameObject.SetActive(true);
- elixirItemWidget.fx_ui_danyao_qi.Play();
- HeroInformationPanel heroInformationPanel = UIManager.Instance.GetComponent<HeroInformationPanel>();
- // heroInformationPanel.UseExpElixir()
- GameObjectPool gameObjectPool = null;
- gameObjectPool = await GObjectPool.Instance.FetchAsync<GameObjectPool>("fx_ui_danyao_tw");
- gameObjectPool.own.transform.SetParent(this.transform);
- Vector2 pos = transform.worldToLocalMatrix * elixirItemWidget.fx_ui_danyao_qi.transform.position;
- Vector2 pos1 = transform.worldToLocalMatrix *
- heroInformationPanel.fxroot.GetComponent<RectTransform>().position;
- gameObjectPool.own.GetComponent<RectTransform>().anchoredPosition = pos;
- CustomTweenManager
- .To(() => pos, x => gameObjectPool.own.transform.GetComponent<RectTransform>().anchoredPosition = x,
- pos1, 0.5f, gameObjectPool.own)
- .SetEase(CustomTweenEX.CustomAnimationCurve.Line).SetLoop(false).OnCompleteAction = () =>
- {
- GObjectPool.Instance.Recycle(gameObjectPool);
- heroInformationPanel.fx_ui_danyao_shi.gameObject.SetActive(true);
- heroInformationPanel.fx_ui_danyao_shi.Play();
- };
- int exp = 0;
- AccumulatorUtility.StartAccumulation(
- elixirItemWidget.ItemConfig.associateVlaue[0], 0.2f, 20,
- current =>
- {
- PlayerManager.Instance.myHero.heroData.exp += current;
- AccountFileInfo.Instance.SavePlayerData();
- LogTool.Error("z" + current);
- },
- () => Debug.Log("累加完成!")
- );
- Text_UseCount.text = $"今日\n{AccountFileInfo.Instance.playerData.todayUseExpElixrPanelCount}/20";
- }
- public async static CTask<UseExpElixirPanel> OpenPanel()
- {
- UseExpElixirPanel useExpElixirPanel =
- await UIManager.Instance.LoadAndOpenPanel<UseExpElixirPanel>(null, UILayer.Top, isFocus: false);
- useExpElixirPanel.CustomInit();
- return useExpElixirPanel;
- }
- public async override CTask Close()
- {
- foreach (var expElixirItemWidget in _expElixirItemWidgets)
- {
- UIManager.Instance.DormancyGComponent(expElixirItemWidget);
- }
- _expElixirItemWidgets.Clear();
- await base.Close();
- }
- }
- }
|