import { UIBase } from '../UIBase'; import { uimanger } from '../UIManger'; import { UIUpdateHero } from './UIUpdateHero'; import { UpdateChoose } from './updatechoose'; var gameConfig = require('gameConfig'); const NetManage = require('../../manages/NetManage'); const { ccclass, property } = cc._decorator; @ccclass export class ChooseHeroUpdate extends UIBase { public static prefabPath = 'prefabs/UIPrefab/pb_upgrade'; @property(cc.Label) currentLv: cc.Label = null; @property(cc.Label) nextlv: cc.Label = null; @property(cc.Label) costLabel: cc.Label = null; @property(cc.Label) timeLabel: cc.Label = null; @property(cc.Node) heroNode: cc.Node = null; @property(cc.Node) chooseNode: cc.Node = null; private hero_uuid = null; private boxIndex = 0; init(data: any) { this.boxIndex = data.boxIndex; } onLoad(): void { cc.Notifier.on('academyCHOOSE', this, this.hasGetOne.bind(this)); //reset this.currentLv.string = 'Lv.'; this.nextlv.string = 'Lv.'; this.costLabel.string = '0'; this.timeLabel.string = '00:00:00'; } onDestroy(): void { cc.Notifier.off('academyCHOOSE', this); } hasGetOne(data) { this.chooseNode.active = false; this.heroNode.getComponent('herochoseone').initdata(data.heroInfo); this.heroNode.active = true; this.hero_uuid = data.heroInfo.hero_uniid; this.currentLv.string = `Lv.${data.heroInfo.hero_lv}`; this.nextlv.string = `Lv.${parseInt(data.heroInfo.hero_lv) + 1}`; let cfg = gameConfig.heroLevel[`${parseInt(data.heroInfo.hero_lv) + 1}`]; this.costLabel.string = cfg.gold; this.timeLabel.string = cfg.time; } onClickChooseHero() { uimanger.showUI(UpdateChoose.prefabPath, {}); } onClose() { this.node.destroy(); } onComform() { if (this.hero_uuid) { NetManage.heroUpgradeLevel(this.hero_uuid, this.boxIndex, () => { var node = cc .find('Canvas') .getComponentInChildren(UIUpdateHero).node; node.emit('refreshUI'); this.node.destroy(); }); } else { cc.uiHelper.showTips('Must Choose a hero'); } } }