4 var ListItem := load("res://addons/dialogic/Editor/Common/BrowserItem.tscn")
6 enum Types {ALL, GENERAL, PRESET}
7 var current_type := Types.ALL
10 var portrait_scenes_info := {}
12 signal activate_part(part_info:Dictionary)
15 func _ready() -> void:
16 collect_portrait_scenes()
18 %Search.right_icon = get_theme_icon("Search", "EditorIcons")
19 %CloseButton.icon = get_theme_icon("Close", "EditorIcons")
21 get_parent().close_requested.connect(_on_close_button_pressed)
22 get_parent().visibility_changed.connect(func():if get_parent().visible: open())
25 func collect_portrait_scenes() -> void:
26 for indexer in DialogicUtil.get_indexers():
27 for element in indexer._get_portrait_scene_presets():
28 portrait_scenes_info[element.get('path', '')] = element
32 collect_portrait_scenes()
36 func is_premade_portrait_scene(scene_path:String) -> bool:
37 return scene_path in portrait_scenes_info
40 func load_parts() -> void:
41 for i in %PartGrid.get_children():
44 %Search.placeholder_text = "Search for "
47 Types.GENERAL: %Search.placeholder_text += "general portrait scenes"
48 Types.PRESET: %Search.placeholder_text += "portrait scene presets"
49 Types.ALL: %Search.placeholder_text += "general portrait scenes and presets"
51 for info in portrait_scenes_info.values():
52 var type: String = info.get('type', '_')
53 if (current_type == Types.GENERAL and type != "General") or (current_type == Types.PRESET and type != "Preset"):
56 var item: Node = ListItem.instantiate()
58 %PartGrid.add_child(item)
59 item.set_meta('info', info)
60 item.clicked.connect(_on_item_clicked.bind(item, info))
61 item.focused.connect(_on_item_clicked.bind(item, info))
62 item.double_clicked.connect(emit_signal.bind('activate_part', info))
64 await get_tree().process_frame
66 if %PartGrid.get_child_count() > 0:
67 %PartGrid.get_child(0).clicked.emit()
68 %PartGrid.get_child(0).grab_focus()
71 func _on_item_clicked(item: Node, info:Dictionary) -> void:
75 func load_part_info(info:Dictionary) -> void:
77 %PartTitle.text = info.get('name', 'Unknown Part')
78 %PartAuthor.text = "by "+info.get('author', 'Anonymus')
79 %PartDescription.text = info.get('description', '')
81 if info.get('preview_image', null) and ResourceLoader.exists(info.preview_image[0]):
82 %PreviewImage.texture = load(info.preview_image[0])
89 %ActivateButton.text = "Use this scene"
90 %TypeDescription.text = "This is a general use scene, it can be used directly."
92 %ActivateButton.text = "Customize this scene"
93 %TypeDescription.text = "This is a preset you can use for a custom portrait scene. Dialogic will promt you to save a copy of this scene that you can then use and customize."
95 %ActivateButton.text = "Use default scene"
96 %TypeDescription.text = ""
98 %ActivateButton.text = "Select a custom scene"
99 %TypeDescription.text = ""
101 if info.get("documentation", ""):
102 %DocumentationButton.show()
103 %DocumentationButton.uri = info.documentation
105 %DocumentationButton.hide()
108 func _on_activate_button_pressed() -> void:
109 activate_part.emit(current_info)
112 func _on_close_button_pressed() -> void:
116 func _on_search_text_changed(new_text: String) -> void:
117 for item in %PartGrid.get_children():
118 if new_text.is_empty():
122 if new_text.to_lower() in item.get_meta('info').name.to_lower():