connections_dialog.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 <reduzio@gmail.com>
  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. Node *source;
  50. StringName signal;
  51. LineEdit *dst_path;
  52. LineEdit *dst_method;
  53. ConnectDialogBinds *cdbinds;
  54. bool bEditMode;
  55. SceneTreeEditor *tree;
  56. ConfirmationDialog *error;
  57. EditorInspector *bind_editor;
  58. OptionButton *type_list;
  59. CheckButton *deferred;
  60. CheckButton *oneshot;
  61. CheckButton *make_callback;
  62. void ok_pressed();
  63. void _cancel_pressed();
  64. void _tree_node_selected();
  65. void _add_bind();
  66. void _remove_bind();
  67. protected:
  68. void _notification(int p_what);
  69. static void _bind_methods();
  70. public:
  71. Node *get_source() const;
  72. StringName get_signal_name() const;
  73. NodePath get_dst_path() const;
  74. void set_dst_node(Node *p_node);
  75. StringName get_dst_method_name() const;
  76. void set_dst_method(const StringName &p_method);
  77. Vector<Variant> get_binds() const;
  78. bool get_make_callback() { return make_callback->is_visible() && make_callback->is_pressed(); }
  79. bool get_deferred() const;
  80. bool get_oneshot() const;
  81. bool is_editing() const;
  82. void init(Connection c, bool bEdit = false);
  83. ConnectDialog();
  84. ~ConnectDialog();
  85. };
  86. //========================================
  87. class ConnectionsDock : public VBoxContainer {
  88. GDCLASS(ConnectionsDock, VBoxContainer);
  89. //Right-click Pop-up Menu Options.
  90. enum SignalMenuOption {
  91. CONNECT,
  92. DISCONNECT_ALL
  93. };
  94. enum SlotMenuOption {
  95. EDIT,
  96. GO_TO_SCRIPT,
  97. DISCONNECT
  98. };
  99. Node *selectedNode;
  100. Tree *tree;
  101. EditorNode *editor;
  102. ConfirmationDialog *disconnect_all_dialog;
  103. ConnectDialog *connect_dialog;
  104. Button *connect_button;
  105. PopupMenu *signal_menu;
  106. PopupMenu *slot_menu;
  107. UndoRedo *undo_redo;
  108. void _make_or_edit_connection();
  109. void _connect(Connection cToMake);
  110. void _disconnect(TreeItem &item);
  111. void _disconnect_all();
  112. void _tree_item_selected();
  113. void _tree_item_activated();
  114. bool _is_item_signal(TreeItem &item);
  115. void _open_connection_dialog(TreeItem &item);
  116. void _open_connection_dialog(Connection cToEdit);
  117. void _go_to_script(TreeItem &item);
  118. void _handle_signal_menu_option(int option);
  119. void _handle_slot_menu_option(int option);
  120. void _rmb_pressed(Vector2 position);
  121. void _close();
  122. protected:
  123. void _connect_pressed();
  124. void _notification(int p_what);
  125. static void _bind_methods();
  126. public:
  127. void set_undoredo(UndoRedo *p_undo_redo) { undo_redo = p_undo_redo; }
  128. void set_node(Node *p_node);
  129. void update_tree();
  130. ConnectionsDock(EditorNode *p_editor = NULL);
  131. ~ConnectionsDock();
  132. };
  133. #endif