RewardsPanel.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. private void OnclickClose()
  27. {
  28. onClose?.Invoke();
  29. UIManager.Instance.HideUIUIPanel(this);
  30. UIManager.Instance.DormancyAllGComponent<WidgetItem>(rewardPool);
  31. }
  32. private Action onClose;
  33. private string rewardPool = "rewardPool";
  34. public override CTask Show()
  35. {
  36. AudioManager.Instance.PlayAudio("jiangliui.wav");
  37. return base.Show();
  38. }
  39. public async void InitRewardsPanel(List<ItemInfo> rewards, Action onClose = null)
  40. {
  41. this.onClose = onClose;
  42. foreach (ItemInfo reward in rewards)
  43. {
  44. GenerateWidget(reward);
  45. }
  46. }
  47. public void SetTitle(string title)
  48. {
  49. txtlName.text = title;
  50. }
  51. public async void InitRewardsPanel(Dictionary<string, ItemInfo> rewardsDic, Action onClose = null)
  52. {
  53. this.onClose = onClose;
  54. foreach (KeyValuePair<string, ItemInfo> keyValuePair in rewardsDic)
  55. {
  56. GenerateWidget(keyValuePair.Value);
  57. }
  58. }
  59. private async void GenerateWidget(ItemInfo itemInfo)
  60. {
  61. WidgetItem widgetItem = await UIManager.Instance.CreateGComponent<WidgetItem>(null,
  62. poolName: rewardPool, root: itemRoot);
  63. widgetItem.InitWidget(itemInfo);
  64. }
  65. public async static CTask<RewardsPanel> OpenPanel(Dictionary<string, ItemInfo> rewardsDic, Action onClose = null)
  66. {
  67. RewardsPanel rewardsPanel = await UIManager.Instance.LoadAndOpenPanel<RewardsPanel>(null, layer: UILayer.Top);
  68. rewardsPanel.InitRewardsPanel(rewardsDic, onClose);
  69. return rewardsPanel;
  70. }
  71. public async static CTask<RewardsPanel> OpenPanel(List<ItemInfo> rewardsDic, Action onClose = null, int titleId = 0)
  72. {
  73. RewardsPanel rewardsPanel = await UIManager.Instance.LoadAndOpenPanel<RewardsPanel>(null, layer: UILayer.Top);
  74. rewardsPanel.InitRewardsPanel(rewardsDic, onClose);
  75. if (titleId != 0)
  76. rewardsPanel.SetTitle(LanguageManager.Instance.Text(titleId));
  77. return rewardsPanel;
  78. }
  79. }
  80. }