RankListUI.ts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /** @format */
  2. import {BaseUI} from './BaseUI'
  3. import {Mgr} from '../GameControl'
  4. import {ccUtils} from '../utils/ccUtils'
  5. import {observer, render, node, label, editBox, list} from '../mobx/observer'
  6. import {msgCmd} from '../proto/msg_cmd'
  7. import List from '../uiutils/List'
  8. import {rankingData, rankingDataRsp} from '../proto/game'
  9. import {rankingInfo} from '../proto/typedef'
  10. import {i18nLabel} from '../uiutils/i18nLabel'
  11. import {StageInfoConfig} from '../config/StageInfoConfig'
  12. import {LANGUAGE_TYPE, Ranking, RankType} from '../enums/Enum'
  13. import {UI} from '../enums/UI'
  14. import {SOUND} from '../enums/Sound'
  15. const {ccclass, property} = cc._decorator
  16. interface rankItem {
  17. checkDone: boolean
  18. rankListData: rankingInfo[]
  19. userRankInfo: rankingInfo
  20. }
  21. @ccclass
  22. @observer
  23. export class RankListUI extends BaseUI {
  24. @node('common_frame4')
  25. userNode: cc.Node
  26. @node('rankTypeList')
  27. rankTypeList: cc.Node
  28. @list('bottom1')
  29. rankList: List
  30. rankingCode: RankType[] = [RankType.stageRanking, RankType.powerRanking]
  31. rankAllData: Map<RankType, rankItem> = new Map()
  32. selType: RankType
  33. onShow(args, fromUI: number) {
  34. Mgr.net.add(msgCmd.cmd_ranking_data_rsp, this, this.onRankRsp)
  35. for (let item of this.rankingCode) {
  36. let data: rankingData = {type: item},
  37. rank: rankItem = {
  38. checkDone: false,
  39. rankListData: [],
  40. userRankInfo: null,
  41. }
  42. this.rankAllData.set(item, rank)
  43. Mgr.net.send(msgCmd.cmd_ranking_data, data)
  44. }
  45. this.selType = RankType.stageRanking
  46. ccUtils.setTogglesChecked(0, this.rankTypeList)
  47. }
  48. onHide(): any {
  49. Mgr.event.removeAll(this)
  50. }
  51. //虚位以待
  52. initVacant(node: cc.Node, isVacant: boolean) {
  53. isVacant ? ccUtils.setLabel(LANGUAGE_TYPE.isVacant, node, 'name') : ''
  54. //不可视其他节点
  55. cc.find('player_frame_1', node).active = !isVacant
  56. cc.find('levelNum', node).active = !isVacant
  57. cc.find('block3', node).active = !isVacant
  58. }
  59. //初始化角色信息
  60. initInfo(node: cc.Node, info: rankingInfo, isPre: boolean) {
  61. this.initVacant(node, false)
  62. //排名名次
  63. let baseUrl = isPre ? 'rank_bottom_1/rankNum' : 'type_base1/rankNum'
  64. ccUtils.setLabel(info.ranking.toString(), node, baseUrl)
  65. //玩家头像
  66. this.loadTexImg(info.role.avatar.toString(), node, 'player_frame_1/0')
  67. //玩家名称
  68. ccUtils.setLabel(info.role.nickname, node, 'name')
  69. //等级
  70. cc.find('levelNum', node).getComponent(i18nLabel).setParamByIndex(info.role.level.toString(), 0)
  71. //等级&战力图标显示
  72. cc.find('block3/icon_rank_1', node).active = this.selType == RankType.stageRanking
  73. cc.find('block3/icon_rank_2', node).active = this.selType == RankType.powerRanking
  74. //等级&战力信息显示
  75. cc.find('block3/level', node).active = this.selType == RankType.stageRanking
  76. cc.find('block3/power', node).active = this.selType == RankType.powerRanking
  77. cc.find('block3/label', node).active = this.selType == RankType.powerRanking
  78. if (this.selType == RankType.stageRanking) {
  79. ccUtils.setLabel(
  80. `${Mgr.i18n.getLabel(StageInfoConfig[info.num].name)}-${StageInfoConfig[info.num].des}`,
  81. node,
  82. 'block3/level',
  83. )
  84. } else {
  85. ccUtils.setLabel(info.num.toString(), node, 'block3/label')
  86. }
  87. }
  88. initUI() {
  89. let data = this.rankAllData.get(this.selType),
  90. listData = data.rankListData,
  91. user = data.userRankInfo
  92. //初始化前三名
  93. for (let i = Ranking.first; i <= Ranking.third; i++) {
  94. let preNode = cc.find(`rankPre${i + 1}`, this.node)
  95. listData.length > i ? this.initInfo(preNode, listData[i], true) : this.initVacant(preNode, true)
  96. }
  97. //初始化排行
  98. this.rankList.numItems = listData.length - 3 > 0 ? listData.length - 3 : 0
  99. //初始化用户信息
  100. this.initInfo(this.userNode, user, false)
  101. }
  102. initRankListItem(node: cc.Node, index: number) {
  103. let data = this.rankAllData.get(this.selType),
  104. listData = data.rankListData
  105. this.initInfo(node, listData[index + Ranking.third + 1], false)
  106. }
  107. //UI或者其他函数=======================================
  108. //网络事件=======================================
  109. onRankRsp(data: rankingDataRsp) {
  110. let rank = this.rankAllData.get(data.type)
  111. rank.rankListData = data.list
  112. rank.userRankInfo = data.myslef
  113. rank.checkDone = true
  114. let checkOut = Array.from(this.rankAllData.values()).every(value => value.checkDone === true)
  115. if (checkOut) {
  116. let index = 0
  117. this.rankAllData.forEach(value => {
  118. let interact = value.rankListData.length > 0 && value.userRankInfo != undefined
  119. this.rankTypeList.children[index].getComponent(cc.Toggle).enabled = interact
  120. index += 1
  121. })
  122. this.initUI()
  123. }
  124. }
  125. //触发事件=======================================
  126. // @render
  127. // showRender() {}
  128. // 点击事件=======================================
  129. onToggleClick(event, data) {
  130. Mgr.audio.playSFX(SOUND.toggleClick)
  131. this.selType = parseInt(data)
  132. this.initUI()
  133. }
  134. }