| 1 | /**************************************************************************/ |
| 2 | /* script_create_dialog.h */ |
| 3 | /**************************************************************************/ |
| 4 | /* This file is part of: */ |
| 5 | /* GODOT ENGINE */ |
| 6 | /* https://godotengine.org */ |
| 7 | /**************************************************************************/ |
| 8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
| 9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
| 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 "core/object/script_language.h" |
| 35 | #include "scene/gui/check_box.h" |
| 36 | #include "scene/gui/dialogs.h" |
| 37 | #include "scene/gui/grid_container.h" |
| 38 | #include "scene/gui/line_edit.h" |
| 39 | #include "scene/gui/option_button.h" |
| 40 | #include "scene/gui/panel_container.h" |
| 41 | |
| 42 | class CreateDialog; |
| 43 | class EditorFileDialog; |
| 44 | class EditorValidationPanel; |
| 45 | |
| 46 | class ScriptCreateDialog : public ConfirmationDialog { |
| 47 | GDCLASS(ScriptCreateDialog, ConfirmationDialog); |
| 48 | |
| 49 | enum { |
| 50 | MSG_ID_SCRIPT, |
| 51 | MSG_ID_PATH, |
| 52 | MSG_ID_BUILT_IN, |
| 53 | MSG_ID_TEMPLATE, |
| 54 | }; |
| 55 | |
| 56 | LineEdit *class_name = nullptr; |
| 57 | EditorValidationPanel *validation_panel = nullptr; |
| 58 | LineEdit *parent_name = nullptr; |
| 59 | Button *parent_browse_button = nullptr; |
| 60 | Button *parent_search_button = nullptr; |
| 61 | OptionButton * = nullptr; |
| 62 | OptionButton * = nullptr; |
| 63 | LineEdit *file_path = nullptr; |
| 64 | LineEdit *internal_name = nullptr; |
| 65 | Button *path_button = nullptr; |
| 66 | EditorFileDialog *file_browse = nullptr; |
| 67 | CheckBox *internal = nullptr; |
| 68 | CheckBox *use_templates = nullptr; |
| 69 | VBoxContainer *path_vb = nullptr; |
| 70 | AcceptDialog *alert = nullptr; |
| 71 | CreateDialog *select_class = nullptr; |
| 72 | bool is_browsing_parent = false; |
| 73 | String path_error; |
| 74 | String template_inactive_message; |
| 75 | String initial_bp; |
| 76 | bool is_new_script_created = true; |
| 77 | bool is_path_valid = false; |
| 78 | bool has_named_classes = false; |
| 79 | bool supports_built_in = false; |
| 80 | bool can_inherit_from_file = false; |
| 81 | bool is_parent_name_valid = false; |
| 82 | bool is_class_name_valid = false; |
| 83 | bool is_built_in = false; |
| 84 | bool is_using_templates = true; |
| 85 | bool built_in_enabled = true; |
| 86 | bool load_enabled = true; |
| 87 | int current_language; |
| 88 | int default_language; |
| 89 | bool re_check_path = false; |
| 90 | |
| 91 | Control *path_controls[2]; |
| 92 | Control *name_controls[2]; |
| 93 | |
| 94 | Vector<ScriptLanguage::ScriptTemplate> template_list; |
| 95 | ScriptLanguage *language = nullptr; |
| 96 | |
| 97 | String base_type; |
| 98 | |
| 99 | void _path_hbox_sorted(); |
| 100 | bool _can_be_built_in(); |
| 101 | void _path_changed(const String &p_path = String()); |
| 102 | void _path_submitted(const String &p_path = String()); |
| 103 | void _language_changed(int l = 0); |
| 104 | void _built_in_pressed(); |
| 105 | void _use_template_pressed(); |
| 106 | bool _validate_parent(const String &p_string); |
| 107 | bool _validate_class(const String &p_string); |
| 108 | String _validate_path(const String &p_path, bool p_file_must_exist); |
| 109 | String _get_class_name() const; |
| 110 | void _class_name_changed(const String &p_name); |
| 111 | void _parent_name_changed(const String &p_parent); |
| 112 | void _template_changed(int p_template = 0); |
| 113 | void _browse_path(bool browse_parent, bool p_save); |
| 114 | void _file_selected(const String &p_file); |
| 115 | void _create(); |
| 116 | void _browse_class_in_tree(); |
| 117 | virtual void ok_pressed() override; |
| 118 | void _create_new(); |
| 119 | void _load_exist(); |
| 120 | void (); |
| 121 | void _update_dialog(); |
| 122 | ScriptLanguage::ScriptTemplate _get_current_template() const; |
| 123 | Vector<ScriptLanguage::ScriptTemplate> _get_user_templates(const ScriptLanguage *p_language, const StringName &p_object, const String &p_dir, const ScriptLanguage::TemplateLocation &p_origin) const; |
| 124 | ScriptLanguage::ScriptTemplate _parse_template(const ScriptLanguage *p_language, const String &p_path, const String &p_filename, const ScriptLanguage::TemplateLocation &p_origin, const String &p_inherits) const; |
| 125 | String _get_script_origin_label(const ScriptLanguage::TemplateLocation &p_origin) const; |
| 126 | |
| 127 | protected: |
| 128 | void _notification(int p_what); |
| 129 | static void _bind_methods(); |
| 130 | |
| 131 | public: |
| 132 | void config(const String &p_base_name, const String &p_base_path, bool p_built_in_enabled = true, bool p_load_enabled = true); |
| 133 | void set_inheritance_base_type(const String &p_base); |
| 134 | ScriptCreateDialog(); |
| 135 | }; |
| 136 | |
| 137 | #endif // SCRIPT_CREATE_DIALOG_H |
| 138 | |