2025-05-28 18:47:51 +08:00
|
|
|
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"
|
2025-05-23 20:47:03 +08:00
|
|
|
|
2025-05-28 18:47:51 +08:00
|
|
|
const { regClass, property } = Laya
|
2025-05-23 20:47:03 +08:00
|
|
|
|
|
|
|
|
@regClass()
|
|
|
|
|
export class TopBar extends Laya.Script {
|
2025-05-28 18:47:51 +08:00
|
|
|
declare owner: Laya.Box
|
2025-05-26 19:57:17 +08:00
|
|
|
|
2025-05-28 18:47:51 +08:00
|
|
|
@property(Laya.Box)
|
|
|
|
|
public btn_classic: Laya.Box
|
2025-05-26 19:57:17 +08:00
|
|
|
|
2025-05-28 18:47:51 +08:00
|
|
|
@property(Laya.Sprite)
|
|
|
|
|
public sprite_classic: Laya.Sprite
|
2025-05-23 20:47:03 +08:00
|
|
|
|
2025-05-28 18:47:51 +08:00
|
|
|
@property(Laya.Label)
|
|
|
|
|
public label_classic: Laya.Label
|
|
|
|
|
|
|
|
|
|
@property(Laya.Box)
|
|
|
|
|
public btn_dc: Laya.Box
|
2025-05-26 19:57:17 +08:00
|
|
|
|
2025-05-28 18:47:51 +08:00
|
|
|
@property(Laya.Sprite)
|
|
|
|
|
public sprite_dc: Laya.Sprite
|
|
|
|
|
|
|
|
|
|
@property(Laya.Label)
|
|
|
|
|
public label_dc: Laya.Label
|
|
|
|
|
|
|
|
|
|
private isClassic: boolean = true
|
|
|
|
|
|
|
|
|
|
@property(Laya.Label)
|
|
|
|
|
public obj_label: Laya.Label
|
|
|
|
|
|
|
|
|
|
@property(Laya.Box)
|
|
|
|
|
public obj_items: Laya.Box
|
|
|
|
|
|
2025-05-30 16:43:00 +08:00
|
|
|
private item_labels: Map<string, Laya.Label> = new Map()
|
2025-05-28 18:47:51 +08:00
|
|
|
|
|
|
|
|
onStart(): void {
|
|
|
|
|
// 如果是第一次以横屏启动游戏需要创建经典关卡
|
|
|
|
|
let difficulty = Laya.LocalStorage.getItem("difficulty")// 读取用户上次选择的难度
|
|
|
|
|
if (!difficulty || difficulty.length <= 0) {
|
|
|
|
|
difficulty = config.DIFFICULTY_TYPE.Easy
|
|
|
|
|
Laya.LocalStorage.setItem("difficulty", difficulty)
|
|
|
|
|
}
|
|
|
|
|
const doStage = StorageManager.getInstance().getStage(config.DEFAULT_STAGE_ID)
|
|
|
|
|
if (!doStage) {
|
|
|
|
|
StorageManager.getInstance().newStage(config.DEFAULT_STAGE_ID, config.STAGE_TYPE.MAIN, difficulty, difficulty)
|
|
|
|
|
} else {
|
|
|
|
|
const 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)// 主线关卡更新难度进度
|
2025-05-26 19:57:17 +08:00
|
|
|
StorageManager.getInstance().newStage(config.DEFAULT_STAGE_ID, config.STAGE_TYPE.MAIN, difficulty, difficulty)
|
2025-05-28 18:47:51 +08:00
|
|
|
} else if (doStage.get_mistake() >= config.MISTAKE_MAX) { // 上次失败了则重新开始
|
|
|
|
|
StorageManager.getInstance().newStage(config.DEFAULT_STAGE_ID, config.STAGE_TYPE.MAIN, difficulty, difficulty)
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-05-26 19:57:17 +08:00
|
|
|
|
2025-05-28 18:47:51 +08:00
|
|
|
this.btn_classic.on(Laya.Event.CLICK, this, () => {
|
2025-05-28 19:15:32 +08:00
|
|
|
if (this.isClassic === false) {
|
2025-05-28 18:47:51 +08:00
|
|
|
this.onClickTab(true)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
this.btn_dc.on(Laya.Event.CLICK, this, () => {
|
|
|
|
|
if (this.isClassic) {
|
|
|
|
|
this.onClickTab(false)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
this.onClickTab(this.isClassic)
|
|
|
|
|
|
|
|
|
|
const showToggle = Laya.LocalStorage.getItem("showToggle")
|
|
|
|
|
if (!showToggle || showToggle.length <= 0) {
|
|
|
|
|
Laya.LocalStorage.setItem("showToggle", "true")
|
2025-05-23 20:47:03 +08:00
|
|
|
}
|
|
|
|
|
|
2025-05-28 18:47:51 +08:00
|
|
|
for (let i = 0; i < this.obj_items.numChildren; i++) {
|
|
|
|
|
const obj = this.obj_items.getChildAt(i)
|
2025-05-30 18:45:24 +08:00
|
|
|
obj.on(Laya.Event.MOUSE_OVER, this, this.onOver)
|
|
|
|
|
obj.on(Laya.Event.MOUSE_OUT, this, this.onOut)
|
2025-05-28 18:47:51 +08:00
|
|
|
const value = config.DIFFICULTY_LIST[i]
|
|
|
|
|
const label = obj.getChildByName("Label") as Laya.Label
|
|
|
|
|
label.text = value
|
2025-05-30 16:43:00 +08:00
|
|
|
this.item_labels.set(value, label)
|
2025-05-28 18:47:51 +08:00
|
|
|
const common = obj.getComponent(CommonData)
|
|
|
|
|
common.strValue = value
|
|
|
|
|
obj.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
|
|
|
|
|
const common = evt.target.getComponent(CommonData)
|
|
|
|
|
const difficulty = Laya.LocalStorage.getItem("difficulty")
|
2025-05-28 20:12:56 +08:00
|
|
|
if (common.strValue !== difficulty) {
|
2025-05-28 19:15:32 +08:00
|
|
|
if (Laya.LocalStorage.getItem("showToggle") === "true") {
|
2025-05-28 18:47:51 +08:00
|
|
|
const title = "Start New Game"
|
|
|
|
|
const 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)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
this.updateDifficulty(difficulty)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onClickTab(isClassic: boolean): void {
|
|
|
|
|
this.isClassic = isClassic
|
|
|
|
|
if (isClassic) {
|
|
|
|
|
UIManager.getInstance().closeTrophyUI()
|
|
|
|
|
UIManager.getInstance().closeDCUI()
|
|
|
|
|
UIManager.getInstance().loadStageUI(config.DEFAULT_STAGE_ID)
|
|
|
|
|
} else {
|
|
|
|
|
UIManager.getInstance().closeStageUI()
|
|
|
|
|
UIManager.getInstance().loadDCUI()
|
2025-05-23 20:47:03 +08:00
|
|
|
}
|
2025-05-28 18:47:51 +08:00
|
|
|
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"
|
|
|
|
|
|
|
|
|
|
this.obj_label.visible = this.isClassic
|
|
|
|
|
this.obj_items.visible = this.isClassic
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 {
|
2025-05-30 16:43:00 +08:00
|
|
|
this.item_labels.forEach((label: Laya.Label) => {
|
2025-05-28 18:47:51 +08:00
|
|
|
label.color = "#0e2a53"
|
|
|
|
|
})
|
2025-05-30 16:43:00 +08:00
|
|
|
const label = this.item_labels.get(difficulty)
|
2025-05-28 18:47:51 +08:00
|
|
|
label.color = "#1d5cdc"
|
|
|
|
|
}
|
2025-05-30 18:45:24 +08:00
|
|
|
|
|
|
|
|
onOver(evt: Laya.Event): void {
|
|
|
|
|
const Box = evt.target as Laya.Box
|
|
|
|
|
const sprite = Box.getChildByName("Sprite") as Laya.Sprite
|
|
|
|
|
sprite.graphics.clear()
|
|
|
|
|
sprite.graphics.drawRoundRect(0, 0, sprite.width, sprite.height, 12, 12, 12, 12, "#0e2a53")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onOut(evt: Laya.Event): void {
|
|
|
|
|
const Box = evt.target as Laya.Box
|
|
|
|
|
const sprite = Box.getChildByName("Sprite") as Laya.Sprite
|
|
|
|
|
sprite.graphics.clear()
|
|
|
|
|
sprite.graphics.drawRoundRect(0, 0, sprite.width, sprite.height, 12, 12, 12, 12, "#f5f7fb")
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-28 18:47:51 +08:00
|
|
|
}
|