From 2dc4b035a8c1296934e7c053b90b30924461d62b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Go=C5=82=C4=85b=20=28n-pigeon=29?= Date: Wed, 3 May 2017 20:41:02 +0200 Subject: Reworked look and feel of Add Script Dialog. Untangled a lot of Controls logic code and placed it in one place. Which squashed few bugs and made code easier to maintain. --- editor/script_create_dialog.cpp | 519 ++++++++++++++++++++++++++++------------ 1 file changed, 372 insertions(+), 147 deletions(-) (limited to 'editor/script_create_dialog.cpp') diff --git a/editor/script_create_dialog.cpp b/editor/script_create_dialog.cpp index 15c540e132..1e86d8db4b 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 { + is_class_name_valid = false; + } + _update_dialog(); +} - error_label->set_text(TTR("N/A")); - error_label->add_color_override("font_color", Color(0, 1.0, 0.8, 0.8)); +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