OpenBattlePassView.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. modal = true;
  31. }
  32. private void OnBtnOpenClick(EventContext context)
  33. {
  34. ReqShopBuy(990003).Coroutine();
  35. }
  36. protected override void OnShown()
  37. {
  38. base.OnShown();
  39. SetPrizeData();
  40. }
  41. protected override void AddEventListener()
  42. {
  43. EventAgent.AddEventListener(ConstMessage.NOTICE_PASSPORT_OPEN, OnNoticePassportOpen);
  44. }
  45. protected override void RemoveEventListener()
  46. {
  47. EventAgent.RemoveEventListener(ConstMessage.NOTICE_PASSPORT_OPEN, OnNoticePassportOpen);
  48. }
  49. private void OnNoticePassportOpen()
  50. {
  51. Hide();
  52. }
  53. private static void SpecialRewardRender(int index, GObject obj)
  54. {
  55. var itemInfos = (List<KeyValuePair<int, int>>)obj.parent.data;
  56. var itemInfo = itemInfos[index];
  57. ItemUtil.CreateItemView(new[] { itemInfo.Key, itemInfo.Value }, obj as GComponent);
  58. }
  59. private void SetPrizeData()
  60. {
  61. //获取所有特别奖励数据
  62. var dataManager = BattlePassTaskDataManager.Instance;
  63. var allSpecialCfg = dataManager.GetAllSpecialCfg();
  64. _ui.m_Rewards.data = allSpecialCfg;
  65. _ui.m_Rewards.numItems = allSpecialCfg.Count;
  66. }
  67. }
  68. }