RoleUI.ts 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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('levelGuide')
  25. levelGuide: cc.Node
  26. lastPower: number
  27. onShow(args: IRole, fromUI: number) {
  28. Mgr.net.add(msgCmd.cmd_hero_upgrade_rsp, this, this.onUpdateRsp)
  29. Mgr.net.add(msgCmd.cmd_hero_reset_rsp, this, this.initRole)
  30. Mgr.net.add(msgCmd.cmd_embattle_battle_rsp, this, this.onUpRsp)
  31. this.iRole = args
  32. this.initRole()
  33. Mgr.event.add(EVENT.goodsChangeSync, this, this.initRole)
  34. Mgr.ui.show(UI.CurrencyUI, [GOODS.coin, GOODS.diamond])
  35. if (this.levelNeed.canUp && this.iRole.hero.lv == 1) {
  36. // 打完第一关 升级角色
  37. this.levelGuide.active = Mgr.global.tryShowUserGuide(['2_3'])
  38. }
  39. }
  40. onHide(): any {
  41. Mgr.event.removeAll(this)
  42. }
  43. initRole() {
  44. let iRole = this.iRole
  45. this.lastPower = iRole.power
  46. //初始技能
  47. let showSkillCfg = RoleShowSkillConfig[RoleConfig[iRole.hero.id].showSkillID[0]]
  48. ccUtils.setLabel(showSkillCfg.name, this.node, 'skillName')
  49. ccUtils.setRichLabel(showSkillCfg.tip, this.node, 'skill_rt')
  50. if (showSkillCfg.attrNum.length > 0) {
  51. let i18nLb = cc.find('skill_rt', this.node).getComponent(i18nLabel)
  52. i18nLb.init(
  53. showSkillCfg.tip,
  54. showSkillCfg.attrNum.map(v => v.toString()),
  55. )
  56. }
  57. let skillItem = cc.find('skill_item', this.node)
  58. this.loadTexImg(`RoleUI/skillIcon/${showSkillCfg.icon}`, skillItem, 'icon')
  59. this.loadTexImg(`Public/goodsQuality/item_frame${showSkillCfg.qualityType}`, skillItem, 'item_frame')
  60. //属性值
  61. let attack = iRole.cfg.profession == PROFESSION.mage ? iRole.spellAttack : iRole.attack
  62. let attackIcon = iRole.cfg.profession == PROFESSION.mage ? ATTR_NAME.spellAttack : ATTR_NAME.attack
  63. this.loadTexImg(`Public/allAttr/${attackIcon}`, this.node, 'attackIcon')
  64. ccUtils.setLabel(Math.toKMBNum(attack), this.node, 'attack')
  65. ccUtils.setLabel(Math.toKMBNum(iRole.HP), this.node, 'hp_lb')
  66. ccUtils.setLabel(Math.toKMBNum(iRole.power), this.node, 'power')
  67. //英雄
  68. let roleNode = cc.find('role', this.node)
  69. ccUtils.setLabel(iRole.cfg.name, roleNode, 'roleName')
  70. ccUtils.setLabel(LANGUAGE_TYPE[PROFESSION[iRole.cfg.profession]], roleNode, 'prof_name')
  71. let roleQualityConfig = RoleQualityConfig[iRole.cfg.quality]
  72. ccUtils.setLabel(`lv.${iRole.hero.lv}/${roleQualityConfig.maxLv}`, roleNode, 'lv')
  73. this.loadTexImg(`Public/role/streamer_${iRole.cfg.qualityType}`, roleNode, 'streamer')
  74. this.loadTexImg(`Public/role/role_type_${iRole.cfg.profession}`, roleNode, 'role_type')
  75. this.loadTexImg(`Public/role/base_light_${iRole.cfg.qualityType}`, roleNode, 'base_light')
  76. this.loadTexImg(`Public/role/base_level_${iRole.cfg.qualityType}`, roleNode, 'base_level')
  77. Mgr.global.initRoleSpine(iRole, roleNode, 'spine')
  78. ccUtils.instantChildren(cc.find('stars/star', roleNode), iRole.grade)
  79. ccUtils.setLabel(iRole.cfg.cost.toString(), roleNode, 'cost/lb')
  80. //需要资源
  81. this.levelNeed = Mgr.goods.checkRoleLevelUpNeed(iRole)
  82. cc.find('needLy', this.node).active = !this.levelNeed.isMax
  83. if (!this.levelNeed.isMax) {
  84. let needItems = ccUtils.instantChildren(cc.find('needLy/item', this.node), this.levelNeed.need.length)
  85. Mgr.goods.initNeedGoods(this.levelNeed.need, needItems, this)
  86. }
  87. //词条
  88. let attrItemOrigin = cc.find('attrList/view/content/item', this.node)
  89. let tips: {tip: string; cfg: IRoleConfig}[] = []
  90. for (let i = 1; i < Data.main.maxRoleQuality; i++) {
  91. let ID = Math.floor(iRole.cfg.ID / 100) * 100 + i
  92. if (RoleConfig[ID.toString()]?.tips)
  93. tips.push({
  94. tip: RoleConfig[ID.toString()].tips,
  95. cfg: RoleConfig[ID.toString()],
  96. })
  97. }
  98. let attrItems = ccUtils.instantChildren(attrItemOrigin, tips.length)
  99. for (let i = 0; i < tips.length; i++) {
  100. let attrItem = attrItems[i]
  101. let tip = tips[i]
  102. cc.find('icon/lock_1', attrItem).active = tip.cfg.quality > iRole.cfg.quality
  103. this.loadTexImg(`Public/goodsQuality/item_frame${tip.cfg.qualityType}`, attrItem, 'icon/item_frame')
  104. let richTextNode = cc.find('richText', attrItem)
  105. ccUtils.setRichLabel(tip.tip, richTextNode)
  106. this.scheduleOnce(() => {
  107. if (attrItem.activeInHierarchy) {
  108. if (tip.cfg.quality > iRole.cfg.quality) ccUtils.setRichLabelGray(richTextNode)
  109. let layout = attrItem.getComponent(cc.Layout)
  110. layout.resizeMode =
  111. richTextNode.height < 65 ? cc.Layout.ResizeMode.NONE : cc.Layout.ResizeMode.CONTAINER
  112. layout.updateLayout()
  113. if (richTextNode.height < 65) {
  114. attrItem.height = 65
  115. }
  116. }
  117. })
  118. }
  119. cc.find('btn_auto_upgrade', this.node).active = !this.levelNeed.isMax && !iRole.isAlter
  120. cc.find('btn_upgrade', this.node).active = !this.levelNeed.isMax && !iRole.isAlter
  121. cc.find('btn_go_altar', this.node).active = iRole.isAlter
  122. cc.find('btn_join', this.node).active = this.roleCanUp(this.iRole)
  123. cc.find('button_reset', this.node).active =
  124. this.iRole.hero.lv > 1 || (this.iRole.grade > 0 && this.iRole.cfg.qualityType >= QUALITY_TYPE.elite)
  125. if (this.levelNeed.canUp && this.iRole.hero.lv == 2 && !Mgr.goods.roleIsUp(this.iRole)) {
  126. // 打完第一关 升级角色
  127. Mgr.global.tryShowUserGuide(['2_4', '2_5'])
  128. }
  129. if (this.iRole.hero.lv == 3 && !Mgr.goods.roleIsUp(this.iRole)) {
  130. // 打完第一关 上阵角色
  131. Mgr.global.tryShowUserGuide(['2_5'])
  132. }
  133. this.showChangeArrow()
  134. }
  135. roleCanUp(role: IRole): boolean {
  136. return Data.user.teamRole.findIndex(iRole => iRole && iRole.hero.sid == role.hero.sid) < 0
  137. }
  138. changeRole(isLeft: boolean) {
  139. let curIndex = Data.user.teamRole.indexOf(this.iRole)
  140. //根据isLeft找到当前位置往左第一个非空的对象或者当前位置往右第一个非空的对象
  141. let roleArr = isLeft ? Data.user.teamRole.slice(0, curIndex) : Data.user.teamRole.slice(curIndex + 1)
  142. roleArr = roleArr.filter(iRole => iRole)
  143. if (roleArr.length > 0) {
  144. this.iRole = isLeft ? roleArr[roleArr.length - 1] : roleArr[0]
  145. this.initRole()
  146. }
  147. }
  148. showChangeArrow() {
  149. let curIndex = Data.user.teamRole.indexOf(this.iRole)
  150. //根据isLeft找到当前位置往左第一个非空的对象或者当前位置往右第一个非空的对象
  151. let leftArr = Data.user.teamRole.slice(0, curIndex).filter(iRole => iRole)
  152. let rightArr = Data.user.teamRole.slice(curIndex + 1).filter(iRole => iRole)
  153. cc.find('arrow_left', this.node).active = leftArr.length > 0 && Mgr.goods.roleIsUp(this.iRole)
  154. cc.find('arrow_right', this.node).active = rightArr.length > 0 && Mgr.goods.roleIsUp(this.iRole)
  155. }
  156. //网络事件=======================================
  157. onUpdateRsp() {
  158. Mgr.audio.playSFX(SOUND.goodsUp)
  159. Mgr.ui.show(UI.PowerUpUI, `+${this.iRole.power - this.lastPower}`)
  160. this.initRole()
  161. ccUtils.playAni('lvup', 0, this.node, 'lvupAni')
  162. }
  163. onUpRsp() {
  164. cc.find('btn_join', this.node).active = this.roleCanUp(this.iRole)
  165. }
  166. //触发事件=======================================
  167. // 点击事件=======================================
  168. onLevelClick(e, isOneClick: string) {
  169. if (this.levelNeed) {
  170. if (this.levelNeed.isMax) {
  171. Mgr.ui.tip(LANGUAGE_TYPE.maxLevel)
  172. } else if (this.levelNeed.canUp) {
  173. let num = isOneClick == '1' ? 0 : 1
  174. let data: heroUpgrade = {
  175. num,
  176. sid: this.iRole.hero.sid,
  177. }
  178. Mgr.net.send(msgCmd.cmd_hero_upgrade, data)
  179. } else {
  180. Mgr.ui.showObtain(this.levelNeed)
  181. }
  182. }
  183. }
  184. onResetClick() {
  185. this.iRole.isAlter ? Mgr.ui.tip(LANGUAGE_TYPE.notReset) : Mgr.ui.show(UI.RoleResetUI, this.iRole)
  186. }
  187. onUpClick() {
  188. Mgr.ui.show(UI.RoleExchangeUI, this.iRole)
  189. }
  190. onLeftClick() {
  191. this.changeRole(true)
  192. }
  193. onRightClick() {
  194. this.changeRole(false)
  195. }
  196. }