openquell/game/about_scene.go

90 lines
1.8 KiB
Go

package game
import (
"image/color"
"log/slog"
"openquell/assets"
"openquell/gameui"
"github.com/ebitenui/ebitenui"
"github.com/ebitenui/ebitenui/widget"
"github.com/hajimehoshi/ebiten/v2"
)
type AboutScene struct {
Game *Game
Next SceneName
Whoami SceneName
UseCache bool
Ui *ebitenui.UI
}
const ABOUT string = `
This is a little Quell clone written by
Thomas von Dein <tom@vondein.org>.
Download it on repo.daemon.de/openquell/.
Copyright (c) 2024 by Thomas von Dein.
`
func NewAboutScene(game *Game) Scene {
scene := &AboutScene{Whoami: About, Game: game, Next: About}
scene.SetupUI()
return scene
}
func (scene *AboutScene) GetNext() SceneName {
return scene.Next
}
func (scene *AboutScene) SetNext(next SceneName) {
slog.Debug("about setnext", "next", next)
scene.Next = next
}
func (scene *AboutScene) ResetNext() {
scene.Next = scene.Whoami
}
func (scene *AboutScene) Update() error {
scene.Ui.Update()
return nil
}
func (scene *AboutScene) Draw(screen *ebiten.Image) {
scene.Ui.Draw(screen)
}
func (scene *AboutScene) SetupUI() {
blue := color.RGBA{0, 255, 128, 255}
rowContainer := gameui.NewRowContainer()
buttonBack := gameui.NewMenuButton("Back", *assets.FontRenderer.FontNormal,
func(args *widget.ButtonClickedEventArgs) {
scene.SetNext(Select)
})
label := widget.NewText(
widget.TextOpts.Text("About this game", *assets.FontRenderer.FontBig, blue),
widget.TextOpts.Position(widget.TextPositionCenter, widget.TextPositionCenter),
)
about := widget.NewText(
widget.TextOpts.Text(ABOUT, *assets.FontRenderer.FontNormal, blue),
widget.TextOpts.Position(widget.TextPositionStart, widget.TextPositionCenter),
)
rowContainer.AddChild(label)
rowContainer.AddChild(about)
rowContainer.AddChild(buttonBack)
scene.Ui = &ebitenui.UI{
Container: rowContainer.Container(),
}
}