123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- /** @format */
- 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 {embattleBattleRsp, equipReset, heroReset, heroResetRsp} from '../proto/game'
- import {equip, hero, idNum} from '../proto/typedef'
- import {GOODS, LANGUAGE_TYPE} from '../enums/Enum'
- import {EquipmentLevelConfig} from '../config/EquipmentLevelConfig'
- import {EquipmentQualityConfig} from '../config/EquipmentQualityConfig'
- import {IRewardNty} from '../interface/UIInterface'
- import {IEquip} from '../interface/GlobalInterface'
- import {SOUND} from '../enums/Sound'
- const {ccclass, property} = cc._decorator
- @ccclass
- @observer
- export class EquipResetUI extends BaseUI {
- iEquip: IEquip
- toggleIndex: number = 0
- onShow(args: IEquip, fromUI: number) {
- Mgr.net.add(msgCmd.cmd_equip_reset_rsp, this, this.onResetRsp)
- this.iEquip = args
- this.toggleIndex = 0
- ccUtils.setTogglesChecked(this.toggleIndex, this.node, 'toggles')
- this.initUI()
- }
- onHide(): any {
- Mgr.event.removeAll(this)
- }
- initUI() {
- //显示英雄
- let resetEquipNode = cc.find('scrollView/view/content/equip', this.node)
- let goods = cc.find('scrollView/view/content/goods', this.node)
- Mgr.global.initEquipItem(this.iEquip, cc.find('equip', this.node), this)
- let isLvReset = this.toggleIndex == 1
- ccUtils.setLabel(isLvReset ? 't48' : 't49', this.node, 'tip')
- let resetEquip: equip = ccUtils.deepCopy(this.iEquip.equip)
- resetEquip.id = isLvReset ? this.iEquip.equip.id : this.iEquip.equip.id - this.iEquip.grade
- resetEquip.lv = 1
- let resetIEquip = Mgr.global.buildIEquip(resetEquip)
- Mgr.global.initEquipItem(resetIEquip, resetEquipNode, this)
- cc.find('btn', this.node).active =
- (isLvReset && this.iEquip.equip.lv > resetEquip.lv) || (!isLvReset && this.iEquip.grade > 0)
- //显示分解列表
- let coinIdNum = {id: GOODS.coin, num: 0}
- let scrollIdNum = {id: GOODS.weaponsScroll + this.iEquip.cfg.type - 1, num: 0}
- for (let i = 2; i <= this.iEquip.equip.lv; i++) {
- let cfg = EquipmentLevelConfig[i]
- if (cfg) {
- coinIdNum.num += cfg.goodNum
- scrollIdNum.num += cfg.scrollNum
- }
- }
- let idNumArr: idNum[] = []
- if (coinIdNum.num > 0) idNumArr.push(coinIdNum)
- if (scrollIdNum.num > 0) idNumArr.push(scrollIdNum)
- if (this.toggleIndex == 0) {
- for (let i = resetIEquip.cfg.quality + 1; i <= this.iEquip.cfg.quality; i++) {
- idNumArr = idNumArr.concat(
- Mgr.goods.getIdNumArr(
- [EquipmentQualityConfig[i].resetGoods[this.iEquip.cfg.type - 1]],
- [EquipmentQualityConfig[i].anyQualityNum],
- ),
- )
- }
- }
- idNumArr = Mgr.goods.getGoodsList(idNumArr)
- let allNodes = ccUtils.instantChildren(goods, idNumArr.length + 1)
- Mgr.goods.initGoods(idNumArr, allNodes.slice(1), this)
- }
- //网络事件=======================================
- onResetRsp(data: heroResetRsp, reward: IRewardNty) {
- Mgr.ui.showReward(reward)
- this.hide()
- }
- //触发事件=======================================
- // 点击事件=======================================
- onToggleClick(e) {
- Mgr.audio.playSFX(SOUND.toggleClick)
- this.toggleIndex = e.target.parent.children.indexOf(e.target)
- this.initUI()
- }
- onSureClick() {
- if (Mgr.goods.equipIsUp(this.iEquip)) {
- Mgr.ui.message(LANGUAGE_TYPE.equipIsUpReset, () => {
- this.sendResetReq()
- })
- } else {
- this.sendResetReq()
- }
- }
- sendResetReq() {
- let data: equipReset = {level: this.toggleIndex == 1, sid: this.iEquip.equip.sid}
- Mgr.net.send(msgCmd.cmd_equip_reset, data)
- }
- }
|