258 lines
9.2 KiB
TypeScript
258 lines
9.2 KiB
TypeScript
import { popupContent } from "./PopupContent";
|
||
import PopupAnimator, { ActivityPopupAnimationType as PopupType } from "./ActivityPopupAnimator";
|
||
// 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";
|
||
import ServerEnvironment from "./module/Config/ServerEnvironment";
|
||
import ServerSelector from "./ServerSelector";
|
||
|
||
|
||
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() {
|
||
if (ServerEnvironment.canSwitch() && cc.director.getScene()?.name === "HomeScene") {
|
||
const panel = this.node.getChildByName("pause");
|
||
if (panel) {
|
||
const selector = new cc.Node("ServerSelector");
|
||
selector.parent = panel;
|
||
selector.setPosition(0, -520);
|
||
selector.addComponent(ServerSelector);
|
||
}
|
||
}
|
||
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() {
|
||
cc.fx.AudioManager._instance.playEffect("anniu_little", null);
|
||
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;
|
||
|
||
}
|
||
cc.fx.AudioManager._instance.playEffect("anniu_little", null);
|
||
}
|
||
|
||
clickVibrate() {
|
||
cc.fx.AudioManager._instance.playEffect("anniu_little", null);
|
||
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.usesRainbowWinStreakUI() ? 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;
|
||
PopupAnimator.open(popupContent(panel, ["New Sprite(Splash)"]));
|
||
return true;
|
||
}
|
||
|
||
returnHome() {
|
||
const content = popupContent(this.win2 && this.win2.active ? this.win2 : this.win, ["New Sprite(Splash)"]);
|
||
if (!content || (Array.isArray(content) && !content.length)) { this.finishPopupReturnHome(); return; }
|
||
PopupAnimator.close(content, PopupType.Bounce, () => this.finishPopupReturnHome());
|
||
}
|
||
|
||
finishPopupReturnHome() {
|
||
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.checkRestartPower()) return;
|
||
const panel = this.win2 && this.win2.active ? this.win2 : this.win;
|
||
const content = popupContent(panel, ["New Sprite(Splash)"]);
|
||
PopupAnimator.close(content, PopupType.Bounce, async () => {
|
||
// 保留原有确认重试后的连胜处理和重新开局调用。
|
||
if (map.powerState || cc.fx.GameConfig.GM_INFO.otherLevel == 0) {
|
||
cc.fx.GameTool.setWinStreak("fail");
|
||
map.trackFinishi("give_up");
|
||
}
|
||
const restarted = await map.againLevel();
|
||
// 动画期间体力状态可能变化;未能重开时恢复内容,避免只剩遮罩。
|
||
if (!restarted && cc.isValid(panel, true) && panel.activeInHierarchy) {
|
||
PopupAnimator.cancel(content);
|
||
}
|
||
});
|
||
}
|
||
|
||
//取消
|
||
cancelExit(event?: cc.Event) {
|
||
if (event) cc.fx.AudioManager._instance.playEffect("anniu_little", null);
|
||
[this.win, this.win2].forEach(panel => {
|
||
if (!panel || !panel.active) return;
|
||
if (!event) { PopupAnimator.cancel(popupContent(panel, ["New Sprite(Splash)"])); panel.active = false; return; }
|
||
PopupAnimator.close(popupContent(panel, ["New Sprite(Splash)"]), PopupType.Bounce, () => { panel.active = false; });
|
||
});
|
||
}
|
||
//关闭ui
|
||
closeUi() {
|
||
const content = this.node.getChildByName("pause");
|
||
if (!content || (Array.isArray(content) && !content.length)) { this.finishPopupCloseUi(); return; }
|
||
PopupAnimator.close(content, PopupType.Bounce, () => this.finishPopupCloseUi());
|
||
}
|
||
|
||
finishPopupCloseUi() {
|
||
cc.fx.AudioManager._instance.playEffect("anniu_little", null);
|
||
if (this.node) {
|
||
this.node.active = false;
|
||
}
|
||
}
|
||
|
||
// update (dt) {}
|
||
}
|