Fixed Escape not working in the menu when playing the game.
This commit is contained in:
parent
11ab3fca0f
commit
11e49d1249
@ -7,6 +7,8 @@ import (
|
|||||||
type Menu struct {
|
type Menu struct {
|
||||||
Column
|
Column
|
||||||
|
|
||||||
|
OnEscape func()
|
||||||
|
|
||||||
active int
|
active int
|
||||||
buttons []*Button
|
buttons []*Button
|
||||||
}
|
}
|
||||||
@ -56,6 +58,10 @@ func (m *Menu) Handle(e allg5.Event) {
|
|||||||
if onClick := m.buttons[m.active].OnClick; onClick != nil {
|
if onClick := m.buttons[m.active].OnClick; onClick != nil {
|
||||||
onClick()
|
onClick()
|
||||||
}
|
}
|
||||||
|
case allg5.KeyEscape:
|
||||||
|
if onEscape := m.OnEscape; onEscape != nil {
|
||||||
|
onEscape()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case *allg5.MouseMoveEvent:
|
case *allg5.MouseMoveEvent:
|
||||||
for i, btn := range m.buttons {
|
for i, btn := range m.buttons {
|
||||||
|
@ -24,6 +24,7 @@ type playLevel struct {
|
|||||||
|
|
||||||
state playLevelState
|
state playLevelState
|
||||||
}
|
}
|
||||||
|
|
||||||
type keyPressedState map[allg5.Key]bool
|
type keyPressedState map[allg5.Key]bool
|
||||||
|
|
||||||
func (s keyPressedState) CountPressed(keys ...allg5.Key) int {
|
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("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 main menu", func() { l.ctx.Navigation.showMainMenu() })
|
||||||
l.menu.Add("Quit to desktop", func() { l.ctx.Navigation.quit() })
|
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)
|
l.state.Init(l.ctx, l.name)
|
||||||
return nil
|
return nil
|
||||||
@ -137,13 +139,6 @@ func (l *playLevel) Handle(e allg5.Event) {
|
|||||||
|
|
||||||
if l.showMenu {
|
if l.showMenu {
|
||||||
l.menu.Handle(e)
|
l.menu.Handle(e)
|
||||||
switch e := e.(type) {
|
|
||||||
case *allg5.KeyDownEvent:
|
|
||||||
switch e.KeyCode {
|
|
||||||
case allg5.KeyEscape:
|
|
||||||
l.showMenu = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user