ServerUI.ts 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 {EVENT, LANGUAGE_TYPE} from '../enums/Enum'
  9. import {HttpUrl} from '../data/HttpUrl'
  10. import List from '../uiutils/List'
  11. import {IServer} from '../interface/GlobalInterface'
  12. import {i18nLabel} from '../uiutils/i18nLabel'
  13. const {ccclass, property} = cc._decorator
  14. @ccclass
  15. @observer
  16. export class ServerUI extends BaseUI {
  17. @list('allList')
  18. allList: List
  19. @list('serverList')
  20. serverList: List
  21. serverArr: IServer[][] = []
  22. curAllIndex: number = 0
  23. onShow(args, fromUI: number) {
  24. this.serverArr.length = 0
  25. this.serverArr.push(Data.main.serverList.filter(v => v.create))
  26. this.serverArr.push(...Data.main.serverList.splitArrBySize(10))
  27. this.allList.numItems = this.serverArr.length
  28. this.serverList.numItems = this.serverArr[this.curAllIndex].length
  29. }
  30. onHide(): any {
  31. Mgr.event.removeAll(this)
  32. }
  33. //UI或者其他函数=======================================
  34. initAllItem(node, index) {
  35. node['index'] = index
  36. cc.find('my', node).active = index == 0
  37. cc.find('lb', node).active = index != 0
  38. cc.find('choose', node).active = index == this.curAllIndex
  39. let i18n = cc.find('lb', node).getComponent(i18nLabel)
  40. i18n.setParamByIndex(`${(index - 1) * 10 + 1}-${index * 10}`, 0)
  41. }
  42. initServerItem(node, index) {
  43. let server: IServer = this.serverArr[this.curAllIndex][index]
  44. node['server'] = server
  45. ccUtils.setLabel(server.server_name, node, 'serverName')
  46. let serverColor = ['#E2E2E2', '#FF6C00', '#66FF00']
  47. ccUtils.setColor(serverColor[server.state], node, 'dl_piont/block5')
  48. cc.find('frame', node).active = server.create
  49. }
  50. //网络事件=======================================
  51. //触发事件=======================================
  52. onAllItemClick(e) {
  53. this.curAllIndex = e.currentTarget['index']
  54. this.allList.numItems = this.serverArr.length
  55. this.serverList.numItems = this.serverArr[this.curAllIndex].length
  56. }
  57. // 点击事件=======================================
  58. onServerClick(e) {
  59. Mgr.event.trigger(EVENT.chooseServer, e.currentTarget['server'])
  60. this.hide()
  61. }
  62. }