Skip to content
Open
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
6 changes: 3 additions & 3 deletions material_maker/doc/user_interface_library_panel.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ give focus to the search field using the **Control+F** keyboard shortcut.
:align: center

Each item in the tree view has a context menu that can be used to rename it, redefine
its thumbnail (using the current 2D preview), or delete it. It is also possible to
define name aliases that will be used by the filter (in the library panel and in the
Nodes menu).
its thumbnail (using the current 2D preview), updated (replaced with current selection),
or delete it. It is also possible to define name aliases that will be used by the filter
(in the library panel and in the Nodes menu).
24 changes: 13 additions & 11 deletions material_maker/main_window.gd
Original file line number Diff line number Diff line change
Expand Up @@ -1048,22 +1048,24 @@ func create_menu_add_to_library(menu : MMMenuManager.MenuBase, manager, function
func create_menu_add_selection_to_library(menu : MMMenuManager.MenuBase) -> void:
create_menu_add_to_library(menu, node_library_manager, "add_selection_to_library")

func add_selection_to_library(index) -> void:
func add_selection_to_library(index: int, should_ask_item_name: bool = true) -> void:
var selected_nodes = get_selected_nodes()
if selected_nodes.is_empty():
return
var dialog = preload("res://material_maker/windows/line_dialog/line_dialog.tscn").instantiate()
dialog.content_scale_factor = mm_globals.main_window.get_window().content_scale_factor
dialog.min_size = Vector2(250, 90) * dialog.content_scale_factor
add_child(dialog)
var current_item_name = ""
var current_item_name : String = ""
if library.is_inside_tree():
current_item_name = library.get_selected_item_name()
var status = await dialog.enter_text("New library element", "Select a name for the new library element", current_item_name)
if ! status.ok:
return
if should_ask_item_name:
var dialog = preload("res://material_maker/windows/line_dialog/line_dialog.tscn").instantiate()
dialog.content_scale_factor = mm_globals.main_window.get_window().content_scale_factor
dialog.min_size = Vector2(250, 90) * dialog.content_scale_factor
add_child(dialog)
var status = await dialog.enter_text("New library element", "Select a name for the new library element", current_item_name)
if ! status.ok:
return
current_item_name = status.text
var graph_edit : MMGraphEdit = get_current_graph_edit()
var data
var data : Dictionary
if selected_nodes.size() == 1:
data = selected_nodes[0].generator.serialize()
data.erase("node_position")
Expand All @@ -1073,7 +1075,7 @@ func add_selection_to_library(index) -> void:
var result = await selected_nodes[0].generator.render(self, 0, 64, true)
var image : Image = result.get_image()
result.release(self)
node_library_manager.add_item_to_library(index, status.text, image, data)
node_library_manager.add_item_to_library(index, current_item_name, image, data)

func create_menu_add_brush_to_library(menu : MMMenuManager.MenuBase) -> void:
create_menu_add_to_library(menu, brush_library_manager, "add_brush_to_library")
Expand Down
6 changes: 4 additions & 2 deletions material_maker/panels/library/library.gd
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,11 @@ func _on_PopupMenu_index_pressed(index):
return
var image : Image = await current_node.generator.render_output(0, Vector2i(64, 64))
library_manager.update_item_icon_in_library(library_index, item_path, image)
2: # Delete item
2: # Update item
mm_globals.main_window.add_selection_to_library(library_index, false)
3: # Delete item
library_manager.remove_item_from_library(library_index, item_path)
4: # Define aliases
5: # Define aliases
var aliases = library_manager.get_aliases(item_path)
var dialog = preload("res://material_maker/windows/line_dialog/line_dialog.tscn").instantiate()
dialog.content_scale_factor = mm_globals.main_window.get_window().content_scale_factor
Expand Down
10 changes: 6 additions & 4 deletions material_maker/panels/library/library.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,19 @@ clip_text = true

[node name="ItemMenu" type="PopupMenu" parent="."]
unique_name_in_owner = true
item_count = 5
item_count = 6
item_0/text = "Rename item"
item_0/id = 0
item_1/text = "Update thumbnail"
item_1/id = 1
item_2/text = "Remove item"
item_2/text = "Update item"
item_2/id = 2
item_3/text = "Delete item"
item_3/id = 3
item_3/separator = true
item_4/text = "Define aliases"
item_4/id = 4
item_4/separator = true
item_5/text = "Define aliases"
item_5/id = 5

[connection signal="text_changed" from="Library/Filter/Filter" to="." method="_on_Filter_text_changed"]
[connection signal="about_to_popup" from="Library/Filter/Libraries" to="." method="_on_Libraries_about_to_show"]
Expand Down