Merge pull request #98891 from Faless/debugger/game_view_settings

[Debugger] Better settings configuration for RuntimeNodeSelect and Window quit
This commit is contained in:
Thaddeus Crews 2024-11-10 12:12:46 -06:00
commit f3294e59e1
No known key found for this signature in database
GPG Key ID: 62181B86FE9E5D84
8 changed files with 79 additions and 42 deletions

View File

@ -147,3 +147,37 @@ bool DebuggerMarshalls::OutputError::deserialize(const Array &p_arr) {
CHECK_END(p_arr, idx, "OutputError"); CHECK_END(p_arr, idx, "OutputError");
return true; return true;
} }
Array DebuggerMarshalls::serialize_key_shortcut(const Ref<Shortcut> &p_shortcut) {
ERR_FAIL_COND_V(p_shortcut.is_null(), Array());
Array keys;
for (const Ref<InputEvent> ev : p_shortcut->get_events()) {
const Ref<InputEventKey> 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<Shortcut> DebuggerMarshalls::deserialize_key_shortcut(const Array &p_keys) {
Array key_events;
ERR_FAIL_COND_V(p_keys.size() % 2 != 0, Ref<Shortcut>());
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<Shortcut>();
}
Ref<Shortcut> shortcut;
shortcut.instantiate();
shortcut->set_events(key_events);
return shortcut;
}

View File

@ -31,6 +31,7 @@
#ifndef DEBUGGER_MARSHALLS_H #ifndef DEBUGGER_MARSHALLS_H
#define DEBUGGER_MARSHALLS_H #define DEBUGGER_MARSHALLS_H
#include "core/input/shortcut.h"
#include "core/object/script_language.h" #include "core/object/script_language.h"
struct DebuggerMarshalls { struct DebuggerMarshalls {
@ -68,6 +69,9 @@ struct DebuggerMarshalls {
Array serialize(); Array serialize();
bool deserialize(const Array &p_arr); bool deserialize(const Array &p_arr);
}; };
static Array serialize_key_shortcut(const Ref<Shortcut> &p_shortcut);
static Ref<Shortcut> deserialize_key_shortcut(const Array &p_keys);
}; };
#endif // DEBUGGER_MARSHALLS_H #endif // DEBUGGER_MARSHALLS_H

View File

@ -1033,6 +1033,9 @@ void ScriptEditorDebugger::start(Ref<RemoteDebuggerPeer> p_peer) {
_update_buttons_state(); _update_buttons_state();
emit_signal(SNAME("started")); 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)) { if (EditorSettings::get_singleton()->get_project_metadata("debug_options", "autostart_profiler", false)) {
profiler->set_profiling(true); profiler->set_profiling(true);
} }

View File

