unLock_view.ts 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. return
  45. }
  46. GameManager.showVideoAd(config.ADS_TYPE.GAME_INFINITE_DEGREE_VIDEO, (res)=>{
  47. this.m_cur_count++
  48. this.lab_look_video.getComponent(Label).string = '看视频' + this.m_cur_count + '/' + this.m_max_count
  49. let free_ads_data = userDataManager.getUserFreeAdsData()
  50. if(this.m_cur_count<this.m_max_count) {
  51. free_ads_data.look_video_count = this.m_cur_count
  52. userDataManager.saveUserFreeAdsData()
  53. } else {
  54. let cur_time = new Date().getTime()
  55. free_ads_data.start_date_time = cur_time
  56. free_ads_data.look_video_count = 0
  57. free_ads_data.is_look_video_infinite_count_reward = true
  58. userDataManager.saveUserFreeAdsData()
  59. if(this.m_lookVideo_finish_cb) {
  60. this.m_lookVideo_finish_cb(this)
  61. }
  62. this.closeSelf()
  63. }
  64. })
  65. }
  66. closeSelf() {
  67. this.close()
  68. }
  69. private playBtnLookVideoAni() {
  70. this.btn_look_video.getComponent(Animation).play()
  71. }
  72. private stopBtnLookVideoAni() {
  73. this.btn_look_video.getComponent(Animation).stop()
  74. }
  75. }