RewardsPanel.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 = true;
  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 override void Close()
  34. {
  35. onClose?.Invoke();
  36. foreach (var widgetItem in widgetItems)
  37. {
  38. UIManager.Instance.DormancyGComponent(widgetItem);
  39. }
  40. widgetItems.Clear();
  41. base.Close();
  42. }
  43. private Action onClose;
  44. public override CTask Show()
  45. {
  46. AudioManager.Instance.PlayAudio("ui_jianglimianban.wav");
  47. return base.Show();
  48. }
  49. public async void InitRewardsPanel(List<ItemInfo> rewards, Action onClose = null)
  50. {
  51. this.onClose = onClose;
  52. foreach (var widgetItem in widgetItems)
  53. {
  54. UIManager.Instance.DormancyGComponent(widgetItem);
  55. }
  56. widgetItems.Clear();
  57. foreach (ItemInfo reward in rewards)
  58. {
  59. GenerateWidget(reward);
  60. }
  61. }
  62. public void SetTitle(string title)
  63. {
  64. txtlName.text = title;
  65. }
  66. public async void InitRewardsPanel(Dictionary<string, ItemInfo> rewardsDic, Action onClose = null)
  67. {
  68. this.onClose = onClose;
  69. foreach (var widgetItem in widgetItems)
  70. {
  71. UIManager.Instance.DormancyGComponent(widgetItem);
  72. }
  73. widgetItems.Clear();
  74. foreach (KeyValuePair<string, ItemInfo> keyValuePair in rewardsDic)
  75. {
  76. GenerateWidget(keyValuePair.Value);
  77. }
  78. }
  79. private async void GenerateWidget(ItemInfo itemInfo)
  80. {
  81. WidgetItemWithName widgetItem =
  82. await UIManager.Instance.CreateGComponent<WidgetItemWithName>(null, root: itemRoot);
  83. widgetItem.InitWidget(itemInfo);
  84. widgetItems.Add(widgetItem);
  85. }
  86. public async static CTask<RewardsPanel> OpenPanel(Dictionary<string, ItemInfo> rewardsDic,
  87. Action onClose = null)
  88. {
  89. RewardsPanel rewardsPanel =
  90. await UIManager.Instance.LoadAndOpenPanel<RewardsPanel>(null, layer: UILayer.Top, isShowBG: true);
  91. rewardsPanel.InitRewardsPanel(rewardsDic, onClose);
  92. return rewardsPanel;
  93. }
  94. public async static CTask<RewardsPanel> OpenPanel(List<ItemInfo> rewardsDic, Action onClose = null,
  95. int titleId = 0)
  96. {
  97. RewardsPanel rewardsPanel =
  98. await UIManager.Instance.LoadAndOpenPanel<RewardsPanel>(null, layer: UILayer.Top, isShowBG: true);
  99. rewardsPanel.InitRewardsPanel(rewardsDic, onClose);
  100. if (titleId != 0)
  101. rewardsPanel.SetTitle(LanguageManager.Instance.Text(titleId));
  102. return rewardsPanel;
  103. }
  104. }
  105. }