添加横屏页面
This commit is contained in:
@@ -2,6 +2,7 @@ import { config } from "../constants/config";
|
||||
import { StorageManager } from "../models/StorageManager";
|
||||
import { UIManager } from "../models/UIManager";
|
||||
import { CommonData } from "./common/CommonData";
|
||||
import { G_ShowCommonTips } from "./CommonTips";
|
||||
|
||||
const { regClass, property } = Laya;
|
||||
|
||||
@@ -25,26 +26,56 @@ export class TopBar extends Laya.Script {
|
||||
|
||||
private isClassic: boolean = true
|
||||
|
||||
@property(Laya.Label)
|
||||
public obj_label: Laya.Label
|
||||
@property(Laya.Box)
|
||||
public obj_items: Laya.Box
|
||||
private items: Map<string, Laya.Label> = new Map()
|
||||
|
||||
onStart(): void {
|
||||
onStart(): void {
|
||||
|
||||
//如果是第一次以横屏启动游戏需要创建经典关卡
|
||||
var difficulty = Laya.LocalStorage.getItem("difficulty")//读取用户上次选择的难度
|
||||
if (!difficulty || difficulty.length<=0) {
|
||||
difficulty = config.DIFFICULTY_TYPE.Easy
|
||||
Laya.LocalStorage.setItem("difficulty", difficulty)
|
||||
}
|
||||
var doStage = StorageManager.getInstance().getStage(config.DEFAULT_STAGE_ID)
|
||||
if (!doStage) {
|
||||
StorageManager.getInstance().newStage(config.DEFAULT_STAGE_ID, config.STAGE_TYPE.MAIN, difficulty, difficulty)
|
||||
}
|
||||
else {
|
||||
var user = StorageManager.getInstance().getUser()
|
||||
if (user.get_done(config.DEFAULT_STAGE_ID) >= 1) {
|
||||
console.log("当前主线关卡完成")
|
||||
user.update_progress(doStage.get_difficulty(), doStage.get_stageIndex()+1)//主线关卡更新难度进度
|
||||
StorageManager.getInstance().newStage(config.DEFAULT_STAGE_ID, config.STAGE_TYPE.MAIN, difficulty, difficulty)
|
||||
}
|
||||
else if (doStage.get_mistake() >= config.MISTAKE_MAX) {//上次失败了则重新开始
|
||||
StorageManager.getInstance().newStage(config.DEFAULT_STAGE_ID, config.STAGE_TYPE.MAIN, difficulty, difficulty)
|
||||
}
|
||||
}
|
||||
|
||||
this.btn_classic.on(Laya.Event.CLICK, this, ()=>{
|
||||
if (this.isClassic == false) {
|
||||
this.isClassic = true
|
||||
this.setLeftTab()
|
||||
this.onClickTab()
|
||||
}
|
||||
})
|
||||
this.btn_dc.on(Laya.Event.CLICK, this, ()=>{
|
||||
if (this.isClassic) {
|
||||
this.isClassic = false
|
||||
this.setLeftTab()
|
||||
this.onClickTab()
|
||||
}
|
||||
})
|
||||
this.setLeftTab()
|
||||
this.onClickTab()
|
||||
|
||||
|
||||
var showToggle = Laya.LocalStorage.getItem("showToggle")
|
||||
if (!showToggle || showToggle.length <= 0) {
|
||||
Laya.LocalStorage.setItem("showToggle", "true")
|
||||
}
|
||||
|
||||
for (var i=0; i<this.obj_items.numChildren; i++) {
|
||||
var obj = this.obj_items.getChildAt(i)
|
||||
var value = config.DIFFICULTY_LIST[i]
|
||||
@@ -57,43 +88,59 @@ export class TopBar extends Laya.Script {
|
||||
var common = evt.target.getComponent(CommonData)
|
||||
var difficulty = Laya.LocalStorage.getItem("difficulty")
|
||||
if (common.strValue != difficulty) {
|
||||
this.setDifficulty(common.strValue)
|
||||
Laya.LocalStorage.setItem("difficulty", common.strValue)//记录横屏模式用户选择的难度
|
||||
|
||||
StorageManager.getInstance().cleanStage()
|
||||
StorageManager.getInstance().newStage(config.DEFAULT_STAGE_ID, config.STAGE_TYPE.MAIN, difficulty, difficulty)
|
||||
UIManager.getInstance().loadStageUI(config.DEFAULT_STAGE_ID)
|
||||
if (Laya.LocalStorage.getItem("showToggle")=="true") {
|
||||
var title = "Start New Game"
|
||||
var content = "Current game progress will be lost"
|
||||
G_ShowCommonTips(title, content, true, (ok: boolean, toggleValue: boolean)=>{
|
||||
if (ok) {
|
||||
if (toggleValue) {
|
||||
Laya.LocalStorage.setItem("showToggle", "false")
|
||||
}
|
||||
this.onClickDifficulty(common.strValue)
|
||||
}
|
||||
})
|
||||
}
|
||||
else {
|
||||
this.onClickDifficulty(common.strValue)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
//如果是第一次以横屏启动游戏需要创建经典关卡
|
||||
var difficulty = Laya.LocalStorage.getItem("difficulty")//读取用户上次选择的难度
|
||||
if (!difficulty || difficulty.length<=0) {
|
||||
difficulty = config.DIFFICULTY_TYPE.Easy
|
||||
Laya.LocalStorage.setItem("difficulty", difficulty)
|
||||
}
|
||||
var doStage = StorageManager.getInstance().loadStage(config.DEFAULT_STAGE_ID)
|
||||
if (!doStage) {
|
||||
StorageManager.getInstance().newStage(config.DEFAULT_STAGE_ID, config.STAGE_TYPE.MAIN, difficulty, difficulty)
|
||||
}
|
||||
|
||||
this.setDifficulty(difficulty)
|
||||
this.updateDifficulty(difficulty)
|
||||
|
||||
}
|
||||
|
||||
setLeftTab(): void {
|
||||
onClickTab(): void {
|
||||
if (this.isClassic) {
|
||||
UIManager.getInstance().closeTrophyUI()
|
||||
UIManager.getInstance().closeDCUI()
|
||||
UIManager.getInstance().loadStageUI(config.DEFAULT_STAGE_ID)
|
||||
}
|
||||
else {
|
||||
UIManager.getInstance().closeStageUI()
|
||||
UIManager.getInstance().loadDCUI()
|
||||
}
|
||||
this.updateLeftTab()
|
||||
}
|
||||
updateLeftTab(): void {
|
||||
this.sprite_classic.alpha = this.isClassic ? 1 : 0.1
|
||||
this.label_classic.color = this.isClassic ? "#ffffff" : "#0e2a53"
|
||||
this.sprite_dc.alpha = this.isClassic ? 0.1 : 1
|
||||
this.label_dc.color = this.isClassic ? "#0e2a53" : "#ffffff"
|
||||
|
||||
if (this.isClassic) {
|
||||
UIManager.getInstance().loadStageUI(config.DEFAULT_STAGE_ID)
|
||||
}
|
||||
this.obj_label.visible = this.isClassic
|
||||
this.obj_items.visible = this.isClassic
|
||||
}
|
||||
|
||||
setDifficulty(difficulty: string): void {
|
||||
onClickDifficulty(difficulty: string): void {
|
||||
Laya.LocalStorage.setItem("difficulty", difficulty)//记录横屏模式用户选择的难度
|
||||
StorageManager.getInstance().newStage(config.DEFAULT_STAGE_ID, config.STAGE_TYPE.MAIN, difficulty, difficulty)
|
||||
UIManager.getInstance().loadStageUI(config.DEFAULT_STAGE_ID)
|
||||
|
||||
this.updateDifficulty(difficulty)
|
||||
}
|
||||
|
||||
updateDifficulty(difficulty: string): void {
|
||||
this.items.forEach((label: Laya.Label, key: string)=>{
|
||||
label.color = "#0e2a53"
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user