难度选择hover效果

This commit is contained in:
2025-06-04 17:52:58 +08:00
parent 89b70a288c
commit 28107a24f9

View File

@@ -36,6 +36,7 @@ export class TopBar extends Laya.Script {
@property(Laya.Box)
public obj_items: Laya.Box
private item_sprites: Map<string, Laya.Sprite> = new Map()
private item_labels: Map<string, Laya.Label> = new Map()
onStart(): void {
@@ -81,6 +82,8 @@ export class TopBar extends Laya.Script {
obj.on(Laya.Event.MOUSE_OVER, this, this.onOver)
obj.on(Laya.Event.MOUSE_OUT, this, this.onOut)
const value = config.DIFFICULTY_LIST[i]
const Sprite = obj.getChildByName("Sprite") as Laya.Sprite
this.item_sprites.set(value, Sprite)
const label = obj.getChildByName("Label") as Laya.Label
label.text = value
this.item_labels.set(value, label)
@@ -142,6 +145,14 @@ export class TopBar extends Laya.Script {
}
updateDifficulty(difficulty: string): void {
this.item_sprites.forEach((sprite: Laya.Sprite) => {
sprite.graphics.clear()
sprite.graphics.drawRoundRect(0, 0, sprite.width, sprite.height, 12, 12, 12, 12, "#f5f7fb")
})
const sprite = this.item_sprites.get(difficulty)
sprite.graphics.clear()
sprite.graphics.drawRoundRect(0, 0, sprite.width, sprite.height, 12, 12, 12, 12, "#f5f7fb", "#1d5cdc", 5)
this.item_labels.forEach((label: Laya.Label) => {
label.color = "#0e2a53"
})
@@ -150,18 +161,26 @@ export class TopBar extends Laya.Script {
}
onOver(evt: Laya.Event): void {
Laya.Render.canvas.style.cursor = "pointer"
const difficulty = Laya.LocalStorage.getItem("difficulty")
const Box = evt.target as Laya.Box
const common = Box.getComponent(CommonData)
if (common.strValue !== difficulty) {
Laya.Render.canvas.style.cursor = "pointer"
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 {
Laya.Render.canvas.style.cursor = ""
const difficulty = Laya.LocalStorage.getItem("difficulty")
const Box = evt.target as Laya.Box
const common = Box.getComponent(CommonData)
if (common.strValue !== difficulty) {
Laya.Render.canvas.style.cursor = ""
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")
}
}
}