Merge pull request #96124 from AeioMuch/check_mouse_pos_inside_inspector

Prevent selecting the hovered node if the mouse is not inside the inspector dock
This commit is contained in:
Rémi Verschelde 2024-10-01 17:30:41 +02:00
commit 0fd62f7525
No known key found for this signature in database
GPG Key ID: C3336907360768E1

View File

@ -88,6 +88,8 @@ void SceneTreeDock::_inspect_hovered_node() {
tree_item_inspected = item; tree_item_inspected = item;
tree_item_inspected->set_custom_color(0, get_theme_color(SNAME("accent_color"), EditorStringName(Editor))); tree_item_inspected->set_custom_color(0, get_theme_color(SNAME("accent_color"), EditorStringName(Editor)));
} }
EditorSelectionHistory *editor_history = EditorNode::get_singleton()->get_editor_selection_history();
editor_history->add_object(node_hovered_now->get_instance_id());
InspectorDock::get_inspector_singleton()->edit(node_hovered_now); InspectorDock::get_inspector_singleton()->edit(node_hovered_now);
InspectorDock::get_inspector_singleton()->propagate_notification(NOTIFICATION_DRAG_BEGIN); // Enable inspector drag preview after it updated. InspectorDock::get_inspector_singleton()->propagate_notification(NOTIFICATION_DRAG_BEGIN); // Enable inspector drag preview after it updated.
InspectorDock::get_singleton()->update(node_hovered_now); InspectorDock::get_singleton()->update(node_hovered_now);
@ -133,14 +135,6 @@ void SceneTreeDock::input(const Ref<InputEvent> &p_event) {
_push_item(pending_click_select); _push_item(pending_click_select);
pending_click_select = nullptr; pending_click_select = nullptr;
} }
if (mb->is_released()) {
if (tree_item_inspected) {
tree_item_inspected->clear_custom_color(0);
tree_item_inspected = nullptr;
}
_reset_hovering_timer();
}
} }
if (tree_clicked && get_viewport()->gui_is_dragging()) { if (tree_clicked && get_viewport()->gui_is_dragging()) {
@ -1718,13 +1712,30 @@ void SceneTreeDock::_notification(int p_what) {
case NOTIFICATION_DRAG_END: { case NOTIFICATION_DRAG_END: {
_reset_hovering_timer(); _reset_hovering_timer();
if (select_node_hovered_at_end_of_drag && !hovered_but_reparenting) { if (tree_item_inspected) {
Node *node_inspected = Object::cast_to<Node>(InspectorDock::get_inspector_singleton()->get_edited_object()); tree_item_inspected->clear_custom_color(0);
if (node_inspected) { tree_item_inspected = nullptr;
} else {
return;
}
if (!hovered_but_reparenting) {
InspectorDock *inspector_dock = InspectorDock::get_singleton();
if (!inspector_dock->get_rect().has_point(inspector_dock->get_local_mouse_position())) {
List<Node *> full_selection = editor_selection->get_full_selected_node_list();
editor_selection->clear(); editor_selection->clear();
editor_selection->add_node(node_inspected); for (Node *E : full_selection) {
scene_tree->set_selected(node_inspected); editor_selection->add_node(E);
select_node_hovered_at_end_of_drag = false; }
return;
}
if (select_node_hovered_at_end_of_drag) {
Node *node_inspected = Object::cast_to<Node>(InspectorDock::get_inspector_singleton()->get_edited_object());
if (node_inspected) {
editor_selection->clear();
editor_selection->add_node(node_inspected);
scene_tree->set_selected(node_inspected);
select_node_hovered_at_end_of_drag = false;
}
} }
} }
hovered_but_reparenting = false; hovered_but_reparenting = false;
@ -4644,7 +4655,6 @@ SceneTreeDock::SceneTreeDock(Node *p_scene_root, EditorSelection *p_editor_selec
scene_tree->connect("files_dropped", callable_mp(this, &SceneTreeDock::_files_dropped)); scene_tree->connect("files_dropped", callable_mp(this, &SceneTreeDock::_files_dropped));
scene_tree->connect("script_dropped", callable_mp(this, &SceneTreeDock::_script_dropped)); scene_tree->connect("script_dropped", callable_mp(this, &SceneTreeDock::_script_dropped));
scene_tree->connect("nodes_dragged", callable_mp(this, &SceneTreeDock::_nodes_drag_begin)); scene_tree->connect("nodes_dragged", callable_mp(this, &SceneTreeDock::_nodes_drag_begin));
scene_tree->connect(SceneStringName(mouse_exited), callable_mp(this, &SceneTreeDock::_reset_hovering_timer));
scene_tree->get_scene_tree()->connect(SceneStringName(gui_input), callable_mp(this, &SceneTreeDock::_scene_tree_gui_input)); scene_tree->get_scene_tree()->connect(SceneStringName(gui_input), callable_mp(this, &SceneTreeDock::_scene_tree_gui_input));
scene_tree->get_scene_tree()->connect("item_icon_double_clicked", callable_mp(this, &SceneTreeDock::_focus_node)); scene_tree->get_scene_tree()->connect("item_icon_double_clicked", callable_mp(this, &SceneTreeDock::_focus_node));