project_dialog.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /**************************************************************************/
  2. /* project_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 PROJECT_DIALOG_H
  31. #define PROJECT_DIALOG_H
  32. #include "scene/gui/dialogs.h"
  33. class Button;
  34. class CheckButton;
  35. class EditorFileDialog;
  36. class LineEdit;
  37. class OptionButton;
  38. class TextureRect;
  39. class ProjectDialog : public ConfirmationDialog {
  40. GDCLASS(ProjectDialog, ConfirmationDialog);
  41. public:
  42. enum Mode {
  43. MODE_NEW,
  44. MODE_IMPORT,
  45. MODE_INSTALL,
  46. MODE_RENAME,
  47. };
  48. private:
  49. enum MessageType {
  50. MESSAGE_ERROR,
  51. MESSAGE_WARNING,
  52. MESSAGE_SUCCESS,
  53. };
  54. enum InputType {
  55. PROJECT_PATH,
  56. INSTALL_PATH,
  57. };
  58. Mode mode = MODE_NEW;
  59. bool is_folder_empty = true;
  60. ConfirmationDialog *nonempty_confirmation = nullptr;
  61. CheckButton *create_dir = nullptr;
  62. Button *project_browse = nullptr;
  63. Button *install_browse = nullptr;
  64. VBoxContainer *name_container = nullptr;
  65. VBoxContainer *project_path_container = nullptr;
  66. VBoxContainer *install_path_container = nullptr;
  67. VBoxContainer *renderer_container = nullptr;
  68. Label *renderer_info = nullptr;
  69. HBoxContainer *default_files_container = nullptr;
  70. Ref<ButtonGroup> renderer_button_group;
  71. bool rendering_device_supported = false;
  72. Label *rd_not_supported = nullptr;
  73. Label *msg = nullptr;
  74. LineEdit *project_name = nullptr;
  75. LineEdit *project_path = nullptr;
  76. LineEdit *install_path = nullptr;
  77. TextureRect *project_status_rect = nullptr;
  78. TextureRect *install_status_rect = nullptr;
  79. OptionButton *vcs_metadata_selection = nullptr;
  80. EditorFileDialog *fdialog_project = nullptr;
  81. EditorFileDialog *fdialog_install = nullptr;
  82. AcceptDialog *dialog_error = nullptr;
  83. String zip_path;
  84. String zip_title;
  85. void _set_message(const String &p_msg, MessageType p_type, InputType input_type = PROJECT_PATH);
  86. void _validate_path();
  87. // Project path for MODE_NEW and MODE_INSTALL. Install path for MODE_IMPORT.
  88. // Install path is only visible when importing a ZIP.
  89. String _get_target_path();
  90. void _set_target_path(const String &p_text);
  91. // Calculated from project name / ZIP name.
  92. String auto_dir;
  93. // Updates `auto_dir`. If the target path dir name is equal to `auto_dir` (the default state), the target path is also updated.
  94. void _update_target_auto_dir();
  95. // While `create_dir` is disabled, stores the last target path dir name, or an empty string if equal to `auto_dir`.
  96. String last_custom_target_dir;
  97. void _create_dir_toggled(bool p_pressed);
  98. void _project_name_changed();
  99. void _project_path_changed();
  100. void _install_path_changed();
  101. void _browse_project_path();
  102. void _browse_install_path();
  103. void _project_path_selected(const String &p_path);
  104. void _install_path_selected(const String &p_path);
  105. void _reset_name();
  106. void _renderer_selected();
  107. void _nonempty_confirmation_ok_pressed();
  108. void ok_pressed() override;
  109. protected:
  110. static void _bind_methods();
  111. void _notification(int p_what);
  112. public:
  113. void set_mode(Mode p_mode);
  114. void set_project_name(const String &p_name);
  115. void set_project_path(const String &p_path);
  116. void set_zip_path(const String &p_path);
  117. void set_zip_title(const String &p_title);
  118. void ask_for_path_and_show();
  119. void show_dialog(bool p_reset_name = true);
  120. ProjectDialog();
  121. };
  122. #endif // PROJECT_DIALOG_H