diff options
Diffstat (limited to 'go/ui/mapView.go')
| -rw-r--r-- | go/ui/mapView.go | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/go/ui/mapView.go b/go/ui/mapView.go index 8bd2e341..64501706 100644 --- a/go/ui/mapView.go +++ b/go/ui/mapView.go @@ -39,9 +39,11 @@ const ( type MapView struct { hoverPermInfo + EventHandlersMap gameState game.State mapLayer *ebiten.Image permanentsLayer *ebiten.Image + scale float64 tileHighlights map[game.Position][]color.Color permanentsHighlights map[game.Permanent][]color.Color } @@ -49,6 +51,7 @@ type MapView struct { func NewMapView(g game.State) *MapView { vw := &MapView{ gameState: g, + scale: 1, tileHighlights: make(map[game.Position][]color.Color), permanentsHighlights: make(map[game.Permanent][]color.Color), } @@ -57,7 +60,7 @@ func NewMapView(g game.State) *MapView { } func (mv *MapView) Height() int { - return len(mv.gameState.Map().Tiles) * TILE_HEIGHT + return int(float64(len(mv.gameState.Map().Tiles)*TILE_HEIGHT) * mv.scale) } func (mv *MapView) Width() int { @@ -67,7 +70,7 @@ func (mv *MapView) Width() int { maxWidth = n } } - return maxWidth * TILE_WIDTH + return int(float64(maxWidth*TILE_WIDTH) * mv.scale) } func rotateTileImg(x, y int, radian float64, op *ebiten.DrawImageOptions) { @@ -238,6 +241,7 @@ func (vw *MapView) drawMapLayer(screen *ebiten.Image) { tile := vw.gameState.Map().TileAt(pos) var tileImg *ebiten.Image op := &ebiten.DrawImageOptions{} + op.GeoM.Scale(vw.scale, vw.scale) switch tile.Type { case game.TileTypes.Street: @@ -300,6 +304,7 @@ func (vw *MapView) drawPermanentsLayer(screen *ebiten.Image) { y_px := t.Position.Y*TILE_HEIGHT + (TILE_HEIGHT-PERMANENT_HEIGHT)/2 op := &ebiten.DrawImageOptions{} + op.GeoM.Scale(vw.scale, vw.scale) op.GeoM.Translate(float64(x_px), float64(y_px)) op.ColorScale.ScaleWithColor(p.Controller().Color) @@ -376,20 +381,22 @@ func isSymbolTransparentAt(p game.Permanent, relativeX, relativeY int) bool { } func (vw *MapView) FindObjectAt(screenX, screenY int) interface{} { - x := screenX / TILE_WIDTH - y := screenY / TILE_HEIGHT + scaled_tile_wdth := int(float64(TILE_WIDTH) * vw.scale) + scaled_tile_hght := int(float64(TILE_HEIGHT) * vw.scale) + x := screenX / scaled_tile_wdth + y := screenY / scaled_tile_hght if x < 0 || y < 0 { return nil } - relativeX := screenX % TILE_WIDTH - relativeY := screenY % TILE_HEIGHT - xMargin := (TILE_WIDTH - PERMANENT_WIDTH) / 2 - yMargin := (TILE_HEIGHT - PERMANENT_HEIGHT) / 2 + relativeX := screenX % scaled_tile_wdth + relativeY := screenY % scaled_tile_hght + xMargin := int(float64(TILE_WIDTH-PERMANENT_WIDTH)*vw.scale) / 2 + yMargin := int(float64(TILE_HEIGHT-PERMANENT_HEIGHT)*vw.scale) / 2 // detect if a permanent or the containing tile was selected - if relativeX >= xMargin && relativeX <= TILE_WIDTH-xMargin && - relativeY >= yMargin && relativeY <= TILE_HEIGHT-yMargin { + if relativeX >= xMargin && relativeX <= scaled_tile_wdth-xMargin && + relativeY >= yMargin && relativeY <= scaled_tile_hght-yMargin { for _, p := range vw.gameState.Permanents() { t := p.Tile() @@ -487,3 +494,12 @@ func (mv *MapView) Contains(x, y int) bool { func (*MapView) Render(Widget) *ebiten.Image { return nil } + +func (mv *MapView) Layout() (int, int) { + return mv.Width(), mv.Height() +} + +func (mv *MapView) Scale(s float64) *MapView { + mv.scale = s + return mv +} |
