RewardsPanel.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System;
  2. using System.Collections.Generic;
  3. using GameLogic.Bag;
  4. namespace Fort23.Mono
  5. {
  6. [UIBinding(prefab = "RewardsPanel" )]
  7. public partial class RewardsPanel : UIPanel
  8. {
  9. private void Init()
  10. {
  11. }
  12. protected override void AddEvent()
  13. {
  14. }
  15. protected override void DelEvent()
  16. {
  17. }
  18. public override void AddButtonEvent()
  19. {
  20. btnDi.onClick.AddListener(OnclickClose);
  21. }
  22. private void OnclickClose()
  23. {
  24. onClose?.Invoke();
  25. UIManager.Instance.HideUIUIPanel(this);
  26. UIManager.Instance.DormancyAllGComponent<WidgetItem>(rewardPool);
  27. }
  28. private Action onClose;
  29. private string rewardPool = "rewardPool";
  30. public async void InitRewardsPanel(List<ItemInfo> rewards, Action onClose = null)
  31. {
  32. this.onClose = onClose;
  33. foreach (ItemInfo reward in rewards)
  34. {
  35. GenerateWidget(reward);
  36. }
  37. }
  38. public async void InitRewardsPanel(Dictionary<string, ItemInfo> rewardsDic, Action onClose = null)
  39. {
  40. this.onClose = onClose;
  41. foreach (KeyValuePair<string,ItemInfo> keyValuePair in rewardsDic)
  42. {
  43. GenerateWidget(keyValuePair.Value);
  44. }
  45. }
  46. private async void GenerateWidget(ItemInfo itemInfo)
  47. {
  48. WidgetItem widgetItem = await UIManager.Instance.CreateGComponentForObject<WidgetItem>(widget, null, isInstance: true,
  49. poolName: rewardPool, root: itemRoot);
  50. widgetItem.InitWidget(itemInfo);
  51. }
  52. }
  53. }