UI_Rank.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. const { ccclass, property } = _decorator;
  8. type page = 1 | 2;//1总榜2好友榜
  9. let type: page = 1;
  10. @ccclass('UI_Rank')
  11. export class UI_Rank extends ui_base {
  12. constructor() {
  13. super(ModuleDef.GAME, 'ui/UI_Rank/Rank', GameUILayers.HUD,Layout_Rank);
  14. }
  15. protected async onCreated() {
  16. const layout = this.getLayout<Layout_Rank>();
  17. ani_ui(layout.Close_Btn.node.parent);
  18. this.onButtonEvent(layout.Close_Btn, async (button: any) => {
  19. //关闭设置界面
  20. gui.close(UI_Rank);
  21. }, this);
  22. layout.onList1 = (item: Node, index: number) => {
  23. // item.getComponent(ui_skin_item).showInfo(index + 1, this._data1[index]);
  24. }
  25. layout.onList2 = (item: Node, index: number) => {
  26. // item.getComponent(ui_skin_block).showInfo(index + 1, this._data2[index]);
  27. }
  28. layout.list1.numItems = type == 1 ? 10 : 0;
  29. layout.list2.numItems = type == 2 ? 10 : 0;
  30. layout.Rank_Toggle_1.isChecked = type == 1;
  31. layout.Rank_Toggle_2.isChecked = type == 2;
  32. this.show();
  33. this.onToggleEvent(layout.Rank_Toggle_1, (tg: Toggle, i: page) => { if (tg.isChecked) this.show(i) }, this, 1);
  34. this.onToggleEvent(layout.Rank_Toggle_2, (tg: Toggle, i: page) => { if (tg.isChecked) this.show(i) }, this, 2);
  35. }
  36. private async show(t?: null | page) {
  37. if (t != null) {
  38. if (t == type) return;
  39. type = t;
  40. // button_sound();
  41. }
  42. const layout = this.getLayout<Layout_Rank>();
  43. layout.list1.numItems = type == 1 ? 10: 0;
  44. layout.list2.numItems = type == 2 ? 10: 0;
  45. layout.list1.node.active = type == 1;
  46. layout.list2.node.active = type == 2;
  47. }
  48. }