RewardsPanel.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. }
  16. protected override void AddEvent()
  17. {
  18. }
  19. protected override void DelEvent()
  20. {
  21. }
  22. public override void AddButtonEvent()
  23. {
  24. btnDi.onClick.AddListener(OnclickClose);
  25. }
  26. List<WidgetItem> widgetItems = new List<WidgetItem>();
  27. private void OnclickClose()
  28. {
  29. UIManager.Instance.HideUIUIPanel(this);
  30. }
  31. public override void Close()
  32. {
  33. onClose?.Invoke();
  34. foreach (var widgetItem in widgetItems)
  35. {
  36. UIManager.Instance.DormancyGComponent(widgetItem);
  37. }
  38. widgetItems.Clear();
  39. base.Close();
  40. }
  41. private Action onClose;
  42. public override CTask Show()
  43. {
  44. AudioManager.Instance.PlayAudio("jiangliui.wav");
  45. return base.Show();
  46. }
  47. public async void InitRewardsPanel(List<ItemInfo> rewards, Action onClose = null)
  48. {
  49. this.onClose = onClose;
  50. foreach (var widgetItem in widgetItems)
  51. {
  52. UIManager.Instance.DormancyGComponent(widgetItem);
  53. }
  54. widgetItems.Clear();
  55. foreach (ItemInfo reward in rewards)
  56. {
  57. GenerateWidget(reward);
  58. }
  59. }
  60. public void SetTitle(string title)
  61. {
  62. txtlName.text = title;
  63. }
  64. public async void InitRewardsPanel(Dictionary<string, ItemInfo> rewardsDic, Action onClose = null)
  65. {
  66. this.onClose = onClose;
  67. foreach (var widgetItem in widgetItems)
  68. {
  69. UIManager.Instance.DormancyGComponent(widgetItem);
  70. }
  71. widgetItems.Clear();
  72. foreach (KeyValuePair<string, ItemInfo> keyValuePair in rewardsDic)
  73. {
  74. GenerateWidget(keyValuePair.Value);
  75. }
  76. }
  77. private async void GenerateWidget(ItemInfo itemInfo)
  78. {
  79. WidgetItem widgetItem = await UIManager.Instance.CreateGComponent<WidgetItem>(null, root: itemRoot);
  80. widgetItem.InitWidget(itemInfo);
  81. widgetItems.Add(widgetItem);
  82. }
  83. public async static CTask<RewardsPanel> OpenPanel(Dictionary<string, ItemInfo> rewardsDic, Action onClose = null)
  84. {
  85. RewardsPanel rewardsPanel = await UIManager.Instance.LoadAndOpenPanel<RewardsPanel>(null, layer: UILayer.Top,isShowBG:true);
  86. rewardsPanel.InitRewardsPanel(rewardsDic, onClose);
  87. return rewardsPanel;
  88. }
  89. public async static CTask<RewardsPanel> OpenPanel(List<ItemInfo> rewardsDic, Action onClose = null, int titleId = 0)
  90. {
  91. RewardsPanel rewardsPanel = await UIManager.Instance.LoadAndOpenPanel<RewardsPanel>(null, layer: UILayer.Top,isShowBG:true);
  92. rewardsPanel.InitRewardsPanel(rewardsDic, onClose);
  93. if (titleId != 0)
  94. rewardsPanel.SetTitle(LanguageManager.Instance.Text(titleId));
  95. return rewardsPanel;
  96. }
  97. }
  98. }