visual_script_property_selector.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. enum ScopeCombo {
  60. COMBO_RELATED,
  61. COMBO_SEPARATOR,
  62. COMBO_BASE,
  63. COMBO_INHERITERS,
  64. COMBO_UNRELATED,
  65. COMBO_ALL,
  66. };
  67. LineEdit *search_box = nullptr;
  68. Button *case_sensitive_button = nullptr;
  69. Button *hierarchy_button = nullptr;
  70. Button *search_visual_script_nodes = nullptr;
  71. Button *search_classes = nullptr;
  72. Button *search_operators = nullptr;
  73. Button *search_methods = nullptr;
  74. Button *search_signals = nullptr;
  75. Button *search_constants = nullptr;
  76. Button *search_properties = nullptr;
  77. Button *search_theme_items = nullptr;
  78. OptionButton *scope_combo = nullptr;
  79. Tree *results_tree = nullptr;
  80. class SearchRunner;
  81. Ref<SearchRunner> search_runner;
  82. void _update_icons();
  83. void _sbox_input(const Ref<InputEvent> &p_ie);
  84. void _update_results_i(int p_int);
  85. void _update_results_s(String p_string);
  86. void _update_results_search_all();
  87. void _update_results();
  88. void _confirmed();
  89. void _item_selected();
  90. void _hide_requested();
  91. EditorHelpBit *help_bit = nullptr;
  92. bool properties = false;
  93. bool visual_script_generic = false;
  94. bool connecting = false;
  95. String selected;
  96. Variant::Type type;
  97. String base_type;
  98. String base_script;
  99. ObjectID script;
  100. Object *instance = nullptr;
  101. bool virtuals_only = false;
  102. VBoxContainer *vbox = nullptr;
  103. protected:
  104. void _notification(int p_what);
  105. static void _bind_methods();
  106. public:
  107. 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);
  108. 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);
  109. void select_from_script(const Ref<Script> &p_script, const bool p_connecting = true, bool clear_text = true);
  110. void select_from_basic_type(Variant::Type p_type, const bool p_connecting = true, bool clear_text = true);
  111. void select_from_action(const String &p_type, const bool p_connecting = true, bool clear_text = true);
  112. void select_from_instance(Object *p_instance, const bool p_connecting = true, bool clear_text = true);
  113. void select_from_visual_script(const Ref<Script> &p_script, bool clear_text = true);
  114. void show_window(float p_screen_ratio);
  115. VisualScriptPropertySelector();
  116. };
  117. class VisualScriptPropertySelector::SearchRunner : public RefCounted {
  118. enum Phase {
  119. PHASE_INIT,
  120. PHASE_MATCH_CLASSES_INIT,
  121. PHASE_NODE_CLASSES_INIT,
  122. PHASE_NODE_CLASSES_BUILD,
  123. PHASE_MATCH_CLASSES,
  124. PHASE_CLASS_ITEMS_INIT,
  125. PHASE_CLASS_ITEMS,
  126. PHASE_MEMBER_ITEMS_INIT,
  127. PHASE_MEMBER_ITEMS,
  128. PHASE_SELECT_MATCH,
  129. PHASE_MAX
  130. };
  131. int phase = 0;
  132. struct ClassMatch {
  133. DocData::ClassDoc *doc;
  134. bool name = false;
  135. String category = "";
  136. Vector<DocData::MethodDoc *> constructors;
  137. Vector<DocData::MethodDoc *> methods;
  138. Vector<DocData::MethodDoc *> operators;
  139. Vector<DocData::MethodDoc *> signals;
  140. Vector<DocData::ConstantDoc *> constants;
  141. Vector<DocData::PropertyDoc *> properties;
  142. Vector<DocData::ThemeItemDoc *> theme_properties;
  143. bool required() {
  144. return name || methods.size() || signals.size() || constants.size() || properties.size() || theme_properties.size();
  145. }
  146. };
  147. VisualScriptPropertySelector *selector_ui = nullptr;
  148. Control *ui_service = nullptr;
  149. Tree *results_tree = nullptr;
  150. String term;
  151. int search_flags = 0;
  152. int scope_flags = 0;
  153. Ref<Texture2D> empty_icon;
  154. Color disabled_color;
  155. Map<String, DocData::ClassDoc>::Element *iterator_doc = nullptr;
  156. Map<String, ClassMatch> matches;
  157. Map<String, ClassMatch>::Element *iterator_match = nullptr;
  158. TreeItem *root_item = nullptr;
  159. Map<String, TreeItem *> class_items;
  160. TreeItem *matched_item = nullptr;
  161. float match_highest_score = 0;
  162. Map<String, DocData::ClassDoc> combined_docs;
  163. List<String> vs_nodes;
  164. bool _is_class_disabled_by_feature_profile(const StringName &p_class);
  165. bool _is_class_disabled_by_scope(const StringName &p_class);
  166. bool _slice();
  167. bool _phase_init();
  168. bool _phase_match_classes_init();
  169. bool _phase_node_classes_init();
  170. bool _phase_node_classes_build();
  171. bool _phase_match_classes();
  172. bool _phase_class_items_init();
  173. bool _phase_class_items();
  174. bool _phase_member_items_init();
  175. bool _phase_member_items();
  176. bool _phase_select_match();
  177. bool _match_string(const String &p_term, const String &p_string) const;
  178. bool _match_visual_script(DocData::ClassDoc &class_doc);
  179. bool _match_is_hidden(DocData::ClassDoc &class_doc);
  180. void _match_item(TreeItem *p_item, const String &p_text);
  181. void _add_class_doc(String class_name, String inherits, String category);
  182. DocData::MethodDoc _get_method_doc(MethodInfo method_info);
  183. TreeItem *_create_class_hierarchy(const ClassMatch &p_match);
  184. TreeItem *_create_class_item(TreeItem *p_parent, const DocData::ClassDoc *p_doc, bool p_gray);
  185. TreeItem *_create_method_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const String &p_text, const DocData::MethodDoc *p_doc);
  186. TreeItem *_create_signal_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::MethodDoc *p_doc);
  187. TreeItem *_create_constant_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::ConstantDoc *p_doc);
  188. TreeItem *_create_property_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::PropertyDoc *p_doc);
  189. TreeItem *_create_theme_property_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::ThemeItemDoc *p_doc);
  190. 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);
  191. public:
  192. bool work(uint64_t slot = 100000);
  193. SearchRunner(VisualScriptPropertySelector *p_selector_ui, Tree *p_results_tree);
  194. };
  195. #endif // VISUALSCRIPT_PROPERTYSELECTOR_H