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