Skip to content

Commit b56e693

Browse files
Various improvements (#2508)
- Fix for autoskip.disable_on_user_input (due to stupid constant input blocking timers) - Fix for shortcode syntax highlighting when [] is in parameter content - Suggest Autoloads, autoload methods and autoload properties in the Set Variable event as well as other related code completion improvements. - Small crash safeguard - Implement search highlight in Broken Reference Manager as well as a note on how only timelines are searched/replaced there (see #2505). - Adds a progress bar to the loading of visual timelines - Fixes some issues with timeline search - Changes the saving behaviour when changes have been made to a half-loaded visual timeline and the editor is switched. - Previously the timeline would save, meaning everything that hadn't loaded yet was discarded - Now the timeline is not saved, meaning the changes made will get lost. - Generally changing and saving a timeline before it's fully loaded should not be done. However I think this is better, because it's more likely you accidentally marked the timeline as *changed then actually wanting to keep changes made before saving. - If you let the timeline finish loading, all changes are of course kept. - Does some adjustments to the variable/expression regex. This should hopefully better support nested expressions (e.g. `{Autoload.dictionary[{Player.Name}]}`). This is also reflected in the improved syntax highlighting.
1 parent 0830fb3 commit b56e693

19 files changed

+333
-138
lines changed

addons/dialogic/Core/DialogicResourceUtil.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ static func add_resource_to_directory(file_path:String, directory:Dictionary) ->
6363
## Returns an empty string if no identifier was found.
6464
static func get_unique_identifier(file_path:String) -> String:
6565
if not file_path: return ""
66-
var identifier: String = get_directory(file_path.get_extension()).find_key(file_path)
66+
var identifier: Variant = get_directory(file_path.get_extension()).find_key(file_path)
6767
if typeof(identifier) == TYPE_STRING:
6868
return identifier
6969
return ""

addons/dialogic/Core/DialogicUtil.gd

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,3 +682,57 @@ static func get_portrait_position_suggestions(search_text := "") -> Dictionary:
682682
suggestions.erase(search_text)
683683

684684
return suggestions
685+
686+
687+
static func get_autoload_suggestions(filter:String="") -> Dictionary:
688+
var suggestions := {}
689+
690+
for prop in ProjectSettings.get_property_list():
691+
if prop.name.begins_with('autoload/'):
692+
var autoload: String = prop.name.trim_prefix('autoload/')
693+
suggestions[autoload] = {'value': autoload, 'tooltip':autoload, 'editor_icon': ["Node", "EditorIcons"]}
694+
if filter.begins_with(autoload):
695+
suggestions[filter] = {'value': filter, 'editor_icon':["GuiScrollArrowRight", "EditorIcons"]}
696+
return suggestions
697+
698+
699+
static func get_autoload_script_resource(autoload_name:String) -> Script:
700+
var script: Script
701+
if autoload_name and ProjectSettings.has_setting('autoload/'+autoload_name):
702+
var loaded_autoload := load(ProjectSettings.get_setting('autoload/'+autoload_name).trim_prefix('*'))
703+
704+
if loaded_autoload is PackedScene:
705+
var packed_scene: PackedScene = loaded_autoload
706+
script = packed_scene.instantiate().get_script()
707+
708+
else:
709+
script = loaded_autoload
710+
return script
711+
712+
713+
static func get_autoload_method_suggestions(filter:String, autoload_name:String) -> Dictionary:
714+
var suggestions := {}
715+
716+
var script := get_autoload_script_resource(autoload_name)
717+
if script:
718+
for script_method in script.get_script_method_list():
719+
if script_method.name.begins_with('@') or script_method.name.begins_with('_'):
720+
continue
721+
suggestions[script_method.name] = {'value': script_method.name, 'tooltip':script_method.name, 'editor_icon': ["Callable", "EditorIcons"]}
722+
723+
if not filter.is_empty():
724+
suggestions[filter] = {'value': filter, 'editor_icon':["GuiScrollArrowRight", "EditorIcons"]}
725+
726+
return suggestions
727+
728+
729+
static func get_autoload_property_suggestions(filter:String, autoload_name:String) -> Dictionary:
730+
var suggestions := {}
731+
var script := get_autoload_script_resource(autoload_name)
732+
if script:
733+
for property in script.get_script_property_list():
734+
if property.name.ends_with('.gd') or property.name.begins_with('_'):
735+
continue
736+
suggestions[property.name] = {'value': property.name, 'tooltip':property.name, 'editor_icon': ["MemberProperty", "EditorIcons"]}
737+
738+
return suggestions

addons/dialogic/Editor/Common/broken_reference_manager.gd

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ func display_search_results(finds:Array[Dictionary]) -> void:
158158

159159
%ReferenceTree.clear()
160160
%ReferenceTree.set_column_expand(0, false)
161+
%ReferenceTree.set_column_expand(1, false)
162+
%ReferenceTree.set_column_custom_minimum_width(1, 50)
161163
%ReferenceTree.create_item()
162164

163165
var timelines := {}
@@ -166,20 +168,25 @@ func display_search_results(finds:Array[Dictionary]) -> void:
166168
var parent: TreeItem = null
167169
if !i.timeline in timelines:
168170
parent = %ReferenceTree.create_item()
169-
parent.set_text(1, i.timeline)
170-
parent.set_custom_color(1, get_theme_color("disabled_font_color", "Editor"))
171+
parent.set_text(0, i.timeline)
172+
parent.set_custom_color(0, get_theme_color("disabled_font_color", "Editor"))
173+
parent.set_expand_right(0, true)
171174
timelines[i.timeline] = parent
172175
height += %ReferenceTree.get_item_area_rect(parent).size.y+10
173176
else:
174177
parent = timelines[i.timeline]
175178

176179
var item: TreeItem = %ReferenceTree.create_item(parent)
177-
item.set_text(1, 'Line '+str(i.line_number)+': '+i.line)
178-
item.set_tooltip_text(1, i.info.what+' -> '+i.info.forwhat)
179180
item.set_cell_mode(0, TreeItem.CELL_MODE_CHECK)
180181
item.set_checked(0, true)
181182
item.set_editable(0, true)
182183
item.set_metadata(0, i)
184+
item.set_text(1, str(i.line_number)+':')
185+
item.set_text_alignment(1, HORIZONTAL_ALIGNMENT_RIGHT)
186+
item.set_cell_mode(2, TreeItem.CELL_MODE_CUSTOM)
187+
item.set_text(2, i.line)
188+
item.set_tooltip_text(2, i.info.what+' -> '+i.info.forwhat)
189+
item.set_custom_draw_callback(2, _custom_draw)
183190
height += %ReferenceTree.get_item_area_rect(item).size.y+10
184191
var change_item: TreeItem = i.info.item
185192
change_item.set_meta('found_items', change_item.get_meta('found_items', [])+[item])
@@ -194,6 +201,27 @@ func display_search_results(finds:Array[Dictionary]) -> void:
194201
%Replace.grab_focus()
195202

196203

204+
## Highlights the found text in the result tree
205+
## Inspired by how godot highlights stuff in its search results
206+
func _custom_draw(item:TreeItem, rect:Rect2) -> void:
207+
var text := item.get_text(2)
208+
var find := item.get_metadata(0)
209+
210+
var font: Font = %ReferenceTree.get_theme_font("font")
211+
var font_size: int = %ReferenceTree.get_theme_font_size("font_size")
212+
213+
var match_rect := rect
214+
var beginning_index: int = find.match.get_start("replace")-find.line_start-1
215+
match_rect.position.x += font.get_string_size(text.left(beginning_index), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size).x -1
216+
match_rect.size.x = font.get_string_size(find.info.what, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size).x + 1
217+
match_rect.position.y += 1 * DialogicUtil.get_editor_scale()
218+
match_rect.size.y -= 2 * DialogicUtil.get_editor_scale()
219+
match_rect.position.x += 4
220+
221+
%ReferenceTree.draw_rect(match_rect, get_theme_color("highlight_color", "Editor"), true)
222+
%ReferenceTree.draw_rect(match_rect, get_theme_color("box_selection_stroke_color", "Editor"), false)
223+
224+
197225
func search_timelines(regexes:Array[Array]) -> Array[Dictionary]:
198226
var finds: Array[Dictionary] = []
199227

0 commit comments

Comments
 (0)