Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove support for built-in scripts in the editor #54553

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion core/object/script_language.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,6 @@ class ScriptLanguage {
virtual String validate_path(const String &p_path) const { return ""; }
virtual Script *create_script() const = 0;
virtual bool has_named_classes() const = 0;
virtual bool supports_builtin_mode() const = 0;
virtual bool supports_documentation() const { return false; }
virtual bool can_inherit_from_file() const { return false; }
virtual int find_function(const String &p_function, const String &p_code) const = 0;
Expand Down
4 changes: 0 additions & 4 deletions editor/editor_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,10 +566,6 @@ void EditorData::remove_scene(int p_idx) {
current_edited_scene--;
}

if (edited_scene[p_idx].path != String()) {
ScriptEditor::get_singleton()->close_builtin_scripts_from_scene(edited_scene[p_idx].path);
}

edited_scene.remove(p_idx);
}

Expand Down
2 changes: 1 addition & 1 deletion editor/editor_inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2506,7 +2506,7 @@ void EditorInspector::update_tree() {
}
}
if (category->icon.is_null()) {
if (type != String()) { // Can happen for built-in scripts.
if (type != String()) {
category->icon = EditorNode::get_singleton()->get_class_icon(type, "Object");
}
}
Expand Down
2 changes: 1 addition & 1 deletion editor/filesystem_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1942,7 +1942,7 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected
if (!fpath.ends_with("/")) {
fpath = fpath.get_base_dir();
}
make_script_dialog->config("Node", fpath.plus_file("new_script.gd"), false, false);
make_script_dialog->config("Node", fpath.plus_file("new_script.gd"), false);
make_script_dialog->popup_centered();
} break;

Expand Down
75 changes: 5 additions & 70 deletions editor/plugins/script_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,6 @@ void ScriptEditorBase::_bind_methods() {
ADD_SIGNAL(MethodInfo("replace_in_files_requested", PropertyInfo(Variant::STRING, "text")));
}

static bool _is_built_in_script(Script *p_script) {
String path = p_script->get_path();

return path.find("::") != -1;
}

