From 28107a24f9c34cb0f2dcc98e7c11fbdf001b521d Mon Sep 17 00:00:00 2001 From: yangwen Date: Wed, 4 Jun 2025 17:52:58 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9A=BE=E5=BA=A6=E9=80=89=E6=8B=A9hover?= =?UTF-8?q?=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/TopBar.ts | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/src/views/TopBar.ts b/src/views/TopBar.ts index 56e75bb..45acbe1 100644 --- a/src/views/TopBar.ts +++ b/src/views/TopBar.ts @@ -36,6 +36,7 @@ export class TopBar extends Laya.Script { @property(Laya.Box) public obj_items: Laya.Box + private item_sprites: Map = new Map() private item_labels: Map = 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 sprite = Box.getChildByName("Sprite") as Laya.Sprite - sprite.graphics.clear() - sprite.graphics.drawRoundRect(0, 0, sprite.width, sprite.height, 12, 12, 12, 12, "#0e2a53") + 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 sprite = Box.getChildByName("Sprite") as Laya.Sprite - sprite.graphics.clear() - sprite.graphics.drawRoundRect(0, 0, sprite.width, sprite.height, 12, 12, 12, 12, "#f5f7fb") + 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") + } } }