UI_Rank.ts 3.8 KB

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