From a495681453c97578cc4a408d6919c6879524a603 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Thu, 24 Oct 2024 18:31:08 +0200 Subject: next commit --- UI/Camera.gd | 47 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) (limited to 'UI/Camera.gd') diff --git a/UI/Camera.gd b/UI/Camera.gd index 926ab36..3009ed2 100644 --- a/UI/Camera.gd +++ b/UI/Camera.gd @@ -4,10 +4,14 @@ extends Camera2D signal zoomed(zoom: Vector2) -var is_in_drag_mode = false -var drag_anchor = Vector2.ZERO +var is_in_drag_mode := false +var drag_anchor := Vector2.ZERO -@export var speed = 25 +var is_in_edge_mode := false +var edge := Vector2.ZERO +@export var edge_scroll_margin := 4.0 + +@export var speed := 25 @export_group("Zoom", "zoom") @export var zoom_min: float = 0.5 @@ -28,6 +32,8 @@ func _ready(): ) zoomed.emit(zoom) ) + + Input.mouse_mode = Input.MOUSE_MODE_CONFINED func _input(event): @@ -45,17 +51,52 @@ func _input(event): zoom = Vector2(new_zoom, new_zoom) zoomed.emit(zoom) + if event.is_action_pressed("camera_drag"): is_in_drag_mode = true drag_anchor = get_global_mouse_position() + Input.set_default_cursor_shape(Input.CURSOR_MOVE) elif event.is_action_released("camera_drag"): is_in_drag_mode = false + Input.set_default_cursor_shape(Input.CURSOR_ARROW) + + + if event is InputEventMouseMotion: + is_in_edge_mode = false + edge = Vector2.ZERO + if get_global_mouse_position().x - edge_scroll_margin <= get_rect().position.x: + is_in_edge_mode = true + edge += Vector2.LEFT + if get_global_mouse_position().y - edge_scroll_margin <= get_rect().position.y: + is_in_edge_mode = true + edge += Vector2.UP + if get_global_mouse_position().x + edge_scroll_margin >= get_rect().end.x: + is_in_edge_mode = true + edge += Vector2.RIGHT + if get_global_mouse_position().y + edge_scroll_margin >= get_rect().end.y: + is_in_edge_mode = true + edge += Vector2.DOWN + edge = edge.normalized() + + if event is InputEventMouseButton and event.is_pressed(): + Input.mouse_mode = Input.MOUSE_MODE_CONFINED + elif event.is_action_pressed("mouse_escape"): + Input.mouse_mode = Input.MOUSE_MODE_VISIBLE func _process(delta): if is_in_drag_mode: set_new_position(global_position + drag_anchor - get_global_mouse_position()) + if is_in_edge_mode: + set_new_position( + lerp( + global_position, + global_position + (edge * speed), + speed * delta + ) + ) + var direction_h = Input.get_axis("ui_left", "ui_right") var direction_v = Input.get_axis("ui_up", "ui_down") -- cgit v1.2.3