源战役客户端
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
2.1 KiB

  1. require("game.advertisement.AdvertisementModel")
  2. require("game.advertisement.AdvertisementView")
  3. AdvertisementController = AdvertisementController or BaseClass(BaseController, true)
  4. local AdvertisementController = AdvertisementController
  5. AdvertisementController.IsDebug = true
  6. function AdvertisementController:__init()
  7. AdvertisementController.Instance = self
  8. self.model = AdvertisementModel:getInstance()
  9. self:AddEvents()
  10. self:RegisterAllProtocal()
  11. end
  12. function AdvertisementController:__delete()
  13. end
  14. function AdvertisementController:RegisterAllProtocal( )
  15. end
  16. function AdvertisementController:AddEvents()
  17. -- 监控场景加载完毕 加载完才可以去判断 防止cookie没有初始化 只在首次登陆起作用
  18. local function onSceneStartHandler()
  19. self.model:SetSceneLoadState()
  20. if self.on_game_start_id then
  21. self:UnBind(self.on_game_start_id)
  22. end
  23. end
  24. self.on_game_start_id = self:Bind(EventName.SCENE_LOAD_VIEW_COMPLETE, onSceneStartHandler)
  25. --EventName.GAME_START
  26. --EventName.SCENE_LOAD_VIEW_COMPLETE
  27. -- 打开广告
  28. local function on_open_advertisement_view( sub_type )
  29. if not sub_type then
  30. --logWarn('=======Msh:AdvertisementController.lua[27] sub_type=======', sub_type)
  31. return
  32. end
  33. if self.advertisement_view == nil then
  34. self.advertisement_view = AdvertisementView.New()
  35. end
  36. if not self.advertisement_view:HasOpen() then
  37. self.advertisement_view:Open(sub_type)
  38. end
  39. end
  40. self.model:Bind(AdvertisementModel.OPEN_ADVERTISEMENT_VIEW, on_open_advertisement_view)
  41. -- 过天刷新cookie检测
  42. local update_cookie = function ( )
  43. self.model:UpdateCookie()
  44. end
  45. GlobalEventSystem:Bind(EventName.UPDATE_ROLE_LOGIN_TIME_DATA, update_cookie)
  46. -- 强制关闭广告
  47. local function on_close_advertisement_view( )
  48. if self.advertisement_view == nil then
  49. return
  50. end
  51. if self.advertisement_view:HasOpen() then
  52. -- 关闭现有广告 回滚今天的cookie次数
  53. self.model:ResetCookieBySubType(self.advertisement_view.sub_type)
  54. self.advertisement_view:Close()
  55. end
  56. end
  57. self.model:Bind(AdvertisementModel.CLOSE_ADVERTISEMENT_VIEW, on_close_advertisement_view)
  58. end