Skip to content

Commit 9083919

Browse files
committed
More performance enhancements
1 parent a4930b6 commit 9083919

6 files changed

Lines changed: 85 additions & 78 deletions

File tree

addons/dialogic/Core/DialogicResourceUtil.gd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ static func update_directory(extension:String) -> void:
5656
set_directory(extension, directory)
5757

5858

59+
static func is_resource_in_directory(file_path:String) -> bool:
60+
var directory := get_directory(file_path.get_extension())
61+
return file_path in directory.values()
62+
5963
static func add_resource_to_directory(file_path:String, directory:Dictionary) -> Dictionary:
6064
var suggested_name := file_path.get_file().trim_suffix("."+file_path.get_extension())
6165
var temp := suggested_name

addons/dialogic/Editor/Events/EventBlock/event_block.gd

Lines changed: 57 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,13 @@ func initialize_ui() -> void:
6464

6565
# Expand Button
6666
%ToggleBodyVisibilityButton.icon = get_theme_icon("CodeFoldedRightArrow", "EditorIcons")
67+
%ToggleBodyVisibilityButton.begin_bulk_theme_override()
6768
%ToggleBodyVisibilityButton.set("theme_override_colors/icon_normal_color", get_theme_color("contrast_color_2", "Editor"))
6869
%ToggleBodyVisibilityButton.set("theme_override_colors/icon_hover_color", get_theme_color("accent_color", "Editor"))
6970
%ToggleBodyVisibilityButton.set("theme_override_colors/icon_pressed_color", get_theme_color("contrast_color_2", "Editor"))
7071
%ToggleBodyVisibilityButton.set("theme_override_colors/icon_hover_pressed_color", get_theme_color("accent_color", "Editor"))
7172
%ToggleBodyVisibilityButton.add_theme_stylebox_override('hover_pressed', StyleBoxEmpty.new())
73+
%ToggleBodyVisibilityButton.end_bulk_theme_override()
7274

7375
# Icon Panel
7476
%IconPanel.tooltip_text = resource.event_name
@@ -153,31 +155,31 @@ func set_indent(indent: int) -> void:
153155
#region EVENT FIELDS
154156
################################################################################
155157

