1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-05 12:10:55 +00:00

Merge pull request #81022 from YuriSizov/editor-run-scripts-valid-and-toasty

Improve warnings when running scripts in the editor
This commit is contained in:
Rémi Verschelde
2023-08-28 12:08:37 +02:00
2 changed files with 25 additions and 10 deletions

View File

@@ -254,7 +254,7 @@ bool CanvasItemEditor::_is_node_movable(const Node *p_node, bool p_popup_warning
} }
if (Object::cast_to<Control>(p_node) && Object::cast_to<Container>(p_node->get_parent())) { if (Object::cast_to<Control>(p_node) && Object::cast_to<Container>(p_node->get_parent())) {
if (p_popup_warning) { if (p_popup_warning) {
EditorToaster::get_singleton()->popup_str("Children of a container get their position and size determined only by their parent.", EditorToaster::SEVERITY_WARNING); EditorToaster::get_singleton()->popup_str(TTR("Children of a container get their position and size determined only by their parent."), EditorToaster::SEVERITY_WARNING);
} }
return false; return false;
} }

View File

@@ -52,6 +52,7 @@
#include "editor/find_in_files.h" #include "editor/find_in_files.h"
#include "editor/gui/editor_file_dialog.h" #include "editor/gui/editor_file_dialog.h"
#include "editor/gui/editor_run_bar.h" #include "editor/gui/editor_run_bar.h"
#include "editor/gui/editor_toaster.h"
#include "editor/inspector_dock.h" #include "editor/inspector_dock.h"
#include "editor/node_dock.h" #include "editor/node_dock.h"
#include "editor/plugins/shader_editor_plugin.h" #include "editor/plugins/shader_editor_plugin.h"
@@ -1347,27 +1348,40 @@ void ScriptEditor::_menu_option(int p_option) {
scr->reload(true); scr->reload(true);
} break; } break;
case FILE_RUN: { case FILE_RUN: {
Ref<Script> scr = current->get_edited_resource(); Ref<Script> scr = current->get_edited_resource();
if (scr == nullptr || scr.is_null()) { if (scr == nullptr || scr.is_null()) {
EditorNode::get_singleton()->show_warning(TTR("Can't obtain the script for running.")); EditorToaster::get_singleton()->popup_str(TTR("Cannot run the edited file because it's not a script."), EditorToaster::SEVERITY_WARNING);
break; break;
} }
if (!scr->is_tool()) {
EditorNode::get_singleton()->show_warning(TTR("Script is not in tool mode, will not be able to run."));
return;
}
current->apply_code(); current->apply_code();
Error err = scr->reload(false); //hard reload script before running always
if (err != OK) { Error err = scr->reload(false); // Always hard reload the script before running.
EditorNode::get_singleton()->show_warning(TTR("Script failed reloading, check console for errors.")); if (err != OK || !scr->is_valid()) {
EditorToaster::get_singleton()->popup_str(TTR("Cannot run the script because it contains errors, check the output log."), EditorToaster::SEVERITY_WARNING);
return; return;
} }
// Perform additional checks on the script to evaluate if it's runnable.
bool is_runnable = true;
if (!ClassDB::is_parent_class(scr->get_instance_base_type(), "EditorScript")) { if (!ClassDB::is_parent_class(scr->get_instance_base_type(), "EditorScript")) {
EditorNode::get_singleton()->show_warning(TTR("To run this script, it must inherit EditorScript and be set to tool mode.")); is_runnable = false;
EditorToaster::get_singleton()->popup_str(TTR("Cannot run the script because it doesn't extend EditorScript."), EditorToaster::SEVERITY_WARNING);
}
if (!scr->is_tool()) {
is_runnable = false;
if (scr->get_class() == "GDScript") {
EditorToaster::get_singleton()->popup_str(TTR("Cannot run the script because it's not a tool script (add the @tool annotation at the top)."), EditorToaster::SEVERITY_WARNING);
} else {
EditorToaster::get_singleton()->popup_str(TTR("Cannot run the script because it's not a tool script."), EditorToaster::SEVERITY_WARNING);
}
}
if (!is_runnable) {
return; return;
} }
@@ -1375,6 +1389,7 @@ void ScriptEditor::_menu_option(int p_option) {
es->set_script(scr); es->set_script(scr);
es->run(); es->run();
} break; } break;
case FILE_CLOSE: { case FILE_CLOSE: {
if (current->is_unsaved()) { if (current->is_unsaved()) {
_ask_close_current_unsaved_tab(current); _ask_close_current_unsaved_tab(current);