feat: basic dragon instantiating
This commit is contained in:
parent
a0bb24464d
commit
9e153b63ac
6 changed files with 76 additions and 1 deletions
|
@ -1,10 +1,12 @@
|
||||||
[gd_scene load_steps=3 format=3 uid="uid://ctytpqaed0yqx"]
|
[gd_scene load_steps=4 format=3 uid="uid://ctytpqaed0yqx"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://3kyt3shje5r1" path="res://scripts/window.gd" id="1_3vi8l"]
|
[ext_resource type="Script" uid="uid://3kyt3shje5r1" path="res://scripts/window.gd" id="1_3vi8l"]
|
||||||
[ext_resource type="Texture2D" uid="uid://fdqnc2qrrvn1" path="res://icon.svg" id="1_rpg24"]
|
[ext_resource type="Texture2D" uid="uid://fdqnc2qrrvn1" path="res://icon.svg" id="1_rpg24"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://c7nfcgjxqeg7l" path="res://dragon.tscn" id="2_8rhti"]
|
||||||
|
|
||||||
[node name="Base" type="Node2D"]
|
[node name="Base" type="Node2D"]
|
||||||
script = ExtResource("1_3vi8l")
|
script = ExtResource("1_3vi8l")
|
||||||
|
dragon_template = ExtResource("2_8rhti")
|
||||||
|
|
||||||
[node name="Icon" type="Sprite2D" parent="."]
|
[node name="Icon" type="Sprite2D" parent="."]
|
||||||
position = Vector2(576, 324)
|
position = Vector2(576, 324)
|
||||||
|
|
24
dragon.tscn
Normal file
24
dragon.tscn
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
[gd_scene load_steps=3 format=3 uid="uid://c7nfcgjxqeg7l"]
|
||||||
|
|
||||||
|
[ext_resource type="Texture2D" uid="uid://fdqnc2qrrvn1" path="res://icon.svg" id="1_ixu8j"]
|
||||||
|
[ext_resource type="Script" uid="uid://bmlkcni4km614" path="res://scripts/dragon.gd" id="1_n6spy"]
|
||||||
|
|
||||||
|
[node name="Dragon" type="Window"]
|
||||||
|
disable_3d = true
|
||||||
|
transparent_bg = true
|
||||||
|
position = Vector2i(0, 36)
|
||||||
|
size = Vector2i(128, 128)
|
||||||
|
unresizable = true
|
||||||
|
borderless = true
|
||||||
|
transparent = true
|
||||||
|
|
||||||
|
[node name="DragDropDetector" type="Control" parent="."]
|
||||||
|
layout_mode = 3
|
||||||
|
anchors_preset = 0
|
||||||
|
offset_right = 40.0
|
||||||
|
offset_bottom = 40.0
|
||||||
|
script = ExtResource("1_n6spy")
|
||||||
|
|
||||||
|
[node name="Icon" type="Sprite2D" parent="."]
|
||||||
|
position = Vector2(64, 65)
|
||||||
|
texture = ExtResource("1_ixu8j")
|
|
@ -20,6 +20,7 @@ config/icon="res://icon.svg"
|
||||||
|
|
||||||
window/size/borderless=true
|
window/size/borderless=true
|
||||||
window/size/transparent=true
|
window/size/transparent=true
|
||||||
|
window/subwindows/embed_subwindows=false
|
||||||
window/per_pixel_transparency/allowed=true
|
window/per_pixel_transparency/allowed=true
|
||||||
|
|
||||||
[dotnet]
|
[dotnet]
|
||||||
|
|
29
scripts/dragon.gd
Normal file
29
scripts/dragon.gd
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
extends Control
|
||||||
|
|
||||||
|
|
||||||
|
var dragging = false
|
||||||
|
var dragging_start_position = Vector2i()
|
||||||
|
|
||||||
|
@onready var window: Window = $".."
|
||||||
|
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
set_process_input(true)
|
||||||
|
|
||||||
|
|
||||||
|
func _input(event):
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
func _process(_delta):
|
||||||
|
if dragging:
|
||||||
|
window.position = window.position + Vector2i(get_global_mouse_position()) - dragging_start_position
|
1
scripts/dragon.gd.uid
Normal file
1
scripts/dragon.gd.uid
Normal file
|
@ -0,0 +1 @@
|
||||||
|
uid://bmlkcni4km614
|
|
@ -1,5 +1,9 @@
|
||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
|
|
||||||
|
@export var dragon_template: PackedScene
|
||||||
|
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
await get_tree().process_frame
|
await get_tree().process_frame
|
||||||
move_window_to_bottom_right()
|
move_window_to_bottom_right()
|
||||||
|
@ -16,3 +20,17 @@ func move_window_to_bottom_right():
|
||||||
var new_position: Vector2i = work_area_position + Vector2i(work_area_size.x - window_size.x, work_area_size.y - window_size.y)
|
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)
|
DisplayServer.window_set_position(new_position)
|
||||||
|
|
||||||
|
|
||||||
|
func _unhandled_input(event: InputEvent) -> void:
|
||||||
|
if event.is_action_pressed("ui_accept"):
|
||||||
|
_instantiate_dragon(Vector2i(0, 0))
|
||||||
|
|
||||||
|
|
||||||
|
func _instantiate_dragon(relative_position: Vector2i) -> void:
|
||||||
|
var dragon = dragon_template.instantiate()
|
||||||
|
add_child(dragon)
|
||||||
|
if dragon is Window:
|
||||||
|
var window_position: Vector2i = DisplayServer.window_get_position()
|
||||||
|
dragon.position = window_position + relative_position
|
||||||
|
dragon.show()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue