script_create_dialog.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. #ifndef SCRIPT_CREATE_DIALOG_H
  31. #define SCRIPT_CREATE_DIALOG_H
  32. #include "core/object/script_language.h"
  33. #include "scene/gui/check_box.h"
  34. #include "scene/gui/dialogs.h"
  35. #include "scene/gui/grid_container.h"
  36. #include "scene/gui/line_edit.h"
  37. #include "scene/gui/option_button.h"
  38. #include "scene/gui/panel_container.h"
  39. class CreateDialog;
  40. class EditorFileDialog;
  41. class ScriptCreateDialog : public ConfirmationDialog {
  42. GDCLASS(ScriptCreateDialog, ConfirmationDialog);
  43. LineEdit *class_name = nullptr;
  44. Label *error_label = nullptr;
  45. Label *path_error_label = nullptr;
  46. Label *builtin_warning_label = nullptr;
  47. Label *script_name_warning_label = nullptr;
  48. Label *template_info_label = nullptr;
  49. PanelContainer *status_panel = nullptr;
  50. LineEdit *parent_name = nullptr;
  51. Button *parent_browse_button = nullptr;
  52. Button *parent_search_button = nullptr;
  53. OptionButton *language_menu = nullptr;
  54. OptionButton *template_menu = nullptr;
  55. LineEdit *file_path = nullptr;
  56. LineEdit *internal_name = nullptr;
  57. Button *path_button = nullptr;
  58. EditorFileDialog *file_browse = nullptr;
  59. CheckBox *internal = nullptr;
  60. CheckBox *use_templates = nullptr;
  61. VBoxContainer *path_vb = nullptr;
  62. AcceptDialog *alert = nullptr;
  63. CreateDialog *select_class = nullptr;
  64. bool is_browsing_parent = false;
  65. String template_inactive_message;
  66. String initial_bp;
  67. bool is_new_script_created = true;
  68. bool is_path_valid = false;
  69. bool has_named_classes = false;
  70. bool supports_built_in = false;
  71. bool can_inherit_from_file = false;
  72. bool is_parent_name_valid = false;
  73. bool is_class_name_valid = false;
  74. bool is_built_in = false;
  75. bool is_using_templates = true;
  76. bool built_in_enabled = true;
  77. bool load_enabled = true;
  78. int current_language;
  79. int default_language;
  80. bool re_check_path = false;
  81. Control *path_controls[2];
  82. Control *name_controls[2];
  83. Vector<ScriptLanguage::ScriptTemplate> template_list;
  84. ScriptLanguage *language = nullptr;
  85. String base_type;
  86. void _path_hbox_sorted();
  87. bool _can_be_built_in();
  88. void _path_changed(const String &p_path = String());
  89. void _path_submitted(const String &p_path = String());
  90. void _language_changed(int l = 0);
  91. void _built_in_pressed();
  92. void _use_template_pressed();
  93. bool _validate_parent(const String &p_string);
  94. bool _validate_class(const String &p_string);
  95. String _validate_path(const String &p_path, bool p_file_must_exist);
  96. String _get_class_name() const;
  97. void _class_name_changed(const String &p_name);
  98. void _parent_name_changed(const String &p_parent);
  99. void _template_changed(int p_template = 0);
  100. void _browse_path(bool browse_parent, bool p_save);
  101. void _file_selected(const String &p_file);
  102. void _create();
  103. void _browse_class_in_tree();
  104. virtual void ok_pressed() override;
  105. void _create_new();
  106. void _load_exist();
  107. void _msg_script_valid(bool valid, const String &p_msg = String());
  108. void _msg_path_valid(bool valid, const String &p_msg = String());
  109. void _update_template_menu();
  110. void _update_dialog();
  111. ScriptLanguage::ScriptTemplate _get_current_template() const;
  112. Vector<ScriptLanguage::ScriptTemplate> _get_user_templates(const ScriptLanguage *p_language, const StringName &p_object, const String &p_dir, const ScriptLanguage::TemplateLocation &p_origin) const;
  113. 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;
  114. String _get_script_origin_label(const ScriptLanguage::TemplateLocation &p_origin) const;
  115. protected:
  116. void _notification(int p_what);
  117. static void _bind_methods();
  118. public:
  119. void config(const String &p_base_name, const String &p_base_path, bool p_built_in_enabled = true, bool p_load_enabled = true);
  120. void set_inheritance_base_type(const String &p_base);
  121. ScriptCreateDialog();
  122. };
  123. #endif // SCRIPT_CREATE_DIALOG_H