// 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"; import { getGiveUpLosses, renderGiveUpConfirmation } from "./GiveUpConfirmation"; 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) win: cc.Node = null; @property(cc.Node) win2: cc.Node = null; @property({ type: [cc.SpriteFrame], tooltip: "放弃提示,依次为 giveup1~giveup6" }) giveUpFrames: cc.SpriteFrame[] = []; 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.vibrate != null) { 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.releaseBackgroundMusicFromMemory(); } else { cc.fx.AudioManager._instance.stopMusic(); 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; cc.fx.AudioManager._instance.releaseEffectsFromMemory(); 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); const map = MapConroler._instance; if (!map.gameStart) { map.returnHome(); return; } map.trackFinishi("give_up"); map.powerState = cc.fx.GameTool.getUserPowerTime(); if (!this.showGiveUpConfirmation(false)) map.returnHome(); } private showGiveUpConfirmation(restart: boolean): boolean { this.cancelExit(); const panel = cc.fx.GameConfig.isRainbowWinStreak() ? this.win2 : this.win; const content = panel.getChildByName("Health"); const losses = getGiveUpLosses(MapConroler._instance.powerState); if (!renderGiveUpConfirmation(content, this.giveUpFrames, losses)) return false; content.getChildByName("return").active = !restart; content.getChildByName("queding").active = restart; panel.active = true; panel.scale = 0.3; cc.tween(panel) .to(0.2, { scale: 1.05 }, { easing: 'backOut' }) .to(0.15, { scale: 1.0 }, { easing: 'sineOut' }) .start(); return true; } returnHome() { if (cc.fx.GameConfig.GM_INFO.otherLevel == 0) { console.log("3从二级页面点击重开3"); cc.fx.GameTool.setWinStreak("fail"); MapConroler._instance.trackFinishi(); } MapConroler._instance.returnHome(); } //重开游戏 clickRestart(event, customEventData) { cc.fx.AudioManager._instance.playEffect("anniu_little", null); const map = MapConroler._instance; if (!map.gameStart) { map.againLevel(); return; } map.powerState = cc.fx.GameTool.getUserPowerTime(); if (customEventData !== "hp") { if (!this.showGiveUpConfirmation(true)) map.againLevel(); return; } // 保留原有确认重试后的连胜处理和重新开局调用。 if (map.powerState || cc.fx.GameConfig.GM_INFO.otherLevel == 0) { cc.fx.GameTool.setWinStreak("fail"); map.trackFinishi("give_up"); } map.againLevel(); } //取消 cancelExit() { this.win.active = false; this.win2.active = false; } //关闭ui closeUi() { cc.fx.AudioManager._instance.playEffect("anniu_little", null); if (this.node) { this.node.active = false; } } // update (dt) {} }