EquipResetUI.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /** @format */
  2. import {BaseUI} from './BaseUI'
  3. import {Data, Mgr} from '../GameControl'
  4. import {ccUtils} from '../utils/ccUtils'
  5. import {observer, render, node, label, editBox, list} from '../mobx/observer'
  6. import {msgCmd} from '../proto/msg_cmd'
  7. import {embattleBattleRsp, equipReset, heroReset, heroResetRsp} from '../proto/game'
  8. import {equip, hero, idNum} from '../proto/typedef'
  9. import {GOODS, LANGUAGE_TYPE} from '../enums/Enum'
  10. import {EquipmentLevelConfig} from '../config/EquipmentLevelConfig'
  11. import {EquipmentQualityConfig} from '../config/EquipmentQualityConfig'
  12. import {IRewardNty} from '../interface/UIInterface'
  13. import {IEquip} from '../interface/GlobalInterface'
  14. import {SOUND} from '../enums/Sound'
  15. const {ccclass, property} = cc._decorator
  16. @ccclass
  17. @observer
  18. export class EquipResetUI extends BaseUI {
  19. iEquip: IEquip
  20. toggleIndex: number = 0
  21. onShow(args: IEquip, fromUI: number) {
  22. Mgr.net.add(msgCmd.cmd_equip_reset_rsp, this, this.onResetRsp)
  23. this.iEquip = args
  24. this.toggleIndex = 0
  25. ccUtils.setTogglesChecked(this.toggleIndex, this.node, 'toggles')
  26. this.initUI()
  27. }
  28. onHide(): any {
  29. Mgr.event.removeAll(this)
  30. }
  31. initUI() {
  32. //显示英雄
  33. let resetEquipNode = cc.find('scrollView/view/content/equip', this.node)
  34. let goods = cc.find('scrollView/view/content/goods', this.node)
  35. Mgr.global.initEquipItem(this.iEquip, cc.find('equip', this.node), this)
  36. let isLvReset = this.toggleIndex == 1
  37. ccUtils.setLabel(isLvReset ? 't48' : 't49', this.node, 'tip')
  38. let resetEquip: equip = ccUtils.deepCopy(this.iEquip.equip)
  39. resetEquip.id = isLvReset ? this.iEquip.equip.id : this.iEquip.equip.id - this.iEquip.grade
  40. resetEquip.lv = 1
  41. let resetIEquip = Mgr.global.buildIEquip(resetEquip)
  42. Mgr.global.initEquipItem(resetIEquip, resetEquipNode, this)
  43. cc.find('btn', this.node).active =
  44. (isLvReset && this.iEquip.equip.lv > resetEquip.lv) || (!isLvReset && this.iEquip.grade > 0)
  45. //显示分解列表
  46. let coinIdNum = {id: GOODS.coin, num: 0}
  47. let scrollIdNum = {id: GOODS.weaponsScroll + this.iEquip.cfg.type - 1, num: 0}
  48. for (let i = 2; i <= this.iEquip.equip.lv; i++) {
  49. let cfg = EquipmentLevelConfig[i]
  50. if (cfg) {
  51. coinIdNum.num += cfg.goodNum
  52. scrollIdNum.num += cfg.scrollNum
  53. }
  54. }
  55. let idNumArr: idNum[] = []
  56. if (coinIdNum.num > 0) idNumArr.push(coinIdNum)
  57. if (scrollIdNum.num > 0) idNumArr.push(scrollIdNum)
  58. if (this.toggleIndex == 0) {
  59. for (let i = resetIEquip.cfg.quality + 1; i <= this.iEquip.cfg.quality; i++) {
  60. idNumArr = idNumArr.concat(
  61. Mgr.goods.getIdNumArr(
  62. [EquipmentQualityConfig[i].resetGoods[this.iEquip.cfg.type - 1]],
  63. [EquipmentQualityConfig[i].anyQualityNum],
  64. ),
  65. )
  66. }
  67. }
  68. idNumArr = Mgr.goods.getGoodsList(idNumArr)
  69. let allNodes = ccUtils.instantChildren(goods, idNumArr.length + 1)
  70. Mgr.goods.initGoods(idNumArr, allNodes.slice(1), this)
  71. }
  72. //网络事件=======================================
  73. onResetRsp(data: heroResetRsp, reward: IRewardNty) {
  74. Mgr.ui.showReward(reward)
  75. this.hide()
  76. }
  77. //触发事件=======================================
  78. // 点击事件=======================================
  79. onToggleClick(e) {
  80. Mgr.audio.playSFX(SOUND.toggleClick)
  81. this.toggleIndex = e.target.parent.children.indexOf(e.target)
  82. this.initUI()
  83. }
  84. onSureClick() {
  85. if (Mgr.goods.equipIsUp(this.iEquip)) {
  86. Mgr.ui.message(LANGUAGE_TYPE.equipIsUpReset, () => {
  87. this.sendResetReq()
  88. })
  89. } else {
  90. this.sendResetReq()
  91. }
  92. }
  93. sendResetReq() {
  94. let data: equipReset = {level: this.toggleIndex == 1, sid: this.iEquip.equip.sid}
  95. Mgr.net.send(msgCmd.cmd_equip_reset, data)
  96. }
  97. }