create_dialog.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /**************************************************************************/
  2. /* 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 CREATE_DIALOG_H
  31. #define CREATE_DIALOG_H
  32. #include "editor/editor_help.h"
  33. #include "scene/gui/button.h"
  34. #include "scene/gui/dialogs.h"
  35. #include "scene/gui/item_list.h"
  36. #include "scene/gui/line_edit.h"
  37. #include "scene/gui/tree.h"
  38. class CreateDialog : public ConfirmationDialog {
  39. GDCLASS(CreateDialog, ConfirmationDialog);
  40. enum TypeCategory {
  41. CPP_TYPE,
  42. PATH_TYPE,
  43. OTHER_TYPE
  44. };
  45. LineEdit *search_box = nullptr;
  46. Tree *search_options = nullptr;
  47. String base_type;
  48. bool is_base_type_node = false;
  49. String icon_fallback;
  50. String preferred_search_result_type;
  51. Button *favorite = nullptr;
  52. Vector<String> favorite_list;
  53. Tree *favorites = nullptr;
  54. ItemList *recent = nullptr;
  55. EditorHelpBit *help_bit = nullptr;
  56. HashMap<String, TreeItem *> search_options_types;
  57. HashMap<String, String> custom_type_parents;
  58. HashMap<String, int> custom_type_indices;
  59. List<StringName> type_list;
  60. HashSet<StringName> type_blacklist;
  61. HashSet<StringName> custom_type_blocklist;
  62. HashMap<StringName, String> custom_type_suffixes;
  63. void _update_search();
  64. bool _should_hide_type(const StringName &p_type) const;
  65. void _add_type(const StringName &p_type, TypeCategory p_type_category);
  66. void _configure_search_option_item(TreeItem *r_item, const StringName &p_type, TypeCategory p_type_category);
  67. float _score_type(const String &p_type, const String &p_search) const;
  68. bool _is_type_preferred(const String &p_type) const;
  69. void _fill_type_list();
  70. void _cleanup();
  71. void _sbox_input(const Ref<InputEvent> &p_event);
  72. void _text_changed(const String &p_newtext);
  73. void select_type(const String &p_type, bool p_center_on_item = true);
  74. void _item_selected();
  75. void _hide_requested();
  76. void _confirmed();
  77. virtual void cancel_pressed() override;
  78. void _favorite_toggled();
  79. void _history_selected(int p_idx);
  80. void _favorite_selected();
  81. void _history_activated(int p_idx);
  82. void _favorite_activated();
  83. Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
  84. bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
  85. void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
  86. bool _is_class_disabled_by_feature_profile(const StringName &p_class) const;
  87. void _load_favorites_and_history();
  88. protected:
  89. void _notification(int p_what);
  90. static void _bind_methods();
  91. void _save_and_update_favorite_list();
  92. public:
  93. Variant instantiate_selected();
  94. String get_selected_type();
  95. void set_base_type(const String &p_base);
  96. String get_base_type() const { return base_type; }
  97. void select_base();
  98. void set_type_blocklist(const HashSet<StringName> &p_blocklist) { custom_type_blocklist = p_blocklist; }
  99. void set_type_suffixes(const HashMap<StringName, String> &p_suffixes) { custom_type_suffixes = p_suffixes; }
  100. void set_preferred_search_result_type(const String &p_preferred_type) { preferred_search_result_type = p_preferred_type; }
  101. void popup_create(bool p_dont_clear, bool p_replace_mode = false, const String &p_current_type = "", const String &p_current_name = "");
  102. CreateDialog();
  103. };
  104. #endif // CREATE_DIALOG_H