Files
fc/dev/project/assets/Scripts/nx/cmp/flex/nx.fx.cd.js
T
2026-05-23 22:10:14 +08:00

93 lines
2.3 KiB
JavaScript

// Learn cc.Class:
// - https://docs.cocos.com/creator/manual/en/scripting/class.html
// Learn Attribute:
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
cc.Class({
extends: cc.Component,
properties: {
endTxt:"", //倒計時結束提示
isPop:false //是否飘窗提示
},
// LIFE-CYCLE CALLBACKS:
editor: {
// 允许当前组件在编辑器模式下运行
executeInEditMode: false,
// requireComponent 参数用来指定当前组件的依赖组件
requireComponent: cc.Label,
// 当本组件添加到节点上后,禁止同类型(含子类)的组件再添加到同一个节点,防止逻辑发生冲突
disallowMultiple: true,
},
start () {
},
onEnable:function(){
},
onDisable:function(){
this.unscheduleAllCallbacks();
},
setSecs:function(_sec,_endCall){
if(!nx.dt.numPositive( _sec, false ) ) {
nx.warn("未知时间:",_sec);
this.stopAll();
return;
}
this.sec = _sec;
this._endCall = _endCall;
this.timeStart();
},
timeStart:function(){
this.unscheduleAllCallbacks();
if( nx.dt.numPositive( this.sec, false ) ) {
this.schedule( () => {
this.tick();
}, 1, cc.macro.REPEAT_FOREVER);
};
},
tick(){
this.sec--;
if(this.sec<=0){
if(this.isPop){
nx.tbox(this.endTxt);
}
nx.gui.setString( this, "", nx.text.getKey(this.endTxt) );
nx.dt.fnInvoke( this._endCall );
this.stopAll();
return;
}else{
//是否大于一天
let txt = this.sec;
if(this.sec/(24*3600) > 1){
txt = nx.bridge.time.toNeedSeconds(this.sec);
}else{
txt = nx.bridge.time.cdSeconds(this.sec);
}
nx.gui.setString( this, "", txt);
}
},
stopAll:function(){
this.unscheduleAllCallbacks();
this.string = "";
},
// update (dt) {},
});