Доработка. Добавить индикацию перемещения карты к краю.

This commit is contained in:
sasha80
2025-06-03 13:58:44 +03:00
parent 0dc8e69785
commit e4814472d9
3 changed files with 29 additions and 9 deletions

View File

@@ -13,7 +13,7 @@ class_name MercatorTileMap
_clean_all()
queue_redraw()
@export var zoom_step: float = 0.025
@export var zoom_step: float = 0.1
@export var tile_width: float = 256.0
@export var tile_height: float = 256.0
@export_range(1, 1000, 1) var max_concurrent_requests:int = 5
@@ -79,7 +79,7 @@ var image_load_proc: Callable
var now: = 0
var visible_marks_count: = 0
var map_server_available: = false
var border: ImageTexture
## Вызывается после того, как загрузка плиток завершена
signal load_completed()
@@ -111,6 +111,13 @@ func get_marks_count(): return _marks.size()
func _ready() -> void:
var img: = Image.create($canvas.size.x, $canvas.size.y / 10, false, Image.FORMAT_RGBA8)
var sz = img.get_size()
for x in sz.x:
for y in sz.y:
img.set_pixel(x, y, Color.CORAL)
border = ImageTexture.create_from_image(img)
_xyz.z = min_zoom_level
image_type = 'png'
$canvas.connect('mouse_entered', func(): _rollover = true)
@@ -190,6 +197,7 @@ func is_mark_visible(dot) -> bool:
func _input(e) -> void:
var lmp = get_local_mouse_position()
if not _rollover:
_dragging = false
return
if e is InputEventMouseButton:
if e.pressed:
@@ -250,6 +258,7 @@ func set_zoom(zoom: float, pivot: Vector2) -> void:
func _draw() -> void:
# Рисование плиток
var z = min(max_zoom_level, _xyz.z)
var t1 = screen_to_tile(Vector2(0, 0), z)
var t2 = screen_to_tile($canvas.size, z) + Vector2(1, 1)
@@ -258,6 +267,7 @@ func _draw() -> void:
for tx in range(t1.x, t2.x):
for ty in range(t1.y, t2.y):
_draw_tile(tx, ty, z)
# Рисование отметок
var n = pow(2, z)
var dx = n * tile_width
var c: Vector2 = $canvas.size / 2.0
@@ -269,6 +279,14 @@ func _draw() -> void:
dot.mark.position = scr_pos
dot.mark.visible = c.distance_to(scr_pos) < (r - dot.gap_size)
visible_marks_count += int(dot.mark.visible)
# Рисование границ
var p1 = $canvas.position
var p2 = $canvas.size / Vector2(1, 20)
if is_out_border1 and _dragging:
draw_texture_rect(border, Rect2(p1, p2), false, Color.WHITE, false)
p1.y = p1.y + $canvas.size.y - p2.y
if is_out_border2 and _dragging:
draw_texture_rect(border, Rect2(p1, p2), false, Color.WHITE, false)
func _clean_all() -> void:
@@ -398,18 +416,18 @@ func check_borders(p1, p2, h):
func _draw_tile(tx: int, ty: int, z: float) -> void:
var tz = floor(z)
var p1 = tile_to_screen(tx, ty, z)
var p2 = tile_to_screen(tx + 1, ty + 1, z)
var tile = get_tile(tx, ty, tz)
var tz: float = floor(z)
var p1: = tile_to_screen(tx, ty, z)
var p2: = tile_to_screen(tx + 1, ty + 1, z)
var tile: = get_tile(tx, ty, tz)
if tile:
if tile.texture:
check_borders(p1, p2, $canvas.size.y)
draw_texture_rect(tile.texture, Rect2(p1, p2 - p1), false, Color.WHITE, false)
else:
var zzz = tz
var txx = tx
var tyy = ty
var zzz: float = tz
var txx: = tx
var tyy: = ty
while zzz > 1:
zzz -= 1
txx = floor(txx / 2.0)

View File

@@ -28,6 +28,7 @@ size = Vector2(400, 400)
[node name="tilemap" type="CanvasGroup" groups=["gui_items"]]
script = ExtResource("1_l64tp")
border_scene = "uid://bumg0moa26skt"
zoom_step = 0.1
[node name="canvas" type="TextureRect" parent="." groups=["gui_items"]]

View File

@@ -86,6 +86,7 @@ self_modulate = Color(1, 1, 1, 0.415686)
position = Vector2(360, 360)
min_zoom_level = 3
max_zoom_level_server = 11
az = 3.0
[node name="player" type="AnimationPlayer" parent="tilemap"]
libraries = {