editor_run_bar.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. /**************************************************************************/
  2. /* editor_run_bar.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "editor_run_bar.h"
  31. #include "core/config/project_settings.h"
  32. #include "editor/debugger/editor_debugger_node.h"
  33. #include "editor/debugger/script_editor_debugger.h"
  34. #include "editor/editor_command_palette.h"
  35. #include "editor/editor_node.h"
  36. #include "editor/editor_run_native.h"
  37. #include "editor/editor_settings.h"
  38. #include "editor/editor_string_names.h"
  39. #include "editor/gui/editor_bottom_panel.h"
  40. #include "editor/gui/editor_quick_open_dialog.h"
  41. #include "editor/gui/editor_toaster.h"
  42. #include "editor/themes/editor_scale.h"
  43. #include "scene/gui/box_container.h"
  44. #include "scene/gui/button.h"
  45. #include "scene/gui/panel_container.h"
  46. EditorRunBar *EditorRunBar::singleton = nullptr;
  47. void EditorRunBar::_notification(int p_what) {
  48. switch (p_what) {
  49. case NOTIFICATION_POSTINITIALIZE: {
  50. _reset_play_buttons();
  51. } break;
  52. case NOTIFICATION_READY: {
  53. if (Engine::get_singleton()->is_recovery_mode_hint()) {
  54. recovery_mode_show_dialog();
  55. }
  56. } break;
  57. case NOTIFICATION_THEME_CHANGED: {
  58. if (Engine::get_singleton()->is_recovery_mode_hint()) {
  59. main_panel->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SNAME("LaunchPadRecoveryMode"), EditorStringName(EditorStyles)));
  60. recovery_mode_panel->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SNAME("RecoveryModeButton"), EditorStringName(EditorStyles)));
  61. recovery_mode_button->add_theme_style_override("hover", get_theme_stylebox(SNAME("RecoveryModeButton"), EditorStringName(EditorStyles)));
  62. recovery_mode_button->set_button_icon(get_editor_theme_icon(SNAME("NodeWarning")));
  63. recovery_mode_reload_button->set_button_icon(get_editor_theme_icon(SNAME("Reload")));
  64. recovery_mode_button->begin_bulk_theme_override();
  65. recovery_mode_button->add_theme_color_override("icon_normal_color", Color(0.3, 0.3, 0.3, 1));
  66. recovery_mode_button->add_theme_color_override("icon_pressed_color", Color(0.4, 0.4, 0.4, 1));
  67. recovery_mode_button->add_theme_color_override("icon_hover_color", Color(0.6, 0.6, 0.6, 1));
  68. Color dark_color = get_theme_color("recovery_mode_text_color", EditorStringName(Editor));
  69. recovery_mode_button->add_theme_color_override(SceneStringName(font_color), dark_color);
  70. recovery_mode_button->add_theme_color_override("font_pressed_color", dark_color.lightened(0.2));
  71. recovery_mode_button->add_theme_color_override("font_hover_color", dark_color.lightened(0.4));
  72. recovery_mode_button->add_theme_color_override("font_hover_pressed_color", dark_color.lightened(0.2));
  73. recovery_mode_button->end_bulk_theme_override();
  74. return;
  75. }
  76. _update_play_buttons();
  77. profiler_autostart_indicator->set_button_icon(get_editor_theme_icon(SNAME("ProfilerAutostartWarning")));
  78. pause_button->set_button_icon(get_editor_theme_icon(SNAME("Pause")));
  79. stop_button->set_button_icon(get_editor_theme_icon(SNAME("Stop")));
  80. if (is_movie_maker_enabled()) {
  81. main_panel->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SNAME("LaunchPadMovieMode"), EditorStringName(EditorStyles)));
  82. write_movie_panel->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SNAME("MovieWriterButtonPressed"), EditorStringName(EditorStyles)));
  83. } else {
  84. main_panel->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SNAME("LaunchPadNormal"), EditorStringName(EditorStyles)));
  85. write_movie_panel->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SNAME("MovieWriterButtonNormal"), EditorStringName(EditorStyles)));
  86. }
  87. write_movie_button->set_button_icon(get_editor_theme_icon(SNAME("MainMovieWrite")));
  88. // This button behaves differently, so color it as such.
  89. write_movie_button->begin_bulk_theme_override();
  90. write_movie_button->add_theme_color_override("icon_normal_color", get_theme_color(SNAME("movie_writer_icon_normal"), EditorStringName(EditorStyles)));
  91. write_movie_button->add_theme_color_override("icon_pressed_color", get_theme_color(SNAME("movie_writer_icon_pressed"), EditorStringName(EditorStyles)));
  92. write_movie_button->add_theme_color_override("icon_hover_color", get_theme_color(SNAME("movie_writer_icon_hover"), EditorStringName(EditorStyles)));
  93. write_movie_button->add_theme_color_override("icon_hover_pressed_color", get_theme_color(SNAME("movie_writer_icon_hover_pressed"), EditorStringName(EditorStyles)));
  94. write_movie_button->end_bulk_theme_override();
  95. } break;
  96. }
  97. }
  98. void EditorRunBar::_reset_play_buttons() {
  99. if (Engine::get_singleton()->is_recovery_mode_hint()) {
  100. return;
  101. }
  102. play_button->set_pressed(false);
  103. play_button->set_button_icon(get_editor_theme_icon(SNAME("MainPlay")));
  104. play_button->set_tooltip_text(TTR("Play the project."));
  105. play_scene_button->set_pressed(false);
  106. play_scene_button->set_button_icon(get_editor_theme_icon(SNAME("PlayScene")));
  107. play_scene_button->set_tooltip_text(TTR("Play the edited scene."));
  108. play_custom_scene_button->set_pressed(false);
  109. play_custom_scene_button->set_button_icon(get_editor_theme_icon(SNAME("PlayCustom")));
  110. play_custom_scene_button->set_tooltip_text(TTR("Play a custom scene."));
  111. }
  112. void EditorRunBar::_update_play_buttons() {
  113. if (Engine::get_singleton()->is_recovery_mode_hint()) {
  114. return;
  115. }
  116. _reset_play_buttons();
  117. if (!is_playing()) {
  118. return;
  119. }
  120. Button *active_button = nullptr;
  121. if (current_mode == RUN_CURRENT) {
  122. active_button = play_scene_button;
  123. } else if (current_mode == RUN_CUSTOM) {
  124. active_button = play_custom_scene_button;
  125. } else {
  126. active_button = play_button;
  127. }
  128. if (active_button) {
  129. active_button->set_pressed(true);
  130. active_button->set_button_icon(get_editor_theme_icon(SNAME("Reload")));
  131. active_button->set_tooltip_text(TTR("Reload the played scene."));
  132. }
  133. }
  134. void EditorRunBar::_write_movie_toggled(bool p_enabled) {
  135. if (p_enabled) {
  136. add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SNAME("LaunchPadMovieMode"), EditorStringName(EditorStyles)));
  137. write_movie_panel->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SNAME("MovieWriterButtonPressed"), EditorStringName(EditorStyles)));
  138. } else {
  139. add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SNAME("LaunchPadNormal"), EditorStringName(EditorStyles)));
  140. write_movie_panel->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SNAME("MovieWriterButtonNormal"), EditorStringName(EditorStyles)));
  141. }
  142. }
  143. void EditorRunBar::_quick_run_selected(const String &p_file_path) {
  144. play_custom_scene(p_file_path);
  145. }
  146. void EditorRunBar::_play_custom_pressed() {
  147. if (editor_run.get_status() == EditorRun::STATUS_STOP || current_mode != RunMode::RUN_CUSTOM) {
  148. stop_playing();
  149. EditorNode::get_singleton()->get_quick_open_dialog()->popup_dialog({ "PackedScene" }, callable_mp(this, &EditorRunBar::_quick_run_selected));
  150. play_custom_scene_button->set_pressed(false);
  151. } else {
  152. // Reload if already running a custom scene.
  153. String last_custom_scene = run_custom_filename; // This is necessary to have a copy of the string.
  154. play_custom_scene(last_custom_scene);
  155. }
  156. }
  157. void EditorRunBar::_play_current_pressed() {
  158. if (editor_run.get_status() == EditorRun::STATUS_STOP || current_mode != RunMode::RUN_CURRENT) {
  159. play_current_scene();
  160. } else {
  161. // Reload if already running the current scene.
  162. play_current_scene(true);
  163. }
  164. }
  165. void EditorRunBar::_run_scene(const String &p_scene_path) {
  166. ERR_FAIL_COND_MSG(current_mode == RUN_CUSTOM && p_scene_path.is_empty(), "Attempting to run a custom scene with an empty path.");
  167. if (editor_run.get_status() == EditorRun::STATUS_PLAY) {
  168. return;
  169. }
  170. _reset_play_buttons();
  171. String write_movie_file;
  172. if (is_movie_maker_enabled()) {
  173. if (current_mode == RUN_CURRENT) {
  174. Node *scene_root = nullptr;
  175. if (p_scene_path.is_empty()) {
  176. scene_root = get_tree()->get_edited_scene_root();
  177. } else {
  178. int scene_index = EditorNode::get_editor_data().get_edited_scene_from_path(p_scene_path);
  179. if (scene_index >= 0) {
  180. scene_root = EditorNode::get_editor_data().get_edited_scene_root(scene_index);
  181. }
  182. }
  183. if (scene_root && scene_root->has_meta("movie_file")) {
  184. // If the scene file has a movie_file metadata set, use this as file.
  185. // Quick workaround if you want to have multiple scenes that write to
  186. // multiple movies.
  187. write_movie_file = scene_root->get_meta("movie_file");
  188. }
  189. }
  190. if (write_movie_file.is_empty()) {
  191. write_movie_file = GLOBAL_GET("editor/movie_writer/movie_file");
  192. }
  193. if (write_movie_file.is_empty()) {
  194. // TODO: Provide options to directly resolve the issue with a custom dialog.
  195. EditorNode::get_singleton()->show_accept(TTR("Movie Maker mode is enabled, but no movie file path has been specified.\nA default movie file path can be specified in the project settings under the Editor > Movie Writer category.\nAlternatively, for running single scenes, a `movie_file` string metadata can be added to the root node,\nspecifying the path to a movie file that will be used when recording that scene."), TTR("OK"));
  196. return;
  197. }
  198. }
  199. String run_filename;
  200. switch (current_mode) {
  201. case RUN_CUSTOM: {
  202. run_filename = p_scene_path;
  203. run_custom_filename = run_filename;
  204. } break;
  205. case RUN_CURRENT: {
  206. if (!p_scene_path.is_empty()) {
  207. run_filename = p_scene_path;
  208. run_current_filename = run_filename;
  209. break;
  210. }
  211. Node *scene_root = get_tree()->get_edited_scene_root();
  212. if (!scene_root) {
  213. EditorNode::get_singleton()->show_accept(TTR("There is no defined scene to run."), TTR("OK"));
  214. return;
  215. }
  216. if (scene_root->get_scene_file_path().is_empty()) {
  217. EditorNode::get_singleton()->save_before_run();
  218. return;
  219. }
  220. run_filename = scene_root->get_scene_file_path();
  221. run_current_filename = run_filename;
  222. } break;
  223. default: {
  224. if (!EditorNode::get_singleton()->ensure_main_scene(false)) {
  225. return;
  226. }
  227. run_filename = GLOBAL_GET("application/run/main_scene");
  228. } break;
  229. }
  230. EditorNode::get_singleton()->try_autosave();
  231. if (!EditorNode::get_singleton()->call_build()) {
  232. return;
  233. }
  234. EditorDebuggerNode::get_singleton()->start();
  235. Error error = editor_run.run(run_filename, write_movie_file);
  236. if (error != OK) {
  237. EditorDebuggerNode::get_singleton()->stop();
  238. EditorNode::get_singleton()->show_accept(TTR("Could not start subprocess(es)!"), TTR("OK"));
  239. return;
  240. }
  241. _update_play_buttons();
  242. stop_button->set_disabled(false);
  243. emit_signal(SNAME("play_pressed"));
  244. }
  245. void EditorRunBar::_run_native(const Ref<EditorExportPreset> &p_preset) {
  246. EditorNode::get_singleton()->try_autosave();
  247. if (run_native->is_deploy_debug_remote_enabled()) {
  248. stop_playing();
  249. if (!EditorNode::get_singleton()->call_build()) {
  250. return; // Build failed.
  251. }
  252. EditorDebuggerNode::get_singleton()->start(p_preset->get_platform()->get_debug_protocol());
  253. emit_signal(SNAME("play_pressed"));
  254. editor_run.run_native_notify();
  255. }
  256. }
  257. void EditorRunBar::_profiler_autostart_indicator_pressed() {
  258. // Switch to the first profiler tab in the bottom panel.
  259. EditorNode::get_singleton()->get_bottom_panel()->make_item_visible(EditorDebuggerNode::get_singleton(), true);
  260. if (EditorSettings::get_singleton()->get_project_metadata("debug_options", "autostart_profiler", false)) {
  261. EditorDebuggerNode::get_singleton()->get_current_debugger()->switch_to_debugger(3);
  262. } else if (EditorSettings::get_singleton()->get_project_metadata("debug_options", "autostart_visual_profiler", false)) {
  263. EditorDebuggerNode::get_singleton()->get_current_debugger()->switch_to_debugger(4);
  264. } else {
  265. // Switch to the network profiler tab.
  266. EditorDebuggerNode::get_singleton()->get_current_debugger()->switch_to_debugger(8);
  267. }
  268. }
  269. void EditorRunBar::recovery_mode_show_dialog() {
  270. recovery_mode_popup->popup_centered();
  271. }
  272. void EditorRunBar::recovery_mode_reload_project() {
  273. EditorNode::get_singleton()->trigger_menu_option(EditorNode::PROJECT_RELOAD_CURRENT_PROJECT, false);
  274. }
  275. void EditorRunBar::play_main_scene(bool p_from_native) {
  276. if (Engine::get_singleton()->is_recovery_mode_hint()) {
  277. EditorToaster::get_singleton()->popup_str(TTR("Recovery Mode is enabled. Disable it to run the project."), EditorToaster::SEVERITY_WARNING);
  278. return;
  279. }
  280. if (p_from_native) {
  281. run_native->resume_run_native();
  282. } else {
  283. stop_playing();
  284. current_mode = RunMode::RUN_MAIN;
  285. _run_scene();
  286. }
  287. }
  288. void EditorRunBar::play_current_scene(bool p_reload) {
  289. if (Engine::get_singleton()->is_recovery_mode_hint()) {
  290. EditorToaster::get_singleton()->popup_str(TTR("Recovery Mode is enabled. Disable it to run the project."), EditorToaster::SEVERITY_WARNING);
  291. return;
  292. }
  293. String last_current_scene = run_current_filename; // This is necessary to have a copy of the string.
  294. EditorNode::get_singleton()->save_default_environment();
  295. stop_playing();
  296. current_mode = RunMode::RUN_CURRENT;
  297. if (p_reload) {
  298. _run_scene(last_current_scene);
  299. } else {
  300. _run_scene();
  301. }
  302. }
  303. void EditorRunBar::play_custom_scene(const String &p_custom) {
  304. if (Engine::get_singleton()->is_recovery_mode_hint()) {
  305. EditorToaster::get_singleton()->popup_str(TTR("Recovery Mode is enabled. Disable it to run the project."), EditorToaster::SEVERITY_WARNING);
  306. return;
  307. }
  308. stop_playing();
  309. current_mode = RunMode::RUN_CUSTOM;
  310. _run_scene(p_custom);
  311. }
  312. void EditorRunBar::stop_playing() {
  313. if (editor_run.get_status() == EditorRun::STATUS_STOP) {
  314. return;
  315. }
  316. current_mode = RunMode::STOPPED;
  317. editor_run.stop();
  318. EditorDebuggerNode::get_singleton()->stop();
  319. run_custom_filename.clear();
  320. run_current_filename.clear();
  321. stop_button->set_pressed(false);
  322. stop_button->set_disabled(true);
  323. _reset_play_buttons();
  324. emit_signal(SNAME("stop_pressed"));
  325. }
  326. bool EditorRunBar::is_playing() const {
  327. EditorRun::Status status = editor_run.get_status();
  328. return (status == EditorRun::STATUS_PLAY || status == EditorRun::STATUS_PAUSED);
  329. }
  330. String EditorRunBar::get_playing_scene() const {
  331. String run_filename = editor_run.get_running_scene();
  332. if (run_filename.is_empty() && is_playing()) {
  333. run_filename = GLOBAL_GET("application/run/main_scene"); // Must be the main scene then.
  334. }
  335. return run_filename;
  336. }
  337. Error EditorRunBar::start_native_device(int p_device_id) {
  338. return run_native->start_run_native(p_device_id);
  339. }
  340. OS::ProcessID EditorRunBar::has_child_process(OS::ProcessID p_pid) const {
  341. return editor_run.has_child_process(p_pid);
  342. }
  343. void EditorRunBar::stop_child_process(OS::ProcessID p_pid) {
  344. if (!has_child_process(p_pid)) {
  345. return;
  346. }
  347. editor_run.stop_child_process(p_pid);
  348. if (!editor_run.get_child_process_count()) { // All children stopped. Closing.
  349. stop_playing();
  350. }
  351. }
  352. OS::ProcessID EditorRunBar::get_current_process() const {
  353. return editor_run.get_current_process();
  354. }
  355. void EditorRunBar::set_movie_maker_enabled(bool p_enabled) {
  356. write_movie_button->set_pressed(p_enabled);
  357. }
  358. bool EditorRunBar::is_movie_maker_enabled() const {
  359. return write_movie_button->is_pressed();
  360. }
  361. void EditorRunBar::update_profiler_autostart_indicator() {
  362. bool profiler_active = EditorSettings::get_singleton()->get_project_metadata("debug_options", "autostart_profiler", false);
  363. bool visual_profiler_active = EditorSettings::get_singleton()->get_project_metadata("debug_options", "autostart_visual_profiler", false);
  364. bool network_profiler_active = EditorSettings::get_singleton()->get_project_metadata("debug_options", "autostart_network_profiler", false);
  365. bool any_profiler_active = profiler_active | visual_profiler_active | network_profiler_active;
  366. any_profiler_active &= !Engine::get_singleton()->is_recovery_mode_hint();
  367. profiler_autostart_indicator->set_visible(any_profiler_active);
  368. if (any_profiler_active) {
  369. String tooltip = TTR("Autostart is enabled for the following profilers, which can have a performance impact:");
  370. if (profiler_active) {
  371. tooltip += "\n- " + TTR("Profiler");
  372. }
  373. if (visual_profiler_active) {
  374. tooltip += "\n- " + TTR("Visual Profiler");
  375. }
  376. if (network_profiler_active) {
  377. tooltip += "\n- " + TTR("Network Profiler");
  378. }
  379. tooltip += "\n\n" + TTR("Click to open the first profiler for which autostart is enabled.");
  380. profiler_autostart_indicator->set_tooltip_text(tooltip);
  381. }
  382. }
  383. HBoxContainer *EditorRunBar::get_buttons_container() {
  384. return main_hbox;
  385. }
  386. void EditorRunBar::_bind_methods() {
  387. ADD_SIGNAL(MethodInfo("play_pressed"));
  388. ADD_SIGNAL(MethodInfo("stop_pressed"));
  389. }
  390. EditorRunBar::EditorRunBar() {
  391. singleton = this;
  392. outer_hbox = memnew(HBoxContainer);
  393. add_child(outer_hbox);
  394. // Use a button for the indicator since it comes with a background panel and pixel perfect centering of an icon.
  395. profiler_autostart_indicator = memnew(Button);
  396. profiler_autostart_indicator->set_icon_alignment(HORIZONTAL_ALIGNMENT_CENTER);
  397. profiler_autostart_indicator->set_focus_mode(FOCUS_NONE);
  398. profiler_autostart_indicator->set_theme_type_variation("ProfilerAutostartIndicator");
  399. profiler_autostart_indicator->connect(SceneStringName(pressed), callable_mp(this, &EditorRunBar::_profiler_autostart_indicator_pressed));
  400. outer_hbox->add_child(profiler_autostart_indicator);
  401. update_profiler_autostart_indicator();
  402. main_panel = memnew(PanelContainer);
  403. outer_hbox->add_child(main_panel);
  404. main_hbox = memnew(HBoxContainer);
  405. main_panel->add_child(main_hbox);
  406. if (Engine::get_singleton()->is_recovery_mode_hint()) {
  407. recovery_mode_popup = memnew(AcceptDialog);
  408. recovery_mode_popup->set_min_size(Size2(550, 70) * EDSCALE);
  409. recovery_mode_popup->set_title(TTR("Recovery Mode"));
  410. recovery_mode_popup->set_text(
  411. TTR("Godot opened the project in Recovery Mode, which is a special mode that can help recover projects that crash the engine upon initialization. The following features have been temporarily disabled:") +
  412. String::utf8("\n\n• ") + TTR("Tool scripts") +
  413. String::utf8("\n• ") + TTR("Editor plugins") +
  414. String::utf8("\n• ") + TTR("GDExtension addons") +
  415. String::utf8("\n• ") + TTR("Automatic scene restoring") +
  416. String::utf8("\n\n") + TTR("If the project cannot be opened outside of this mode, then it's very likely any of these components is preventing this project from launching. This mode is intended only for basic editing to troubleshoot such issues, and therefore it is not possible to run a project in this mode.") +
  417. String::utf8("\n\n") + TTR("To disable Recovery Mode, reload the project by pressing the Reload button next to the Recovery Mode banner, or by reopening the project normally."));
  418. recovery_mode_popup->set_autowrap(true);
  419. add_child(recovery_mode_popup);
  420. recovery_mode_reload_button = memnew(Button);
  421. main_hbox->add_child(recovery_mode_reload_button);
  422. recovery_mode_reload_button->set_theme_type_variation("RunBarButton");
  423. recovery_mode_reload_button->set_focus_mode(Control::FOCUS_NONE);
  424. recovery_mode_reload_button->set_tooltip_text(TTR("Disable recovery mode and reload the project."));
  425. recovery_mode_reload_button->connect(SceneStringName(pressed), callable_mp(this, &EditorRunBar::recovery_mode_reload_project));
  426. recovery_mode_panel = memnew(PanelContainer);
  427. main_hbox->add_child(recovery_mode_panel);
  428. recovery_mode_button = memnew(Button);
  429. recovery_mode_panel->add_child(recovery_mode_button);
  430. recovery_mode_button->set_theme_type_variation("RunBarButton");
  431. recovery_mode_button->set_focus_mode(Control::FOCUS_NONE);
  432. recovery_mode_button->set_text(TTR("Recovery Mode"));
  433. recovery_mode_button->set_tooltip_text(TTR("Recovery Mode is enabled. Click for more details."));
  434. recovery_mode_button->connect(SceneStringName(pressed), callable_mp(this, &EditorRunBar::recovery_mode_show_dialog));
  435. return;
  436. }
  437. play_button = memnew(Button);
  438. main_hbox->add_child(play_button);
  439. play_button->set_theme_type_variation("RunBarButton");
  440. play_button->set_toggle_mode(true);
  441. play_button->set_focus_mode(Control::FOCUS_NONE);
  442. play_button->set_tooltip_text(TTRC("Run the project's default scene."));
  443. play_button->connect(SceneStringName(pressed), callable_mp(this, &EditorRunBar::play_main_scene).bind(false));
  444. ED_SHORTCUT_AND_COMMAND("editor/run_project", TTRC("Run Project"), Key::F5);
  445. ED_SHORTCUT_OVERRIDE("editor/run_project", "macos", KeyModifierMask::META | Key::B);
  446. play_button->set_shortcut(ED_GET_SHORTCUT("editor/run_project"));
  447. pause_button = memnew(Button);
  448. main_hbox->add_child(pause_button);
  449. pause_button->set_theme_type_variation("RunBarButton");
  450. pause_button->set_toggle_mode(true);
  451. pause_button->set_focus_mode(Control::FOCUS_NONE);
  452. pause_button->set_tooltip_text(TTRC("Pause the running project's execution for debugging."));
  453. pause_button->set_disabled(true);
  454. ED_SHORTCUT("editor/pause_running_project", TTRC("Pause Running Project"), Key::F7);
  455. ED_SHORTCUT_OVERRIDE("editor/pause_running_project", "macos", KeyModifierMask::META | KeyModifierMask::CTRL | Key::Y);
  456. pause_button->set_shortcut(ED_GET_SHORTCUT("editor/pause_running_project"));
  457. stop_button = memnew(Button);
  458. main_hbox->add_child(stop_button);
  459. stop_button->set_theme_type_variation("RunBarButton");
  460. stop_button->set_focus_mode(Control::FOCUS_NONE);
  461. stop_button->set_tooltip_text(TTRC("Stop the currently running project."));
  462. stop_button->set_disabled(true);
  463. stop_button->connect(SceneStringName(pressed), callable_mp(this, &EditorRunBar::stop_playing));
  464. ED_SHORTCUT("editor/stop_running_project", TTRC("Stop Running Project"), Key::F8);
  465. ED_SHORTCUT_OVERRIDE("editor/stop_running_project", "macos", KeyModifierMask::META | Key::PERIOD);
  466. stop_button->set_shortcut(ED_GET_SHORTCUT("editor/stop_running_project"));
  467. run_native = memnew(EditorRunNative);
  468. main_hbox->add_child(run_native);
  469. run_native->connect("native_run", callable_mp(this, &EditorRunBar::_run_native));
  470. play_scene_button = memnew(Button);
  471. main_hbox->add_child(play_scene_button);
  472. play_scene_button->set_theme_type_variation("RunBarButton");
  473. play_scene_button->set_toggle_mode(true);
  474. play_scene_button->set_focus_mode(Control::FOCUS_NONE);
  475. play_scene_button->set_tooltip_text(TTRC("Run the currently edited scene."));
  476. play_scene_button->connect(SceneStringName(pressed), callable_mp(this, &EditorRunBar::_play_current_pressed));
  477. ED_SHORTCUT_AND_COMMAND("editor/run_current_scene", TTRC("Run Current Scene"), Key::F6);
  478. ED_SHORTCUT_OVERRIDE("editor/run_current_scene", "macos", KeyModifierMask::META | Key::R);
  479. play_scene_button->set_shortcut(ED_GET_SHORTCUT("editor/run_current_scene"));
  480. play_custom_scene_button = memnew(Button);
  481. main_hbox->add_child(play_custom_scene_button);
  482. play_custom_scene_button->set_theme_type_variation("RunBarButton");
  483. play_custom_scene_button->set_toggle_mode(true);
  484. play_custom_scene_button->set_focus_mode(Control::FOCUS_NONE);
  485. play_custom_scene_button->set_tooltip_text(TTRC("Run a specific scene."));
  486. play_custom_scene_button->connect(SceneStringName(pressed), callable_mp(this, &EditorRunBar::_play_custom_pressed));
  487. ED_SHORTCUT_AND_COMMAND("editor/run_specific_scene", TTRC("Run Specific Scene"), KeyModifierMask::CTRL | KeyModifierMask::SHIFT | Key::F5);
  488. ED_SHORTCUT_OVERRIDE("editor/run_specific_scene", "macos", KeyModifierMask::META | KeyModifierMask::SHIFT | Key::R);
  489. play_custom_scene_button->set_shortcut(ED_GET_SHORTCUT("editor/run_specific_scene"));
  490. write_movie_panel = memnew(PanelContainer);
  491. main_hbox->add_child(write_movie_panel);
  492. write_movie_button = memnew(Button);
  493. write_movie_panel->add_child(write_movie_button);
  494. write_movie_button->set_theme_type_variation("RunBarButton");
  495. write_movie_button->set_toggle_mode(true);
  496. write_movie_button->set_pressed(false);
  497. write_movie_button->set_focus_mode(Control::FOCUS_NONE);
  498. write_movie_button->set_tooltip_text(TTR("Enable Movie Maker mode.\nThe project will run at stable FPS and the visual and audio output will be recorded to a video file."));
  499. write_movie_button->connect(SceneStringName(toggled), callable_mp(this, &EditorRunBar::_write_movie_toggled));
  500. }