connections_dialog.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*************************************************************************/
  2. /* connections_dialog.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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/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. Label *connect_to_label;
  50. LineEdit *from_signal;
  51. Node *source;
  52. StringName signal;
  53. LineEdit *dst_method;
  54. ConnectDialogBinds *cdbinds;
  55. bool bEditMode;
  56. NodePath dst_path;
  57. VBoxContainer *vbc_right;
  58. SceneTreeEditor *tree;
  59. AcceptDialog *error;
  60. EditorInspector *bind_editor;
  61. OptionButton *type_list;
  62. CheckButton *deferred;
  63. CheckButton *oneshot;
  64. CheckBox *advanced;
  65. Label *error_label;
  66. void ok_pressed();
  67. void _cancel_pressed();
  68. void _tree_node_selected();
  69. void _add_bind();
  70. void _remove_bind();
  71. void _advanced_pressed();
  72. protected:
  73. void _notification(int p_what);
  74. static void _bind_methods();
  75. public:
  76. Node *get_source() const;
  77. StringName get_signal_name() const;
  78. NodePath get_dst_path() const;
  79. void set_dst_node(Node *p_node);
  80. StringName get_dst_method_name() const;
  81. void set_dst_method(const StringName &p_method);
  82. Vector<Variant> get_binds() const;
  83. bool get_deferred() const;
  84. bool get_oneshot() const;
  85. bool is_editing() const;
  86. void init(Connection c, bool bEdit = false);
  87. void popup_dialog(const String &p_for_signal, bool p_advanced);
  88. ConnectDialog();
  89. ~ConnectDialog();
  90. };
  91. //========================================
  92. class ConnectionsDock : public VBoxContainer {
  93. GDCLASS(ConnectionsDock, VBoxContainer);
  94. //Right-click Pop-up Menu Options.
  95. enum SignalMenuOption {
  96. CONNECT,
  97. DISCONNECT_ALL
  98. };
  99. enum SlotMenuOption {
  100. EDIT,
  101. GO_TO_SCRIPT,
  102. DISCONNECT
  103. };
  104. Node *selectedNode;
  105. Tree *tree;
  106. EditorNode *editor;
  107. ConfirmationDialog *disconnect_all_dialog;
  108. ConnectDialog *connect_dialog;
  109. Button *connect_button;
  110. PopupMenu *signal_menu;
  111. PopupMenu *slot_menu;
  112. UndoRedo *undo_redo;
  113. void _make_or_edit_connection();
  114. void _connect(Connection cToMake);
  115. void _disconnect(TreeItem &item);
  116. void _disconnect_all();
  117. void _tree_item_selected();
  118. void _tree_item_activated();
  119. bool _is_item_signal(TreeItem &item);
  120. void _open_connection_dialog(TreeItem &item);
  121. void _open_connection_dialog(Connection cToEdit);
  122. void _go_to_script(TreeItem &item);
  123. void _handle_signal_menu_option(int option);
  124. void _handle_slot_menu_option(int option);
  125. void _rmb_pressed(Vector2 position);
  126. void _close();
  127. protected:
  128. void _connect_pressed();
  129. void _notification(int p_what);
  130. static void _bind_methods();
  131. public:
  132. void set_undoredo(UndoRedo *p_undo_redo) { undo_redo = p_undo_redo; }
  133. void set_node(Node *p_node);
  134. void update_tree();
  135. ConnectionsDock(EditorNode *p_editor = NULL);
  136. ~ConnectionsDock();
  137. };
  138. #endif