diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2025-08-20 13:39:41 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-08-20 15:57:41 +0200 |
| commit | 2f1b1f831c97124f0ec7ed7055338f929e9fd984 (patch) | |
| tree | dce2b613f2c7fdd9e5a8750c1034eed6ddd8e046 /go/client | |
| parent | 815d9936d2b75b59a0ff13bb502558809c418f93 (diff) | |
| download | muhqs-game-2f1b1f831c97124f0ec7ed7055338f929e9fd984.tar.gz muhqs-game-2f1b1f831c97124f0ec7ed7055338f929e9fd984.zip | |
add button list activity to simplify challenges and future activities
Diffstat (limited to 'go/client')
| -rw-r--r-- | go/client/challenges.go | 75 | ||||
| -rw-r--r-- | go/client/startMenu.go | 2 |
2 files changed, 28 insertions, 49 deletions
diff --git a/go/client/challenges.go b/go/client/challenges.go index 7a9e1ace..ca6e3563 100644 --- a/go/client/challenges.go +++ b/go/client/challenges.go @@ -1,67 +1,42 @@ package main import ( + "github.com/hajimehoshi/ebiten/v2" "muhq.space/muhqs-game/go/activities" "muhq.space/muhqs-game/go/game" - "muhq.space/muhqs-game/go/ui" ) +var availChallenges = map[string]func(string) *game.LocalState{ + "Missionary": game.NewMissionaryChallenge, + "Cav. Archer": game.NewCavArcherChallenge, + "Random": game.NewRandomChallenge, +} + type challenges struct { - ui.Collection + bl *activities.ButtonList app *app playerName string } -func NewChallengesMenu(app *app, playerName string) *challenges { - m := &challenges{app: app, playerName: playerName} - m.Width = app.windowWidth - m.Height = app.windowHeight - - return m -} - -var availChallenges map[string]func(string) *game.LocalState - -func init() { - availChallenges = make(map[string]func(string) *game.LocalState) - availChallenges["Missionary"] = game.NewMissionaryChallenge - availChallenges["Cav. Archer"] = game.NewCavArcherChallenge - availChallenges["Random"] = game.NewRandomChallenge -} - -func (m *challenges) build() { - i := 0 - for ch, f := range availChallenges { - - m.AddWidget(ui.NewSimpleButton( - (m.Width-START_BUTTON_WIDTH)/2, - i*START_BUTTON_HEIGHT+50+i*25, - START_BUTTON_WIDTH, - START_BUTTON_HEIGHT, - ch, - func(*ui.SimpleButton) { - s := f(m.playerName) - m.startChallenge(s) - })) - i = i + 1 +func newChallengesMenu(app *app, playerName string) *challenges { + var m *challenges + labels := []string{} + handlers := []func(){} + for k, start := range availChallenges { + labels = append(labels, k) + handlers = append(handlers, func() { + s := start(m.playerName) + m.startChallenge(s) + }) } -} - -func (m *challenges) Update() error { - if m.Widgets() == nil { - m.build() - } - - if err := ui.Update(); err != nil { - return err + m = &challenges{ + bl: activities.NewButtonList(app.windowWidth, app.windowHeight, labels, handlers), + app: app, + playerName: playerName, } - return m.Collection.Update() -} - -func (m *challenges) Layout(width, height int) (int, int) { - return m.Width, m.Height + return m } func (m *challenges) startChallenge(state game.State) { @@ -74,3 +49,7 @@ func (m *challenges) startChallenge(state game.State) { activities.PushActivity(g.Start()) } + +func (c *challenges) Draw(screen *ebiten.Image) { c.bl.Draw(screen) } +func (c *challenges) Layout(w, h int) (int, int) { return c.bl.Layout(w, h) } +func (c *challenges) Update() error { return c.bl.Update() } diff --git a/go/client/startMenu.go b/go/client/startMenu.go index ad3219bf..aaf51de4 100644 --- a/go/client/startMenu.go +++ b/go/client/startMenu.go @@ -139,7 +139,7 @@ func (m *startMenu) build() { START_BUTTON_HEIGHT, "Challenges", func(*ui.SimpleButton) { - activities.PushActivity(NewChallengesMenu(m.app, playerInput.Text())) + activities.PushActivity(newChallengesMenu(m.app, playerInput.Text())) })) } |