class EditorScriptCodeCompletionCache : public ScriptCodeCompletionCache {
struct Cache {
uint64_t time_loaded = 0;
Expand Down Expand Up @@ -1159,7 +1153,7 @@ void ScriptEditor::_menu_option(int p_option) {
ScriptEditorBase *current = _get_current_editor();
switch (p_option) {
case FILE_NEW: {
script_create_dialog->config("Node", "new_script", false, false);
script_create_dialog->config("Node", "new_script", false);
script_create_dialog->popup_centered();
} break;
case FILE_NEW_TEXTFILE: {
Expand Down Expand Up @@ -1205,23 +1199,8 @@ void ScriptEditor::_menu_option(int p_option) {

List<String> extensions;
ResourceLoader::get_recognized_extensions_for_type("Script", &extensions);
bool built_in = !path.is_resource_file();

if (extensions.find(path.get_extension()) || built_in) {
if (built_in) {
String res_path = path.get_slice("::", 0);
if (ResourceLoader::get_resource_type(res_path) == "PackedScene") {
if (!EditorNode::get_singleton()->is_scene_open(res_path)) {
EditorNode::get_singleton()->load_scene(res_path);
script_editor->call_deferred(SNAME("_menu_option"), p_option);
previous_scripts.push_back(path); //repeat the operation
return;
}
} else {
EditorNode::get_singleton()->load_resource(res_path);
}
}

if (extensions.find(path.get_extension())) {
Ref<Script> scr = ResourceLoader::load(path);
if (!scr.is_valid()) {
editor->show_warning(TTR("Could not load file at:") + "\n\n" + path, TTR("Error!"));
Expand Down Expand Up @@ -1614,24 +1593,6 @@ bool ScriptEditor::can_take_away_focus() const {
}
}

void ScriptEditor::close_builtin_scripts_from_scene(const String &p_scene) {
for (int i = 0; i < tab_container->get_child_count(); i++) {
ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));

if (se) {
Ref<Script> script = se->get_edited_resource();
if (script == nullptr || !script.is_valid()) {
continue;
}

if (script->get_path().find("::") != -1 && script->get_path().begins_with(p_scene)) { //is an internal script and belongs to scene being closed
_close_tab(i);
i--;
}
}
}
}

void ScriptEditor::edited_scene_changed() {
_update_modified_scripts_for_external_editor();
}
Expand Down Expand Up @@ -1818,9 +1779,7 @@ void ScriptEditor::_update_members_overview() {
}

String path = se->get_edited_resource()->get_path();
bool built_in = !path.is_resource_file();
String name = built_in ? path.get_file() : se->get_name();
filename->set_text(name);
filename->set_text(se->get_name());
}

void ScriptEditor::_update_help_overview_visibility() {
Expand Down Expand Up @@ -1932,20 +1891,7 @@ void ScriptEditor::_update_script_names() {
// to update original path to previously edited resource.
se->set_meta("_edit_res_path", path);
}
bool built_in = !path.is_resource_file();
String name;

if (built_in) {
name = path.get_file();
const String &resource_name = se->get_edited_resource()->get_name();
if (resource_name != "") {
// If the built-in script has a custom resource name defined,
// display the built-in script name as follows: `ResourceName (scene_file.tscn)`
name = vformat("%s (%s)", resource_name, name.substr(0, name.find("::", 0)));
}
} else {
name = se->get_name();
}
const String name = se->get_name();

_ScriptEditorItemData sd;
sd.icon = icon;
Expand Down Expand Up @@ -2570,9 +2516,7 @@ void ScriptEditor::_add_callback(Object *p_obj, const String &p_function, const
script_list->select(script_list->find_metadata(i));

// Save the current script so the changes can be picked up by an external editor.
if (!_is_built_in_script(script.ptr())) { // But only if it's not built-in script.
save_current_script();
}
save_current_script();

break;
}
Expand Down Expand Up @@ -3858,15 +3802,6 @@ void ScriptEditorPlugin::edit(Object *p_object) {
Script *p_script = Object::cast_to<Script>(p_object);
String res_path = p_script->get_path().get_slice("::", 0);

if (_is_built_in_script(p_script)) {
if (ResourceLoader::get_resource_type(res_path) == "PackedScene") {
if (!EditorNode::get_singleton()->is_scene_open(res_path)) {
EditorNode::get_singleton()->load_scene(res_path);
}
} else {
EditorNode::get_singleton()->load_resource(res_path);
}
}
script_editor->edit(p_script);
} else if (Object::cast_to<TextFile>(p_object)) {
script_editor->edit(Object::cast_to<TextFile>(p_object));
Expand Down
2 changes: 0 additions & 2 deletions editor/plugins/script_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,6 @@ class ScriptEditor : public PanelContainer {
void notify_script_close(const Ref<Script> &p_script);
void notify_script_changed(const Ref<Script> &p_script);

void close_builtin_scripts_from_scene(const String &p_scene);

void goto_help(const String &p_desc) { _help_class_goto(p_desc); }
void update_doc(const String &p_name);

Expand Down
105 changes: 18 additions & 87 deletions editor/script_create_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ void ScriptCreateDialog::_path_hbox_sorted() {
int filename_start_pos = initial_bp.rfind("/") + 1;
int filename_end_pos = initial_bp.length();

if (!is_built_in) {
file_path->select(filename_start_pos, filename_end_pos);
}
file_path->select(filename_start_pos, filename_end_pos);

// First set cursor to the end of line to scroll LineEdit view
// to the right and then set the actual cursor position.
Expand All @@ -91,11 +89,7 @@ void ScriptCreateDialog::_path_hbox_sorted() {
}
}

bool ScriptCreateDialog::_can_be_built_in() {
return (supports_built_in && built_in_enabled);
}

void ScriptCreateDialog::config(const String &p_base_name, const String &p_base_path, bool p_built_in_enabled, bool p_load_enabled) {
void ScriptCreateDialog::config(const String &p_base_name, const String &p_base_path, bool p_load_enabled) {
class_name->set_text("");
class_name->deselect();
parent_name->set_text(p_base_name);
Expand All @@ -111,7 +105,6 @@ void ScriptCreateDialog::config(const String &p_base_name, const String &p_base_
}
file_path->deselect();

built_in_enabled = p_built_in_enabled;
load_enabled = p_load_enabled;

_lang_changed(current_language);
Expand Down Expand Up @@ -315,15 +308,13 @@ void ScriptCreateDialog::_create_new() {
}
}

if (!is_built_in) {
String lpath = ProjectSettings::get_singleton()->localize_path(file_path->get_text());
scr->set_path(lpath);
Error err = ResourceSaver::save(lpath, scr, ResourceSaver::FLAG_CHANGE_PATH);
if (err != OK) {
alert->set_text(TTR("Error - Could not create script in filesystem."));
alert->popup_centered();
return;
}
String lpath = ProjectSettings::get_singleton()->localize_path(file_path->get_text());
scr->set_path(lpath);
Error err = ResourceSaver::save(lpath, scr, ResourceSaver::FLAG_CHANGE_PATH);
if (err != OK) {
alert->set_text(TTR("Error - Could not create script in filesystem."));
alert->popup_centered();
return;
}

emit_signal(SNAME("script_created"), scr);
Expand All @@ -348,10 +339,6 @@ void ScriptCreateDialog::_lang_changed(int l) {

has_named_classes = language->has_named_classes();
can_inherit_from_file = language->can_inherit_from_file();
supports_built_in = language->supports_builtin_mode();
if (!supports_built_in) {
is_built_in = false;
}

String selected_ext = "." + language->get_extension();
String path = file_path->get_text();
Expand Down Expand Up @@ -504,17 +491,6 @@ void ScriptCreateDialog::_update_script_templates(const String &p_extension) {
}
}

void ScriptCreateDialog::_built_in_pressed() {
if (internal->is_pressed()) {
is_built_in = true;
is_new_script_created = true;
} else {
is_built_in = false;
_path_changed(file_path->get_text());
}
_update_dialog();
}

void ScriptCreateDialog::_browse_path(bool browse_parent, bool p_save) {
is_browsing_parent = browse_parent;

Expand Down Expand Up @@ -572,10 +548,6 @@ void ScriptCreateDialog::_browse_class_in_tree() {
}

void ScriptCreateDialog::_path_changed(const String &p_path) {
if (is_built_in) {
return;
}

is_path_valid = false;
is_new_script_created = true;

Expand Down Expand Up @@ -628,7 +600,7 @@ void ScriptCreateDialog::_update_dialog() {

// Is script path/name valid (order from top to bottom)?

if (!is_built_in && !is_path_valid) {
if (!is_path_valid) {
_msg_script_valid(false, TTR("Invalid path."));
script_ok = false;
}
Expand Down Expand Up @@ -662,41 +634,18 @@ void ScriptCreateDialog::_update_dialog() {
class_name->set_text("");
}

// Is script Built-in?

if (is_built_in) {
file_path->set_editable(false);
path_button->set_disabled(true);
re_check_path = true;
} else {
file_path->set_editable(true);
path_button->set_disabled(false);
if (re_check_path) {
re_check_path = false;
_path_changed(file_path->get_text());
}
}

if (!_can_be_built_in()) {
internal->set_pressed(false);
file_path->set_editable(true);
path_button->set_disabled(false);
if (re_check_path) {
re_check_path = false;
_path_changed(file_path->get_text());
}
internal->set_disabled(!_can_be_built_in());

// Is Script created or loaded from existing file?

builtin_warning_label->set_visible(is_built_in);

// Check if the script name is the same as the parent class.
// This warning isn't relevant if the script is built-in.
script_name_warning_label->set_visible(!is_built_in && _get_class_name() == parent_name->get_text());
script_name_warning_label->set_visible(_get_class_name() == parent_name->get_text());

if (is_built_in) {
get_ok_button()->set_text(TTR("Create"));
parent_name->set_editable(true);
parent_search_button->set_disabled(false);
parent_browse_button->set_disabled(!can_inherit_from_file);
_msg_path_valid(true, TTR("Built-in script (into scene file)."));
} else if (is_new_script_created) {
if (is_new_script_created) {
// New script created.

get_ok_button()->set_text(TTR("Create"));
Expand Down Expand Up @@ -739,7 +688,7 @@ void ScriptCreateDialog::_update_dialog() {
}

void ScriptCreateDialog::_bind_methods() {
ClassDB::bind_method(D_METHOD("config", "inherits", "path", "built_in_enabled", "load_enabled"), &ScriptCreateDialog::config, DEFVAL(true), DEFVAL(true));
ClassDB::bind_method(D_METHOD("config", "inherits", "path", "load_enabled"), &ScriptCreateDialog::config, DEFVAL(true));

ADD_SIGNAL(MethodInfo("script_created", PropertyInfo(Variant::OBJECT, "script", PROPERTY_HINT_RESOURCE_TYPE, "Script")));
}
Expand All @@ -760,13 +709,6 @@ ScriptCreateDialog::ScriptCreateDialog() {
path_error_label = memnew(Label);
vb->add_child(path_error_label);

builtin_warning_label = memnew(Label);
builtin_warning_label->set_text(
TTR("Note: Built-in scripts have some limitations and can't be edited using an external editor."));
vb->add_child(builtin_warning_label);
builtin_warning_label->set_autowrap_mode(Label::AUTOWRAP_WORD_SMART);
builtin_warning_label->hide();

script_name_warning_label = memnew(Label);
script_name_warning_label->set_text(
TTR("Warning: Having the script name be the same as a built-in type is usually not desired."));
Expand Down Expand Up @@ -849,14 +791,6 @@ ScriptCreateDialog::ScriptCreateDialog() {
gc->add_child(template_menu);
template_menu->connect("item_selected", callable_mp(this, &ScriptCreateDialog::_template_changed));

/* Built-in Script */

internal = memnew(CheckBox);
internal->set_text(TTR("On"));
internal->connect("pressed", callable_mp(this, &ScriptCreateDialog::_built_in_pressed));
gc->add_child(memnew(Label(TTR("Built-in Script:"))));
gc->add_child(internal);

/* Path */

hb = memnew(HBoxContainer);
Expand Down Expand Up @@ -898,10 +832,7 @@ ScriptCreateDialog::ScriptCreateDialog() {
is_path_valid = false;

has_named_classes = false;
supports_built_in = false;
can_inherit_from_file = false;
is_built_in = false;
built_in_enabled = true;
load_enabled = true;

is_new_script_created = true;
Expand Down
Loading