node_dock.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*************************************************************************/
  2. /* node_dock.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 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. #include "node_dock.h"
  31. #include "editor_node.h"
  32. void NodeDock::show_groups() {
  33. groups_button->set_pressed(true);
  34. connections_button->set_pressed(false);
  35. groups->show();
  36. connections->hide();
  37. }
  38. void NodeDock::show_connections() {
  39. groups_button->set_pressed(false);
  40. connections_button->set_pressed(true);
  41. groups->hide();
  42. connections->show();
  43. }
  44. void NodeDock::_bind_methods() {
  45. ObjectTypeDB::bind_method(_MD("show_groups"), &NodeDock::show_groups);
  46. ObjectTypeDB::bind_method(_MD("show_connections"), &NodeDock::show_connections);
  47. }
  48. void NodeDock::_notification(int p_what) {
  49. if (p_what == NOTIFICATION_ENTER_TREE) {
  50. connections_button->set_icon(get_icon("Connect", "EditorIcons"));
  51. groups_button->set_icon(get_icon("Groups", "EditorIcons"));
  52. }
  53. }
  54. NodeDock *NodeDock::singleton = NULL;
  55. void NodeDock::set_node(Node *p_node) {
  56. connections->set_node(p_node);
  57. groups->set_current(p_node);
  58. if (p_node) {
  59. if (connections_button->is_pressed())
  60. connections->show();
  61. else
  62. groups->show();
  63. mode_hb->show();
  64. select_a_node->hide();
  65. } else {
  66. connections->hide();
  67. groups->hide();
  68. mode_hb->hide();
  69. select_a_node->show();
  70. }
  71. }
  72. NodeDock::NodeDock() {
  73. singleton = this;
  74. set_name(TTR("Node"));
  75. mode_hb = memnew(HBoxContainer);
  76. add_child(mode_hb);
  77. mode_hb->hide();
  78. connections_button = memnew(ToolButton);
  79. connections_button->set_text(TTR("Signals"));
  80. connections_button->set_toggle_mode(true);
  81. connections_button->set_pressed(true);
  82. connections_button->set_h_size_flags(SIZE_EXPAND_FILL);
  83. mode_hb->add_child(connections_button);
  84. connections_button->connect("pressed", this, "show_connections");
  85. groups_button = memnew(ToolButton);
  86. groups_button->set_text(TTR("Groups"));
  87. groups_button->set_toggle_mode(true);
  88. groups_button->set_pressed(false);
  89. groups_button->set_h_size_flags(SIZE_EXPAND_FILL);
  90. mode_hb->add_child(groups_button);
  91. groups_button->connect("pressed", this, "show_groups");
  92. connections = memnew(ConnectionsDock(EditorNode::get_singleton()));
  93. connections->set_undoredo(EditorNode::get_singleton()->get_undo_redo());
  94. add_child(connections);
  95. connections->set_v_size_flags(SIZE_EXPAND_FILL);
  96. connections->hide();
  97. groups = memnew(GroupsEditor);
  98. groups->set_undo_redo(EditorNode::get_singleton()->get_undo_redo());
  99. add_child(groups);
  100. groups->set_v_size_flags(SIZE_EXPAND_FILL);
  101. groups->hide();
  102. select_a_node = memnew(Label);
  103. select_a_node->set_text(TTR("Select a Node to edit Signals and Groups."));
  104. select_a_node->set_v_size_flags(SIZE_EXPAND_FILL);
  105. select_a_node->set_valign(Label::VALIGN_CENTER);
  106. select_a_node->set_align(Label::ALIGN_CENTER);
  107. select_a_node->set_autowrap(true);
  108. add_child(select_a_node);
  109. }