123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- /** @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 {equipUpgrade, equipUpgradeRsp, heroUpgrade, heroWearEquip, heroWearEquipRsp} from '../proto/game'
- import {ATTR_NAME, EVENT, LANGUAGE_TYPE, PROFESSION, QUALITY_TYPE} from '../enums/Enum'
- import {IRoleConfig, RoleConfig} from '../config/RoleConfig'
- import {ArmorConfig, IArmorConfig} from '../config/ArmorConfig'
- import {IEquip, IOperateNeed, IRole} from '../interface/GlobalInterface'
- import {SOUND} from '../enums/Sound'
- const {ccclass, property} = cc._decorator
- export interface IEquipDetailUIArgs {
- equip: IEquip
- role: IRole
- }
- @ccclass
- @observer
- export class EquipDetailUI extends BaseUI {
- curEquip: IEquip
- curRole: IRole
- levelNeed: IOperateNeed
- lastPower: number
- onShow(args: IEquipDetailUIArgs, fromUI: number) {
- Mgr.net.add(msgCmd.cmd_equip_upgrade_rsp, this, this.onUpgradeRsp)
- Mgr.net.add(msgCmd.cmd_hero_wear_equip_rsp, this, this.hide)
- Mgr.net.add(msgCmd.cmd_equip_reset_rsp, this, this.initUI)
- this.curEquip = args.equip
- this.curRole = args.role
- this.initUI()
- Mgr.event.add(EVENT.goodsChangeSync, this, this.initUI)
- }
- onHide(): any {
- Mgr.event.removeAll(this)
- }
- initUI() {
- let iEquip = this.curEquip
- this.lastPower = iEquip.power
- ccUtils.setLabel(iEquip.cfg.name, this.node, 'equipName')
- Mgr.global.initEquipItem(iEquip, cc.find('equip', this.node), this, {lvMax: true})
- //属性值
- let attrNum =
- iEquip.HP > 0 ? iEquip.HP : iEquip.spellAttack > iEquip.attack ? iEquip.spellAttack : iEquip.attack
- let attrName =
- iEquip.HP > 0 ? ATTR_NAME.HP : iEquip.spellAttack > iEquip.attack ? ATTR_NAME.spellAttack : ATTR_NAME.attack
- ccUtils.setLabel(LANGUAGE_TYPE[attrName], this.node, 'atk_lb')
- ccUtils.setLabel(attrNum.toString(), this.node, 'atk_num')
- //职业限定
- let professionNodes = ccUtils.instantChildren(
- cc.find('professions/role_type', this.node),
- iEquip.cfg.profession.length,
- )
- for (let i = 0; i < professionNodes.length; i++) {
- this.loadTexImg(`Public/role/role_type_${iEquip.cfg.profession[i]}`, professionNodes[i])
- }
- cc.find('button_reset', this.node).active =
- iEquip.equip.lv > 1 || (iEquip.cfg.qualityType >= QUALITY_TYPE.elite && iEquip.grade > 0)
- //词条
- let attrItemOrigin = cc.find('attrList/view/content/item', this.node)
- let tips: {entry: number; cfg: IArmorConfig}[] = []
- for (let i = 1; i <= Data.main.maxEquipQuality; i++) {
- let ID = Math.floor(iEquip.cfg.ID / 100) * 100 + i
- if (ArmorConfig[ID.toString()]?.entry)
- tips.push({
- entry: ArmorConfig[ID.toString()].entry,
- cfg: ArmorConfig[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 > iEquip.cfg.quality
- this.loadTexImg(`Public/goodsQuality/item_frame${tip.cfg.qualityType}`, attrItem, 'icon/item_frame')
- let richTextNode = cc.find('richText', attrItem)
- ccUtils.setRichLabel(Mgr.i18n.getEntryLabel(tip.entry), richTextNode)
- if (tip.cfg.quality > iEquip.cfg.quality) ccUtils.setRichLabelGray(richTextNode)
- this.scheduleOnce(() => {
- if (attrItem.activeInHierarchy) {
- 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
- }
- }
- })
- }
- //需要资源
- this.levelNeed = Mgr.goods.checkEquipLevelNeed(iEquip)
- 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)
- }
- cc.find('layout/btn_onekey', this.node).active = !this.levelNeed.isMax
- cc.find('layout/btn_upgrade', this.node).active = !this.levelNeed.isMax
- cc.find('layout/btn_equip', this.node).active = !Mgr.goods.equipIsUp(iEquip)
- cc.find('layout/btn_remove', this.node).active = iEquip.equip.hero == this.curRole.hero.sid
- }
- //网络事件=======================================
- onUpgradeRsp() {
- Mgr.audio.playSFX(SOUND.goodsUp)
- Mgr.ui.show(UI.PowerUpUI, `+${this.curEquip.power - this.lastPower}`)
- this.initUI()
- ccUtils.playAni('smallLvup', 0, this.node, 'smallLvup')
- }
- // 点击事件=======================================
- 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: equipUpgrade = {
- num,
- sid: this.curEquip.equip.sid,
- }
- Mgr.net.send(msgCmd.cmd_equip_upgrade, data)
- } else {
- Mgr.ui.showObtain(this.levelNeed)
- }
- }
- }
- onResetClick() {
- Mgr.ui.show(UI.EquipResetUI, this.curEquip)
- }
- onUpOrRemoveClick(e, detail) {
- let equips = this.curRole.equips.map(iEquip => (iEquip ? iEquip.equip.sid : ''))
- equips[this.curEquip.cfg.type - 1] = detail ? '' : this.curEquip.equip.sid
- if (!detail) {
- //不同职业不能穿
- if (!this.curEquip.cfg.profession.includes(this.curRole.cfg.profession)) {
- Mgr.ui.tip(LANGUAGE_TYPE.professionEquip)
- return
- }
- }
- let data: heroWearEquip = {list: equips, sid: this.curRole.hero.sid}
- Mgr.net.send(msgCmd.cmd_hero_wear_equip, data)
- }
- }
|