home_bottom_countdown.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. }
  36. }