RoleUI.ts 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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 {RoleShowSkillConfig} from '../config/RoleShowSkillConfig'
  9. import {IRoleConfig, RoleConfig} from '../config/RoleConfig'
  10. import {ATTR_NAME, EVENT, GOODS, LANGUAGE_TYPE, PROFESSION, QUALITY_COLOR, QUALITY_TYPE} from '../enums/Enum'
  11. import {IRoleLevelConfig, RoleLevelConfig} from '../config/RoleLevelConfig'
  12. import {heroUpgrade, heroUpgradeRsp} from '../proto/game'
  13. import {RoleQualityConfig} from '../config/RoleQualityConfig'
  14. import {i18nLabel} from '../uiutils/i18nLabel'
  15. import {IOperateNeed, IRole} from '../interface/GlobalInterface'
  16. import {GlobalManager} from '../mgrs/GlobalManager'
  17. import {SOUND} from '../enums/Sound'
  18. const {ccclass, property} = cc._decorator
  19. @ccclass
  20. @observer
  21. export class RoleUI extends BaseUI {
  22. iRole: IRole
  23. levelNeed: IOperateNeed
  24. @node('toggles')
  25. toggles: cc.Node
  26. @node('info')
  27. infoNode: cc.Node
  28. @node('skills')
  29. skillNode: cc.Node
  30. @node('levelGuide')
  31. levelGuide: cc.Node
  32. lastPower: number
  33. toggleIndex = 0
  34. onShow(args: IRole, fromUI: number) {
  35. Mgr.net.add(msgCmd.cmd_hero_upgrade_rsp, this, this.onUpdateRsp)
  36. Mgr.net.add(msgCmd.cmd_hero_reset_rsp, this, this.initRole)
  37. Mgr.net.add(msgCmd.cmd_embattle_battle_rsp, this, this.onUpRsp)
  38. this.iRole = args
  39. this.initToggles()
  40. this.initRole()
  41. Mgr.event.add(EVENT.goodsChangeSync, this, this.initRole)
  42. if (this.levelNeed.canUp && this.iRole.hero.lv == 1) {
  43. // 打完第一关 升级角色
  44. this.levelGuide.active = Mgr.global.tryShowUserGuide(['2_3'])
  45. }
  46. }
  47. onHide(): any {
  48. Mgr.event.removeAll(this)
  49. }
  50. initToggles() {
  51. ccUtils.setTogglesChecked(this.toggleIndex, this.toggles)
  52. this.infoNode.active = this.toggleIndex == 0
  53. this.skillNode.active = this.toggleIndex == 1
  54. }
  55. initRole() {
  56. let iRole = this.iRole
  57. this.lastPower = iRole.power
  58. //属性值
  59. let isSpell = iRole.spellAttack > iRole.attack
  60. let attrs = cc.find('attr', this.infoNode).children
  61. for (let i = 0; i < attrs.length; i++) {
  62. let attr = attrs[i]
  63. ccUtils.setLabel(attr.name == ATTR_NAME.attackRange ? iRole.cfg.attackRange : iRole[attr.name], attr, 'num')
  64. if (attr.name == ATTR_NAME.attack) attr.active = !isSpell
  65. if (attr.name == ATTR_NAME.spellAttack) attr.active = isSpell
  66. }
  67. //英雄
  68. let roleNode = cc.find('role', this.node)
  69. ccUtils.setLabel(iRole.cfg.name, roleNode, 'roleName')
  70. ccUtils.setLabel(`lv.${iRole.hero.lv}`, roleNode, 'lv')
  71. this.loadTexImg(`Public/role/icon_type_${iRole.cfg.profession}`, roleNode, 'role_type')
  72. this.loadTexImg(`Public/role/role_base_${iRole.cfg.profession}`, roleNode, 'role_base')
  73. this.loadTexImg(`Public/role/quality_icon_${iRole.cfg.quality}`, roleNode, 'quality_icon')
  74. let nextRoleConfig = RoleConfig[iRole.cfg.ID + 1]
  75. ccUtils.setLabel(nextRoleConfig ? `${iRole.hero.num}/${nextRoleConfig.consume}` : 'MAX', roleNode, 'numPb/num')
  76. ccUtils.setProgress(nextRoleConfig ? iRole.hero.num / nextRoleConfig.consume : 1, roleNode, 'numPb/pb')
  77. Mgr.global.initRoleSpine(iRole, roleNode, 'spine')
  78. //需要资源
  79. this.levelNeed = Mgr.goods.checkRoleLevelUpNeed(iRole)
  80. cc.find('needLy', this.node).active = !this.levelNeed.isMax
  81. if (!this.levelNeed.isMax) {
  82. let needItems = ccUtils.instantChildren(cc.find('needLy/item', this.node), this.levelNeed.need.length)
  83. Mgr.goods.initNeedGoods(this.levelNeed.need, needItems, this)
  84. }
  85. //词条
  86. let attrItemOrigin = cc.find('entry/attrList/view/content/item', this.infoNode)
  87. let tips: {tip: string; cfg: IRoleConfig}[] = []
  88. for (let i = 1; i < Data.main.maxRoleQuality; i++) {
  89. let ID = Math.floor(iRole.cfg.ID / 100) * 100 + i
  90. if (RoleConfig[ID.toString()]?.tips)
  91. tips.push({
  92. tip: RoleConfig[ID.toString()].tips,
  93. cfg: RoleConfig[ID.toString()],
  94. })
  95. }
  96. let attrItems = ccUtils.instantChildren(attrItemOrigin, tips.length)
  97. for (let i = 0; i < tips.length; i++) {
  98. let attrItem = attrItems[i]
  99. let tip = tips[i]
  100. cc.find('lock_1', attrItem).active = tip.cfg.quality > iRole.cfg.quality
  101. this.loadTexImg(`Public/role/quality_icon_${tip.cfg.quality}`, attrItem, 'quality_icon')
  102. ccUtils.setColor(QUALITY_COLOR[tip.cfg.quality], attrItem, 'block_2')
  103. let richTextNode = cc.find('richText', attrItem)
  104. ccUtils.setRichLabel(tip.tip, richTextNode)
  105. richTextNode.active = tip.cfg.quality <= iRole.cfg.quality
  106. let blackLb = cc.find('blackLb', attrItem)
  107. ccUtils.setLabel(tip.tip, blackLb)
  108. blackLb.active = tip.cfg.quality > iRole.cfg.quality
  109. cc.find('btn_promote', attrItem).active =
  110. iRole.cfg.quality + 1 == tip.cfg.quality && Mgr.goods.checkRoleBreakNeed(iRole).canUp
  111. cc.tween(cc.find('btn_promote/arrow_1', attrItem))
  112. .then(cc.tween().to(0.5, {y: 8}).to(0.5, {y: 18}))
  113. .repeatForever()
  114. .start()
  115. }
  116. //技能
  117. let skillIDs = RoleConfig[iRole.hero.id].showSkillID
  118. let showSkillCfgArr = skillIDs.map(v => RoleShowSkillConfig[v])
  119. let skillNodes = cc.find('skills', this.skillNode).children
  120. for (let i = 0; i < showSkillCfgArr.length; i++) {
  121. let showSkillCfg = showSkillCfgArr[i]
  122. let skillItem = skillNodes[i]
  123. ccUtils.setLabel(showSkillCfg.name, skillItem, 'skillName')
  124. ccUtils.setRichLabel(showSkillCfg.tip, skillItem, 'skill_rt')
  125. if (showSkillCfg.attrNum.length > 0) {
  126. let i18nLb = cc.find('skill_rt', skillItem).getComponent(i18nLabel)
  127. i18nLb.init(
  128. showSkillCfg.tip,
  129. showSkillCfg.attrNum.map(v => v.toString()),
  130. )
  131. }
  132. this.loadTexImg(`RoleUI/skillIcon/${showSkillCfg.icon}`, skillItem, 'icon')
  133. }
  134. //cc.find('btn_auto_upgrade', this.node).active = !this.levelNeed.isMax && !iRole.isAlter
  135. cc.find('btn_upgrade', this.node).active = !this.levelNeed.isMax && !iRole.isAlter
  136. cc.find('btn_join', this.node).active = this.roleCanUp(this.iRole)
  137. // cc.find('button_reset', this.node).active =
  138. // this.iRole.hero.lv > 1 || (this.iRole.grade > 0 && this.iRole.cfg.qualityType >= QUALITY_TYPE.elite)
  139. if (this.levelNeed.canUp && this.iRole.hero.lv == 2 && !Mgr.goods.roleIsUp(this.iRole)) {
  140. // 打完第一关 升级角色
  141. Mgr.global.tryShowUserGuide(['2_4', '2_5'])
  142. }
  143. if (this.iRole.hero.lv == 3 && !Mgr.goods.roleIsUp(this.iRole)) {
  144. // 打完第一关 上阵角色
  145. Mgr.global.tryShowUserGuide(['2_5'])
  146. }
  147. //this.showChangeArrow()
  148. }
  149. roleCanUp(role: IRole): boolean {
  150. return !Data.user.teamRole[role.cfg.profession - 1]
  151. }
  152. changeRole(isLeft: boolean) {
  153. let curIndex = Data.user.teamRole.indexOf(this.iRole)
  154. //根据isLeft找到当前位置往左第一个非空的对象或者当前位置往右第一个非空的对象
  155. let roleArr = isLeft ? Data.user.teamRole.slice(0, curIndex) : Data.user.teamRole.slice(curIndex + 1)
  156. roleArr = roleArr.filter(iRole => iRole)
  157. if (roleArr.length > 0) {
  158. this.iRole = isLeft ? roleArr[roleArr.length - 1] : roleArr[0]
  159. this.initRole()
  160. }
  161. }
  162. showChangeArrow() {
  163. let curIndex = Data.user.teamRole.indexOf(this.iRole)
  164. //根据isLeft找到当前位置往左第一个非空的对象或者当前位置往右第一个非空的对象
  165. let leftArr = Data.user.teamRole.slice(0, curIndex).filter(iRole => iRole)
  166. let rightArr = Data.user.teamRole.slice(curIndex + 1).filter(iRole => iRole)
  167. cc.find('arrow_left', this.node).active = leftArr.length > 0 && Mgr.goods.roleIsUp(this.iRole)
  168. cc.find('arrow_right', this.node).active = rightArr.length > 0 && Mgr.goods.roleIsUp(this.iRole)
  169. }
  170. //网络事件=======================================
  171. onUpdateRsp() {
  172. Mgr.audio.playSFX(SOUND.goodsUp)
  173. Mgr.ui.show(UI.PowerUpUI, `+${this.iRole.power - this.lastPower}`)
  174. this.initRole()
  175. ccUtils.playAni('lvup', 0, this.node, 'lvupAni')
  176. }
  177. onUpRsp() {
  178. cc.find('btn_join', this.node).active = this.roleCanUp(this.iRole)
  179. }
  180. //触发事件=======================================
  181. // 点击事件=======================================
  182. onLevelClick(e, isOneClick: string) {
  183. if (this.levelNeed) {
  184. if (this.levelNeed.isMax) {
  185. Mgr.ui.tip(LANGUAGE_TYPE.maxLevel)
  186. } else if (this.levelNeed.canUp) {
  187. let num = isOneClick == '1' ? 0 : 1
  188. let data: heroUpgrade = {
  189. num,
  190. sid: this.iRole.hero.sid,
  191. }
  192. Mgr.net.send(msgCmd.cmd_hero_upgrade, data)
  193. } else {
  194. Mgr.ui.showObtain(this.levelNeed)
  195. }
  196. }
  197. }
  198. onResetClick() {
  199. this.iRole.isAlter ? Mgr.ui.tip(LANGUAGE_TYPE.notReset) : Mgr.ui.show(UI.RoleResetUI, this.iRole)
  200. }
  201. onUpClick() {
  202. Mgr.net.send(msgCmd.cmd_embattle_battle, {
  203. sid: this.iRole.hero.sid,
  204. pos: this.iRole.cfg.profession,
  205. skill: false,
  206. })
  207. }
  208. onLeftClick() {
  209. this.changeRole(true)
  210. }
  211. onRightClick() {
  212. this.changeRole(false)
  213. }
  214. onToggleClick(e) {
  215. this.toggleIndex = e.target.parent.children.indexOf(e.target)
  216. this.initToggles()
  217. }
  218. }