Path: blob/master/editor/debugger/debugger_editor_plugin.cpp
9903 views
/**************************************************************************/1/* debugger_editor_plugin.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#include "debugger_editor_plugin.h"3132#include "core/os/keyboard.h"33#include "editor/debugger/editor_debugger_node.h"34#include "editor/debugger/editor_debugger_server.h"35#include "editor/debugger/editor_file_server.h"36#include "editor/editor_node.h"37#include "editor/gui/editor_bottom_panel.h"38#include "editor/run/run_instances_dialog.h"39#include "editor/script/script_editor_plugin.h"40#include "editor/settings/editor_command_palette.h"41#include "editor/settings/editor_settings.h"42#include "scene/gui/popup_menu.h"4344DebuggerEditorPlugin::DebuggerEditorPlugin(PopupMenu *p_debug_menu) {45EditorDebuggerServer::initialize();4647ED_SHORTCUT("debugger/step_into", TTRC("Step Into"), Key::F11);48ED_SHORTCUT("debugger/step_over", TTRC("Step Over"), Key::F10);49ED_SHORTCUT("debugger/break", TTRC("Break"));50ED_SHORTCUT("debugger/continue", TTRC("Continue"), Key::F12);51ED_SHORTCUT("debugger/debug_with_external_editor", TTRC("Debug with External Editor"));5253// File Server for deploy with remote filesystem.54file_server = memnew(EditorFileServer);5556EditorDebuggerNode *debugger = memnew(EditorDebuggerNode);57Button *db = EditorNode::get_bottom_panel()->add_item(TTRC("Debugger"), debugger, ED_SHORTCUT_AND_COMMAND("bottom_panels/toggle_debugger_bottom_panel", TTRC("Toggle Debugger Bottom Panel"), KeyModifierMask::ALT | Key::D));58debugger->set_tool_button(db);5960// Main editor debug menu.61debug_menu = p_debug_menu;62debug_menu->set_hide_on_checkable_item_selection(false);63debug_menu->add_check_shortcut(ED_SHORTCUT("editor/deploy_with_remote_debug", TTRC("Deploy with Remote Debug")), RUN_DEPLOY_REMOTE_DEBUG);64debug_menu->set_item_tooltip(-1,65TTRC("When this option is enabled, using one-click deploy will make the executable attempt to connect to this computer's IP so the running project can be debugged.\nThis option is intended to be used for remote debugging (typically with a mobile device).\nYou don't need to enable it to use the GDScript debugger locally."));66debug_menu->add_check_shortcut(ED_SHORTCUT("editor/small_deploy_with_network_fs", TTRC("Small Deploy with Network Filesystem")), RUN_FILE_SERVER);67debug_menu->set_item_tooltip(-1,68TTRC("When this option is enabled, using one-click deploy for Android will only export an executable without the project data.\nThe filesystem will be provided from the project by the editor over the network.\nOn Android, deploying will use the USB cable for faster performance. This option speeds up testing for projects with large assets."));69debug_menu->add_separator();70debug_menu->add_check_shortcut(ED_SHORTCUT("editor/visible_collision_shapes", TTRC("Visible Collision Shapes")), RUN_DEBUG_COLLISIONS);71debug_menu->set_item_tooltip(-1,72TTRC("When this option is enabled, collision shapes and raycast nodes (for 2D and 3D) will be visible in the running project."));73debug_menu->add_check_shortcut(ED_SHORTCUT("editor/visible_paths", TTRC("Visible Paths")), RUN_DEBUG_PATHS);74debug_menu->set_item_tooltip(-1,75TTRC("When this option is enabled, curve resources used by path nodes will be visible in the running project."));76debug_menu->add_check_shortcut(ED_SHORTCUT("editor/visible_navigation", TTRC("Visible Navigation")), RUN_DEBUG_NAVIGATION);77debug_menu->set_item_tooltip(-1,78TTRC("When this option is enabled, navigation meshes, and polygons will be visible in the running project."));79debug_menu->add_check_shortcut(ED_SHORTCUT("editor/visible_avoidance", TTRC("Visible Avoidance")), RUN_DEBUG_AVOIDANCE);80debug_menu->set_item_tooltip(-1,81TTRC("When this option is enabled, avoidance object shapes, radiuses, and velocities will be visible in the running project."));82debug_menu->add_separator();83debug_menu->add_check_shortcut(ED_SHORTCUT("editor/visible_canvas_redraw", TTRC("Debug CanvasItem Redraws")), RUN_DEBUG_CANVAS_REDRAW);84debug_menu->set_item_tooltip(-1,85TTRC("When this option is enabled, redraw requests of 2D objects will become visible (as a short flash) in the running project.\nThis is useful to troubleshoot low processor mode."));86debug_menu->add_separator();87debug_menu->add_check_shortcut(ED_SHORTCUT("editor/sync_scene_changes", TTRC("Synchronize Scene Changes")), RUN_LIVE_DEBUG);88debug_menu->set_item_tooltip(-1,89TTRC("When this option is enabled, any changes made to the scene in the editor will be replicated in the running project.\nWhen used remotely on a device, this is more efficient when the network filesystem option is enabled."));90debug_menu->add_check_shortcut(ED_SHORTCUT("editor/sync_script_changes", TTRC("Synchronize Script Changes")), RUN_RELOAD_SCRIPTS);91debug_menu->set_item_tooltip(-1,92TTRC("When this option is enabled, any script that is saved will be reloaded in the running project.\nWhen used remotely on a device, this is more efficient when the network filesystem option is enabled."));93debug_menu->add_check_shortcut(ED_SHORTCUT("editor/keep_server_open", TTRC("Keep Debug Server Open")), SERVER_KEEP_OPEN);94debug_menu->set_item_tooltip(-1,95TTRC("When this option is enabled, the editor debug server will stay open and listen for new sessions started outside of the editor itself."));9697// Multi-instance, start/stop.98debug_menu->add_separator();99debug_menu->add_item(TTRC("Customize Run Instances..."), RUN_MULTIPLE_INSTANCES);100debug_menu->connect(SceneStringName(id_pressed), callable_mp(this, &DebuggerEditorPlugin::_menu_option));101102run_instances_dialog = memnew(RunInstancesDialog);103EditorNode::get_singleton()->get_gui_base()->add_child(run_instances_dialog);104}105106DebuggerEditorPlugin::~DebuggerEditorPlugin() {107EditorDebuggerServer::deinitialize();108memdelete(file_server);109}110111void DebuggerEditorPlugin::_menu_option(int p_option) {112switch (p_option) {113case RUN_FILE_SERVER: {114bool ischecked = debug_menu->is_item_checked(debug_menu->get_item_index(RUN_FILE_SERVER));115116if (ischecked) {117file_server->stop();118set_process(false);119} else {120file_server->start();121set_process(true);122}123124debug_menu->set_item_checked(debug_menu->get_item_index(RUN_FILE_SERVER), !ischecked);125if (!initializing) {126EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_file_server", !ischecked);127}128129} break;130case RUN_LIVE_DEBUG: {131bool ischecked = debug_menu->is_item_checked(debug_menu->get_item_index(RUN_LIVE_DEBUG));132133debug_menu->set_item_checked(debug_menu->get_item_index(RUN_LIVE_DEBUG), !ischecked);134EditorDebuggerNode::get_singleton()->set_live_debugging(!ischecked);135if (!initializing) {136EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_live_debug", !ischecked);137}138139} break;140case RUN_DEPLOY_REMOTE_DEBUG: {141bool ischecked = debug_menu->is_item_checked(debug_menu->get_item_index(RUN_DEPLOY_REMOTE_DEBUG));142debug_menu->set_item_checked(debug_menu->get_item_index(RUN_DEPLOY_REMOTE_DEBUG), !ischecked);143if (!initializing) {144EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_deploy_remote_debug", !ischecked);145}146147} break;148case RUN_DEBUG_COLLISIONS: {149bool ischecked = debug_menu->is_item_checked(debug_menu->get_item_index(RUN_DEBUG_COLLISIONS));150debug_menu->set_item_checked(debug_menu->get_item_index(RUN_DEBUG_COLLISIONS), !ischecked);151if (!initializing) {152EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_debug_collisions", !ischecked);153}154155} break;156case RUN_DEBUG_PATHS: {157bool ischecked = debug_menu->is_item_checked(debug_menu->get_item_index(RUN_DEBUG_PATHS));158debug_menu->set_item_checked(debug_menu->get_item_index(RUN_DEBUG_PATHS), !ischecked);159if (!initializing) {160EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_debug_paths", !ischecked);161}162163} break;164case RUN_DEBUG_NAVIGATION: {165bool ischecked = debug_menu->is_item_checked(debug_menu->get_item_index(RUN_DEBUG_NAVIGATION));166debug_menu->set_item_checked(debug_menu->get_item_index(RUN_DEBUG_NAVIGATION), !ischecked);167if (!initializing) {168EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_debug_navigation", !ischecked);169}170171} break;172case RUN_DEBUG_AVOIDANCE: {173bool ischecked = debug_menu->is_item_checked(debug_menu->get_item_index(RUN_DEBUG_AVOIDANCE));174debug_menu->set_item_checked(debug_menu->get_item_index(RUN_DEBUG_AVOIDANCE), !ischecked);175if (!initializing) {176EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_debug_avoidance", !ischecked);177}178179} break;180case RUN_DEBUG_CANVAS_REDRAW: {181bool ischecked = debug_menu->is_item_checked(debug_menu->get_item_index(RUN_DEBUG_CANVAS_REDRAW));182debug_menu->set_item_checked(debug_menu->get_item_index(RUN_DEBUG_CANVAS_REDRAW), !ischecked);183if (!initializing) {184EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_debug_canvas_redraw", !ischecked);185}186187} break;188case RUN_RELOAD_SCRIPTS: {189bool ischecked = debug_menu->is_item_checked(debug_menu->get_item_index(RUN_RELOAD_SCRIPTS));190debug_menu->set_item_checked(debug_menu->get_item_index(RUN_RELOAD_SCRIPTS), !ischecked);191192ScriptEditor::get_singleton()->set_live_auto_reload_running_scripts(!ischecked);193if (!initializing) {194EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_reload_scripts", !ischecked);195}196197} break;198case SERVER_KEEP_OPEN: {199bool ischecked = debug_menu->is_item_checked(debug_menu->get_item_index(SERVER_KEEP_OPEN));200debug_menu->set_item_checked(debug_menu->get_item_index(SERVER_KEEP_OPEN), !ischecked);201202EditorDebuggerNode::get_singleton()->set_keep_open(!ischecked);203if (!initializing) {204EditorSettings::get_singleton()->set_project_metadata("debug_options", "server_keep_open", !ischecked);205}206207} break;208case RUN_MULTIPLE_INSTANCES: {209run_instances_dialog->popup_dialog();210211} break;212}213}214215void DebuggerEditorPlugin::_notification(int p_what) {216switch (p_what) {217case NOTIFICATION_READY: {218_update_debug_options();219initializing = false;220} break;221222case NOTIFICATION_PROCESS: {223file_server->poll();224} break;225}226}227228void DebuggerEditorPlugin::_update_debug_options() {229bool check_deploy_remote = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_deploy_remote_debug", true);230bool check_file_server = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_file_server", false);231bool check_debug_collisions = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_debug_collisions", false);232bool check_debug_paths = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_debug_paths", false);233bool check_debug_navigation = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_debug_navigation", false);234bool check_debug_avoidance = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_debug_avoidance", false);235bool check_debug_canvas_redraw = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_debug_canvas_redraw", false);236bool check_live_debug = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_live_debug", true);237bool check_reload_scripts = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_reload_scripts", true);238bool check_server_keep_open = EditorSettings::get_singleton()->get_project_metadata("debug_options", "server_keep_open", false);239240if (check_deploy_remote) {241_menu_option(RUN_DEPLOY_REMOTE_DEBUG);242}243if (check_file_server) {244_menu_option(RUN_FILE_SERVER);245}246if (check_debug_collisions) {247_menu_option(RUN_DEBUG_COLLISIONS);248}249if (check_debug_paths) {250_menu_option(RUN_DEBUG_PATHS);251}252if (check_debug_navigation) {253_menu_option(RUN_DEBUG_NAVIGATION);254}255if (check_debug_avoidance) {256_menu_option(RUN_DEBUG_AVOIDANCE);257}258if (check_debug_canvas_redraw) {259_menu_option(RUN_DEBUG_CANVAS_REDRAW);260}261if (check_live_debug) {262_menu_option(RUN_LIVE_DEBUG);263}264if (check_reload_scripts) {265_menu_option(RUN_RELOAD_SCRIPTS);266}267if (check_server_keep_open) {268_menu_option(SERVER_KEEP_OPEN);269}270}271272273