86 lines
2.2 KiB
JavaScript
86 lines
2.2 KiB
JavaScript
"use strict";
|
|
cc._RF.push(module, '2834aarzJBH65GgtSvu+U/A', 'nx.fx.cd');
|
|
// Scripts/nx/cmp/flex/nx.fx.cd.js
|
|
|
|
"use strict";
|
|
|
|
// 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: function start() {},
|
|
onEnable: function onEnable() {},
|
|
onDisable: function onDisable() {
|
|
this.unscheduleAllCallbacks();
|
|
},
|
|
setSecs: function setSecs(_sec, _endCall) {
|
|
if (!nx.dt.numPositive(_sec, false)) {
|
|
nx.warn("未知时间:", _sec);
|
|
this.stopAll();
|
|
return;
|
|
}
|
|
this.sec = _sec;
|
|
this._endCall = _endCall;
|
|
this.timeStart();
|
|
},
|
|
timeStart: function timeStart() {
|
|
var _this = this;
|
|
this.unscheduleAllCallbacks();
|
|
if (nx.dt.numPositive(this.sec, false)) {
|
|
this.schedule(function () {
|
|
_this.tick();
|
|
}, 1, cc.macro.REPEAT_FOREVER);
|
|
}
|
|
;
|
|
},
|
|
tick: function 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 {
|
|
//是否大于一天
|
|
var 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 stopAll() {
|
|
this.unscheduleAllCallbacks();
|
|
this.string = "";
|
|
}
|
|
|
|
// update (dt) {},
|
|
});
|
|
|
|
cc._RF.pop(); |