package main import ( "log" "github.com/hajimehoshi/ebiten/v2" "github.com/hajimehoshi/ebiten/v2/inpututil" // "muhq.space/muhqs-game/go/game" "muhq.space/muhqs-game/go/ui" ) const ( START_BUTTON_WIDTH = 150 START_BUTTON_HEIGHT = 50 ) type StartMenu struct { app *app width, height int playerName string startDeck string remote string mapPath string widgets []ui.Widget } func NewStartMenu(app *app) *StartMenu { m := &StartMenu{app: app} return m } func (m *StartMenu) build() { m.widgets = append(m.widgets, ui.NewSimpleButton( (m.width-START_BUTTON_WIDTH)/2, (m.height-START_BUTTON_HEIGHT)/2, 150, 50, "Start", func(*ui.SimpleButton) { m.app.active = m.next() })) } func (m *StartMenu) Update() error { if m.widgets == nil { m.build() } x, y := ebiten.CursorPosition() if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonLeft) { for _, w := range m.widgets { if !w.Contains(x, y) { continue } if btn, ok := w.(ui.Button); ok { btn.Click(x, y) } } } return nil } func (m *StartMenu) Draw(screen *ebiten.Image) { for _, w := range m.widgets { w.Draw(screen) } } func (m *StartMenu) Layout(width, height int) (int, int) { return m.width, m.height } func (m *StartMenu) next() ebiten.Game { if m.remote != "" { log.Fatal("Remote games are currently not implemented") } g := newGame(m.app).loadMap(m.mapPath).addActivePlayer(m.playerName, m.startDeck) if m.mapPath == "the-kraken" { idx := len(g.gameState.Players) color := playerColors[idx] g.gameState.AddKraken() g.gameState.Players[idx].Color = color } return g.Start() }