node_dock.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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/scene/connections_dialog.h"
  33. #include "editor/settings/editor_command_palette.h"
  34. #include "editor/themes/editor_scale.h"
  35. void NodeDock::show_groups() {
  36. groups_button->set_pressed(true);
  37. connections_button->set_pressed(false);
  38. groups->show();
  39. connections->hide();
  40. }
  41. void NodeDock::show_connections() {
  42. groups_button->set_pressed(false);
  43. connections_button->set_pressed(true);
  44. groups->hide();
  45. connections->show();
  46. }
  47. void NodeDock::save_layout_to_config(Ref<ConfigFile> &p_layout, const String &p_section) const {
  48. p_layout->set_value(p_section, "current_tab", int(groups_button->is_pressed()));
  49. }
  50. void NodeDock::load_layout_from_config(const Ref<ConfigFile> &p_layout, const String &p_section) {
  51. const int current_tab = p_layout->get_value(p_section, "current_tab", 0);
  52. if (current_tab == 0) {
  53. show_connections();
  54. } else if (current_tab == 1) {
  55. show_groups();
  56. }
  57. }
  58. void NodeDock::_notification(int p_what) {
  59. switch (p_what) {
  60. case NOTIFICATION_THEME_CHANGED: {
  61. connections_button->set_button_icon(get_editor_theme_icon(SNAME("Signals")));
  62. groups_button->set_button_icon(get_editor_theme_icon(SNAME("Groups")));
  63. } break;
  64. }
  65. }
  66. void NodeDock::update_lists() {
  67. connections->update_tree();
  68. }
  69. void NodeDock::set_selection(const Vector<Object *> &p_objects) {
  70. connections->set_selection(p_objects);
  71. Vector<Node *> nodes;
  72. for (Object *obj : p_objects) {
  73. Node *n = Object::cast_to<Node>(obj);
  74. if (n) {
  75. nodes.append(n);
  76. }
  77. }
  78. groups->set_selection(nodes);
  79. }
  80. NodeDock::NodeDock() {
  81. singleton = this;
  82. set_name(TTRC("Node"));
  83. set_icon_name("Object");
  84. set_dock_shortcut(ED_SHORTCUT_AND_COMMAND("docks/open_node", TTRC("Open Node Dock")));
  85. set_default_slot(EditorDockManager::DOCK_SLOT_RIGHT_UL);
  86. VBoxContainer *main_vb = memnew(VBoxContainer);
  87. add_child(main_vb);
  88. mode_hb = memnew(HBoxContainer);
  89. main_vb->add_child(mode_hb);
  90. connections_button = memnew(Button);
  91. connections_button->set_theme_type_variation(SceneStringName(FlatButton));
  92. connections_button->set_text(TTRC("Signals"));
  93. connections_button->set_toggle_mode(true);
  94. connections_button->set_h_size_flags(SIZE_EXPAND_FILL);
  95. connections_button->set_clip_text(true);
  96. mode_hb->add_child(connections_button);
  97. connections_button->connect(SceneStringName(pressed), callable_mp(this, &NodeDock::show_connections));
  98. groups_button = memnew(Button);
  99. groups_button->set_theme_type_variation(SceneStringName(FlatButton));
  100. groups_button->set_text(TTRC("Groups"));
  101. groups_button->set_toggle_mode(true);
  102. groups_button->set_h_size_flags(SIZE_EXPAND_FILL);
  103. groups_button->set_clip_text(true);
  104. mode_hb->add_child(groups_button);
  105. groups_button->connect(SceneStringName(pressed), callable_mp(this, &NodeDock::show_groups));
  106. connections = memnew(ConnectionsDock);
  107. main_vb->add_child(connections);
  108. connections->set_v_size_flags(SIZE_EXPAND_FILL);
  109. connections->hide();
  110. groups = memnew(GroupsEditor);
  111. main_vb->add_child(groups);
  112. groups->set_v_size_flags(SIZE_EXPAND_FILL);
  113. groups->hide();
  114. show_connections();
  115. }
  116. NodeDock::~NodeDock() {
  117. singleton = nullptr;
  118. }