import { heroUpgradeQuality, upgradeQualityPreview } from '../../TsJsBridge'; import { QualityStar } from '../QualityStar'; import { UIBase } from '../UIBase'; import { uimanger } from '../UIManger'; import { UIUpdateHero } from './UIUpdateHero'; import { UpdateChoose } from './updatechoose'; var gameConfig = require('gameConfig'); const { ccclass, property } = cc._decorator; @ccclass export class ChooseHeroUpQuality extends UIBase { public static prefabPath: string = 'prefabs/UIPrefab/pb_advenced'; @property(cc.Node) mainHeroChoose: cc.Node = null; @property(cc.Node) secHeroChoose: cc.Node = null; @property(cc.Node) mainHero: cc.Node = null; @property(cc.Node) secHero: cc.Node = null; @property(cc.Node) finalHero: cc.Node = null; @property(cc.Label) costLabel: cc.Label = null; @property(cc.Label) timeLabel: cc.Label = null; @property(cc.Label) rateLabel: cc.Label = null; @property(QualityStar) beforeStar: QualityStar = null; @property(QualityStar) afterStar: QualityStar = null; @property(cc.Label) oldHp: cc.Label = null; @property(cc.Label) oldAtk: cc.Label = null; @property(cc.Label) oldDef: cc.Label = null; @property(cc.Label) newHp: cc.Label = null; @property(cc.Label) newAtk: cc.Label = null; @property(cc.Label) newDef: cc.Label = null; private mainHeroData: any; private secHeroData: any; private boxIndex = 0; // private mainHeroID = 0; // private secHeroID = 0; init(data: any) { this.boxIndex = data.boxIndex; } onLoad(): void { this.oldAtk.string = '0'; this.oldDef.string = '0'; this.oldHp.string = '0'; this.newAtk.string = '0'; this.newDef.string = '0'; this.newHp.string = '0'; cc.Notifier.on('academyCHOOSE', this, this.hasGetOne.bind(this)); } hasGetOne(data) { if (data.index == 0) { this.mainHeroChoose.active = false; this.mainHero.getComponent('herochoseone').initdata(data.heroInfo); this.finalHero.getComponent('herochoseone').initdata(data.heroInfo); this.mainHero.active = true; this.mainHeroData = data.heroInfo.hero_uniid; // this.mainHeroID = data.heroInfo.hero_id; let cfg = gameConfig.heroQuality[ `${parseInt(data.heroInfo.quality) + 1}` ]; this.costLabel.string = cfg.gold; this.timeLabel.string = cfg.time; this.rateLabel.string = cfg.success_rate + '%'; window.qualityMainData = { heroid: data.heroInfo.hero_id, herouuid: data.heroInfo.hero_uniid, }; } else if (data.index == 1) { this.secHeroChoose.active = false; this.secHero.getComponent('herochoseone').initdata(data.heroInfo); this.secHero.active = true; this.secHeroData = data.heroInfo.hero_uniid; // this.secHeroID = data.heroInfo.hero_id; window.qualitySecData = { heroid: data.heroInfo.hero_id, herouuid: data.heroInfo.hero_uniid, }; } if (this.mainHeroData && this.secHeroData) { if (this.mainHeroData == this.secHeroData) { cc.uiHelper.showTips('Must Choose two hero'); return; } // if (this.mainHeroID != this.secHeroID) { // cc.uiHelper.showTips('Must Choose same hero'); // return; // } // NetManage.upgradeQualityPreview( // this.mainHeroData, // this.secHeroData, // (res) => { // this.oldHp.string = res.old_hero.hp; // this.oldAtk.string = res.old_hero.atk; // this.oldDef.string = res.old_hero.def; // this.newHp.string = res.new_hero.hp; // this.newAtk.string = res.new_hero.atk; // this.newDef.string = res.new_hero.def; // this.beforeStar.initStar(res.old_hero.quality); // this.afterStar.initStar(res.new_hero.quality); // } // ); upgradeQualityPreview( this.mainHeroData, this.secHeroData, (res) => { this.oldHp.string = res.old_hero.hp; this.oldAtk.string = res.old_hero.atk; this.oldDef.string = res.old_hero.def; this.newHp.string = res.new_hero.hp; this.newAtk.string = res.new_hero.atk; this.newDef.string = res.new_hero.def; this.beforeStar.initStar(res.old_hero.quality); this.afterStar.initStar(res.new_hero.quality); } ); } } onDestroy(): void { cc.Notifier.off('academyCHOOSE', this); } onChooseHero(event, param) { var data = { index: param, }; uimanger.showUI(UpdateChoose.prefabPath, data); } onClose() { window.qualityMainData = null; window.qualitySecData = null; this.node.destroy(); } onOk() { if (this.mainHeroData && this.secHeroData) { if (this.mainHeroData == this.secHeroData) { cc.uiHelper.showTips('Must Choose two hero'); return; } // if (this.mainHeroID != this.secHeroID) { // cc.uiHelper.showTips('Must Choose same hero'); // return; // } // NetManage.heroUpgradeQuality( // this.mainHeroData, // this.secHeroData, // this.boxIndex, // () => { // var node = cc // .find('Canvas') // .getComponentInChildren(UIUpdateHero).node; // node.emit('refreshUI'); // window.qualityMainData = null; // window.qualitySecData = null; // this.node.destroy(); // } // ); heroUpgradeQuality( this.mainHeroData, this.secHeroData, this.boxIndex, () => { var node = cc .find('Canvas') .getComponentInChildren(UIUpdateHero).node; node.emit('refreshUI'); window.qualityMainData = null; window.qualitySecData = null; this.node.destroy(); } ); } else { cc.uiHelper.showTips('Must Choose two hero'); } } }