2 extends DialogicCharacterEditorMainSection
4 ## Character editor section that allows editing typing sound moods.
7 var current_moods_info := {}
12 hint_text = 'Typing sound moods allow you to vary the "typing" sounds of your character. \nThey can be changed based on the portrait or with the [mood=something] text effect.'
15 func _get_title() -> String:
16 return "Typing Sounds"
18 ################################################################################
19 ## COMMUNICATION WITH EDITOR
20 ################################################################################
22 func _load_character(character:DialogicCharacter):
23 default_mood = character.custom_info.get('sound_mood_default', '')
25 current_moods_info = character.custom_info.get('sound_moods', {}).duplicate(true)
31 func _save_changes(character:DialogicCharacter) -> DialogicCharacter:
32 # Quickly save latest mood
34 current_moods_info[current_mood] = get_mood_info()
36 character.custom_info['sound_mood_default'] = default_mood
37 character.custom_info['sound_moods'] = current_moods_info.duplicate(true)
41 func get_portrait_data() -> Dictionary:
42 if character_editor.selected_item and is_instance_valid(character_editor.selected_item):
43 return character_editor.selected_item.get_metadata(0)
47 func set_portrait_data(data:Dictionary) -> void:
48 if character_editor.selected_item and is_instance_valid(character_editor.selected_item):
49 character_editor.selected_item.set_metadata(0, data)
52 ################################################################################
54 ################################################################################
56 func _ready() -> void:
57 %ListPanel.self_modulate = get_theme_color("base_color", "Editor")
58 %Add.icon = get_theme_icon("Add", "EditorIcons")
59 %Delete.icon = get_theme_icon("Remove", "EditorIcons")
60 %Duplicate.icon = get_theme_icon("Duplicate", "EditorIcons")
61 %Play.icon = get_theme_icon("Play", "EditorIcons")
62 %Default.icon = get_theme_icon("NonFavorite", "EditorIcons")
64 %NameWarning.texture = get_theme_icon("StatusWarning", "EditorIcons")
67 func update_mood_list(selected_name := "") -> void:
70 for mood in current_moods_info:
71 var idx: int = %MoodList.add_item(mood, get_theme_icon("AudioStreamPlayer", "EditorIcons"))
72 if mood == selected_name:
74 _on_mood_list_item_selected(idx)
75 if !%MoodList.is_anything_selected() and %MoodList.item_count:
77 _on_mood_list_item_selected(0)
79 if %MoodList.item_count == 0:
82 %Delete.disabled = !%MoodList.is_anything_selected()
83 %Play.disabled = !%MoodList.is_anything_selected()
84 %Duplicate.disabled = !%MoodList.is_anything_selected()
85 %Default.disabled = !%MoodList.is_anything_selected()
86 %Settings.visible = %MoodList.is_anything_selected()
88 %MoodList.custom_minimum_size.y = min(%MoodList.item_count*45, 100)
89 %MoodList.visible = %MoodList.item_count != 0
91 character_editor.get_settings_section_by_name('Typing Sound Mood', false).update_visibility(%MoodList.item_count != 0)
95 func _input(event:InputEvent) -> void:
96 if !is_visible_in_tree() or (get_viewport().gui_get_focus_owner() and !name+'/' in str(get_viewport().gui_get_focus_owner().get_path())):
98 if event is InputEventKey and event.keycode == KEY_F2 and event.pressed:
99 if %MoodList.is_anything_selected():
102 get_viewport().set_input_as_handled()
105 func _on_mood_list_item_selected(index:int) -> void:
107 current_moods_info[current_mood] = get_mood_info()
109 current_mood = %MoodList.get_item_text(index)
110 load_mood_info(current_moods_info[current_mood])
112 %Delete.disabled = !%MoodList.is_anything_selected()
113 %Play.disabled = !%MoodList.is_anything_selected()
114 %Duplicate.disabled = !%MoodList.is_anything_selected()
115 %Default.disabled = !%MoodList.is_anything_selected()
116 %Settings.visible = %MoodList.is_anything_selected()
119 func load_mood_info(dict:Dictionary) -> void:
120 %Name.text = dict.get('name', '')
122 set_default_button(default_mood == dict.get('name', ''))
123 %SoundFolder.set_value(dict.get('sound_path', ''))
124 %Mode.select(dict.get('mode', 0))
125 %PitchBase.set_value(dict.get('pitch_base', 1))
126 %PitchVariance.set_value(dict.get('pitch_variance', 0))
127 %VolumeBase.set_value(dict.get('volume_base', 0))
128 %VolumeVariance.set_value(dict.get('volume_variance', 0))
129 %Skip.set_value(dict.get('skip_characters', 0))
132 func get_mood_info() -> Dictionary:
134 dict['name'] = %Name.text
135 dict['sound_path'] = %SoundFolder.current_value
136 dict['mode'] = %Mode.selected
137 dict['pitch_base'] = %PitchBase.value
138 dict['pitch_variance'] = %PitchVariance.value
139 dict['volume_base'] = %VolumeBase.value
140 dict['volume_variance'] = %VolumeVariance.value
141 dict['skip_characters'] = %Skip.value
145 func _on_add_pressed() -> void:
146 if !current_mood.is_empty():
147 current_moods_info[current_mood] = get_mood_info()
149 var new_name := 'Mood '
151 while new_name+str(counter) in current_moods_info:
153 new_name += str(counter)
155 current_moods_info[new_name] = {'name':new_name}
157 update_mood_list(new_name)
160 func _on_duplicate_pressed() -> void:
161 if !current_mood.is_empty():
162 current_moods_info[current_mood] = get_mood_info()
164 current_moods_info[current_mood+"_copy"] = get_mood_info()
165 current_moods_info[current_mood+"_copy"].name = current_mood+"_copy"
166 update_mood_list(current_mood+"_copy")
169 func _on_delete_pressed() -> void:
170 if current_mood.is_empty():
172 current_moods_info.erase(current_mood)
177 func _on_name_text_changed(new_text:String) -> void:
178 if new_text.is_empty():
180 %NameWarning.tooltip_text = "Name cannot be empty!"
181 elif new_text in current_moods_info and new_text != current_mood:
183 %NameWarning.tooltip_text = "Name is already in use!"
188 func _on_name_text_submitted(new_text:String) -> void:
189 if %NameWarning.visible:
190 new_text = current_mood
193 %MoodList.set_item_text(%MoodList.get_selected_items()[0], new_text)
194 current_moods_info.erase(current_mood)
195 current_moods_info[new_text] = get_mood_info()
196 current_mood = new_text
199 func _on_name_focus_exited() -> void:
200 _on_name_text_submitted(%Name.text)
203 func _on_default_toggled(button_pressed:bool) -> void:
205 default_mood = current_mood
208 set_default_button(button_pressed)
211 func set_default_button(enabled:bool) -> void:
212 %Default.set_pressed_no_signal(enabled)
214 %Default.icon = get_theme_icon("Favorites", "EditorIcons")
216 %Default.icon = get_theme_icon("NonFavorite", "EditorIcons")
219 func preview() -> void:
220 $Preview.load_overwrite(get_mood_info())
221 var preview_timer := Timer.new()
222 DialogicUtil.update_timer_process_callback(preview_timer)
223 add_child(preview_timer)
224 preview_timer.start(ProjectSettings.get_setting('dialogic/text/letter_speed', 0.01))
227 $Preview._on_continued_revealing_text("a")
228 await preview_timer.timeout
230 preview_timer.queue_free()