| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- 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);
- }
- }
|