mirror of
https://github.com/Relintai/material-maker.git
synced 2024-11-13 06:27:18 +01:00
Added hierarchy pane
This commit is contained in:
parent
6148004b45
commit
8283c744d3
@ -7,6 +7,7 @@ Base class for texture generators, that defines their API
|
||||
"""
|
||||
|
||||
signal parameter_changed
|
||||
signal output_changed(index)
|
||||
|
||||
class InputPort:
|
||||
var generator : MMGenBase = null
|
||||
@ -49,6 +50,9 @@ func can_be_deleted() -> bool:
|
||||
func toggle_editable() -> bool:
|
||||
return false
|
||||
|
||||
func is_template() -> bool:
|
||||
return model != null
|
||||
|
||||
func is_editable() -> bool:
|
||||
return false
|
||||
|
||||
@ -117,6 +121,7 @@ func notify_output_change(output_index : int) -> void:
|
||||
var targets = get_targets(output_index)
|
||||
for target in targets:
|
||||
target.generator.source_changed(target.input_index)
|
||||
emit_signal("output_changed", output_index)
|
||||
|
||||
func source_changed(__) -> void:
|
||||
emit_signal("parameter_changed", "__input_changed__", 0)
|
||||
|
@ -16,6 +16,7 @@ onready var layout = $VBoxContainer/Layout
|
||||
var library
|
||||
var preview_2d
|
||||
var preview_3d
|
||||
var hierarchy
|
||||
|
||||
onready var preview_2d_background = $VBoxContainer/Layout/SplitRight/ProjectsPane/Preview2D
|
||||
onready var preview_2d_background_button = $VBoxContainer/Layout/SplitRight/ProjectsPane/PreviewUI/Preview2DButton
|
||||
@ -130,6 +131,8 @@ func _ready() -> void:
|
||||
library = layout.get_pane("Library")
|
||||
preview_2d = layout.get_pane("Preview2D")
|
||||
preview_3d = layout.get_pane("Preview3D")
|
||||
hierarchy = layout.get_pane("Hierarchy")
|
||||
hierarchy.connect("group_selected", self, "on_group_selected")
|
||||
|
||||
# Load recent projects
|
||||
load_recents()
|
||||
@ -521,6 +524,7 @@ func _on_PopupMenu_id_pressed(id) -> void:
|
||||
# Preview
|
||||
|
||||
func update_preview() -> void:
|
||||
hierarchy.update_from_graph_edit(get_current_graph_edit())
|
||||
var status
|
||||
need_update = true
|
||||
if updating:
|
||||
@ -587,6 +591,11 @@ func _on_Projects_tab_changed(tab) -> void:
|
||||
current_tab = new_tab
|
||||
update_preview()
|
||||
|
||||
func on_group_selected(generator) -> void:
|
||||
var graph_edit : MMGraphEdit = get_current_graph_edit()
|
||||
if graph_edit != null:
|
||||
graph_edit.edit_subgraph(generator)
|
||||
|
||||
func _exit_tree() -> void:
|
||||
# Save the window position and size to remember it when restarting the application
|
||||
config_cache.set_value("window", "screen", OS.current_screen)
|
||||
|
@ -9,7 +9,8 @@ const PANE_POSITIONS = {
|
||||
const PANES = [
|
||||
{ name="Library", scene=preload("res://material_maker/library.tscn"), position="TopLeft" },
|
||||
{ name="Preview2D", scene=preload("res://material_maker/preview/preview_2d_panel.tscn"), position="BottomLeft" },
|
||||
{ name="Preview3D", scene=preload("res://material_maker/preview/preview_3d_panel.tscn"), position="BottomLeft" }
|
||||
{ name="Preview3D", scene=preload("res://material_maker/preview/preview_3d_panel.tscn"), position="BottomLeft" },
|
||||
{ name="Hierarchy", scene=preload("res://material_maker/widgets/graph_tree/hierarchy_pane.tscn"), position="TopRight" }
|
||||
]
|
||||
|
||||
var panes = {}
|
||||
|
57
material_maker/widgets/graph_tree/hierarchy_pane.gd
Normal file
57
material_maker/widgets/graph_tree/hierarchy_pane.gd
Normal file
@ -0,0 +1,57 @@
|
||||
extends Tree
|
||||
|
||||
signal group_selected
|
||||
|
||||
func update_from_graph_edit(graph_edit) -> void:
|
||||
set_column_expand(0, true)
|
||||
# columns = 4
|
||||
# for i in range(1, 4):
|
||||
# set_column_expand(i, false)
|
||||
# set_column_min_width(i, 24)
|
||||
if graph_edit == null:
|
||||
return
|
||||
var file_name = "PTex"
|
||||
if graph_edit.save_path != null:
|
||||
file_name = graph_edit.save_path.get_file()
|
||||
fill_tree(graph_edit.top_generator, graph_edit.generator, file_name)
|
||||
|
||||
func fill_tree(top : MMGenGraph, selected : MMGenGraph, top_name : String) -> void:
|
||||
clear()
|
||||
if top == null or selected == null:
|
||||
return
|
||||
var root : TreeItem = create_item(null)
|
||||
root.set_text(0, top_name)
|
||||
if top == selected:
|
||||
root.set_custom_color(0, Color(0.5, 0.5, 1))
|
||||
else:
|
||||
root.set_custom_color(0, Color(1, 1, 1))
|
||||
root.set_metadata(0, top)
|
||||
fill_item(root, top, selected)
|
||||
|
||||
#func set_icon(item, generator):
|
||||
# var result = generator.render(0, 24, true)
|
||||
# while result is GDScriptFunctionState:
|
||||
# result = yield(result, "completed")
|
||||
# var tex = ImageTexture.new()
|
||||
# result.copy_to_texture(tex)
|
||||
# result.release()
|
||||
# item.set_icon(3, tex)
|
||||
|
||||
func fill_item(parent : TreeItem, generator : MMGenGraph, selected : MMGenGraph) -> void:
|
||||
for c in generator.get_children():
|
||||
if c is MMGenGraph:
|
||||
if c.is_template():
|
||||
continue
|
||||
var item : TreeItem = create_item(parent)
|
||||
item.set_text(0, c.get_type_name())
|
||||
if c == selected:
|
||||
item.set_custom_color(0, Color(0.5, 0.5, 1))
|
||||
elif c.is_editable():
|
||||
item.set_custom_color(0, Color(1, 1, 1))
|
||||
item.set_metadata(0, c)
|
||||
# if c.get_output_defs().size() > 0:
|
||||
# call_deferred("set_icon", item, c)
|
||||
fill_item(item, c, selected)
|
||||
|
||||
func _on_Hierarchy_item_double_clicked():
|
||||
emit_signal("group_selected", get_selected().get_metadata(0))
|
15
material_maker/widgets/graph_tree/hierarchy_pane.tscn
Normal file
15
material_maker/widgets/graph_tree/hierarchy_pane.tscn
Normal file
@ -0,0 +1,15 @@
|
||||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://material_maker/widgets/graph_tree/hierarchy_pane.gd" type="Script" id=1]
|
||||
|
||||
[node name="Hierarchy" type="Tree"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
rect_min_size = Vector2( 200, 150 )
|
||||
allow_reselect = true
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
[connection signal="item_activated" from="." to="." method="_on_Hierarchy_item_double_clicked"]
|
||||
[connection signal="item_double_clicked" from="." to="." method="_on_Hierarchy_item_double_clicked"]
|
Loading…
Reference in New Issue
Block a user