94 lines
2.1 KiB
Go
94 lines
2.1 KiB
Go
package game
|
|
|
|
import (
|
|
"image/color"
|
|
"log/slog"
|
|
"openquell/assets"
|
|
"openquell/gameui"
|
|
"os"
|
|
|
|
"github.com/ebitenui/ebitenui"
|
|
"github.com/ebitenui/ebitenui/widget"
|
|
|
|
"github.com/hajimehoshi/ebiten/v2"
|
|
)
|
|
|
|
type SelectScene struct {
|
|
Game *Game
|
|
Next SceneName
|
|
Whoami SceneName
|
|
UseCache bool
|
|
Ui *ebitenui.UI
|
|
}
|
|
|
|
func NewSelectScene(game *Game) Scene {
|
|
scene := &SelectScene{Whoami: Select, Game: game, Next: Select}
|
|
|
|
scene.SetupUI()
|
|
|
|
return scene
|
|
}
|
|
|
|
func (scene *SelectScene) GetNext() SceneName {
|
|
return scene.Next
|
|
}
|
|
|
|
func (scene *SelectScene) ResetNext() {
|
|
scene.Next = scene.Whoami
|
|
}
|
|
|
|
func (scene *SelectScene) SetNext(next SceneName) {
|
|
slog.Debug("select setnext", "next", next)
|
|
scene.Next = next
|
|
}
|
|
|
|
func (scene *SelectScene) Update() error {
|
|
scene.Ui.Update()
|
|
return nil
|
|
}
|
|
|
|
func (scene *SelectScene) Draw(screen *ebiten.Image) {
|
|
scene.Ui.Draw(screen)
|
|
}
|
|
|
|
func (scene *SelectScene) SetupUI() {
|
|
blue := color.RGBA{0, 255, 128, 255}
|
|
|
|
rowContainer := gameui.NewRowContainer()
|
|
|
|
buttonStartnew := gameui.NewMenuButton("Start new game", *assets.FontRenderer.FontNormal,
|
|
func(args *widget.ButtonClickedEventArgs) {
|
|
scene.SetNext(Play)
|
|
})
|
|
|
|
buttonSelectLevel := 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(
|
|
widget.TextOpts.Text("Menu", *assets.FontRenderer.FontBig, blue),
|
|
widget.TextOpts.Position(widget.TextPositionCenter, widget.TextPositionCenter),
|
|
)
|
|
|
|
rowContainer.AddChild(label)
|
|
rowContainer.AddChild(buttonStartnew)
|
|
rowContainer.AddChild(buttonSelectLevel)
|
|
rowContainer.AddChild(buttonAbout)
|
|
rowContainer.AddChild(buttonQuit)
|
|
|
|
scene.Ui = &ebitenui.UI{
|
|
Container: rowContainer.Container(),
|
|
}
|
|
}
|