diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2025-06-25 17:10:24 -0500 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-08-20 15:57:21 +0200 |
| commit | 0f78406cde7890f3f9b16cd0ba55afac4c9065cf (patch) | |
| tree | 9d8cb7243f67660369fa2a80535c9172c3447726 | |
| parent | 9a4b12e6d388bb14a3c1b6343197f63a362709f4 (diff) | |
| download | muhqs-game-0f78406cde7890f3f9b16cd0ba55afac4c9065cf.tar.gz muhqs-game-0f78406cde7890f3f9b16cd0ba55afac4c9065cf.zip | |
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
| -rw-r--r-- | go/client/game.go | 32 | ||||
| -rw-r--r-- | go/client/keybindings.go | 4 | ||||
| -rw-r--r-- | go/ui/prompt.go | 10 |
3 files changed, 34 insertions, 12 deletions
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() } diff --git a/go/ui/prompt.go b/go/ui/prompt.go index a7f2ce07..a289ae13 100644 --- a/go/ui/prompt.go +++ b/go/ui/prompt.go @@ -17,6 +17,7 @@ type Prompt struct { y, width int action game.Action components []Widget + cancelable bool } func NewPrompt(y, width int, action game.Action, promptText string) *Prompt { @@ -30,10 +31,15 @@ func NewPrompt(y, width int, action game.Action, promptText string) *Prompt { return p } -func (p *Prompt) Action() game.Action { - return p.action +func NewCancelablePrompt(y, width int, action game.Action, promptText string) *Prompt { + p := NewPrompt(y, width, action, promptText) + p.cancelable = true + return p } +func (p *Prompt) Cancelable() bool { return p.cancelable } +func (p *Prompt) Action() game.Action { return p.action } + func (p *Prompt) Add(obj interface{}) error { if handCard, ok := obj.(HandCard); ok { obj = handCard.C |
