UI_Settings.ts 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { _decorator, AudioSource, Component, director, game, Node, Scheduler, Toggle } from 'cc';
  2. import { GameUILayers, gui, ui_base } from 'db://assets/core/ui/ui';
  3. import { ModuleDef } from 'db://assets/Script/ModuleDef';
  4. import { Layout_Settings } from './Layout_Settings';
  5. import { UI_Main } from '../main/UI_Main';
  6. import { ani_ui } from '../../game/animation_utils';
  7. import { Hall } from '../../hall/Hall';
  8. import { audioManager } from '../../Audio/AudioManager';
  9. const { ccclass, property } = _decorator;
  10. @ccclass('UI_Settings')
  11. export class UI_Settings extends ui_base {
  12. constructor() {
  13. super(ModuleDef.GAME, 'ui/UI_Settings/setDlg', GameUILayers.HUD, Layout_Settings);
  14. }
  15. protected onCreated() {
  16. ani_ui(this.node);
  17. const layout = this.getLayout<Layout_Settings>();
  18. this.onButtonEvent(layout.returnBtn, async () => {
  19. audioManager.playOneShot('sound/click_Btn')
  20. if (gui.get(UI_Main)) {
  21. gui.get(UI_Main).evt.emit(gui.get(UI_Main).evt.key.resume);
  22. }
  23. await gui.closeAll();
  24. Hall.getInstance().to_hall()
  25. console.log('大厅界面')
  26. });
  27. this.onButtonEvent(layout.shareBtn, () => {
  28. audioManager.playOneShot('sound/click_Btn')
  29. //TODO
  30. chsdk.shareAppMessage();
  31. });
  32. this.onButtonEvent(layout.closeBtn, () => {
  33. audioManager.playOneShot('sound/click_Btn')
  34. if (gui.get(UI_Main)) {
  35. gui.get(UI_Main).evt.emit(gui.get(UI_Main).evt.key.resume);
  36. }
  37. this.close()
  38. })
  39. }
  40. get_Count() {
  41. const layout = this.getLayout<Layout_Settings>();
  42. chsdk.getShareList().then((res) => {
  43. if (res.code === 0 && res.data) {
  44. // 确保数据有效
  45. const friendCount = res.data.length; // 计算人数
  46. // layout.Txt.string = friendCount + '/' + layout.target_count;
  47. // layout.progressBar.progress = friendCount / layout.target_count;
  48. // let remain= layout.target_count - friendCount;
  49. // layout.Num_Sp.spriteFrame=layout.Num[remain-1];
  50. } else {
  51. // 错误处理
  52. console.error(`获取分享列表失败: ${res.err || "未知错误"}`);
  53. }
  54. }).catch((err) => {
  55. // 捕获 promise 的异常
  56. console.error(`请求失败: ${err.message}`);
  57. });
  58. }
  59. }