From f9ab2cfdb25eb3fcd85868a2e375326a9c8b6022 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Wed, 15 Feb 2023 13:13:06 +0100 Subject: intermediate commit * fix a lot of target and action bugs * check target selection before adding it to the prompt * use the store view for stores on the map * fix card highlighting in CardGrid * Only prompt for Upkeep-/DiscardActions if appropriate * Add helper for areaEffects granting new FullActions * Add Target() helper selecting the first target to the Action interface * Fix BuyAction and DiscardAction targets * Remember the stores a player has seen --- go/ui/cardGrid.go | 3 +++ go/ui/mapView.go | 4 ++++ go/ui/prompt.go | 8 ++++++-- go/ui/textBox.go | 19 +++++++++++++++---- 4 files changed, 28 insertions(+), 6 deletions(-) (limited to 'go/ui') diff --git a/go/ui/cardGrid.go b/go/ui/cardGrid.go index 59e25f2c..abe1d60b 100644 --- a/go/ui/cardGrid.go +++ b/go/ui/cardGrid.go @@ -98,6 +98,7 @@ func (w *CardGrid) render() *ebiten.Image { op.GeoM.Translate(xOffset, yOffset) if slices.Contains(w.highlights, card) { + log.Println("Highlighting card", card.Name) op.ColorM.Scale(1, 0, 0, 0.5) } @@ -153,6 +154,8 @@ func (w *CardGrid) FindObjectAt(_x, _y int) interface{} { func (w *CardGrid) setHighlights(cards []*game.Card) { w.highlights = cards + // Reset the grid card count to force grid to be redrawn containing the highlights + w.gridCards = 0 w.ForceRedraw() } diff --git a/go/ui/mapView.go b/go/ui/mapView.go index a6fd55c1..697eb774 100644 --- a/go/ui/mapView.go +++ b/go/ui/mapView.go @@ -266,6 +266,10 @@ func (vw *MapView) HighlightPermanents(permanents []game.Permanent) { vw.ForceRedraw() } +func (vw *MapView) AddHighlightPermanent(p game.Permanent) { + vw.HighlightPermanents(append(vw.permanentsHighlights, p)) +} + func (vw *MapView) HighlightPermanent(p game.Permanent) { vw.HighlightPermanents([]game.Permanent{p}) } diff --git a/go/ui/prompt.go b/go/ui/prompt.go index af5fca1d..b8d60a49 100644 --- a/go/ui/prompt.go +++ b/go/ui/prompt.go @@ -26,8 +26,12 @@ func NewPrompt(y, width int, action game.Action, promptText string) *Prompt { return p } -func (p *Prompt) Add(obj interface{}) { - p.action.Targets().AddSelection(obj) +func (p *Prompt) Add(obj interface{}) error { + if handCard, ok := obj.(HandCard); ok { + obj = handCard.C + } + + return p.action.Targets().AddSelection(obj) } func (p *Prompt) Confirm() game.Action { diff --git a/go/ui/textBox.go b/go/ui/textBox.go index 7f1ab98c..2635535c 100644 --- a/go/ui/textBox.go +++ b/go/ui/textBox.go @@ -153,15 +153,26 @@ func (w *PocList) setText() { w.Y = w.bottomY - b.Dy() - w.YMargin } -func (w *PocList) FindObjectAt(x, y int) interface{} { +func (w *PocList) FindObjectAt(_x, _y int) interface{} { + if !w.Contains(_x, _y) { + return nil + } + cards := w.poc.Cards() if len(cards) == 0 { return nil } - // b := text.BoundString(font.Font, w.Text) - // i := b.Dy() / w.poc.Size() - return cards[0] + y := _y - w.Y + + b := text.BoundString(font.Font24, w.text) + i := y / (b.Dy() / w.poc.Size()) + + if i >= len(cards) { + return nil + } + + return cards[i] } type TextInput struct { -- cgit v1.2.3