UI_Rank.ts 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import { _decorator, Component, Node, Toggle } from 'cc';
  2. import { GameUILayers, gui } from 'db://assets/core/ui/ui';
  3. import ui_base from 'db://assets/core/ui/ui_base';
  4. import { ModuleDef } from 'db://assets/Scripts/ModuleDef';
  5. import { Layout_Rank } from './Layout_Rank';
  6. import { ani_ui } from '../UI_Main/UI_Main';
  7. import PlayerData from '../../game/PlayerData';
  8. import { ch } from 'db://assets/ch/ch';
  9. import { UIWaiting } from 'db://assets/module_basic/ui_waiting/UIWaiting';
  10. import { Hall } from 'db://assets/Scripts/Hall';
  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. constructor() {
  19. super(ModuleDef.GAME, 'ui/UI_Rank/Rank', GameUILayers.HUD, Layout_Rank);
  20. }
  21. protected async 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_skin_item).showInfo(index + 1, this._data1[index]);
  30. }
  31. layout.onList2 = (item: Node, index: number) => {
  32. // item.getComponent(ui_skin_block).showInfo(index + 1, this._data2[index]);
  33. }
  34. layout.list1.numItems = type == 1 ? 10 : 0;
  35. layout.list2.numItems = type == 2 ? 10 : 0;
  36. layout.Rank_Toggle_1.isChecked = type == 1;
  37. layout.Rank_Toggle_2.isChecked = type == 2;
  38. this.show();
  39. this.onToggleEvent(layout.Rank_Toggle_1, (tg: Toggle, i: page) => { if (tg.isChecked) this.show(i) }, this, 1);
  40. this.onToggleEvent(layout.Rank_Toggle_2, (tg: Toggle, i: page) => { if (tg.isChecked) this.show(i) }, this, 2);
  41. }
  42. private async show(t?: null | page) {
  43. if (t != null) {
  44. if (t == type) return;
  45. type = t;
  46. // button_sound();
  47. }
  48. const layout = this.getLayout<Layout_Rank>();
  49. await gui.show(UIWaiting);
  50. if (type == 1) {
  51. layout.list1.node.active =true;
  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. // layout.own_item.showInfo(index, type, this._ower, true);
  61. }
  62. gui.close(UIWaiting);
  63. }
  64. if(type == 2){
  65. layout.list2.node.active = true;
  66. }
  67. }
  68. }