diff --git a/godot/.godot/global_script_class_cache.cfg b/godot/.godot/global_script_class_cache.cfg index 60ab278..62c7409 100644 --- a/godot/.godot/global_script_class_cache.cfg +++ b/godot/.godot/global_script_class_cache.cfg @@ -1,4 +1,10 @@ list=Array[Dictionary]([{ +"base": &"Button", +"class": &"DragAndDropItem", +"icon": "", +"language": &"GDScript", +"path": "res://src/widgets/dragable_item/dragable.gd" +}, { "base": &"EditorPlugin", "class": &"FormatOnSave", "icon": "", diff --git a/godot/src/script_editor/script_fragment.tscn b/godot/src/script_editor/script_fragment.tscn index 591ae35..86285ff 100644 --- a/godot/src/script_editor/script_fragment.tscn +++ b/godot/src/script_editor/script_fragment.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=3 format=3 uid="uid://rsvepepjglmt"] -[ext_resource type="Script" path="res://src/script_editor/script_fragment.gd" id="1_koyt3"] +[ext_resource type="Script" path="res://src/widgets/dragable_item/dragable.gd" id="1_57m8w"] [ext_resource type="PackedScene" uid="uid://btvekcxpfheas" path="res://src/script_editor/move_fragment.tscn" id="2_llv2k"] [node name="ScriptEditor" type="Control"] @@ -12,7 +12,7 @@ grow_horizontal = 2 grow_vertical = 2 size_flags_horizontal = 3 size_flags_vertical = 3 -script = ExtResource("1_koyt3") +script = ExtResource("1_57m8w") [node name="VBoxContainer" type="VBoxContainer" parent="."] layout_mode = 1 diff --git a/godot/src/sprite_selector/add_sprite.gd b/godot/src/sprite_selector/add_sprite.gd index 857e4b0..0766b3e 100644 --- a/godot/src/sprite_selector/add_sprite.gd +++ b/godot/src/sprite_selector/add_sprite.gd @@ -1,6 +1,6 @@ extends Control -var Sprites: Resource = preload("res://src/sprite_selector/sprite.tscn") +var Sprites: Resource = preload("res://src/sprite_selector/sprite_test.tscn") # Called when the node enters the scene tree for the first time. @@ -18,13 +18,14 @@ func _on_add_sprite_button_pressed(): func _on_file_dialog_file_selected(path): - var sprite: Button = Sprites.instantiate() + var sprite = Sprites.instantiate() sprite.setup(path) var margin_container = MarginContainer.new() - var margin_value = 10 - margin_container.add_theme_constant_override("margin_top", margin_value / 2) - margin_container.add_theme_constant_override("margin_left", margin_value) - margin_container.add_theme_constant_override("margin_bottom", margin_value / 2) - margin_container.add_theme_constant_override("margin_right", margin_value) + #var margin_value = 10 + #margin_container.add_theme_constant_override("margin_top", margin_value / 2) + #margin_container.add_theme_constant_override("margin_left", margin_value) + #margin_container.add_theme_constant_override("margin_bottom", margin_value / 2) + #margin_container.add_theme_constant_override("margin_right", margin_value) + #get_node("VBoxContainer2/VBox/ScrollContainer/VBoxIntems").add_child(sprite) get_node("VBoxContainer2/VBox/ScrollContainer/VBoxIntems").add_child(sprite) print_tree_pretty() diff --git a/godot/src/sprite_selector/sprite.gd b/godot/src/sprite_selector/sprite.gd index 74100b3..702a9cf 100644 --- a/godot/src/sprite_selector/sprite.gd +++ b/godot/src/sprite_selector/sprite.gd @@ -1,6 +1,4 @@ -extends Control - -@onready var target = 0 +extends DragAndDropItem func setup(path): @@ -10,7 +8,7 @@ func setup(path): tex.set_image(img) var label = get_node("VBoxContainer/Label") $VBoxContainer/TextureRect.texture = tex - label.text = path + $VBoxContainer/Label.text = path self.expand_icon = true @@ -18,26 +16,23 @@ func _ready(): set_process_input(false) -func _get_drag_data(_at_position: Vector2): - set_drag_preview(get_preview_controll()) - target = get_parent().get_node(self.get_path()).get_index(true) - return self - - -func _can_drop_data(_at_position, data): - target = get_parent().get_node(self.get_path()).get_index(true) - var node = get_parent().get_node(data.get_path()) - get_parent().move_child(node, target) - return true - +#func _get_drag_data(_at_position: Vector2): +# set_drag_preview(get_preview_controll()) +# target = get_parent().get_node(self.get_path()).get_index(true) +# return self -func get_preview_controll(): - return duplicate() +#func _can_drop_data(_at_position, data): +# target = get_parent().get_node(self.get_path()).get_index(true) +# var node = get_parent().get_node(data.get_path()) +# get_parent().move_child(node, target) +# return true +#func get_preview_controll(): +# return duplicate() -func _drop_data(_at_position, data): - var node = get_parent().get_node(data.get_path()) - get_parent().move_child(node, target) +#func _drop_data(_at_position, data): +# var node = get_parent().get_node(data.get_path()) +# get_parent().move_child(node, target) func _on_pressed(): diff --git a/godot/src/sprite_selector/sprite.tscn b/godot/src/sprite_selector/sprite.tscn index 4b84f7e..d401125 100644 --- a/godot/src/sprite_selector/sprite.tscn +++ b/godot/src/sprite_selector/sprite.tscn @@ -1,34 +1,36 @@ -[gd_scene load_steps=2 format=3 uid="uid://rsvepepjglmt"] +[gd_scene load_steps=3 format=3 uid="uid://rsvepepjglmt"] +[ext_resource type="Script" path="res://src/widgets/dragable_item/dragable.gd" id="1_lsqbi"] [ext_resource type="Script" path="res://src/sprite_selector/sprite.gd" id="1_p6m3n"] [node name="SpriteButton" type="Button"] -clip_contents = true -custom_minimum_size = Vector2(100, 100) -offset_right = 100.0 -offset_bottom = 200.0 -size_flags_horizontal = 3 -button_mask = 3 script = ExtResource("1_p6m3n") -[node name="VBoxContainer" type="VBoxContainer" parent="."] +[node name="DragAndDropItem" type="Button" parent="."] +offset_right = 8.0 +offset_bottom = 8.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 +script = ExtResource("1_lsqbi") + +[node name="VBoxContainer" type="VBoxContainer" parent="DragAndDropItem"] layout_mode = 1 anchors_preset = 15 anchor_right = 1.0 anchor_bottom = 1.0 +offset_right = 70.0 +offset_bottom = 97.0 grow_horizontal = 2 grow_vertical = 2 alignment = 1 -[node name="TextureRect" type="TextureRect" parent="VBoxContainer"] +[node name="TextureRect" type="TextureRect" parent="DragAndDropItem/VBoxContainer"] custom_minimum_size = Vector2(70, 70) layout_mode = 2 size_flags_vertical = 3 expand_mode = 3 stretch_mode = 5 -[node name="Label" type="Label" parent="VBoxContainer"] +[node name="Label" type="Label" parent="DragAndDropItem/VBoxContainer"] layout_mode = 2 horizontal_alignment = 1 - -[connection signal="pressed" from="." to="." method="_on_pressed"]