UseExpElixirPanel.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using Core.Audio;
  4. using Core.UI.UTool;
  5. using Excel2Json;
  6. using Fort23.Core;
  7. using Fort23.UTool;
  8. using GameLogic.Bag;
  9. using UnityEngine;
  10. using Utility.CTween;
  11. namespace Fort23.Mono
  12. {
  13. [UIBinding(prefab = "UseExpElixirPanel")]
  14. public partial class UseExpElixirPanel : UIPanel
  15. {
  16. List<ExpElixirItemWidget> _expElixirItemWidgets = new List<ExpElixirItemWidget>();
  17. private void Init()
  18. {
  19. IsShowAppBar = false;
  20. isAddStack = true;
  21. }
  22. public override CTask GetFocus()
  23. {
  24. AppBarPanel.OpenPanel(this);
  25. return base.GetFocus();
  26. }
  27. protected override void AddEvent()
  28. {
  29. }
  30. protected override void DelEvent()
  31. {
  32. }
  33. public override void AddButtonEvent()
  34. {
  35. Btn_Close.onClick.AddListener(() => { UIManager.Instance.HideUIUIPanel(this); });
  36. }
  37. public async void CustomInit()
  38. {
  39. List<ItemConfig> itemConfigs = ConfigComponent.Instance.GetAll<ItemConfig>().ToList();
  40. List<ItemConfig> itemConfigs2 = itemConfigs
  41. .Where(i => i.itemTag == 5 && PlayerManager.Instance.BagController.IsEnough(i.ID, 1)).ToList();
  42. foreach (var itemConfig in itemConfigs2)
  43. {
  44. ExpElixirItemWidget elixirItemWidget =
  45. await UIManager.Instance.CreateGComponent<ExpElixirItemWidget>(null, Content);
  46. elixirItemWidget.CustomInit(itemConfig.ID);
  47. elixirItemWidget.OnClick = OnClick;
  48. _expElixirItemWidgets.Add(elixirItemWidget);
  49. }
  50. Text_UseCount.text = $"今日\n{AccountFileInfo.Instance.playerData.todayUseExpElixrPanelCount}/20";
  51. }
  52. private async void OnClick(ItemWidgetBasic obj)
  53. {
  54. ExpElixirItemWidget elixirItemWidget = obj as ExpElixirItemWidget;
  55. if (AccountFileInfo.Instance.playerData.todayUseExpElixrPanelCount >= 20)
  56. {
  57. TipMessagePanel.OpenTipMessagePanel("今日使用经验已达上限!");
  58. return;
  59. }
  60. if (PlayerManager.Instance.BagController.DeductItem(elixirItemWidget.ItemConfig.ID, 1))
  61. {
  62. // PlayerManager.Instance.myHero.heroData.exp += elixirItemWidget.ItemConfig.associateVlaue[0];
  63. AccountFileInfo.Instance.playerData.todayUseExpElixrPanelCount++;
  64. AccountFileInfo.Instance.SavePlayerData();
  65. AudioManager.Instance.PlayAudio("ui_shiyonghuode");
  66. }
  67. else
  68. {
  69. TipMessagePanel.OpenTipMessagePanel("道具不足!");
  70. return;
  71. }
  72. elixirItemWidget.fx_ui_danyao_qi.gameObject.SetActive(true);
  73. elixirItemWidget.fx_ui_danyao_qi.Play();
  74. HeroInformationPanel heroInformationPanel = UIManager.Instance.GetComponent<HeroInformationPanel>();
  75. // heroInformationPanel.UseExpElixir()
  76. GameObjectPool gameObjectPool = null;
  77. gameObjectPool = await GObjectPool.Instance.FetchAsync<GameObjectPool>("fx_ui_danyao_tw");
  78. gameObjectPool.own.transform.SetParent(this.transform);
  79. Vector2 pos = transform.worldToLocalMatrix * elixirItemWidget.fx_ui_danyao_qi.transform.position;
  80. Vector2 pos1 = transform.worldToLocalMatrix *
  81. heroInformationPanel.fxroot.GetComponent<RectTransform>().position;
  82. gameObjectPool.own.GetComponent<RectTransform>().anchoredPosition = pos;
  83. CustomTweenManager
  84. .To(() => pos, x => gameObjectPool.own.transform.GetComponent<RectTransform>().anchoredPosition = x,
  85. pos1, 0.5f, gameObjectPool.own)
  86. .SetEase(CustomTweenEX.CustomAnimationCurve.Line).SetLoop(false).OnCompleteAction = () =>
  87. {
  88. GObjectPool.Instance.Recycle(gameObjectPool);
  89. heroInformationPanel.fx_ui_danyao_shi.gameObject.SetActive(true);
  90. heroInformationPanel.fx_ui_danyao_shi.Play();
  91. };
  92. int exp = 0;
  93. AccumulatorUtility.StartAccumulation(
  94. elixirItemWidget.ItemConfig.associateVlaue[0], 0.2f, 20,
  95. current =>
  96. {
  97. PlayerManager.Instance.myHero.heroData.exp += current;
  98. AccountFileInfo.Instance.SavePlayerData();
  99. LogTool.Error("z" + current);
  100. },
  101. () => Debug.Log("累加完成!")
  102. );
  103. Text_UseCount.text = $"今日\n{AccountFileInfo.Instance.playerData.todayUseExpElixrPanelCount}/20";
  104. }
  105. public async static CTask<UseExpElixirPanel> OpenPanel()
  106. {
  107. UseExpElixirPanel useExpElixirPanel =
  108. await UIManager.Instance.LoadAndOpenPanel<UseExpElixirPanel>(null, UILayer.Top, isFocus: false);
  109. useExpElixirPanel.CustomInit();
  110. return useExpElixirPanel;
  111. }
  112. public async override CTask Close()
  113. {
  114. foreach (var expElixirItemWidget in _expElixirItemWidgets)
  115. {
  116. UIManager.Instance.DormancyGComponent(expElixirItemWidget);
  117. }
  118. _expElixirItemWidgets.Clear();
  119. await base.Close();
  120. }
  121. }
  122. }