2024-02-18 18:19:34 +01:00
|
|
|
package game
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"log/slog"
|
|
|
|
|
"openquell/assets"
|
2024-04-07 12:05:37 +02:00
|
|
|
"openquell/config"
|
2024-02-18 18:19:34 +01:00
|
|
|
"openquell/gameui"
|
|
|
|
|
"os"
|
|
|
|
|
|
|
|
|
|
"github.com/ebitenui/ebitenui"
|
|
|
|
|
"github.com/ebitenui/ebitenui/widget"
|
|
|
|
|
|
|
|
|
|
"github.com/hajimehoshi/ebiten/v2"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type MenuScene struct {
|
|
|
|
|
Game *Game
|
|
|
|
|
Next SceneName
|
|
|
|
|
Whoami SceneName
|
|
|
|
|
UseCache bool
|
|
|
|
|
Ui *ebitenui.UI
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewMenuScene(game *Game) Scene {
|
|
|
|
|
scene := &MenuScene{Whoami: Menu, Game: game, Next: Menu}
|
|
|
|
|
|
|
|
|
|
scene.SetupUI()
|
|
|
|
|
|
|
|
|
|
return scene
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (scene *MenuScene) GetNext() SceneName {
|
|
|
|
|
return scene.Next
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (scene *MenuScene) ResetNext() {
|
|
|
|
|
scene.Next = scene.Whoami
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-21 12:50:17 +01:00
|
|
|
func (scene *MenuScene) SetLevel(level int) {}
|
|
|
|
|
|
2024-02-18 18:19:34 +01:00
|
|
|
func (scene *MenuScene) SetNext(next SceneName) {
|
|
|
|
|
slog.Debug("select setnext", "next", next)
|
|
|
|
|
scene.Next = next
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (scene *MenuScene) Clearscreen() bool {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (scene *MenuScene) Update() error {
|
|
|
|
|
scene.Ui.Update()
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (scene *MenuScene) Draw(screen *ebiten.Image) {
|
|
|
|
|
scene.Ui.Draw(screen)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (scene *MenuScene) SetupUI() {
|
|
|
|
|
rowContainer := gameui.NewRowContainer()
|
|
|
|
|
|
|
|
|
|
buttonStartnew := gameui.NewMenuButton("Start new game", *assets.FontRenderer.FontNormal,
|
|
|
|
|
func(args *widget.ButtonClickedEventArgs) {
|
|
|
|
|
scene.SetNext(Play)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
buttonMenuLevel := gameui.NewMenuButton("Select Level", *assets.FontRenderer.FontNormal,
|
|
|
|
|
func(args *widget.ButtonClickedEventArgs) {
|
|
|
|
|
scene.SetNext(Select)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
buttonAbout := gameui.NewMenuButton("About this game", *assets.FontRenderer.FontNormal,
|
|
|
|
|
func(args *widget.ButtonClickedEventArgs) {
|
|
|
|
|
scene.SetNext(About)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
buttonQuit := gameui.NewMenuButton("Quit Game", *assets.FontRenderer.FontNormal,
|
|
|
|
|
func(args *widget.ButtonClickedEventArgs) {
|
|
|
|
|
os.Exit(1) // FIXME: present another scene "are you sure and/or thank you"
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
label := widget.NewText(
|
2024-04-07 12:05:37 +02:00
|
|
|
widget.TextOpts.Text("Menu", *assets.FontRenderer.FontBig, config.FontColorFG),
|
2024-02-18 18:19:34 +01:00
|
|
|
widget.TextOpts.Position(widget.TextPositionCenter, widget.TextPositionCenter),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
rowContainer.AddChild(label)
|
|
|
|
|
rowContainer.AddChild(buttonStartnew)
|
|
|
|
|
rowContainer.AddChild(buttonMenuLevel)
|
|
|
|
|
rowContainer.AddChild(buttonAbout)
|
|
|
|
|
rowContainer.AddChild(buttonQuit)
|
|
|
|
|
|
|
|
|
|
scene.Ui = &ebitenui.UI{
|
|
|
|
|
Container: rowContainer.Container(),
|
|
|
|
|
}
|
|
|
|
|
}
|