OpenBattlePassView.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System.Collections.Generic;
  2. using FairyGUI;
  3. using UI.Task;
  4. using static GFGGame.ShopSProxy;
  5. namespace GFGGame
  6. {
  7. public class OpenBattlePassView : BaseWindow
  8. {
  9. private UI_OpenBattlePassUI _ui;
  10. public override void Dispose()
  11. {
  12. if (_ui != null)
  13. {
  14. _ui.Dispose();
  15. _ui = null;
  16. }
  17. base.Dispose();
  18. }
  19. protected override void OnInit()
  20. {
  21. base.OnInit();
  22. packageName = UI_OpenBattlePassUI.PACKAGE_NAME;
  23. _ui = UI_OpenBattlePassUI.Create();
  24. viewCom = _ui.target;
  25. viewCom.Center();
  26. _ui.m_CloseBtn.onClick.Add(Hide);
  27. // clickBlankToClose = false;
  28. _ui.m_Rewards.itemRenderer = SpecialRewardRender;
  29. _ui.m_OpenBtn.onClick.Add(OnBtnOpenClick);
  30. }
  31. private void OnBtnOpenClick(EventContext context)
  32. {
  33. ReqShopBuy(990003).Coroutine();
  34. }
  35. protected override void OnShown()
  36. {
  37. base.OnShown();
  38. SetPrizeData();
  39. }
  40. protected override void AddEventListener()
  41. {
  42. EventAgent.AddEventListener(ConstMessage.NOTICE_PASSPORT_OPEN, OnNoticePassportOpen);
  43. }
  44. protected override void RemoveEventListener()
  45. {
  46. EventAgent.RemoveEventListener(ConstMessage.NOTICE_PASSPORT_OPEN, OnNoticePassportOpen);
  47. }
  48. private void OnNoticePassportOpen()
  49. {
  50. Hide();
  51. }
  52. private static void SpecialRewardRender(int index, GObject obj)
  53. {
  54. var itemInfos = (List<KeyValuePair<int, int>>)obj.parent.data;
  55. var itemInfo = itemInfos[index];
  56. ItemUtil.CreateItemView(new[] { itemInfo.Key, itemInfo.Value }, obj as GComponent);
  57. }
  58. private void SetPrizeData()
  59. {
  60. //获取所有特别奖励数据
  61. var dataManager = BattlePassTaskDataManager.Instance;
  62. var allSpecialCfg = dataManager.GetAllSpecialCfg();
  63. _ui.m_Rewards.data = allSpecialCfg;
  64. _ui.m_Rewards.numItems = allSpecialCfg.Count;
  65. }
  66. }
  67. }