From 4d623b70d726309ccec31698fc639fb4f8bc4ae5 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Sun, 8 Mar 2020 18:58:31 +0100 Subject: Move Debug menu logic to DebuggerEditorPlugin --- editor/plugins/debugger_editor_plugin.cpp | 143 +++++++++++++++++++++++++++++- 1 file changed, 142 insertions(+), 1 deletion(-) (limited to 'editor/plugins/debugger_editor_plugin.cpp') diff --git a/editor/plugins/debugger_editor_plugin.cpp b/editor/plugins/debugger_editor_plugin.cpp index 2534a2cc17..6e74f8fcf3 100644 --- a/editor/plugins/debugger_editor_plugin.cpp +++ b/editor/plugins/debugger_editor_plugin.cpp @@ -32,8 +32,11 @@ #include "core/os/keyboard.h" #include "editor/debugger/editor_debugger_node.h" +#include "editor/editor_node.h" +#include "editor/fileserver/editor_file_server.h" +#include "scene/gui/menu_button.h" -DebuggerEditorPlugin::DebuggerEditorPlugin(EditorNode *p_editor) { +DebuggerEditorPlugin::DebuggerEditorPlugin(EditorNode *p_editor, MenuButton *p_debug_menu) { ED_SHORTCUT("debugger/step_into", TTR("Step Into"), KEY_F11); ED_SHORTCUT("debugger/step_over", TTR("Step Over"), KEY_F10); ED_SHORTCUT("debugger/break", TTR("Break")); @@ -41,11 +44,149 @@ DebuggerEditorPlugin::DebuggerEditorPlugin(EditorNode *p_editor) { ED_SHORTCUT("debugger/keep_debugger_open", TTR("Keep Debugger Open")); ED_SHORTCUT("debugger/debug_with_external_editor", TTR("Debug with External Editor")); + // File Server for deploy with remote fs. + file_server = memnew(EditorFileServer); + EditorDebuggerNode *debugger = memnew(EditorDebuggerNode); Button *db = EditorNode::get_singleton()->add_bottom_panel_item(TTR("Debugger"), debugger); debugger->set_tool_button(db); + + // Main editor debug menu. + debug_menu = p_debug_menu; + PopupMenu *p = debug_menu->get_popup(); + p->set_hide_on_window_lose_focus(true); + p->set_hide_on_checkable_item_selection(false); + p->add_check_shortcut(ED_SHORTCUT("editor/deploy_with_remote_debug", TTR("Deploy with Remote Debug")), RUN_DEPLOY_REMOTE_DEBUG); + p->set_item_tooltip(p->get_item_count() - 1, TTR("When exporting or deploying, the resulting executable will attempt to connect to the IP of this computer in order to be debugged.")); + p->add_check_shortcut(ED_SHORTCUT("editor/small_deploy_with_network_fs", TTR("Small Deploy with Network FS")), RUN_FILE_SERVER); + p->set_item_tooltip(p->get_item_count() - 1, TTR("When this option is enabled, export or deploy will produce a minimal executable.\nThe filesystem will be provided from the project by the editor over the network.\nOn Android, deploy will use the USB cable for faster performance. This option speeds up testing for games with a large footprint.")); + p->add_separator(); + p->add_check_shortcut(ED_SHORTCUT("editor/visible_collision_shapes", TTR("Visible Collision Shapes")), RUN_DEBUG_COLLISONS); + p->set_item_tooltip(p->get_item_count() - 1, TTR("Collision shapes and raycast nodes (for 2D and 3D) will be visible on the running game if this option is turned on.")); + p->add_check_shortcut(ED_SHORTCUT("editor/visible_navigation", TTR("Visible Navigation")), RUN_DEBUG_NAVIGATION); + p->set_item_tooltip(p->get_item_count() - 1, TTR("Navigation meshes and polygons will be visible on the running game if this option is turned on.")); + p->add_separator(); + //those are now on by default, since they are harmless + p->add_check_shortcut(ED_SHORTCUT("editor/sync_scene_changes", TTR("Sync Scene Changes")), RUN_LIVE_DEBUG); + p->set_item_tooltip(p->get_item_count() - 1, TTR("When this option is turned on, any changes made to the scene in the editor will be replicated in the running game.\nWhen used remotely on a device, this is more efficient with network filesystem.")); + p->set_item_checked(p->get_item_count() - 1, true); + p->add_check_shortcut(ED_SHORTCUT("editor/sync_script_changes", TTR("Sync Script Changes")), RUN_RELOAD_SCRIPTS); + p->set_item_tooltip(p->get_item_count() - 1, TTR("When this option is turned on, any script that is saved will be reloaded on the running game.\nWhen used remotely on a device, this is more efficient with network filesystem.")); + p->set_item_checked(p->get_item_count() - 1, true); + + // Multi-instance, start/stop + p->add_separator(); + p->add_radio_check_item(TTR("Debug 1 instance"), RUN_DEBUG_ONE); + p->add_radio_check_item(TTR("Debug 2 instances"), RUN_DEBUG_TWO); + p->set_item_checked(p->get_item_index(RUN_DEBUG_ONE), true); + + p->connect("id_pressed", callable_mp(this, &DebuggerEditorPlugin::_menu_option)); } DebuggerEditorPlugin::~DebuggerEditorPlugin() { + memdelete(file_server); // Should delete debugger? } + +void DebuggerEditorPlugin::_menu_option(int p_option) { + switch (p_option) { + case RUN_DEBUG_ONE: { + debug_menu->get_popup()->set_item_checked(debug_menu->get_popup()->get_item_index(RUN_DEBUG_ONE), true); + debug_menu->get_popup()->set_item_checked(debug_menu->get_popup()->get_item_index(RUN_DEBUG_TWO), false); + EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_debug_instances", 1); + + } break; + case RUN_DEBUG_TWO: { + debug_menu->get_popup()->set_item_checked(debug_menu->get_popup()->get_item_index(RUN_DEBUG_TWO), true); + debug_menu->get_popup()->set_item_checked(debug_menu->get_popup()->get_item_index(RUN_DEBUG_ONE), false); + EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_debug_instances", 2); + + } break; + case RUN_FILE_SERVER: { + + bool ischecked = debug_menu->get_popup()->is_item_checked(debug_menu->get_popup()->get_item_index(RUN_FILE_SERVER)); + + if (ischecked) { + file_server->stop(); + } else { + file_server->start(); + } + + debug_menu->get_popup()->set_item_checked(debug_menu->get_popup()->get_item_index(RUN_FILE_SERVER), !ischecked); + EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_file_server", !ischecked); + } break; + case RUN_LIVE_DEBUG: { + + bool ischecked = debug_menu->get_popup()->is_item_checked(debug_menu->get_popup()->get_item_index(RUN_LIVE_DEBUG)); + + debug_menu->get_popup()->set_item_checked(debug_menu->get_popup()->get_item_index(RUN_LIVE_DEBUG), !ischecked); + EditorDebuggerNode::get_singleton()->set_live_debugging(!ischecked); + EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_live_debug", !ischecked); + + } break; + case RUN_DEPLOY_REMOTE_DEBUG: { + + bool ischecked = debug_menu->get_popup()->is_item_checked(debug_menu->get_popup()->get_item_index(RUN_DEPLOY_REMOTE_DEBUG)); + debug_menu->get_popup()->set_item_checked(debug_menu->get_popup()->get_item_index(RUN_DEPLOY_REMOTE_DEBUG), !ischecked); + + } break; + case RUN_DEBUG_COLLISONS: { + + bool ischecked = debug_menu->get_popup()->is_item_checked(debug_menu->get_popup()->get_item_index(RUN_DEBUG_COLLISONS)); + debug_menu->get_popup()->set_item_checked(debug_menu->get_popup()->get_item_index(RUN_DEBUG_COLLISONS), !ischecked); + EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_debug_collisons", !ischecked); + + } break; + case RUN_DEBUG_NAVIGATION: { + + bool ischecked = debug_menu->get_popup()->is_item_checked(debug_menu->get_popup()->get_item_index(RUN_DEBUG_NAVIGATION)); + debug_menu->get_popup()->set_item_checked(debug_menu->get_popup()->get_item_index(RUN_DEBUG_NAVIGATION), !ischecked); + EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_debug_navigation", !ischecked); + + } break; + case RUN_RELOAD_SCRIPTS: { + + bool ischecked = debug_menu->get_popup()->is_item_checked(debug_menu->get_popup()->get_item_index(RUN_RELOAD_SCRIPTS)); + debug_menu->get_popup()->set_item_checked(debug_menu->get_popup()->get_item_index(RUN_RELOAD_SCRIPTS), !ischecked); + + ScriptEditor::get_singleton()->set_live_auto_reload_running_scripts(!ischecked); + EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_reload_scripts", !ischecked); + + } break; + } +} + +void DebuggerEditorPlugin::_notification(int p_what) { + switch (p_what) { + case NOTIFICATION_READY: + _update_debug_options(); + break; + default: + break; + } +} + +void DebuggerEditorPlugin::_update_debug_options() { + bool check_deploy_remote = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_deploy_remote_debug", false); + bool check_file_server = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_file_server", false); + bool check_debug_collisions = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_debug_collisons", false); + bool check_debug_navigation = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_debug_navigation", false); + bool check_live_debug = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_live_debug", false); + bool check_reload_scripts = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_reload_scripts", false); + int instances = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_debug_instances", 1); + + if (check_deploy_remote) _menu_option(RUN_DEPLOY_REMOTE_DEBUG); + if (check_file_server) _menu_option(RUN_FILE_SERVER); + if (check_debug_collisions) _menu_option(RUN_DEBUG_COLLISONS); + if (check_debug_navigation) _menu_option(RUN_DEBUG_NAVIGATION); + if (check_live_debug) _menu_option(RUN_LIVE_DEBUG); + if (check_reload_scripts) _menu_option(RUN_RELOAD_SCRIPTS); + int one = false; + int two = false; + if (instances == 2) + two = true; + else + one = true; + debug_menu->get_popup()->set_item_checked(debug_menu->get_popup()->get_item_index(RUN_DEBUG_ONE), one); + debug_menu->get_popup()->set_item_checked(debug_menu->get_popup()->get_item_index(RUN_DEBUG_TWO), two); +} -- cgit v1.2.3 From bfc1b76803f1606e7d108bdaab63c1a2ba7b59f1 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Sun, 8 Mar 2020 22:48:04 +0100 Subject: Allow running/debugging up to 4 instances. --- editor/plugins/debugger_editor_plugin.cpp | 65 ++++++++++++++++--------------- 1 file changed, 33 insertions(+), 32 deletions(-) (limited to 'editor/plugins/debugger_editor_plugin.cpp') diff --git a/editor/plugins/debugger_editor_plugin.cpp b/editor/plugins/debugger_editor_plugin.cpp index 6e74f8fcf3..b195609fb0 100644 --- a/editor/plugins/debugger_editor_plugin.cpp +++ b/editor/plugins/debugger_editor_plugin.cpp @@ -75,33 +75,41 @@ DebuggerEditorPlugin::DebuggerEditorPlugin(EditorNode *p_editor, MenuButton *p_d p->set_item_checked(p->get_item_count() - 1, true); // Multi-instance, start/stop - p->add_separator(); - p->add_radio_check_item(TTR("Debug 1 instance"), RUN_DEBUG_ONE); - p->add_radio_check_item(TTR("Debug 2 instances"), RUN_DEBUG_TWO); - p->set_item_checked(p->get_item_index(RUN_DEBUG_ONE), true); + instances_menu = memnew(PopupMenu); + instances_menu->set_name("run_instances"); + instances_menu->set_hide_on_checkable_item_selection(false); + p->add_child(instances_menu); + p->add_separator(); + p->add_submenu_item(TTR("Run Multiple Instances"), "run_instances"); + + instances_menu->add_radio_check_item(TTR("Run 1 Instance")); + instances_menu->set_item_metadata(0, 1); + instances_menu->add_radio_check_item(TTR("Run 2 Instances")); + instances_menu->set_item_metadata(1, 2); + instances_menu->add_radio_check_item(TTR("Run 3 Instances")); + instances_menu->set_item_metadata(2, 3); + instances_menu->add_radio_check_item(TTR("Run 4 Instances")); + instances_menu->set_item_metadata(3, 4); + instances_menu->set_item_checked(0, true); + instances_menu->connect("index_pressed", callable_mp(this, &DebuggerEditorPlugin::_select_run_count)); p->connect("id_pressed", callable_mp(this, &DebuggerEditorPlugin::_menu_option)); } DebuggerEditorPlugin::~DebuggerEditorPlugin() { memdelete(file_server); - // Should delete debugger? +} + +void DebuggerEditorPlugin::_select_run_count(int p_index) { + int len = instances_menu->get_item_count(); + for (int idx = 0; idx < len; idx++) { + instances_menu->set_item_checked(idx, idx == p_index); + } + EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_debug_instances", instances_menu->get_item_metadata(p_index)); } void DebuggerEditorPlugin::_menu_option(int p_option) { switch (p_option) { - case RUN_DEBUG_ONE: { - debug_menu->get_popup()->set_item_checked(debug_menu->get_popup()->get_item_index(RUN_DEBUG_ONE), true); - debug_menu->get_popup()->set_item_checked(debug_menu->get_popup()->get_item_index(RUN_DEBUG_TWO), false); - EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_debug_instances", 1); - - } break; - case RUN_DEBUG_TWO: { - debug_menu->get_popup()->set_item_checked(debug_menu->get_popup()->get_item_index(RUN_DEBUG_TWO), true); - debug_menu->get_popup()->set_item_checked(debug_menu->get_popup()->get_item_index(RUN_DEBUG_ONE), false); - EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_debug_instances", 2); - - } break; case RUN_FILE_SERVER: { bool ischecked = debug_menu->get_popup()->is_item_checked(debug_menu->get_popup()->get_item_index(RUN_FILE_SERVER)); @@ -157,13 +165,8 @@ void DebuggerEditorPlugin::_menu_option(int p_option) { } void DebuggerEditorPlugin::_notification(int p_what) { - switch (p_what) { - case NOTIFICATION_READY: - _update_debug_options(); - break; - default: - break; - } + if (p_what == NOTIFICATION_READY) + _update_debug_options(); } void DebuggerEditorPlugin::_update_debug_options() { @@ -181,12 +184,10 @@ void DebuggerEditorPlugin::_update_debug_options() { if (check_debug_navigation) _menu_option(RUN_DEBUG_NAVIGATION); if (check_live_debug) _menu_option(RUN_LIVE_DEBUG); if (check_reload_scripts) _menu_option(RUN_RELOAD_SCRIPTS); - int one = false; - int two = false; - if (instances == 2) - two = true; - else - one = true; - debug_menu->get_popup()->set_item_checked(debug_menu->get_popup()->get_item_index(RUN_DEBUG_ONE), one); - debug_menu->get_popup()->set_item_checked(debug_menu->get_popup()->get_item_index(RUN_DEBUG_TWO), two); + + int len = instances_menu->get_item_count(); + for (int idx = 0; idx < len; idx++) { + bool checked = (int)instances_menu->get_item_metadata(idx) == instances; + instances_menu->set_item_checked(idx, checked); + } } -- cgit v1.2.3