RoleResetUI.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 {DataConfig} from '../config/DataConfig'
  9. import {i18nLabel} from '../uiutils/i18nLabel'
  10. import {embattleBattleRsp, heroReset, heroResetRsp} from '../proto/game'
  11. import {hero} from '../proto/typedef'
  12. import {RoleQualityConfig} from '../config/RoleQualityConfig'
  13. import {RoleLevelConfig} from '../config/RoleLevelConfig'
  14. import {LANGUAGE_TYPE} from '../enums/Enum'
  15. import {IRewardNty} from '../interface/UIInterface'
  16. import {IRole} from '../interface/GlobalInterface'
  17. import {SOUND} from '../enums/Sound'
  18. const {ccclass, property} = cc._decorator
  19. @ccclass
  20. @observer
  21. export class RoleResetUI extends BaseUI {
  22. iRole: IRole
  23. toggleIndex: number = 0
  24. onShow(args: IRole, fromUI: number) {
  25. Mgr.net.add(msgCmd.cmd_hero_reset_rsp, this, this.onResetRsp)
  26. this.iRole = args
  27. this.toggleIndex = 0
  28. ccUtils.setTogglesChecked(this.toggleIndex, this.node, 'toggles')
  29. this.initUI()
  30. }
  31. onHide(): any {
  32. Mgr.event.removeAll(this)
  33. }
  34. initUI() {
  35. //显示英雄
  36. let resetRoleNode = cc.find('scrollView/view/content/role', this.node)
  37. let goods = cc.find('scrollView/view/content/goods', this.node)
  38. Mgr.global.initRoleItem(this.iRole, cc.find('role', this.node), this)
  39. let isLvReset = this.toggleIndex == 1
  40. ccUtils.setLabel(isLvReset ? 't48' : 't49', this.node, 'tip')
  41. let resetHero: hero = ccUtils.deepCopy(this.iRole.hero)
  42. resetHero.id = isLvReset ? this.iRole.hero.id : this.iRole.hero.id - this.iRole.grade
  43. resetHero.lv = 1
  44. let resetRole = Mgr.global.buildIRole(resetHero)
  45. Mgr.global.initRoleItem(resetRole, resetRoleNode, this)
  46. cc.find('btn', this.node).active =
  47. (isLvReset && this.iRole.hero.lv > resetHero.lv) || (!isLvReset && this.iRole.grade > 0)
  48. //显示分解列表
  49. let idNumArr = []
  50. for (let i = 2; i <= this.iRole.hero.lv; i++) {
  51. idNumArr = idNumArr.concat(Mgr.goods.getIdNumArr(RoleLevelConfig[i].goods, RoleLevelConfig[i].goodNum))
  52. }
  53. if (this.toggleIndex == 0) {
  54. for (let i = resetRole.cfg.quality + 1; i <= this.iRole.cfg.quality; i++) {
  55. idNumArr = idNumArr.concat(
  56. Mgr.goods.getIdNumArr([RoleQualityConfig[i].resetGoods], [RoleQualityConfig[i].anyQualityNum]),
  57. )
  58. }
  59. }
  60. idNumArr = Mgr.goods.getGoodsList(idNumArr)
  61. let allNodes = ccUtils.instantChildren(goods, idNumArr.length + 1)
  62. Mgr.goods.initGoods(idNumArr, allNodes.slice(1), this)
  63. }
  64. //网络事件=======================================
  65. onResetRsp(data: heroResetRsp, reward: IRewardNty) {
  66. Mgr.ui.showReward(reward)
  67. this.hide()
  68. }
  69. //触发事件=======================================
  70. // @render
  71. // showRender() {}
  72. // 点击事件=======================================
  73. onToggleClick(e) {
  74. Mgr.audio.playSFX(SOUND.toggleClick)
  75. this.toggleIndex = e.target.parent.children.indexOf(e.target)
  76. this.initUI()
  77. }
  78. onSureClick() {
  79. if (Mgr.goods.roleIsUp(this.iRole)) {
  80. Mgr.ui.message(LANGUAGE_TYPE.heroIsUpReset, () => {
  81. this.sendResetReq()
  82. })
  83. } else {
  84. this.sendResetReq()
  85. }
  86. }
  87. sendResetReq() {
  88. let data: heroReset = {level: this.toggleIndex == 1, sid: this.iRole.hero.sid}
  89. Mgr.net.send(msgCmd.cmd_hero_reset, data)
  90. }
  91. }