195 lines
6.0 KiB
TypeScript
195 lines
6.0 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
|
|
|
|
import JiaZai from "./JiaZai";
|
|
import MapConroler from "./Map";
|
|
import SceneManager from "./SceneManager";
|
|
import { MiniGameSdk } from "./Sdk/MiniGameSdk";
|
|
|
|
|
|
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;
|
|
|
|
@property(cc.Node)
|
|
exit: cc.Node = null;
|
|
|
|
musicState: boolean = true;
|
|
effectState: boolean = true;
|
|
vibrateState: boolean = true;
|
|
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;
|
|
if (this.musicState == true) {
|
|
this.music.children[0].active = true;
|
|
} else {
|
|
this.music.children[1].active = true;
|
|
}
|
|
if (this.effectState == true) {
|
|
this.effect.children[0].active = true;
|
|
} else {
|
|
this.effect.children[1].active = true;
|
|
}
|
|
if (this.vibrateState == true) {
|
|
this.vibrate.children[0].active = true;
|
|
} else {
|
|
this.vibrate.children[1].active = true;
|
|
}
|
|
}
|
|
|
|
start() {
|
|
}
|
|
|
|
|
|
clickMusic() {
|
|
if (this.musicState) {
|
|
this.musicState = false;
|
|
cc.fx.GameConfig.GM_INFO.musicOpen = this.musicState;
|
|
|
|
this.setMusicConfig();
|
|
this.music.children[0].active = false;
|
|
this.music.children[1].active = true;
|
|
//如果音乐关闭了,则停止音乐
|
|
cc.fx.AudioManager._instance.stopMusic();
|
|
}
|
|
else {
|
|
this.musicState = true;
|
|
cc.fx.GameConfig.GM_INFO.musicOpen = this.musicState;
|
|
this.setMusicConfig();
|
|
this.music.children[0].active = true;
|
|
this.music.children[1].active = false;
|
|
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.effectState) {
|
|
this.effectState = false;
|
|
cc.fx.GameConfig.GM_INFO.effectOpen = this.effectState;
|
|
this.setMusicConfig();
|
|
this.effect.children[0].active = false;
|
|
this.effect.children[1].active = true;
|
|
}
|
|
else {
|
|
this.effectState = true;
|
|
cc.fx.GameConfig.GM_INFO.effectOpen = this.effectState;
|
|
this.setMusicConfig();
|
|
this.effect.children[0].active = true;
|
|
this.effect.children[1].active = false;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
clickVibrate() {
|
|
if (this.vibrateState) {
|
|
this.vibrateState = false;
|
|
cc.fx.GameConfig.GM_INFO.vibrateOpen = this.vibrateState;
|
|
this.setMusicConfig();
|
|
this.vibrate.children[0].active = false;
|
|
this.vibrate.children[1].active = true;
|
|
|
|
}
|
|
else {
|
|
this.vibrateState = true;
|
|
cc.fx.GameConfig.GM_INFO.vibrateOpen = this.vibrateState;
|
|
this.setMusicConfig();
|
|
this.vibrate.children[0].active = true;
|
|
this.vibrate.children[1].active = false;
|
|
|
|
|
|
}
|
|
}
|
|
syncToggleState() {
|
|
|
|
}
|
|
|
|
//退出游戏
|
|
clickExit() {
|
|
cc.fx.AudioManager._instance.playEffect("anniu_little", null);
|
|
if (MapConroler._instance.gameStart == true && MapConroler._instance.powerState == false) {
|
|
this.exit.active = true;
|
|
let pauseNode = this.exit;
|
|
pauseNode.scale = 0.3;
|
|
cc.tween(pauseNode)
|
|
.to(0.2, { scale: 1.05 }, { easing: 'backOut' })
|
|
.to(0.15, { scale: 1.0 }, { easing: 'sineOut' })
|
|
.start();
|
|
this.exit.getChildByName("Health").getChildByName("queding").active = false;
|
|
}
|
|
else {
|
|
MapConroler._instance.returnHome();
|
|
}
|
|
}
|
|
|
|
//重开游戏
|
|
clickRestart(event, customEventData) {
|
|
cc.fx.AudioManager._instance.playEffect("anniu_little", null);
|
|
if (MapConroler._instance.gameStart == true && MapConroler._instance.powerState == false && customEventData != "hp") {
|
|
this.exit.active = true;
|
|
this.exit.getChildByName("Health").getChildByName("queding").active = true;
|
|
}
|
|
else {
|
|
if (customEventData == "hp") {
|
|
if (cc.fx.GameConfig.GM_INFO.hp <= 0) {
|
|
MiniGameSdk.API.showToast("体力值不足");
|
|
return;
|
|
}
|
|
}
|
|
MapConroler._instance.againLevel();
|
|
}
|
|
}
|
|
|
|
//取消
|
|
cancelExit() {
|
|
this.exit.active = false;
|
|
// 获取场景中的 pause 组件
|
|
// const pauseTs = cc.find("Canvas");
|
|
// if (pauseTs) {
|
|
// const pause = pauseTs.getComponent(SceneManager);
|
|
// if (pause) {
|
|
// pause.closePause();
|
|
// } else {
|
|
// console.warn("pause 组件未找到");
|
|
// }
|
|
// } else {
|
|
// console.warn("pause 节点未找到");
|
|
// }
|
|
}
|
|
//关闭ui
|
|
closeUi() {
|
|
cc.fx.AudioManager._instance.playEffect("anniu_little", null);
|
|
cc.fx.AudioManager._instance.playEffect("anniu_little", null);
|
|
this.node.active = false;
|
|
}
|
|
|
|
// update (dt) {}
|
|
}
|