@@ -12,7 +12,7 @@ var waiting_for_input = false
1212export (String ) var timeline_id # Timeline-var-replace
1313
1414var dialog_resource
15- export ( Array , Resource ) var dialog_characters
15+ var characters
1616
1717onready var Portrait = load ("res://addons/dialogic/Nodes/Portrait.tscn" )
1818var dialog_script = {}
@@ -22,12 +22,12 @@ func parse_text(text):
2222 var end_text = text
2323
2424 # for character variables
25- if '{' and '}' in end_text :
26- for c in dialog_characters : # dialog_resource.characters:
27- if c .name in end_text :
28- end_text = end_text .replace ('{' + c .name + '}' ,
29- '[color=#' + c .color .to_html () + ']' + c .name + '[/color]'
30- )
25+ # if '{' and '}' in end_text:
26+ # for c in characters : #dialog_resource.characters:
27+ # if c.name in end_text:
28+ # end_text = end_text.replace('{' + c.name + '}',
29+ # '[color=#' + c.color.to_html() + ']' + c.name + '[/color]'
30+ # )
3131
3232 var c_variable
3333 # for key in dialog_resource.custom_variables.keys():
@@ -54,31 +54,40 @@ func _ready():
5454 $ TextBubble/NameLabel .text = ''
5555 $ Background .visible = false
5656
57+ # Getting the character information
58+ characters = DialogicUtil .get_character_list ()
59+ print (characters )
60+
5761 # Loading theme properties and settings
58- var settings = DialogicUtil .load_settings ()
62+ var settings = DialogicUtil .load_settings ()
5963 if settings .has ('theme_font' ):
6064 $ TextBubble/RichTextLabel .set ('custom_fonts/normal_font' , load (settings ['theme_font' ]))
65+ $ TextBubble/NameLabel .set ('custom_fonts/normal_font' , load (settings ['theme_font' ]))
6166 # Text
6267 if settings .has ('theme_text_color' ):
6368 $ TextBubble/RichTextLabel .set ('custom_colors/default_color' , Color ('#' + str (settings ['theme_text_color' ])))
69+ $ TextBubble/NameLabel .set ('custom_colors/default_color' , Color ('#' + str (settings ['theme_text_color' ])))
6470 if settings .has ('theme_text_shadow' ):
6571 if settings ['theme_text_shadow' ]:
6672 if settings .has ('theme_text_shadow_color' ):
6773 $ TextBubble/RichTextLabel .set ('custom_colors/font_color_shadow' , Color ('#' + str (settings ['theme_text_shadow_color' ])))
74+ $ TextBubble/NameLabel .set ('custom_colors/font_color_shadow' , Color ('#' + str (settings ['theme_text_shadow_color' ])))
6875 if settings .has ('theme_shadow_offset_x' ):
6976 $ TextBubble/RichTextLabel .set ('custom_constants/shadow_offset_x' , settings ['theme_shadow_offset_x' ])
77+ $ TextBubble/NameLabel .set ('custom_constants/shadow_offset_x' , settings ['theme_shadow_offset_x' ])
7078 if settings .has ('theme_shadow_offset_y' ):
7179 $ TextBubble/RichTextLabel .set ('custom_constants/shadow_offset_y' , settings ['theme_shadow_offset_y' ])
80+ $ TextBubble/NameLabel .set ('custom_constants/shadow_offset_y' , settings ['theme_shadow_offset_y' ])
7281 # Text speed
7382 if settings .has ('theme_text_speed' ):
7483 text_speed = settings ['theme_text_speed' ] * 0.01
7584 # Margin
7685 if settings .has ('theme_text_margin' ):
77- if settings . has ( 'theme_text_margin_h' ):
78- $ TextBubble/RichTextLabel .set ('margin_left ' , settings ['theme_text_margin_h' ] )
79- $ TextBubble/RichTextLabel . set ( 'margin_top' , settings [ 'theme_text_margin' ])
80- $ TextBubble/RichTextLabel .set ('margin_right ' , settings ['theme_text_margin_h' ] * - 1 )
81- $ TextBubble/RichTextLabel .set ('margin_bottom ' , settings ['theme_text_margin ' ] * - 1 )
86+ $ TextBubble/RichTextLabel . set ( 'margin_top' , settings [ 'theme_text_margin' ])
87+ $ TextBubble/RichTextLabel .set ('margin_bottom ' , settings ['theme_text_margin' ] * - 1 )
88+ if settings . has ( 'theme_text_margin_h' ):
89+ $ TextBubble/RichTextLabel .set ('margin_left ' , settings ['theme_text_margin_h' ])
90+ $ TextBubble/RichTextLabel .set ('margin_right ' , settings ['theme_text_margin_h ' ] * - 1 )
8291 # Images
8392 if settings .has ('theme_background_image' ):
8493 $ TextBubble/TextureRect .texture = load (settings ['theme_background_image' ])
@@ -125,9 +134,14 @@ func start_text_tween():
125134 $ TextBubble/Tween .start ()
126135
127136
128- func update_name (name_string , color = 'FFFFFF' ):
129- var parsed_name = parse_text (name_string )
130- $ TextBubble/NameLabel .bbcode_text = '[color=#' + color + ']' + parsed_name + '[/color]'
137+ func update_name (character , color = 'FFFFFF' ):
138+ if str (character ) == '' :
139+ $ TextBubble/NameLabel .bbcode_text = ''
140+ else :
141+ var parsed_name = character ['name' ]
142+ if character .has ('color' ):
143+ color = character ['color' ].to_html ()
144+ $ TextBubble/NameLabel .bbcode_text = '[color=#' + color + ']' + parsed_name + '[/color]'
131145 return true
132146
133147
@@ -154,27 +168,25 @@ func load_dialog(skip_add = false):
154168 dialog_index += 1
155169
156170
157- func get_character_variable (name ):
158- for c in dialog_characters :# dialog_resource.characters:
159- if c .name == name :
160- return c
161- # push_error('DialogCharacterResource [' + name + '] does not exists. Make sure the name field is not empty.')
162- return false
163-
164-
165171func reset_dialog_extras ():
166172 $ TextBubble/NameLabel .bbcode_text = ''
167173
168174
175+ func get_character (character_id ):
176+ for c in characters :
177+ if c ['file' ] == character_id :
178+ return c
179+ return ''
180+
181+
169182func event_handler (event ):
170183 # Handling an event and updating the available nodes accordingly.
171184 reset_dialog_extras ()
172185 match event :
173186 {'text' , 'character' }, {'text' , 'character' , ..}:
174187 show_dialog ()
175188 finished = false
176- # var character_data = get_character_variable(event['character'])
177- ## update_name(character_data.name, character_data.color.to_html())
189+ update_name (get_character (event ['character' ]))
178190 # var exists = false
179191 # var existing
180192 # for portrait in $Portraits.get_children():
@@ -196,14 +208,14 @@ func event_handler(event):
196208 # p.init('left') # Default character position
197209 # $Portraits.add_child(p)
198210 # p.fade_in()
199-
211+
200212 update_text (event ['text' ])
201213 {'question' , ..}:
202214 show_dialog ()
203215 finished = false
204216 waiting_for_answer = true
205217 if event .has ('name' ):
206- update_name (event ['name' ])
218+ update_name (event ['name' ])
207219 update_text (event ['question' ])
208220 for o in event ['options' ]:
209221 var button = Button .new ()
0 commit comments