Skip to content

Commit 3874991

Browse files
committed
dialogs showing proper character name and color
1 parent 25b455f commit 3874991

File tree

3 files changed

+53
-37
lines changed

3 files changed

+53
-37
lines changed

addons/dialogic/Editor/EditorView.tscn

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ margin_right = 180.0
459459
margin_bottom = 541.0
460460
size_flags_horizontal = 3
461461
size_flags_vertical = 3
462-
items = [ "Lyra", ExtResource( 7 ), false, "Shia", ExtResource( 7 ), false, "Narrator", ExtResource( 7 ), false ]
462+
items = [ "Narrator", ExtResource( 7 ), false, "Shia", ExtResource( 7 ), false, "Lyra", ExtResource( 7 ), false ]
463463
allow_rmb_select = true
464464

465465
[node name="NoCharacters" type="CenterContainer" parent="EditorCharacter"]
@@ -797,10 +797,10 @@ margin_right = 511.0
797797
margin_bottom = 38.0
798798

799799
[node name="ActionOptionButton" type="OptionButton" parent="EditorTheme/VBoxContainer/VBoxContainer/HBoxContainer/VBoxContainer"]
800-
margin_right = 104.0
800+
margin_right = 76.0
801801
margin_bottom = 20.0
802802
size_flags_horizontal = 0
803-
text = "mouse_test"
803+
text = "ui_right"
804804
items = [ "[Select Action]", null, false, 0, null, "ui_accept", null, false, 1, null, "ui_select", null, false, 2, null, "ui_cancel", null, false, 3, null, "ui_focus_next", null, false, 4, null, "ui_focus_prev", null, false, 5, null, "ui_left", null, false, 6, null, "ui_right", null, false, 7, null, "ui_up", null, false, 8, null, "ui_down", null, false, 9, null, "ui_page_up", null, false, 10, null, "ui_page_down", null, false, 11, null, "ui_home", null, false, 12, null, "ui_end", null, false, 13, null ]
805805
selected = 0
806806

@@ -920,7 +920,7 @@ margin_left = 123.0
920920
margin_right = 173.0
921921
margin_bottom = 30.0
922922
rect_min_size = Vector2( 50, 30 )
923-
color = Color( 0.207843, 0.968627, 0.898039, 0.576471 )
923+
color = Color( 0, 0, 0, 0.576471 )
924924

925925
[node name="Label3" type="Label" parent="EditorTheme/VBoxContainer/HBoxContainer"]
926926
margin_left = 183.0
@@ -958,15 +958,15 @@ text = " Text margin"
958958
margin_left = 569.0
959959
margin_right = 643.0
960960
margin_bottom = 30.0
961-
value = 15.0
961+
value = 19.0
962962
rounded = true
963963
prefix = "V"
964964

965965
[node name="TextMarginH" type="SpinBox" parent="EditorTheme/VBoxContainer/HBoxContainer"]
966966
margin_left = 653.0
967967
margin_right = 727.0
968968
margin_bottom = 30.0
969-
value = 15.0
969+
value = 40.0
970970
rounded = true
971971
prefix = "H"
972972

addons/dialogic/Nodes/Dialog.tscn

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ __meta__ = {
7777
[node name="RichTextLabel" type="RichTextLabel" parent="TextBubble"]
7878
anchor_right = 1.0
7979
anchor_bottom = 1.0
80-
margin_left = 15.0
80+
margin_left = 26.0
8181
margin_top = 15.0
82-
margin_right = -15.0
82+
margin_right = -26.0
8383
margin_bottom = -15.0
8484
rect_clip_content = false
8585
custom_styles/normal = SubResource( 1 )
@@ -123,7 +123,11 @@ margin_left = 2.0
123123
margin_top = -37.0
124124
margin_right = 369.0
125125
custom_styles/normal = SubResource( 1 )
126-
custom_colors/font_color_shadow = Color( 0, 0, 0, 1 )
126+
custom_fonts/normal_font = ExtResource( 3 )
127+
custom_colors/default_color = Color( 1, 1, 1, 1 )
128+
custom_colors/font_color_shadow = Color( 0, 0, 0, 0.576471 )
129+
custom_constants/shadow_offset_x = 1
130+
custom_constants/shadow_offset_y = 1
127131
custom_constants/shadow_as_outline = 10
128132
bbcode_enabled = true
129133
bbcode_text = "Name Here"

addons/dialogic/Nodes/dialog_node.gd

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var waiting_for_input = false
1212
export(String) var timeline_id # Timeline-var-replace
1313

1414
var dialog_resource
15-
export(Array, Resource) var dialog_characters
15+
var characters
1616

1717
onready var Portrait = load("res://addons/dialogic/Nodes/Portrait.tscn")
1818
var 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-
165171
func 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+
169182
func 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

Comments
 (0)