开始添加横屏UI
This commit is contained in:
@@ -97,10 +97,14 @@ export class Stage extends Laya.Script {
|
||||
}
|
||||
}
|
||||
for (var i=0; i<this.obj_candys.numChildren; i++) {
|
||||
var candy = this.obj_candys.getChildAt(i).getComponent(Candy);
|
||||
this.candys.push(candy);
|
||||
var box = this.obj_candy_labels.getChildAt(i) as Laya.Box
|
||||
candy.onInit(box, this, this.onClickCandy)
|
||||
hbox = this.obj_candys.getChildAt(i)
|
||||
l_hbox = this.obj_candy_labels.getChildAt(i)
|
||||
for (var j=0; j<hbox.numChildren; j++) {
|
||||
var candy = hbox.getChildAt(j).getComponent(Candy);
|
||||
this.candys.push(candy);
|
||||
var box = l_hbox.getChildAt(j) as Laya.Box
|
||||
candy.onInit(box, this, this.onClickCandy)
|
||||
}
|
||||
}
|
||||
|
||||
this.btn_undo.on(Laya.Event.CLICK, this, this.onClickUndo)
|
||||
|
||||
103
src/views/TopBar.ts
Normal file
103
src/views/TopBar.ts
Normal file
@@ -0,0 +1,103 @@
|
||||
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<string, Laya.Label> = 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<this.obj_items.numChildren; i++) {
|
||||
var obj = this.obj_items.getChildAt(i)
|
||||
var value = config.DIFFICULTY_LIST[i]
|
||||
var label = obj.getChildByName("Label") as Laya.Label
|
||||
label.text = value
|
||||
this.items.set(value, label)
|
||||
var common = obj.getComponent(CommonData)
|
||||
common.strValue = value
|
||||
obj.on(Laya.Event.CLICK, this, (evt: Laya.Event)=>{
|
||||
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"
|
||||
}
|
||||
}
|
||||
3
src/views/TopBar.ts.meta
Normal file
3
src/views/TopBar.ts.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"uuid": "cadd567d-5099-49b9-a9b3-b7c404d5fe1b"
|
||||
}
|
||||
@@ -1,11 +1,10 @@
|
||||
import { config } from "../constants/config";
|
||||
import { Utility_ConvertSecondToString } from "../utils/utility";
|
||||
import { StorageManager } from "../models/StorageManager";
|
||||
import { config } from "../../constants/config";
|
||||
import { Utility_ConvertSecondToString } from "../../utils/utility";
|
||||
import { StorageManager } from "../../models/StorageManager";
|
||||
import { CalendarUnit } from "./CalendarUnit";
|
||||
import { LevelManager } from "../models/LevelManager";
|
||||
import { UIManager } from "../models/UIManager";
|
||||
import { respath } from "../constants/respath";
|
||||
import { MONTH_LIST } from "../models/DCManager";
|
||||
import { UIManager } from "../../models/UIManager";
|
||||
import { respath } from "../../constants/respath";
|
||||
import { MONTH_LIST } from "../../models/DCManager";
|
||||
|
||||
|
||||
const { regClass, property } = Laya;
|
||||
@@ -1,6 +1,6 @@
|
||||
import { config } from "../constants/config";
|
||||
import { MONTH_LIST } from "../models/DCManager";
|
||||
import { TrophyRecord } from "../types/global";
|
||||
import { config } from "../../constants/config";
|
||||
import { MONTH_LIST } from "../../models/DCManager";
|
||||
import { TrophyRecord } from "../../types/global";
|
||||
|
||||
const { regClass, property } = Laya;
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
|
||||
|
||||
import { respath } from "../constants/respath";
|
||||
import { MONTH_LIST } from "../models/DCManager";
|
||||
import { respath } from "../../constants/respath";
|
||||
import { MONTH_LIST } from "../../models/DCManager";
|
||||
import { TrophyUnit } from "./TrophyUnit";
|
||||
|
||||
const { regClass, property } = Laya;
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
import { config } from "../constants/config";
|
||||
import { MONTH_LIST } from "../models/DCManager";
|
||||
import { TrophyRecord } from "../types/global";
|
||||
import { config } from "../../constants/config";
|
||||
import { MONTH_LIST } from "../../models/DCManager";
|
||||
import { TrophyRecord } from "../../types/global";
|
||||
|
||||
|
||||
const { regClass, property } = Laya;
|
||||
@@ -1,7 +1,7 @@
|
||||
import { config } from "../constants/config";
|
||||
import { respath } from "../constants/respath";
|
||||
import { StorageManager } from "../models/StorageManager";
|
||||
import { UIManager } from "../models/UIManager";
|
||||
import { config } from "../../constants/config";
|
||||
import { respath } from "../../constants/respath";
|
||||
import { StorageManager } from "../../models/StorageManager";
|
||||
import { UIManager } from "../../models/UIManager";
|
||||
|
||||
const { regClass, property } = Laya;
|
||||
|
||||
Reference in New Issue
Block a user