OpenBattlePassView.cs 2.3 KB

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