import { config } from "../constants/config"; import { StorageManager } from "../models/StorageManager"; import { UIManager } from "../models/UIManager"; import { CommonData } from "./common/CommonData"; const { regClass, property } = Laya; @regClass() export class TopBar extends Laya.Script { declare owner : Laya.Box; @property(Laya.Box) public btn_classic: Laya.Box @property(Laya.Sprite) public sprite_classic: Laya.Sprite @property(Laya.Label) public label_classic: Laya.Label @property(Laya.Box) public btn_dc: Laya.Box @property(Laya.Sprite) public sprite_dc: Laya.Sprite @property(Laya.Label) public label_dc: Laya.Label private isClassic: boolean = true @property(Laya.Box) public obj_items: Laya.Box private items: Map = new Map() onStart(): void { this.btn_classic.on(Laya.Event.CLICK, this, ()=>{ if (this.isClassic == false) { this.isClassic = true this.setLeftTab() } }) this.btn_dc.on(Laya.Event.CLICK, this, ()=>{ if (this.isClassic) { this.isClassic = false this.setLeftTab() } }) this.setLeftTab() for (var i=0; i{ 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) } }) } //如果是第一次以横屏启动游戏需要创建经典关卡 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) } setLeftTab(): 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) } } setDifficulty(difficulty: string): void { this.items.forEach((label: Laya.Label, key: string)=>{ label.color = "#0e2a53" }) var label = this.items.get(difficulty) label.color = "#1d5cdc" } }