UI_Settings.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { _decorator, Button, Component, Node } from 'cc';
  2. import { Layout_Settings } from './Layout_Settings';
  3. import { ani_ui } 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. }, this);
  24. layout.Toggle_Music.isChecked = ch.audio.volumeMusic != 0;
  25. layout.Toggle_Sound.isChecked = ch.audio.switchEffect;
  26. this.onToggleEvent(layout.Toggle_Music, async (toggle: any) => {
  27. ch.audio.volumeMusic = toggle.isChecked;
  28. ch.audio.save();
  29. // button_sound();
  30. }, this);
  31. this.onToggleEvent(layout.Toggle_Sound, async (toggle: any) => {
  32. ch.audio.switchEffect = toggle.isChecked;
  33. ch.audio.save();
  34. // button_sound();
  35. }, this);
  36. this.onButtonEvent(layout.Defeat_Btn, async (button: any) => {
  37. await gui.closeAll();
  38. gui.show(UI_Hall);
  39. ResUtil.loadScene(SceneDef.Hall, ModuleDef.GAME, true);
  40. }, this);
  41. }
  42. }