unLock_view.ts 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. import { GameManager } from '../GameManager';
  8. const { ccclass, property } = _decorator;
  9. @ccclass('unLock_view')
  10. export class unLock_view extends base_ui {
  11. @property(Node) btn_close:Node = null
  12. @property(Node) btn_look_video:Node = null
  13. @property(Node) lab_look_video:Node = null
  14. @property(Node) lab_des:Node = null
  15. private m_cur_count:number = 0
  16. private m_max_count:number = 3
  17. private m_lookVideo_finish_cb = null
  18. start() {
  19. this.onButtonListen(this.btn_close, ()=>{
  20. this.stopBtnLookVideoAni()
  21. this.closeSelf()
  22. })
  23. this.onButtonListen(this.btn_look_video, this.onLookVideo.bind(this))
  24. this.playBtnLookVideoAni()
  25. }
  26. initView(lookVideo_finish_cb) {
  27. this.m_lookVideo_finish_cb = lookVideo_finish_cb
  28. this.m_cur_count = userDataManager.getUserFreeAdsData().look_video_count
  29. let sys_config = tools.sys_config
  30. this.m_max_count = sys_config.free_ads_number
  31. let time = 0
  32. if(sys_config.free_game_time >0) {
  33. time = sys_config.free_game_time / 3600
  34. }
  35. if(time<1) {
  36. time = parseFloat(time.toFixed(1))
  37. }
  38. // console.log('time=',time)
  39. this.lab_look_video.getComponent(Label).string = '看视频' + this.m_cur_count + '/' + this.m_max_count
  40. this.lab_des.getComponent(Label).string = '观看' + this.m_max_count + '次视频,获取' + time + '小时无限挑战机会'
  41. }
  42. private onLookVideo() {
  43. if(this.m_cur_count>=this.m_max_count) {
  44. this.finishLookVideo()
  45. return
  46. }
  47. GameManager.showVideoAd(config.ADS_TYPE.GAME_INFINITE_DEGREE_VIDEO, (res)=>{
  48. this.m_cur_count++
  49. this.lab_look_video.getComponent(Label).string = '看视频' + this.m_cur_count + '/' + this.m_max_count
  50. if(this.m_cur_count<this.m_max_count) {
  51. let free_ads_data = userDataManager.getUserFreeAdsData()
  52. free_ads_data.look_video_count = this.m_cur_count
  53. userDataManager.saveUserFreeAdsData()
  54. } else {
  55. this.finishLookVideo()
  56. }
  57. })
  58. }
  59. private finishLookVideo() {
  60. let cur_time = new Date().getTime()
  61. let free_ads_data = userDataManager.getUserFreeAdsData()
  62. free_ads_data.start_date_time = cur_time
  63. free_ads_data.look_video_count = 0
  64. free_ads_data.is_look_video_infinite_count_reward = true
  65. userDataManager.saveUserFreeAdsData()
  66. if(this.m_lookVideo_finish_cb) {
  67. this.m_lookVideo_finish_cb(this)
  68. }
  69. this.closeSelf()
  70. }
  71. closeSelf() {
  72. this.close()
  73. }
  74. private playBtnLookVideoAni() {
  75. this.btn_look_video.getComponent(Animation).play()
  76. }
  77. private stopBtnLookVideoAni() {
  78. this.btn_look_video.getComponent(Animation).stop()
  79. }
  80. }