summaryrefslogtreecommitdiff
path: root/editor/script_create_dialog.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/script_create_dialog.cpp')
-rw-r--r--editor/script_create_dialog.cpp41
1 files changed, 29 insertions, 12 deletions
diff --git a/editor/script_create_dialog.cpp b/editor/script_create_dialog.cpp
index 089c054b59..3cab14b0c4 100644
--- a/editor/script_create_dialog.cpp
+++ b/editor/script_create_dialog.cpp
@@ -88,7 +88,7 @@ bool ScriptCreateDialog::_validate(const String &p_string) {
continue;
}
- bool valid_char = (p_string[i] >= '0' && p_string[i] <= '9') || (p_string[i] >= 'a' && p_string[i] <= 'z') || (p_string[i] >= 'A' && p_string[i] <= 'Z') || p_string[i] == '_' || (is_val_path && (p_string[i] == '/' || p_string[i] == '.'));
+ bool valid_char = (p_string[i] >= '0' && p_string[i] <= '9') || (p_string[i] >= 'a' && p_string[i] <= 'z') || (p_string[i] >= 'A' && p_string[i] <= 'Z') || p_string[i] == '_' || p_string[i] == '-' || (is_val_path && (p_string[i] == '/' || p_string[i] == '.'));
if (!valid_char)
return false;
@@ -128,7 +128,7 @@ void ScriptCreateDialog::_template_changed(int p_template) {
}
String ext = ScriptServer::get_language(language_menu->get_selected())->get_extension();
String name = template_list[p_template - 1] + "." + ext;
- script_template = EditorSettings::get_singleton()->get_settings_path() + "/script_templates/" + name;
+ script_template = EditorSettings::get_singleton()->get_script_templates_dir().plus_file(name);
}
void ScriptCreateDialog::ok_pressed() {
@@ -145,9 +145,13 @@ void ScriptCreateDialog::ok_pressed() {
void ScriptCreateDialog::_create_new() {
- String cname;
- if (has_named_classes)
- cname = class_name->get_text();
+ String cname_param;
+
+ if (has_named_classes) {
+ cname_param = class_name->get_text();
+ } else {
+ cname_param = ProjectSettings::get_singleton()->localize_path(file_path->get_text()).get_file().get_basename();
+ }
Ref<Script> scr;
if (script_template != "") {
@@ -159,13 +163,16 @@ void ScriptCreateDialog::_create_new() {
return;
}
scr = scr->duplicate();
- ScriptServer::get_language(language_menu->get_selected())->make_template(cname, parent_name->get_text(), scr);
+ ScriptServer::get_language(language_menu->get_selected())->make_template(cname_param, parent_name->get_text(), scr);
} else {
- scr = ScriptServer::get_language(language_menu->get_selected())->get_template(cname, parent_name->get_text());
+ scr = ScriptServer::get_language(language_menu->get_selected())->get_template(cname_param, parent_name->get_text());
}
- if (cname != "")
- scr->set_name(cname);
+ if (has_named_classes) {
+ String cname = class_name->get_text();
+ if (cname.length())
+ scr->set_name(cname);
+ }
if (!is_built_in) {
String lpath = ProjectSettings::get_singleton()->localize_path(file_path->get_text());
@@ -201,12 +208,20 @@ void ScriptCreateDialog::_lang_changed(int l) {
l = language_menu->get_selected();
ScriptLanguage *language = ScriptServer::get_language(l);
+
if (language->has_named_classes()) {
has_named_classes = true;
} else {
has_named_classes = false;
}
+ if (language->supports_builtin_mode()) {
+ supports_built_in = true;
+ } else {
+ supports_built_in = false;
+ is_built_in = false;
+ }
+
if (ScriptServer::get_language(l)->can_inherit_from_file()) {
can_inherit_from_file = true;
} else {
@@ -496,6 +511,9 @@ void ScriptCreateDialog::_update_dialog() {
}
}
+ if (!supports_built_in)
+ internal->set_pressed(false);
+
/* Is Script created or loaded from existing file */
if (is_new_script_created) {
@@ -503,7 +521,7 @@ void ScriptCreateDialog::_update_dialog() {
get_ok()->set_text(TTR("Create"));
parent_name->set_editable(true);
parent_browse_button->set_disabled(false);
- internal->set_disabled(false);
+ internal->set_disabled(!supports_built_in);
if (is_built_in) {
_msg_path_valid(true, TTR("Built-in script (into scene file)"));
} else {
@@ -685,9 +703,7 @@ ScriptCreateDialog::ScriptCreateDialog() {
internal = memnew(CheckButton);
internal->connect("pressed", this, "_built_in_pressed");
hb = memnew(HBoxContainer);
- Control *empty = memnew(Control);
hb->add_child(internal);
- hb->add_child(empty);
l = memnew(Label);
l->set_text(TTR("Built-in Script"));
l->set_align(Label::ALIGN_RIGHT);
@@ -734,6 +750,7 @@ ScriptCreateDialog::ScriptCreateDialog() {
is_path_valid = false;
has_named_classes = false;
+ supports_built_in = false;
can_inherit_from_file = false;
is_built_in = false;