diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index 901b259960f..835243e4015 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -362,8 +362,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { else { String path = selected->get_filename(); script_create_dialog->config(selected->get_class(), path); - script_create_dialog->popup_centered(Size2(300, 290)); - //script_create_dialog->popup_centered_minsize(); + script_create_dialog->popup_centered(); } } break; diff --git a/editor/script_create_dialog.cpp b/editor/script_create_dialog.cpp index 15c540e1321..1e86d8db4b4 100644 --- a/editor/script_create_dialog.cpp +++ b/editor/script_create_dialog.cpp @@ -29,12 +29,23 @@ /*************************************************************************/ #include "script_create_dialog.h" +#include "editor/editor_scale.h" #include "editor_file_system.h" #include "global_config.h" #include "io/resource_saver.h" #include "os/file_access.h" #include "script_language.h" +void ScriptCreateDialog::_notification(int p_what) { + + switch (p_what) { + case NOTIFICATION_ENTER_TREE: { + path_button->set_icon(get_icon("Folder", "EditorIcons")); + parent_browse_button->set_icon(get_icon("Folder", "EditorIcons")); + } + } +} + void ScriptCreateDialog::config(const String &p_base_name, const String &p_base_path) { class_name->set_text(""); @@ -46,6 +57,8 @@ void ScriptCreateDialog::config(const String &p_base_name, const String &p_base_ initial_bp = ""; file_path->set_text(""); } + _lang_changed(current_language); + _parent_name_changed(parent_name->get_text()); _class_name_changed(""); _path_changed(file_path->get_text()); } @@ -85,54 +98,40 @@ bool ScriptCreateDialog::_validate(const String &p_string) { void ScriptCreateDialog::_class_name_changed(const String &p_name) { - if (!_validate(parent_name->get_text())) { - error_label->set_text(TTR("Invalid parent class name or path")); - error_label->add_color_override("font_color", Color(1, 0.4, 0.0, 0.8)); - } else if (class_name->is_editable()) { - if (class_name->get_text() == "") { - error_label->set_text(TTR("Valid chars:") + " a-z A-Z 0-9 _"); - error_label->add_color_override("font_color", Color(1, 1, 1, 0.6)); - } else if (!_validate(class_name->get_text())) { - error_label->set_text(TTR("Invalid class name")); - error_label->add_color_override("font_color", Color(1, 0.2, 0.2, 0.8)); - } else { - error_label->set_text(TTR("Valid name")); - error_label->add_color_override("font_color", Color(0, 1.0, 0.8, 0.8)); - } + if (_validate(class_name->get_text())) { + is_class_name_valid = true; } else { - - error_label->set_text(TTR("N/A")); - error_label->add_color_override("font_color", Color(0, 1.0, 0.8, 0.8)); + is_class_name_valid = false; } + _update_dialog(); +} + +void ScriptCreateDialog::_parent_name_changed(const String &p_parent) { + + if (_validate(parent_name->get_text())) { + is_parent_name_valid = true; + } else { + is_parent_name_valid = false; + } + _update_dialog(); } void ScriptCreateDialog::ok_pressed() { - if (create_new) { + if (is_new_script_created) { _create_new(); } else { _load_exist(); } - create_new = true; - _update_controls(); + is_new_script_created = true; + _update_dialog(); } void ScriptCreateDialog::_create_new() { - if (class_name->is_editable() && !_validate(class_name->get_text())) { - alert->set_text(TTR("Class name is invalid!")); - alert->popup_centered_minsize(); - return; - } - if (!_validate(parent_name->get_text())) { - alert->set_text(TTR("Parent class name is invalid!")); - alert->popup_centered_minsize(); - return; - } - String cname; - if (class_name->is_editable()) + if (has_named_classes) cname = class_name->get_text(); Ref