summaryrefslogtreecommitdiff
path: root/UI/Camera.gd
diff options
context:
space:
mode:
Diffstat (limited to 'UI/Camera.gd')
-rw-r--r--UI/Camera.gd47
1 files changed, 44 insertions, 3 deletions
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")