RewardsPanel.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. GenerateWidget(reward);
  64. }
  65. }
  66. public void SetTitle(string title)
  67. {
  68. txtlName.text = title;
  69. }
  70. public async void InitRewardsPanel(Dictionary<string, ItemInfo> rewardsDic, Action onClose = null)
  71. {
  72. this.onClose = onClose;
  73. foreach (var widgetItem in widgetItems)
  74. {
  75. UIManager.Instance.DormancyGComponent(widgetItem);
  76. }
  77. widgetItems.Clear();
  78. foreach (KeyValuePair<string, ItemInfo> keyValuePair in rewardsDic)
  79. {
  80. GenerateWidget(keyValuePair.Value);
  81. }
  82. }
  83. private async void GenerateWidget(ItemInfo itemInfo)
  84. {
  85. WidgetItemWithName widgetItem =
  86. await UIManager.Instance.CreateGComponent<WidgetItemWithName>(null, root: itemRoot);
  87. widgetItem.InitWidget(itemInfo);
  88. widgetItems.Add(widgetItem);
  89. }
  90. public async static CTask<RewardsPanel> OpenPanel(Dictionary<string, ItemInfo> rewardsDic,
  91. Action onClose = null)
  92. {
  93. RewardsPanel rewardsPanel =
  94. await UIManager.Instance.LoadAndOpenPanel<RewardsPanel>(null, layer: UILayer.Top, isShowBG: true);
  95. rewardsPanel.InitRewardsPanel(rewardsDic, onClose);
  96. return rewardsPanel;
  97. }
  98. public async static CTask<RewardsPanel> OpenPanel(List<ItemInfo> rewardsDic, Action onClose = null,
  99. int titleId = 0)
  100. {
  101. RewardsPanel rewardsPanel =
  102. await UIManager.Instance.LoadAndOpenPanel<RewardsPanel>(null, layer: UILayer.Top, isShowBG: true);
  103. rewardsPanel.InitRewardsPanel(rewardsDic, onClose);
  104. if (titleId != 0)
  105. rewardsPanel.SetTitle(LanguageManager.Instance.Text(titleId));
  106. return rewardsPanel;
  107. }
  108. }
  109. }