From 0f78406cde7890f3f9b16cd0ba55afac4c9065cf Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Wed, 25 Jun 2025 17:10:24 -0500 Subject: improve prompt cancellation The cancel button was overlaying the submit button preventing the submission of a prompt. Distinguish between cancelable and mandatory prompt. Only^ allow cancelable prompts to be removed. Fixes: 37acd982 --- go/client/game.go | 32 +++++++++++++++++++++++--------- go/client/keybindings.go | 4 +++- 2 files changed, 26 insertions(+), 10 deletions(-) (limited to 'go/client') diff --git a/go/client/game.go b/go/client/game.go index 62e1d79c..0870450e 100644 --- a/go/client/game.go +++ b/go/client/game.go @@ -93,13 +93,13 @@ func newGame(app *app, gameState game.State) *Game { } }) - g.resetButton = ui.NewSimpleButton(g.Width-PASS_BUTTON_WIDTH, - g.Height-DEFAULT_BUTTON_HEIGHT, - PASS_BUTTON_WIDTH, + g.resetButton = ui.NewRoundSimpleButton( + 10, + g.Height/2+DEFAULT_BUTTON_HEIGHT/2, DEFAULT_BUTTON_HEIGHT, - "cancel", + "X", func(*ui.SimpleButton) { - reset(g) + g.reset() }) g.stackBuffer = ui.NewBuffer(g.Width-STACK_BUFFER_WIDTH, g.passButton.Y-400, @@ -236,7 +236,7 @@ func (g *Game) addPermActionChoice(perm game.Permanent, x, y int) { func (g *Game) declareOrPromptTargets(a game.Action) { if a.Targets() != nil && a.Targets().RequireSelection() { - g.addPrompt(a, fmt.Sprintf("Select targets for %v", a)) + g.addCancelablePrompt(a, fmt.Sprintf("Select targets for %v", a)) } else { g.declareAction(a) } @@ -299,13 +299,27 @@ func (g *Game) removeChoice() { g.choice = nil } +func (g *Game) addCancelablePrompt(action game.Action, prompt string) { + g._addPrompt(action, prompt, true) +} + func (g *Game) addPrompt(action game.Action, prompt string) { + g._addPrompt(action, prompt, false) +} + +func (g *Game) _addPrompt(action game.Action, prompt string, cancelable bool) { if g.prompt != nil { g.removePrompt() } - g.prompt = ui.NewPrompt(g.Height/2, g.Width, action, prompt) + if cancelable { + g.prompt = ui.NewCancelablePrompt(g.Height/2, g.Width, action, prompt) + } else { + g.prompt = ui.NewPrompt(g.Height/2, g.Width, action, prompt) + } g.AddWidget(g.prompt) - g.AddWidget(g.resetButton) + if cancelable { + g.show(g.resetButton) + } g.updateHighlight() } @@ -486,7 +500,7 @@ func (g *Game) findObjectAt(x, y int) interface{} { func (g *Game) progressPlayAction(a *game.PlayAction) { targets := a.Targets() if targets != nil && targets.AllowSelection() { - g.addPrompt(a, fmt.Sprintf("Select targets to play %v", a.Card.Name)) + g.addCancelablePrompt(a, fmt.Sprintf("Select targets to play %v", a.Card.Name)) g.handLayer.HighlightCard(a.Card, ui.HighlightSelectionColor) } else { g.declareAction(a) diff --git a/go/client/keybindings.go b/go/client/keybindings.go index 2bfc52c7..ebc66c22 100644 --- a/go/client/keybindings.go +++ b/go/client/keybindings.go @@ -67,7 +67,9 @@ func selection(g *Game, x, y int) bool { if g.prompt != nil { if err := g.prompt.Add(obj); err != nil { log.Println("Not added", obj, "to active prompt:", err) - g.handleSelection(obj, x, y) + if g.prompt.Cancelable() { + g.handleSelection(obj, x, y) + } } else { g.updateHighlight() } -- cgit v1.2.3