ld-56/no_cre_build_signals.gd
2024-10-07 19:06:22 -04:00

46 lines
920 B
GDScript

extends Node2D
var mouse_in_window
var following
var diff = Vector2.ZERO
var last_mouse = Vector2.ZERO
func _ready() -> void:
Triggerer.listen("released", _on_released)
func _on_released(_data):
if mouse_in_window:
get_window().grab_focus()
func _notification(blah):
match blah:
NOTIFICATION_WM_MOUSE_EXIT:
mouse_in_window = false
NOTIFICATION_WM_MOUSE_ENTER:
mouse_in_window = true
if not Persister.get_value("grabbing"):
get_window().grab_focus()
func _process(delta: float) -> void:
if Input.is_action_just_pressed("right_click") and mouse_in_window:
following = true
if Input.is_action_just_released("right_click"):
following = false
var mouse = get_tree().root.get_mouse_position()
if following:
diff += (mouse - last_mouse) * 4
var x = floor(diff.x)
var y = floor(diff.y)
get_parent().position += Vector2i(x, y)
diff -= Vector2(x, y)
last_mouse = mouse