]> Untitled Git - wolf-seeking-sheep.git/blob - addons/dialogic/Editor/CharacterEditor/char_edit_p_section_main.gd
Updated export config options
[wolf-seeking-sheep.git] / addons / dialogic / Editor / CharacterEditor / char_edit_p_section_main.gd
1 @tool
2 extends DialogicCharacterEditorPortraitSection
3
4 ## Tab that allows setting a custom scene for a portrait.
5
6 func _get_title() -> String:
7         return "Scene"
8
9 func _init() -> void:
10         hint_text = "You can use a custom scene for this portrait."
11
12 func _start_opened() -> bool:
13         return true
14
15 func _ready() -> void:
16         %ChangeSceneButton.icon = get_theme_icon("Loop", "EditorIcons")
17         %ScenePicker.file_filter = "*.tscn, *.scn; Scenes"
18         %ScenePicker.resource_icon = get_theme_icon('PackedScene', 'EditorIcons')
19         %ScenePicker.placeholder = 'Default scene'
20
21         %OpenSceneButton.icon = get_theme_icon("ExternalLink", "EditorIcons")
22
23
24 func _load_portrait_data(data:Dictionary) -> void:
25         reload_ui(data)
26
27
28 func _on_open_scene_button_pressed() -> void:
29         var data: Dictionary = selected_item.get_metadata(0)
30         if ResourceLoader.exists(data.get("scene", "")):
31                 DialogicUtil.get_dialogic_plugin().get_editor_interface().open_scene_from_path(data.get("scene", ""))
32                 await get_tree().process_frame
33                 EditorInterface.set_main_screen_editor("2D")
34
35
36 func _on_change_scene_button_pressed() -> void:
37         %PortraitSceneBrowserWindow.popup_centered_ratio(0.6)
38
39
40 func _on_portrait_scene_browser_activate_part(part_info: Dictionary) -> void:
41         %PortraitSceneBrowserWindow.hide()
42         match part_info.type:
43                 "General":
44                         set_scene_path(part_info.path)
45                 "Preset":
46                         find_parent("EditorView").godot_file_dialog(
47                                 create_new_portrait_scene.bind(part_info),
48                                 '*.tscn,*.scn',
49                                 EditorFileDialog.FILE_MODE_SAVE_FILE,
50                                 "Select where to save the new scene",
51                                 part_info.path.get_file().trim_suffix("."+part_info.path.get_extension())+"_"+character_editor.current_resource.get_character_name().to_lower())
52                 "Custom":
53                         find_parent("EditorView").godot_file_dialog(
54                                 set_scene_path,
55                                 '*.tscn, *.scn',
56                                 EditorFileDialog.FILE_MODE_OPEN_FILE,
57                                 "Select custom portrait scene",)
58                 "Default":
59                         set_scene_path("")
60
61
62 func create_new_portrait_scene(target_file: String, info: Dictionary) -> void:
63         var path := make_portrait_preset_custom(target_file, info)
64         set_scene_path(path)
65
66
67 func make_portrait_preset_custom(target_file:String, info: Dictionary) -> String:
68         var previous_file: String = info.path
69
70         var result_path := DialogicUtil.make_file_custom(previous_file, target_file.get_base_dir(), target_file.get_file())
71
72         return result_path
73
74
75 func set_scene_path(path:String) -> void:
76         var data: Dictionary = selected_item.get_metadata(0)
77         data['scene'] = path
78         update_preview.emit()
79         changed.emit()
80         reload_ui(data)
81
82
83 func reload_ui(data: Dictionary) -> void:
84         var path: String = data.get('scene', '')
85         %OpenSceneButton.hide()
86
87         if path.is_empty():
88                 %SceneLabel.text = "Default Portrait Scene"
89                 %SceneLabel.tooltip_text = "Can be changed in the settings."
90                 %SceneLabel.add_theme_color_override("font_color", get_theme_color("readonly_color", "Editor"))
91
92         elif %PortraitSceneBrowser.is_premade_portrait_scene(path):
93                 %SceneLabel.text = %PortraitSceneBrowser.portrait_scenes_info[path].name
94                 %SceneLabel.tooltip_text = path
95                 %SceneLabel.add_theme_color_override("font_color", get_theme_color("accent_color", "Editor"))
96
97         else:
98                 %SceneLabel.text = path.get_file()
99                 %SceneLabel.tooltip_text = path
100                 %SceneLabel.add_theme_color_override("font_color", get_theme_color("property_color_x", "Editor"))
101                 %OpenSceneButton.show()