/**************************************************************************/ /* node_dock.cpp */ /**************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ /* https://godotengine.org */ /**************************************************************************/ /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ /* "Software"), to deal in the Software without restriction, including */ /* without limitation the rights to use, copy, modify, merge, publish, */ /* distribute, sublicense, and/or sell copies of the Software, and to */ /* permit persons to whom the Software is furnished to do so, subject to */ /* the following conditions: */ /* */ /* The above copyright notice and this permission notice shall be */ /* included in all copies or substantial portions of the Software. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /**************************************************************************/ #include "node_dock.h" #include "core/io/config_file.h" #include "editor/scene/connections_dialog.h" #include "editor/settings/editor_command_palette.h" #include "editor/themes/editor_scale.h" void NodeDock::show_groups() { groups_button->set_pressed(true); connections_button->set_pressed(false); groups->show(); connections->hide(); } void NodeDock::show_connections() { groups_button->set_pressed(false); connections_button->set_pressed(true); groups->hide(); connections->show(); } void NodeDock::save_layout_to_config(Ref &p_layout, const String &p_section) const { p_layout->set_value(p_section, "current_tab", int(groups_button->is_pressed())); } void NodeDock::load_layout_from_config(const Ref &p_layout, const String &p_section) { const int current_tab = p_layout->get_value(p_section, "current_tab", 0); if (current_tab == 0) { show_connections(); } else if (current_tab == 1) { show_groups(); } } void NodeDock::_notification(int p_what) { switch (p_what) { case NOTIFICATION_THEME_CHANGED: { connections_button->set_button_icon(get_editor_theme_icon(SNAME("Signals"))); groups_button->set_button_icon(get_editor_theme_icon(SNAME("Groups"))); } break; } } void NodeDock::update_lists() { connections->update_tree(); } void NodeDock::set_selection(const Vector &p_objects) { connections->set_selection(p_objects); Vector nodes; for (Object *obj : p_objects) { Node *n = Object::cast_to(obj); if (n) { nodes.append(n); } } groups->set_selection(nodes); } NodeDock::NodeDock() { singleton = this; set_name(TTRC("Node")); set_icon_name("Object"); set_dock_shortcut(ED_SHORTCUT_AND_COMMAND("docks/open_node", TTRC("Open Node Dock"))); set_default_slot(EditorDockManager::DOCK_SLOT_RIGHT_UL); VBoxContainer *main_vb = memnew(VBoxContainer); add_child(main_vb); mode_hb = memnew(HBoxContainer); main_vb->add_child(mode_hb); connections_button = memnew(Button); connections_button->set_theme_type_variation(SceneStringName(FlatButton)); connections_button->set_text(TTRC("Signals")); connections_button->set_toggle_mode(true); connections_button->set_h_size_flags(SIZE_EXPAND_FILL); connections_button->set_clip_text(true); mode_hb->add_child(connections_button); connections_button->connect(SceneStringName(pressed), callable_mp(this, &NodeDock::show_connections)); groups_button = memnew(Button); groups_button->set_theme_type_variation(SceneStringName(FlatButton)); groups_button->set_text(TTRC("Groups")); groups_button->set_toggle_mode(true); groups_button->set_h_size_flags(SIZE_EXPAND_FILL); groups_button->set_clip_text(true); mode_hb->add_child(groups_button); groups_button->connect(SceneStringName(pressed), callable_mp(this, &NodeDock::show_groups)); connections = memnew(ConnectionsDock); main_vb->add_child(connections); connections->set_v_size_flags(SIZE_EXPAND_FILL); connections->hide(); groups = memnew(GroupsEditor); main_vb->add_child(groups); groups->set_v_size_flags(SIZE_EXPAND_FILL); groups->hide(); show_connections(); } NodeDock::~NodeDock() { singleton = nullptr; }