chore: reorganize project structure
This commit is contained in:
parent
8983b84731
commit
8e0bcc51a3
14 changed files with 14 additions and 14 deletions
9
scenes/dragons/dragon.tscn
Normal file
9
scenes/dragons/dragon.tscn
Normal file
|
@ -0,0 +1,9 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://baa8gpicw2yg0"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://fdqnc2qrrvn1" path="res://assets/sprites/icon.svg" id="1_ixu8j"]
|
||||
|
||||
[node name="Dragon" type="Node2D"]
|
||||
|
||||
[node name="Sprite" type="Sprite2D" parent="."]
|
||||
position = Vector2(0, 1)
|
||||
texture = ExtResource("1_ixu8j")
|
33
scenes/main.gd
Normal file
33
scenes/main.gd
Normal file
|
@ -0,0 +1,33 @@
|
|||
extends Node
|
||||
|
||||
|
||||
@export var dragon_template: PackedScene
|
||||
@export var dragon_spots: Array[Node2D]
|
||||
|
||||
var _instantiator: DragonInstantiator
|
||||
|
||||
|
||||
func _ready():
|
||||
_instantiator = DragonInstantiator.new(dragon_template, dragon_spots)
|
||||
|
||||
await get_tree().process_frame
|
||||
move_window_to_bottom_right()
|
||||
|
||||
|
||||
func move_window_to_bottom_right():
|
||||
var display_index: int = DisplayServer.window_get_current_screen()
|
||||
|
||||
var work_area_position: Vector2i = DisplayServer.screen_get_usable_rect(display_index).position
|
||||
var work_area_size: Vector2i = DisplayServer.screen_get_usable_rect(display_index).size
|
||||
|
||||
var window_size: Vector2i = DisplayServer.window_get_size()
|
||||
|
||||
var new_position: Vector2i = work_area_position + Vector2i(work_area_size.x - window_size.x, work_area_size.y - window_size.y)
|
||||
|
||||
DisplayServer.window_set_position(new_position)
|
||||
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("ui_accept"):
|
||||
var dragon = _instantiator.instantiate()
|
||||
add_child(dragon)
|
1
scenes/main.gd.uid
Normal file
1
scenes/main.gd.uid
Normal file
|
@ -0,0 +1 @@
|
|||
uid://3kyt3shje5r1
|
24
scenes/main.tscn
Normal file
24
scenes/main.tscn
Normal file
|
@ -0,0 +1,24 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://ctytpqaed0yqx"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://3kyt3shje5r1" path="res://scenes/main.gd" id="1_sugp2"]
|
||||
[ext_resource type="PackedScene" uid="uid://c7nfcgjxqeg7l" path="res://scenes/window/dragon_popup.tscn" id="2_jyhfs"]
|
||||
[ext_resource type="Texture2D" uid="uid://fdqnc2qrrvn1" path="res://assets/sprites/icon.svg" id="3_tbgi4"]
|
||||
|
||||
[node name="Base" type="Node2D" node_paths=PackedStringArray("dragon_spots")]
|
||||
script = ExtResource("1_sugp2")
|
||||
dragon_template = ExtResource("2_jyhfs")
|
||||
dragon_spots = [NodePath("DragonSpot1"), NodePath("DragonSpot2"), NodePath("DragonSpot3")]
|
||||
|
||||
[node name="Icon" type="Sprite2D" parent="."]
|
||||
position = Vector2(576, 324)
|
||||
scale = Vector2(9, 5.0625)
|
||||
texture = ExtResource("3_tbgi4")
|
||||
|
||||
[node name="DragonSpot1" type="Node2D" parent="."]
|
||||
position = Vector2(259, 450)
|
||||
|
||||
[node name="DragonSpot2" type="Node2D" parent="."]
|
||||
position = Vector2(557, 239)
|
||||
|
||||
[node name="DragonSpot3" type="Node2D" parent="."]
|
||||
position = Vector2(850, 360)
|
44
scenes/window/draggable.gd
Normal file
44
scenes/window/draggable.gd
Normal file
|
@ -0,0 +1,44 @@
|
|||
extends Control
|
||||
|
||||
|
||||
var dragging: bool = false
|
||||
var dragging_start_position: Vector2i = Vector2i()
|
||||
|
||||
@onready var dragon: Dragon = $".."
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
set_process_input(true)
|
||||
|
||||
|
||||
func _input(event) -> void:
|
||||
if event is not InputEventMouseButton:
|
||||
return
|
||||
if event.button_index != MOUSE_BUTTON_LEFT:
|
||||
return
|
||||
|
||||
if event.pressed:
|
||||
dragging = true
|
||||
dragging_start_position = Vector2i(get_global_mouse_position())
|
||||
else:
|
||||
dragging = false
|
||||
if _is_inside_main_window():
|
||||
_destroy_dragon()
|
||||
|
||||
|
||||
func _process(_delta) -> void:
|
||||
if dragging:
|
||||
dragon.position = dragon.position + Vector2i(get_global_mouse_position()) - dragging_start_position
|
||||
|
||||
|
||||
func _is_inside_main_window() -> bool:
|
||||
var id: int = get_window().get_window_id()
|
||||
var window_position: Vector2i = DisplayServer.window_get_position(id)
|
||||
var window_size: Vector2i = DisplayServer.window_get_size(id)
|
||||
var rect: Rect2i = Rect2i(window_position, window_size)
|
||||
|
||||
return rect.intersects(dragon.main_window_rect)
|
||||
|
||||
|
||||
func _destroy_dragon() -> void:
|
||||
dragon.queue_free()
|
1
scenes/window/draggable.gd.uid
Normal file
1
scenes/window/draggable.gd.uid
Normal file
|
@ -0,0 +1 @@
|
|||
uid://ch7d3wo8ucskb
|
5
scenes/window/dragon.gd
Normal file
5
scenes/window/dragon.gd
Normal file
|
@ -0,0 +1,5 @@
|
|||
extends Window
|
||||
class_name Dragon
|
||||
|
||||
|
||||
var main_window_rect: Rect2i
|
1
scenes/window/dragon.gd.uid
Normal file
1
scenes/window/dragon.gd.uid
Normal file
|
@ -0,0 +1 @@
|
|||
uid://bmlkcni4km614
|
25
scenes/window/dragon_popup.tscn
Normal file
25
scenes/window/dragon_popup.tscn
Normal file
|
@ -0,0 +1,25 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://c7nfcgjxqeg7l"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bmlkcni4km614" path="res://scenes/window/dragon.gd" id="1_ctdir"]
|
||||
[ext_resource type="Script" uid="uid://ch7d3wo8ucskb" path="res://scenes/window/draggable.gd" id="2_2r6si"]
|
||||
[ext_resource type="PackedScene" uid="uid://baa8gpicw2yg0" path="res://scenes/dragons/dragon.tscn" id="3_ctdir"]
|
||||
|
||||
[node name="DragonPopup" type="Window"]
|
||||
disable_3d = true
|
||||
transparent_bg = true
|
||||
position = Vector2i(0, 36)
|
||||
size = Vector2i(128, 128)
|
||||
unresizable = true
|
||||
borderless = true
|
||||
transparent = true
|
||||
script = ExtResource("1_ctdir")
|
||||
|
||||
[node name="DragDropDetector" type="Control" parent="."]
|
||||
layout_mode = 3
|
||||
anchors_preset = 0
|
||||
offset_right = 40.0
|
||||
offset_bottom = 40.0
|
||||
script = ExtResource("2_2r6si")
|
||||
|
||||
[node name="Dragon" parent="." instance=ExtResource("3_ctdir")]
|
||||
position = Vector2(64, 64)
|
Loading…
Add table
Add a link
Reference in a new issue