import { _decorator, Button, Component, director, Node, tween, UIOpacity } from 'cc'; import { UIManager } from './UIManager'; import ch_audio from '../../ch/audio/audio'; import { BasePanel } from './BasePanel'; import { MyGame } from '../Game/MyGame'; const { ccclass, property } = _decorator; @ccclass('SettingsPanel') export class SettingsPanel extends BasePanel { private musicBtn:Button=null; private effectBtn:Button=null; private VibrateBtn:Button=null; private returnHallBtn:Button=null; private switchMusic:boolean=true; private switchEffect:boolean=true; private mask_1:Node=null; private mask_2:Node=null; private mask_3:Node=null; start() { this.musicBtn=this.node.getChildByPath('MusicVolume/Button').getComponent(Button); this.effectBtn=this.node.getChildByPath('EffectVolume/Button').getComponent(Button); this.VibrateBtn=this.node.getChildByPath('Vibrate/Button').getComponent(Button); this.returnHallBtn=this.node.getChildByName('ReturnHallBtn').getComponent(Button); //初始化用户上次的设置 this.musicBtn.node.on(Button.EventType.CLICK, this.onSwitchMusic, this); this.effectBtn.node.on(Button.EventType.CLICK, this.onSwitchEffect, this); this.VibrateBtn.node.on(Button.EventType.CLICK, this.onSwitchVibrate, this); this.returnHallBtn.node.on(Button.EventType.CLICK, this.ReturnHall, this); this.mask_1=this.node.getChildByPath('MusicVolume/Mask'); this.mask_2=this.node.getChildByPath('EffectVolume/Mask'); this.mask_3=this.node.getChildByPath('Vibrate/Mask'); this.mask_1.active=false; this.mask_2.active=false; } update(deltaTime: number) { } //音乐开关 public onSwitchMusic(){ ch_audio.getInstance().switchMusic = !ch_audio.getInstance().switchMusic; if( ch_audio.getInstance().switchMusic) { console.log('play music'); //隐藏遮罩 this.mask_1.active=false; ch_audio.getInstance().volumeMusic=1; } else { console.log('stop music'); //显示遮罩 this.mask_1.active=true; ch_audio.getInstance().volumeMusic=0; } } //音效开关 public onSwitchEffect(){ ch_audio.getInstance().switchEffect = !ch_audio.getInstance().switchEffect; if(ch_audio.getInstance().switchEffect) { console.log('play effect'); //隐藏遮罩 this.mask_2.active=false; ch_audio.getInstance().volumeEffect=1; } else { console.log('stop effect'); //显示遮罩 this.mask_2.active=true; ch_audio.getInstance().volumeEffect=0; } } public onSwitchVibrate(){ //震动开关 } ReturnHall(){ MyGame.getInstance().setLastScene("Main"); //返回大厅 ch_audio.getInstance().stop(); UIManager.Instance.clearStack(); const sceneName = 'Hall'; director.loadScene(sceneName, (err, scene) => { if (err) { console.error('场景加载失败:', err); return; } }); } onClose(){ super.onClose(null); } }