OpenBattlePassView.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. ItemUtil.CreateItemView(new ItemParamProto(){ItemId = itemInfo.Key,Count = itemInfo.Value}, obj as GComponent);
  59. }
  60. private void SetPrizeData()
  61. {
  62. //获取所有特别奖励数据
  63. var dataManager = BattlePassTaskDataManager.Instance;
  64. var allSpecialCfg = dataManager.GetAllSpecialCfg();
  65. _ui.m_Rewards.data = allSpecialCfg;
  66. _ui.m_Rewards.numItems = allSpecialCfg.Count;
  67. }
  68. }
  69. }