allow closing the radial or build menu with the esc key

This commit is contained in:
Sean Lowe
2025-02-21 14:56:19 -07:00
parent 5898f0360c
commit 13a0593689
2 changed files with 21 additions and 0 deletions
+7
View File
@@ -48,6 +48,8 @@ export class AlternateViewEvent implements GameEvent {
constructor(public readonly alternateView: boolean) {}
}
export class CloseViewEvent implements GameEvent {}
export class RefreshGraphicsEvent implements GameEvent {}
export class ShowBuildMenuEvent implements GameEvent {
@@ -149,6 +151,11 @@ export class InputHandler {
}
}
if (e.code === "Escape") {
e.preventDefault();
this.eventBus.emit(new CloseViewEvent());
}
// Add all movement keys to activeKeys
if (
[
+14
View File
@@ -8,6 +8,7 @@ import {
} from "../../../core/game/Game";
import { ClientID } from "../../../core/Schemas";
import {
CloseViewEvent,
ContextMenuEvent,
MouseUpEvent,
ShowBuildMenuEvent,
@@ -123,9 +124,22 @@ export class RadialMenu implements Layer {
}
this.buildMenu.showMenu(tile);
});
this.eventBus.on(CloseViewEvent, () => this.closeMenu());
this.createMenuElement();
}
private closeMenu() {
if (this.isVisible) {
this.hideRadialMenu();
}
if (this.buildMenu.isVisible) {
this.buildMenu.hideMenu();
}
}
private createMenuElement() {
this.menuElement = d3
.select(document.body)