/** @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 {IRole} from '../interface/GlobalInterface' import {LANGUAGE_TYPE} from '../enums/Enum' const {ccclass, property} = cc._decorator @ccclass @observer export class RoleExchangeUI extends BaseUI { upIndex: number = -1 iRole: IRole onShow(args: IRole, fromUI: number) { Mgr.net.add(msgCmd.cmd_embattle_battle_rsp, this, this.onUpRsp) this.upIndex = -1 this.iRole = args this.initTeam() } onOpenAniOver() { Mgr.global.tryShowUserGuide(['2_6', '2_7']) } onHide(): any { Mgr.event.removeAll(this) } initTeam() { //显示英雄 let roleNodes = ccUtils.instantChildren(cc.find('roles/item1', this.node), Data.user.maxFightRoleNum) for (let i = 0; i < Data.user.maxFightRoleNum; i++) { let node = roleNodes[i] let lockLevel = Data.user.roleSlotLv let role = cc.find('role', node) let iRole = Data.user.teamRole[i] role.active = iRole != null cc.find('select_1', node).active = false let isLock = Data.user.level < lockLevel[i] cc.find('lock_1', node).active = isLock cc.find('add_2', node).active = !isLock && !role.active if (role.active) { Mgr.global.initRoleItem(iRole, role, this) } node['isLock'] = isLock } } //网络事件======================================= onUpRsp() { this.hide() } //触发事件======================================= // @render // showRender() {} // 点击事件======================================= onClick(e) { if (e.target['isLock']) { Mgr.ui.tip(LANGUAGE_TYPE.slotLock) return } let chooseIndex = e.target.parent.children.indexOf(e.target) let sameNameIndex = Data.user.teamRole.findIndex( v => v && Math.floor(v.hero.id / 100) == Math.floor(this.iRole.hero.id / 100), ) if (sameNameIndex >= 0 && sameNameIndex != chooseIndex) { Mgr.ui.tip(LANGUAGE_TYPE.sameRoleOrCard) return } e.target.parent.children.forEach((node, index) => { cc.find('select_1', node).active = node == e.target if (e.target == node) { this.upIndex = index } }) } onSureClick() { if (this.upIndex >= 0) { Mgr.net.send(msgCmd.cmd_embattle_battle, { sid: this.iRole.hero.sid, pos: this.upIndex + 1, skill: false, }) } } }