2024-04-24 17:11:33 +03:00
|
|
|
package state
|
|
|
|
|
|
|
|
import (
|
2024-05-06 20:43:35 +03:00
|
|
|
"mvvasilev/last_light/engine"
|
2024-06-06 23:17:22 +03:00
|
|
|
"mvvasilev/last_light/game/systems"
|
2024-05-06 20:43:35 +03:00
|
|
|
"mvvasilev/last_light/game/ui"
|
2024-04-24 17:11:33 +03:00
|
|
|
|
|
|
|
"github.com/gdamore/tcell/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
type MainMenuState struct {
|
2024-06-06 23:17:22 +03:00
|
|
|
turnSystem *systems.TurnSystem
|
|
|
|
inputSystem *systems.InputSystem
|
2024-05-30 23:39:54 +03:00
|
|
|
|
2024-05-06 20:43:35 +03:00
|
|
|
menuTitle *engine.Raw
|
2024-04-24 17:11:33 +03:00
|
|
|
buttons []*ui.UISimpleButton
|
|
|
|
currButtonSelected int
|
|
|
|
|
|
|
|
quitGame bool
|
|
|
|
startNewGame bool
|
|
|
|
}
|
|
|
|
|
2024-06-06 23:17:22 +03:00
|
|
|
func CreateMainMenuState(turnSystem *systems.TurnSystem, inputSystem *systems.InputSystem) *MainMenuState {
|
2024-05-30 23:39:54 +03:00
|
|
|
turnSystem.Clear()
|
|
|
|
|
2024-04-24 17:11:33 +03:00
|
|
|
state := new(MainMenuState)
|
|
|
|
|
|
|
|
highlightStyle := tcell.StyleDefault.Attributes(tcell.AttrBold)
|
|
|
|
|
2024-05-30 23:39:54 +03:00
|
|
|
state.turnSystem = turnSystem
|
|
|
|
state.inputSystem = inputSystem
|
|
|
|
|
2024-05-06 20:43:35 +03:00
|
|
|
state.menuTitle = engine.CreateRawDrawable(
|
2024-04-24 17:11:33 +03:00
|
|
|
11, 1, tcell.StyleDefault.Attributes(tcell.AttrBold).Foreground(tcell.ColorYellow),
|
|
|
|
" | | | _) | | ",
|
|
|
|
" | _` | __| __| | | _` | __ \\ __|",
|
|
|
|
" | ( | \\__ \\ | | | ( | | | | | ",
|
|
|
|
"_____| \\__,_| ____/ \\__| _____| _| \\__, | _| |_| \\__|",
|
|
|
|
" |___/ ",
|
|
|
|
)
|
|
|
|
state.buttons = make([]*ui.UISimpleButton, 0)
|
|
|
|
state.buttons = append(state.buttons, ui.CreateSimpleButton(11, 7, "New Game", tcell.StyleDefault, highlightStyle, func() {
|
|
|
|
state.startNewGame = true
|
|
|
|
}))
|
2024-06-06 23:17:22 +03:00
|
|
|
state.buttons = append(state.buttons, ui.CreateSimpleButton(11, 9, "Key Bindings // TODO", tcell.StyleDefault, highlightStyle, func() {
|
2024-04-24 17:11:33 +03:00
|
|
|
|
|
|
|
}))
|
|
|
|
state.buttons = append(state.buttons, ui.CreateSimpleButton(11, 11, "Quit", tcell.StyleDefault, highlightStyle, func() {
|
|
|
|
state.quitGame = true
|
|
|
|
}))
|
|
|
|
|
|
|
|
state.currButtonSelected = 0
|
|
|
|
state.buttons[state.currButtonSelected].Highlight()
|
|
|
|
|
|
|
|
return state
|
|
|
|
}
|
|
|
|
|
2024-06-06 23:17:22 +03:00
|
|
|
func (s *MainMenuState) InputContext() systems.InputContext {
|
|
|
|
return systems.InputContext_Menu
|
2024-05-30 23:39:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (mms *MainMenuState) OnTick(dt int64) GameState {
|
|
|
|
nextAction := mms.inputSystem.NextAction()
|
|
|
|
|
2024-06-06 23:17:22 +03:00
|
|
|
if nextAction == systems.InputAction_Menu_HighlightDown {
|
2024-04-24 17:11:33 +03:00
|
|
|
mms.buttons[mms.currButtonSelected].Unhighlight()
|
2024-05-06 21:47:20 +03:00
|
|
|
mms.currButtonSelected = engine.LimitIncrement(mms.currButtonSelected, 2)
|
2024-04-24 17:11:33 +03:00
|
|
|
mms.buttons[mms.currButtonSelected].Highlight()
|
|
|
|
}
|
|
|
|
|
2024-06-06 23:17:22 +03:00
|
|
|
if nextAction == systems.InputAction_Menu_HighlightUp {
|
2024-04-24 17:11:33 +03:00
|
|
|
mms.buttons[mms.currButtonSelected].Unhighlight()
|
2024-05-06 21:47:20 +03:00
|
|
|
mms.currButtonSelected = engine.LimitDecrement(mms.currButtonSelected, 0)
|
2024-04-24 17:11:33 +03:00
|
|
|
mms.buttons[mms.currButtonSelected].Highlight()
|
|
|
|
}
|
|
|
|
|
2024-06-06 23:17:22 +03:00
|
|
|
if nextAction == systems.InputAction_Menu_Select {
|
2024-04-24 17:11:33 +03:00
|
|
|
mms.buttons[mms.currButtonSelected].Select()
|
|
|
|
}
|
|
|
|
|
|
|
|
if mms.quitGame {
|
|
|
|
return &QuitState{}
|
|
|
|
}
|
|
|
|
|
|
|
|
if mms.startNewGame {
|
2024-05-31 23:37:06 +03:00
|
|
|
return CreateCharacterCreationState(mms.turnSystem, mms.inputSystem)
|
2024-04-24 17:11:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return mms
|
|
|
|
}
|
|
|
|
|
2024-05-06 20:43:35 +03:00
|
|
|
func (mms *MainMenuState) CollectDrawables() []engine.Drawable {
|
|
|
|
arr := make([]engine.Drawable, 0)
|
2024-04-27 22:32:05 +03:00
|
|
|
|
|
|
|
arr = append(arr, mms.menuTitle)
|
2024-04-24 17:11:33 +03:00
|
|
|
|
|
|
|
for _, b := range mms.buttons {
|
2024-04-27 22:32:05 +03:00
|
|
|
arr = append(arr, b)
|
2024-04-24 17:11:33 +03:00
|
|
|
}
|
2024-04-27 22:32:05 +03:00
|
|
|
|
|
|
|
return arr
|
2024-04-24 17:11:33 +03:00
|
|
|
}
|