Skip to content

Various improvements #2508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jan 18, 2025
2 changes: 1 addition & 1 deletion addons/dialogic/Core/DialogicResourceUtil.gd
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static func add_resource_to_directory(file_path:String, directory:Dictionary) ->
## Returns an empty string if no identifier was found.
static func get_unique_identifier(file_path:String) -> String:
if not file_path: return ""
var identifier: String = get_directory(file_path.get_extension()).find_key(file_path)
var identifier: Variant = get_directory(file_path.get_extension()).find_key(file_path)
if typeof(identifier) == TYPE_STRING:
return identifier
return ""
Expand Down
54 changes: 54 additions & 0 deletions addons/dialogic/Core/DialogicUtil.gd
Original file line number Diff line number Diff line change
Expand Up @@ -682,3 +682,57 @@ static func get_portrait_position_suggestions(search_text := "") -> Dictionary:
suggestions.erase(search_text)

return suggestions


static func get_autoload_suggestions(filter:String="") -> Dictionary:
var suggestions := {}

for prop in ProjectSettings.get_property_list():
if prop.name.begins_with('autoload/'):
var autoload: String = prop.name.trim_prefix('autoload/')
suggestions[autoload] = {'value': autoload, 'tooltip':autoload, 'editor_icon': ["Node", "EditorIcons"]}
if filter.begins_with(autoload):
suggestions[filter] = {'value': filter, 'editor_icon':["GuiScrollArrowRight", "EditorIcons"]}
return suggestions


static func get_autoload_script_resource(autoload_name:String) -> Script:
var script: Script
if autoload_name and ProjectSettings.has_setting('autoload/'+autoload_name):
var loaded_autoload := load(ProjectSettings.get_setting('autoload/'+autoload_name).trim_prefix('*'))

if loaded_autoload is PackedScene:
var packed_scene: PackedScene = loaded_autoload
script = packed_scene.instantiate().get_script()

else:
script = loaded_autoload
return script


static func get_autoload_method_suggestions(filter:String, autoload_name:String) -> Dictionary:
var suggestions := {}

var script := get_autoload_script_resource(autoload_name)
if script:
for script_method in script.get_script_method_list():
if script_method.name.begins_with('@') or script_method.name.begins_with('_'):
continue
suggestions[script_method.name] = {'value': script_method.name, 'tooltip':script_method.name, 'editor_icon': ["Callable", "EditorIcons"]}

if not filter.is_empty():
suggestions[filter] = {'value': filter, 'editor_icon':["GuiScrollArrowRight", "EditorIcons"]}

return suggestions


static func get_autoload_property_suggestions(filter:String, autoload_name:String) -> Dictionary:
var suggestions := {}
var script := get_autoload_script_resource(autoload_name)
if script:
for property in script.get_script_property_list():
if property.name.ends_with('.gd') or property.name.begins_with('_'):
continue
suggestions[property.name] = {'value': property.name, 'tooltip':property.name, 'editor_icon': ["MemberProperty", "EditorIcons"]}

return suggestions
36 changes: 32 additions & 4 deletions addons/dialogic/Editor/Common/broken_reference_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ func display_search_results(finds:Array[Dictionary]) -> void:

%ReferenceTree.clear()
%ReferenceTree.set_column_expand(0, false)
%ReferenceTree.set_column_expand(1, false)
%ReferenceTree.set_column_custom_minimum_width(1, 50)
%ReferenceTree.create_item()

var timelines := {}
Expand All @@ -166,20 +168,25 @@ func display_search_results(finds:Array[Dictionary]) -> void:
var parent: TreeItem = null
if !i.timeline in timelines:
parent = %ReferenceTree.create_item()
parent.set_text(1, i.timeline)
parent.set_custom_color(1, get_theme_color("disabled_font_color", "Editor"))
parent.set_text(0, i.timeline)
parent.set_custom_color(0, get_theme_color("disabled_font_color", "Editor"))
parent.set_expand_right(0, true)
timelines[i.timeline] = parent
height += %ReferenceTree.get_item_area_rect(parent).size.y+10
else:
parent = timelines[i.timeline]

var item: TreeItem = %ReferenceTree.create_item(parent)
item.set_text(1, 'Line '+str(i.line_number)+': '+i.line)
item.set_tooltip_text(1, i.info.what+' -> '+i.info.forwhat)
item.set_cell_mode(0, TreeItem.CELL_MODE_CHECK)
item.set_checked(0, true)
item.set_editable(0, true)
item.set_metadata(0, i)
item.set_text(1, str(i.line_number)+':')
item.set_text_alignment(1, HORIZONTAL_ALIGNMENT_RIGHT)
item.set_cell_mode(2, TreeItem.CELL_MODE_CUSTOM)
item.set_text(2, i.line)
item.set_tooltip_text(2, i.info.what+' -> '+i.info.forwhat)
item.set_custom_draw_callback(2, _custom_draw)
height += %ReferenceTree.get_item_area_rect(item).size.y+10
var change_item: TreeItem = i.info.item
change_item.set_meta('found_items', change_item.get_meta('found_items', [])+[item])
Expand All @@ -194,6 +201,27 @@ func display_search_results(finds:Array[Dictionary]) -> void:
%Replace.grab_focus()


## Highlights the found text in the result tree
## Inspired by how godot highlights stuff in its search results
func _custom_draw(item:TreeItem, rect:Rect2) -> void:
var text := item.get_text(2)
var find := item.get_metadata(0)

var font: Font = %ReferenceTree.get_theme_font("font")
var font_size: int = %ReferenceTree.get_theme_font_size("font_size")

var match_rect := rect
var beginning_index: int = find.match.get_start("replace")-find.line_start-1
match_rect.position.x += font.get_string_size(text.left(beginning_index), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size).x -1
match_rect.size.x = font.get_string_size(find.info.what, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size).x + 1
match_rect.position.y += 1 * DialogicUtil.get_editor_scale()
match_rect.size.y -= 2 * DialogicUtil.get_editor_scale()
match_rect.position.x += 4

%ReferenceTree.draw_rect(match_rect, get_theme_color("highlight_color", "Editor"), true)
%ReferenceTree.draw_rect(match_rect, get_theme_color("box_selection_stroke_color", "Editor"), false)


func search_timelines(regexes:Array[Array]) -> Array[Dictionary]:
var finds: Array[Dictionary] = []

Expand Down
Loading
Loading