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

@@ -13,7 +13,7 @@
{
"_$type": "7bad1742-6eed-4d8d-81c0-501dc5bf03d6",
"scriptPath": "../src/Main.ts",
"debug": true
"debug": false
},
{
"_$type": "cd70cd5e-b4cd-4277-ac0a-2224cfbe89ac",

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

@@ -0,0 +1,6 @@
{
"uuid": "7d36066d-f01a-4a46-9eb7-109f58cdbc19",
"importer": {
"textureType": 2
}
}

View File

@@ -0,0 +1,299 @@
{
"_$ver": 1,
"_$id": "2c04twx2",
"_$type": "Box",
"name": "GamePause",
"width": 1080,
"height": 1920,
"_mouseState": 2,
"drawCallOptimize": true,
"left": 0,
"right": 0,
"top": 0,
"bottom": 0,
"_$comp": [
{
"_$type": "c8bf81c2-c8fd-4f25-b120-4ad620ff7b88",
"scriptPath": "../src/views/GamePause.ts",
"label_time": {
"_$ref": "lvemgoo4"
},
"label_diffucuty": {
"_$ref": "ztc8yofh"
},
"btn_continue": {
"_$ref": "ugz9ejd0"
},
"btn_restart": {
"_$ref": "lkzndo0i"
}
}
],
"_$child": [
{
"_$id": "vqp0nqaw",
"_$type": "Image",
"name": "Image",
"width": 1080,
"height": 1920,
"alpha": 0.6,
"left": 0,
"right": 0,
"top": 0,
"bottom": 0,
"skin": "res://a98f334e-ce04-4cd0-8fc5-bbdf9b048609",
"color": "#000000"
},
{
"_$id": "cy0qcxu0",
"_$type": "Box",
"name": "center",
"x": 96,
"y": 507,
"width": 888,
"height": 906,
"_mouseState": 2,
"centerX": 0,
"centerY": 0,
"_$child": [
{
"_$id": "ybaxa7q2",
"_$type": "Sprite",
"name": "Sprite",
"width": 888,
"height": 906,
"_gcmds": [
{
"_$type": "DrawRoundRectCmd",
"x": 0,
"y": 0,
"width": 1,
"height": 1,
"lt": 20,
"rt": 20,
"lb": 20,
"rb": 20,
"percent": true,
"lineWidth": 1,
"fillColor": "#FFFFFF"
}
]
},
{
"_$id": "gpjobt41",
"_$type": "VBox",
"name": "buttons",
"x": 72,
"y": 478,
"width": 744,
"height": 600,
"centerX": 0,
"centerY": 325,
"space": 40,
"align": "center",
"_$child": [
{
"_$id": "ugz9ejd0",
"_$type": "Sprite",
"name": "btn_continue",
"width": 744,
"height": 156,
"_gcmds": [
{
"_$type": "DrawRoundRectCmd",
"x": 0,
"y": 0,
"width": 1,
"height": 1,
"lt": 20,
"rt": 20,
"lb": 20,
"rb": 20,
"percent": true,
"lineWidth": 1,
"fillColor": "rgba(29, 92, 220, 1)"
}
]
},
{
"_$id": "lkzndo0i",
"_$type": "Sprite",
"name": "btn_restart",
"y": 196,
"width": 744,
"height": 156,
"alpha": 0.1,
"_gcmds": [
{
"_$type": "DrawRoundRectCmd",
"x": 0,
"y": 0,
"width": 1,
"height": 1,
"lt": 20,
"rt": 20,
"lb": 20,
"rb": 20,
"percent": true,
"lineWidth": 1,
"fillColor": "rgba(29, 92, 220, 1)"
}
]
}
]
},
{
"_$id": "e5ib0aqq",
"_$type": "VBox",
"name": "labels",
"x": 72,
"y": 478,
"width": 744,
"height": 600,
"centerX": 0,
"centerY": 325,
"space": 40,
"align": "center",
"_$child": [
{
"_$id": "8v40s793",
"_$type": "Label",
"name": "Label(1)",
"width": 744,
"height": 156,
"text": "Continue",
"fontSize": 60,
"color": "rgba(255, 255, 255, 1)",
"bold": true,
"align": "center",
"valign": "middle",
"padding": "0,0,0,0"
},
{
"_$id": "urss0raj",
"_$type": "Label",
"name": "Label(2)",
"y": 196,
"width": 744,
"height": 156,
"text": "Restart",
"fontSize": 60,
"color": "rgba(29, 92, 220, 1)",
"bold": true,
"align": "center",
"valign": "middle",
"padding": "0,0,0,0"
}
]
},
{
"_$id": "hk8la5r2",
"_$type": "Label",
"name": "Label",
"x": 76,
"y": 103,
"width": 736,
"height": 100,
"centerX": 0,
"centerY": -300,
"text": "Pause",
"fontSize": 72,
"color": "rgba(45, 49, 56, 1)",
"bold": true,
"align": "center",
"valign": "middle",
"padding": "0,0,0,0"
},
{
"_$id": "va1fgpv1",
"_$type": "HBox",
"name": "summary",
"x": 84,
"y": 250,
"width": 720,
"height": 140,
"centerX": 0,
"space": 0,
"align": "middle",
"_$child": [
{
"_$id": "4ur3tdna",
"_$type": "Box",
"name": "Box(1)",
"y": 2.5,
"width": 360,
"height": 135,
"_$child": [
{
"_$id": "10mi9wxu",
"_$type": "Label",
"name": "up",
"width": 360,
"height": 60,
"text": "Time",
"fontSize": 42,
"color": "rgba(123, 129, 140, 1)",
"align": "center",
"valign": "middle",
"padding": "0,0,0,0"
},
{
"_$id": "lvemgoo4",
"_$type": "Label",
"name": "down",
"y": 70,
"width": 360,
"height": 72,
"text": "Medium",
"fontSize": 60,
"color": "rgba(45, 49, 56, 1)",
"align": "center",
"valign": "middle",
"padding": "0,0,0,0"
}
]
},
{
"_$id": "26zqj788",
"_$type": "Box",
"name": "Box(2)",
"x": 360,
"y": 2.5,
"width": 360,
"height": 135,
"_$child": [
{
"_$id": "nu9nfub9",
"_$type": "Label",
"name": "up",
"width": 360,
"height": 60,
"text": "Difficuty",
"fontSize": 42,
"color": "rgba(123, 129, 140, 1)",
"align": "center",
"valign": "middle",
"padding": "0,0,0,0"
},
{
"_$id": "ztc8yofh",
"_$type": "Label",
"name": "down",
"y": 70,
"width": 360,
"height": 72,
"text": "Medium",
"fontSize": 60,
"color": "rgba(45, 49, 56, 1)",
"align": "center",
"valign": "middle",
"padding": "0,0,0,0"
}
]
}
]
}
]
}
]
}

View File

@@ -0,0 +1,3 @@
{
"uuid": "b6e5dbcc-bac5-45ae-98d6-48ff60f88a29"
}

View File

@@ -17,6 +17,9 @@
"btn_back": {
"_$ref": "l1ebdt6a"
},
"btn_pause": {
"_$ref": "qfuij2yw"
},
"label_score": {
"_$ref": "zgzyqyoc"
},
@@ -72,19 +75,19 @@
{
"_$id": "xllpjjqz",
"_$type": "Box",
"name": "back",
"x": 45,
"name": "top",
"y": 60,
"width": 400,
"width": 1080,
"height": 64,
"_mouseState": 2,
"centerX": -295,
"centerX": 0,
"centerY": -868,
"_$child": [
{
"_$id": "l1ebdt6a",
"_$type": "Button",
"name": "btn_back",
"x": 45,
"width": 69,
"height": 48,
"_mouseState": 2,
@@ -94,6 +97,21 @@
"labelSize": 20,
"labelAlign": "center",
"labelVAlign": "middle"
},
{
"_$id": "qfuij2yw",
"_$type": "Button",
"name": "btn_pause",
"x": 956,
"width": 75,
"height": 75,
"_mouseState": 2,
"stateNum": 1,
"skin": "res://7d36066d-f01a-4a46-9eb7-109f58cdbc19",
"label": "",
"labelSize": 20,
"labelAlign": "center",
"labelVAlign": "middle"
}
]
},

View File

@@ -13,6 +13,7 @@ export const respath = {
return config.H_SCREEN ? "resources/Stage_H.lh" : "resources/Stage.lh"
},
gamepause_ui_res: "resources/GamePause.lh",
gameover_ui_res: "resources/GameOver.lh",
gamedone_ui_res: "resources/GameDone.lh",

View File

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

View File

@@ -1,3 +0,0 @@
{
"uuid": "58dcdb79-495f-4e55-9403-eada57f40c67"
}

View File

@@ -3,6 +3,7 @@
export const EVENT_TYPES = {
NOT_UPDATE_MISTAKE: "NOT_UPDATE_MISTAKE",//更新分数
NOT_UPDATE_PAUSE: "NOT_UPDATE_PAUSE",//更新暂停状态
}

View File

@@ -153,4 +153,5 @@ export class LevelManager {
}
return ""
}
}

