2026-04-30 00:13:37 +08:00
|
|
|
import { _decorator, Component, director, Node } from "cc";
|
|
|
|
|
import { EventDispatcher } from "../libs/EventDispatcher";
|
2026-05-12 06:46:31 +08:00
|
|
|
import Common from "../libs/Common";
|
2026-04-30 00:13:37 +08:00
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
|
|
|
|
|
|
@ccclass("PauseModal")
|
|
|
|
|
export class PauseModal extends Component {
|
|
|
|
|
start() {
|
|
|
|
|
// 隐藏暂停游戏弹窗
|
|
|
|
|
this.node.active = false;
|
|
|
|
|
// 初始化位置
|
|
|
|
|
this.node.setPosition(0, 0, 0);
|
|
|
|
|
// 监听继续游戏事件
|
|
|
|
|
EventDispatcher.getTarget().on(
|
|
|
|
|
EventDispatcher.SHOW_PAUSE_MODAL,
|
|
|
|
|
this.showModal,
|
|
|
|
|
this,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 显示弹窗
|
|
|
|
|
showModal() {
|
|
|
|
|
this.node.active = true;
|
2026-05-12 06:46:31 +08:00
|
|
|
// 设置暂停游戏背景色
|
|
|
|
|
Common.setPageBackgroundColorAsDino(this.node);
|
2026-04-30 00:13:37 +08:00
|
|
|
// 暂停游戏
|
|
|
|
|
director.pause();
|
|
|
|
|
// 发送暂停游戏事件
|
|
|
|
|
EventDispatcher.getTarget().emit(EventDispatcher.GAME_PAUSE);
|
|
|
|
|
// 发送继续游戏弹窗
|
|
|
|
|
EventDispatcher.getTarget().emit(EventDispatcher.SHOW_CONTINUE_MODAL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 关闭弹窗
|
|
|
|
|
closeModal() {
|
|
|
|
|
this.node.active = false;
|
|
|
|
|
// 恢复游戏继续
|
|
|
|
|
director.resume();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 回到首页
|
|
|
|
|
backToHome() {
|
|
|
|
|
// 恢复游戏继续
|
|
|
|
|
director.resume();
|
|
|
|
|
// 跳转到首页
|
|
|
|
|
director.loadScene("home");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 继续游戏
|
|
|
|
|
resumeGame() {
|
|
|
|
|
// 关闭弹窗
|
|
|
|
|
this.closeModal();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
update(deltaTime: number) {}
|
|
|
|
|
}
|