node_dock.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /**************************************************************************/
  2. /* node_dock.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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 "connections_dialog.h"
  32. #include "editor/editor_node.h"
  33. #include "editor/editor_scale.h"
  34. void NodeDock::show_groups() {
  35. groups_button->set_pressed(true);
  36. connections_button->set_pressed(false);
  37. groups->show();
  38. connections->hide();
  39. }
  40. void NodeDock::show_connections() {
  41. groups_button->set_pressed(false);
  42. connections_button->set_pressed(true);
  43. groups->hide();
  44. connections->show();
  45. }
  46. void NodeDock::_bind_methods() {
  47. }
  48. void NodeDock::_notification(int p_what) {
  49. switch (p_what) {
  50. case NOTIFICATION_ENTER_TREE:
  51. case NOTIFICATION_THEME_CHANGED: {
  52. connections_button->set_icon(get_theme_icon(SNAME("Signals"), SNAME("EditorIcons")));
  53. groups_button->set_icon(get_theme_icon(SNAME("Groups"), SNAME("EditorIcons")));
  54. } break;
  55. }
  56. }
  57. NodeDock *NodeDock::singleton = nullptr;
  58. void NodeDock::update_lists() {
  59. connections->update_tree();
  60. }
  61. void NodeDock::set_node(Node *p_node) {
  62. connections->set_node(p_node);
  63. groups->set_current(p_node);
  64. if (p_node) {
  65. last_valid_node = p_node;
  66. }
  67. if (p_node) {
  68. if (connections_button->is_pressed()) {
  69. connections->show();
  70. } else {
  71. groups->show();
  72. }
  73. mode_hb->show();
  74. select_a_node->hide();
  75. } else {
  76. connections->hide();
  77. groups->hide();
  78. mode_hb->hide();
  79. select_a_node->show();
  80. }
  81. }
  82. void NodeDock::restore_last_valid_node() {
  83. set_node(last_valid_node);
  84. }
  85. NodeDock::NodeDock() {
  86. singleton = this;
  87. set_name("Node");
  88. mode_hb = memnew(HBoxContainer);
  89. add_child(mode_hb);
  90. mode_hb->hide();
  91. connections_button = memnew(Button);
  92. connections_button->set_flat(true);
  93. connections_button->set_text(TTR("Signals"));
  94. connections_button->set_toggle_mode(true);
  95. connections_button->set_pressed(true);
  96. connections_button->set_h_size_flags(SIZE_EXPAND_FILL);
  97. connections_button->set_clip_text(true);
  98. mode_hb->add_child(connections_button);
  99. connections_button->connect("pressed", callable_mp(this, &NodeDock::show_connections));
  100. groups_button = memnew(Button);
  101. groups_button->set_flat(true);
  102. groups_button->set_text(TTR("Groups"));
  103. groups_button->set_toggle_mode(true);
  104. groups_button->set_pressed(false);
  105. groups_button->set_h_size_flags(SIZE_EXPAND_FILL);
  106. groups_button->set_clip_text(true);
  107. mode_hb->add_child(groups_button);
  108. groups_button->connect("pressed", callable_mp(this, &NodeDock::show_groups));
  109. connections = memnew(ConnectionsDock);
  110. add_child(connections);
  111. connections->set_v_size_flags(SIZE_EXPAND_FILL);
  112. connections->hide();
  113. groups = memnew(GroupsEditor);
  114. add_child(groups);
  115. groups->set_v_size_flags(SIZE_EXPAND_FILL);
  116. groups->hide();
  117. select_a_node = memnew(Label);
  118. select_a_node->set_text(TTR("Select a single node to edit its signals and groups."));
  119. select_a_node->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
  120. select_a_node->set_v_size_flags(SIZE_EXPAND_FILL);
  121. select_a_node->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER);
  122. select_a_node->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
  123. select_a_node->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART);
  124. add_child(select_a_node);
  125. }
  126. NodeDock::~NodeDock() {
  127. singleton = nullptr;
  128. }