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") + } } }