160 lines
4.0 KiB
TypeScript
160 lines
4.0 KiB
TypeScript
const NetManage = require('../../manages/NetManage');
|
|
import { UpSuccess } from '../../tips/UpSuccess';
|
|
import { uimanger } from '../UIManger';
|
|
import { ChooseHeroUpdate } from './ChooseHeroUpdate';
|
|
import { ChooseHeroUpQuality } from './ChooseHeroUpQuality';
|
|
import { UIUpdateHero } from './UIUpdateHero';
|
|
|
|
const { ccclass, property } = cc._decorator;
|
|
|
|
export enum TRAINBLOCKSTATUS {
|
|
NULL = 'null',
|
|
// LOCKED = 'locked',
|
|
FREE = 'free',
|
|
TRAINING = 'training',
|
|
COMPLETE = 'complete',
|
|
}
|
|
|
|
export enum BoxType {
|
|
UpLevel,
|
|
UpQuality,
|
|
}
|
|
|
|
@ccclass
|
|
export default class Academy_block extends cc.Component {
|
|
@property(cc.Node) bg: cc.Node = null;
|
|
@property(cc.Node) addsign: cc.Node = null;
|
|
@property(cc.Label) title: cc.Label = null;
|
|
@property(cc.Label) timeLabel: cc.Label = null;
|
|
@property(cc.Node) okTag: cc.Node = null;
|
|
@property([cc.SpriteFrame]) allbgs: cc.SpriteFrame[] = []; // 0 null 1 finish 2 training
|
|
@property({ type: cc.Enum(BoxType) }) boxtype: BoxType = BoxType.UpLevel;
|
|
|
|
public status = TRAINBLOCKSTATUS.FREE;
|
|
private currentData: any;
|
|
private leftTime = 0;
|
|
|
|
onLoad() {
|
|
this.setStatus(this.status);
|
|
}
|
|
|
|
init(data) {
|
|
this.currentData = data;
|
|
if (data == null) {
|
|
this.status = TRAINBLOCKSTATUS.FREE;
|
|
} else {
|
|
if (data.countdown == 0) {
|
|
this.status = TRAINBLOCKSTATUS.COMPLETE;
|
|
} else {
|
|
this.status = TRAINBLOCKSTATUS.TRAINING;
|
|
}
|
|
this.leftTime = this.currentData.countdown;
|
|
}
|
|
this.setStatus(this.status);
|
|
}
|
|
|
|
setStatus(status: TRAINBLOCKSTATUS) {
|
|
switch (status) {
|
|
case TRAINBLOCKSTATUS.FREE:
|
|
this.bg.getComponent(cc.Sprite).spriteFrame = this.allbgs[0];
|
|
this.addsign.active = true;
|
|
this.title.string = 'FREE';
|
|
this.timeLabel.node.active = false;
|
|
this.okTag.active = false;
|
|
break;
|
|
case TRAINBLOCKSTATUS.TRAINING:
|
|
this.bg.getComponent(cc.Sprite).spriteFrame = this.allbgs[2];
|
|
this.addsign.active = false;
|
|
this.title.string = 'TRAINING';
|
|
this.timeLabel.node.active = true;
|
|
this.unscheduleAllCallbacks();
|
|
this.schedule(function () {
|
|
if (this.leftTime >= 1) {
|
|
this.timeLabel.string = this.formatSeconds(
|
|
this.leftTime
|
|
);
|
|
this.leftTime -= 1;
|
|
} else {
|
|
var node = cc
|
|
.find('Canvas')
|
|
.getComponentInChildren(UIUpdateHero).node;
|
|
node.emit('refreshUI');
|
|
}
|
|
}, 1);
|
|
|
|
this.okTag.active = false;
|
|
break;
|
|
case TRAINBLOCKSTATUS.COMPLETE:
|
|
this.bg.getComponent(cc.Sprite).spriteFrame = this.allbgs[1];
|
|
this.addsign.active = false;
|
|
this.title.string = 'FINISH';
|
|
this.timeLabel.string = '00:00:00';
|
|
this.okTag.active = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
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 = '';
|
|
res += `${h}:`;
|
|
res += `${m}:`;
|
|
res += `${s}`;
|
|
return res;
|
|
}
|
|
|
|
onClick(event, param) {
|
|
var data = {
|
|
boxIndex: param,
|
|
};
|
|
switch (this.status) {
|
|
case TRAINBLOCKSTATUS.FREE:
|
|
if (this.boxtype == BoxType.UpLevel) {
|
|
uimanger.showUI(ChooseHeroUpdate.prefabPath, data);
|
|
} else {
|
|
uimanger.showUI(ChooseHeroUpQuality.prefabPath, data);
|
|
}
|
|
break;
|
|
case TRAINBLOCKSTATUS.TRAINING:
|
|
break;
|
|
case TRAINBLOCKSTATUS.COMPLETE:
|
|
break;
|
|
}
|
|
}
|
|
|
|
onRecive() {
|
|
var type = 0;
|
|
if (this.boxtype == BoxType.UpLevel) {
|
|
type = 1;
|
|
} else {
|
|
type = 2;
|
|
}
|
|
|
|
NetManage.reciveUpReward(
|
|
type,
|
|
this.currentData.info.hero_uniid,
|
|
(res) => {
|
|
uimanger.showUI(UpSuccess.prefabPath, res);
|
|
var node = cc
|
|
.find('Canvas')
|
|
.getComponentInChildren(UIUpdateHero).node;
|
|
node.emit('refreshUI');
|
|
// cc.Notifier.emit('refreshUI');
|
|
}
|
|
);
|
|
}
|
|
}
|