summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2021-09-14 13:45:32 +0200
committerGitHub <noreply@github.com>2021-09-14 13:45:32 +0200
commitc110b294e910c6ede64801ba1030ee527d465e80 (patch)
treeacb26385056d435277f2c556e33e2d89b0b0a98a /editor
parent0c66c990e7fab2fc56fd69eee712ed3e01834e1b (diff)
parent645cc71be4b02020a5f783fa0a007a8f579d12bf (diff)
Merge pull request #52644 from jmb462/error-message-on-invalid-autoload-name
Display an error message in autoload settings when autoload name is invalid
Diffstat (limited to 'editor')
-rw-r--r--editor/editor_autoload_settings.cpp28
-rw-r--r--editor/editor_autoload_settings.h1
2 files changed, 22 insertions, 7 deletions
diff --git a/editor/editor_autoload_settings.cpp b/editor/editor_autoload_settings.cpp
index 362c4c3457..fcf79a80a7 100644
--- a/editor/editor_autoload_settings.cpp
+++ b/editor/editor_autoload_settings.cpp
@@ -64,7 +64,12 @@ void EditorAutoloadSettings::_notification(int p_what) {
bool EditorAutoloadSettings::_autoload_name_is_valid(const String &p_name, String *r_error) {
if (!p_name.is_valid_identifier()) {
if (r_error) {
- *r_error = TTR("Invalid name.") + "\n" + TTR("Valid characters:") + " a-z, A-Z, 0-9 or _";
+ *r_error = TTR("Invalid name.") + " ";
+ if (p_name.size() > 0 && p_name.left(1).is_numeric()) {
+ *r_error += TTR("Cannot begin with a digit.");
+ } else {
+ *r_error += TTR("Valid characters:") + " a-z, A-Z, 0-9 or _";
+ }
}
return false;
@@ -72,7 +77,7 @@ bool EditorAutoloadSettings::_autoload_name_is_valid(const String &p_name, Strin
if (ClassDB::class_exists(p_name)) {
if (r_error) {
- *r_error = TTR("Invalid name.") + "\n" + TTR("Must not collide with an existing engine class name.");
+ *r_error = TTR("Invalid name.") + " " + TTR("Must not collide with an existing engine class name.");
}
return false;
@@ -89,7 +94,7 @@ bool EditorAutoloadSettings::_autoload_name_is_valid(const String &p_name, Strin
for (int i = 0; i < Variant::VARIANT_MAX; i++) {
if (Variant::get_type_name(Variant::Type(i)) == p_name) {
if (r_error) {
- *r_error = TTR("Invalid name.") + "\n" + TTR("Must not collide with an existing built-in type name.");
+ *r_error = TTR("Invalid name.") + " " + TTR("Must not collide with an existing built-in type name.");
}
return false;
@@ -99,7 +104,7 @@ bool EditorAutoloadSettings::_autoload_name_is_valid(const String &p_name, Strin
for (int i = 0; i < CoreConstants::get_global_constant_count(); i++) {
if (CoreConstants::get_global_constant_name(i) == p_name) {
if (r_error) {
- *r_error = TTR("Invalid name.") + "\n" + TTR("Must not collide with an existing global constant name.");
+ *r_error = TTR("Invalid name.") + " " + TTR("Must not collide with an existing global constant name.");
}
return false;
@@ -112,7 +117,7 @@ bool EditorAutoloadSettings::_autoload_name_is_valid(const String &p_name, Strin
for (const String &E : keywords) {
if (E == p_name) {
if (r_error) {
- *r_error = TTR("Invalid name.") + "\n" + TTR("Keyword cannot be used as an autoload name.");
+ *r_error = TTR("Invalid name.") + " " + TTR("Keyword cannot be used as an autoload name.");
}
return false;
@@ -346,8 +351,11 @@ void EditorAutoloadSettings::_autoload_path_text_changed(const String p_path) {
}
void EditorAutoloadSettings::_autoload_text_changed(const String p_name) {
- add_autoload->set_disabled(
- autoload_add_path->get_text() == "" || !_autoload_name_is_valid(p_name, nullptr));
+ String error_string;
+ bool is_name_valid = _autoload_name_is_valid(p_name, &error_string);
+ add_autoload->set_disabled(autoload_add_path->get_text() == "" || !is_name_valid);
+ error_message->set_text(error_string);
+ error_message->set_visible(autoload_add_name->get_text() != "" && !is_name_valid);
}
Node *EditorAutoloadSettings::_create_autoload(const String &p_path) {
@@ -828,6 +836,12 @@ EditorAutoloadSettings::EditorAutoloadSettings() {
HBoxContainer *hbc = memnew(HBoxContainer);
add_child(hbc);
+ error_message = memnew(Label);
+ error_message->hide();
+ error_message->set_align(Label::Align::ALIGN_RIGHT);
+ error_message->add_theme_color_override("font_color", EditorNode::get_singleton()->get_gui_base()->get_theme_color(SNAME("error_color"), SNAME("Editor")));
+ add_child(error_message);
+
Label *l = memnew(Label);
l->set_text(TTR("Path:"));
hbc->add_child(l);
diff --git a/editor/editor_autoload_settings.h b/editor/editor_autoload_settings.h
index b709728856..b8e054cd14 100644
--- a/editor/editor_autoload_settings.h
+++ b/editor/editor_autoload_settings.h
@@ -70,6 +70,7 @@ class EditorAutoloadSettings : public VBoxContainer {
LineEdit *autoload_add_name;
Button *add_autoload;
LineEdit *autoload_add_path;
+ Label *error_message;
Button *browse_button;
EditorFileDialog *file_dialog;