diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2023-02-08 17:50:10 +0100 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-08-20 15:50:10 +0200 |
| commit | 45df9bf319d38db916ca983b8c92bb912f5ce9ee (patch) | |
| tree | d7966002dad4a20bc3ef385bd152554fe278a6df /go/ui | |
| parent | eb10f6f4940ecd09fd7d881fe5e1735ff146f919 (diff) | |
| download | muhqs-game-45df9bf319d38db916ca983b8c92bb912f5ce9ee.tar.gz muhqs-game-45df9bf319d38db916ca983b8c92bb912f5ce9ee.zip | |
intermediate commit
Diffstat (limited to 'go/ui')
| -rw-r--r-- | go/ui/cardGrid.go | 3 | ||||
| -rw-r--r-- | go/ui/mapView.go | 4 | ||||
| -rw-r--r-- | go/ui/prompt.go | 38 | ||||
| -rw-r--r-- | go/ui/textBox.go | 21 |
4 files changed, 31 insertions, 35 deletions
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 1d552564..b8d60a49 100644 --- a/go/ui/prompt.go +++ b/go/ui/prompt.go @@ -1,63 +1,41 @@ package ui import ( - "log" - "github.com/hajimehoshi/ebiten/v2" "muhq.space/muhqs-game/go/game" ) -type promptType int - const ( - handCard promptType = iota - PROMPT_HEIGHT int = 50 ) type Prompt struct { - promptType promptType y, width int - sel []interface{} + action game.Action components []Widget } -func NewHandCardPrompt(y, width int, promptText string) *Prompt { +func NewPrompt(y, width int, action game.Action, promptText string) *Prompt { p := &Prompt{ y: y, width: width, - promptType: handCard, + action: action, components: []Widget{NewFixedTextBox(0, y, width, PROMPT_HEIGHT, promptText).Centering(true)}, } return p } -func (p *Prompt) Add(obj interface{}) { - var ok bool - switch p.promptType { - case handCard: - _, ok = obj.(HandCard) +func (p *Prompt) Add(obj interface{}) error { + if handCard, ok := obj.(HandCard); ok { + obj = handCard.C } - if !ok { - log.Fatalf("Invalid type %T for prompt %d", obj, p.promptType) - } - - p.sel = append(p.sel, obj) + return p.action.Targets().AddSelection(obj) } func (p *Prompt) Confirm() game.Action { - switch p.promptType { - case handCard: - cards := make([]*game.Card, 0, len(p.sel)) - for _, c := range p.sel { - cards = append(cards, c.(HandCard).C) - } - return game.NewHandCardSelection(cards) - } - - return nil + return p.action } func (p *Prompt) Height() int { diff --git a/go/ui/textBox.go b/go/ui/textBox.go index cc813a4e..2635535c 100644 --- a/go/ui/textBox.go +++ b/go/ui/textBox.go @@ -64,7 +64,7 @@ func (tb *TextBox) Centering(centering bool) *TextBox { func NewUnitInfo(x, y int, u *game.Unit) *TextBox { info := fmt.Sprintf("%s\nDamage: %d\nHealth: %d\nUpkeep: %d", - u.String(), u.Damage(), u.Health, u.Upkeep) + u.String(), u.Damage(), u.Health, u.UpkeepCost()) if u.Movement != game.INVALID_MOVEMENT() { info = fmt.Sprintf("%s\nMovement: %s", info, u.Movement.String()) @@ -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 { |
