123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- /** @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('levelGuide')
- levelGuide: cc.Node
- lastPower: number
- 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.initRole()
- Mgr.event.add(EVENT.goodsChangeSync, this, this.initRole)
- Mgr.ui.show(UI.CurrencyUI, [GOODS.coin, GOODS.diamond])
- if (this.levelNeed.canUp && this.iRole.hero.lv == 1) {
- // 打完第一关 升级角色
- this.levelGuide.active = Mgr.global.tryShowUserGuide(['2_3'])
- }
- }
- onHide(): any {
- Mgr.event.removeAll(this)
- }
- initRole() {
- let iRole = this.iRole
- this.lastPower = iRole.power
- //初始技能
- let showSkillCfg = RoleShowSkillConfig[RoleConfig[iRole.hero.id].showSkillID[0]]
- ccUtils.setLabel(showSkillCfg.name, this.node, 'skillName')
- ccUtils.setRichLabel(showSkillCfg.tip, this.node, 'skill_rt')
- if (showSkillCfg.attrNum.length > 0) {
- let i18nLb = cc.find('skill_rt', this.node).getComponent(i18nLabel)
- i18nLb.init(
- showSkillCfg.tip,
- showSkillCfg.attrNum.map(v => v.toString()),
- )
- }
- let skillItem = cc.find('skill_item', this.node)
- this.loadTexImg(`RoleUI/skillIcon/${showSkillCfg.icon}`, skillItem, 'icon')
- this.loadTexImg(`Public/goodsQuality/item_frame${showSkillCfg.qualityType}`, skillItem, 'item_frame')
- //属性值
- let attack = iRole.cfg.profession == PROFESSION.mage ? iRole.spellAttack : iRole.attack
- let attackIcon = iRole.cfg.profession == PROFESSION.mage ? ATTR_NAME.spellAttack : ATTR_NAME.attack
- this.loadTexImg(`Public/allAttr/${attackIcon}`, this.node, 'attackIcon')
- ccUtils.setLabel(Math.toKMBNum(attack), this.node, 'attack')
- ccUtils.setLabel(Math.toKMBNum(iRole.HP), this.node, 'hp_lb')
- ccUtils.setLabel(Math.toKMBNum(iRole.power), this.node, 'power')
- //英雄
- let roleNode = cc.find('role', this.node)
- ccUtils.setLabel(iRole.cfg.name, roleNode, 'roleName')
- ccUtils.setLabel(LANGUAGE_TYPE[PROFESSION[iRole.cfg.profession]], roleNode, 'prof_name')
- let roleQualityConfig = RoleQualityConfig[iRole.cfg.quality]
- ccUtils.setLabel(`lv.${iRole.hero.lv}/${roleQualityConfig.maxLv}`, roleNode, 'lv')
- this.loadTexImg(`Public/role/streamer_${iRole.cfg.qualityType}`, roleNode, 'streamer')
- this.loadTexImg(`Public/role/role_type_${iRole.cfg.profession}`, roleNode, 'role_type')
- this.loadTexImg(`Public/role/base_light_${iRole.cfg.qualityType}`, roleNode, 'base_light')
- this.loadTexImg(`Public/role/base_level_${iRole.cfg.qualityType}`, roleNode, 'base_level')
- Mgr.global.initRoleSpine(iRole, roleNode, 'spine')
- ccUtils.instantChildren(cc.find('stars/star', roleNode), iRole.grade)
- ccUtils.setLabel(iRole.cfg.cost.toString(), roleNode, 'cost/lb')
- //需要资源
- 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('attrList/view/content/item', this.node)
- 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('icon/lock_1', attrItem).active = tip.cfg.quality > iRole.cfg.quality
- this.loadTexImg(`Public/goodsQuality/item_frame${tip.cfg.qualityType}`, attrItem, 'icon/item_frame')
- let richTextNode = cc.find('richText', attrItem)
- ccUtils.setRichLabel(tip.tip, richTextNode)
- this.scheduleOnce(() => {
- if (attrItem.activeInHierarchy) {
- if (tip.cfg.quality > iRole.cfg.quality) ccUtils.setRichLabelGray(richTextNode)
- let layout = attrItem.getComponent(cc.Layout)
- layout.resizeMode =
- richTextNode.height < 65 ? cc.Layout.ResizeMode.NONE : cc.Layout.ResizeMode.CONTAINER
- layout.updateLayout()
- if (richTextNode.height < 65) {
- attrItem.height = 65
- }
- }
- })
- }
- 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_go_altar', this.node).active = 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.findIndex(iRole => iRole && iRole.hero.sid == role.hero.sid) < 0
- }
- 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.ui.show(UI.RoleExchangeUI, this.iRole)
- }
- onLeftClick() {
- this.changeRole(true)
- }
- onRightClick() {
- this.changeRole(false)
- }
- }
|