script_create_dialog.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 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. #ifndef SCRIPT_CREATE_DIALOG_H
  31. #define SCRIPT_CREATE_DIALOG_H
  32. #include "editor/editor_file_dialog.h"
  33. #include "editor/editor_settings.h"
  34. #include "scene/gui/check_box.h"
  35. #include "scene/gui/dialogs.h"
  36. #include "scene/gui/grid_container.h"
  37. #include "scene/gui/line_edit.h"
  38. #include "scene/gui/option_button.h"
  39. #include "scene/gui/panel_container.h"
  40. class CreateDialog;
  41. class ScriptCreateDialog : public ConfirmationDialog {
  42. GDCLASS(ScriptCreateDialog, ConfirmationDialog);
  43. LineEdit *class_name;
  44. Label *error_label;
  45. Label *path_error_label;
  46. Label *builtin_warning_label;
  47. Label *script_name_warning_label;
  48. PanelContainer *status_panel;
  49. LineEdit *parent_name;
  50. Button *parent_browse_button;
  51. Button *parent_search_button;
  52. OptionButton *language_menu;
  53. OptionButton *template_menu;
  54. LineEdit *file_path;
  55. Button *path_button;
  56. EditorFileDialog *file_browse;
  57. CheckBox *internal;
  58. VBoxContainer *path_vb;
  59. AcceptDialog *alert;
  60. CreateDialog *select_class;
  61. bool path_valid;
  62. bool create_new;
  63. bool is_browsing_parent;
  64. String initial_bp;
  65. bool is_new_script_created;
  66. bool is_path_valid;
  67. bool has_named_classes;
  68. bool supports_built_in;
  69. bool can_inherit_from_file;
  70. bool is_parent_name_valid;
  71. bool is_class_name_valid;
  72. bool is_built_in;
  73. bool built_in_enabled;
  74. bool load_enabled;
  75. int current_language;
  76. int default_language;
  77. bool re_check_path;
  78. enum ScriptOrigin {
  79. SCRIPT_ORIGIN_PROJECT,
  80. SCRIPT_ORIGIN_EDITOR,
  81. };
  82. struct ScriptTemplateInfo {
  83. int id;
  84. ScriptOrigin origin;
  85. String dir;
  86. String name;
  87. String extension;
  88. };
  89. String script_template;
  90. Vector<ScriptTemplateInfo> template_list;
  91. Map<String, Vector<int>> template_overrides; // name : indices
  92. void _update_script_templates(const String &p_extension);
  93. String base_type;
  94. void _path_hbox_sorted();
  95. bool _can_be_built_in();
  96. void _path_changed(const String &p_path = String());
  97. void _path_entered(const String &p_path = String());
  98. void _lang_changed(int l = 0);
  99. void _built_in_pressed();
  100. bool _validate_parent(const String &p_string);
  101. bool _validate_class(const String &p_string);
  102. String _validate_path(const String &p_path, bool p_file_must_exist);
  103. String _get_class_name() const;
  104. void _class_name_changed(const String &p_name);
  105. void _parent_name_changed(const String &p_parent);
  106. void _template_changed(int p_template = 0);
  107. void _browse_path(bool browse_parent, bool p_save);
  108. void _file_selected(const String &p_file);
  109. void _create();
  110. void _browse_class_in_tree();
  111. virtual void ok_pressed();
  112. void _create_new();
  113. void _load_exist();
  114. void _msg_script_valid(bool valid, const String &p_msg = String());
  115. void _msg_path_valid(bool valid, const String &p_msg = String());
  116. void _update_dialog();
  117. protected:
  118. void _notification(int p_what);
  119. static void _bind_methods();
  120. public:
  121. void config(const String &p_base_name, const String &p_base_path, bool p_built_in_enabled = true, bool p_load_enabled = true);
  122. void set_inheritance_base_type(const String &p_base);
  123. ScriptCreateDialog();
  124. };
  125. #endif // SCRIPT_CREATE_DIALOG_H