64 lines
1.9 KiB
TypeScript
64 lines
1.9 KiB
TypeScript
import { config } from "../constants/config"
|
|
import { Utility_EaseOut, Utility_EaseOut_2 } from "../utils/utility"
|
|
import { CommonData } from "./common/CommonData"
|
|
|
|
const { regClass, property } = Laya
|
|
|
|
@regClass()
|
|
export class Difficulty extends Laya.Script {
|
|
declare owner: Laya.Box
|
|
|
|
@property(Laya.Box)
|
|
public obj_items: Laya.Box
|
|
|
|
private mask: Laya.Image
|
|
private offset: Laya.Box
|
|
|
|
onAwake(): void {
|
|
this.mask = this.owner.getChildByName("mask") as Laya.Image
|
|
this.mask.alpha = 0
|
|
Laya.Tween.to(this.mask, { alpha: 0.4 }, 400, Utility_EaseOut)
|
|
|
|
this.offset = this.owner.getChildByName("bottom").getChildByName("offset") as Laya.Box
|
|
this.offset.y = this.offset.width
|
|
|
|
const bg = this.offset.getChildByName("bg") as Laya.Sprite
|
|
bg.graphics.clear()
|
|
bg.graphics.drawRoundRect(0, 0, this.offset.width, this.offset.height, 20, 20, 0, 0, "#f5f7fb")
|
|
|
|
const mask = this.owner.getChildByName("mask")
|
|
mask.on(Laya.Event.CLICK, this, () => {
|
|
Laya.Tween.to(this.offset, { y: 2400 }, 200, null, Laya.Handler.create(this, () => {
|
|
this.destroyUI()
|
|
}))
|
|
})
|
|
}
|
|
|
|
destroyUI(): void {
|
|
Laya.Tween.to(this.mask, { alpha: 0 }, 400, Utility_EaseOut_2, Laya.Handler.create(this, () => {
|
|
this.owner.destroy()
|
|
}))
|
|
}
|
|
|
|
onStart(): void {
|
|
Laya.Tween.to(this.offset, { y: 0 }, 200)
|
|
}
|
|
|
|
public onInit(callback: any): void {
|
|
for (let i = 0; i < config.DIFFICULTY_LIST.length; i++) {
|
|
const obj = this.obj_items.getChildAt(i)
|
|
const Label = obj.getChildByName("Label") as Laya.Label
|
|
Label.text = config.DIFFICULTY_LIST[i]
|
|
const data = obj.getComponent(CommonData)
|
|
data.strValue = config.DIFFICULTY_LIST[i]
|
|
obj.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
|
|
const data = evt.target.getComponent(CommonData)
|
|
if (callback) {
|
|
callback(data.strValue)
|
|
}
|
|
this.owner.destroy()
|
|
})
|
|
}
|
|
}
|
|
}
|