aboutsummaryrefslogtreecommitdiff
path: root/go/ui/mapView.go
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2023-01-26 22:16:10 +0100
committerFlorian Fischer <florian.fischer@muhq.space>2025-01-27 16:43:44 +0100
commit926ca5cdd20a39e3e05aaa3486cb166718dab5ca (patch)
tree3d7bc8a0e1e0be1ce8d92d5503bdede878e718e9 /go/ui/mapView.go
parent8720ebf9c74d9e11001772b5c00c293fa3a8b9e5 (diff)
downloadmuhqs-game-926ca5cdd20a39e3e05aaa3486cb166718dab5ca.tar.gz
muhqs-game-926ca5cdd20a39e3e05aaa3486cb166718dab5ca.zip
intermeditae commit
Diffstat (limited to 'go/ui/mapView.go')
-rw-r--r--go/ui/mapView.go57
1 files changed, 40 insertions, 17 deletions
diff --git a/go/ui/mapView.go b/go/ui/mapView.go
index 6c887920..c966f1a8 100644
--- a/go/ui/mapView.go
+++ b/go/ui/mapView.go
@@ -132,20 +132,25 @@ func (vw *MapView) drawMapLayer(screen *ebiten.Image) {
screen.DrawImage(vw.mapLayer, &ebiten.DrawImageOptions{})
}
+func getPermanentSymbol(p game.Permanent, i int) *ebiten.Image {
+ permanentSymbol := assets.GetSymbol(strings.ToLower(p.GetCard().Name))
+ if permanentSymbol == nil {
+ symbol := fmt.Sprintf("%c%d", unicode.ToUpper(rune(p.GetCard().Type.String()[0])), i)
+ permanentSymbol = assets.GetGenericSymbol(symbol)
+ if permanentSymbol == nil {
+ log.Fatalf("Failed to generate generic symbol %s", symbol)
+ }
+ }
+
+ return permanentSymbol
+}
+
func (vw *MapView) drawPermanentsLayer(screen *ebiten.Image) {
if vw.permanentsLayer == nil {
vw.permanentsLayer = vw.newLayerImage()
for i, p := range vw.gameState.Permanents {
- permanentSymbol := assets.GetSymbol(strings.ToLower(p.GetCard().Name))
- if permanentSymbol == nil {
- symbol := fmt.Sprintf("%c%d", unicode.ToUpper(rune(p.GetCard().Type.String()[0])), i)
- permanentSymbol = assets.GetGenericSymbol(symbol)
- if permanentSymbol == nil {
- log.Fatalf("Failed to generate generic symbol %s", symbol)
- }
- }
-
+ permanentSymbol := getPermanentSymbol(p, i)
t := p.GetTile()
x_px := t.Position.X*TILE_WIDTH + (TILE_WIDTH-PERMANENT_WIDTH)/2
y_px := t.Position.Y*TILE_HEIGHT + (TILE_HEIGHT-PERMANENT_HEIGHT)/2
@@ -178,19 +183,37 @@ func (vw *MapView) ForceRedraw() {
vw.permanentsLayer = nil
}
-func (vw *MapView) FindObjectAt(x_px, y_px int) interface{} {
- x := x_px / TILE_WIDTH
- y := y_px / TILE_HEIGHT
+func isSymbolTransparentAt(p game.Permanent, relativeX, relativeY int) bool {
+ permanentSymbol := getPermanentSymbol(p, 0)
+ _, _, _, alpha := permanentSymbol.At(relativeX, relativeY).RGBA()
+ return alpha == 0
+}
+
+func (vw *MapView) FindObjectAt(screenX, screenY int) interface{} {
+ x := screenX / TILE_WIDTH
+ y := screenY / TILE_HEIGHT
if x < 0 || y < 0 {
return nil
}
- // TODO: detect if a permanent or the containing tile was selected
- for _, u := range vw.gameState.Permanents {
- pos := u.GetTile().Position
- if pos.X == x && pos.Y == y {
- return u
+ relativeX := screenX % TILE_WIDTH
+ relativeY := screenY % TILE_HEIGHT
+ xMargin := (TILE_WIDTH - PERMANENT_WIDTH) / 2
+ yMargin := (TILE_HEIGHT - PERMANENT_HEIGHT) / 2
+ // detect if a permanent or the containing tile was selected
+ if relativeX >= xMargin && relativeX <= TILE_WIDTH-xMargin &&
+ relativeY >= yMargin && relativeY <= TILE_HEIGHT-yMargin {
+
+ for _, p := range vw.gameState.Permanents {
+ pos := p.GetTile().Position
+ if pos.X == x && pos.Y == y {
+ if isSymbolTransparentAt(p, relativeX, relativeY) {
+ break
+ }
+
+ return p
+ }
}
}