From 154cf56c5deafb8bcbdef925775c9c565d7f6362 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Fri, 6 Jun 2025 16:42:46 -0500 Subject: refactor client activities Make the activity stack explicit and move reusable activities to the activity package. --- go/client/startMenu.go | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) (limited to 'go/client/startMenu.go') diff --git a/go/client/startMenu.go b/go/client/startMenu.go index 10fa8e1f..10b9e23d 100644 --- a/go/client/startMenu.go +++ b/go/client/startMenu.go @@ -3,6 +3,7 @@ package main import ( "log" + "muhq.space/muhqs-game/go/activities" "muhq.space/muhqs-game/go/game" "muhq.space/muhqs-game/go/ui" ) @@ -15,25 +16,28 @@ const ( DECK_LIST_HEIGHT = 500 ) -type StartMenu struct { +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} +func NewStartMenu(app *app) *startMenu { + m := &startMenu{app: app} return m } -func (m *StartMenu) build() { +func (m *startMenu) build() { deckInput := ui.NewTextInput( (m.Width-DECK_LIST_WIDTH)/2, (m.Height-DECK_LIST_HEIGHT)/2, @@ -101,8 +105,8 @@ func (m *StartMenu) build() { START_BUTTON_HEIGHT, "Sealed", func(*ui.SimpleButton) { - sealed := NewSealed(m.Width, m.Height, m.app) - m.app.pushActivity(sealed) + sealed := activities.NewSealed(m.Width, m.Height) + activities.PushActivity(sealed) })) m.AddWidget(ui.NewSimpleButton( @@ -112,8 +116,8 @@ func (m *StartMenu) build() { START_BUTTON_HEIGHT, "Draft", func(*ui.SimpleButton) { - draft := NewDraft(m.Width, m.Height, m.app) - m.app.pushActivity(draft) + m.draft = activities.NewDraft(m.Width, m.Height, playerInput.Text()) + activities.PushActivity(m.draft) })) m.AddWidget(ui.NewSimpleButton( @@ -130,11 +134,23 @@ func (m *StartMenu) build() { })) } -func (m *StartMenu) Update() error { +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.TouchManager.Update(); err != nil { return err } @@ -142,11 +158,11 @@ func (m *StartMenu) Update() error { return m.Collection.Update() } -func (m *StartMenu) Layout(width, height int) (int, int) { +func (m *startMenu) Layout(width, height int) (int, int) { return m.Width, m.Height } -func (m *StartMenu) startGame() { +func (m *startMenu) startGame() { var state game.State if m.remote != "" { log.Fatal("Remote games are currently not implemented") @@ -162,5 +178,5 @@ func (m *StartMenu) startGame() { g.gameState.AddNewAiPlayer("kraken", color) } - m.app.pushActivity(g.Start()) + activities.PushActivity(g.Start()) } -- cgit v1.2.3