Bug markers can now give bug info when clicked

The bug marker root node is now placed directly in the scene tree, as it was
once before. Not only does this now work correctly when switching nodes, this
makes them interactible, allowing them to give information about the bug that
was clicked on, currently printed to the console.
This commit is contained in:
Jamie Greunbaum 2024-06-05 01:08:00 -04:00
parent cfe08da56c
commit c21115e97a

View File

@ -27,6 +27,10 @@ func _enter_tree() -> void:
bugbot_menu.add_item("Hide Bug Markers", BugbotMenuItems.HIDE_BUG_MARKERS) bugbot_menu.add_item("Hide Bug Markers", BugbotMenuItems.HIDE_BUG_MARKERS)
bugbot_menu.id_pressed.connect(__on_bugbot_menu_item_pressed) bugbot_menu.id_pressed.connect(__on_bugbot_menu_item_pressed)
# Set selection responses for bug markers
var selection : EditorSelection = get_editor_interface().get_selection()
selection.selection_changed.connect(__on_marker_selection_changed)
func _exit_tree() -> void: func _exit_tree() -> void:
remove_control_from_container(CustomControlContainer.CONTAINER_SPATIAL_EDITOR_MENU, __bugbot_menu_button) remove_control_from_container(CustomControlContainer.CONTAINER_SPATIAL_EDITOR_MENU, __bugbot_menu_button)
__bugbot_menu_button.queue_free() __bugbot_menu_button.queue_free()
@ -121,30 +125,38 @@ func __on_bugbot_menu_item_pressed(id:int) -> void:
func __show_editor_bug_markers() -> void: func __show_editor_bug_markers() -> void:
var scene_root : Node = EditorInterface.get_edited_scene_root() var scene_root : Node = EditorInterface.get_edited_scene_root()
var scene : String = scene_root.scene_file_path var scene : String = scene_root.scene_file_path
var tree_root : Node = scene_root.get_tree().get_root()
if __marker_root_exists(scene): if __marker_root_exists(scene):
__bugbot_marker_containers[scene].queue_free() __bugbot_marker_containers[scene].queue_free()
var marker_container : Node3D = Node3D.new()
marker_container.name = "BugMarkerContainer"
__bugbot_marker_containers[scene] = marker_container
tree_root.add_child(marker_container)
__editor_server_api = BugbotServerAPI._create_new_server_api() __editor_server_api = BugbotServerAPI._create_new_server_api()
__editor_server_api._return_list_of_bugs(scene, __show_bug_markers_response) __editor_server_api._return_list_of_bugs(scene, __show_bug_markers_response)
func __show_bug_markers_response(bug_list:Array) -> void: func __show_bug_markers_response(bug_list:Array) -> void:
var scene_root : Node = EditorInterface.get_edited_scene_root() var scene_root : Node = EditorInterface.get_edited_scene_root()
var marker_container : Node3D = __bugbot_marker_containers[scene_root.scene_file_path] var marker_container : Node3D = Node3D.new()
marker_container.name = "BugMarkerContainer"
__bugbot_marker_containers[scene_root.scene_file_path] = marker_container
scene_root.add_child(marker_container)
Bugbot.load_bug_markers(marker_container, bug_list) Bugbot.load_bug_markers(marker_container, bug_list)
func __marker_root_exists(scene_path:String) -> bool: func __marker_root_exists(scene_path:String) -> bool:
return __bugbot_marker_containers.has(scene_path) and is_instance_valid(__bugbot_marker_containers[scene_path]) return __bugbot_marker_containers.has(scene_path) and is_instance_valid(__bugbot_marker_containers[scene_path])
func __on_marker_selection_changed() -> void:
var selected : Array = get_editor_interface().get_selection().get_selected_nodes()
if selected.size() == 1:
var selected_marker : Node = selected[0]
if selected_marker is BugMarker:
print(selected_marker.bug_info.title)
func __on_editor_tab_switched(new_scene:Node) -> void: func __on_editor_tab_switched(new_scene:Node) -> void:
if __marker_root_exists(__current_edited_scene_path): if __marker_root_exists(__current_edited_scene_path):
(__bugbot_marker_containers[__current_edited_scene_path] as Node).visible = false var scene_root : Node = (__bugbot_marker_containers[__current_edited_scene_path] as Node).get_parent()
if __marker_root_exists(new_scene.scene_file_path): if scene_root:
(__bugbot_marker_containers[new_scene.scene_file_path] as Node).visible = true scene_root.remove_child(__bugbot_marker_containers[__current_edited_scene_path])
__current_edited_scene_path = new_scene.scene_file_path if new_scene:
__current_edited_scene_path = new_scene.scene_file_path
if __marker_root_exists(__current_edited_scene_path):
new_scene.add_child(__bugbot_marker_containers[new_scene.scene_file_path])
func __on_project_settings_changed() -> void: func __on_project_settings_changed() -> void:
Bugbot.adjust_bug_marker_colours() Bugbot.adjust_bug_marker_colours()