UI_Settings.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { _decorator, Button, Component, director, 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. if(director.getScene().name == 'hall'){
  21. layout.Defeat_Btn.node.active = false;
  22. }
  23. this.onButtonEvent(layout.Close_Btn, async (button: any) => {
  24. //关闭设置界面
  25. gui.close(UI_Settings);
  26. if(director.getScene().name == 'main')
  27. {
  28. gui.get(UI_Main).evt.emit(gui.get(UI_Main).evt.key.resume);
  29. }
  30. }, this);
  31. layout.Toggle_Music.isChecked = ch.audio.volumeMusic != 0;
  32. layout.Toggle_Sound.isChecked = ch.audio.switchEffect;
  33. this.onToggleEvent(layout.Toggle_Music, async (toggle: any) => {
  34. ch.audio.volumeMusic = toggle.isChecked;
  35. ch.audio.save();
  36. // button_sound();
  37. }, this);
  38. this.onToggleEvent(layout.Toggle_Sound, async (toggle: any) => {
  39. ch.audio.switchEffect = toggle.isChecked;
  40. ch.audio.save();
  41. // button_sound();
  42. }, this);
  43. this.onButtonEvent(layout.Defeat_Btn, async (button: any) => {
  44. await gui.closeAll();
  45. gui.show(UI_Hall);
  46. ResUtil.loadScene(SceneDef.Hall, ModuleDef.GAME, true);
  47. }, this);
  48. }
  49. }