aboutsummaryrefslogtreecommitdiff
path: root/go/ui/mapView.go
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2023-02-16 18:57:15 +0100
committerFlorian Fischer <florian.fischer@muhq.space>2025-01-27 16:43:50 +0100
commitc12057320c06f9b4a0bd6c9b25a1dd2d2bd8fd8d (patch)
tree77e2d4f4b1430b95fd20dc14a8c2c561a80d6bc8 /go/ui/mapView.go
parent2f01274717d62e59e4bf3b4426a2ec6a76ffac11 (diff)
downloadmuhqs-game-c12057320c06f9b4a0bd6c9b25a1dd2d2bd8fd8d.tar.gz
muhqs-game-c12057320c06f9b4a0bd6c9b25a1dd2d2bd8fd8d.zip
move more ui logic into Collection
* Generalize hover detection and move it into ui.Collection * Implement transparencu for the prompt banner
Diffstat (limited to 'go/ui/mapView.go')
-rw-r--r--go/ui/mapView.go22
1 files changed, 20 insertions, 2 deletions
diff --git a/go/ui/mapView.go b/go/ui/mapView.go
index 155750b4..0553b348 100644
--- a/go/ui/mapView.go
+++ b/go/ui/mapView.go
@@ -23,6 +23,7 @@ const (
)
type MapView struct {
+ hoverPermInfo
gameState *game.State
mapLayer *ebiten.Image
permanentsLayer *ebiten.Image
@@ -31,14 +32,25 @@ type MapView struct {
}
func NewMapView(g *game.State) *MapView {
- vw := MapView{g, nil, nil, []game.Position{}, []game.Permanent{}}
- return &vw
+ vw := &MapView{gameState: g}
+ vw.hoverPermInfo.init(vw)
+ return vw
}
func (mv *MapView) Height() int {
return len(mv.gameState.Map.Tiles) * TILE_HEIGHT
}
+func (mv *MapView) Width() int {
+ maxWidth := 0
+ for _, row := range mv.gameState.Map.Tiles {
+ if n := len(row); n > maxWidth {
+ maxWidth = n
+ }
+ }
+ return maxWidth * TILE_WIDTH
+}
+
func rotateStreetImg(x, y int, radian float64, op *ebiten.DrawImageOptions) {
// Move the image's center to the screen's upper-left corner.
// This is a preparation for rotating. When geometry matrices are applied,
@@ -278,6 +290,12 @@ func (vw *MapView) ClearPermanentsHighlights() {
vw.HighlightPermanents([]game.Permanent{})
}
+func (mv *MapView) Contains(x, y int) bool {
+ w := mv.Width()
+ h := mv.Height()
+ return x >= 0 && y >= 0 && x <= w && y <= h
+}
+
func (*MapView) Render(Widget) *ebiten.Image {
return nil
}