1 /*************************************************************************/ 2 /* script_create_dialog.h */ 3 /*************************************************************************/ 4 /* This file is part of: */ 5 /* GODOT ENGINE */ 6 /* https://godotengine.org */ 7 /*************************************************************************/ 8 /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ 9 /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ 10 /* */ 11 /* Permission is hereby granted, free of charge, to any person obtaining */ 12 /* a copy of this software and associated documentation files (the */ 13 /* "Software"), to deal in the Software without restriction, including */ 14 /* without limitation the rights to use, copy, modify, merge, publish, */ 15 /* distribute, sublicense, and/or sell copies of the Software, and to */ 16 /* permit persons to whom the Software is furnished to do so, subject to */ 17 /* the following conditions: */ 18 /* */ 19 /* The above copyright notice and this permission notice shall be */ 20 /* included in all copies or substantial portions of the Software. */ 21 /* */ 22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ 23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ 24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ 25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ 26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ 27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ 28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 29 /*************************************************************************/ 30 31 #ifndef SCRIPT_CREATE_DIALOG_H 32 #define SCRIPT_CREATE_DIALOG_H 33 34 #include "editor/editor_file_dialog.h" 35 #include "editor/editor_settings.h" 36 #include "scene/gui/check_box.h" 37 #include "scene/gui/dialogs.h" 38 #include "scene/gui/grid_container.h" 39 #include "scene/gui/line_edit.h" 40 #include "scene/gui/option_button.h" 41 #include "scene/gui/panel_container.h" 42 43 class CreateDialog; 44 45 class ScriptCreateDialog : public ConfirmationDialog { 46 GDCLASS(ScriptCreateDialog, ConfirmationDialog); 47 48 LineEdit *class_name; 49 Label *error_label; 50 Label *path_error_label; 51 Label *builtin_warning_label; 52 PanelContainer *status_panel; 53 LineEdit *parent_name; 54 Button *parent_browse_button; 55 Button *parent_search_button; 56 OptionButton *language_menu; 57 OptionButton *template_menu; 58 LineEdit *file_path; 59 Button *path_button; 60 EditorFileDialog *file_browse; 61 CheckBox *internal; 62 VBoxContainer *path_vb; 63 AcceptDialog *alert; 64 CreateDialog *select_class; 65 bool path_valid; 66 bool create_new; 67 bool is_browsing_parent; 68 String initial_bp; 69 bool is_new_script_created; 70 bool is_path_valid; 71 bool has_named_classes; 72 bool supports_built_in; 73 bool can_inherit_from_file; 74 bool is_parent_name_valid; 75 bool is_class_name_valid; 76 bool is_built_in; 77 bool built_in_enabled; 78 bool load_enabled; 79 int current_language; 80 int default_language; 81 bool re_check_path; 82 83 enum ScriptOrigin { 84 SCRIPT_ORIGIN_PROJECT, 85 SCRIPT_ORIGIN_EDITOR, 86 }; 87 struct ScriptTemplateInfo { 88 int id; 89 ScriptOrigin origin; 90 String dir; 91 String name; 92 String extension; 93 }; 94 95 String script_template; 96 Vector<ScriptTemplateInfo> template_list; 97 Map<String, Vector<int> > template_overrides; // name : indices 98 99 void _update_script_templates(const String &p_extension); 100 101 String base_type; 102 103 void _path_hbox_sorted(); 104 bool _can_be_built_in(); 105 void _path_changed(const String &p_path = String()); 106 void _path_entered(const String &p_path = String()); 107 void _lang_changed(int l = 0); 108 void _built_in_pressed(); 109 bool _validate_parent(const String &p_string); 110 bool _validate_class(const String &p_string); 111 String _validate_path(const String &p_path, bool p_file_must_exist); 112 void _class_name_changed(const String &p_name); 113 void _parent_name_changed(const String &p_parent); 114 void _template_changed(int p_template = 0); 115 void _browse_path(bool browse_parent, bool p_save); 116 void _file_selected(const String &p_file); 117 void _create(); 118 void _browse_class_in_tree(); 119 virtual void ok_pressed(); 120 void _create_new(); 121 void _load_exist(); 122 void _msg_script_valid(bool valid, const String &p_msg = String()); 123 void _msg_path_valid(bool valid, const String &p_msg = String()); 124 void _update_dialog(); 125 126 protected: 127 void _notification(int p_what); 128 static void _bind_methods(); 129 130 public: 131 void config(const String &p_base_name, const String &p_base_path, bool p_built_in_enabled = true, bool p_load_enabled = true); 132 void set_inheritance_base_type(const String &p_base); 133 ScriptCreateDialog(); 134 }; 135 136 #endif // SCRIPT_CREATE_DIALOG_H 137