From 11e49d1249eaead514296b50d25f19d4319a1d16 Mon Sep 17 00:00:00 2001 From: Sander Schobers Date: Sat, 28 Dec 2019 16:14:42 +0100 Subject: [PATCH] Fixed Escape not working in the menu when playing the game. --- alui/menu.go | 6 ++++++ cmd/krampus19/playlevel.go | 9 ++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/alui/menu.go b/alui/menu.go index 3aa532c..f4c29a7 100644 --- a/alui/menu.go +++ b/alui/menu.go @@ -7,6 +7,8 @@ import ( type Menu struct { Column + OnEscape func() + active int buttons []*Button } @@ -56,6 +58,10 @@ func (m *Menu) Handle(e allg5.Event) { if onClick := m.buttons[m.active].OnClick; onClick != nil { onClick() } + case allg5.KeyEscape: + if onEscape := m.OnEscape; onEscape != nil { + onEscape() + } } case *allg5.MouseMoveEvent: for i, btn := range m.buttons { diff --git a/cmd/krampus19/playlevel.go b/cmd/krampus19/playlevel.go index 7adada7..8cf95f4 100644 --- a/cmd/krampus19/playlevel.go +++ b/cmd/krampus19/playlevel.go @@ -24,6 +24,7 @@ type playLevel struct { state playLevelState } + type keyPressedState map[allg5.Key]bool func (s keyPressedState) CountPressed(keys ...allg5.Key) int { @@ -81,6 +82,7 @@ func (l *playLevel) Enter(ctx *Context) error { l.menu.Add("Restart", func() { l.ctx.Navigation.playLevel(l.name) }) l.menu.Add("Quit to main menu", func() { l.ctx.Navigation.showMainMenu() }) l.menu.Add("Quit to desktop", func() { l.ctx.Navigation.quit() }) + l.menu.OnEscape = func() { l.showMenu = false } l.state.Init(l.ctx, l.name) return nil @@ -137,13 +139,6 @@ func (l *playLevel) Handle(e allg5.Event) { if l.showMenu { l.menu.Handle(e) - switch e := e.(type) { - case *allg5.KeyDownEvent: - switch e.KeyCode { - case allg5.KeyEscape: - l.showMenu = false - } - } return }