UseExpElixirPanel.cs 5.4 KB

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