Compare commits
3 commits
46552f0ed2
...
eb7486f57c
| Author | SHA1 | Date | |
|---|---|---|---|
| eb7486f57c | |||
| ef798896c3 | |||
| f3d7995bc2 |
2 changed files with 20 additions and 5 deletions
|
|
@ -2,6 +2,7 @@ package handlers
|
|||
|
||||
import (
|
||||
"tetris/assets"
|
||||
"tetris/engine/audio"
|
||||
"tetris/engine/render"
|
||||
"tetris/game"
|
||||
"tetris/game/state"
|
||||
|
|
@ -17,19 +18,26 @@ 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, func() { fsm.Switch("gameplay") }),
|
||||
widgets.NewButton("Options", 32, func() { fsm.Switch("options") }),
|
||||
widgets.NewButton("Quit", 32, func() { fsm.Switch("quit") }),
|
||||
widgets.NewButton("Start", 32, enterState(fsm, "gameplay")),
|
||||
widgets.NewButton("Options", 32, enterState(fsm, "options")),
|
||||
widgets.NewButton("Quit", 32, enterState(fsm, "quit")),
|
||||
}).Spacing(10).
|
||||
OnSelect(uievents.MenuSelect),
|
||||
}
|
||||
}
|
||||
|
||||
func (main *MainMenu) Enter() {
|
||||
main.list.Select(0)
|
||||
main.list.SetSelected(0)
|
||||
}
|
||||
|
||||
func (MainMenu) Exit() {
|
||||
|
|
|
|||
|
|
@ -42,12 +42,19 @@ 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)
|
||||
lb.onSelect()
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (lb ListBox) Selected() ui.InputWidget {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue