123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- import { Button, Size, Toggle } from "cc";
- import { Layout_Set } from "./Layout_Set";
- import { ModuleDef } from "../../scripts/ModuleDef";
- import { GameUILayers, gui, ui_base } from "../../core/ui/ui";
- import { ch } from "../../ch/ch";
- import get_new_wait from "../../core/util_class/Wait";
- export class UI_Set extends ui_base {
- constructor() {
- super(ModuleDef.BASIC, 'ui_set/UI_Set', GameUILayers.POPUP, Layout_Set);
- }
- protected onCreated(is_in_game: boolean): void {
- let layout = this.getLayout<Layout_Set>();
- this.onButtonEvent(layout.btnClose, this.onClose, this);
- this.onButtonEvent(layout.btnRestart, this.onRestart, this);
- this.onButtonEvent(layout.btnMain, this.onMain, this);
- layout.toogleMusic.isChecked = ch.audio.volumeMusic == 0;
- layout.toogleSound.isChecked = !ch.audio.switchEffect;
- this.onToggleEvent(layout.toogleMusic, this.onMusic, this);
- this.onToggleEvent(layout.toogleSound, this.onSound, this);
- ch.audio.pause();
- gui.scale_anim(layout.btnClose.node.parent);
- //
- layout.btnRestart.node.active = is_in_game;
- layout.btnMain.node.active = is_in_game;
- }
- private onClose(button: Button): void {
- this.wait.resolve(null);
- this.close();
- ch.audio.resume();
- }
- private wait = get_new_wait<string>();
- public async await_choose(): Promise<string> {
- return this.wait.wait();
- }
- private onRestart(button: Button): void {
- this.wait.resolve('restart');
- this.close();
- }
- private onMain(button: Button): void {
- this.wait.resolve('remain');
- this.close();
- }
- private onMusic(toggle: Toggle): void {
- ch.audio.volumeMusic = toggle.isChecked ? 0 : 1;
- ch.audio.save();
- }
- private onSound(toggle: Toggle): void {
- ch.audio.switchEffect = !toggle.isChecked;
- ch.audio.save();
- }
- protected onDispose(): void {
- this.wait?.resolve(null);
- this.wait?.dispose();
- this.wait = null;
- }
- }
|