package main import ( "log" // "muhq.space/muhqs-game/go/game" "muhq.space/muhqs-game/go/ui" ) const ( START_BUTTON_WIDTH = 150 START_BUTTON_HEIGHT = 50 DECK_LIST_WIDTH = 300 DECK_LIST_HEIGHT = 500 ) type StartMenu struct { ui.Collection app *app deckInput *ui.TextInput playerName string startDeck string remote string mapPath string } func NewStartMenu(app *app) *StartMenu { m := &StartMenu{app: app} return m } func (m *StartMenu) build() { deckInput := ui.NewTextInput( (m.Width-DECK_LIST_WIDTH)/2, (m.Height-DECK_LIST_HEIGHT)/2, DECK_LIST_WIDTH, DECK_LIST_HEIGHT, "deck", ) deckInput.Bg(ui.Gray) if m.startDeck != "" { deckInput.AddInput([]rune(m.startDeck)) } m.deckInput = deckInput m.AddWidget(deckInput) m.AddWidget(ui.NewFixedTextBox( (m.Width-START_BUTTON_WIDTH)/2-START_BUTTON_WIDTH, deckInput.Y-START_BUTTON_HEIGHT, START_BUTTON_WIDTH, START_BUTTON_HEIGHT, "map:", ).Centering(true)) mapInput := ui.NewTextInput( (m.Width-START_BUTTON_WIDTH)/2, deckInput.Y-START_BUTTON_HEIGHT, START_BUTTON_WIDTH, START_BUTTON_HEIGHT, "map", ) if m.mapPath != "" { mapInput.AddInput([]rune(m.mapPath)) } m.AddWidget(mapInput) m.AddWidget(ui.NewFixedTextBox( (m.Width-START_BUTTON_WIDTH)/2-START_BUTTON_WIDTH, mapInput.Y-START_BUTTON_HEIGHT, START_BUTTON_WIDTH, START_BUTTON_HEIGHT, "name:", ).Centering(true)) playerInput := ui.NewTextInput( (m.Width-START_BUTTON_WIDTH)/2, mapInput.Y-START_BUTTON_HEIGHT, START_BUTTON_WIDTH, START_BUTTON_HEIGHT, "player name", ) if m.playerName != "" { playerInput.AddInput([]rune(m.playerName)) } m.AddWidget(playerInput) m.AddWidget(ui.NewSimpleButton( (m.Width-START_BUTTON_WIDTH)/2+START_BUTTON_WIDTH/2, deckInput.Y+deckInput.Height, START_BUTTON_WIDTH, START_BUTTON_HEIGHT, "Sealed", func(*ui.SimpleButton) { sealed := NewSealed(m.Width, m.Height, m.app) m.app.pushActivity(sealed) })) m.AddWidget(ui.NewSimpleButton( (m.Width-START_BUTTON_WIDTH)/2-START_BUTTON_WIDTH/2, deckInput.Y+deckInput.Height, START_BUTTON_WIDTH, START_BUTTON_HEIGHT, "Start", func(*ui.SimpleButton) { m.playerName = playerInput.Text() m.mapPath = mapInput.Text() m.startDeck = deckInput.Text() m.startGame() })) } func (m *StartMenu) Update() error { if m.Widgets() == nil { m.build() } return m.Collection.Update() } func (m *StartMenu) Layout(width, height int) (int, int) { return m.Width, m.Height } func (m *StartMenu) startGame() { 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 } m.app.pushActivity(g.Start()) }