123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- 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<Layout_Invite>();
- 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<Layout_Invite>();
- 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_Invite>();
- layout.progressBar.progress = layout.count/layout.target_count;
- layout.Txt.string = layout.count + '/' + layout.target_count;
- }
- }
|