From 159ee7678b0de422eb21cf5159ecd9442e9bea74 Mon Sep 17 00:00:00 2001 From: Rodolphe Suescun Date: Sun, 20 Oct 2019 11:33:33 +0200 Subject: [PATCH] Added subgraph navigation popup --- addons/material_maker/graph_edit.gd | 17 ++++-- addons/material_maker/graph_edit.tscn | 53 ++++++++++++++----- addons/material_maker/icons/icons.svg | 36 +++++++++++-- addons/material_maker/main_window.tscn | 8 +-- .../widgets/graph_tree/graph_tree.gd | 22 ++++++++ .../widgets/graph_tree/graph_tree.tscn | 14 +++++ 6 files changed, 125 insertions(+), 25 deletions(-) create mode 100644 addons/material_maker/widgets/graph_tree/graph_tree.gd create mode 100644 addons/material_maker/widgets/graph_tree/graph_tree.tscn diff --git a/addons/material_maker/graph_edit.gd b/addons/material_maker/graph_edit.gd index afe7c37..a665d29 100644 --- a/addons/material_maker/graph_edit.gd +++ b/addons/material_maker/graph_edit.gd @@ -12,6 +12,10 @@ var need_save = false var top_generator = null var generator = null +onready var timer : Timer = $Timer + +onready var subgraph_ui : HBoxContainer = $GraphUI/SubGraphUI + signal save_path_changed signal graph_changed @@ -110,8 +114,8 @@ func update_view(g): clear_view() generator = g update_graph(generator.get_children(), generator.connections) - $SubGraphUI.visible = generator != top_generator - $SubGraphUI/Label.text = generator.label + subgraph_ui.visible = generator != top_generator + subgraph_ui.get_node("Label").text = generator.label center_view() func clear_material(): @@ -263,7 +267,7 @@ func paste(pos = Vector2(0, 0)): func send_changed_signal(): set_need_save(true) - $Timer.start(0.1) + timer.start(0.1) func do_send_changed_signal(): emit_signal("graph_changed") @@ -296,4 +300,9 @@ func create_subgraph(): generator.create_subgraph(generators) update_view(generator) - +func _on_ButtonShowTree_pressed(): + var graph_tree : Popup = preload("res://addons/material_maker/widgets/graph_tree/graph_tree.tscn").instance() + graph_tree.init("Top", top_generator) + add_child(graph_tree) + graph_tree.connect("item_double_clicked", self, "update_view") + graph_tree.popup_centered() diff --git a/addons/material_maker/graph_edit.tscn b/addons/material_maker/graph_edit.tscn index cb926a5..edcb557 100644 --- a/addons/material_maker/graph_edit.tscn +++ b/addons/material_maker/graph_edit.tscn @@ -1,6 +1,17 @@ -[gd_scene load_steps=2 format=2] +[gd_scene load_steps=5 format=2] [ext_resource path="res://addons/material_maker/graph_edit.gd" type="Script" id=1] +[ext_resource path="res://addons/material_maker/icons/icons.svg" type="Texture" id=2] + +[sub_resource type="AtlasTexture" id=1] +flags = 4 +atlas = ExtResource( 2 ) +region = Rect2( 15.4016, 47.1451, 16.7512, 17.8319 ) + +[sub_resource type="AtlasTexture" id=2] +flags = 4 +atlas = ExtResource( 2 ) +region = Rect2( 0, 48, 16, 16 ) [node name="GraphEdit" type="GraphEdit"] self_modulate = Color( 1, 1, 1, 0 ) @@ -14,25 +25,41 @@ script = ExtResource( 1 ) wait_time = 0.2 one_shot = true -[node name="SubGraphUI" type="HBoxContainer" parent="."] +[node name="GraphUI" type="HBoxContainer" parent="."] anchor_left = 1.0 anchor_right = 1.0 -margin_left = -197.0 -margin_right = -13.0 -margin_bottom = 24.0 +margin_left = -592.0 +margin_right = -16.0 +margin_bottom = 40.0 +alignment = 2 -[node name="Label" type="LineEdit" parent="SubGraphUI"] +[node name="SubGraphUI" type="HBoxContainer" parent="GraphUI"] +margin_left = 362.0 +margin_right = 544.0 +margin_bottom = 40.0 +size_flags_horizontal = 9 + +[node name="Label" type="LineEdit" parent="GraphUI/SubGraphUI"] margin_right = 150.0 -margin_bottom = 24.0 +margin_bottom = 40.0 rect_min_size = Vector2( 150, 0 ) +size_flags_horizontal = 9 -[node name="ButtonUp" type="Button" parent="SubGraphUI"] +[node name="ButtonUp" type="Button" parent="GraphUI/SubGraphUI"] margin_left = 154.0 -margin_right = 184.0 -margin_bottom = 24.0 -text = "Up" +margin_right = 182.0 +margin_bottom = 40.0 +size_flags_horizontal = 9 +icon = SubResource( 1 ) + +[node name="ButtonShowTree" type="Button" parent="GraphUI"] +margin_left = 548.0 +margin_right = 576.0 +margin_bottom = 40.0 +icon = SubResource( 2 ) [connection signal="connection_request" from="." to="." method="connect_node"] [connection signal="disconnection_request" from="." to="." method="disconnect_node"] [connection signal="timeout" from="Timer" to="." method="do_send_changed_signal"] -[connection signal="text_changed" from="SubGraphUI/Label" to="." method="_on_Label_text_changed"] -[connection signal="pressed" from="SubGraphUI/ButtonUp" to="." method="on_ButtonUp_pressed"] +[connection signal="text_changed" from="GraphUI/SubGraphUI/Label" to="." method="_on_Label_text_changed"] +[connection signal="pressed" from="GraphUI/SubGraphUI/ButtonUp" to="." method="on_ButtonUp_pressed"] +[connection signal="pressed" from="GraphUI/ButtonShowTree" to="." method="_on_ButtonShowTree_pressed"] diff --git a/addons/material_maker/icons/icons.svg b/addons/material_maker/icons/icons.svg index f7fed9a..ab2a85f 100644 --- a/addons/material_maker/icons/icons.svg +++ b/addons/material_maker/icons/icons.svg @@ -15,7 +15,7 @@ viewBox="0 0 64 64" version="1.1" id="svg8" - inkscape:version="0.92.3 (2405546, 2018-03-11)" + inkscape:version="0.92.4 (5da689c313, 2019-01-14)" sodipodi:docname="icons.svg"> @@ -48,9 +48,9 @@ borderopacity="1.0" inkscape:pageopacity="0.0" inkscape:pageshadow="2" - inkscape:zoom="14.304427" - inkscape:cx="33.274902" - inkscape:cy="41.347265" + inkscape:zoom="40.459029" + inkscape:cx="17.695886" + inkscape:cy="7.9897925" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="true" @@ -324,5 +324,33 @@ d="m 23.783078,44.110649 -4.508983,4.648736 -3.980261,-5.27284 a 12.770835,12.770835 0 0 0 -2.631282,1.045173 l 0.825522,6.441784 -6.571368,-0.17469 a 12.770835,12.770835 0 0 0 -0.7896172,2.557631 12.770835,12.770835 0 0 0 -0.027504,0.173796 l 5.5120272,3.347264 -4.1861363,4.972095 a 12.770835,12.770835 0 0 0 1.6563998,2.37002 l 5.9760855,-2.194035 1.267643,6.324612 a 12.770835,12.770835 0 0 0 2.907828,0.192046 l 1.997862,-6.001057 5.727797,2.948399 a 12.770835,12.770835 0 0 0 1.98019,-2.135962 l -3.455675,-5.317616 5.926699,-2.662342 a 12.770835,12.770835 0 0 0 -0.414249,-2.850168 l -6.383635,-0.620945 1.631047,-6.361785 a 12.770835,12.770835 0 0 0 -2.46039,-1.430116 z m -4.472442,8.529047 a 3.1927084,3.1927084 0 0 1 2.523332,3.744269 3.1927084,3.1927084 0 0 1 -3.744267,2.523336 3.1927084,3.1927084 0 0 1 -2.523335,-3.744269 3.1927084,3.1927084 0 0 1 3.74427,-2.523336 z" style="opacity:1;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:0.80446196;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:fill markers stroke" /> + + + + + diff --git a/addons/material_maker/main_window.tscn b/addons/material_maker/main_window.tscn index 71d0015..146fef7 100644 --- a/addons/material_maker/main_window.tscn +++ b/addons/material_maker/main_window.tscn @@ -8,13 +8,13 @@ [ext_resource path="res://addons/material_maker/engine/renderer.tscn" type="PackedScene" id=6] [ext_resource path="res://addons/material_maker/node_factory.gd" type="Script" id=7] -[sub_resource type="PanoramaSky" id=4] +[sub_resource type="PanoramaSky" id=1] resource_local_to_scene = true panorama = ExtResource( 4 ) -[sub_resource type="Environment" id=5] +[sub_resource type="Environment" id=2] background_mode = 2 -background_sky = SubResource( 4 ) +background_sky = SubResource( 1 ) background_energy = 1.5 ambient_light_color = Color( 1, 1, 1, 1 ) ambient_light_energy = 0.32 @@ -124,7 +124,7 @@ render_target_update_mode = 0 [node name="Camera" type="Camera" parent="VBoxContainer/HBoxContainer/ProjectsPane/BackgroundPreview/Viewport"] transform = Transform( 1, 0, 0, 0, 0.766044, 0.642788, 0, -0.642788, 0.766044, 0, 2.24976, 2.68115 ) -environment = SubResource( 5 ) +environment = SubResource( 2 ) current = true [node name="Projects" type="Panel" parent="VBoxContainer/HBoxContainer/ProjectsPane"] diff --git a/addons/material_maker/widgets/graph_tree/graph_tree.gd b/addons/material_maker/widgets/graph_tree/graph_tree.gd new file mode 100644 index 0000000..6df586b --- /dev/null +++ b/addons/material_maker/widgets/graph_tree/graph_tree.gd @@ -0,0 +1,22 @@ +extends Popup + +signal item_double_clicked(generator) + +func init(graph_name : String, generator : MMGenGraph): + $Tree.clear() + var root : TreeItem = $Tree.create_item(null) + root.set_text(0, graph_name) + root.set_metadata(0, generator) + fill_item(root, generator) + +func fill_item(parent : TreeItem, generator : MMGenGraph): + for c in generator.get_children(): + if c is MMGenGraph: + var item : TreeItem = $Tree.create_item(parent) + item.set_text(0, c.get_type_name()) + item.set_metadata(0, c) + fill_item(item, c) + +func _on_Tree_item_double_clicked(): + emit_signal("item_double_clicked", $Tree.get_selected().get_metadata(0)) + queue_free() diff --git a/addons/material_maker/widgets/graph_tree/graph_tree.tscn b/addons/material_maker/widgets/graph_tree/graph_tree.tscn new file mode 100644 index 0000000..57d466c --- /dev/null +++ b/addons/material_maker/widgets/graph_tree/graph_tree.tscn @@ -0,0 +1,14 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://addons/material_maker/widgets/graph_tree/graph_tree.gd" type="Script" id=1] + +[node name="GraphTree" type="Popup"] +margin_right = 335.0 +margin_bottom = 339.0 +script = ExtResource( 1 ) + +[node name="Tree" type="Tree" parent="."] +anchor_right = 1.0 +anchor_bottom = 1.0 +[connection signal="item_activated" from="Tree" to="." method="_on_Tree_item_double_clicked"] +[connection signal="item_double_clicked" from="Tree" to="." method="_on_Tree_item_double_clicked"]