1
0
Fork 0

Compare commits

..

No commits in common. "eb7486f57cf9878cd626fcbf39417b714e9acaef" and "46552f0ed257f7ae74751588a28a3ac3a51e4434" have entirely different histories.

2 changed files with 5 additions and 20 deletions

View file

@ -2,7 +2,6 @@ package handlers
import (
"tetris/assets"
"tetris/engine/audio"
"tetris/engine/render"
"tetris/game"
"tetris/game/state"
@ -18,26 +17,19 @@ type MainMenu struct {
list *layouts.ListBox
}
func enterState(fsm state.Transitioner, state string) func() {
return func() {
audio.Play(assets.SFX_MENU_ENTER)
fsm.Switch(state)
}
}
func NewMainMenu(fsm state.Transitioner) *MainMenu {
return &MainMenu{
list: layouts.NewListBox([]ui.InputWidget{
widgets.NewButton("Start", 32, enterState(fsm, "gameplay")),
widgets.NewButton("Options", 32, enterState(fsm, "options")),
widgets.NewButton("Quit", 32, enterState(fsm, "quit")),
widgets.NewButton("Start", 32, func() { fsm.Switch("gameplay") }),
widgets.NewButton("Options", 32, func() { fsm.Switch("options") }),
widgets.NewButton("Quit", 32, func() { fsm.Switch("quit") }),
}).Spacing(10).
OnSelect(uievents.MenuSelect),
}
}
func (main *MainMenu) Enter() {
main.list.SetSelected(0)
main.list.Select(0)
}
func (MainMenu) Exit() {

View file

@ -42,19 +42,12 @@ func (lb ListBox) Entries() []ui.InputWidget {
}
func (lb *ListBox) Select(index int) {
if lb.SetSelected(index) {
lb.onSelect()
}
}
func (lb *ListBox) SetSelected(index int) bool {
if index >= 0 && index < len(lb.entries) {
lb.entries[lb.selected].SetFocus(false)
lb.selected = index
lb.entries[lb.selected].SetFocus(true)
return true
lb.onSelect()
}
return false
}
func (lb ListBox) Selected() ui.InputWidget {