UseExpElixirPanel.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. //TODO 消耗:修为丹
  61. if (PlayerManager.Instance.BagController.DeductItem(elixirItemWidget.ItemConfig.ID, 1))
  62. {
  63. // PlayerManager.Instance.myHero.heroData.exp += elixirItemWidget.ItemConfig.associateVlaue[0];
  64. AccountFileInfo.Instance.playerData.todayUseExpElixrPanelCount++;
  65. AccountFileInfo.Instance.SavePlayerData();
  66. AudioManager.Instance.PlayAudio("ui_shiyonghuode");
  67. }
  68. else
  69. {
  70. TipMessagePanel.OpenTipMessagePanel("道具不足!");
  71. return;
  72. }
  73. elixirItemWidget.fx_ui_danyao_qi.gameObject.SetActive(true);
  74. elixirItemWidget.fx_ui_danyao_qi.Play();
  75. HeroInformationPanel heroInformationPanel = UIManager.Instance.GetComponent<HeroInformationPanel>();
  76. // heroInformationPanel.UseExpElixir()
  77. GameObjectPool gameObjectPool = null;
  78. gameObjectPool = await GObjectPool.Instance.FetchAsync<GameObjectPool>("fx_ui_danyao_tw");
  79. gameObjectPool.own.transform.SetParent(this.transform);
  80. Vector2 pos = transform.worldToLocalMatrix * elixirItemWidget.fx_ui_danyao_qi.transform.position;
  81. Vector2 pos1 = transform.worldToLocalMatrix *
  82. heroInformationPanel.fxroot.GetComponent<RectTransform>().position;
  83. gameObjectPool.own.GetComponent<RectTransform>().anchoredPosition = pos;
  84. CustomTweenManager
  85. .To(() => pos, x => gameObjectPool.own.transform.GetComponent<RectTransform>().anchoredPosition = x,
  86. pos1, 0.5f, gameObjectPool.own)
  87. .SetEase(CustomTweenEX.CustomAnimationCurve.Line).SetLoop(false).OnCompleteAction = () =>
  88. {
  89. GObjectPool.Instance.Recycle(gameObjectPool);
  90. heroInformationPanel.fx_ui_danyao_shi.gameObject.SetActive(true);
  91. heroInformationPanel.fx_ui_danyao_shi.Play();
  92. };
  93. int exp = 0;
  94. AccumulatorUtility.StartAccumulation(
  95. elixirItemWidget.ItemConfig.associateVlaue[0], 0.2f, 20,
  96. current =>
  97. {
  98. PlayerManager.Instance.myHero.heroData.exp += current;
  99. AccountFileInfo.Instance.SavePlayerData();
  100. LogTool.Error("z" + current);
  101. },
  102. () => Debug.Log("累加完成!")
  103. );
  104. Text_UseCount.text = $"今日\n{AccountFileInfo.Instance.playerData.todayUseExpElixrPanelCount}/20";
  105. }
  106. public async static CTask<UseExpElixirPanel> OpenPanel()
  107. {
  108. UseExpElixirPanel useExpElixirPanel =
  109. await UIManager.Instance.LoadAndOpenPanel<UseExpElixirPanel>(null, UILayer.Top, isFocus: false);
  110. useExpElixirPanel.CustomInit();
  111. return useExpElixirPanel;
  112. }
  113. public async override CTask Close()
  114. {
  115. foreach (var expElixirItemWidget in _expElixirItemWidgets)
  116. {
  117. UIManager.Instance.DormancyGComponent(expElixirItemWidget);
  118. }
  119. _expElixirItemWidgets.Clear();
  120. await base.Close();
  121. }
  122. }
  123. }