UI_Settings.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { _decorator, Button, Component, Node } from 'cc';
  2. import { Layout_Settings } from './Layout_Settings';
  3. import { ani_ui, UI_Main } from '../UI_Main/UI_Main';
  4. import { UI_Hall } from '../UI_Hall/UI_Hall';
  5. import { ch } from '../../../ch/ch';
  6. import { GameUILayers, gui } from '../../../core/ui/ui';
  7. import ui_base from '../../../core/ui/ui_base';
  8. import { ResUtil } from '../../../core/util/ResUtil';
  9. import { ModuleDef } from '../../../Scripts/ModuleDef';
  10. import { SceneDef } from '../../../Scripts/SceneDef';
  11. const { ccclass, property } = _decorator;
  12. @ccclass('UI_Settings')
  13. export class UI_Settings extends ui_base {
  14. constructor() {
  15. super(ModuleDef.GAME, 'ui/UI_Settings/Settings', GameUILayers.HUD, Layout_Settings);
  16. }
  17. protected async onCreated() {
  18. const layout = this.getLayout<Layout_Settings>();
  19. ani_ui(layout.Close_Btn.node.parent);
  20. this.onButtonEvent(layout.Close_Btn, async (button: any) => {
  21. //关闭设置界面
  22. gui.close(UI_Settings);
  23. gui.get(UI_Main).evt.emit(gui.get(UI_Main).evt.key.resume);
  24. }, this);
  25. layout.Toggle_Music.isChecked = ch.audio.volumeMusic != 0;
  26. layout.Toggle_Sound.isChecked = ch.audio.switchEffect;
  27. this.onToggleEvent(layout.Toggle_Music, async (toggle: any) => {
  28. ch.audio.volumeMusic = toggle.isChecked;
  29. ch.audio.save();
  30. // button_sound();
  31. }, this);
  32. this.onToggleEvent(layout.Toggle_Sound, async (toggle: any) => {
  33. ch.audio.switchEffect = toggle.isChecked;
  34. ch.audio.save();
  35. // button_sound();
  36. }, this);
  37. this.onButtonEvent(layout.Defeat_Btn, async (button: any) => {
  38. await gui.closeAll();
  39. gui.show(UI_Hall);
  40. ResUtil.loadScene(SceneDef.Hall, ModuleDef.GAME, true);
  41. }, this);
  42. }
  43. }