RoleExchangeUI.ts 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 {IRole} from '../interface/GlobalInterface'
  9. import {LANGUAGE_TYPE} from '../enums/Enum'
  10. const {ccclass, property} = cc._decorator
  11. @ccclass
  12. @observer
  13. export class RoleExchangeUI extends BaseUI {
  14. upIndex: number = -1
  15. iRole: IRole
  16. onShow(args: IRole, fromUI: number) {
  17. Mgr.net.add(msgCmd.cmd_embattle_battle_rsp, this, this.onUpRsp)
  18. this.upIndex = -1
  19. this.iRole = args
  20. this.initTeam()
  21. }
  22. onOpenAniOver() {
  23. Mgr.global.tryShowUserGuide(['2_6', '2_7'])
  24. }
  25. onHide(): any {
  26. Mgr.event.removeAll(this)
  27. }
  28. initTeam() {
  29. //显示英雄
  30. let roleNodes = ccUtils.instantChildren(cc.find('roles/item1', this.node), Data.user.maxFightRoleNum)
  31. for (let i = 0; i < Data.user.maxFightRoleNum; i++) {
  32. let node = roleNodes[i]
  33. let lockLevel = Data.user.roleSlotLv
  34. let role = cc.find('role', node)
  35. let iRole = Data.user.teamRole[i]
  36. role.active = iRole != null
  37. cc.find('select_1', node).active = false
  38. let isLock = Data.user.level < lockLevel[i]
  39. cc.find('lock_1', node).active = isLock
  40. cc.find('add_2', node).active = !isLock && !role.active
  41. if (role.active) {
  42. Mgr.global.initRoleItem(iRole, role, this)
  43. }
  44. node['isLock'] = isLock
  45. }
  46. }
  47. //网络事件=======================================
  48. onUpRsp() {
  49. this.hide()
  50. }
  51. //触发事件=======================================
  52. // @render
  53. // showRender() {}
  54. // 点击事件=======================================
  55. onClick(e) {
  56. if (e.target['isLock']) {
  57. Mgr.ui.tip(LANGUAGE_TYPE.slotLock)
  58. return
  59. }
  60. let chooseIndex = e.target.parent.children.indexOf(e.target)
  61. let sameNameIndex = Data.user.teamRole.findIndex(
  62. v => v && Math.floor(v.hero.id / 100) == Math.floor(this.iRole.hero.id / 100),
  63. )
  64. if (sameNameIndex >= 0 && sameNameIndex != chooseIndex) {
  65. Mgr.ui.tip(LANGUAGE_TYPE.sameRoleOrCard)
  66. return
  67. }
  68. e.target.parent.children.forEach((node, index) => {
  69. cc.find('select_1', node).active = node == e.target
  70. if (e.target == node) {
  71. this.upIndex = index
  72. }
  73. })
  74. }
  75. onSureClick() {
  76. if (this.upIndex >= 0) {
  77. Mgr.net.send(msgCmd.cmd_embattle_battle, {
  78. sid: this.iRole.hero.sid,
  79. pos: this.upIndex + 1,
  80. skill: false,
  81. })
  82. }
  83. }
  84. }