From 7cd850b90989d032a9b4942514252eb9f607c4e7 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Wed, 6 Nov 2024 16:47:36 +0100 Subject: [PATCH 1/2] [Debugger] Move quit shortcut configuration to the SceneDebugger --- core/debugger/debugger_marshalls.cpp | 34 ++++++++++++++++++++++ core/debugger/debugger_marshalls.h | 4 +++ editor/debugger/script_editor_debugger.cpp | 3 ++ editor/editor_run.cpp | 5 ---- scene/debugger/scene_debugger.cpp | 13 ++++++++- scene/debugger/scene_debugger.h | 2 ++ scene/main/window.cpp | 31 -------------------- 7 files changed, 55 insertions(+), 37 deletions(-) diff --git a/core/debugger/debugger_marshalls.cpp b/core/debugger/debugger_marshalls.cpp index f4283e0ea9c..cc36ca4816a 100644 --- a/core/debugger/debugger_marshalls.cpp +++ b/core/debugger/debugger_marshalls.cpp @@ -147,3 +147,37 @@ bool DebuggerMarshalls::OutputError::deserialize(const Array &p_arr) { CHECK_END(p_arr, idx, "OutputError"); return true; } + +Array DebuggerMarshalls::serialize_key_shortcut(const Ref &p_shortcut) { + ERR_FAIL_COND_V(p_shortcut.is_null(), Array()); + Array keys; + for (const Ref ev : p_shortcut->get_events()) { + const Ref kev = ev; + ERR_CONTINUE(kev.is_null()); + if (kev->get_physical_keycode() != Key::NONE) { + keys.push_back(true); + keys.push_back(kev->get_physical_keycode_with_modifiers()); + } else { + keys.push_back(false); + keys.push_back(kev->get_keycode_with_modifiers()); + } + } + return keys; +} + +Ref DebuggerMarshalls::deserialize_key_shortcut(const Array &p_keys) { + Array key_events; + ERR_FAIL_COND_V(p_keys.size() % 2 != 0, Ref()); + for (int i = 0; i < p_keys.size(); i += 2) { + ERR_CONTINUE(p_keys[i].get_type() != Variant::BOOL); + ERR_CONTINUE(p_keys[i + 1].get_type() != Variant::INT); + key_events.push_back(InputEventKey::create_reference((Key)p_keys[i + 1].operator int(), p_keys[i].operator bool())); + } + if (key_events.is_empty()) { + return Ref(); + } + Ref shortcut; + shortcut.instantiate(); + shortcut->set_events(key_events); + return shortcut; +} diff --git a/core/debugger/debugger_marshalls.h b/core/debugger/debugger_marshalls.h index 1b81623688e..1072ddaeb7f 100644 --- a/core/debugger/debugger_marshalls.h +++ b/core/debugger/debugger_marshalls.h @@ -31,6 +31,7 @@ #ifndef DEBUGGER_MARSHALLS_H #define DEBUGGER_MARSHALLS_H +#include "core/input/shortcut.h" #include "core/object/script_language.h" struct DebuggerMarshalls { @@ -68,6 +69,9 @@ struct DebuggerMarshalls { Array serialize(); bool deserialize(const Array &p_arr); }; + + static Array serialize_key_shortcut(const Ref &p_shortcut); + static Ref deserialize_key_shortcut(const Array &p_keys); }; #endif // DEBUGGER_MARSHALLS_H diff --git a/editor/debugger/script_editor_debugger.cpp b/editor/debugger/script_editor_debugger.cpp index b78aad17218..52fd3416fa8 100644 --- a/editor/debugger/script_editor_debugger.cpp +++ b/editor/debugger/script_editor_debugger.cpp @@ -1033,6 +1033,9 @@ void ScriptEditorDebugger::start(Ref p_peer) { _update_buttons_state(); emit_signal(SNAME("started")); + Array quit_keys = DebuggerMarshalls::serialize_key_shortcut(ED_GET_SHORTCUT("editor/stop_running_project")); + _put_msg("scene:setup_scene", quit_keys); + if (EditorSettings::get_singleton()->get_project_metadata("debug_options", "autostart_profiler", false)) { profiler->set_profiling(true); } diff --git a/editor/editor_run.cpp b/editor/editor_run.cpp index d5135f41984..caed02ae58e 100644 --- a/editor/editor_run.cpp +++ b/editor/editor_run.cpp @@ -223,11 +223,6 @@ Error EditorRun::run(const String &p_scene, const String &p_write_movie) { args.push_back(p_scene); } - // Pass the debugger stop shortcut to the running instance(s). - String shortcut; - VariantWriter::write_to_string(ED_GET_SHORTCUT("editor/stop_running_project"), shortcut); - OS::get_singleton()->set_environment("__GODOT_EDITOR_STOP_SHORTCUT__", shortcut); - String exec = OS::get_singleton()->get_executable_path(); int instance_count = RunInstancesDialog::get_singleton()->get_instance_count(); for (int i = 0; i < instance_count; i++) { diff --git a/scene/debugger/scene_debugger.cpp b/scene/debugger/scene_debugger.cpp index b87285ed74f..bcad4e966a2 100644 --- a/scene/debugger/scene_debugger.cpp +++ b/scene/debugger/scene_debugger.cpp @@ -30,6 +30,7 @@ #include "scene_debugger.h" +#include "core/debugger/debugger_marshalls.h" #include "core/debugger/engine_debugger.h" #include "core/io/marshalls.h" #include "core/object/script_language.h" @@ -93,6 +94,13 @@ void SceneDebugger::deinitialize() { } #ifdef DEBUG_ENABLED +void SceneDebugger::_handle_input(const Ref &p_event, const Ref &p_shortcut) { + Ref k = p_event; + if (k.is_valid() && k->is_pressed() && !k->is_echo() && p_shortcut->matches_event(k)) { + EngineDebugger::get_singleton()->send_message("request_quit", Array()); + } +} + Error SceneDebugger::parse_message(void *p_user, const String &p_msg, const Array &p_args, bool &r_captured) { SceneTree *scene_tree = SceneTree::get_singleton(); if (!scene_tree) { @@ -109,7 +117,10 @@ Error SceneDebugger::parse_message(void *p_user, const String &p_msg, const Arra } r_captured = true; - if (p_msg == "request_scene_tree") { // Scene tree + if (p_msg == "setup_scene") { + SceneTree::get_singleton()->get_root()->connect(SceneStringName(window_input), callable_mp_static(SceneDebugger::_handle_input).bind(DebuggerMarshalls::deserialize_key_shortcut(p_args))); + + } else if (p_msg == "request_scene_tree") { // Scene tree live_editor->_send_tree(); } else if (p_msg == "save_node") { // Save node. diff --git a/scene/debugger/scene_debugger.h b/scene/debugger/scene_debugger.h index f9dd6161aa3..1da3d526320 100644 --- a/scene/debugger/scene_debugger.h +++ b/scene/debugger/scene_debugger.h @@ -57,6 +57,8 @@ public: #ifdef DEBUG_ENABLED private: + static void _handle_input(const Ref &p_event, const Ref &p_shortcut); + static void _save_node(ObjectID id, const String &p_path); static void _set_node_owner_recursive(Node *p_node, Node *p_owner); static void _set_object_property(ObjectID p_id, const String &p_property, const Variant &p_value); diff --git a/scene/main/window.cpp b/scene/main/window.cpp index 045c3ae02d8..fc2fe4320b3 100644 --- a/scene/main/window.cpp +++ b/scene/main/window.cpp @@ -31,10 +31,8 @@ #include "window.h" #include "core/config/project_settings.h" -#include "core/debugger/engine_debugger.h" #include "core/input/shortcut.h" #include "core/string/translation_server.h" -#include "core/variant/variant_parser.h" #include "scene/gui/control.h" #include "scene/theme/theme_db.h" #include "scene/theme/theme_owner.h" @@ -1631,35 +1629,6 @@ bool Window::_can_consume_input_events() const { void Window::_window_input(const Ref &p_ev) { ERR_MAIN_THREAD_GUARD; - if (EngineDebugger::is_active()) { - // Quit from game window using the stop shortcut (F8 by default). - // The custom shortcut is provided via environment variable when running from the editor. - if (debugger_stop_shortcut.is_null()) { - String shortcut_str = OS::get_singleton()->get_environment("__GODOT_EDITOR_STOP_SHORTCUT__"); - if (!shortcut_str.is_empty()) { - Variant shortcut_var; - - VariantParser::StreamString ss; - ss.s = shortcut_str; - - String errs; - int line; - VariantParser::parse(&ss, shortcut_var, errs, line); - debugger_stop_shortcut = shortcut_var; - } - - if (debugger_stop_shortcut.is_null()) { - // Define a default shortcut if it wasn't provided or is invalid. - debugger_stop_shortcut.instantiate(); - debugger_stop_shortcut->set_events({ (Variant)InputEventKey::create_reference(Key::F8) }); - } - } - - Ref k = p_ev; - if (k.is_valid() && k->is_pressed() && !k->is_echo() && debugger_stop_shortcut->matches_event(k)) { - EngineDebugger::get_singleton()->send_message("request_quit", Array()); - } - } if (exclusive_child != nullptr) { if (!is_embedding_subwindows()) { // Not embedding, no need for event. From c3e2e468554881c021aa2123efe295c147df3f46 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Wed, 6 Nov 2024 04:01:58 +0100 Subject: [PATCH 2/2] [Debugger] Add configuration to the GameView debugger plugin --- editor/plugins/game_view_plugin.cpp | 11 ++++++++++- scene/debugger/scene_debugger.cpp | 15 ++++++++++++--- scene/debugger/scene_debugger.h | 3 ++- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/editor/plugins/game_view_plugin.cpp b/editor/plugins/game_view_plugin.cpp index f45af72e909..5c1f81ee94e 100644 --- a/editor/plugins/game_view_plugin.cpp +++ b/editor/plugins/game_view_plugin.cpp @@ -30,6 +30,7 @@ #include "game_view_plugin.h" +#include "core/debugger/debugger_marshalls.h" #include "editor/editor_main_screen.h" #include "editor/editor_node.h" #include "editor/editor_settings.h" @@ -40,7 +41,15 @@ #include "scene/gui/separator.h" void GameViewDebugger::_session_started(Ref p_session) { - p_session->send_message("scene:runtime_node_select_setup", Array()); + Array setup_data; + Dictionary settings; + settings["editors/panning/2d_editor_panning_scheme"] = EDITOR_GET("editors/panning/2d_editor_panning_scheme"); + settings["editors/panning/simple_panning"] = EDITOR_GET("editors/panning/simple_panning"); + settings["editors/panning/warped_mouse_panning"] = EDITOR_GET("editors/panning/warped_mouse_panning"); + settings["editors/panning/2d_editor_pan_speed"] = EDITOR_GET("editors/panning/2d_editor_pan_speed"); + settings["canvas_item_editor/pan_view"] = DebuggerMarshalls::serialize_key_shortcut(ED_GET_SHORTCUT("canvas_item_editor/pan_view")); + setup_data.append(settings); + p_session->send_message("scene:runtime_node_select_setup", setup_data); Array type; type.append(node_type); diff --git a/scene/debugger/scene_debugger.cpp b/scene/debugger/scene_debugger.cpp index bcad4e966a2..35b8e3fe27a 100644 --- a/scene/debugger/scene_debugger.cpp +++ b/scene/debugger/scene_debugger.cpp @@ -280,7 +280,8 @@ Error SceneDebugger::parse_message(void *p_user, const String &p_msg, const Arra } else if (p_msg.begins_with("runtime_node_select_")) { /// Runtime Node Selection if (p_msg == "runtime_node_select_setup") { - runtime_node_select->_setup(); + ERR_FAIL_COND_V(p_args.is_empty() || p_args[0].get_type() != Variant::DICTIONARY, ERR_INVALID_DATA); + runtime_node_select->_setup(p_args[0]); } else if (p_msg == "runtime_node_select_set_type") { ERR_FAIL_COND_V(p_args.is_empty(), ERR_INVALID_DATA); @@ -1221,7 +1222,7 @@ RuntimeNodeSelect::~RuntimeNodeSelect() { #endif // _3D_DISABLED } -void RuntimeNodeSelect::_setup() { +void RuntimeNodeSelect::_setup(const Dictionary &p_settings) { Window *root = SceneTree::get_singleton()->get_root(); ERR_FAIL_COND(root->is_connected(SceneStringName(window_input), callable_mp(this, &RuntimeNodeSelect::_root_window_input))); @@ -1238,6 +1239,14 @@ void RuntimeNodeSelect::_setup() { panner.instantiate(); panner->set_callbacks(callable_mp(this, &RuntimeNodeSelect::_pan_callback), callable_mp(this, &RuntimeNodeSelect::_zoom_callback)); + ViewPanner::ControlScheme panning_scheme = (ViewPanner::ControlScheme)p_settings.get("editors/panning/2d_editor_panning_scheme", 0).operator int(); + bool simple_panning = p_settings.get("editors/panning/simple_panning", false); + int pan_speed = p_settings.get("editors/panning/2d_editor_pan_speed", 20); + Array keys = p_settings.get("canvas_item_editor/pan_view", Array()).operator Array(); + panner->setup(panning_scheme, DebuggerMarshalls::deserialize_key_shortcut(keys), simple_panning); + panner->set_scroll_speed(pan_speed); + warped_panning = p_settings.get("editors/panning/warped_mouse_panning", false); + /// 2D Selection Box Generation sbox_2d_canvas = RS::get_singleton()->canvas_create(); @@ -1347,7 +1356,7 @@ void RuntimeNodeSelect::_root_window_input(const Ref &p_event) { if (camera_override) { if (node_select_type == NODE_TYPE_2D) { - if (panner->gui_input(p_event, Rect2(Vector2(), root->get_size()))) { + if (panner->gui_input(p_event, warped_panning ? Rect2(Vector2(), root->get_size()) : Rect2())) { return; } } else if (node_select_type == NODE_TYPE_3D) { diff --git a/scene/debugger/scene_debugger.h b/scene/debugger/scene_debugger.h index 1da3d526320..efdf3efa0fe 100644 --- a/scene/debugger/scene_debugger.h +++ b/scene/debugger/scene_debugger.h @@ -202,6 +202,7 @@ private: PopupMenu *selection_list = nullptr; bool selection_visible = true; bool selection_update_queued = false; + bool warped_panning = false; bool camera_override = false; @@ -272,7 +273,7 @@ private: NodeType node_select_type = NODE_TYPE_2D; SelectMode node_select_mode = SELECT_MODE_SINGLE; - void _setup(); + void _setup(const Dictionary &p_settings); void _node_set_type(NodeType p_type); void _select_set_mode(SelectMode p_mode);