RankListUI.ts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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.ui.hide(UI.CurrencyUI)
  35. Mgr.net.add(msgCmd.cmd_ranking_data_rsp, this, this.onRankRsp)
  36. for (let item of this.rankingCode) {
  37. let data: rankingData = {type: item},
  38. rank: rankItem = {
  39. checkDone: false,
  40. rankListData: [],
  41. userRankInfo: null,
  42. }
  43. this.rankAllData.set(item, rank)
  44. Mgr.net.send(msgCmd.cmd_ranking_data, data)
  45. }
  46. this.selType = RankType.stageRanking
  47. ccUtils.setTogglesChecked(0, this.rankTypeList)
  48. }
  49. onHide(): any {
  50. Mgr.event.removeAll(this)
  51. }
  52. //虚位以待
  53. initVacant(node: cc.Node, isVacant: boolean) {
  54. isVacant ? ccUtils.setLabel(LANGUAGE_TYPE.isVacant, node, 'name') : ''
  55. //不可视其他节点
  56. cc.find('player_frame_1', node).active = !isVacant
  57. cc.find('levelNum', node).active = !isVacant
  58. cc.find('block3', node).active = !isVacant
  59. }
  60. //初始化角色信息
  61. initInfo(node: cc.Node, info: rankingInfo, isPre: boolean) {
  62. this.initVacant(node, false)
  63. //排名名次
  64. let baseUrl = isPre ? 'rank_bottom_1/rankNum' : 'type_base1/rankNum'
  65. ccUtils.setLabel(info.ranking.toString(), node, baseUrl)
  66. //玩家头像
  67. this.loadTexImg(info.role.avatar.toString(), node, 'player_frame_1/0')
  68. //玩家名称
  69. ccUtils.setLabel(info.role.nickname, node, 'name')
  70. //等级
  71. cc.find('levelNum', node).getComponent(i18nLabel).setParamByIndex(info.role.level.toString(), 0)
  72. //等级&战力图标显示
  73. cc.find('block3/icon_rank_1', node).active = this.selType == RankType.stageRanking
  74. cc.find('block3/icon_rank_2', node).active = this.selType == RankType.powerRanking
  75. //等级&战力信息显示
  76. cc.find('block3/level', node).active = this.selType == RankType.stageRanking
  77. cc.find('block3/power', node).active = this.selType == RankType.powerRanking
  78. cc.find('block3/label', node).active = this.selType == RankType.powerRanking
  79. if (this.selType == RankType.stageRanking) {
  80. ccUtils.setLabel(
  81. `${Mgr.i18n.getLabel(StageInfoConfig[info.num].name)}-${StageInfoConfig[info.num].des}`,
  82. node,
  83. 'block3/level',
  84. )
  85. } else {
  86. ccUtils.setLabel(info.num.toString(), node, 'block3/label')
  87. }
  88. }
  89. initUI() {
  90. let data = this.rankAllData.get(this.selType),
  91. listData = data.rankListData,
  92. user = data.userRankInfo
  93. //初始化前三名
  94. for (let i = Ranking.first; i <= Ranking.third; i++) {
  95. let preNode = cc.find(`rankPre${i + 1}`, this.node)
  96. listData.length > i ? this.initInfo(preNode, listData[i], true) : this.initVacant(preNode, true)
  97. }
  98. //初始化排行
  99. this.rankList.numItems = listData.length - 3 > 0 ? listData.length - 3 : 0
  100. //初始化用户信息
  101. this.initInfo(this.userNode, user, false)
  102. }
  103. initRankListItem(node: cc.Node, index: number) {
  104. let data = this.rankAllData.get(this.selType),
  105. listData = data.rankListData
  106. this.initInfo(node, listData[index + Ranking.third + 1], false)
  107. }
  108. //UI或者其他函数=======================================
  109. //网络事件=======================================
  110. onRankRsp(data: rankingDataRsp) {
  111. let rank = this.rankAllData.get(data.type)
  112. rank.rankListData = data.list
  113. rank.userRankInfo = data.myslef
  114. rank.checkDone = true
  115. let checkOut = Array.from(this.rankAllData.values()).every(value => value.checkDone === true)
  116. if (checkOut) {
  117. let index = 0
  118. this.rankAllData.forEach(value => {
  119. let interact = value.rankListData.length > 0 && value.userRankInfo != undefined
  120. this.rankTypeList.children[index].getComponent(cc.Toggle).enabled = interact
  121. index += 1
  122. })
  123. this.initUI()
  124. }
  125. }
  126. //触发事件=======================================
  127. // @render
  128. // showRender() {}
  129. // 点击事件=======================================
  130. onToggleClick(event, data) {
  131. Mgr.audio.playSFX(SOUND.toggleClick)
  132. this.selType = parseInt(data)
  133. this.initUI()
  134. }
  135. }