aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2025-08-07 18:01:30 +0200
committerFlorian Fischer <florian.fischer@muhq.space>2025-08-07 18:01:30 +0200
commit8f09f910ef50efa56e0c08701c5a31ac5b489160 (patch)
tree455344ccbfa1fb4290da3225ae2ca948370f3477
parent585278b74f5add91016ea8ffef20c80e20a8e372 (diff)
downloadmuhqs-game-8f09f910ef50efa56e0c08701c5a31ac5b489160.tar.gz
muhqs-game-8f09f910ef50efa56e0c08701c5a31ac5b489160.zip
highlight reachable tiles in hover info
-rw-r--r--go/ui/hoverable.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/go/ui/hoverable.go b/go/ui/hoverable.go
index c70340bb..75c04fe8 100644
--- a/go/ui/hoverable.go
+++ b/go/ui/hoverable.go
@@ -1,6 +1,7 @@
package ui
import (
+ "golang.org/x/exp/slices"
"muhq.space/muhqs-game/go/game"
)
@@ -31,7 +32,11 @@ func (h *hoverWidget) showHint(x, y int) {
}
h.c.AddWidget(hint)
+ oldReset := h.reset
h.reset = func() {
+ if oldReset != nil {
+ oldReset()
+ }
h.c.RemoveWidget(hint)
}
}
@@ -97,6 +102,27 @@ func (h *hoverPermInfo) init(mv *MapView, c *Collection) {
return nil
}
+ if unit, ok := obj.(*game.Unit); ok {
+ reachableRange := unit.Attack.MaxRange() + unit.Movement.Range
+ movable := unit.MoveRangeTiles()
+ for _, t := range movable {
+ mv.AddHighlightTile(t, HighlightMovementColor)
+ }
+
+ // TODO: only show actually reachable tiles
+ attackable := game.TilesInRange(mv.gameState.Map(), perm, reachableRange)
+ for _, t := range attackable {
+ if slices.Contains(movable, t) {
+ continue
+ }
+ mv.AddHighlightTile(t, HighlightAttackColor)
+ }
+
+ h.reset = func() {
+ mv.ClearTileHighlights()
+ }
+ }
+
hint := NewPermInfo(x+TILE_WIDTH, y, perm)
wx, wy := x, y