package main import ( "log" "muhq.space/muhqs-game/go/activities" "muhq.space/muhqs-game/go/game" "muhq.space/muhqs-game/go/ui" ) const ( START_BUTTON_WIDTH = 175 START_BUTTON_HEIGHT = 50 DECK_LIST_WIDTH = 350 DECK_LIST_HEIGHT = 500 ) type startMenu struct { ui.Collection app *app deckInput *ui.TextInput draft *activities.Draft sealed *activities.Sealed 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", true, ) 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", false, ) 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", false, ) 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 := activities.NewSealed(m.Width, m.Height) activities.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, "Draft", func(*ui.SimpleButton) { m.draft = activities.NewLocalDraft(m.Width, m.Height, playerInput.Text()) activities.PushActivity(m.draft) })) m.AddWidget(ui.NewSimpleButton( (m.Width-START_BUTTON_WIDTH)/2, deckInput.Y+deckInput.Height+START_BUTTON_HEIGHT+20, START_BUTTON_WIDTH, START_BUTTON_HEIGHT, "Start", func(*ui.SimpleButton) { m.playerName = playerInput.Text() m.mapPath = mapInput.Text() m.startDeck = deckInput.Text() m.startGame() })) m.AddWidget(ui.NewSimpleButton( (m.Width-START_BUTTON_WIDTH)/2, deckInput.Y+deckInput.Height+2*START_BUTTON_HEIGHT+40, START_BUTTON_WIDTH, START_BUTTON_HEIGHT, "Challenges", func(*ui.SimpleButton) { activities.PushActivity(newChallengesMenu(m.app, playerInput.Text())) })) } func (m *startMenu) Update() error { if m.Widgets() == nil { m.build() } // Get the drafted deck if m.draft != nil { m.deckInput.SetInput(m.draft.GetDeckList()) m.draft = nil } // Get the sealed deck if m.sealed != nil { m.deckInput.SetInput(m.sealed.Deck.ToList()) m.sealed = nil } if err := ui.Update(); err != nil { return err } return m.Collection.Update() } func (m *startMenu) Layout(width, height int) (int, int) { return m.Width, m.Height } func (m *startMenu) startGame() { var state game.State if m.remote != "" { log.Fatal("Remote games are currently not implemented") } else { state = game.NewLocalState() } g := newGame(m.app, state).loadMap(m.mapPath).addActivePlayer(m.playerName, m.startDeck) if m.mapPath == "the-kraken" { g.gameState.AddNewAiPlayer("kraken") } activities.PushActivity(g.Start()) }