node_dock.cpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 "core/io/config_file.h"
  32. #include "editor/connections_dialog.h"
  33. #include "editor/themes/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::_save_layout_to_config(Ref<ConfigFile> p_layout, const String &p_section) const {
  47. p_layout->set_value(p_section, "dock_node_current_tab", int(groups_button->is_pressed()));
  48. }
  49. void NodeDock::_load_layout_from_config(Ref<ConfigFile> p_layout, const String &p_section) {
  50. const int current_tab = p_layout->get_value(p_section, "dock_node_current_tab", 0);
  51. if (select_a_node->is_visible()) {
  52. if (current_tab == 0) {
  53. groups_button->set_pressed_no_signal(false);
  54. connections_button->set_pressed_no_signal(true);
  55. } else if (current_tab == 1) {
  56. groups_button->set_pressed_no_signal(true);
  57. connections_button->set_pressed_no_signal(false);
  58. }
  59. } else if (current_tab == 0) {
  60. show_connections();
  61. } else if (current_tab == 1) {
  62. show_groups();
  63. }
  64. }
  65. void NodeDock::_notification(int p_what) {
  66. switch (p_what) {
  67. case NOTIFICATION_THEME_CHANGED: {
  68. connections_button->set_button_icon(get_editor_theme_icon(SNAME("Signals")));
  69. groups_button->set_button_icon(get_editor_theme_icon(SNAME("Groups")));
  70. } break;
  71. }
  72. }
  73. void NodeDock::_bind_methods() {
  74. ClassDB::bind_method(D_METHOD("_save_layout_to_config"), &NodeDock::_save_layout_to_config);
  75. ClassDB::bind_method(D_METHOD("_load_layout_from_config"), &NodeDock::_load_layout_from_config);
  76. }
  77. void NodeDock::update_lists() {
  78. connections->update_tree();
  79. }
  80. void NodeDock::set_node(Node *p_node) {
  81. connections->set_node(p_node);
  82. groups->set_current(p_node);
  83. if (p_node) {
  84. if (connections_button->is_pressed()) {
  85. connections->show();
  86. } else {
  87. groups->show();
  88. }
  89. mode_hb->show();
  90. select_a_node->hide();
  91. } else {
  92. connections->hide();
  93. groups->hide();
  94. mode_hb->hide();
  95. select_a_node->show();
  96. }
  97. }
  98. NodeDock::NodeDock() {
  99. singleton = this;
  100. set_name("Node");
  101. mode_hb = memnew(HBoxContainer);
  102. add_child(mode_hb);
  103. mode_hb->hide();
  104. connections_button = memnew(Button);
  105. connections_button->set_theme_type_variation(SceneStringName(FlatButton));
  106. connections_button->set_text(TTRC("Signals"));
  107. connections_button->set_toggle_mode(true);
  108. connections_button->set_pressed(true);
  109. connections_button->set_h_size_flags(SIZE_EXPAND_FILL);
  110. connections_button->set_clip_text(true);
  111. mode_hb->add_child(connections_button);
  112. connections_button->connect(SceneStringName(pressed), callable_mp(this, &NodeDock::show_connections));
  113. groups_button = memnew(Button);
  114. groups_button->set_theme_type_variation(SceneStringName(FlatButton));
  115. groups_button->set_text(TTRC("Groups"));
  116. groups_button->set_toggle_mode(true);
  117. groups_button->set_pressed(false);
  118. groups_button->set_h_size_flags(SIZE_EXPAND_FILL);
  119. groups_button->set_clip_text(true);
  120. mode_hb->add_child(groups_button);
  121. groups_button->connect(SceneStringName(pressed), callable_mp(this, &NodeDock::show_groups));
  122. connections = memnew(ConnectionsDock);
  123. add_child(connections);
  124. connections->set_v_size_flags(SIZE_EXPAND_FILL);
  125. connections->hide();
  126. groups = memnew(GroupsEditor);
  127. add_child(groups);
  128. groups->set_v_size_flags(SIZE_EXPAND_FILL);
  129. groups->hide();
  130. select_a_node = memnew(Label);
  131. select_a_node->set_focus_mode(FOCUS_ACCESSIBILITY);
  132. select_a_node->set_text(TTRC("Select a single node to edit its signals and groups."));
  133. select_a_node->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
  134. select_a_node->set_v_size_flags(SIZE_EXPAND_FILL);
  135. select_a_node->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER);
  136. select_a_node->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
  137. select_a_node->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART);
  138. add_child(select_a_node);
  139. }
  140. NodeDock::~NodeDock() {
  141. singleton = nullptr;
  142. }