EquipUI.ts 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /** @format */
  2. import {BaseUI} from './BaseUI'
  3. import {Data, Mgr} from '../GameControl'
  4. import {ccUtils} from '../utils/ccUtils'
  5. import {list, node, observer, render} from '../mobx/observer'
  6. import List from '../uiutils/List'
  7. import {ATTR_NAME, EQUIPMENT, GOODS, LANGUAGE_TYPE, PROFESSION} from '../enums/Enum'
  8. import {UI} from '../enums/UI'
  9. import {msgCmd} from '../proto/msg_cmd'
  10. import {IEquip, IRole} from '../interface/GlobalInterface'
  11. const {ccclass, property} = cc._decorator
  12. @ccclass
  13. @observer
  14. export class EquipUI extends BaseUI {
  15. @node('bigRoleList')
  16. bigRoleListNode: cc.Node
  17. @node('chooseType')
  18. chooseTypeNode: cc.Node
  19. equipSlots: cc.Node[]
  20. @list('smallRoleList')
  21. smallRoleList: List
  22. @list('bigRoleList/roleList')
  23. bigRoleList: List
  24. @list('equipList')
  25. equipList: List
  26. chooseRole: IRole
  27. chooseType: EQUIPMENT = EQUIPMENT.none
  28. equips: IEquip[] = []
  29. onLoad() {
  30. this.equipSlots = cc.find('equipSlots', this.node).children
  31. }
  32. onShow(args, fromUI: number) {
  33. Mgr.net.add(msgCmd.cmd_hero_wear_equip_rsp, this, this.onEquipWearRsp)
  34. Mgr.net.add(msgCmd.cmd_equip_upgrade_star_rsp, this, this.initRoleUI)
  35. Mgr.net.add(msgCmd.cmd_equip_upgrade_rsp, this, this.initRoleUI)
  36. cc.find('roleList/lb', this.bigRoleListNode).active = Data.user.roles.length == 0
  37. if (Data.user.roles.length > 0) {
  38. this.chooseRole = Data.user.roles[0]
  39. }
  40. this.smallRoleList.numItems = Data.user.roles.length
  41. this.bigRoleList.numItems = Data.user.roles.length
  42. this.onChooseEquipItemClick(null, '0')
  43. this.initRoleUI()
  44. Mgr.ui.showTop(this, [GOODS.coin, GOODS.diamond])
  45. //3.当拥有的装备(包括佩戴的装备)可合成突破时,装备界面中【突破】按钮上拥有红点提示;装备合成界面中对应可合成的“装备图标”右上角拥有红点提示
  46. cc.find('btn_break/red_dots', this.node).active = Data.user.equips.some(
  47. equip => Mgr.goods.checkEquipBreakNeed(equip).canUp,
  48. )
  49. }
  50. onHide(): any {
  51. Mgr.event.removeAll(this)
  52. }
  53. initRoleUI() {
  54. let iRole = this.chooseRole
  55. //英雄
  56. let roleNode = cc.find('role', this.node)
  57. roleNode.active = iRole != undefined
  58. if (iRole) {
  59. Mgr.global.buildIRole(iRole.hero, iRole)
  60. ccUtils.setLabel(iRole.cfg.name, roleNode, 'roleName')
  61. ccUtils.setLabel(`lv.${iRole.hero.lv}`, roleNode, 'lv')
  62. this.loadTexImg(`Public/role/streamer_${iRole.cfg.qualityType}`, roleNode, 'streamer')
  63. this.loadTexImg(`Public/role/role_type_${iRole.cfg.profession}`, roleNode, 'role_type')
  64. this.loadTexImg(`Public/role/base_light_${iRole.cfg.qualityType}`, roleNode, 'base_light')
  65. Mgr.global.initRoleSpine(iRole, roleNode, 'spine')
  66. ccUtils.instantChildren(cc.find('stars/star', roleNode), iRole.grade)
  67. //属性值
  68. let attack = iRole.cfg.profession == PROFESSION.mage ? iRole.spellAttack : iRole.attack
  69. let attackIcon = iRole.cfg.profession == PROFESSION.mage ? ATTR_NAME.spellAttack : ATTR_NAME.attack
  70. this.loadTexImg(`Public/allAttr/${attackIcon}`, roleNode, 'attackIcon')
  71. ccUtils.setLabel(Math.toKMBNum(attack), roleNode, 'attack')
  72. ccUtils.setLabel(Math.toKMBNum(iRole.HP), roleNode, 'hp_lb')
  73. //人物装备
  74. for (let i = 1; i <= Data.main.equipMaxNum; i++) {
  75. let equipSlot = this.equipSlots[i - 1]
  76. let equipNode = cc.find('equip', equipSlot)
  77. let red = cc.find('red_dots', equipSlot)
  78. let equip = iRole.equips[i - 1]
  79. equipNode.active = equip != null
  80. red.active = false
  81. if (equip) {
  82. Mgr.global.initEquipItem(equip, equipNode, this)
  83. equipNode['equip'] = equip
  84. red.active =
  85. Mgr.goods.roleIsUp(iRole) &&
  86. (Mgr.goods.checkEquipLevelNeed(equip).canUp || Mgr.goods.checkEquipBreakNeed(equip).canUp)
  87. }
  88. }
  89. }
  90. }
  91. initChooseTypeUI() {
  92. let icon = cc.find('btn_chooseType/type_icon', this.node)
  93. icon.active = this.chooseType > 0
  94. if (icon.active) {
  95. this.loadTexImg(`Public/equip/type_icon${this.chooseType}`, this.node, 'btn_chooseType/type_icon')
  96. }
  97. ccUtils.setLabel(
  98. this.chooseType == EQUIPMENT.none ? LANGUAGE_TYPE.all : LANGUAGE_TYPE[EQUIPMENT[this.chooseType]],
  99. this.node,
  100. 'btn_chooseType/label',
  101. )
  102. let items = cc.find('items', this.chooseTypeNode).children
  103. for (let i = 0; i < items.length; i++) {
  104. let item = items[i]
  105. cc.find('choose', item).active = this.chooseType == i
  106. }
  107. }
  108. initEquipByType() {
  109. this.equips.length = 0
  110. this.equips = Data.user.equips.filter(
  111. equip => !equip.equip.hero && (!this.chooseType || this.chooseType == equip.cfg.type),
  112. )
  113. this.equipList.numItems = this.equips.length
  114. cc.find('equipList/lb', this.node).active = this.equips.length == 0
  115. }
  116. initRoleItem(node: cc.Node, index: number) {
  117. let iRole = Data.user.roles[index]
  118. let role = cc.find('role', node)
  119. Mgr.global.initRoleItem(iRole, role, this)
  120. let icon_battle = cc.find('icon_battle', node)
  121. icon_battle.active = Mgr.goods.roleIsUp(iRole)
  122. node['iRole'] = iRole
  123. cc.find('select_1', node).active = this.chooseRole && this.chooseRole.hero.sid == iRole.hero.sid
  124. cc.find('red_dots', node).active = Mgr.goods.checkRoleWearEquipUp(iRole) || Mgr.goods.checkRoleEquipUp(iRole)
  125. }
  126. initEquipItem(node: cc.Node, index: number) {
  127. let equip = this.equips[index]
  128. let equipNode = cc.find('equip', node)
  129. Mgr.global.initEquipItem(equip, equipNode, this)
  130. cc.find('red_dots', node).active = this.chooseRole && Mgr.goods.checkEquipWearUp(this.chooseRole, equip)
  131. node['equip'] = equip
  132. }
  133. //网络事件=======================================
  134. onEquipWearRsp() {
  135. this.initRoleUI()
  136. this.smallRoleList.numItems = Data.user.roles.length
  137. }
  138. //触发事件=======================================
  139. @render
  140. freshRoleAndEquips() {
  141. let equipDirty = Data.user.equipsDirty
  142. this.initRoleUI()
  143. this.initEquipByType()
  144. }
  145. // 点击事件=======================================
  146. onRoleClick(e) {
  147. this.chooseRole = e.target['iRole']
  148. this.smallRoleList.numItems = Data.user.roles.length
  149. this.bigRoleList.numItems = Data.user.roles.length
  150. this.freshRoleAndEquips()
  151. this.bigRoleListNode.active = false
  152. }
  153. onAllRoleClick() {
  154. this.bigRoleListNode.active = !this.bigRoleListNode.active
  155. }
  156. onAllEquipClick() {
  157. this.chooseTypeNode.active = true
  158. }
  159. onChooseEquipItemClick(e, detail) {
  160. this.chooseType = parseInt(detail)
  161. this.chooseTypeNode.active = false
  162. this.initChooseTypeUI()
  163. this.initEquipByType()
  164. }
  165. onEquipClick(e) {
  166. Mgr.ui.show(UI.EquipDetailUI, {equip: e.target['equip'], role: this.chooseRole})
  167. }
  168. onEquipAttrClick(e) {
  169. Mgr.ui.show(UI.EquipAttrUI, this.chooseRole)
  170. }
  171. onEquipBreakClick() {
  172. Mgr.ui.show(UI.EquipBreakUI)
  173. }
  174. onEquipSlotClick(e) {
  175. let node = e.target
  176. let index = node.parent.children.indexOf(node)
  177. if (!cc.find('equip', node).active) {
  178. this.onChooseEquipItemClick(null, index + 1)
  179. }
  180. }
  181. }