12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- import { _decorator, Component, Label, Node, Animation } from 'cc';
- import { base_ui } from '../fw/base_ui';
- import { userDataManager } from '../manager/userDataManager';
- import { tools } from '../tools';
- import { SdkUtil } from '../sdkUtil';
- import { config } from '../config';
- const { ccclass, property } = _decorator;
- @ccclass('unLock_view')
- export class unLock_view extends base_ui {
- @property(Node) btn_close:Node = null
- @property(Node) btn_look_video:Node = null
- @property(Node) lab_look_video:Node = null
- @property(Node) lab_des:Node = null
- private m_cur_count:number = 0
- private m_max_count:number = 3
- private m_lookVideo_finish_cb = null
- start() {
- this.onButtonListen(this.btn_close, ()=>{
- this.stopBtnLookVideoAni()
- this.closeSelf()
- })
- this.onButtonListen(this.btn_look_video, this.onLookVideo.bind(this))
- this.playBtnLookVideoAni()
- }
- initView(lookVideo_finish_cb) {
- this.m_lookVideo_finish_cb = lookVideo_finish_cb
- this.m_cur_count = userDataManager.getUserFreeAdsData().look_video_count
- let sys_config = tools.sys_config
- this.m_max_count = sys_config.free_ads_number
- let time = 0
- if(sys_config.free_game_time >0) {
- time = sys_config.free_game_time / 3600
- }
- if(time<1) {
- time = parseFloat(time.toFixed(1))
- }
- // console.log('time=',time)
- this.lab_look_video.getComponent(Label).string = '看视频' + this.m_cur_count + '/' + this.m_max_count
- this.lab_des.getComponent(Label).string = '观看' + this.m_max_count + '次视频,获取' + time + '小时无限挑战机会'
- }
- private onLookVideo() {
- if(this.m_cur_count>=this.m_max_count) {
- return
- }
- let ad_id = SdkUtil.getAdId(config.ADS_TYPE.GAME_INFINITE_DEGREE_VIDEO)
- SdkUtil.showVideoAd(ad_id,(res)=>{
- if(res.isEnded){
- this.m_cur_count++
- this.lab_look_video.getComponent(Label).string = '看视频' + this.m_cur_count + '/' + this.m_max_count
- let free_ads_data = userDataManager.getUserFreeAdsData()
- if(this.m_cur_count<this.m_max_count) {
- free_ads_data.look_video_count = this.m_cur_count
- userDataManager.saveUserFreeAdsData()
- } else {
- let cur_time = new Date().getTime()
- free_ads_data.start_date_time = cur_time
- free_ads_data.look_video_count = 0
- free_ads_data.is_look_video_infinite_count_reward = true
- userDataManager.saveUserFreeAdsData()
- if(this.m_lookVideo_finish_cb) {
- this.m_lookVideo_finish_cb(this)
- }
- this.closeSelf()
- }
- }
- })
-
- }
- closeSelf() {
- this.close()
- }
- private playBtnLookVideoAni() {
- this.btn_look_video.getComponent(Animation).play()
- }
- private stopBtnLookVideoAni() {
- this.btn_look_video.getComponent(Animation).stop()
- }
- }
|