cb/assets/Script/setUi.ts
2025-07-03 12:16:00 +08:00

126 lines
3.5 KiB
TypeScript

// Learn TypeScript:
// - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
const { ccclass, property } = cc._decorator;
@ccclass
export default class setUi extends cc.Component {
static _instance: any;
time: number = 0;
@property(cc.Node)
music: cc.Node = null;
@property(cc.Node)
effect: cc.Node = null;
@property(cc.Node)
vibrate: cc.Node = null;
// mapInfo: number[][] = [];
musicState: boolean = true;
effectState: boolean = true;
vibrateState: boolean = true;
private _isSyncing = false;
onLoad() {
this.musicState = cc.fx.GameConfig.GM_INFO.musicOpen;
this.effectState = cc.fx.GameConfig.GM_INFO.effectOpen;
this.vibrateState = cc.fx.GameConfig.GM_INFO.vibrateOpen;
console.log("音乐状态", cc.fx.GameConfig.GM_INFO.musicOpen);
console.log("音效状态", cc.fx.GameConfig.GM_INFO.effectOpen);
console.log("震动状态", cc.fx.GameConfig.GM_INFO.vibrateOpen);
this.syncToggleState();
}
start() {
}
init(time) {
}
clickMusic() {
if (this._isSyncing) return;
if (this.musicState) {
this.musicState = false;
cc.fx.GameConfig.GM_INFO.musicOpen = this.musicState;
this.setMusicConfig();
//如果音乐关闭了,则停止音乐
cc.fx.AudioManager._instance.stopMusic();
}
else {
this.musicState = true;
cc.fx.GameConfig.GM_INFO.musicOpen = this.musicState;
this.setMusicConfig();
cc.fx.AudioManager._instance.playMusicGame();
}
}
setMusicConfig() {
let audioInfo = {
"musicOpen": cc.fx.GameConfig.GM_INFO.musicOpen, //音乐
"effectOpen": cc.fx.GameConfig.GM_INFO.effectOpen, //音效
"vibrateOpen": cc.fx.GameConfig.GM_INFO.vibrateOpen, //震动
}
cc.fx.StorageMessage.setStorage("music", audioInfo);
}
clickEffect() {
if (this._isSyncing) return;
if (this.effectState) {
this.effectState = false;
cc.fx.GameConfig.GM_INFO.effectOpen = this.effectState;
this.setMusicConfig();
}
else {
this.effectState = true;
cc.fx.GameConfig.GM_INFO.effectOpen = this.effectState;
this.setMusicConfig();
}
}
clickVibrate() {
if (this._isSyncing) return;
if (this.vibrateState) {
this.vibrateState = false;
cc.fx.GameConfig.GM_INFO.vibrateOpen = this.vibrateState;
this.setMusicConfig();
}
else {
this.vibrateState = true;
cc.fx.GameConfig.GM_INFO.vibrateOpen = this.vibrateState;
this.setMusicConfig();
}
}
syncToggleState() {
this._isSyncing = true;
this.music.getComponent(cc.Toggle).isChecked = cc.fx.GameConfig.GM_INFO.musicOpen;
this.effect.getComponent(cc.Toggle).isChecked = cc.fx.GameConfig.GM_INFO.effectOpen;
this.vibrate.getComponent(cc.Toggle).isChecked = cc.fx.GameConfig.GM_INFO.vibrateOpen;
}
//关闭ui
closeUi() {
cc.fx.AudioManager._instance.playEffect("anniu_little", null);
this.node.active = false;
}
// update (dt) {}
}