]> Untitled Git - wolf-seeking-sheep.git/blob - addons/dialogic/Editor/CharacterEditor/portrait_scene_browser.gd
Initial Godot project with Dialogic 2.0-Alpha-17
[wolf-seeking-sheep.git] / addons / dialogic / Editor / CharacterEditor / portrait_scene_browser.gd
1 @tool
2 extends Control
3
4 var ListItem := load("res://addons/dialogic/Editor/Common/BrowserItem.tscn")
5
6 enum Types {ALL, GENERAL, PRESET}
7 var current_type := Types.ALL
8 var current_info := {}
9
10 var portrait_scenes_info := {}
11
12 signal activate_part(part_info:Dictionary)
13
14
15 func _ready() -> void:
16         collect_portrait_scenes()
17
18         %Search.right_icon = get_theme_icon("Search", "EditorIcons")
19         %CloseButton.icon = get_theme_icon("Close", "EditorIcons")
20
21         get_parent().close_requested.connect(_on_close_button_pressed)
22         get_parent().visibility_changed.connect(func():if get_parent().visible: open())
23
24
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
29
30
31 func open() -> void:
32         collect_portrait_scenes()
33         load_parts()
34
35
36 func is_premade_portrait_scene(scene_path:String) -> bool:
37         return scene_path in portrait_scenes_info
38
39
40 func load_parts() -> void:
41         for i in %PartGrid.get_children():
42                 i.queue_free()
43
44         %Search.placeholder_text = "Search for "
45         %Search.text = ""
46         match current_type:
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"
50
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"):
54                         continue
55
56                 var item: Node = ListItem.instantiate()
57                 item.load_info(info)
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))
63
64         await get_tree().process_frame
65
66         if %PartGrid.get_child_count() > 0:
67                 %PartGrid.get_child(0).clicked.emit()
68                 %PartGrid.get_child(0).grab_focus()
69
70
71 func _on_item_clicked(item: Node, info:Dictionary) -> void:
72         load_part_info(info)
73
74
75 func load_part_info(info:Dictionary) -> void:
76         current_info = info
77         %PartTitle.text = info.get('name', 'Unknown Part')
78         %PartAuthor.text = "by "+info.get('author', 'Anonymus')
79         %PartDescription.text = info.get('description', '')
80
81         if info.get('preview_image', null) and ResourceLoader.exists(info.preview_image[0]):
82                 %PreviewImage.texture = load(info.preview_image[0])
83                 %PreviewImage.show()
84         else:
85                 %PreviewImage.hide()
86
87         match info.type:
88                 "General":
89                         %ActivateButton.text = "Use this scene"
90                         %TypeDescription.text = "This is a general use scene, it can be used directly."
91                 "Preset":
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."
94                 "Default":
95                         %ActivateButton.text = "Use default scene"
96                         %TypeDescription.text = ""
97                 "Custom":
98                         %ActivateButton.text = "Select a custom scene"
99                         %TypeDescription.text = ""
100
101         if info.get("documentation", ""):
102                 %DocumentationButton.show()
103                 %DocumentationButton.uri = info.documentation
104         else:
105                 %DocumentationButton.hide()
106
107
108 func _on_activate_button_pressed() -> void:
109         activate_part.emit(current_info)
110
111
112 func _on_close_button_pressed() -> void:
113         get_parent().hide()
114
115
116 func _on_search_text_changed(new_text: String) -> void:
117         for item in %PartGrid.get_children():
118                 if new_text.is_empty():
119                         item.show()
120                         continue
121
122                 if new_text.to_lower() in item.get_meta('info').name.to_lower():
123                         item.show()
124                         continue
125
126                 item.hide()