game pause
This commit is contained in:
@@ -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",
|
||||
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
|
||||
const { regClass, property } = Laya
|
||||
|
||||
@regClass()
|
||||
export class GameController extends Laya.Script {
|
||||
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"uuid": "58dcdb79-495f-4e55-9403-eada57f40c67"
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
export const EVENT_TYPES = {
|
||||
NOT_UPDATE_MISTAKE: "NOT_UPDATE_MISTAKE",//更新分数
|
||||
NOT_UPDATE_PAUSE: "NOT_UPDATE_PAUSE",//更新暂停状态
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -153,4 +153,5 @@ export class LevelManager {
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { config } from "../constants/config";
|
||||
import { CommonData } from "./CommonData";
|
||||
import { CommonData } from "./common/CommonData";
|
||||
|
||||
const { regClass, property } = Laya;
|
||||
|
||||
|
||||
@@ -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()
|
||||
})
|
||||
|
||||
@@ -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
52
src/views/GamePause.ts
Normal 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()
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
3
src/views/GamePause.ts.meta
Normal file
3
src/views/GamePause.ts.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"uuid": "c8bf81c2-c8fd-4f25-b120-4ad620ff7b88"
|
||||
}
|
||||
@@ -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()
|
||||
})
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
|
||||
const { regClass, property } = Laya
|
||||
|
||||
@regClass()
|
||||
export class Loading extends Laya.Script {
|
||||
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"uuid": "100c54c4-c515-4e10-8cfc-181e7067024a"
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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)=>{
|
||||
Reference in New Issue
Block a user