EquipDetailUI.ts 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /** @format */
  2. import {UI} from '../enums/UI'
  3. import {BaseUI} from './BaseUI'
  4. import {Data, Mgr} from '../GameControl'
  5. import {ccUtils} from '../utils/ccUtils'
  6. import {observer, render, node, label, editBox, list} from '../mobx/observer'
  7. import {msgCmd} from '../proto/msg_cmd'
  8. import {equipUpgrade, equipUpgradeRsp, heroUpgrade, heroWearEquip, heroWearEquipRsp} from '../proto/game'
  9. import {ATTR_NAME, EVENT, LANGUAGE_TYPE, PROFESSION, QUALITY_TYPE} from '../enums/Enum'
  10. import {IRoleConfig, RoleConfig} from '../config/RoleConfig'
  11. import {ArmorConfig, IArmorConfig} from '../config/ArmorConfig'
  12. import {IEquip, IOperateNeed, IRole} from '../interface/GlobalInterface'
  13. import {SOUND} from '../enums/Sound'
  14. const {ccclass, property} = cc._decorator
  15. export interface IEquipDetailUIArgs {
  16. equip: IEquip
  17. role: IRole
  18. }
  19. @ccclass
  20. @observer
  21. export class EquipDetailUI extends BaseUI {
  22. curEquip: IEquip
  23. curRole: IRole
  24. levelNeed: IOperateNeed
  25. lastPower: number
  26. onShow(args: IEquipDetailUIArgs, fromUI: number) {
  27. Mgr.net.add(msgCmd.cmd_equip_upgrade_rsp, this, this.onUpgradeRsp)
  28. Mgr.net.add(msgCmd.cmd_hero_wear_equip_rsp, this, this.hide)
  29. Mgr.net.add(msgCmd.cmd_equip_reset_rsp, this, this.initUI)
  30. this.curEquip = args.equip
  31. this.curRole = args.role
  32. this.initUI()
  33. Mgr.event.add(EVENT.goodsChangeSync, this, this.initUI)
  34. }
  35. onHide(): any {
  36. Mgr.event.removeAll(this)
  37. }
  38. initUI() {
  39. let iEquip = this.curEquip
  40. this.lastPower = iEquip.power
  41. ccUtils.setLabel(iEquip.cfg.name, this.node, 'equipName')
  42. Mgr.global.initEquipItem(iEquip, cc.find('equip', this.node), this, {lvMax: true})
  43. //属性值
  44. let attrNum =
  45. iEquip.HP > 0 ? iEquip.HP : iEquip.spellAttack > iEquip.attack ? iEquip.spellAttack : iEquip.attack
  46. let attrName =
  47. iEquip.HP > 0 ? ATTR_NAME.HP : iEquip.spellAttack > iEquip.attack ? ATTR_NAME.spellAttack : ATTR_NAME.attack
  48. ccUtils.setLabel(LANGUAGE_TYPE[attrName], this.node, 'atk_lb')
  49. ccUtils.setLabel(attrNum.toString(), this.node, 'atk_num')
  50. //职业限定
  51. let professionNodes = ccUtils.instantChildren(
  52. cc.find('professions/role_type', this.node),
  53. iEquip.cfg.profession.length,
  54. )
  55. for (let i = 0; i < professionNodes.length; i++) {
  56. this.loadTexImg(`Public/role/role_type_${iEquip.cfg.profession[i]}`, professionNodes[i])
  57. }
  58. cc.find('button_reset', this.node).active =
  59. iEquip.equip.lv > 1 || (iEquip.cfg.qualityType >= QUALITY_TYPE.elite && iEquip.grade > 0)
  60. //词条
  61. let attrItemOrigin = cc.find('attrList/view/content/item', this.node)
  62. let tips: {entry: number; cfg: IArmorConfig}[] = []
  63. for (let i = 1; i <= Data.main.maxEquipQuality; i++) {
  64. let ID = Math.floor(iEquip.cfg.ID / 100) * 100 + i
  65. if (ArmorConfig[ID.toString()]?.entry)
  66. tips.push({
  67. entry: ArmorConfig[ID.toString()].entry,
  68. cfg: ArmorConfig[ID.toString()],
  69. })
  70. }
  71. let attrItems = ccUtils.instantChildren(attrItemOrigin, tips.length)
  72. for (let i = 0; i < tips.length; i++) {
  73. let attrItem = attrItems[i]
  74. let tip = tips[i]
  75. cc.find('icon/lock_1', attrItem).active = tip.cfg.quality > iEquip.cfg.quality
  76. this.loadTexImg(`Public/goodsQuality/item_frame${tip.cfg.qualityType}`, attrItem, 'icon/item_frame')
  77. let richTextNode = cc.find('richText', attrItem)
  78. ccUtils.setRichLabel(Mgr.i18n.getEntryLabel(tip.entry), richTextNode)
  79. if (tip.cfg.quality > iEquip.cfg.quality) ccUtils.setRichLabelGray(richTextNode)
  80. this.scheduleOnce(() => {
  81. if (attrItem.activeInHierarchy) {
  82. let layout = attrItem.getComponent(cc.Layout)
  83. layout.resizeMode =
  84. richTextNode.height < 65 ? cc.Layout.ResizeMode.NONE : cc.Layout.ResizeMode.CONTAINER
  85. layout.updateLayout()
  86. if (richTextNode.height < 65) {
  87. attrItem.height = 65
  88. }
  89. }
  90. })
  91. }
  92. //需要资源
  93. this.levelNeed = Mgr.goods.checkEquipLevelNeed(iEquip)
  94. cc.find('needLy', this.node).active = !this.levelNeed.isMax
  95. if (!this.levelNeed.isMax) {
  96. let needItems = ccUtils.instantChildren(cc.find('needLy/item', this.node), this.levelNeed.need.length)
  97. Mgr.goods.initNeedGoods(this.levelNeed.need, needItems, this)
  98. }
  99. cc.find('layout/btn_onekey', this.node).active = !this.levelNeed.isMax
  100. cc.find('layout/btn_upgrade', this.node).active = !this.levelNeed.isMax
  101. cc.find('layout/btn_equip', this.node).active = !Mgr.goods.equipIsUp(iEquip)
  102. cc.find('layout/btn_remove', this.node).active = iEquip.equip.hero == this.curRole.hero.sid
  103. }
  104. //网络事件=======================================
  105. onUpgradeRsp() {
  106. Mgr.audio.playSFX(SOUND.goodsUp)
  107. Mgr.ui.show(UI.PowerUpUI, `+${this.curEquip.power - this.lastPower}`)
  108. this.initUI()
  109. ccUtils.playAni('smallLvup', 0, this.node, 'smallLvup')
  110. }
  111. // 点击事件=======================================
  112. onLevelClick(e, isOneClick: string) {
  113. if (this.levelNeed) {
  114. if (this.levelNeed.isMax) {
  115. Mgr.ui.tip(LANGUAGE_TYPE.maxLevel)
  116. } else if (this.levelNeed.canUp) {
  117. let num = isOneClick == '1' ? 0 : 1
  118. let data: equipUpgrade = {
  119. num,
  120. sid: this.curEquip.equip.sid,
  121. }
  122. Mgr.net.send(msgCmd.cmd_equip_upgrade, data)
  123. } else {
  124. Mgr.ui.showObtain(this.levelNeed)
  125. }
  126. }
  127. }
  128. onResetClick() {
  129. Mgr.ui.show(UI.EquipResetUI, this.curEquip)
  130. }
  131. onUpOrRemoveClick(e, detail) {
  132. let equips = this.curRole.equips.map(iEquip => (iEquip ? iEquip.equip.sid : ''))
  133. equips[this.curEquip.cfg.type - 1] = detail ? '' : this.curEquip.equip.sid
  134. if (!detail) {
  135. //不同职业不能穿
  136. if (!this.curEquip.cfg.profession.includes(this.curRole.cfg.profession)) {
  137. Mgr.ui.tip(LANGUAGE_TYPE.professionEquip)
  138. return
  139. }
  140. }
  141. let data: heroWearEquip = {list: equips, sid: this.curRole.hero.sid}
  142. Mgr.net.send(msgCmd.cmd_hero_wear_equip, data)
  143. }
  144. }