unLock_view.ts 2.5 KB

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