game pause

This commit is contained in:
2025-05-22 19:12:00 +08:00
parent 4df55f9031
commit 4626e98717
30 changed files with 439 additions and 70 deletions

View File

@@ -1,4 +1,4 @@
import { G_ShowScoreTips } from "../views/GUITips";
import { G_ShowScoreTips } from "../views/common/GUITips";
import { DOBlock } from "../models/DOBlock";
const { regClass, property } = Laya;

View File

@@ -84,14 +84,8 @@ export class DailyChallenge extends Laya.Script {
var doStage = StorageManager.getInstance().loadStage(stageID)
console.log("play >>>>>>>>>>>>>>>>>>>>>>>", stageID, doStage)
if (!doStage) {
var random = Math.random()
var value = config.DIFFICULTY_LIST[Math.floor(random*config.DIFFICULTY_LIST.length)]
var list = LevelManager.getInstance().getLevelList(value)
random = Math.random()
var index = Math.floor(random*list.length)
var stageName = `${config.MONTH_ABBRS[month-1]} ${dayNow}`
console.log("随机一个关卡", value, index)
StorageManager.getInstance().newStage(stageID, config.STAGE_TYPE.DC, stageName, value, index)
StorageManager.getInstance().newStage(stageID, config.STAGE_TYPE.DC, stageName)
}
UIManager.getInstance().loadStageUI(stageID);
this.owner.destroy()

View File

@@ -1,5 +1,5 @@
import { config } from "../constants/config";
import { CommonData } from "./CommonData";
import { CommonData } from "./common/CommonData";
const { regClass, property } = Laya;

View File

@@ -64,13 +64,7 @@ export class GameDone extends Laya.Script {
d.onInit((value: string)=> {
console.log("选择难度", value)
StorageManager.getInstance().cleanStage()
var user = StorageManager.getInstance().getUser()
var index = user.get_progress(value)
var levelStr = LevelManager.getInstance().getLevelStr(value, index)
if (!levelStr || levelStr.length <= 0) {//说明当前难度已经打通了,所以给他从头开始
user.update_progress(value, 0)
}
StorageManager.getInstance().newStage(config.DEFAULT_STAGE_ID, config.STAGE_TYPE.MAIN, value, value, user.get_progress(value))
StorageManager.getInstance().newStage(config.DEFAULT_STAGE_ID, config.STAGE_TYPE.MAIN, value, value)
UIManager.getInstance().loadStageUI(config.DEFAULT_STAGE_ID);
this.owner.destroy()
})

View File

@@ -40,8 +40,7 @@ export class GameOver extends Laya.Script {
var type = doStage.get_stageType()
var difficulty = doStage.get_difficulty()
StorageManager.getInstance().cleanStage()
var user = StorageManager.getInstance().getUser()
StorageManager.getInstance().newStage(stageID, type, difficulty, difficulty, user.get_progress(difficulty))
StorageManager.getInstance().newStage(stageID, type, difficulty, difficulty)
UIManager.getInstance().loadStageUI(stageID);
this.owner.destroy()
})
@@ -58,13 +57,7 @@ export class GameOver extends Laya.Script {
d.onInit((value: string)=> {
console.log("选择难度", value)
StorageManager.getInstance().cleanStage()
var user = StorageManager.getInstance().getUser()
var index = user.get_progress(value)
var levelStr = LevelManager.getInstance().getLevelStr(value, index)
if (!levelStr || levelStr.length <= 0) {//说明当前难度已经打通了,所以给他从头开始
user.update_progress(value, 0)
}
StorageManager.getInstance().newStage(config.DEFAULT_STAGE_ID, config.STAGE_TYPE.MAIN, value, value, user.get_progress(value))
StorageManager.getInstance().newStage(config.DEFAULT_STAGE_ID, config.STAGE_TYPE.MAIN, value, value)
UIManager.getInstance().loadStageUI(config.DEFAULT_STAGE_ID);
this.owner.destroy()
})

52
src/views/GamePause.ts Normal file
View File

@@ -0,0 +1,52 @@
import { UIManager } from "../models/UIManager";
import { StorageManager } from "../models/StorageManager";
import { Utility_ConvertSecondToString } from "../utils/utility";
import { EVENT_TYPES, EventManager } from "../models/EventManager";
const { regClass, property } = Laya;
@regClass()
export class GamePause extends Laya.Script {
declare owner : Laya.Box;
@property(Laya.Label)
public label_time: Laya.Label
@property(Laya.Label)
public label_diffucuty: Laya.Label
@property(Laya.Sprite)
public btn_continue: Laya.Sprite
@property(Laya.Sprite)
public btn_restart: Laya.Sprite
//组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次
onAwake(): void {
var doStage = StorageManager.getInstance().getStage()
this.label_time.text = Utility_ConvertSecondToString(doStage.get_duration())
this.label_diffucuty.text = doStage.get_difficulty()
EventManager.getInstance().DispatchEvent(EVENT_TYPES.NOT_UPDATE_PAUSE, true)
this.btn_continue.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
EventManager.getInstance().DispatchEvent(EVENT_TYPES.NOT_UPDATE_PAUSE, false)
this.owner.destroy()
})
this.btn_restart.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
var stageID = doStage.get_stageID()
var type = doStage.get_stageType()
var difficulty = doStage.get_difficulty()
StorageManager.getInstance().cleanStage()
StorageManager.getInstance().newStage(stageID, type, difficulty, difficulty)
UIManager.getInstance().loadStageUI(stageID);
this.owner.destroy()
})
}
}

