unLock_view.ts 3.1 KB

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