connections_dialog.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /*************************************************************************/
  2. /* connections_dialog.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 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. /**
  31. @author Juan Linietsky <[email protected]>
  32. */
  33. #ifndef CONNECTIONS_DIALOG_H
  34. #define CONNECTIONS_DIALOG_H
  35. #include "core/object/undo_redo.h"
  36. #include "editor/editor_inspector.h"
  37. #include "editor/scene_tree_editor.h"
  38. #include "scene/gui/button.h"
  39. #include "scene/gui/check_button.h"
  40. #include "scene/gui/dialogs.h"
  41. #include "scene/gui/line_edit.h"
  42. #include "scene/gui/menu_button.h"
  43. #include "scene/gui/popup.h"
  44. #include "scene/gui/tree.h"
  45. class PopupMenu;
  46. class ConnectDialogBinds;
  47. class ConnectDialog : public ConfirmationDialog {
  48. GDCLASS(ConnectDialog, ConfirmationDialog);
  49. public:
  50. struct ConnectionData {
  51. Node *source = nullptr;
  52. Node *target = nullptr;
  53. StringName signal;
  54. StringName method;
  55. uint32_t flags = 0;
  56. Vector<Variant> binds;
  57. ConnectionData() {
  58. }
  59. ConnectionData(const Connection &p_connection) {
  60. source = Object::cast_to<Node>(p_connection.signal.get_object());
  61. signal = p_connection.signal.get_name();
  62. target = Object::cast_to<Node>(p_connection.callable.get_object());
  63. method = p_connection.callable.get_method();
  64. flags = p_connection.flags;
  65. binds = p_connection.binds;
  66. }
  67. operator Connection() {
  68. Connection c;
  69. c.signal = ::Signal(source, signal);
  70. c.callable = Callable(target, method);
  71. c.flags = flags;
  72. c.binds = binds;
  73. return c;
  74. }
  75. };
  76. private:
  77. Label *connect_to_label;
  78. LineEdit *from_signal;
  79. Node *source;
  80. StringName signal;
  81. LineEdit *dst_method;
  82. ConnectDialogBinds *cdbinds;
  83. bool bEditMode;
  84. NodePath dst_path;
  85. VBoxContainer *vbc_right;
  86. SceneTreeEditor *tree;
  87. AcceptDialog *error;
  88. EditorInspector *bind_editor;
  89. OptionButton *type_list;
  90. CheckBox *deferred;
  91. CheckBox *oneshot;
  92. CheckButton *advanced;
  93. Label *error_label;
  94. void ok_pressed() override;
  95. void _cancel_pressed();
  96. void _item_activated();
  97. void _text_submitted(const String &_text);
  98. void _tree_node_selected();
  99. void _add_bind();
  100. void _remove_bind();
  101. void _advanced_pressed();
  102. void _update_ok_enabled();
  103. protected:
  104. void _notification(int p_what);
  105. static void _bind_methods();
  106. public:
  107. Node *get_source() const;
  108. StringName get_signal_name() const;
  109. NodePath get_dst_path() const;
  110. void set_dst_node(Node *p_node);
  111. StringName get_dst_method_name() const;
  112. void set_dst_method(const StringName &p_method);
  113. Vector<Variant> get_binds() const;
  114. bool get_deferred() const;
  115. bool get_oneshot() const;
  116. bool is_editing() const;
  117. void init(ConnectionData c, bool bEdit = false);
  118. void popup_dialog(const String &p_for_signal);
  119. ConnectDialog();
  120. ~ConnectDialog();
  121. };
  122. //////////////////////////////////////////
  123. // Custom Tree needed to use a RichTextLabel as tooltip control
  124. // when display signal documentation.
  125. class ConnectionsDockTree : public Tree {
  126. virtual Control *make_custom_tooltip(const String &p_text) const;
  127. };
  128. class ConnectionsDock : public VBoxContainer {
  129. GDCLASS(ConnectionsDock, VBoxContainer);
  130. //Right-click Pop-up Menu Options.
  131. enum SignalMenuOption {
  132. CONNECT,
  133. DISCONNECT_ALL
  134. };
  135. enum SlotMenuOption {
  136. EDIT,
  137. GO_TO_SCRIPT,
  138. DISCONNECT
  139. };
  140. Node *selectedNode;
  141. ConnectionsDockTree *tree;
  142. EditorNode *editor;
  143. ConfirmationDialog *disconnect_all_dialog;
  144. ConnectDialog *connect_dialog;
  145. Button *connect_button;
  146. PopupMenu *signal_menu;
  147. PopupMenu *slot_menu;
  148. UndoRedo *undo_redo;
  149. LineEdit *search_box;
  150. Map<StringName, Map<StringName, String>> descr_cache;
  151. void _filter_changed(const String &p_text);
  152. void _make_or_edit_connection();
  153. void _connect(ConnectDialog::ConnectionData cToMake);
  154. void _disconnect(TreeItem &item);
  155. void _disconnect_all();
  156. void _tree_item_selected();
  157. void _tree_item_activated();
  158. bool _is_item_signal(TreeItem &item);
  159. void _open_connection_dialog(TreeItem &item);
  160. void _open_connection_dialog(ConnectDialog::ConnectionData cToEdit);
  161. void _go_to_script(TreeItem &item);
  162. void _handle_signal_menu_option(int option);
  163. void _handle_slot_menu_option(int option);
  164. void _rmb_pressed(Vector2 position);
  165. void _close();
  166. protected:
  167. void _connect_pressed();
  168. void _notification(int p_what);
  169. static void _bind_methods();
  170. public:
  171. void set_undoredo(UndoRedo *p_undo_redo) { undo_redo = p_undo_redo; }
  172. void set_node(Node *p_node);
  173. void update_tree();
  174. ConnectionsDock(EditorNode *p_editor = nullptr);
  175. ~ConnectionsDock();
  176. };
  177. #endif