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