import { _decorator, Layout } from "cc"; import { GameUILayers, gui } from "../../../core/ui/ui"; import ui_base from "../../../core/ui/ui_base"; import { ModuleDef } from "../../../Scripts/ModuleDef"; import { ani_ui } from "../UI_Main/UI_Main"; import { Layout_Invite } from "./Layout_Invite"; const { ccclass, property } = _decorator; @ccclass('UI_Invite') export class UI_Invite extends ui_base { constructor() { super(ModuleDef.GAME, 'ui/UI_Invite/Invite', GameUILayers.HUD, Layout_Invite); } protected async onCreated() { // 拉取通过邀请进入该游戏的好友数量 this.get_Count(); this.show(); const layout = this.getLayout(); ani_ui(layout.Close_Btn.node.parent); this.onButtonEvent(layout.Close_Btn, () => { gui.close(UI_Invite); }); this.onButtonEvent(layout.Invite_Friend_Btn, () => { //分享给好友 chsdk.shareAppMessage(); }); this.onButtonEvent(layout.Refresh_Btn, () => { //刷新好友列表 this.get_Count(); this.show(); }) } get_Count(){ const layout = this.getLayout(); chsdk.getShareList().then((res) => { if (res.code === 0 && res.data) { // 确保数据有效 const friendCount = res.data.length; // 计算人数 layout.Txt.string = friendCount + '/' + layout.target_count; layout.progressBar.progress = friendCount / layout.target_count; let remain= layout.target_count - friendCount; layout.Num_Sp.spriteFrame=layout.Num[remain-1]; } else { // 错误处理 console.error(`获取分享列表失败: ${res.err || "未知错误"}`); } }).catch((err) => { // 捕获 promise 的异常 console.error(`请求失败: ${err.message}`); }); } show(){ const layout=this.getLayout(); layout.progressBar.progress = layout.count/layout.target_count; layout.Txt.string = layout.count + '/' + layout.target_count; } }