Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

drag and drop basic #106

Merged
merged 3 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions godot/src/script_editor/AddTurnButton.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
extends Button

const MoveFragment: Resource = preload(
"res://src/script_editor/fragments/move_fragment/turn_fragment.tscn"
)


func _on_pressed():
#print_tree_pretty()
API.insert(200)
(
get_tree()
. get_current_scene()
. get_node("VBoxContainer/VScrollContainer/AutoRefresh/Code")
. add_child(MoveFragment.instantiate())
)
#get_tree().get_current_scene().print_tree_pretty()
10 changes: 10 additions & 0 deletions godot/src/script_editor/button_add.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
extends Button

const TurnFragment: Resource = preload(
"res://src/script_editor/fragments/move_fragment/move_fragment.tscn"
)


func _on_pressed():
API.insert(200)
(
get_tree()
. get_current_scene()
. get_node("VBoxContainer/VScrollContainer/AutoRefresh/Code")
. add_child(TurnFragment.instantiate())
)
15 changes: 15 additions & 0 deletions godot/src/script_editor/button_for.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
extends Button

const MoveFragment: Resource = preload(
"res://src/script_editor/fragments/move_fragment/for_fragment.tscn"
)


func _on_pressed():
API.insert(200)
(
get_tree()
. get_current_scene()
. get_node("VBoxContainer/VScrollContainer/AutoRefresh/Code")
. add_child(MoveFragment.instantiate())
)
15 changes: 15 additions & 0 deletions godot/src/script_editor/button_while.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
extends Button

const MoveFragment: Resource = preload(
"res://src/script_editor/fragments/move_fragment/while_fragment.tscn"
)


func _on_pressed():
API.insert(200)
(
get_tree()
. get_current_scene()
. get_node("VBoxContainer/VScrollContainer/AutoRefresh/Code")
. add_child(MoveFragment.instantiate())
)
76 changes: 76 additions & 0 deletions godot/src/script_editor/fragments/move_fragment/for_fragment.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
[gd_scene load_steps=4 format=3 uid="uid://oiepjld6lwrp"]

[ext_resource type="Script" path="res://src/widgets/draggable tree/draggable_node.gd" id="1_o43h1"]
[ext_resource type="Script" path="res://src/widgets/draggable tree/non_dragable_label.gd" id="2_37oc4"]
[ext_resource type="Script" path="res://src/widgets/draggable tree/draggable_node_start.gd" id="3_wsklg"]

[node name="ForFragment" type="Control"]
custom_minimum_size = Vector2(0, 200)
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 3
script = ExtResource("1_o43h1")

