UI_Rank.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import { _decorator, Toggle,Node } from "cc";
  2. import { WECHAT } from "cc/env";
  3. import { GameUILayers, gui } from "../../../core/ui/ui";
  4. import ui_base from "../../../core/ui/ui_base";
  5. import { UIWaiting } from "../../../module_basic/ui_waiting/UIWaiting";
  6. import { Hall } from "../../../Scripts/Hall";
  7. import { ModuleDef } from "../../../Scripts/ModuleDef";
  8. import { ani_ui } from "../UI_Main/UI_Main";
  9. import { Layout_Rank } from "./Layout_Rank";
  10. import { UI_Rank_Item } from "./UI_Rank_Item";
  11. const { ccclass, property } = _decorator;
  12. type page = 1 | 2;//1总榜2好友榜
  13. let type: page = 1;
  14. @ccclass('UI_Rank')
  15. export class UI_Rank extends ui_base {
  16. private _owner: { head: string, nickName: string, score: number, userId: number, [key: string]: any };
  17. private _data: { head: string, nickName: string, score: number, userId: number, [key: string]: any }[];
  18. _openContext: any;
  19. constructor() {
  20. super(ModuleDef.GAME, 'ui/UI_Rank/Rank', GameUILayers.HUD, Layout_Rank);
  21. }
  22. protected async onCreated() {
  23. const layout = this.getLayout<Layout_Rank>();
  24. ani_ui(layout.Close_Btn.node.parent);
  25. this.onButtonEvent(layout.Close_Btn, async (button: any) => {
  26. //关闭设置界面
  27. gui.close(UI_Rank);
  28. }, this);
  29. layout.onList1 = (item: Node, index: number) => {
  30. item.getComponent(UI_Rank_Item).showInfo(index + 1, type, this._data[index], false);
  31. }
  32. layout.onList2 = (item: Node, index: number) => {
  33. // item.getComponent(ui_skin_block).showInfo(index + 1, this._data2[index]);
  34. }
  35. layout.Rank_Toggle_1.isChecked = type == 1;
  36. layout.Rank_Toggle_2.isChecked = type == 2;
  37. this.show();
  38. this.onToggleEvent(layout.Rank_Toggle_1, (tg: Toggle, i: page) => { if (tg.isChecked) this.show(i) }, this, 1);
  39. this.onToggleEvent(layout.Rank_Toggle_2, (tg: Toggle, i: page) => { if (tg.isChecked) this.show(i) }, this, 2);
  40. }
  41. private async show(t?: null | page) {
  42. if (t != null) {
  43. if (t == type) return;
  44. type = t;
  45. // button_sound();
  46. }
  47. const layout = this.getLayout<Layout_Rank>();
  48. if (type == 1 || t == null) {
  49. await gui.show(UIWaiting);
  50. layout.list1.node.active = true;
  51. layout.list2.node.active = false;
  52. layout.list1.numItems = 0;
  53. const d = await Hall.getInstance().player.get_rank_floor();
  54. this._data = d.list;
  55. this._owner = d.owner;
  56. let index = d.index;
  57. layout.list1.numItems = this._data.length;
  58. if (!this._owner) {
  59. this._owner = { head: Hall.getInstance().player.avatarUrl, nickName: Hall.getInstance().player.nickName, score: 0, userId: 0, province: Hall.getInstance().player.user_info.province };
  60. }
  61. layout.own1_item.showInfo(index, type, this._owner, true);
  62. gui.close(UIWaiting);
  63. }
  64. if (type == 2) {
  65. await gui.show(UIWaiting);
  66. layout.list2.node.active = true;
  67. layout.list1.node.active = false;
  68. layout.list2.numItems = 0;
  69. const d = await Hall.getInstance().player.get_rank_floor();
  70. this._data = d.list;
  71. this._owner = d.owner;
  72. let index = d.index;
  73. layout.list2.numItems = this._data.length;
  74. if (!this._owner) {
  75. this._owner = { head: Hall.getInstance().player.avatarUrl, nickName: Hall.getInstance().player.nickName, score: 0, userId: 0, province: Hall.getInstance().player.user_info.province };
  76. }
  77. layout.own2_item.showInfo(index, type, this._owner, true);
  78. gui.close(UIWaiting);
  79. }
  80. }
  81. private _reportUserLevel(level: number, listener?: Function, target?: any) {
  82. if (!WECHAT) {
  83. return;
  84. }
  85. }
  86. }