home_bottom_countdown.ts 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { _decorator, Component, Label, Node } from 'cc';
  2. import { userDataManager } from '../../manager/userDataManager';
  3. import { Util } from '../../util';
  4. const { ccclass, property } = _decorator;
  5. @ccclass('home_bottom_countdown')
  6. export class home_bottom_countdown extends Component {
  7. @property(Node) lab_countdown_time:Node = null
  8. private seconds:number = 0
  9. startTime(active_cb) {
  10. this.seconds = userDataManager.getUserFreeAdsSeconds()
  11. if(this.seconds<=0) {
  12. this.unscheduleAllCallbacks()
  13. this.node.active = false
  14. if(active_cb){ active_cb(false) }
  15. return
  16. }
  17. this.node.active = true
  18. if(active_cb){ active_cb(true) }
  19. this.lab_countdown_time.getComponent(Label).string = Util.formatTimeForSecond(this.seconds)
  20. this.unscheduleAllCallbacks()
  21. this.schedule(()=>{
  22. this.seconds --
  23. if(this.seconds<=0) {
  24. let c_free_ads_data = userDataManager.getUserFreeAdsData()
  25. c_free_ads_data.is_free = false
  26. c_free_ads_data.look_video_count = 0
  27. userDataManager.saveUserFreeAdsData()
  28. this.unscheduleAllCallbacks()
  29. this.node.active = false
  30. if(active_cb){ active_cb(false) }
  31. return
  32. }
  33. this.lab_countdown_time.getComponent(Label).string = Util.formatTimeForSecond(this.seconds)
  34. },1)
  35. // this.seconds = userDataManager.getUserFreeAdsTime()
  36. // console.log('seconds=',this.seconds)
  37. // if(this.seconds==-1) {
  38. // this.unscheduleAllCallbacks()
  39. // this.node.active = false
  40. // if(active_cb){ active_cb(false) }
  41. // return
  42. // }
  43. // this.node.active = true
  44. // if(active_cb){ active_cb(true) }
  45. // this.lab_countdown_time.getComponent(Label).string = Util.formatTimeForSecond(this.seconds)
  46. // this.unscheduleAllCallbacks()
  47. // this.schedule(()=>{
  48. // this.seconds --
  49. // if(this.seconds<=0) {
  50. // userDataManager.is_free_ads = false
  51. // userDataManager.saveUserFreeAdsLookVideoCount(0)
  52. // this.unscheduleAllCallbacks()
  53. // this.node.active = false
  54. // if(active_cb){ active_cb(false) }
  55. // return
  56. // }
  57. // this.lab_countdown_time.getComponent(Label).string = Util.formatTimeForSecond(this.seconds)
  58. // },1)
  59. }
  60. }