Warn when creating a script with the same name as the parent class
(cherry picked from commit 5a9037f828
)
This commit is contained in:
parent
917630107c
commit
d304187357
2 changed files with 23 additions and 8 deletions
|
@ -225,6 +225,14 @@ String ScriptCreateDialog::_validate_path(const String &p_path, bool p_file_must
|
|||
return "";
|
||||
}
|
||||
|
||||
String ScriptCreateDialog::_get_class_name() const {
|
||||
if (has_named_classes) {
|
||||
return class_name->get_text();
|
||||
} else {
|
||||
return ProjectSettings::get_singleton()->localize_path(file_path->get_text()).get_file().get_basename();
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptCreateDialog::_class_name_changed(const String &p_name) {
|
||||
|
||||
if (_validate_class(class_name->get_text())) {
|
||||
|
@ -278,14 +286,7 @@ void ScriptCreateDialog::ok_pressed() {
|
|||
}
|
||||
|
||||
void ScriptCreateDialog::_create_new() {
|
||||
|
||||
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();
|
||||
}
|
||||
String cname_param = _get_class_name();
|
||||
|
||||
Ref<Script> scr;
|
||||
if (script_template != "") {
|
||||
|
@ -690,6 +691,10 @@ void ScriptCreateDialog::_update_dialog() {
|
|||
|
||||
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());
|
||||
|
||||
if (is_built_in) {
|
||||
get_ok()->set_text(TTR("Create"));
|
||||
parent_name->set_editable(true);
|
||||
|
@ -775,6 +780,14 @@ ScriptCreateDialog::ScriptCreateDialog() {
|
|||
builtin_warning_label->set_autowrap(true);
|
||||
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."));
|
||||
vb->add_child(script_name_warning_label);
|
||||
script_name_warning_label->add_color_override("font_color", Color(1, 0.85, 0.4));
|
||||
script_name_warning_label->set_autowrap(true);
|
||||
script_name_warning_label->hide();
|
||||
|
||||
status_panel = memnew(PanelContainer);
|
||||
status_panel->set_h_size_flags(Control::SIZE_FILL);
|
||||
status_panel->add_child(vb);
|
||||
|
|
|
@ -49,6 +49,7 @@ class ScriptCreateDialog : public ConfirmationDialog {
|
|||
Label *error_label;
|
||||
Label *path_error_label;
|
||||
Label *builtin_warning_label;
|
||||
Label *script_name_warning_label;
|
||||
PanelContainer *status_panel;
|
||||
LineEdit *parent_name;
|
||||
Button *parent_browse_button;
|
||||
|
@ -109,6 +110,7 @@ class ScriptCreateDialog : public ConfirmationDialog {
|
|||
bool _validate_parent(const String &p_string);
|
||||
bool _validate_class(const String &p_string);
|
||||
String _validate_path(const String &p_path, bool p_file_must_exist);
|
||||
String _get_class_name() const;
|
||||
void _class_name_changed(const String &p_name);
|
||||
void _parent_name_changed(const String &p_parent);
|
||||
void _template_changed(int p_template = 0);
|
||||
|
|
Loading…
Reference in a new issue