@ -223,11 +223,6 @@ Error EditorRun::run(const String &p_scene, const String &p_write_movie) {
args.push_back(p_scene); 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(); String exec = OS::get_singleton()->get_executable_path();
int instance_count = RunInstancesDialog::get_singleton()->get_instance_count(); int instance_count = RunInstancesDialog::get_singleton()->get_instance_count();
for (int i = 0; i < instance_count; i++) { for (int i = 0; i < instance_count; i++) {

View File

@ -30,6 +30,7 @@
#include "game_view_plugin.h" #include "game_view_plugin.h"
#include "core/debugger/debugger_marshalls.h"
#include "editor/editor_main_screen.h" #include "editor/editor_main_screen.h"
#include "editor/editor_node.h" #include "editor/editor_node.h"
#include "editor/editor_settings.h" #include "editor/editor_settings.h"
@ -40,7 +41,15 @@
#include "scene/gui/separator.h" #include "scene/gui/separator.h"
void GameViewDebugger::_session_started(Ref<EditorDebuggerSession> p_session) { void GameViewDebugger::_session_started(Ref<EditorDebuggerSession> 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; Array type;
type.append(node_type); type.append(node_type);

View File

@ -30,6 +30,7 @@
#include "scene_debugger.h" #include "scene_debugger.h"
#include "core/debugger/debugger_marshalls.h"
#include "core/debugger/engine_debugger.h" #include "core/debugger/engine_debugger.h"
#include "core/io/marshalls.h" #include "core/io/marshalls.h"
#include "core/object/script_language.h" #include "core/object/script_language.h"
@ -93,6 +94,13 @@ void SceneDebugger::deinitialize() {
} }
#ifdef DEBUG_ENABLED #ifdef DEBUG_ENABLED
void SceneDebugger::_handle_input(const Ref<InputEvent> &p_event, const Ref<Shortcut> &p_shortcut) {
Ref<InputEventKey> 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) { Error SceneDebugger::parse_message(void *p_user, const String &p_msg, const Array &p_args, bool &r_captured) {
SceneTree *scene_tree = SceneTree::get_singleton(); SceneTree *scene_tree = SceneTree::get_singleton();
if (!scene_tree) { if (!scene_tree) {
@ -109,7 +117,10 @@ Error SceneDebugger::parse_message(void *p_user, const String &p_msg, const Arra
} }
r_captured = true; 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(); live_editor->_send_tree();
} else if (p_msg == "save_node") { // Save node. } else if (p_msg == "save_node") { // Save node.
@ -271,7 +282,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 } else if (p_msg.begins_with("runtime_node_select_")) { /// Runtime Node Selection
if (p_msg == "runtime_node_select_setup") { 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") { } else if (p_msg == "runtime_node_select_set_type") {
ERR_FAIL_COND_V(p_args.is_empty(), ERR_INVALID_DATA); ERR_FAIL_COND_V(p_args.is_empty(), ERR_INVALID_DATA);
@ -1221,7 +1233,7 @@ RuntimeNodeSelect::~RuntimeNodeSelect() {
#endif // _3D_DISABLED #endif // _3D_DISABLED
} }
void RuntimeNodeSelect::_setup() { void RuntimeNodeSelect::_setup(const Dictionary &p_settings) {
Window *root = SceneTree::get_singleton()->get_root(); Window *root = SceneTree::get_singleton()->get_root();
ERR_FAIL_COND(root->is_connected(SceneStringName(window_input), callable_mp(this, &RuntimeNodeSelect::_root_window_input))); ERR_FAIL_COND(root->is_connected(SceneStringName(window_input), callable_mp(this, &RuntimeNodeSelect::_root_window_input)));
@ -1238,6 +1250,14 @@ void RuntimeNodeSelect::_setup() {
panner.instantiate(); panner.instantiate();
panner->set_callbacks(callable_mp(this, &RuntimeNodeSelect::_pan_callback), callable_mp(this, &RuntimeNodeSelect::_zoom_callback)); 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 /// 2D Selection Box Generation
sbox_2d_canvas = RS::get_singleton()->canvas_create(); sbox_2d_canvas = RS::get_singleton()->canvas_create();
@ -1347,7 +1367,7 @@ void RuntimeNodeSelect::_root_window_input(const Ref<InputEvent> &p_event) {
if (camera_override) { if (camera_override) {
if (node_select_type == NODE_TYPE_2D) { 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; return;
} }
} else if (node_select_type == NODE_TYPE_3D) { } else if (node_select_type == NODE_TYPE_3D) {

View File

@ -57,6 +57,8 @@ public:
#ifdef DEBUG_ENABLED #ifdef DEBUG_ENABLED
private: private:
static void _handle_input(const Ref<InputEvent> &p_event, const Ref<Shortcut> &p_shortcut);
static void _save_node(ObjectID id, const String &p_path); 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_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); static void _set_object_property(ObjectID p_id, const String &p_property, const Variant &p_value);
@ -201,6 +203,7 @@ private:
PopupMenu *selection_list = nullptr; PopupMenu *selection_list = nullptr;
bool selection_visible = true; bool selection_visible = true;
bool selection_update_queued = false; bool selection_update_queued = false;
bool warped_panning = false;
bool camera_override = false; bool camera_override = false;
@ -271,7 +274,7 @@ private:
NodeType node_select_type = NODE_TYPE_2D; NodeType node_select_type = NODE_TYPE_2D;
SelectMode node_select_mode = SELECT_MODE_SINGLE; SelectMode node_select_mode = SELECT_MODE_SINGLE;
void _setup(); void _setup(const Dictionary &p_settings);
void _node_set_type(NodeType p_type); void _node_set_type(NodeType p_type);
void _select_set_mode(SelectMode p_mode); void _select_set_mode(SelectMode p_mode);

View File

@ -31,10 +31,8 @@
#include "window.h" #include "window.h"
#include "core/config/project_settings.h" #include "core/config/project_settings.h"
#include "core/debugger/engine_debugger.h"
#include "core/input/shortcut.h" #include "core/input/shortcut.h"
#include "core/string/translation_server.h" #include "core/string/translation_server.h"
#include "core/variant/variant_parser.h"
#include "scene/gui/control.h" #include "scene/gui/control.h"
#include "scene/theme/theme_db.h" #include "scene/theme/theme_db.h"
#include "scene/theme/theme_owner.h" #include "scene/theme/theme_owner.h"
@ -1631,35 +1629,6 @@ bool Window::_can_consume_input_events() const {
void Window::_window_input(const Ref<InputEvent> &p_ev) { void Window::_window_input(const Ref<InputEvent> &p_ev) {
ERR_MAIN_THREAD_GUARD; 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<InputEventKey> 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 (exclusive_child != nullptr) {
if (!is_embedding_subwindows()) { // Not embedding, no need for event. if (!is_embedding_subwindows()) { // Not embedding, no need for event.