unLock_view.ts 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import { _decorator, Component, Label, Node, Animation } from 'cc';
  2. import { base_ui } from '../fw/base_ui';
  3. import { userDataManager } from '../manager/userDataManager';
  4. import { tools } from '../tools';
  5. import { SdkUtil } from '../sdkUtil';
  6. import { config } from '../config';
  7. const { ccclass, property } = _decorator;
  8. @ccclass('unLock_view')
  9. export class unLock_view extends base_ui {
  10. @property(Node) btn_close:Node = null
  11. @property(Node) btn_look_video:Node = null
  12. @property(Node) lab_look_video:Node = null
  13. @property(Node) lab_des:Node = null
  14. private m_cur_count:number = 0
  15. private m_max_count:number = 3
  16. private m_lookVideo_finish_cb = null
  17. start() {
  18. this.onButtonListen(this.btn_close, ()=>{
  19. this.stopBtnLookVideoAni()
  20. this.closeSelf()
  21. })
  22. this.onButtonListen(this.btn_look_video, this.onLookVideo.bind(this))
  23. this.playBtnLookVideoAni()
  24. }
  25. initView(lookVideo_finish_cb) {
  26. this.m_lookVideo_finish_cb = lookVideo_finish_cb
  27. this.m_cur_count = userDataManager.getUserFreeAdsLookVideoCount()
  28. let sys_config = tools.sys_config
  29. this.m_max_count = sys_config.free_ads_number
  30. let time = 0
  31. if(sys_config.free_game_time >0) {
  32. time = sys_config.free_game_time / 3600
  33. }
  34. if(time<1) {
  35. time = parseFloat(time.toFixed(1))
  36. }
  37. // console.log('time=',time)
  38. this.lab_look_video.getComponent(Label).string = '看视频' + this.m_cur_count + '/' + this.m_max_count
  39. this.lab_des.getComponent(Label).string = '观看' + this.m_max_count + '次视频,获取' + time + '小时无限挑战机会'
  40. }
  41. private onLookVideo() {
  42. if(this.m_cur_count>=this.m_max_count) {
  43. return
  44. }
  45. let ad_id = SdkUtil.getAdId(config.ADS_TYPE.GAME_INFINITE_DEGREE_VIDEO)
  46. SdkUtil.showVideoAd(ad_id,(res)=>{
  47. if(res.isEnded){
  48. this.m_cur_count++
  49. userDataManager.saveUserFreeAdsLookVideoCount(this.m_cur_count)
  50. this.lab_look_video.getComponent(Label).string = '看视频' + this.m_cur_count + '/' + this.m_max_count
  51. if(this.m_cur_count>=this.m_max_count) {
  52. if(this.m_lookVideo_finish_cb) {
  53. let cur_time = new Date().getTime()
  54. userDataManager.saveUserFreeAdsTime(cur_time)
  55. userDataManager.saveUserFreeAdsLookVideoCount(0)
  56. this.m_lookVideo_finish_cb(this)
  57. }
  58. this.closeSelf()
  59. }
  60. }
  61. })
  62. }
  63. closeSelf() {
  64. this.close()
  65. }
  66. private playBtnLookVideoAni() {
  67. this.btn_look_video.getComponent(Animation).play()
  68. }
  69. private stopBtnLookVideoAni() {
  70. this.btn_look_video.getComponent(Animation).stop()
  71. }
  72. }