Fixed Escape not working in the menu when playing the game.

This commit is contained in:
Sander Schobers 2019-12-28 16:14:42 +01:00
parent 11ab3fca0f
commit 11e49d1249
2 changed files with 8 additions and 7 deletions

View File

@ -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 {

View File

@ -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
}