98 lines
2.3 KiB
JavaScript
98 lines
2.3 KiB
JavaScript
const NetManage = require('../../manages/NetManage');
|
|
|
|
cc.Class({
|
|
extends: cc.Component,
|
|
|
|
properties: {
|
|
title: {
|
|
default: null,
|
|
type: cc.Label,
|
|
},
|
|
btn_label: {
|
|
default: null,
|
|
type: cc.Label,
|
|
},
|
|
missionPrefab: {
|
|
default: null,
|
|
type: cc.Prefab,
|
|
},
|
|
lb_time: {
|
|
default: null,
|
|
type: cc.Label,
|
|
},
|
|
},
|
|
|
|
onClickBtn() {
|
|
if (this.missionState == 0) {
|
|
NetManage.commitMission(this.missionId, () => {
|
|
cc.uiHelper.showTips('Get Reward Success!');
|
|
});
|
|
this.node.destroy();
|
|
}
|
|
if (this.missionState == 1) {
|
|
const node = cc.instantiate(this.missionPrefab);
|
|
node.getComponent('mission_choose').initData(this.wantedData);
|
|
cc.find('Canvas').addChild(node);
|
|
}
|
|
if (this.missionState == 2) {
|
|
|
|
NetManage.boostOfferRewardMission(this.missionId, () => {
|
|
this.node.destroy();
|
|
cc.uiHelper.showTips('Boost Success!');
|
|
});
|
|
}
|
|
},
|
|
|
|
formatSeconds(value) {
|
|
let result = parseInt(value);
|
|
let h =
|
|
Math.floor(result / 3600) < 10
|
|
? '0' + Math.floor(result / 3600)
|
|
: Math.floor(result / 3600);
|
|
let m =
|
|
Math.floor((result / 60) % 60) < 10
|
|
? '0' + Math.floor((result / 60) % 60)
|
|
: Math.floor((result / 60) % 60);
|
|
let s =
|
|
Math.floor(result % 60) < 10
|
|
? '0' + Math.floor(result % 60)
|
|
: Math.floor(result % 60);
|
|
|
|
let res = '';
|
|
if (h !== '00') res += `${h}:`;
|
|
if (m !== '00') res += `${m}:`;
|
|
res += `${s}`;
|
|
return res;
|
|
},
|
|
|
|
init(data, originData) {
|
|
this.wantedData = data;
|
|
this.missionId = originData.mission_id;
|
|
if (originData.state == 0) {
|
|
this.btn_label.string = 'GET';
|
|
this.missionState = 0;
|
|
}
|
|
if (originData.state == 2) {
|
|
if (originData.objects.length == 0) {
|
|
this.btn_label.string = 'RECEIVE';
|
|
this.missionState = 1;
|
|
} else {
|
|
var leftTime = originData.lefttime;
|
|
this.lb_time.node.active = true;
|
|
this.btn_label.string = 'BOOST';
|
|
this.missionState = 2;
|
|
this.lb_time.string = this.formatSeconds(leftTime);
|
|
this.schedule(function () {
|
|
this.lb_time.string = this.formatSeconds((leftTime -= 1));
|
|
if (leftTime <= 0) {
|
|
cc.Notifier.emit('FinishOne');
|
|
}
|
|
}, 1);
|
|
}
|
|
}
|
|
if (originData.state == 1) {
|
|
this.node.destroy();
|
|
}
|
|
},
|
|
});
|