156-
var FIELD_SCENES := {
157-
DialogicEvent.ValueType.MULTILINE_TEXT: "res://addons/dialogic/Editor/Events/Fields/field_text_multiline.tscn",
158-
DialogicEvent.ValueType.SINGLELINE_TEXT: "res://addons/dialogic/Editor/Events/Fields/field_text_singleline.tscn",
159-
DialogicEvent.ValueType.FILE: "res://addons/dialogic/Editor/Events/Fields/field_file.tscn",
160-
DialogicEvent.ValueType.BOOL: "res://addons/dialogic/Editor/Events/Fields/field_bool_check.tscn",
161-
DialogicEvent.ValueType.BOOL_BUTTON: "res://addons/dialogic/Editor/Events/Fields/field_bool_button.tscn",
162-
DialogicEvent.ValueType.CONDITION: "res://addons/dialogic/Editor/Events/Fields/field_condition.tscn",
163-
DialogicEvent.ValueType.ARRAY: "res://addons/dialogic/Editor/Events/Fields/field_array.tscn",
164-
DialogicEvent.ValueType.DICTIONARY: "res://addons/dialogic/Editor/Events/Fields/field_dictionary.tscn",
165-
DialogicEvent.ValueType.DYNAMIC_OPTIONS: "res://addons/dialogic/Editor/Events/Fields/field_options_dynamic.tscn",
166-
DialogicEvent.ValueType.FIXED_OPTIONS : "res://addons/dialogic/Editor/Events/Fields/field_options_fixed.tscn",
167-
DialogicEvent.ValueType.NUMBER: "res://addons/dialogic/Editor/Events/Fields/field_number.tscn",
168-
DialogicEvent.ValueType.VECTOR2: "res://addons/dialogic/Editor/Events/Fields/field_vector2.tscn",
169-
DialogicEvent.ValueType.VECTOR3: "res://addons/dialogic/Editor/Events/Fields/field_vector3.tscn",
170-
DialogicEvent.ValueType.VECTOR4: "res://addons/dialogic/Editor/Events/Fields/field_vector4.tscn",
171-
DialogicEvent.ValueType.COLOR: "res://addons/dialogic/Editor/Events/Fields/field_color.tscn",
172-
DialogicEvent.ValueType.AUDIO_PREVIEW: "res://addons/dialogic/Editor/Events/Fields/field_audio_preview.tscn",
173-
DialogicEvent.ValueType.IMAGE_PREVIEW: "res://addons/dialogic/Editor/Events/Fields/field_image_preview.tscn",
158+
static var FIELD_SCENES := {
159+
DialogicEvent.ValueType.MULTILINE_TEXT: preload("res://addons/dialogic/Editor/Events/Fields/field_text_multiline.tscn"),
160+
DialogicEvent.ValueType.SINGLELINE_TEXT: preload("res://addons/dialogic/Editor/Events/Fields/field_text_singleline.tscn"),
161+
DialogicEvent.ValueType.FILE: preload("res://addons/dialogic/Editor/Events/Fields/field_file.tscn"),
162+
DialogicEvent.ValueType.BOOL: preload("res://addons/dialogic/Editor/Events/Fields/field_bool_check.tscn"),
163+
DialogicEvent.ValueType.BOOL_BUTTON: preload("res://addons/dialogic/Editor/Events/Fields/field_bool_button.tscn"),
164+
DialogicEvent.ValueType.CONDITION: preload("res://addons/dialogic/Editor/Events/Fields/field_condition.tscn"),
165+
DialogicEvent.ValueType.ARRAY: preload("res://addons/dialogic/Editor/Events/Fields/field_array.tscn"),
166+
DialogicEvent.ValueType.DICTIONARY: preload("res://addons/dialogic/Editor/Events/Fields/field_dictionary.tscn"),
167+
DialogicEvent.ValueType.DYNAMIC_OPTIONS: preload("res://addons/dialogic/Editor/Events/Fields/field_options_dynamic.tscn"),
168+
DialogicEvent.ValueType.FIXED_OPTIONS : preload("res://addons/dialogic/Editor/Events/Fields/field_options_fixed.tscn"),
169+
DialogicEvent.ValueType.NUMBER: preload("res://addons/dialogic/Editor/Events/Fields/field_number.tscn"),
170+
DialogicEvent.ValueType.VECTOR2: preload("res://addons/dialogic/Editor/Events/Fields/field_vector2.tscn"),
171+
DialogicEvent.ValueType.VECTOR3: preload("res://addons/dialogic/Editor/Events/Fields/field_vector3.tscn"),
172+
DialogicEvent.ValueType.VECTOR4: preload("res://addons/dialogic/Editor/Events/Fields/field_vector4.tscn"),
173+
DialogicEvent.ValueType.COLOR: preload("res://addons/dialogic/Editor/Events/Fields/field_color.tscn"),
174+
DialogicEvent.ValueType.AUDIO_PREVIEW: preload("res://addons/dialogic/Editor/Events/Fields/field_audio_preview.tscn"),
175+
DialogicEvent.ValueType.IMAGE_PREVIEW: preload("res://addons/dialogic/Editor/Events/Fields/field_image_preview.tscn"),
174176
}
175177

176178

177179
func build_editor(build_header:bool = true, build_body:bool = false) -> void:
178-
var debug := true
180+
#var debug := false
181+
#var start_time := Time.get_unix_time_from_system()
179182

180-
var start_time := Time.get_unix_time_from_system()
181183
var current_body_container: HFlowContainer = null
182184

183185
if build_body and body_was_build:
@@ -190,19 +192,19 @@ func build_editor(build_header:bool = true, build_body:bool = false) -> void:
190192
%BodyContent.add_child(current_body_container)
191193
body_was_build = true
192194

193-
if debug: printt("","Preloop: ", Time.get_unix_time_from_system()-start_time)
195+
#if debug: printt("","Preloop: ", Time.get_unix_time_from_system()-start_time)
194196

195197
for p in resource.get_event_editor_info():
196198
field_list.append({'node':null, 'location':p.location})
197199
if p.has('condition'):
198200
field_list[-1]['condition'] = p.condition
199201

200-
if debug: printt("","Element: ", p.name, Time.get_unix_time_from_system()-start_time)
201-
var element_start := Time.get_unix_time_from_system()
202-
var prev := Time.get_unix_time_from_system()
203-
if !build_body and p.location == 1:
202+
#if debug: printt("","Element: ", p.name, Time.get_unix_time_from_system()-start_time)
203+
#var element_start := Time.get_unix_time_from_system()
204+
#var prev := Time.get_unix_time_from_system()
205+
if not build_body and p.location == 1:
204206
continue
205-
elif !build_header and p.location == 0:
207+
elif not build_header and p.location == 0:
206208
continue
207209

208210
### --------------------------------------------------------------------
@@ -212,14 +214,14 @@ func build_editor(build_header:bool = true, build_body:bool = false) -> void:
212214
### LINEBREAK
213215
if p.name == "linebreak":
214216
field_list.remove_at(field_list.size()-1)
215-
if !current_body_container.get_child_count():
217+
if not current_body_container.get_child_count():
216218
current_body_container.queue_free()
217219
current_body_container = HFlowContainer.new()
218220
%BodyContent.add_child(current_body_container)
219221
continue
220222

221223
elif p.field_type in FIELD_SCENES:
222-
editor_node = load(FIELD_SCENES[p.field_type]).instantiate()
224+
editor_node = FIELD_SCENES[p.field_type].instantiate()
223225

224226
elif p.field_type == resource.ValueType.LABEL:
225227
editor_node = Label.new()
@@ -251,27 +253,29 @@ func build_editor(build_header:bool = true, build_body:bool = false) -> void:
251253
editor_node.text = p.name
252254
editor_node.add_theme_color_override('font_color', resource.event_color.lerp(get_theme_color("font_color", "Editor"), 0.8))
253255

254-
if debug: printt("","","A: ", Time.get_unix_time_from_system()-prev)
255-
prev = Time.get_unix_time_from_system()
256+
#if debug: printt("","","A: ", Time.get_unix_time_from_system()-prev)
257+
#prev = Time.get_unix_time_from_system()
256258
field_list[-1]['node'] = editor_node
259+
editor_node.name = p.name.to_pascal_case()
257260
### --------------------------------------------------------------------
258261
# Some things need to be called BEFORE the field is added to the tree
259262
if editor_node is DialogicVisualEditorField:
260263
editor_node.event_resource = resource
261264

262265
editor_node.property_name = p.name
266+
263267
field_list[-1]['property'] = p.name
264268

265269
editor_node._load_display_info(p.display_info)
266270

267-
if debug: printt("","","B: ", Time.get_unix_time_from_system()-prev)
268-
prev = Time.get_unix_time_from_system()
271+
#if debug: printt("","","B: ", Time.get_unix_time_from_system()-prev)
272+
#prev = Time.get_unix_time_from_system()
269273
var location: Control = %HeaderContent
270274
if p.location == 1:
271275
location = current_body_container
272276
location.add_child(editor_node)
273-
if debug: printt("","","C: ", Time.get_unix_time_from_system()-prev)
274-
prev = Time.get_unix_time_from_system()
277+
#if debug: printt("","","C: ", Time.get_unix_time_from_system()-prev)
278+
#prev = Time.get_unix_time_from_system()
275279
# Some things need to be called AFTER the field is added to the tree
276280
if editor_node is DialogicVisualEditorField:
277281
## Only set the value if the field is visible
@@ -293,28 +297,28 @@ func build_editor(build_header:bool = true, build_body:bool = false) -> void:
293297
# Apply autofocus
294298
if resource.created_by_button and p.display_info.get('autofocus', false):
295299
editor_node.call_deferred('take_autofocus')
296-
if debug: printt("","","D: ", Time.get_unix_time_from_system()-prev)
297-
prev = Time.get_unix_time_from_system()
300+
#if debug: printt("","","D: ", Time.get_unix_time_from_system()-prev)
301+
#prev = Time.get_unix_time_from_system()
298302
### --------------------------------------------------------------------
299303
### 4. ADD LEFT AND RIGHT TEXT
300304
var left_label: Label = null
301305
var right_label: Label = null
302-
if !p.get('left_text', '').is_empty():
306+
if not p.get('left_text', '').is_empty():
303307
left_label = Label.new()
304308
left_label.text = p.get('left_text')
305309
left_label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
306310
left_label.add_theme_color_override('font_color', resource.event_color.lerp(get_theme_color("font_color", "Editor"), 0.8))
307311
location.add_child(left_label)
308312
location.move_child(left_label, editor_node.get_index())
309-
if !p.get('right_text', '').is_empty():
313+
if not p.get('right_text', '').is_empty():
310314
right_label = Label.new()
311315
right_label.text = p.get('right_text')
312316
right_label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
313317
right_label.add_theme_color_override('font_color', resource.event_color.lerp(get_theme_color("font_color", "Editor"), 0.8))
314318
location.add_child(right_label)
315319
location.move_child(right_label, editor_node.get_index()+1)
316-
if debug: printt("","","E: ", Time.get_unix_time_from_system()-prev)
317-
prev = Time.get_unix_time_from_system()
320+
#if debug: printt("","","E: ", Time.get_unix_time_from_system()-prev)
321+
#prev = Time.get_unix_time_from_system()
318322
### --------------------------------------------------------------------
319323
### 5. REGISTER CONDITION
320324
if p.has('condition'):
@@ -324,25 +328,27 @@ func build_editor(build_header:bool = true, build_body:bool = false) -> void:
324328
if right_label:
325329
field_list.append({'node': right_label, 'condition':p.condition, 'location':p.location})
326330

327-
if debug: printt("","","Z: ", Time.get_unix_time_from_system()-prev)
328-
if debug: printt("","","Full: ", Time.get_unix_time_from_system()-element_start)
331+
#if debug: printt("","","Z: ", Time.get_unix_time_from_system()-prev)
332+
#if debug: printt("","","Full: ", Time.get_unix_time_from_system()-element_start)
329333

330-
if debug: printt("", "BlockB: ", Time.get_unix_time_from_system()-start_time)
334+
#if debug: printt("", "BlockB: ", Time.get_unix_time_from_system()-start_time)
331335

332336
if build_body:
333337
if current_body_container.get_child_count() == 0:
334338
%Body.visible = false
335-
if debug: printt("", "BlockC: ", Time.get_unix_time_from_system()-start_time)
339+
#if debug: printt("", "BlockC: ", Time.get_unix_time_from_system()-start_time)
336340

337341
recalculate_field_visibility()
338342

339-
if debug: printt("", "BlockFull: ", Time.get_unix_time_from_system()-start_time)
343+
#if debug: printt("", "BlockFull: ", Time.get_unix_time_from_system()-start_time)
340344

341345

342346
func recalculate_field_visibility() -> void:
343347
has_any_enabled_body_content = false
344348
for field in field_list:
345-
if field.get("condition", "").is_empty() or _evaluate_visibility_condition(field):
349+
if not field.node and has_any_enabled_body_content:
350+
continue
351+
if _evaluate_visibility_condition(field):
346352
if field.node:
347353
if field.has("condition") and (not field.node.visible) and field.has("property"):
348354
field.node._set_value(resource.get(field.property))
@@ -356,25 +362,6 @@ func recalculate_field_visibility() -> void:
356362
if field.node != null:
357363
field.node.hide()
358364

359-
#for p in field_list:
360-
#if not p.has('condition') or p.condition.is_empty():
361-
#if p.node != null:
362-
#p.node.show()
363-
#if p.location == 1:
364-
#has_any_enabled_body_content = true
365-
#
366-
#else:
367-
#if _evaluate_visibility_condition(p):
368-
#if p.node != null:
369-
#if p.node.visible == false and p.has("property"):
370-
#p.node._set_value(resource.get(p.property))
371-
#p.node.show()
372-
#if p.location == 1:
373-
#has_any_enabled_body_content = true
374-
#else:
375-
#if p.node != null:
376-
#p.node.hide()
377-
378365
%ToggleBodyVisibilityButton.visible = has_any_enabled_body_content
379366

380367

@@ -386,8 +373,9 @@ func set_property(property_name:String, value:Variant) -> void:
386373

387374

388375
func _evaluate_visibility_condition(field: Dictionary) -> bool:
389-
#if
390-
#
376+
if field.get("condition", "").is_empty():
377+
return true
378+
391379
var expr: Expression
392380
var cache: Dictionary = Engine.get_meta("dialogic_visibility_condition_cache", {})
393381
if field.condition in cache:
@@ -423,11 +411,9 @@ func _on_resource_ui_update_needed() -> void:
423411
# This prevents events with varied value types (event_setting, event_variable)
424412
# from injecting incorrect types into hidden fields, which then throw errors
425413
# in the console.
426-
if node_info.has('condition') and not node_info.condition.is_empty():
427-
if _evaluate_visibility_condition(node_info):
428-
node_info.node.set_value(resource.get(node_info.property))
429-
else:
414+
if _evaluate_visibility_condition(node_info):
430415
node_info.node.set_value(resource.get(node_info.property))
416+
431417
recalculate_field_visibility()
432418

433419

addons/dialogic/Editor/Events/Fields/field_bool_button.gd

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,22 @@ extends DialogicVisualEditorField
77
################################################################################
88

99
func _ready() -> void:
10-
add_theme_color_override("icon_normal_color", get_theme_color("disabled_font_color", "Editor"))
11-
add_theme_color_override("icon_hover_color", get_theme_color("warning_color", "Editor"))
12-
add_theme_color_override("icon_pressed_color", get_theme_color("icon_saturation", "Editor"))
13-
add_theme_color_override("icon_hover_pressed_color", get_theme_color("warning_color", "Editor"))
14-
add_theme_color_override("icon_focus_color", get_theme_color("disabled_font_color", "Editor"))
1510
self.toggled.connect(_on_value_changed)
1611

1712

13+
# We do this because theme changes are costly and many of these nodes are never becoming visible at all
14+
func _on_visibility_changed() -> void:
15+
if visible and not has_meta("did_theming"):
16+
begin_bulk_theme_override()
17+
add_theme_color_override("icon_normal_color", get_theme_color("disabled_font_color", "Editor"))
18+
add_theme_color_override("icon_hover_color", get_theme_color("warning_color", "Editor"))
19+
add_theme_color_override("icon_pressed_color", get_theme_color("icon_saturation", "Editor"))
20+
add_theme_color_override("icon_hover_pressed_color", get_theme_color("warning_color", "Editor"))
21+
add_theme_color_override("icon_focus_color", get_theme_color("disabled_font_color", "Editor"))
22+
end_bulk_theme_override()
23+
set_meta("did_theming", true)
24+
25+
1826
func _load_display_info(info:Dictionary) -> void:
1927
if info.has('editor_icon'):
2028
if not is_inside_tree():

addons/dialogic/Editor/Events/Fields/field_options_dynamic.gd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ func _load_display_info(info:Dictionary) -> void:
7676
valid_file_drop_extension = info.get('file_extension', '')
7777
collapse_when_empty = info.get('collapse_when_empty', false)
7878
suggestions_func = info.get('suggestions_func', suggestions_func)
79+
if not suggestions_func.is_valid():
80+
if event_resource.has_method(suggestions_func.get_method()):
81+
suggestions_func = Callable(event_resource, suggestions_func.get_method())
7982
validation_func = info.get('validation_func', validation_func)
8083
empty_text = info.get('empty_text', '')
8184
placeholder_text = info.get('placeholder', 'Select Resource')
@@ -97,6 +100,8 @@ func _autofocus() -> void:
97100
################################################################################
98101

99102
func _ready() -> void:
103+
if not is_visible_in_tree():
104+
return
100105
var focus := get_theme_stylebox("focus", "LineEdit")
101106
if has_theme_stylebox("focus", "DialogicEventEdit"):
102107
focus = get_theme_stylebox('focus', 'DialogicEventEdit')
@@ -293,6 +298,8 @@ func suggestion_selected(index: int, _position := Vector2(), button_index := MOU
293298

294299

295300
func _input(event:InputEvent) -> void:
301+
if not visible:
302+
return
296303
if %Suggestions.visible and event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
297304
if not %Suggestions.get_global_rect().has_point(get_global_mouse_position()) and \
298305
not %SelectButton.get_global_rect().has_point(get_global_mouse_position()):

addons/dialogic/Editor/TimelineEditor/TextEditor/timeline_editor_text.gd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ func save_timeline() -> void:
5353

5454
timeline_editor.current_resource.set_meta("timeline_not_saved", false)
5555
timeline_editor.current_resource_state = DialogicEditor.ResourceStates.SAVED
56-
DialogicResourceUtil.update_directory('dtl')
56+
if not DialogicResourceUtil.is_resource_in_directory(timeline_editor.current_resource.resource_path):
57+
DialogicResourceUtil.update_directory('dtl')
5758

5859

5960
func text_timeline_to_array(timeline_text:String) -> Array:

addons/dialogic/Modules/Character/event_character.gd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,8 @@ func to_text() -> String:
256256

257257
func from_text(string:String) -> void:
258258
# Load default character
259-
character = DialogicResourceUtil.get_character_resource(character_identifier)
259+
if character_identifier:
260+
character = DialogicResourceUtil.get_character_resource(character_identifier)
260261

261262
var result := regex.search(string)
262263

0 commit comments

Comments
 (0)