Merge pull request #61162 from KoBeWi/drag_nodes_like_a_boss

This commit is contained in:
Rémi Verschelde 2022-05-23 22:08:03 +02:00 committed by GitHub
commit 3c9cc7914a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 16 deletions

View file

@ -59,10 +59,7 @@
#endif // MODULE_REGEX_ENABLED
void SceneTreeDock::_nodes_drag_begin() {
if (restore_script_editor_on_drag) {
EditorNode::get_singleton()->set_visible_editor(EditorNode::EDITOR_SCRIPT);
restore_script_editor_on_drag = false;
}
pending_click_select = nullptr;
}
void SceneTreeDock::_quick_open() {
@ -74,8 +71,9 @@ void SceneTreeDock::input(const Ref<InputEvent> &p_event) {
Ref<InputEventMouseButton> mb = p_event;
if (mb.is_valid() && !mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT) {
restore_script_editor_on_drag = false; //lost chance
if (pending_click_select && mb.is_valid() && !mb->is_pressed() && (mb->get_button_index() == MouseButton::LEFT || mb->get_button_index() == MouseButton::RIGHT)) {
_push_item(pending_click_select);
pending_click_select = nullptr;
}
}
@ -1369,8 +1367,14 @@ void SceneTreeDock::_script_open_request(const Ref<Script> &p_script) {
}
void SceneTreeDock::_push_item(Object *p_object) {
if (!Input::get_singleton()->is_key_pressed(Key::ALT)) {
EditorNode::get_singleton()->push_item(p_object);
EditorNode::get_singleton()->push_item(p_object);
}
void SceneTreeDock::_handle_select(Node *p_node) {
if ((Input::get_singleton()->get_mouse_button_mask() & (MouseButton::MASK_LEFT | MouseButton::MASK_RIGHT)) != MouseButton::NONE) {
pending_click_select = p_node;
} else {
EditorNode::get_singleton()->push_item(p_node);
}
}
@ -1380,12 +1384,7 @@ void SceneTreeDock::_node_selected() {
if (!node) {
return;
}
if (ScriptEditor::get_singleton()->is_visible_in_tree()) {
restore_script_editor_on_drag = true;
}
_push_item(node);
_handle_select(node);
}
void SceneTreeDock::_node_renamed() {
@ -2148,7 +2147,7 @@ void SceneTreeDock::_selection_changed() {
//automatically turn on multi-edit
_tool_selected(TOOL_MULTI_EDIT);
} else if (selection_size == 1) {
_push_item(editor_selection->get_selection().begin()->key);
_handle_select(editor_selection->get_selection().begin()->key);
} else if (selection_size == 0) {
_push_item(nullptr);
}

View file

@ -105,7 +105,6 @@ class SceneTreeDock : public VBoxContainer {
Vector<ObjectID> subresources;
bool restore_script_editor_on_drag = false;
bool reset_create_dialog = false;
int current_option = 0;
@ -172,6 +171,7 @@ class SceneTreeDock : public VBoxContainer {
void _do_create(Node *p_parent);
Node *scene_root = nullptr;
Node *edited_scene = nullptr;
Node *pending_click_select = nullptr;
VBoxContainer *create_root_dialog = nullptr;
String selected_favorite_root;
@ -198,6 +198,7 @@ class SceneTreeDock : public VBoxContainer {
void _load_request(const String &p_path);
void _script_open_request(const Ref<Script> &p_script);
void _push_item(Object *p_object);
void _handle_select(Node *p_node);
bool _cyclical_dependency_exists(const String &p_target_scene_path, Node *p_desired_node);
bool _track_inherit(const String &p_target_scene_path, Node *p_desired_node);