import { _decorator, Component, log, 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/Script/ModuleDef'; import { Layout_rank } from './Layout_rank'; import ch_audio from 'db://assets/ch/audio/audio'; import { UIWaiting } from 'db://assets/module_basic/ui_waiting/UIWaiting'; import { Hall } from '../../hall/Hall'; import { UI_rank_item } from './UI_rank_item'; import { ani_ui } from '../../game/animation_utils'; import { audioManager } from '../../Audio/AudioManager'; 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/UI_rank', GameUILayers.HUD, Layout_rank); } protected onCreated() { ani_ui(this.node); // debugger console.log("排行榜") const layout = this.getLayout(); this.onButtonEvent(layout.close_Btn, () => { audioManager.playOneShot('sound/click_Btn'); this.close(); }); 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_rank_item).showInfo(index + 1, type, this._data[index], false); } 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) { const layout = this.getLayout(); // debugger console.log("全国榜-----------------------------") if (t != null) { if (t == type) return; type = t; } layout.Rank_Toggle_1.isChecked = type == 1; layout.Rank_Toggle_2.isChecked = type == 2; if (type == 1 || t == null) { await gui.show(UIWaiting); debugger; layout.list1.node.active = true; layout.list2.node.active = false; layout.list1.numItems = 0; const d = await Hall.getInstance().player.get_rank_floor(); log("d",d) 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 }; } //console.log("this._owner=-=====",layout.list1.numItems) layout.own1_item.showInfo(index, type, this._owner, true); gui.close(UIWaiting) } if (type == 2 ) {//地区榜 console.log("地区榜-----------------------------") //debugger await gui.show(UIWaiting); layout.list1.node.active = false; layout.list2.node.active = true; layout.list2.numItems = 0; const d = await Hall.getInstance().player.get_Province_Rank(chsdk.get_player_info().hid); this._data = d.list; this._owner = d.ower; let index = d.index; layout.list2.numItems = this._data.length; // console.log("this._owner",this._data) 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) } } }