RewardsPanel.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. using System;
  2. using System.Collections.Generic;
  3. using Core.Audio;
  4. using Core.Language;
  5. using Fort23.Core;
  6. using GameLogic.Bag;
  7. using NetCore.Protocol.MemoryPack;
  8. namespace Fort23.Mono
  9. {
  10. [UIBinding(prefab = "RewardsPanel")]
  11. public partial class RewardsPanel : UIPanel
  12. {
  13. private void Init()
  14. {
  15. isAddStack = false;
  16. IsShowAppBar = false;
  17. }
  18. protected override void AddEvent()
  19. {
  20. }
  21. protected override void DelEvent()
  22. {
  23. }
  24. public override void AddButtonEvent()
  25. {
  26. btnDi.onClick.AddListener(OnclickClose);
  27. }
  28. List<WidgetItemWithName> widgetItems = new List<WidgetItemWithName>();
  29. private void OnclickClose()
  30. {
  31. UIManager.Instance.HideUIUIPanel(this);
  32. }
  33. public async override CTask Close()
  34. {
  35. onClose?.Invoke();
  36. foreach (var widgetItem in widgetItems)
  37. {
  38. UIManager.Instance.DormancyGComponent(widgetItem);
  39. }
  40. widgetItems.Clear();
  41. if (PlayerGuideManager.Instance.GuideIsCanDo(2, 7))
  42. {
  43. PlayerGuideManager.Instance.NextGuide();
  44. }
  45. await base.Close();
  46. }
  47. private Action onClose;
  48. public override CTask Show()
  49. {
  50. AudioManager.Instance.PlayAudio("ui_jianglimianban.wav");
  51. return base.Show();
  52. }
  53. public async void InitRewardsPanel(List<ItemInfo> rewards, Action onClose = null)
  54. {
  55. this.onClose = onClose;
  56. foreach (var widgetItem in widgetItems)
  57. {
  58. UIManager.Instance.DormancyGComponent(widgetItem);
  59. }
  60. widgetItems.Clear();
  61. foreach (ItemInfo reward in rewards)
  62. {
  63. if (reward.config.isVisible == 0)
  64. {
  65. continue;
  66. }
  67. GenerateWidget(reward);
  68. }
  69. }
  70. public void SetTitle(string title)
  71. {
  72. txtlName.text = title;
  73. }
  74. public async void InitRewardsPanel(Dictionary<string, ItemInfo> rewardsDic, Action onClose = null)
  75. {
  76. this.onClose = onClose;
  77. foreach (var widgetItem in widgetItems)
  78. {
  79. UIManager.Instance.DormancyGComponent(widgetItem);
  80. }
  81. widgetItems.Clear();
  82. foreach (KeyValuePair<string, ItemInfo> keyValuePair in rewardsDic)
  83. {
  84. GenerateWidget(keyValuePair.Value);
  85. }
  86. }
  87. private async void GenerateWidget(ItemInfo itemInfo)
  88. {
  89. WidgetItemWithName widgetItem =
  90. await UIManager.Instance.CreateGComponent<WidgetItemWithName>(null, root: itemRoot);
  91. widgetItem.InitWidget(itemInfo);
  92. widgetItems.Add(widgetItem);
  93. }
  94. public async static CTask<RewardsPanel> OpenPanel(Dictionary<string, ItemInfo> rewardsDic,
  95. Action onClose = null)
  96. {
  97. RewardsPanel rewardsPanel =
  98. await UIManager.Instance.LoadAndOpenPanel<RewardsPanel>(null, layer: UILayer.Top, isShowBG: true);
  99. rewardsPanel.InitRewardsPanel(rewardsDic, onClose);
  100. return rewardsPanel;
  101. }
  102. public async static CTask<RewardsPanel> OpenPanel(List<ItemInfo> rewardsDic, Action onClose = null,
  103. int titleId = 0)
  104. {
  105. RewardsPanel rewardsPanel =
  106. await UIManager.Instance.LoadAndOpenPanel<RewardsPanel>(null, layer: UILayer.Top, isShowBG: true);
  107. rewardsPanel.InitRewardsPanel(rewardsDic, onClose);
  108. if (titleId != 0)
  109. rewardsPanel.SetTitle(LanguageManager.Instance.Text(titleId));
  110. return rewardsPanel;
  111. }
  112. }
  113. }