diff options
author | kobewi <kobewi4e@gmail.com> | 2021-11-04 02:34:35 +0100 |
---|---|---|
committer | kobewi <kobewi4e@gmail.com> | 2021-11-04 02:34:35 +0100 |
commit | 64a2681cf0ff5a16c2efade06db174e4b6b64bd8 (patch) | |
tree | 3c8fb8104dae1bae46d60909233593db6434962a | |
parent | 78931aa040bb0d0586345f95cc982605c0720ba1 (diff) |
Allow to name built-in scripts upon creation
-rw-r--r-- | editor/script_create_dialog.cpp | 26 | ||||
-rw-r--r-- | editor/script_create_dialog.h | 4 |
2 files changed, 28 insertions, 2 deletions
diff --git a/editor/script_create_dialog.cpp b/editor/script_create_dialog.cpp index 1e19d9bd47..fb1575ad8c 100644 --- a/editor/script_create_dialog.cpp +++ b/editor/script_create_dialog.cpp @@ -315,7 +315,9 @@ void ScriptCreateDialog::_create_new() { } } - if (!is_built_in) { + if (is_built_in) { + scr->set_name(internal_name->get_text()); + } else { 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); @@ -686,6 +688,11 @@ void ScriptCreateDialog::_update_dialog() { builtin_warning_label->set_visible(is_built_in); + path_controls[0]->set_visible(!is_built_in); + path_controls[1]->set_visible(!is_built_in); + name_controls[0]->set_visible(is_built_in); + name_controls[1]->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()); @@ -868,9 +875,24 @@ ScriptCreateDialog::ScriptCreateDialog() { path_button = memnew(Button); path_button->connect("pressed", callable_mp(this, &ScriptCreateDialog::_browse_path), varray(false, true)); hb->add_child(path_button); - gc->add_child(memnew(Label(TTR("Path:")))); + Label *label = memnew(Label(TTR("Path:"))); + gc->add_child(label); gc->add_child(hb); re_check_path = false; + path_controls[0] = label; + path_controls[1] = hb; + + /* Name */ + + internal_name = memnew(LineEdit); + internal_name->set_h_size_flags(Control::SIZE_EXPAND_FILL); + label = memnew(Label(TTR("Name:"))); + gc->add_child(label); + gc->add_child(internal_name); + name_controls[0] = label; + name_controls[1] = internal_name; + label->hide(); + internal_name->hide(); /* Dialog Setup */ diff --git a/editor/script_create_dialog.h b/editor/script_create_dialog.h index 7c2ef1e150..dba798eea7 100644 --- a/editor/script_create_dialog.h +++ b/editor/script_create_dialog.h @@ -57,6 +57,7 @@ class ScriptCreateDialog : public ConfirmationDialog { OptionButton *language_menu; OptionButton *template_menu; LineEdit *file_path; + LineEdit *internal_name; Button *path_button; EditorFileDialog *file_browse; CheckBox *internal; @@ -81,6 +82,9 @@ class ScriptCreateDialog : public ConfirmationDialog { int default_language; bool re_check_path; + Control *path_controls[2]; + Control *name_controls[2]; + enum ScriptOrigin { SCRIPT_ORIGIN_PROJECT, SCRIPT_ORIGIN_EDITOR, |