visual_script_property_selector.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /*************************************************************************/
  2. /* visual_script_property_selector.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 VISUALSCRIPT_PROPERTYSELECTOR_H
  31. #define VISUALSCRIPT_PROPERTYSELECTOR_H
  32. #include "../visual_script.h"
  33. #include "editor/editor_help.h"
  34. #include "editor/property_editor.h"
  35. #include "scene/gui/rich_text_label.h"
  36. class VisualScriptPropertySelector : public ConfirmationDialog {
  37. GDCLASS(VisualScriptPropertySelector, ConfirmationDialog);
  38. enum SearchFlags {
  39. SEARCH_CLASSES = 1 << 0,
  40. SEARCH_CONSTRUCTORS = 1 << 1,
  41. SEARCH_METHODS = 1 << 2,
  42. SEARCH_OPERATORS = 1 << 3,
  43. SEARCH_SIGNALS = 1 << 4,
  44. SEARCH_CONSTANTS = 1 << 5,
  45. SEARCH_PROPERTIES = 1 << 6,
  46. SEARCH_THEME_ITEMS = 1 << 7,
  47. SEARCH_VISUAL_SCRIPT_NODES = 1 << 8,
  48. SEARCH_ALL = SEARCH_CLASSES | SEARCH_CONSTRUCTORS | SEARCH_METHODS | SEARCH_OPERATORS | SEARCH_SIGNALS | SEARCH_CONSTANTS | SEARCH_PROPERTIES | SEARCH_THEME_ITEMS,
  49. SEARCH_CASE_SENSITIVE = 1 << 29,
  50. SEARCH_SHOW_HIERARCHY = 1 << 30,
  51. };
  52. enum ScopeFlags {
  53. SCOPE_BASE = 1 << 0,
  54. SCOPE_INHERITERS = 1 << 1,
  55. SCOPE_UNRELATED = 1 << 2,
  56. SCOPE_RELATED = SCOPE_BASE | SCOPE_INHERITERS,
  57. SCOPE_ALL = SCOPE_BASE | SCOPE_INHERITERS | SCOPE_UNRELATED
  58. };
  59. LineEdit *search_box;
  60. Button *case_sensitive_button;
  61. Button *hierarchy_button;
  62. Button *search_visual_script_nodes;
  63. Button *search_classes;
  64. Button *search_operators;
  65. Button *search_methods;
  66. Button *search_signals;
  67. Button *search_constants;
  68. Button *search_properties;
  69. Button *search_theme_items;
  70. OptionButton *scope_combo;
  71. Tree *results_tree;
  72. class SearchRunner;
  73. Ref<SearchRunner> search_runner;
  74. void _update_icons();
  75. void _sbox_input(const Ref<InputEvent> &p_ie);
  76. void _update_results_i(int p_int);
  77. void _update_results_s(String p_string);
  78. void _update_results();
  79. void _confirmed();
  80. void _item_selected();
  81. void _hide_requested();
  82. EditorHelpBit *help_bit;
  83. bool properties = false;
  84. bool visual_script_generic = false;
  85. bool connecting = false;
  86. String selected;
  87. Variant::Type type;
  88. String base_type;
  89. String base_script;
  90. ObjectID script;
  91. Object *instance;
  92. bool virtuals_only = false;
  93. VBoxContainer *vbox;
  94. protected:
  95. void _notification(int p_what);
  96. static void _bind_methods();
  97. public:
  98. void select_method_from_base_type(const String &p_base, const bool p_virtuals_only = false, const bool p_connecting = true, bool clear_text = true);
  99. void select_from_base_type(const String &p_base, const String &p_base_script = "", bool p_virtuals_only = false, const bool p_connecting = true, bool clear_text = true);
  100. void select_from_script(const Ref<Script> &p_script, const bool p_connecting = true, bool clear_text = true);
  101. void select_from_basic_type(Variant::Type p_type, const bool p_connecting = true, bool clear_text = true);
  102. void select_from_action(const String &p_type, const bool p_connecting = true, bool clear_text = true);
  103. void select_from_instance(Object *p_instance, const bool p_connecting = true, bool clear_text = true);
  104. void select_from_visual_script(const Ref<Script> &p_script, bool clear_text = true);
  105. void show_window(float p_screen_ratio);
  106. VisualScriptPropertySelector();
  107. };
  108. class VisualScriptPropertySelector::SearchRunner : public RefCounted {
  109. enum Phase {
  110. PHASE_INIT,
  111. PHASE_MATCH_CLASSES_INIT,
  112. PHASE_NODE_CLASSES_INIT,
  113. PHASE_NODE_CLASSES_BUILD,
  114. PHASE_MATCH_CLASSES,
  115. PHASE_CLASS_ITEMS_INIT,
  116. PHASE_CLASS_ITEMS,
  117. PHASE_MEMBER_ITEMS_INIT,
  118. PHASE_MEMBER_ITEMS,
  119. PHASE_SELECT_MATCH,
  120. PHASE_MAX
  121. };
  122. int phase = 0;
  123. struct ClassMatch {
  124. DocData::ClassDoc *doc;
  125. bool name = false;
  126. String category = "";
  127. Vector<DocData::MethodDoc *> constructors;
  128. Vector<DocData::MethodDoc *> methods;
  129. Vector<DocData::MethodDoc *> operators;
  130. Vector<DocData::MethodDoc *> signals;
  131. Vector<DocData::ConstantDoc *> constants;
  132. Vector<DocData::PropertyDoc *> properties;
  133. Vector<DocData::ThemeItemDoc *> theme_properties;
  134. bool required() {
  135. return name || methods.size() || signals.size() || constants.size() || properties.size() || theme_properties.size();
  136. }
  137. };
  138. VisualScriptPropertySelector *selector_ui;
  139. Control *ui_service;
  140. Tree *results_tree;
  141. String term;
  142. int search_flags;
  143. int scope_flags;
  144. Ref<Texture2D> empty_icon;
  145. Color disabled_color;
  146. Map<String, DocData::ClassDoc>::Element *iterator_doc = nullptr;
  147. Map<String, ClassMatch> matches;
  148. Map<String, ClassMatch>::Element *iterator_match = nullptr;
  149. TreeItem *root_item = nullptr;
  150. Map<String, TreeItem *> class_items;
  151. TreeItem *matched_item = nullptr;
  152. float match_highest_score = 0;
  153. Map<String, DocData::ClassDoc> combined_docs;
  154. List<String> vs_nodes;
  155. bool _is_class_disabled_by_feature_profile(const StringName &p_class);
  156. bool _is_class_disabled_by_scope(const StringName &p_class);
  157. bool _slice();
  158. bool _phase_init();
  159. bool _phase_match_classes_init();
  160. bool _phase_node_classes_init();
  161. bool _phase_node_classes_build();
  162. bool _phase_match_classes();
  163. bool _phase_class_items_init();
  164. bool _phase_class_items();
  165. bool _phase_member_items_init();
  166. bool _phase_member_items();
  167. bool _phase_select_match();
  168. bool _match_string(const String &p_term, const String &p_string) const;
  169. bool _match_visual_script(DocData::ClassDoc &class_doc);
  170. bool _match_is_hidden(DocData::ClassDoc &class_doc);
  171. void _match_item(TreeItem *p_item, const String &p_text);
  172. void _add_class_doc(String class_name, String inherits, String category);
  173. DocData::MethodDoc _get_method_doc(MethodInfo method_info);
  174. TreeItem *_create_class_hierarchy(const ClassMatch &p_match);
  175. TreeItem *_create_class_item(TreeItem *p_parent, const DocData::ClassDoc *p_doc, bool p_gray);
  176. TreeItem *_create_method_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const String &p_text, const DocData::MethodDoc *p_doc);
  177. TreeItem *_create_signal_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::MethodDoc *p_doc);
  178. TreeItem *_create_constant_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::ConstantDoc *p_doc);
  179. TreeItem *_create_property_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::PropertyDoc *p_doc);
  180. TreeItem *_create_theme_property_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::ThemeItemDoc *p_doc);
  181. TreeItem *_create_member_item(TreeItem *p_parent, const String &p_class_name, const String &p_icon, const String &p_name, const String &p_text, const String &p_type, const String &p_metatype, const String &p_tooltip, const String &p_description);
  182. public:
  183. bool work(uint64_t slot = 100000);
  184. SearchRunner(VisualScriptPropertySelector *p_selector_ui, Tree *p_results_tree);
  185. };
  186. #endif // VISUALSCRIPT_PROPERTYSELECTOR_H