unLock_view.ts 3.2 KB

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