View File

@@ -4,6 +4,7 @@ import { config } from "../constants/config"
import { DataStage, createDataStage } from "../types/global"
import { DOStage } from "./DOStage"
import { DOUser } from "./DOUser"
import { LevelManager } from "./LevelManager"
export class StorageManager {
@@ -57,9 +58,27 @@ export class StorageManager {
this.userChanged = true
}
public newStage(stageID: string, type: number, name: string, difficulty: string, index: number): DOStage {
public newStage(stageID: string, type: number, name: string, difficulty: string = config.DIFFICULTY_TYPE.Easy): DOStage {
this.stageID = stageID
this.stageChanged = false
var index
if (type == config.STAGE_TYPE.MAIN) {//主线关卡
index = this.user.get_progress(difficulty)
var levelStr = LevelManager.getInstance().getLevelStr(difficulty, index)
if (!levelStr || levelStr.length <= 0) {//说明当前难度已经打通了,所以给他从头开始
index = 0
this.user.update_progress(difficulty, index)
}
}
else if (type == config.STAGE_TYPE.DC) {
var random = Math.random()
difficulty = config.DIFFICULTY_LIST[Math.floor(random*config.DIFFICULTY_LIST.length)]
var list = LevelManager.getInstance().getLevelList(difficulty)
random = Math.random()
index = Math.floor(random*list.length)
console.log("每日挑战随机一个关卡", difficulty, index)
}
var dataStage: DataStage = createDataStage(stageID, type, name, difficulty, index)
var doStage: DOStage = new DOStage(dataStage)
this.stageMap.set(stageID, doStage)

View File

@@ -5,7 +5,6 @@ import { DailyChallenge } from "../views/DailyChallenge"
import { TrophyRecord } from "../types/global"
import { TrophyClaim } from "../views/TrophyClaim"
import { TrophyShow } from "../views/TrophyShow"
import { config } from "../constants/config"
const { regClass, property } = Laya
@@ -91,6 +90,12 @@ export class UIManager extends Laya.Script {
}
}
public loadGamePauseUI(): void {
Laya.loader.load(respath.gamepause_ui_res).then((go)=>{
var prefab = go.create()
this.getUIRoot().addChild(prefab)
})
}
public loadGameOverUI(): void {
Laya.loader.load(respath.gameover_ui_res).then((go)=>{
var prefab = go.create()

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)=>{