Replaced the TabContainer with a Tabs control

- Load material can now load several materials
- the current tab now has a close button
This commit is contained in:
Rodolphe Suescun 2018-08-27 17:22:57 +02:00
parent 467ba24a5f
commit ec645a06f4
5 changed files with 119 additions and 22 deletions

View File

@ -66,6 +66,8 @@ func remove_node(node):
# Global operations on graph
func update_tab_title():
if !get_parent().has_method("set_tab_title"):
return
var title = "[unnamed]"
if save_path != null:
title = save_path.right(save_path.rfind("/")+1)
@ -77,8 +79,7 @@ func update_tab_title():
func set_need_save(ns):
if ns != need_save:
need_save = ns
if get_parent() is TabContainer:
update_tab_title()
update_tab_title()
func set_save_path(path):
if path != save_path:

View File

@ -1,7 +1,7 @@
tool
extends Panel
var current_tab = -1
var current_tab = null
const MENU = [
{ menu="File", command="new_material", description="New material" },
@ -89,11 +89,16 @@ func load_material():
add_child(dialog)
dialog.rect_min_size = Vector2(500, 500)
dialog.access = FileDialog.ACCESS_FILESYSTEM
dialog.mode = FileDialog.MODE_OPEN_FILE
dialog.mode = FileDialog.MODE_OPEN_FILES
dialog.add_filter("*.ptex;Procedural textures file")
dialog.connect("file_selected", self, "do_load_material")
#dialog.connect("file_selected", self, "do_load_material")
dialog.connect("files_selected", self, "do_load_materials")
dialog.popup_centered()
func do_load_materials(filenames):
for f in filenames:
do_load_material(f)
func do_load_material(filename):
var graph_edit = $VBoxContainer/HBoxContainer/Projects.get_current_tab_control()
var node_count = 0
@ -120,9 +125,7 @@ func save_material_as():
graph_edit.save_file_as()
func close_material():
var graph_edit = $VBoxContainer/HBoxContainer/Projects.get_current_tab_control()
if graph_edit != null:
graph_edit.queue_free()
$VBoxContainer/HBoxContainer/Projects.close_tab()
func export_material():
var graph_edit = $VBoxContainer/HBoxContainer/Projects.get_current_tab_control()
@ -245,11 +248,13 @@ func update_preview_2d(node = null):
graph_edit.setup_material(preview.get_2d_material(), node.get_textures(), node.generate_shader())
func _on_Projects_tab_changed(tab):
if tab != current_tab:
for c in get_incoming_connections():
if c.method_name == "update_preview" or c.method_name == "update_preview_2d":
c.source.disconnect(c.signal_name, self, c.method_name)
$VBoxContainer/HBoxContainer/Projects.get_current_tab_control().connect("graph_changed", self, "update_preview")
$VBoxContainer/HBoxContainer/Projects.get_current_tab_control().connect("node_selected", self, "update_preview_2d")
current_tab = tab
var new_tab = $VBoxContainer/HBoxContainer/Projects.get_current_tab_control()
if new_tab != current_tab:
if new_tab != null:
for c in get_incoming_connections():
if c.method_name == "update_preview" or c.method_name == "update_preview_2d":
c.source.disconnect(c.signal_name, self, c.method_name)
new_tab.connect("graph_changed", self, "update_preview")
new_tab.connect("node_selected", self, "update_preview_2d")
current_tab = new_tab
update_preview()

View File

@ -1,8 +1,9 @@
[gd_scene load_steps=4 format=2]
[gd_scene load_steps=5 format=2]
[ext_resource path="res://addons/procedural_material/main_window.gd" type="Script" id=1]
[ext_resource path="res://addons/procedural_material/library.gd" type="Script" id=2]
[ext_resource path="res://addons/procedural_material/preview.tscn" type="PackedScene" id=3]
[ext_resource path="res://addons/procedural_material/widgets/tabs.gd" type="Script" id=4]
[node name="MainWindow" type="Panel" index="0"]
@ -222,7 +223,7 @@ margin_top = 354.0
margin_right = 314.0
margin_bottom = 696.0
[node name="Projects" type="TabContainer" parent="VBoxContainer/HBoxContainer" index="1"]
[node name="Projects" type="Panel" parent="VBoxContainer/HBoxContainer" index="1"]
anchor_left = 0.0
anchor_top = 0.0
@ -238,16 +239,41 @@ mouse_default_cursor_shape = 0
size_flags_horizontal = 3
size_flags_vertical = 3
size_flags_stretch_ratio = 3.0
script = ExtResource( 4 )
_sections_unfolded = [ "custom_styles" ]
[node name="Tabs" type="Tabs" parent="VBoxContainer/HBoxContainer/Projects" index="1"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_right = 954.0
margin_bottom = 23.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
tab_align = 0
tabs_visible = true
_sections_unfolded = [ "Size Flags" ]
tab_close_display_policy = 1
scrolling_enabled = true
[connection signal="no_more_tabs" from="VBoxContainer/HBoxContainer/Projects" to="." method="new_material"]
[connection signal="resized" from="VBoxContainer/HBoxContainer/Projects" to="VBoxContainer/HBoxContainer/Projects" method="_on_Projects_resized"]
[connection signal="tab_changed" from="VBoxContainer/HBoxContainer/Projects" to="." method="_on_Projects_tab_changed"]
[connection signal="tab_selected" from="VBoxContainer/HBoxContainer/Projects" to="." method="_on_Projects_tab_changed"]
[connection signal="connection_request" from="VBoxContainer/HBoxContainer/Projects/GraphEdit" to="VBoxContainer/HBoxContainer/Projects/GraphEdit" method="connect_node"]
[connection signal="disconnection_request" from="VBoxContainer/HBoxContainer/Projects/GraphEdit" to="VBoxContainer/HBoxContainer/Projects/GraphEdit" method="disconnect_node"]
[connection signal="reposition_active_tab_request" from="VBoxContainer/HBoxContainer/Projects/Tabs" to="VBoxContainer/HBoxContainer/Projects" method="move_active_tab_to"]
[connection signal="tab_changed" from="VBoxContainer/HBoxContainer/Projects/Tabs" to="VBoxContainer/HBoxContainer/Projects" method="set_current_tab"]
[connection signal="tab_close" from="VBoxContainer/HBoxContainer/Projects/Tabs" to="VBoxContainer/HBoxContainer/Projects" method="close_tab"]

View File

@ -10,7 +10,6 @@ func _ready():
$HBoxContainer1/size.add_item(str(int(pow(2, 5+i))), i)
$HBoxContainer1/size.selected = size
initialize_properties([ $HBoxContainer1/size, $HBoxContainer2/density ])
print(size)
func _get_shader_code(uv):
var rv = { defs="", code="" }

View File

@ -0,0 +1,66 @@
tool
extends Panel
var current_tab = -1 setget set_current_tab
signal tab_changed
signal no_more_tabs
func _ready():
pass
func add_child(control):
.add_child(control)
if !(control is Tabs):
$Tabs.add_tab(control.name)
move_child(control, $Tabs.get_tab_count()-1)
func close_tab(tab = null):
if tab == null:
tab = $Tabs.get_current_tab()
get_child(tab).queue_free()
$Tabs.remove_tab(tab)
var control = get_child(tab)
remove_child(control)
control.free()
current_tab = -1
if $Tabs.get_tab_count() == 0:
emit_signal("no_more_tabs")
else:
set_current_tab(0)
func move_active_tab_to(idx_to):
$Tabs.move_tab(current_tab, idx_to)
move_child(get_child(current_tab), idx_to)
set_current_tab(idx_to)
func set_current_tab(t):
if t == current_tab:
return
var node
if current_tab >= 0 && current_tab < $Tabs.get_tab_count():
node = get_child(current_tab)
node.visible = false
current_tab = t
if current_tab >= 0 && current_tab < $Tabs.get_tab_count():
node = get_child(current_tab)
node.visible = true
node.rect_position = Vector2(0, $Tabs.rect_size.y)
node.rect_size = rect_size - node.rect_position
else:
print("Incorrect current tab "+str(current_tab))
$Tabs.current_tab = current_tab
emit_signal("tab_changed", current_tab)
func set_tab_title(index, title):
$Tabs.set_tab_title(index, title)
func get_current_tab_control():
return get_child(current_tab)
func _on_Tabs_tab_changed(tab):
set_current_tab(tab)
func _on_Projects_resized():
$Tabs.rect_size.x = rect_size.x