Godot Engine – Multi-platform 2D and 3D game engine
Make temporary pivot centering shortcut work in the Game view
Michael Alexsandera46a97a580e3
diff --git a/editor/run/game_view_plugin.cpp b/editor/run/game_view_plugin.cppindex 3c528c02bc8..a9cec8e86cd 100644--- a/editor/run/game_view_plugin.cpp+++ b/editor/run/game_view_plugin.cpp@@ -145,7 +145,7 @@ void GameViewDebugger::_session_started(Ref<EditorDebuggerSession> p_session) {p_session->send_message("scene:runtime_node_select_setup", { settings });p_session->send_message("scene:runtime_node_select_set_node_type", { node_type });p_session->send_message("scene:runtime_node_select_set_selection_visible", { selection_visible });- p_session->send_message("scene:runtime_node_select_set_ci_tool", { ci_tool });+ p_session->send_message("scene:runtime_node_select_set_ci_tool", { ci_tool, false });if (!is_native) {p_session->send_message("scene:runtime_node_select_set_ci_local_space", { ci_local_space });}@@ -296,6 +296,7 @@ void GameViewDebugger::set_ci_tool(int p_tool) {Array message;message.append(p_tool);+ message.append(Input::get_singleton()->is_key_pressed(Key::SHIFT));for (Ref<EditorDebuggerSession> &I : sessions) {if (I->is_active()) {diff --git a/editor/scene/canvas_item_editor_plugin.cpp b/editor/scene/canvas_item_editor_plugin.cppindex 0692a14de80..f89dc0b6dfa 100644--- a/editor/scene/canvas_item_editor_plugin.cpp+++ b/editor/scene/canvas_item_editor_plugin.cpp@@ -2951,6 +2951,9 @@ void CanvasItemEditor::_button_tool_select(int p_index) {}ci_manipulator->set_tool((CanvasItemManipulator::Tool)p_index);+ if (ci_manipulator->get_tool() == CanvasItemManipulator::TOOL_EDIT_PIVOT && Input::get_singleton()->is_key_pressed(Key::SHIFT)) {+ ci_manipulator->center_temp_pivot_on_selection();+ }viewport->queue_redraw();emit_signal("canvas_item_tool_changed", ci_manipulator->get_tool());diff --git a/scene/debugger/canvas_item_manipulator.cpp b/scene/debugger/canvas_item_manipulator.cppindex f7521f1a6a8..5506eb7426c 100644--- a/scene/debugger/canvas_item_manipulator.cpp+++ b/scene/debugger/canvas_item_manipulator.cpp@@ -1893,6 +1893,21 @@ bool CanvasItemManipulator::reset_temp_pivot() {return false;}+void CanvasItemManipulator::center_temp_pivot_on_selection() {+ Array selection;+ get_selection_callback.call(selection);++ if (!selection.is_empty()) {+ Vector2 center;+ for (const Variant &var : selection) {+ const CanvasItem *ci = Object::cast_to<CanvasItem>(var);+ Transform2D xform = ci->get_screen_transform() * ci->get_transform().affine_inverse();+ center += xform.xform(ci->_edit_get_position());+ }+ temp_pivot = center / selection.size();+ }+}+void CanvasItemManipulator::set_shortcut(const ShortcutName p_name, const Ref<Shortcut> &p_shortcut) {ERR_FAIL_INDEX(0, SHORTCUT_MAX);inputs[p_name] = p_shortcut;@@ -2276,25 +2291,12 @@ void CanvasItemManipulator::set_tool(Tool p_tool) {if (drag_type != DRAG_NONE) {commit_drag();}+#endiftool = p_tool;- if (p_tool == TOOL_EDIT_PIVOT && Input::get_singleton()->is_key_pressed(Key::SHIFT)) {- // Special action that places temporary rotation pivot in the middle of the selection.- Array selection;- get_selection_callback.call(selection);-- if (!selection.is_empty()) {- Vector2 center;- for (const Variant &var : selection) {- const CanvasItem *ci = Object::cast_to<CanvasItem>(var);- center += ci->get_viewport()->get_popup_base_transform().xform(ci->_edit_get_position());- }- temp_pivot = center / selection.size();- }- }-#else- tool = p_tool;+#ifdef TOOLS_ENABLED+ center_temp_pivot_on_selection();#endif}diff --git a/scene/debugger/canvas_item_manipulator.h b/scene/debugger/canvas_item_manipulator.hindex dc50719496f..dc2dbcc8275 100644--- a/scene/debugger/canvas_item_manipulator.h+++ b/scene/debugger/canvas_item_manipulator.h@@ -278,6 +278,7 @@ public:void commit_drag();bool reset_temp_pivot();+ void center_temp_pivot_on_selection();void set_local_space_enabled(bool p_enabled) { local_space = p_enabled; }void set_anchors_mode_enabled(bool p_enabled) { anchors_mode = p_enabled; }diff --git a/scene/debugger/runtime_node_select.cpp b/scene/debugger/runtime_node_select.cppindex c0717e2a3b1..61db69a3c6c 100644--- a/scene/debugger/runtime_node_select.cpp+++ b/scene/debugger/runtime_node_select.cpp@@ -347,12 +347,18 @@ void RuntimeNodeSelect::_set_camera_override_enabled(bool p_enabled) {Camera3D *override_camera = root->get_override_camera_3d();override_camera->set_transform(view_3d_controller->to_camera_transform());override_camera->set_perspective(camera_fov * view_3d_controller->cursor.fov_scale, camera_znear, camera_zfar);-#endif // _3D_DISABLED+#endif}}-void RuntimeNodeSelect::_set_ci_tool(CanvasItemManipulator::Tool p_tool) {+void RuntimeNodeSelect::_set_ci_tool(CanvasItemManipulator::Tool p_tool, bool p_shift_pressed) {ci_manipulator->set_tool(p_tool);+#ifdef TOOLS_ENABLED+ if (p_shift_pressed && ci_manipulator->get_tool() == CanvasItemManipulator::TOOL_EDIT_PIVOT) {+ ci_manipulator->center_temp_pivot_on_selection();+ }+#endif+panner->set_force_drag(p_tool == CanvasItemManipulator::TOOL_PAN);_queue_selection_update();}diff --git a/scene/debugger/runtime_node_select.h b/scene/debugger/runtime_node_select.hindex 807aad86190..35e3d613502 100644--- a/scene/debugger/runtime_node_select.h+++ b/scene/debugger/runtime_node_select.h@@ -164,7 +164,7 @@ private:void _set_node_type(NodeType p_type);void _set_camera_override_enabled(bool p_enabled);- void _set_ci_tool(CanvasItemManipulator::Tool p_tool);+ void _set_ci_tool(CanvasItemManipulator::Tool p_tool, bool p_shift_pressed);#ifdef TOOLS_ENABLEDvoid _set_ci_local_space(bool p_enabled);#endifdiff --git a/scene/debugger/scene_debugger.cpp b/scene/debugger/scene_debugger.cppindex bd5fd30c046..699838caf4b 100644--- a/scene/debugger/scene_debugger.cpp+++ b/scene/debugger/scene_debugger.cpp@@ -226,7 +226,7 @@ Error SceneDebugger::_msg_request_scene_tree(const Array &p_args) {}Error SceneDebugger::_msg_save_node(const Array &p_args) {- ERR_FAIL_COND_V(p_args.size() < 2, ERR_INVALID_DATA);+ ERR_FAIL_COND_V(p_args.size() != 2, ERR_INVALID_DATA);_save_node(p_args[0], p_args[1]);Array arr;arr.append(p_args[1]);@@ -537,9 +537,10 @@ Error SceneDebugger::_msg_runtime_node_select_set_node_type(const Array &p_args)}Error SceneDebugger::_msg_runtime_node_select_set_ci_tool(const Array &p_args) {- ERR_FAIL_COND_V(p_args.is_empty(), ERR_INVALID_DATA);+ ERR_FAIL_COND_V(p_args.size() != 2, ERR_INVALID_DATA);CanvasItemManipulator::Tool tool = (CanvasItemManipulator::Tool)p_args[0];- RuntimeNodeSelect::get_singleton()->_set_ci_tool(tool);+ bool shift_pressed = p_args[1];+ RuntimeNodeSelect::get_singleton()->_set_ci_tool(tool, shift_pressed);return OK;}