/** @format */ import {UI} from '../enums/UI' import {BaseUI} from './BaseUI' import {Data, Mgr} from '../GameControl' import {ccUtils} from '../utils/ccUtils' import {observer, render, node, label, editBox, list} from '../mobx/observer' import {msgCmd} from '../proto/msg_cmd' import {DataConfig} from '../config/DataConfig' import {i18nLabel} from '../uiutils/i18nLabel' import {embattleBattleRsp, heroReset, heroResetRsp} from '../proto/game' import {hero} from '../proto/typedef' import {RoleQualityConfig} from '../config/RoleQualityConfig' import {RoleLevelConfig} from '../config/RoleLevelConfig' import {LANGUAGE_TYPE} from '../enums/Enum' import {IRewardNty} from '../interface/UIInterface' import {IRole} from '../interface/GlobalInterface' import {SOUND} from '../enums/Sound' const {ccclass, property} = cc._decorator @ccclass @observer export class RoleResetUI extends BaseUI { iRole: IRole toggleIndex: number = 0 onShow(args: IRole, fromUI: number) { Mgr.net.add(msgCmd.cmd_hero_reset_rsp, this, this.onResetRsp) this.iRole = args this.toggleIndex = 0 ccUtils.setTogglesChecked(this.toggleIndex, this.node, 'toggles') this.initUI() } onHide(): any { Mgr.event.removeAll(this) } initUI() { //显示英雄 let resetRoleNode = cc.find('scrollView/view/content/role', this.node) let goods = cc.find('scrollView/view/content/goods', this.node) Mgr.global.initRoleItem(this.iRole, cc.find('role', this.node), this) let isLvReset = this.toggleIndex == 1 ccUtils.setLabel(isLvReset ? 't48' : 't49', this.node, 'tip') let resetHero: hero = ccUtils.deepCopy(this.iRole.hero) resetHero.id = isLvReset ? this.iRole.hero.id : this.iRole.hero.id - this.iRole.grade resetHero.lv = 1 let resetRole = Mgr.global.buildIRole(resetHero) Mgr.global.initRoleItem(resetRole, resetRoleNode, this) cc.find('btn', this.node).active = (isLvReset && this.iRole.hero.lv > resetHero.lv) || (!isLvReset && this.iRole.grade > 0) //显示分解列表 let idNumArr = [] for (let i = 2; i <= this.iRole.hero.lv; i++) { idNumArr = idNumArr.concat(Mgr.goods.getIdNumArr(RoleLevelConfig[i].goods, RoleLevelConfig[i].goodNum)) } if (this.toggleIndex == 0) { for (let i = resetRole.cfg.quality + 1; i <= this.iRole.cfg.quality; i++) { idNumArr = idNumArr.concat( Mgr.goods.getIdNumArr([RoleQualityConfig[i].resetGoods], [RoleQualityConfig[i].anyQualityNum]), ) } } idNumArr = Mgr.goods.getGoodsList(idNumArr) let allNodes = ccUtils.instantChildren(goods, idNumArr.length + 1) Mgr.goods.initGoods(idNumArr, allNodes.slice(1), this) } //网络事件======================================= onResetRsp(data: heroResetRsp, reward: IRewardNty) { Mgr.ui.showReward(reward) this.hide() } //触发事件======================================= // @render // showRender() {} // 点击事件======================================= onToggleClick(e) { Mgr.audio.playSFX(SOUND.toggleClick) this.toggleIndex = e.target.parent.children.indexOf(e.target) this.initUI() } onSureClick() { if (Mgr.goods.roleIsUp(this.iRole)) { Mgr.ui.message(LANGUAGE_TYPE.heroIsUpReset, () => { this.sendResetReq() }) } else { this.sendResetReq() } } sendResetReq() { let data: heroReset = {level: this.toggleIndex == 1, sid: this.iRole.hero.sid} Mgr.net.send(msgCmd.cmd_hero_reset, data) } }