import { _decorator, Component, Node, Toggle } from 'cc'; import { GameUILayers, gui } from 'db://assets/core/ui/ui'; import ui_base from 'db://assets/core/ui/ui_base'; import { ModuleDef } from 'db://assets/Scripts/ModuleDef'; import { Layout_Rank } from './Layout_Rank'; import { ani_ui } from '../UI_Main/UI_Main'; import PlayerData from '../../game/PlayerData'; import { ch } from 'db://assets/ch/ch'; import { UIWaiting } from 'db://assets/module_basic/ui_waiting/UIWaiting'; import { Hall } from 'db://assets/Scripts/Hall'; import { UI_Rank_Item } from './UI_Rank_Item'; const { ccclass, property } = _decorator; type page = 1 | 2;//1总榜2好友榜 let type: page = 1; @ccclass('UI_Rank') export class UI_Rank extends ui_base { private _owner: { head: string, nickName: string, score: number, userId: number, [key: string]: any }; private _data: { head: string, nickName: string, score: number, userId: number, [key: string]: any }[]; constructor() { super(ModuleDef.GAME, 'ui/UI_Rank/Rank', GameUILayers.HUD, Layout_Rank); } protected async onCreated() { const layout = this.getLayout(); ani_ui(layout.Close_Btn.node.parent); this.onButtonEvent(layout.Close_Btn, async (button: any) => { //关闭设置界面 gui.close(UI_Rank); }, this); layout.onList1 = (item: Node, index: number) => { item.getComponent(UI_Rank_Item).showInfo(index + 1, type, this._data[index], false); } layout.onList2 = (item: Node, index: number) => { // item.getComponent(ui_skin_block).showInfo(index + 1, this._data2[index]); } layout.Rank_Toggle_1.isChecked = type == 1; layout.Rank_Toggle_2.isChecked = type == 2; this.show(); this.onToggleEvent(layout.Rank_Toggle_1, (tg: Toggle, i: page) => { if (tg.isChecked) this.show(i) }, this, 1); this.onToggleEvent(layout.Rank_Toggle_2, (tg: Toggle, i: page) => { if (tg.isChecked) this.show(i) }, this, 2); } private async show(t?: null | page) { if (t != null) { if (t == type) return; type = t; // button_sound(); } const layout = this.getLayout(); if (type == 1||t==null) { await gui.show(UIWaiting); layout.list1.node.active =true; layout.list2.node.active =false; layout.list1.numItems = 0; const d = await Hall.getInstance().player.get_rank_floor(); this._data = d.list; this._owner = d.owner; let index = d.index; layout.list1.numItems=this._data.length; if(!this._owner){ this._owner = { head: Hall.getInstance().player.avatarUrl,nickName:Hall.getInstance().player.nickName, score: 0, userId:0,province:Hall.getInstance().player.user_info.province }; } layout.own1_item.showInfo(index, type, this._owner, true); gui.close(UIWaiting); } if(type == 2){ await gui.show(UIWaiting); layout.list2.node.active = true; layout.list1.node.active =false; layout.list2.numItems = 0; const d = await Hall.getInstance().player.get_rank_floor(); this._data = d.list; this._owner = d.owner; let index = d.index; layout.list2.numItems=this._data.length; if(!this._owner){ this._owner = { head: Hall.getInstance().player.avatarUrl,nickName:Hall.getInstance().player.nickName, score: 0, userId:0,province:Hall.getInstance().player.user_info.province }; } layout.own2_item.showInfo(index, type, this._owner, true); gui.close(UIWaiting); } } }