/** @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 List, {SelectedType} from '../uiutils/List' import {ATTR_NAME, EQUIPMENT, LANGUAGE_TYPE, PROFESSION, QUALITY_COLOR, QUALITY_TYPE} from '../enums/Enum' import {i18nLabel} from '../uiutils/i18nLabel' import UserButton from '../uiutils/UserButton' import {equipOnekeyUpgradeStarRsp, equipUpgradeStar, equipUpgradeStarRsp, heroUpgradeStar} from '../proto/game' import {idNum} from '../proto/typedef' import {qualityGoods} from './RoleBreakUI' import {EquipmentQualityConfig, IEquipmentQualityConfig} from '../config/EquipmentQualityConfig' import {EntryConfig} from '../config/EntryConfig' import {RoleQualityConfig} from '../config/RoleQualityConfig' import {IRewardNty} from '../interface/UIInterface' import {IEquip} from '../interface/GlobalInterface' const {ccclass, property} = cc._decorator type equipGoods = IEquip | qualityGoods @ccclass @observer export class EquipBreakUI extends BaseUI { chooseEquip: IEquip = null equipAndGoodArr: equipGoods[] needArr: equipGoods[] @list('equipList') equipList: List @node('chooseType') chooseTypeNode: cc.Node chooseType: EQUIPMENT = EQUIPMENT.none equips: IEquip[] = [] lastPower: number onShow(args, fromUI: number) { Mgr.net.add(msgCmd.cmd_equip_upgrade_star_rsp, this, this.onEquipStarRsp) Mgr.net.add(msgCmd.cmd_equip_onekey_upgrade_star_rsp, this, this.onEquipOneKeyStarRsp) this.onChooseEquipItemClick(null, '0') } onHide(): any { Mgr.event.removeAll(this) } clearEquip() { this.chooseEquip = null this.resetData() this.initNeedSlot() this.initUI() this.initOneKey() } resetData() { this.equipList.selectedMode = SelectedType.SINGLE this.equipList.selectedId = -1 this.equipAndGoodArr = [...this.equips] let goodsIDArr: number[] = [] let cfgArr: IEquipmentQualityConfig[] = [] for (let ID in EquipmentQualityConfig) { let goodsIDs = EquipmentQualityConfig[ID].resetGoods for (let i = 0; i < goodsIDs.length; i++) { let goodsID = goodsIDs[i] if (goodsID && !goodsIDArr.includes(goodsID) && (this.chooseType == 0 || i == this.chooseType - 1)) { goodsIDArr.push(goodsID) cfgArr.push(EquipmentQualityConfig[ID]) } } } for (let i = 0; i < goodsIDArr.length; i++) { let goodsID = goodsIDArr[i] if (goodsID > 0 && Mgr.goods.getGoodsNum(goodsID) > 0) { for (let j = 0; j < Mgr.goods.getGoodsNum(goodsID); j++) { this.equipAndGoodArr.push({ id: goodsID, num: 1, quality: cfgArr[i].ID - 1, }) } } } this.needArr = [] } initUI() { cc.find('btn_auto', this.node).active = this.chooseEquip == null cc.find('btn_break', this.node).active = this.chooseEquip != null cc.find('joinTip', this.node).active = this.chooseEquip == null let breakTip = cc.find('breakTip', this.node) let curSlotEquipNode = cc.find('cur_slot/equip', this.node) curSlotEquipNode.active = false let nextSlotEquipNode = cc.find('next_slot/equip', this.node) nextSlotEquipNode.active = false let hasChoose = this.chooseEquip != null breakTip.active = hasChoose let rtTip = cc.find('tip_rt', this.node) ccUtils.setLabel(LANGUAGE_TYPE.autoBreakEquipTip, rtTip) cc.find('add_need', this.node).active = hasChoose cc.find('need', this.node).active = hasChoose if (this.chooseEquip) { let iEquip = this.chooseEquip this.lastPower = iEquip.power curSlotEquipNode.active = true let equip = ccUtils.deepCopy(iEquip.equip) equip.id += 1 Mgr.global.initEquipItem(iEquip, curSlotEquipNode, this) let nextQualityIEquip = Mgr.global.buildIEquip(equip) nextSlotEquipNode.active = true Mgr.global.initEquipItem(nextQualityIEquip, nextSlotEquipNode, this) this.loadTexImg(`Public/role/streamer_${iEquip.cfg.qualityType + 1}`, breakTip, 'streamer') ccUtils.setLabel(iEquip.cfg.name, breakTip, 'equipName') let attrOrigin = cc.find('scrollView/view/content/attrs/attr', breakTip) let attrs = [ iEquip.HP > 0 ? ATTR_NAME.HP : iEquip.spellAttack > iEquip.attack ? ATTR_NAME.spellAttack : ATTR_NAME.attack, ] let allAttrs = ccUtils.instantChildren(attrOrigin, attrs.length + 1) //显示等级 let lvNode = allAttrs[0] ccUtils.setLabel(LANGUAGE_TYPE.lvMax, lvNode, 'attrName') ccUtils.setLabel(EquipmentQualityConfig[iEquip.cfg.quality].maxLv.toString(), lvNode, 'attrNum') ccUtils.setLabel(EquipmentQualityConfig[nextQualityIEquip.cfg.quality].maxLv.toString(), lvNode, 'nextNum') for (let i = 0; i < attrs.length; i++) { let attr = attrs[i] let attrNode = allAttrs[i + 1] ccUtils.setLabel(LANGUAGE_TYPE[attr.toString()], attrNode, 'attrName') ccUtils.setLabel(iEquip[attr.toString()], attrNode, 'attrNum') ccUtils.setLabel(nextQualityIEquip[attr.toString()], attrNode, 'nextNum') } ccUtils.setRichLabel( Mgr.i18n.getEntryLabel(nextQualityIEquip.cfg.entry), breakTip, 'scrollView/view/content/rtL/rt', ) ccUtils.setLabel(LANGUAGE_TYPE.needBreakTip, rtTip) let rtTipI18n = rtTip.getComponent(i18nLabel) let qCfg = EquipmentQualityConfig[iEquip.cfg.quality + 1] if (qCfg.anyQualityNum > 0) { this.equipList.maxMutSelected = qCfg.anyQualityNum rtTipI18n.setParamByIndex(qCfg.anyQualityNum.toString(), 0) rtTipI18n.setParamByIndex(QUALITY_COLOR[Data.user.qualityTypeArr[qCfg.anyQuality]], 1) rtTipI18n.setParamByIndex(LANGUAGE_TYPE[QUALITY_TYPE[Data.user.qualityTypeArr[qCfg.anyQuality]]], 2) } else { this.equipList.maxMutSelected = qCfg.sameQualityNum rtTipI18n.setParamByIndex(qCfg.sameQualityNum.toString(), 0) rtTipI18n.setParamByIndex(QUALITY_COLOR[Data.user.qualityTypeArr[qCfg.sameQuality]], 1) rtTipI18n.setParamByIndex( Mgr.i18n.getLabel(iEquip.cfg.name) + (iEquip.grade > 0 ? `(${iEquip.grade}${Mgr.i18n.getLabel(LANGUAGE_TYPE.star)})` : ''), 2, ) } cc.find('need', this.node).children.forEach((value, index) => { value.active = index < this.equipList.maxMutSelected }) } this.equipAndGoodArr.sort((a, b) => { if (this.chooseEquip) { let aNeed = 'cfg' in a ? this.equipCanBeNeed(a) : this.goodsCanBeNeed(a) let bNeed = 'cfg' in b ? this.equipCanBeNeed(b) : this.goodsCanBeNeed(b) return Number(bNeed) - Number(aNeed) } let aIndex = 'cfg' in a ? Data.user.teamRole.findIndex(v => v && v.hero.sid == a.equip.hero) : -1 let bIndex = 'cfg' in b ? Data.user.teamRole.findIndex(v => v && v.hero.sid == b.equip.hero) : -1 if (aIndex != bIndex) { if (aIndex >= 0 && bIndex >= 0) { return aIndex - bIndex } else { return bIndex - aIndex } } let aQuality let aNum = 0 let bNum = 0 let bQuality if ('quality' in a) { aQuality = a.quality aNum = a.num } else { aQuality = a.cfg.quality } if ('quality' in b) { bQuality = b.quality bNum = b.num } else { bQuality = b.cfg.quality } let curQuality = this.chooseEquip ? this.chooseEquip.cfg.quality : -1 // 先按照aQuality bQuality是否等于 cfg.quality 进行排序 if (aQuality == curQuality && bQuality != curQuality) { return -1 } else if (aQuality != curQuality && bQuality == curQuality) { return 1 } else { if (aQuality != bQuality) { return bQuality - aQuality } if (aNum != bNum) { return aNum - bNum } if ('cfg' in a && 'cfg' in b) { return a.cfg.type - b.cfg.type } } }) this.equipList.numItems = this.equipAndGoodArr.length } equipCanBeNeed(iEquip: IEquip) { if (!this.chooseEquip) return false //选择了某个目标,可以吃的材料卡可以点击 let qCfg = EquipmentQualityConfig[this.chooseEquip.cfg.quality + 1] //同名卡可以点击 let can1 = qCfg.sameQualityNum > 0 && this.chooseEquip.equip.id == iEquip.equip.id //当前颜色卡可以点击 let can2 = qCfg.anyQualityNum > 0 && this.chooseEquip.cfg.quality - this.chooseEquip.grade == iEquip.cfg.quality && iEquip.cfg.type == this.chooseEquip.cfg.type return (can1 || can2) && !Mgr.goods.equipIsUp(iEquip) && iEquip != this.chooseEquip } goodsCanBeNeed(goods: qualityGoods) { if (!this.chooseEquip) return false let qCfg = EquipmentQualityConfig[this.chooseEquip.cfg.quality + 1] return qCfg.anyQualityNum > 0 && qCfg.resetGoods[this.chooseEquip.cfg.type - 1] == goods.id } initNeedSlot() { let children = cc.find('need', this.node).children for (let i = 0; i < children.length; i++) { let node = children[i] let itemParent = cc.find('itemParent', node) if (this.needArr[i]) { itemParent.active = true this.initByEquipAndGoods(node, this.needArr[i]) } else { itemParent.active = false } } } initEquipListItem(node: cc.Node, index: number) { let equipAndGoods = this.equipAndGoodArr[index] let iEquip: IEquip = 'cfg' in equipAndGoods ? equipAndGoods : null let goods: qualityGoods = 'quality' in equipAndGoods ? equipAndGoods : null this.initByEquipAndGoods(node, equipAndGoods) let isIEquip = iEquip != null //升级需要资源 cc.find('red_dot', node).active = isIEquip && Mgr.goods.checkEquipBreakNeed(iEquip).canUp let canClick = false if (this.chooseEquip) { if (iEquip) canClick = this.equipCanBeNeed(iEquip) if (goods) canClick = this.goodsCanBeNeed(goods) } else if (iEquip) { //没有选择,可以突破的角色可以点击 canClick = EquipmentQualityConfig[iEquip.cfg.quality + 1] != undefined } node.getComponent(UserButton).interactable = canClick cc.find('gray', node).active = !canClick let hero = cc.find('hero', node) hero.active = isIEquip && !!iEquip.equip.hero if (hero.active) { let iRole = Data.user.roles.find(v => v.hero.sid == iEquip.equip.hero) this.loadTexImg(`Public/role/icon/${iRole.cfg.url}`, hero, 'icon') } } initByEquipAndGoods(node: cc.Node, equipAndGoods: equipGoods) { let iEquip: IEquip = 'cfg' in equipAndGoods ? equipAndGoods : null let goods: qualityGoods = 'quality' in equipAndGoods ? equipAndGoods : null let itemParent = cc.find('itemParent', node) if (goods) { Mgr.goods.initOneGoods({id: goods.id, num: goods.num}, itemParent, this, {showDetails: false}) } else { Mgr.global.initEquipItem(iEquip, itemParent, this) } } initChooseTypeUI() { let icon = cc.find('btn_chooseType/type_icon', this.node) icon.active = this.chooseType > 0 if (icon.active) { this.loadTexImg(`Public/equip/type_icon${this.chooseType}`, this.node, 'btn_chooseType/type_icon') } ccUtils.setLabel( this.chooseType == EQUIPMENT.none ? LANGUAGE_TYPE.all : LANGUAGE_TYPE[EQUIPMENT[this.chooseType]], this.node, 'btn_chooseType/label', ) let items = cc.find('items', this.chooseTypeNode).children for (let i = 0; i < items.length; i++) { let item = items[i] cc.find('choose', item).active = this.chooseType == i } } initEquipByType() { this.equips.length = 0 this.equips = Data.user.equips.filter( equip => (!this.chooseType || this.chooseType == equip.cfg.type) && equip.cfg.quality < Data.main.maxEquipQuality, ) cc.find('equipList/lb', this.node).active = this.equips.length == 0 } initOneKey() { let canUp = false for (let equip of Data.user.equips) { if (equip.cfg.qualityType < QUALITY_TYPE.elite && !Mgr.goods.equipIsUp(equip)) { canUp ||= Mgr.goods.checkEquipBreakNeed(equip, true).canUp if (canUp) break } } cc.find('btn_auto/red_dot', this.node).active = canUp } //网络事件======================================= onEquipStarRsp(data: equipUpgradeStarRsp, rewardNty: IRewardNty) { Mgr.ui.show(UI.PowerUpUI, `+${this.chooseEquip.power - this.lastPower}`) this.initEquipByType() this.clearEquip() Mgr.ui.showUIs([ Mgr.ui.getGroupUIInfo(UI.EquipBreakSuccessUI, Mgr.global.buildIEquip(data.data)), Mgr.ui.getRewardGroupUIInfo(rewardNty), ]) } onEquipOneKeyStarRsp(data: equipOnekeyUpgradeStarRsp, rewardNty: IRewardNty) { this.initEquipByType() this.clearEquip() let changeIEquip: IEquip[] = [] for (let i = Data.user.equips.length - 1; i >= 0; i--) { let find = data.changeList.find(value => value.sid == Data.user.equips[i].equip.sid) if (find) { changeIEquip.push(Data.user.equips[i]) } } } //触发事件======================================= // 点击事件======================================= onAllEquipClick() { this.chooseTypeNode.active = true } onChooseEquipItemClick(e, detail) { this.chooseType = parseInt(detail) this.chooseTypeNode.active = false this.initChooseTypeUI() this.initEquipByType() this.clearEquip() } onEquipClick(node, index, lastSelected, isSelected, isMax) { if (!node) return if (cc.find('gray', node).active) return if (isMax) Mgr.ui.tip(LANGUAGE_TYPE.materialsLimit) if (this.chooseEquip) { this.needArr = [] this.equipList.getMultSelected().forEach(i => { this.needArr.push(this.equipAndGoodArr[i]) }) this.initNeedSlot() } else { this.chooseEquip = this.equipAndGoodArr[index] as IEquip this.equipList.selectedMode = SelectedType.MULT this.equipList.setMultSelected([], null) this.initUI() this.equipList.scrollTo(0) } } onChooseEquipClick() { this.clearEquip() } onBreakClick() { if (!this.chooseEquip) return if (this.needArr?.length < this.equipList.maxMutSelected) { Mgr.ui.tip(LANGUAGE_TYPE.materialsNeed) return } let currency: idNum = {id: 0, num: 0} let sidArr: string[] = [] let hasLvUp = false this.needArr.forEach(value => { if ('equip' in value) { sidArr.push(value.equip.sid) if (!hasLvUp && value.equip.lv > 1) hasLvUp = true } if ('quality' in value) { currency.id = value.id currency.num += 1 } }) let isSame = EquipmentQualityConfig[this.chooseEquip.cfg.quality + 1].sameQualityNum > 0 let data: equipUpgradeStar = { currency, other: isSame ? [] : sidArr, same: isSame ? sidArr : [], sid: this.chooseEquip.equip.sid, } if (hasLvUp) { Mgr.ui.message(LANGUAGE_TYPE.materialsLvUp, () => { Mgr.net.send(msgCmd.cmd_equip_upgrade_star, data) }) } else { Mgr.net.send(msgCmd.cmd_equip_upgrade_star, data) } } onOneKeyBreakClick() { Mgr.net.send(msgCmd.cmd_equip_onekey_upgrade_star) } }