diff --git a/scenes/tilemap/tilemap.gd b/scenes/tilemap/tilemap.gd index 5884b2f..9af9005 100644 --- a/scenes/tilemap/tilemap.gd +++ b/scenes/tilemap/tilemap.gd @@ -78,7 +78,6 @@ var image: = Image.new() var image_load_proc: Callable var now: = 0 var visible_marks_count: = 0 -var mouse_wheel_count: = 0 var map_server_available: = false @@ -200,10 +199,10 @@ func _input(e) -> void: if e is InputEventMouseButton: if e.pressed: if e.button_index == MOUSE_BUTTON_WHEEL_DOWN: - mouse_wheel_count -= 1 + increment_zoom(-zoom_step, lmp) queue_redraw() elif e.button_index == MOUSE_BUTTON_WHEEL_UP: - mouse_wheel_count += 1 + increment_zoom( zoom_step, lmp) queue_redraw() if e.button_index == MOUSE_BUTTON_LEFT: @@ -236,10 +235,15 @@ func multiply_zoom(multiplier: float, pivot: Vector2) -> void: _xyz.y -= p2.y - p1.y -func set_zoom(zoom: float, pivot=null) -> void: - if pivot == null: - pivot = $canvas.size / 2.0 +func increment_zoom(increment: float, pivot: Vector2) -> void: + var p1: = screen_to_world(_xyz, pivot.x, pivot.y) + _xyz.z = clampf(_xyz.z + increment, min_zoom_level, max_zoom_level) + var p2: = screen_to_world(_xyz, pivot.x, pivot.y) + _xyz.x -= p2.x - p1.x + _xyz.y -= p2.y - p1.y + +func set_zoom(zoom: float, pivot: Vector2) -> void: var p1: = screen_to_world(_xyz, pivot.x, pivot.y) _xyz.z = clampf(zoom, max_zoom_level, min_zoom_level) var p2: = screen_to_world(_xyz, pivot.x, pivot.y) @@ -248,15 +252,6 @@ func set_zoom(zoom: float, pivot=null) -> void: func _draw() -> void: - - var lmp = get_local_mouse_position() - if mouse_wheel_count > 0: - multiply_zoom(1.0 + zoom_step, lmp) - mouse_wheel_count -= 1 - elif mouse_wheel_count < 0: - multiply_zoom(1.0 - zoom_step, lmp) - mouse_wheel_count += 1 - var z = min(max_zoom_level, _xyz.z) var t1 = screen_to_tile(0, 0, z) var t2 = screen_to_tile($canvas.size.x, $canvas.size.y, z) @@ -528,7 +523,7 @@ func xyz_to_idx(x: float, y: float, z: float) -> int: return int(i + (y * n + x)) -func get_tile(x: int, y: int, z: int, create: bool = true) -> Tile: +func get_tile(x: int, y: int, z: int) -> Tile: var n = pow(2, z) if x >= 0: @@ -560,7 +555,7 @@ func get_tile(x: int, y: int, z: int, create: bool = true) -> Tile: return tile var queue_size: = _queue.size() - if create and (not $canvas/player.is_playing()): + if not $canvas/player.is_playing(): if not tile: tile = Tile.new(idx, x, y, z) tile.url = base_url.replace('{x}', str(x)).replace('{y}', str(y)).replace('{z}', str(z)) diff --git a/scenes/tilemap/tilemap.tscn b/scenes/tilemap/tilemap.tscn index aa619a9..c00214d 100644 --- a/scenes/tilemap/tilemap.tscn +++ b/scenes/tilemap/tilemap.tscn @@ -31,7 +31,6 @@ script = ExtResource("1_l64tp") base_url = "http://192.168.11.105:8001/osm_tiles/{z}/{x}/{y}.png" max_zoom_level = 15 max_zoom_level_server = 10 -az = 2.0 [node name="canvas" type="TextureRect" parent="." groups=["gui_items"]] clip_contents = true