aboutsummaryrefslogtreecommitdiff
path: root/go/ui/textBox.go
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2023-02-08 17:50:10 +0100
committerFlorian Fischer <florian.fischer@muhq.space>2025-08-20 15:50:10 +0200
commit45df9bf319d38db916ca983b8c92bb912f5ce9ee (patch)
treed7966002dad4a20bc3ef385bd152554fe278a6df /go/ui/textBox.go
parenteb10f6f4940ecd09fd7d881fe5e1735ff146f919 (diff)
downloadmuhqs-game-45df9bf319d38db916ca983b8c92bb912f5ce9ee.tar.gz
muhqs-game-45df9bf319d38db916ca983b8c92bb912f5ce9ee.zip
intermediate commit
Diffstat (limited to 'go/ui/textBox.go')
-rw-r--r--go/ui/textBox.go21
1 files changed, 16 insertions, 5 deletions
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 {