feat: windows moving
This commit is contained in:
parent
f32dd932f6
commit
a0a746008e
4 changed files with 44 additions and 1 deletions
|
@ -30,5 +30,10 @@ func move_window_to_bottom_right():
|
|||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("ui_accept"):
|
||||
var dragon = _instantiator.instantiate()
|
||||
var dragon: Dragon = _instantiator.instantiate()
|
||||
dragon.place_back.connect(_dragon_place_back)
|
||||
add_child(dragon)
|
||||
|
||||
|
||||
func _dragon_place_back(dragon: Dragon):
|
||||
print(dragon)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
extends Control
|
||||
class_name Draggable
|
||||
|
||||
|
||||
var dragging: bool = false
|
||||
|
@ -41,4 +42,5 @@ func _is_inside_main_window() -> bool:
|
|||
|
||||
|
||||
func _destroy_dragon() -> void:
|
||||
dragon.on_place_back()
|
||||
dragon.queue_free()
|
||||
|
|
|
@ -1,5 +1,40 @@
|
|||
extends Window
|
||||
class_name Dragon
|
||||
|
||||
@export var dragon_speed: float = 20.0
|
||||
|
||||
@onready var _actual_position: Vector2 = position
|
||||
var main_window_rect: Rect2i
|
||||
@onready var draggable: Draggable = $DragDropDetector
|
||||
|
||||
var _walking: bool = false
|
||||
var _target_pos: Vector2
|
||||
|
||||
signal place_back(dragon: Dragon)
|
||||
|
||||
|
||||
func on_place_back() -> void:
|
||||
place_back.emit(self)
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if draggable.dragging:
|
||||
_actual_position = position
|
||||
return
|
||||
|
||||
if not _walking:
|
||||
_pick_random_screen_position()
|
||||
|
||||
_move_to_target(delta)
|
||||
|
||||
|
||||
func _move_to_target(delta: float):
|
||||
if _actual_position.distance_to(_target_pos) > 10.0:
|
||||
var direction: Vector2 = (_target_pos - _actual_position).normalized()
|
||||
_actual_position += dragon_speed * direction * delta
|
||||
position = _actual_position
|
||||
|
||||
|
||||
func _pick_random_screen_position() -> void:
|
||||
_walking = true
|
||||
_target_pos = Vector2i(10, 10)
|
||||
|
|
|
@ -13,6 +13,7 @@ unresizable = true
|
|||
borderless = true
|
||||
transparent = true
|
||||
script = ExtResource("1_ctdir")
|
||||
dragon_speed = 100.0
|
||||
|
||||
[node name="DragDropDetector" type="Control" parent="."]
|
||||
layout_mode = 3
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue