diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2025-08-20 14:44:06 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-08-20 15:57:42 +0200 |
| commit | a059fa9bb1ace39cf5fdcfd489a90f5d778c9344 (patch) | |
| tree | 8907fbb2246c829d85d995694c35b229761ad5b8 | |
| parent | a702781e58fc6db55aca6b61b1eb556bfca481b2 (diff) | |
| download | muhqs-game-a059fa9bb1ace39cf5fdcfd489a90f5d778c9344.tar.gz muhqs-game-a059fa9bb1ace39cf5fdcfd489a90f5d778c9344.zip | |
add game and settings menus
| -rw-r--r-- | assets/icons/menu.png | bin | 0 -> 828 bytes | |||
| -rw-r--r-- | assets/icons/menu.xcf | bin | 0 -> 5820 bytes | |||
| -rw-r--r-- | go/activities/buttonList.go | 7 | ||||
| -rw-r--r-- | go/client/challenges.go | 7 | ||||
| -rw-r--r-- | go/client/game.go | 19 | ||||
| -rw-r--r-- | go/client/gameMenu.go | 25 | ||||
| -rw-r--r-- | go/client/settings.go | 45 |
7 files changed, 93 insertions, 10 deletions
diff --git a/assets/icons/menu.png b/assets/icons/menu.png Binary files differnew file mode 100644 index 00000000..3e8482cc --- /dev/null +++ b/assets/icons/menu.png diff --git a/assets/icons/menu.xcf b/assets/icons/menu.xcf Binary files differnew file mode 100644 index 00000000..14dc2763 --- /dev/null +++ b/assets/icons/menu.xcf diff --git a/go/activities/buttonList.go b/go/activities/buttonList.go index 55e5d0de..f3ea9f23 100644 --- a/go/activities/buttonList.go +++ b/go/activities/buttonList.go @@ -14,12 +14,13 @@ type ButtonList struct { } const ( - BUTTON_LIST_BUTTON_WIDTH = 250 + // TODO: determine required with for the displayed labels + BUTTON_LIST_BUTTON_WIDTH = 450 BUTTON_LIST_BUTTON_HEIGHT = 75 BUTTON_LIST_BUTTON_PADDING = 40 ) -func NewButtonList(width, height int, labels []string, handlers []func()) *ButtonList { +func NewButtonList(width, height int, labels []string, handlers []func(*ui.SimpleButton)) *ButtonList { bl := &ButtonList{ui.Collection{Width: width, Height: height}} if len(labels) != len(handlers) { @@ -35,7 +36,7 @@ func NewButtonList(width, height int, labels []string, handlers []func()) *Butto BUTTON_LIST_BUTTON_WIDTH, BUTTON_LIST_BUTTON_HEIGHT, labels[i], - func(*ui.SimpleButton) { handler() }, + handler, ) bl.AddWidget(btn) diff --git a/go/client/challenges.go b/go/client/challenges.go index ca6e3563..6956282b 100644 --- a/go/client/challenges.go +++ b/go/client/challenges.go @@ -4,6 +4,7 @@ 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{ @@ -21,11 +22,11 @@ type challenges struct { func newChallengesMenu(app *app, playerName string) *challenges { var m *challenges - labels := []string{} - handlers := []func(){} + labels := make([]string, 0, len(availChallenges)) + handlers := make([]func(*ui.SimpleButton), 0, len(availChallenges)) for k, start := range availChallenges { labels = append(labels, k) - handlers = append(handlers, func() { + handlers = append(handlers, func(*ui.SimpleButton) { s := start(m.playerName) m.startChallenge(s) }) diff --git a/go/client/game.go b/go/client/game.go index eae065c6..f4262f67 100644 --- a/go/client/game.go +++ b/go/client/game.go @@ -34,17 +34,17 @@ const ( STATE_BAR_WIDTH = 300 POC_BUTTON_WIDTH = 150 - - AUTO_PROGRESS_PROMPT = true ) type Game struct { - app *app + app *app + settings *settings keyBindings keyBindings selectedObject any + menuButton *ui.ImageButton handLayer *ui.HandView discardBtn *ui.ImageButton stateBar *ui.StateBar @@ -77,6 +77,7 @@ type Game struct { func newGame(app *app, gameState game.State) *Game { g := &Game{ app: app, + settings: newSettings(), gameState: gameState, keyBindings: make(keyBindings), Collection: ui.Collection{ @@ -92,6 +93,16 @@ func newGame(app *app, gameState game.State) *Game { g.keyBindings[ebiten.KeyEscape] = reset g.keyBindings[ebiten.KeyQ] = func(ui.InputEvent, *Game) (bool, error) { return false, ebiten.Termination } + menuImg := ebiten.NewImageFromImage(assets.GetIcon("menu.png")) + g.menuButton = ui.NewImageButton( + g.Width-menuImg.Bounds().Dx()-10, + 10, + menuImg, + func(*ui.ImageButton) { + activities.PushActivity(newGameMenu(g)) + }) + g.AddWidget(g.menuButton) + g.passButton = ui.NewSimpleButton(g.Width-PASS_BUTTON_WIDTH, g.Height-DEFAULT_BUTTON_HEIGHT, PASS_BUTTON_WIDTH, @@ -504,7 +515,7 @@ func (g *Game) updateButtons() { passButtonLabel = "confirm" } - if AUTO_PROGRESS_PROMPT && !targets.Cur().AllowSelection() { + if g.settings.gameplay["autoProgressPrompt"].(bool) && !targets.Cur().AllowSelection() { g.progressPrompt() return } diff --git a/go/client/gameMenu.go b/go/client/gameMenu.go new file mode 100644 index 00000000..82287f38 --- /dev/null +++ b/go/client/gameMenu.go @@ -0,0 +1,25 @@ +package main + +import ( + "muhq.space/muhqs-game/go/activities" + "muhq.space/muhqs-game/go/ui" +) + +func newGameMenu(g *Game) *activities.ButtonList { + var bl *activities.ButtonList + labels := []string{ + "wincondition", + "settings", + } + handlers := []func(*ui.SimpleButton){ + func(*ui.SimpleButton) { + g.showMessage(g.gameState.Map().WinCondition.String()) + activities.PopActivity() + }, + func(*ui.SimpleButton) { + activities.PushActivity(newSettingsMenu(g)) + }, + } + bl = activities.NewButtonList(g.Width, g.Height, labels, handlers) + return bl +} diff --git a/go/client/settings.go b/go/client/settings.go new file mode 100644 index 00000000..02f23211 --- /dev/null +++ b/go/client/settings.go @@ -0,0 +1,45 @@ +package main + +import ( + "fmt" + "log" + + "muhq.space/muhqs-game/go/activities" + "muhq.space/muhqs-game/go/ui" +) + +type settings struct { + gameplay map[string]any +} + +func newSettings() *settings { + return &settings{ + gameplay: map[string]any{ + "autoProgressPrompt": true, + }, + } +} + +func newSettingsMenu(g *Game) *activities.ButtonList { + var bl *activities.ButtonList + s := g.settings + labels := make([]string, 0, len(s.gameplay)) + handlers := make([]func(*ui.SimpleButton), 0, len(s.gameplay)) + + for k, v := range s.gameplay { + name := "gameplay." + k + labels = append(labels, fmt.Sprintf("%s: %v", name, v)) + handlers = append(handlers, func(btn *ui.SimpleButton) { + switch typedVal := v.(type) { + case bool: + s.gameplay[k] = !typedVal + default: + log.Panicf("Unhandled settings %s type %T", name, typedVal) + } + btn.UpdateLabel(fmt.Sprintf("%s: %v", name, s.gameplay[k])) + }) + } + + bl = activities.NewButtonList(g.Width, g.Height, labels, handlers) + return bl +} |
