mirror of
https://github.com/godotengine/godot.git
synced 2024-11-21 11:32:13 +00:00
[Debugger] Move quit shortcut configuration to the SceneDebugger
This commit is contained in:
parent
87318a2fb7
commit
7cd850b909
@ -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<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;
|
||||
}
|
||||
|
@ -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<Shortcut> &p_shortcut);
|
||||
static Ref<Shortcut> deserialize_key_shortcut(const Array &p_keys);
|
||||
};
|
||||
|
||||
#endif // DEBUGGER_MARSHALLS_H
|
||||
|
@ -1033,6 +1033,9 @@ void ScriptEditorDebugger::start(Ref<RemoteDebuggerPeer> 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);
|
||||
}
|
||||
|
@ -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++) {
|
||||
|
@ -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<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) {
|
||||
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.
|
||||
|
@ -57,6 +57,8 @@ public:
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
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 _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);
|
||||
|
@ -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<InputEvent> &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<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 (!is_embedding_subwindows()) { // Not embedding, no need for event.
|
||||
|
Loading…
Reference in New Issue
Block a user