node_dock.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 "editor/connections_dialog.h"
  32. #include "editor/themes/editor_scale.h"
  33. void NodeDock::show_groups() {
  34. groups_button->set_pressed(true);
  35. connections_button->set_pressed(false);
  36. groups->show();
  37. connections->hide();
  38. }
  39. void NodeDock::show_connections() {
  40. groups_button->set_pressed(false);
  41. connections_button->set_pressed(true);
  42. groups->hide();
  43. connections->show();
  44. }
  45. void NodeDock::_notification(int p_what) {
  46. switch (p_what) {
  47. case NOTIFICATION_ENTER_TREE:
  48. case NOTIFICATION_THEME_CHANGED: {
  49. connections_button->set_button_icon(get_editor_theme_icon(SNAME("Signals")));
  50. groups_button->set_button_icon(get_editor_theme_icon(SNAME("Groups")));
  51. } break;
  52. }
  53. }
  54. NodeDock *NodeDock::singleton = nullptr;
  55. void NodeDock::update_lists() {
  56. connections->update_tree();
  57. }
  58. void NodeDock::set_node(Node *p_node) {
  59. connections->set_node(p_node);
  60. groups->set_current(p_node);
  61. if (p_node) {
  62. if (connections_button->is_pressed()) {
  63. connections->show();
  64. } else {
  65. groups->show();
  66. }
  67. mode_hb->show();
  68. select_a_node->hide();
  69. } else {
  70. connections->hide();
  71. groups->hide();
  72. mode_hb->hide();
  73. select_a_node->show();
  74. }
  75. }
  76. NodeDock::NodeDock() {
  77. singleton = this;
  78. set_name("Node");
  79. mode_hb = memnew(HBoxContainer);
  80. add_child(mode_hb);
  81. mode_hb->hide();
  82. connections_button = memnew(Button);
  83. connections_button->set_theme_type_variation(SceneStringName(FlatButton));
  84. connections_button->set_text(TTR("Signals"));
  85. connections_button->set_toggle_mode(true);
  86. connections_button->set_pressed(true);
  87. connections_button->set_h_size_flags(SIZE_EXPAND_FILL);
  88. connections_button->set_clip_text(true);
  89. mode_hb->add_child(connections_button);
  90. connections_button->connect(SceneStringName(pressed), callable_mp(this, &NodeDock::show_connections));
  91. groups_button = memnew(Button);
  92. groups_button->set_theme_type_variation(SceneStringName(FlatButton));
  93. groups_button->set_text(TTR("Groups"));
  94. groups_button->set_toggle_mode(true);
  95. groups_button->set_pressed(false);
  96. groups_button->set_h_size_flags(SIZE_EXPAND_FILL);
  97. groups_button->set_clip_text(true);
  98. mode_hb->add_child(groups_button);
  99. groups_button->connect(SceneStringName(pressed), callable_mp(this, &NodeDock::show_groups));
  100. connections = memnew(ConnectionsDock);
  101. add_child(connections);
  102. connections->set_v_size_flags(SIZE_EXPAND_FILL);
  103. connections->hide();
  104. groups = memnew(GroupsEditor);
  105. add_child(groups);
  106. groups->set_v_size_flags(SIZE_EXPAND_FILL);
  107. groups->hide();
  108. select_a_node = memnew(Label);
  109. select_a_node->set_text(TTR("Select a single node to edit its signals and groups."));
  110. select_a_node->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
  111. select_a_node->set_v_size_flags(SIZE_EXPAND_FILL);
  112. select_a_node->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER);
  113. select_a_node->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
  114. select_a_node->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART);
  115. add_child(select_a_node);
  116. }
  117. NodeDock::~NodeDock() {
  118. singleton = nullptr;
  119. }