/** @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 {RoleShowSkillConfig} from '../config/RoleShowSkillConfig' import {IRoleConfig, RoleConfig} from '../config/RoleConfig' import {ATTR_NAME, EVENT, GOODS, LANGUAGE_TYPE, PROFESSION, QUALITY_COLOR, QUALITY_TYPE} from '../enums/Enum' import {IRoleLevelConfig, RoleLevelConfig} from '../config/RoleLevelConfig' import {heroUpgrade, heroUpgradeRsp} from '../proto/game' import {RoleQualityConfig} from '../config/RoleQualityConfig' import {i18nLabel} from '../uiutils/i18nLabel' import {IOperateNeed, IRole} from '../interface/GlobalInterface' import {GlobalManager} from '../mgrs/GlobalManager' import {SOUND} from '../enums/Sound' const {ccclass, property} = cc._decorator @ccclass @observer export class RoleUI extends BaseUI { iRole: IRole levelNeed: IOperateNeed @node('toggles') toggles: cc.Node @node('info') infoNode: cc.Node @node('skills') skillNode: cc.Node @node('levelGuide') levelGuide: cc.Node lastPower: number toggleIndex = 0 onShow(args: IRole, fromUI: number) { Mgr.net.add(msgCmd.cmd_hero_upgrade_rsp, this, this.onUpdateRsp) Mgr.net.add(msgCmd.cmd_hero_reset_rsp, this, this.initRole) Mgr.net.add(msgCmd.cmd_embattle_battle_rsp, this, this.onUpRsp) this.iRole = args this.initToggles() this.initRole() Mgr.event.add(EVENT.goodsChangeSync, this, this.initRole) if (this.levelNeed.canUp && this.iRole.hero.lv == 1) { // 打完第一关 升级角色 this.levelGuide.active = Mgr.global.tryShowUserGuide(['2_3']) } } onHide(): any { Mgr.event.removeAll(this) } initToggles() { ccUtils.setTogglesChecked(this.toggleIndex, this.toggles) this.infoNode.active = this.toggleIndex == 0 this.skillNode.active = this.toggleIndex == 1 } initRole() { let iRole = this.iRole this.lastPower = iRole.power //属性值 let isSpell = iRole.spellAttack > iRole.attack let attrs = cc.find('attr', this.infoNode).children for (let i = 0; i < attrs.length; i++) { let attr = attrs[i] ccUtils.setLabel(attr.name == ATTR_NAME.attackRange ? iRole.cfg.attackRange : iRole[attr.name], attr, 'num') if (attr.name == ATTR_NAME.attack) attr.active = !isSpell if (attr.name == ATTR_NAME.spellAttack) attr.active = isSpell } //英雄 let roleNode = cc.find('role', this.node) ccUtils.setLabel(iRole.cfg.name, roleNode, 'roleName') ccUtils.setLabel(`lv.${iRole.hero.lv}`, roleNode, 'lv') this.loadTexImg(`Public/role/icon_type_${iRole.cfg.profession}`, roleNode, 'role_type') this.loadTexImg(`Public/role/role_base_${iRole.cfg.profession}`, roleNode, 'role_base') this.loadTexImg(`Public/role/quality_icon_${iRole.cfg.quality}`, roleNode, 'quality_icon') let nextRoleConfig = RoleConfig[iRole.cfg.ID + 1] ccUtils.setLabel(nextRoleConfig ? `${iRole.hero.num}/${nextRoleConfig.consume}` : 'MAX', roleNode, 'numPb/num') ccUtils.setProgress(nextRoleConfig ? iRole.hero.num / nextRoleConfig.consume : 1, roleNode, 'numPb/pb') Mgr.global.initRoleSpine(iRole, roleNode, 'spine') //需要资源 this.levelNeed = Mgr.goods.checkRoleLevelUpNeed(iRole) cc.find('needLy', this.node).active = !this.levelNeed.isMax if (!this.levelNeed.isMax) { let needItems = ccUtils.instantChildren(cc.find('needLy/item', this.node), this.levelNeed.need.length) Mgr.goods.initNeedGoods(this.levelNeed.need, needItems, this) } //词条 let attrItemOrigin = cc.find('entry/attrList/view/content/item', this.infoNode) let tips: {tip: string; cfg: IRoleConfig}[] = [] for (let i = 1; i < Data.main.maxRoleQuality; i++) { let ID = Math.floor(iRole.cfg.ID / 100) * 100 + i if (RoleConfig[ID.toString()]?.tips) tips.push({ tip: RoleConfig[ID.toString()].tips, cfg: RoleConfig[ID.toString()], }) } let attrItems = ccUtils.instantChildren(attrItemOrigin, tips.length) for (let i = 0; i < tips.length; i++) { let attrItem = attrItems[i] let tip = tips[i] cc.find('lock_1', attrItem).active = tip.cfg.quality > iRole.cfg.quality this.loadTexImg(`Public/role/quality_icon_${tip.cfg.quality}`, attrItem, 'quality_icon') ccUtils.setColor(QUALITY_COLOR[tip.cfg.quality], attrItem, 'block_2') let richTextNode = cc.find('richText', attrItem) ccUtils.setRichLabel(tip.tip, richTextNode) richTextNode.active = tip.cfg.quality <= iRole.cfg.quality let blackLb = cc.find('blackLb', attrItem) ccUtils.setLabel(tip.tip, blackLb) blackLb.active = tip.cfg.quality > iRole.cfg.quality cc.find('btn_promote', attrItem).active = iRole.cfg.quality + 1 == tip.cfg.quality && Mgr.goods.checkRoleBreakNeed(iRole).canUp cc.tween(cc.find('btn_promote/arrow_1', attrItem)) .then(cc.tween().to(0.5, {y: 8}).to(0.5, {y: 18})) .repeatForever() .start() } //技能 let skillIDs = RoleConfig[iRole.hero.id].showSkillID let showSkillCfgArr = skillIDs.map(v => RoleShowSkillConfig[v]) let skillNodes = cc.find('skills', this.skillNode).children for (let i = 0; i < showSkillCfgArr.length; i++) { let showSkillCfg = showSkillCfgArr[i] let skillItem = skillNodes[i] ccUtils.setLabel(showSkillCfg.name, skillItem, 'skillName') ccUtils.setRichLabel(showSkillCfg.tip, skillItem, 'skill_rt') if (showSkillCfg.attrNum.length > 0) { let i18nLb = cc.find('skill_rt', skillItem).getComponent(i18nLabel) i18nLb.init( showSkillCfg.tip, showSkillCfg.attrNum.map(v => v.toString()), ) } this.loadTexImg(`RoleUI/skillIcon/${showSkillCfg.icon}`, skillItem, 'icon') } //cc.find('btn_auto_upgrade', this.node).active = !this.levelNeed.isMax && !iRole.isAlter cc.find('btn_upgrade', this.node).active = !this.levelNeed.isMax && !iRole.isAlter cc.find('btn_join', this.node).active = this.roleCanUp(this.iRole) // cc.find('button_reset', this.node).active = // this.iRole.hero.lv > 1 || (this.iRole.grade > 0 && this.iRole.cfg.qualityType >= QUALITY_TYPE.elite) if (this.levelNeed.canUp && this.iRole.hero.lv == 2 && !Mgr.goods.roleIsUp(this.iRole)) { // 打完第一关 升级角色 Mgr.global.tryShowUserGuide(['2_4', '2_5']) } if (this.iRole.hero.lv == 3 && !Mgr.goods.roleIsUp(this.iRole)) { // 打完第一关 上阵角色 Mgr.global.tryShowUserGuide(['2_5']) } //this.showChangeArrow() } roleCanUp(role: IRole): boolean { return !Data.user.teamRole[role.cfg.profession - 1] } changeRole(isLeft: boolean) { let curIndex = Data.user.teamRole.indexOf(this.iRole) //根据isLeft找到当前位置往左第一个非空的对象或者当前位置往右第一个非空的对象 let roleArr = isLeft ? Data.user.teamRole.slice(0, curIndex) : Data.user.teamRole.slice(curIndex + 1) roleArr = roleArr.filter(iRole => iRole) if (roleArr.length > 0) { this.iRole = isLeft ? roleArr[roleArr.length - 1] : roleArr[0] this.initRole() } } showChangeArrow() { let curIndex = Data.user.teamRole.indexOf(this.iRole) //根据isLeft找到当前位置往左第一个非空的对象或者当前位置往右第一个非空的对象 let leftArr = Data.user.teamRole.slice(0, curIndex).filter(iRole => iRole) let rightArr = Data.user.teamRole.slice(curIndex + 1).filter(iRole => iRole) cc.find('arrow_left', this.node).active = leftArr.length > 0 && Mgr.goods.roleIsUp(this.iRole) cc.find('arrow_right', this.node).active = rightArr.length > 0 && Mgr.goods.roleIsUp(this.iRole) } //网络事件======================================= onUpdateRsp() { Mgr.audio.playSFX(SOUND.goodsUp) Mgr.ui.show(UI.PowerUpUI, `+${this.iRole.power - this.lastPower}`) this.initRole() ccUtils.playAni('lvup', 0, this.node, 'lvupAni') } onUpRsp() { cc.find('btn_join', this.node).active = this.roleCanUp(this.iRole) } //触发事件======================================= // 点击事件======================================= onLevelClick(e, isOneClick: string) { if (this.levelNeed) { if (this.levelNeed.isMax) { Mgr.ui.tip(LANGUAGE_TYPE.maxLevel) } else if (this.levelNeed.canUp) { let num = isOneClick == '1' ? 0 : 1 let data: heroUpgrade = { num, sid: this.iRole.hero.sid, } Mgr.net.send(msgCmd.cmd_hero_upgrade, data) } else { Mgr.ui.showObtain(this.levelNeed) } } } onResetClick() { this.iRole.isAlter ? Mgr.ui.tip(LANGUAGE_TYPE.notReset) : Mgr.ui.show(UI.RoleResetUI, this.iRole) } onUpClick() { Mgr.net.send(msgCmd.cmd_embattle_battle, { sid: this.iRole.hero.sid, pos: this.iRole.cfg.profession, skill: false, }) } onLeftClick() { this.changeRole(true) } onRightClick() { this.changeRole(false) } onToggleClick(e) { this.toggleIndex = e.target.parent.children.indexOf(e.target) this.initToggles() } }