aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2025-06-25 17:10:24 -0500
committerFlorian Fischer <florian.fischer@muhq.space>2025-07-03 22:01:22 -0400
commit31f98408521a893099c180e3c971ce8c122b5c36 (patch)
tree70084bee1643699275aa88480392d05d38e8cadc
parent7db18a534591360e8ca2b38ad87752fdd56f33be (diff)
downloadmuhqs-game-31f98408521a893099c180e3c971ce8c122b5c36.tar.gz
muhqs-game-31f98408521a893099c180e3c971ce8c122b5c36.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.go32
-rw-r--r--go/client/keybindings.go4
-rw-r--r--go/ui/prompt.go10
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