topbar hover 效果

This commit is contained in:
2025-05-30 18:45:24 +08:00
parent 9cdf29fb66
commit 5add17c02a
3 changed files with 22 additions and 38 deletions

View File

@@ -36,7 +36,6 @@ 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 {
@@ -79,9 +78,9 @@ export class TopBar extends Laya.Script {
for (let i = 0; i < this.obj_items.numChildren; i++) {
const obj = this.obj_items.getChildAt(i)
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)
@@ -143,18 +142,25 @@ 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", "#0e2a53", 5)
})
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"
})
const label = this.item_labels.get(difficulty)
label.color = "#1d5cdc"
}
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")
}
}