]> Untitled Git - wolf-seeking-sheep.git/blob - addons/dialogic/Modules/DefaultLayoutParts/Layer_VN_Textbox/vn_textbox_layer.gd
Adding import files
[wolf-seeking-sheep.git] / addons / dialogic / Modules / DefaultLayoutParts / Layer_VN_Textbox / vn_textbox_layer.gd
1 @tool
2 extends DialogicLayoutLayer
3 ## This layer's scene file contains following nodes:
4 ## - a dialog_text node
5 ## - a name_label node
6 ## - a next_indicator node
7 ## - a type_sound node
8 ##
9 ## As well as custom:
10 ## - animations
11 ## - auto-advance progress indicator
12 ##
13 ## If you want to customize this layer, here is a little rundown of this layer:
14 ## The Layer Settings are divided into the `@export_group`s below.
15 ## They get applied in [method _apply_export_overrides].
16 ## Each `@export_group` has its own method to apply the settings to the scene.
17 ## If you want to change a specific part inside the scene, you can simply
18 ## remove or add # (commenting) to the method line.
19
20
21
22 enum Alignments {LEFT, CENTER, RIGHT}
23
24 enum AnimationsIn {NONE, POP_IN, FADE_UP}
25 enum AnimationsOut {NONE, POP_OUT, FADE_DOWN}
26 enum AnimationsNewText {NONE, WIGGLE}
27
28 @export_group("Text")
29
30 @export_subgroup("Alignment & Size")
31 @export var text_alignment: Alignments= Alignments.LEFT
32 @export var text_use_global_size: bool = true
33 @export var text_size: int = 15
34
35 @export_subgroup("Color")
36 @export var text_use_global_color: bool = true
37 @export var text_custom_color: Color = Color.WHITE
38
39 @export_subgroup('Font')
40 @export var text_use_global_font: bool = true
41 @export_file('*.ttf', '*.tres') var normal_font: String = ""
42 @export_file('*.ttf', '*.tres') var bold_font: String = ""
43 @export_file('*.ttf', '*.tres') var italics_font: String = ""
44 @export_file('*.ttf', '*.tres') var bold_italics_font: String = ""
45
46
47 @export_group("Box")
48
49 @export_subgroup("Panel")
50 @export_file("*.tres") var box_panel: String = this_folder.path_join("vn_textbox_default_panel.tres")
51
52 @export_subgroup("Color")
53 @export var box_color_use_global: bool = true
54 @export var box_color_custom: Color = Color.BLACK
55
56 @export_subgroup("Size & Position")
57 @export var box_size: Vector2 = Vector2(550, 110)
58 @export var box_margin_bottom: int = 15
59
60 @export_subgroup("Animation")
61 @export var box_animation_in: AnimationsIn = AnimationsIn.FADE_UP
62 @export var box_animation_out: AnimationsOut = AnimationsOut.FADE_DOWN
63 @export var box_animation_new_text: AnimationsNewText = AnimationsNewText.NONE
64
65
66 @export_group("Name Label")
67
68 @export_subgroup('Color')
69 @export var name_label_use_global_color: bool= true
70 @export var name_label_use_character_color: bool = true
71 @export var name_label_custom_color: Color = Color.WHITE
72
73 @export_subgroup('Font')
74 @export var name_label_use_global_font: bool = true
75 @export_file('*.ttf', '*.tres') var name_label_font: String = ""
76 @export var name_label_use_global_font_size: bool = true
77 @export var name_label_custom_font_size: int = 15
78
79 @export_subgroup('Box')
80 @export_file("*.tres") var name_label_box_panel: String = this_folder.path_join("vn_textbox_name_label_panel.tres")
81 @export var name_label_box_use_global_color: bool = true
82 @export var name_label_box_modulate: Color = box_color_custom
83
84 @export_subgroup('Alignment')
85 @export var name_label_alignment: Alignments = Alignments.LEFT
86 @export var name_label_box_offset: Vector2 = Vector2.ZERO
87
88
89 @export_group("Indicators")
90
91 @export_subgroup("Next Indicator")
92 @export var next_indicator_enabled: bool = true
93 @export var next_indicator_show_on_questions: bool = true
94 @export var next_indicator_show_on_autoadvance: bool = false
95 @export_enum('bounce', 'blink', 'none') var next_indicator_animation: int = 0
96 @export_file("*.png","*.svg","*.tres") var next_indicator_texture: String = ''
97 @export var next_indicator_size: Vector2 = Vector2(25,25)
98
99 @export_subgroup("Autoadvance")
100 @export var autoadvance_progressbar: bool = true
101
102
103 @export_group('Sounds')
104
105 @export_subgroup('Typing Sounds')
106 @export var typing_sounds_enabled: bool = true
107 @export var typing_sounds_mode: DialogicNode_TypeSounds.Modes = DialogicNode_TypeSounds.Modes.INTERRUPT
108 @export_dir var typing_sounds_sounds_folder: String = "res://addons/dialogic/Example Assets/sound-effects/"
109 @export_file("*.wav", "*.ogg", "*.mp3") var typing_sounds_end_sound: String = ""
110 @export_range(1, 999, 1) var typing_sounds_every_nths_character: int = 1
111 @export_range(0.01, 4, 0.01) var typing_sounds_pitch: float = 1.0
112 @export_range(0.0, 3.0) var typing_sounds_pitch_variance: float = 0.0
113 @export_range(-80, 24, 0.01) var typing_sounds_volume: float = -10
114 @export_range(0.0, 10) var typing_sounds_volume_variance: float = 0.0
115 @export var typing_sounds_ignore_characters: String = " .,!?"
116
117
118 func _apply_export_overrides() -> void:
119         if !is_inside_tree():
120                 await ready
121
122         ## FONT SETTINGS
123         _apply_text_settings()
124
125
126         ## BOX SETTINGS
127         _apply_box_settings()
128
129         ## BOX ANIMATIONS
130         _apply_box_animations_settings()
131
132         ## NAME LABEL SETTINGS
133         _apply_name_label_settings()
134
135         ## NEXT INDICATOR SETTINGS
136         _apply_indicator_settings()
137
138         ## OTHER
139         var progress_bar: ProgressBar = %AutoAdvanceProgressbar
140         progress_bar.set(&'enabled', autoadvance_progressbar)
141
142         #### SOUNDS
143
144         ## TYPING SOUNDS
145         _apply_sounds_settings()
146
147
148 ## Applies all text box settings to the scene.
149 ## Except the box animations.
150 func _apply_box_settings() -> void:
151         var dialog_text_panel: PanelContainer = %DialogTextPanel
152         if ResourceLoader.exists(box_panel):
153                 dialog_text_panel.add_theme_stylebox_override(&'panel', load(box_panel) as StyleBox)
154
155         if box_color_use_global:
156                 dialog_text_panel.self_modulate = get_global_setting(&'bg_color', box_color_custom)
157         else:
158                 dialog_text_panel.self_modulate = box_color_custom
159
160         var sizer: Control = %Sizer
161         sizer.size = box_size
162         sizer.position = box_size * Vector2(-0.5, -1)+Vector2(0, -box_margin_bottom)
163
164
165 ## Applies box animations settings to the scene.
166 func _apply_box_animations_settings() -> void:
167         var animations: AnimationPlayer = %Animations
168         animations.set(&'animation_in', box_animation_in)
169         animations.set(&'animation_out', box_animation_out)
170         animations.set(&'animation_new_text', box_animation_new_text)
171
172
173 ## Applies all name label settings to the scene.
174 func _apply_name_label_settings() -> void:
175         var name_label: DialogicNode_NameLabel = %DialogicNode_NameLabel
176
177         if name_label_use_global_font_size:
178                 name_label.add_theme_font_size_override(&"font_size", get_global_setting(&'font_size', name_label_custom_font_size) as int)
179         else:
180                 name_label.add_theme_font_size_override(&"font_size", name_label_custom_font_size)
181
182         if name_label_use_global_font and get_global_setting(&'font', false):
183                 name_label.add_theme_font_override(&'font', load(get_global_setting(&'font', '') as String) as Font)
184         elif not name_label_font.is_empty():
185                 name_label.add_theme_font_override(&'font', load(name_label_font) as Font)
186
187         if name_label_use_global_color:
188                 name_label.add_theme_color_override(&"font_color", get_global_setting(&'font_color', name_label_custom_color) as Color)
189         else:
190                 name_label.add_theme_color_override(&"font_color", name_label_custom_color)
191
192         name_label.use_character_color = name_label_use_character_color
193
194         var name_label_panel: PanelContainer = %NameLabelPanel
195         if ResourceLoader.exists(name_label_box_panel):
196                 name_label_panel.add_theme_stylebox_override(&'panel', load(name_label_box_panel) as StyleBox)
197         else:
198                 name_label_panel.add_theme_stylebox_override(&'panel', load(this_folder.path_join("vn_textbox_name_label_panel.tres")) as StyleBox)
199
200         if name_label_box_use_global_color:
201                 name_label_panel.self_modulate = get_global_setting(&'bg_color', name_label_box_modulate)
202         else:
203                 name_label_panel.self_modulate = name_label_box_modulate
204         var dialog_text_panel: PanelContainer = %DialogTextPanel
205         name_label_panel.position = name_label_box_offset+Vector2(0, -40)
206         name_label_panel.position -= Vector2(
207                 dialog_text_panel.get_theme_stylebox(&'panel', &'PanelContainer').content_margin_left,
208                 dialog_text_panel.get_theme_stylebox(&'panel', &'PanelContainer').content_margin_top)
209         name_label_panel.anchor_left = name_label_alignment/2.0
210         name_label_panel.anchor_right = name_label_alignment/2.0
211         name_label_panel.grow_horizontal = [1, 2, 0][name_label_alignment]
212
213
214 ## Applies all text settings to the scene.
215 func _apply_text_settings() -> void:
216         var dialog_text: DialogicNode_DialogText = %DialogicNode_DialogText
217         dialog_text.alignment = text_alignment as DialogicNode_DialogText.Alignment
218
219         if text_use_global_size:
220                 text_size = get_global_setting(&'font_size', text_size)
221         dialog_text.add_theme_font_size_override(&"normal_font_size", text_size)
222         dialog_text.add_theme_font_size_override(&"bold_font_size", text_size)
223         dialog_text.add_theme_font_size_override(&"italics_font_size", text_size)
224         dialog_text.add_theme_font_size_override(&"bold_italics_font_size", text_size)
225
226         if text_use_global_color:
227                 dialog_text.add_theme_color_override(&"default_color", get_global_setting(&'font_color', text_custom_color) as Color)
228         else:
229                 dialog_text.add_theme_color_override(&"default_color", text_custom_color)
230
231         if text_use_global_font and get_global_setting(&'font', false):
232                 dialog_text.add_theme_font_override(&"normal_font", load(get_global_setting(&'font', '') as String) as Font)
233         elif !normal_font.is_empty():
234                 dialog_text.add_theme_font_override(&"normal_font", load(normal_font) as Font)
235         if !bold_font.is_empty():
236                 dialog_text.add_theme_font_override(&"bold_font", load(bold_font) as Font)
237         if !italics_font.is_empty():
238                 dialog_text.add_theme_font_override(&"italics_font", load(italics_font) as Font)
239         if !bold_italics_font.is_empty():
240                 dialog_text.add_theme_font_override(&"bold_italics_font", load(bold_italics_font) as Font)
241
242
243 ## Applies all indicator settings to the scene.
244 func _apply_indicator_settings() -> void:
245         var next_indicator: DialogicNode_NextIndicator = %NextIndicator
246         next_indicator.enabled = next_indicator_enabled
247
248         if next_indicator_enabled:
249                 next_indicator.animation = next_indicator_animation as DialogicNode_NextIndicator.Animations
250                 if ResourceLoader.exists(next_indicator_texture):
251                         next_indicator.texture = load(next_indicator_texture)
252                 next_indicator.show_on_questions = next_indicator_show_on_questions
253                 next_indicator.show_on_autoadvance = next_indicator_show_on_autoadvance
254                 next_indicator.texture_size = next_indicator_size
255
256
257 ## Applies all sound settings to the scene.
258 func _apply_sounds_settings() -> void:
259         var type_sounds: DialogicNode_TypeSounds = %DialogicNode_TypeSounds
260         type_sounds.enabled = typing_sounds_enabled
261         type_sounds.mode = typing_sounds_mode
262
263         if not typing_sounds_sounds_folder.is_empty():
264                 type_sounds.sounds = DialogicNode_TypeSounds.load_sounds_from_path(typing_sounds_sounds_folder)
265         else:
266                 type_sounds.sounds.clear()
267
268         if not typing_sounds_end_sound.is_empty():
269                 type_sounds.end_sound = load(typing_sounds_end_sound)
270         else:
271                 type_sounds.end_sound = null
272
273         type_sounds.play_every_character = typing_sounds_every_nths_character
274         type_sounds.base_pitch = typing_sounds_pitch
275         type_sounds.base_volume = typing_sounds_volume
276         type_sounds.pitch_variance = typing_sounds_pitch_variance
277         type_sounds.volume_variance = typing_sounds_volume_variance
278         type_sounds.ignore_characters = typing_sounds_ignore_characters