View File

@@ -0,0 +1,3 @@
{
"uuid": "c8bf81c2-c8fd-4f25-b120-4ad620ff7b88"
}

View File

@@ -75,14 +75,8 @@ export class Home extends Laya.Script {
this.btn_continue.visible = false
this.btn_more.visible = false
this.btn_play.on(Laya.Event.CLICK, this, ()=>{//Play
var random = Math.random()
var value = config.DIFFICULTY_LIST[Math.floor(random*config.DIFFICULTY_LIST.length)]
var list = LevelManager.getInstance().getLevelList(value)
random = Math.random()
var index = Math.floor(random*list.length)
var stageName = `${config.MONTH_ABBRS[nowMonth-1]} ${nowDay}`
console.log("随机一个关卡", value, index)
StorageManager.getInstance().newStage(stageID, config.STAGE_TYPE.DC, stageName, value, index)
StorageManager.getInstance().newStage(stageID, config.STAGE_TYPE.DC, stageName)
UIManager.getInstance().loadStageUI(stageID);
this.owner.destroy()
})
@@ -153,13 +147,7 @@ export class Home extends Laya.Script {
d.onInit((value: string)=> {
console.log("选择难度", value)
StorageManager.getInstance().cleanMainStage()
var user = StorageManager.getInstance().getUser()
var index = user.get_progress(value)
var levelStr = LevelManager.getInstance().getLevelStr(value, index)
if (!levelStr || levelStr.length <= 0) {//说明当前难度已经打通了,所以给他从头开始
user.update_progress(value, 0)
}
StorageManager.getInstance().newStage(config.DEFAULT_STAGE_ID, config.STAGE_TYPE.MAIN, value, value, user.get_progress(value))
StorageManager.getInstance().newStage(config.DEFAULT_STAGE_ID, config.STAGE_TYPE.MAIN, value, value)
UIManager.getInstance().loadStageUI(config.DEFAULT_STAGE_ID);
this.owner.destroy()
})

View File

@@ -1,7 +0,0 @@
const { regClass, property } = Laya
@regClass()
export class Loading extends Laya.Script {
}

View File

@@ -1,3 +0,0 @@
{
"uuid": "100c54c4-c515-4e10-8cfc-181e7067024a"
}

View File

@@ -18,6 +18,8 @@ export class Stage extends Laya.Script {
@property(Laya.Button)
public btn_back: Laya.Button
@property(Laya.Button)
public btn_pause: Laya.Button
@property(Laya.Label)
public label_score: Laya.Label;
@property(Laya.Label)
@@ -71,6 +73,9 @@ export class Stage extends Laya.Script {
UIManager.getInstance().closeStageUI();
}
})
this.btn_pause.on(Laya.Event.CLICK, this, ()=>{
UIManager.getInstance().loadGamePauseUI();
})
for (var i=0; i<this.obj_blocks.numChildren; i++) {
var hbox = this.obj_blocks.getChildAt(i);
var l_hbox = this.obj_block_labels.getChildAt(i);
@@ -109,18 +114,25 @@ export class Stage extends Laya.Script {
this.btn_hint_ad = this.btn_hint.getChildByName("Image").getChildByName("ad") as Laya.Box
this.btn_hint_label = this.btn_hint.getChildByName("Image").getChildByName("normal").getChildByName("label") as Laya.Label
EventManager.getInstance().RegisterEvent(EVENT_TYPES.NOT_UPDATE_MISTAKE, Stage.EventUpdateMistak)
EventManager.getInstance().RegisterEvent(EVENT_TYPES.NOT_UPDATE_MISTAKE, Stage.EventUpdateMistake)
EventManager.getInstance().RegisterEvent(EVENT_TYPES.NOT_UPDATE_PAUSE, Stage.EventUpdatePause)
}
onDestroy(): void {
EventManager.getInstance().UnregisterEvent(EVENT_TYPES.NOT_UPDATE_MISTAKE, Stage.EventUpdateMistak)
EventManager.getInstance().UnregisterEvent(EVENT_TYPES.NOT_UPDATE_MISTAKE, Stage.EventUpdateMistake)
EventManager.getInstance().UnregisterEvent(EVENT_TYPES.NOT_UPDATE_PAUSE, Stage.EventUpdatePause)
}
public static EventUpdateMistak(arg: any): void {
public static EventUpdateMistake(arg: any): void {
if (Stage._instance) {
Stage._instance.onUpdateMistake()
}
}
public static EventUpdatePause(arg: any): void {
if (Stage._instance) {
Stage._instance.paused = arg
}
}
public onLoadStage(doStage: DOStage): void {
this.data = doStage

View File

@@ -1,4 +1,4 @@
import { respath } from "../constants/respath";
import { respath } from "../../constants/respath"
export function G_ShowScoreTips(text: string, parent: any): void {
Laya.loader.load(respath.score_add_ui_res).then((go)=>{