[node name="VBoxContainer2" type="VBoxContainer" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2

[node name="NonDragLabel" type="Control" parent="VBoxContainer2"]
custom_minimum_size = Vector2(0, 20)
layout_mode = 2
script = ExtResource("2_37oc4")

[node name="Label" type="Label" parent="VBoxContainer2/NonDragLabel"]
custom_minimum_size = Vector2(0, 20)
layout_mode = 0
offset_right = 40.0
offset_bottom = 23.0
text = "For sdfsdfsdf"

[node name="DragNodeStart" type="Control" parent="VBoxContainer2"]
visible = false
custom_minimum_size = Vector2(0, 20)
layout_mode = 2
script = ExtResource("3_wsklg")

[node name="VBoxContainer" type="VBoxContainer" parent="VBoxContainer2"]
custom_minimum_size = Vector2(200, 200)
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 2

[node name="Label3" type="Label" parent="VBoxContainer2/VBoxContainer"]
custom_minimum_size = Vector2(200, 20)
layout_mode = 2
size_flags_vertical = 3
text = "wrwerwer"
autowrap_mode = 3

[node name="Label2" type="Label" parent="VBoxContainer2/VBoxContainer"]
custom_minimum_size = Vector2(200, 20)
layout_mode = 2
size_flags_vertical = 3
text = "wrwer"
autowrap_mode = 3

[node name="Label" type="Label" parent="VBoxContainer2/VBoxContainer"]
custom_minimum_size = Vector2(200, 20)
layout_mode = 2
size_flags_vertical = 3
text = "werwer"
autowrap_mode = 3

[node name="Label4" type="Label" parent="VBoxContainer2/VBoxContainer"]
custom_minimum_size = Vector2(200, 20)
layout_mode = 2
size_flags_vertical = 3
text = "werwer"
autowrap_mode = 3
27 changes: 27 additions & 0 deletions godot/src/script_editor/fragments/move_fragment/move_fragment.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[gd_scene load_steps=2 format=3 uid="uid://bsutrnlas8do1"]

[ext_resource type="Script" path="res://src/widgets/draggable tree/draggable_leaf.gd" id="1_8mp6h"]

[node name="Move Fragment" type="Control"]
custom_minimum_size = Vector2(0, 20)
layout_mode = 3
anchors_preset = 0
offset_right = 40.0
offset_bottom = 40.0
script = ExtResource("1_8mp6h")

[node name="VBoxContainer" type="VBoxContainer" parent="."]
custom_minimum_size = Vector2(0, 20)
layout_mode = 2
offset_right = 74.0
offset_bottom = 23.0
size_flags_horizontal = 3
size_flags_vertical = 3

[node name="Label" type="Label" parent="VBoxContainer"]
custom_minimum_size = Vector2(0, 20)
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
text = "MOVE X Y"
vertical_alignment = 1
28 changes: 28 additions & 0 deletions godot/src/script_editor/fragments/move_fragment/turn_fragment.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[gd_scene load_steps=2 format=3 uid="uid://ccy3ijvvrbguo"]

[ext_resource type="Script" path="res://src/widgets/draggable tree/draggable_leaf.gd" id="1_8rgbb"]

[node name="MoveFragment" type="Container"]
custom_minimum_size = Vector2(0, 20)
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 3
size_flags_vertical = 3
script = ExtResource("1_8rgbb")

[node name="VBoxContainer" type="VBoxContainer" parent="."]
custom_minimum_size = Vector2(0, 20)
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3

[node name="Label" type="Label" parent="VBoxContainer"]
custom_minimum_size = Vector2(0, 20)
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
text = "TURN X"
vertical_alignment = 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
[gd_scene load_steps=4 format=3 uid="uid://d215f38mcypns"]

[ext_resource type="Script" path="res://src/widgets/draggable tree/draggable_node.gd" id="1_oy1be"]
[ext_resource type="Script" path="res://src/widgets/draggable tree/non_dragable_label.gd" id="2_wuun8"]
[ext_resource type="Script" path="res://src/widgets/draggable tree/draggable_node_start.gd" id="3_jnb65"]

[node name="ForFragment" type="Control"]
custom_minimum_size = Vector2(0, 200)
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 3
script = ExtResource("1_oy1be")

[node name="VBoxContainer2" type="VBoxContainer" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2

[node name="NonDragLabel" type="Control" parent="VBoxContainer2"]
custom_minimum_size = Vector2(0, 20)
layout_mode = 2
script = ExtResource("2_wuun8")

[node name="Label" type="Label" parent="VBoxContainer2/NonDragLabel"]
custom_minimum_size = Vector2(0, 20)
layout_mode = 0
offset_right = 40.0
offset_bottom = 23.0
text = "while sdfsdfsdf"

[node name="DragNodeStart" type="Control" parent="VBoxContainer2"]
visible = false
custom_minimum_size = Vector2(0, 20)
layout_mode = 2
script = ExtResource("3_jnb65")

[node name="VBoxContainer" type="VBoxContainer" parent="VBoxContainer2"]
custom_minimum_size = Vector2(200, 200)
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 2

[node name="Label3" type="Label" parent="VBoxContainer2/VBoxContainer"]
custom_minimum_size = Vector2(200, 20)
layout_mode = 2
size_flags_vertical = 3
text = "wrwerwer"
autowrap_mode = 3

[node name="Label2" type="Label" parent="VBoxContainer2/VBoxContainer"]
custom_minimum_size = Vector2(200, 20)
layout_mode = 2
size_flags_vertical = 3
text = "wrwer"
autowrap_mode = 3

[node name="Label" type="Label" parent="VBoxContainer2/VBoxContainer"]
custom_minimum_size = Vector2(200, 20)
layout_mode = 2
size_flags_vertical = 3
text = "werwer"
autowrap_mode = 3

[node name="Label4" type="Label" parent="VBoxContainer2/VBoxContainer"]
custom_minimum_size = Vector2(200, 20)
layout_mode = 2
size_flags_vertical = 3
text = "werwer"
autowrap_mode = 3
25 changes: 24 additions & 1 deletion godot/src/script_editor/main.tscn
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
[gd_scene load_steps=4 format=3 uid="uid://rsvepepjglmt"]
[gd_scene load_steps=7 format=3 uid="uid://rsvepepjglmt"]

[ext_resource type="Script" path="res://src/script_editor/button_run.gd" id="1_2l7lb"]
[ext_resource type="Script" path="res://src/script_editor/button_add.gd" id="2_vfewj"]
[ext_resource type="Script" path="res://src/script_editor/AddTurnButton.gd" id="3_03kqp"]
[ext_resource type="Script" path="res://src/script_editor/auto_refresh_fragments.gd" id="3_6u76r"]
[ext_resource type="Script" path="res://src/script_editor/button_for.gd" id="4_kijn7"]
[ext_resource type="Script" path="res://src/script_editor/button_while.gd" id="5_qxwii"]

[node name="ScriptEditor" type="Control"]
layout_mode = 3
Expand Down Expand Up @@ -37,13 +40,30 @@ layout_mode = 2
text = "Add Move"
script = ExtResource("2_vfewj")

[node name="AddTurnButton" type="Button" parent="VBoxContainer/HBoxContainer"]
layout_mode = 2
text = "Add testnode"
script = ExtResource("3_03kqp")

[node name="AddForButton" type="Button" parent="VBoxContainer/HBoxContainer"]
layout_mode = 2
text = "Add For"
script = ExtResource("4_kijn7")

[node name="AddWhileButton" type="Button" parent="VBoxContainer/HBoxContainer"]
layout_mode = 2
text = "Add While"
script = ExtResource("5_qxwii")

[node name="VScrollContainer" type="ScrollContainer" parent="VBoxContainer"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3

[node name="AutoRefresh" type="VBoxContainer" parent="VBoxContainer/VScrollContainer"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
script = ExtResource("3_6u76r")

[node name="Code" type="VBoxContainer" parent="VBoxContainer/VScrollContainer/AutoRefresh"]
Expand All @@ -52,3 +72,6 @@ size_flags_horizontal = 3

[connection signal="pressed" from="VBoxContainer/HBoxContainer/RunButton" to="VBoxContainer/HBoxContainer/RunButton" method="_on_pressed"]
[connection signal="pressed" from="VBoxContainer/HBoxContainer/AddButton" to="VBoxContainer/HBoxContainer/AddButton" method="_on_pressed"]
[connection signal="pressed" from="VBoxContainer/HBoxContainer/AddTurnButton" to="VBoxContainer/HBoxContainer/AddTurnButton" method="_on_pressed"]
[connection signal="pressed" from="VBoxContainer/HBoxContainer/AddForButton" to="VBoxContainer/HBoxContainer/AddForButton" method="_on_pressed"]
[connection signal="pressed" from="VBoxContainer/HBoxContainer/AddWhileButton" to="VBoxContainer/HBoxContainer/AddWhileButton" method="_on_pressed"]
39 changes: 39 additions & 0 deletions godot/src/widgets/draggable tree/draggable_leaf.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
@tool
class_name DragLeaf
extends Control

@onready var target = 0


func _ready():
add_to_group("draggable_leaf")


func _get_drag_data(_at_position: Vector2):
set_drag_preview(get_preview_controll())
return self


func get_preview_controll():
return duplicate()


func _drop_data(_at_position, _data):
pass


func _can_drop_data(_at_position, data):
var node
if data.is_in_group("draggable_leaf"):
target = get_node(self.get_path()).get_index(true)
node = get_node(data.get_path())
get_parent().move_child(node, target)

elif data.is_in_group("draggable_node"):
target = get_node(self.get_path()).get_index(true)
node = get_node(data.get_path())
get_parent().move_child(node, target)
else:
print(data)
assert(false, "Invalid node")
return true
Loading
Loading