summaryrefslogtreecommitdiff
path: root/editor/connections_dialog.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/connections_dialog.cpp')
-rw-r--r--editor/connections_dialog.cpp428
1 files changed, 220 insertions, 208 deletions
diff --git a/editor/connections_dialog.cpp b/editor/connections_dialog.cpp
index 1853133bc7..d1661fd7b3 100644
--- a/editor/connections_dialog.cpp
+++ b/editor/connections_dialog.cpp
@@ -40,67 +40,63 @@
static Node *_find_first_script(Node *p_root, Node *p_node) {
if (p_node != p_root && p_node->get_owner() != p_root) {
- return NULL;
+ return nullptr;
}
if (!p_node->get_script().is_null()) {
return p_node;
}
for (int i = 0; i < p_node->get_child_count(); i++) {
-
Node *ret = _find_first_script(p_root, p_node->get_child(i));
if (ret) {
return ret;
}
}
- return NULL;
+ return nullptr;
}
class ConnectDialogBinds : public Object {
-
GDCLASS(ConnectDialogBinds, Object);
public:
Vector<Variant> params;
bool _set(const StringName &p_name, const Variant &p_value) {
-
String name = p_name;
if (name.begins_with("bind/")) {
int which = name.get_slice("/", 1).to_int() - 1;
ERR_FAIL_INDEX_V(which, params.size(), false);
params.write[which] = p_value;
- } else
+ } else {
return false;
+ }
return true;
}
bool _get(const StringName &p_name, Variant &r_ret) const {
-
String name = p_name;
if (name.begins_with("bind/")) {
int which = name.get_slice("/", 1).to_int() - 1;
ERR_FAIL_INDEX_V(which, params.size(), false);
r_ret = params[which];
- } else
+ } else {
return false;
+ }
return true;
}
void _get_property_list(List<PropertyInfo> *p_list) const {
-
for (int i = 0; i < params.size(); i++) {
p_list->push_back(PropertyInfo(params[i].get_type(), "bind/" + itos(i + 1)));
}
}
void notify_changed() {
-
_change_notify();
}
@@ -112,17 +108,28 @@ public:
* Signal automatically called by parent dialog.
*/
void ConnectDialog::ok_pressed() {
+ String method_name = dst_method->get_text();
- if (dst_method->get_text() == "") {
+ if (method_name == "") {
error->set_text(TTR("Method in target node must be specified."));
- error->popup_centered_minsize();
+ error->popup_centered();
return;
}
+
+ if (!method_name.strip_edges().is_valid_identifier()) {
+ error->set_text(TTR("Method name must be a valid identifier."));
+ error->popup_centered();
+ return;
+ }
+
Node *target = tree->get_selected();
+ if (!target) {
+ return; // Nothing selected in the tree, not an error.
+ }
if (target->get_script().is_null()) {
- if (!target->has_method(dst_method->get_text())) {
+ if (!target->has_method(method_name)) {
error->set_text(TTR("Target method not found. Specify a valid method or attach a script to the target node."));
- error->popup_centered_minsize();
+ error->popup_centered();
return;
}
}
@@ -131,59 +138,85 @@ void ConnectDialog::ok_pressed() {
}
void ConnectDialog::_cancel_pressed() {
-
hide();
}
+void ConnectDialog::_item_activated() {
+ _ok_pressed(); // From AcceptDialog.
+}
+
+void ConnectDialog::_text_entered(const String &p_text) {
+ _ok_pressed(); // From AcceptDialog.
+}
+
/*
* Called each time a target node is selected within the target node tree.
*/
void ConnectDialog::_tree_node_selected() {
-
Node *current = tree->get_selected();
- if (!current)
+ if (!current) {
return;
+ }
dst_path = source->get_path_to(current);
_update_ok_enabled();
}
/*
- * Called each time a target node is activated within the target node tree.
- */
-void ConnectDialog::_tree_item_activated() {
-
- if (!get_ok()->is_disabled()) {
- get_ok()->emit_signal("pressed");
- }
-}
-
-/*
* Adds a new parameter bind to connection.
*/
void ConnectDialog::_add_bind() {
-
- if (cdbinds->params.size() >= VARIANT_ARG_MAX)
+ if (cdbinds->params.size() >= VARIANT_ARG_MAX) {
return;
+ }
Variant::Type vt = (Variant::Type)type_list->get_item_id(type_list->get_selected());
Variant value;
switch (vt) {
- case Variant::BOOL: value = false; break;
- case Variant::INT: value = 0; break;
- case Variant::REAL: value = 0.0; break;
- case Variant::STRING: value = ""; break;
- case Variant::VECTOR2: value = Vector2(); break;
- case Variant::RECT2: value = Rect2(); break;
- case Variant::VECTOR3: value = Vector3(); break;
- case Variant::PLANE: value = Plane(); break;
- case Variant::QUAT: value = Quat(); break;
- case Variant::AABB: value = AABB(); break;
- case Variant::BASIS: value = Basis(); break;
- case Variant::TRANSFORM: value = Transform(); break;
- case Variant::COLOR: value = Color(); break;
+ case Variant::BOOL:
+ value = false;
+ break;
+ case Variant::INT:
+ value = 0;
+ break;
+ case Variant::FLOAT:
+ value = 0.0;
+ break;
+ case Variant::STRING:
+ value = "";
+ break;
+ case Variant::STRING_NAME:
+ value = "";
+ break;
+ case Variant::VECTOR2:
+ value = Vector2();
+ break;
+ case Variant::RECT2:
+ value = Rect2();
+ break;
+ case Variant::VECTOR3:
+ value = Vector3();
+ break;
+ case Variant::PLANE:
+ value = Plane();
+ break;
+ case Variant::QUAT:
+ value = Quat();
+ break;
+ case Variant::AABB:
+ value = AABB();
+ break;
+ case Variant::BASIS:
+ value = Basis();
+ break;
+ case Variant::TRANSFORM:
+ value = Transform();
+ break;
+ case Variant::COLOR:
+ value = Color();
+ break;
default: {
ERR_FAIL();
} break;
@@ -199,10 +232,10 @@ void ConnectDialog::_add_bind() {
* Remove parameter bind from connection.
*/
void ConnectDialog::_remove_bind() {
-
String st = bind_editor->get_selected_path();
- if (st == "")
+ if (st == "") {
return;
+ }
int idx = st.get_slice("/", 1).to_int() - 1;
ERR_FAIL_INDEX(idx, cdbinds->params.size());
@@ -215,7 +248,6 @@ void ConnectDialog::_remove_bind() {
* node is selected and valid in the selected mode.
*/
void ConnectDialog::_update_ok_enabled() {
-
Node *target = tree->get_selected();
if (target == nullptr) {
@@ -232,70 +264,55 @@ void ConnectDialog::_update_ok_enabled() {
}
void ConnectDialog::_notification(int p_what) {
-
if (p_what == NOTIFICATION_ENTER_TREE) {
bind_editor->edit(cdbinds);
}
}
void ConnectDialog::_bind_methods() {
-
- ClassDB::bind_method("_advanced_pressed", &ConnectDialog::_advanced_pressed);
ClassDB::bind_method("_cancel", &ConnectDialog::_cancel_pressed);
- ClassDB::bind_method("_tree_node_selected", &ConnectDialog::_tree_node_selected);
- ClassDB::bind_method("_tree_item_activated", &ConnectDialog::_tree_item_activated);
- ClassDB::bind_method("_add_bind", &ConnectDialog::_add_bind);
- ClassDB::bind_method("_remove_bind", &ConnectDialog::_remove_bind);
ClassDB::bind_method("_update_ok_enabled", &ConnectDialog::_update_ok_enabled);
ADD_SIGNAL(MethodInfo("connected"));
}
Node *ConnectDialog::get_source() const {
-
return source;
}
StringName ConnectDialog::get_signal_name() const {
-
return signal;
}
NodePath ConnectDialog::get_dst_path() const {
-
return dst_path;
}
void ConnectDialog::set_dst_node(Node *p_node) {
-
tree->set_selected(p_node);
}
StringName ConnectDialog::get_dst_method_name() const {
-
String txt = dst_method->get_text();
- if (txt.find("(") != -1)
+ if (txt.find("(") != -1) {
txt = txt.left(txt.find("(")).strip_edges();
+ }
return txt;
}
void ConnectDialog::set_dst_method(const StringName &p_method) {
-
dst_method->set_text(p_method);
}
Vector<Variant> ConnectDialog::get_binds() const {
-
return cdbinds->params;
}
bool ConnectDialog::get_deferred() const {
-
return deferred->is_pressed();
}
bool ConnectDialog::get_oneshot() const {
-
return oneshot->is_pressed();
}
@@ -303,7 +320,6 @@ bool ConnectDialog::get_oneshot() const {
* Returns true if ConnectDialog is being used to edit an existing connection.
*/
bool ConnectDialog::is_editing() const {
-
return bEditMode;
}
@@ -312,14 +328,13 @@ bool ConnectDialog::is_editing() const {
* If creating a connection from scratch, sensible defaults are used.
* If editing an existing connection, previous data is retained.
*/
-void ConnectDialog::init(Connection c, bool bEdit) {
-
+void ConnectDialog::init(ConnectionData c, bool bEdit) {
set_hide_on_ok(false);
source = static_cast<Node *>(c.source);
signal = c.signal;
- tree->set_selected(NULL);
+ tree->set_selected(nullptr);
tree->set_marked(source, true);
if (c.target) {
@@ -343,26 +358,25 @@ void ConnectDialog::init(Connection c, bool bEdit) {
}
void ConnectDialog::popup_dialog(const String &p_for_signal) {
-
from_signal->set_text(p_for_signal);
- error_label->add_color_override("font_color", get_color("error_color", "Editor"));
- if (!advanced->is_pressed())
+ error_label->add_theme_color_override("font_color", error_label->get_theme_color("error_color", "Editor"));
+ if (!advanced->is_pressed()) {
error_label->set_visible(!_find_first_script(get_tree()->get_edited_scene_root(), get_tree()->get_edited_scene_root()));
+ }
popup_centered();
}
void ConnectDialog::_advanced_pressed() {
-
if (advanced->is_pressed()) {
- set_custom_minimum_size(Size2(900, 500) * EDSCALE);
+ set_min_size(Size2(900, 500) * EDSCALE);
connect_to_label->set_text(TTR("Connect to Node:"));
tree->set_connect_to_script_mode(false);
vbc_right->show();
error_label->hide();
} else {
- set_custom_minimum_size(Size2(600, 500) * EDSCALE);
+ set_min_size(Size2(600, 500) * EDSCALE);
set_size(Size2());
connect_to_label->set_text(TTR("Connect to Script:"));
tree->set_connect_to_script_mode(true);
@@ -373,23 +387,22 @@ void ConnectDialog::_advanced_pressed() {
_update_ok_enabled();
- set_position((get_viewport_rect().size - get_custom_minimum_size()) / 2);
+ popup_centered();
}
ConnectDialog::ConnectDialog() {
-
- set_custom_minimum_size(Size2(600, 500) * EDSCALE);
+ set_min_size(Size2(600, 500) * EDSCALE);
VBoxContainer *vbc = memnew(VBoxContainer);
add_child(vbc);
HBoxContainer *main_hb = memnew(HBoxContainer);
vbc->add_child(main_hb);
- main_hb->set_v_size_flags(SIZE_EXPAND_FILL);
+ main_hb->set_v_size_flags(Control::SIZE_EXPAND_FILL);
VBoxContainer *vbc_left = memnew(VBoxContainer);
main_hb->add_child(vbc_left);
- vbc_left->set_h_size_flags(SIZE_EXPAND_FILL);
+ vbc_left->set_h_size_flags(Control::SIZE_EXPAND_FILL);
from_signal = memnew(LineEdit);
from_signal->set_editable(false);
@@ -397,8 +410,8 @@ ConnectDialog::ConnectDialog() {
tree = memnew(SceneTreeEditor(false));
tree->set_connecting_signal(true);
- tree->get_scene_tree()->connect("item_activated", this, "_tree_item_activated");
- tree->connect("node_selected", this, "_tree_node_selected");
+ tree->get_scene_tree()->connect("item_activated", callable_mp(this, &ConnectDialog::_item_activated));
+ tree->connect("node_selected", callable_mp(this, &ConnectDialog::_tree_node_selected));
tree->set_connect_to_script_mode(true);
Node *mc = vbc_left->add_margin_child(TTR("Connect to Script:"), tree, true);
@@ -411,18 +424,19 @@ ConnectDialog::ConnectDialog() {
vbc_right = memnew(VBoxContainer);
main_hb->add_child(vbc_right);
- vbc_right->set_h_size_flags(SIZE_EXPAND_FILL);
+ vbc_right->set_h_size_flags(Control::SIZE_EXPAND_FILL);
vbc_right->hide();
HBoxContainer *add_bind_hb = memnew(HBoxContainer);
type_list = memnew(OptionButton);
- type_list->set_h_size_flags(SIZE_EXPAND_FILL);
+ type_list->set_h_size_flags(Control::SIZE_EXPAND_FILL);
add_bind_hb->add_child(type_list);
type_list->add_item("bool", Variant::BOOL);
type_list->add_item("int", Variant::INT);
- type_list->add_item("real", Variant::REAL);
+ type_list->add_item("real", Variant::FLOAT);
type_list->add_item("String", Variant::STRING);
+ type_list->add_item("StringName", Variant::STRING_NAME);
type_list->add_item("Vector2", Variant::VECTOR2);
type_list->add_item("Rect2", Variant::RECT2);
type_list->add_item("Vector3", Variant::VECTOR3);
@@ -437,12 +451,12 @@ ConnectDialog::ConnectDialog() {
Button *add_bind = memnew(Button);
add_bind->set_text(TTR("Add"));
add_bind_hb->add_child(add_bind);
- add_bind->connect("pressed", this, "_add_bind");
+ add_bind->connect("pressed", callable_mp(this, &ConnectDialog::_add_bind));
Button *del_bind = memnew(Button);
del_bind->set_text(TTR("Remove"));
add_bind_hb->add_child(del_bind);
- del_bind->connect("pressed", this, "_remove_bind");
+ del_bind->connect("pressed", callable_mp(this, &ConnectDialog::_remove_bind));
vbc_right->add_margin_child(TTR("Add Extra Call Argument:"), add_bind_hb);
@@ -454,19 +468,14 @@ ConnectDialog::ConnectDialog() {
vbc_left->add_margin_child(TTR("Receiver Method:"), dstm_hb);
dst_method = memnew(LineEdit);
- dst_method->set_h_size_flags(SIZE_EXPAND_FILL);
- dst_method->connect("text_entered", this, "_builtin_text_entered");
+ dst_method->set_h_size_flags(Control::SIZE_EXPAND_FILL);
+ dst_method->connect("text_entered", callable_mp(this, &ConnectDialog::_text_entered));
dstm_hb->add_child(dst_method);
advanced = memnew(CheckButton);
dstm_hb->add_child(advanced);
advanced->set_text(TTR("Advanced"));
- advanced->connect("pressed", this, "_advanced_pressed");
-
- // Add spacing so the tree and inspector are the same size.
- Control *spacing = memnew(Control);
- spacing->set_custom_minimum_size(Size2(0, 4) * EDSCALE);
- vbc_right->add_child(spacing);
+ advanced->connect("pressed", callable_mp(this, &ConnectDialog::_advanced_pressed));
deferred = memnew(CheckBox);
deferred->set_h_size_flags(0);
@@ -480,8 +489,6 @@ ConnectDialog::ConnectDialog() {
oneshot->set_tooltip(TTR("Disconnects the signal after its first emission."));
vbc_right->add_child(oneshot);
- set_as_toplevel(true);
-
cdbinds = memnew(ConnectDialogBinds);
error = memnew(AcceptDialog);
@@ -492,7 +499,6 @@ ConnectDialog::ConnectDialog() {
}
ConnectDialog::~ConnectDialog() {
-
memdelete(cdbinds);
}
@@ -500,32 +506,32 @@ ConnectDialog::~ConnectDialog() {
// Originally copied and adapted from EditorProperty, try to keep style in sync.
Control *ConnectionsDockTree::make_custom_tooltip(const String &p_text) const {
-
EditorHelpBit *help_bit = memnew(EditorHelpBit);
- help_bit->add_style_override("panel", get_stylebox("panel", "TooltipPanel"));
+ help_bit->add_theme_style_override("panel", get_theme_stylebox("panel", "TooltipPanel"));
help_bit->get_rich_text()->set_fixed_size_to_width(360 * EDSCALE);
String text = TTR("Signal:") + " [u][b]" + p_text.get_slice("::", 0) + "[/b][/u]";
text += p_text.get_slice("::", 1).strip_edges() + "\n";
text += p_text.get_slice("::", 2).strip_edges();
- help_bit->set_text(text);
help_bit->call_deferred("set_text", text); //hack so it uses proper theme once inside scene
return help_bit;
}
struct _ConnectionsDockMethodInfoSort {
-
_FORCE_INLINE_ bool operator()(const MethodInfo &a, const MethodInfo &b) const {
return a.name < b.name;
}
};
+void ConnectionsDock::_filter_changed(const String &p_text) {
+ update_tree();
+}
+
/*
* Post-ConnectDialog callback for creating/editing connections.
* Creates or edits connections based on state of the ConnectDialog when "Connect" is pressed.
*/
void ConnectionsDock::_make_or_edit_connection() {
-
TreeItem *it = tree->get_selected();
ERR_FAIL_COND(!it);
@@ -533,7 +539,7 @@ void ConnectionsDock::_make_or_edit_connection() {
Node *target = selectedNode->get_node(dst_path);
ERR_FAIL_COND(!target);
- Connection cToMake;
+ ConnectDialog::ConnectionData cToMake;
cToMake.source = connect_dialog->get_source();
cToMake.target = target;
cToMake.signal = connect_dialog->get_signal_name();
@@ -563,12 +569,12 @@ void ConnectionsDock::_make_or_edit_connection() {
add_script_function = !found_inherited_function;
}
- PoolStringArray script_function_args;
+ PackedStringArray script_function_args;
if (add_script_function) {
// Pick up args here before "it" is deleted by update_tree.
script_function_args = it->get_metadata(0).operator Dictionary()["args"];
for (int i = 0; i < cToMake.binds.size(); i++) {
- script_function_args.append("extra_arg_" + itos(i) + ":" + Variant::get_type_name(cToMake.binds[i].get_type()));
+ script_function_args.push_back("extra_arg_" + itos(i) + ":" + Variant::get_type_name(cToMake.binds[i].get_type()));
}
}
@@ -580,7 +586,7 @@ void ConnectionsDock::_make_or_edit_connection() {
}
// IMPORTANT NOTE: _disconnect and _connect cause an update_tree, which will delete the object "it" is pointing to.
- it = NULL;
+ it = nullptr;
if (add_script_function) {
editor->emit_signal("script_add_function_request", target, cToMake.method, script_function_args);
@@ -593,18 +599,20 @@ void ConnectionsDock::_make_or_edit_connection() {
/*
* Creates single connection w/ undo-redo functionality.
*/
-void ConnectionsDock::_connect(Connection cToMake) {
-
+void ConnectionsDock::_connect(ConnectDialog::ConnectionData cToMake) {
Node *source = static_cast<Node *>(cToMake.source);
Node *target = static_cast<Node *>(cToMake.target);
- if (!source || !target)
+ if (!source || !target) {
return;
+ }
undo_redo->create_action(vformat(TTR("Connect '%s' to '%s'"), String(cToMake.signal), String(cToMake.method)));
- undo_redo->add_do_method(source, "connect", cToMake.signal, target, cToMake.method, cToMake.binds, cToMake.flags);
- undo_redo->add_undo_method(source, "disconnect", cToMake.signal, target, cToMake.method);
+ Callable c(target, cToMake.method);
+
+ undo_redo->add_do_method(source, "connect", cToMake.signal, c, cToMake.binds, cToMake.flags);
+ undo_redo->add_undo_method(source, "disconnect", cToMake.signal, c);
undo_redo->add_do_method(this, "update_tree");
undo_redo->add_undo_method(this, "update_tree");
undo_redo->add_do_method(EditorNode::get_singleton()->get_scene_tree_dock()->get_tree_editor(), "update_tree"); //to force redraw of scene tree
@@ -617,14 +625,15 @@ void ConnectionsDock::_connect(Connection cToMake) {
* Break single connection w/ undo-redo functionality.
*/
void ConnectionsDock::_disconnect(TreeItem &item) {
+ Connection cd = item.get_metadata(0);
+ ConnectDialog::ConnectionData c = cd;
- Connection c = item.get_metadata(0);
ERR_FAIL_COND(c.source != selectedNode); // Shouldn't happen but... Bugcheck.
undo_redo->create_action(vformat(TTR("Disconnect '%s' from '%s'"), c.signal, c.method));
- undo_redo->add_do_method(selectedNode, "disconnect", c.signal, c.target, c.method);
- undo_redo->add_undo_method(selectedNode, "connect", c.signal, c.target, c.method, c.binds, c.flags);
+ undo_redo->add_do_method(selectedNode, "disconnect", c.signal, Callable(c.target, c.method));
+ undo_redo->add_undo_method(selectedNode, "connect", c.signal, Callable(c.target, c.method), c.binds, c.flags);
undo_redo->add_do_method(this, "update_tree");
undo_redo->add_undo_method(this, "update_tree");
undo_redo->add_do_method(EditorNode::get_singleton()->get_scene_tree_dock()->get_tree_editor(), "update_tree"); // To force redraw of scene tree.
@@ -638,20 +647,21 @@ void ConnectionsDock::_disconnect(TreeItem &item) {
* Can undo-redo as a single action.
*/
void ConnectionsDock::_disconnect_all() {
-
TreeItem *item = tree->get_selected();
- if (!_is_item_signal(*item))
+ if (!_is_item_signal(*item)) {
return;
+ }
TreeItem *child = item->get_children();
String signalName = item->get_metadata(0).operator Dictionary()["name"];
undo_redo->create_action(vformat(TTR("Disconnect all from signal: '%s'"), signalName));
while (child) {
- Connection c = child->get_metadata(0);
- undo_redo->add_do_method(selectedNode, "disconnect", c.signal, c.target, c.method);
- undo_redo->add_undo_method(selectedNode, "connect", c.signal, c.target, c.method, c.binds, c.flags);
+ Connection cd = child->get_metadata(0);
+ ConnectDialog::ConnectionData c = cd;
+ undo_redo->add_do_method(selectedNode, "disconnect", c.signal, Callable(c.target, c.method));
+ undo_redo->add_undo_method(selectedNode, "connect", c.signal, Callable(c.target, c.method), c.binds, c.flags);
child = child->get_next();
}
@@ -664,7 +674,6 @@ void ConnectionsDock::_disconnect_all() {
}
void ConnectionsDock::_tree_item_selected() {
-
TreeItem *item = tree->get_selected();
if (!item) { // Unlikely. Disable button just in case.
connect_button->set_text(TTR("Connect..."));
@@ -682,8 +691,9 @@ void ConnectionsDock::_tree_item_activated() { // "Activation" on double-click.
TreeItem *item = tree->get_selected();
- if (!item)
+ if (!item) {
return;
+ }
if (_is_item_signal(*item)) {
_open_connection_dialog(*item);
@@ -693,7 +703,6 @@ void ConnectionsDock::_tree_item_activated() { // "Activation" on double-click.
}
bool ConnectionsDock::_is_item_signal(TreeItem &item) {
-
return (item.get_parent() == tree->get_root() || item.get_parent()->get_parent() == tree->get_root());
}
@@ -701,12 +710,11 @@ bool ConnectionsDock::_is_item_signal(TreeItem &item) {
* Open connection dialog with TreeItem data to CREATE a brand-new connection.
*/
void ConnectionsDock::_open_connection_dialog(TreeItem &item) {
-
String signal = item.get_metadata(0).operator Dictionary()["name"];
const String &signalname = signal;
String midname = selectedNode->get_name();
for (int i = 0; i < midname.length(); i++) { //TODO: Regex filter may be cleaner.
- CharType c = midname[i];
+ char32_t c = midname[i];
if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_')) {
if (c == ' ') {
// Replace spaces with underlines.
@@ -728,7 +736,7 @@ void ConnectionsDock::_open_connection_dialog(TreeItem &item) {
StringName dst_method = "_on_" + midname + "_" + signal;
- Connection c;
+ ConnectDialog::ConnectionData c;
c.source = selectedNode;
c.signal = StringName(signalname);
c.target = dst_node;
@@ -741,14 +749,14 @@ void ConnectionsDock::_open_connection_dialog(TreeItem &item) {
/*
* Open connection dialog with Connection data to EDIT an existing connection.
*/
-void ConnectionsDock::_open_connection_dialog(Connection cToEdit) {
-
+void ConnectionsDock::_open_connection_dialog(ConnectDialog::ConnectionData cToEdit) {
Node *src = static_cast<Node *>(cToEdit.source);
Node *dst = static_cast<Node *>(cToEdit.target);
if (src && dst) {
+ const String &signalname = cToEdit.signal;
connect_dialog->set_title(TTR("Edit Connection:") + cToEdit.signal);
- connect_dialog->popup_centered();
+ connect_dialog->popup_dialog(signalname);
connect_dialog->init(cToEdit, true);
}
}
@@ -757,20 +765,23 @@ void ConnectionsDock::_open_connection_dialog(Connection cToEdit) {
* Open slot method location in script editor.
*/
void ConnectionsDock::_go_to_script(TreeItem &item) {
-
- if (_is_item_signal(item))
+ if (_is_item_signal(item)) {
return;
+ }
- Connection c = item.get_metadata(0);
+ Connection cd = item.get_metadata(0);
+ ConnectDialog::ConnectionData c = cd;
ERR_FAIL_COND(c.source != selectedNode); //shouldn't happen but...bugcheck
- if (!c.target)
+ if (!c.target) {
return;
+ }
Ref<Script> script = c.target->get_script();
- if (script.is_null())
+ if (script.is_null()) {
return;
+ }
if (script.is_valid() && ScriptEditor::get_singleton()->script_goto_method(script, c.method)) {
editor->call("_editor_select", EditorNode::EDITOR_SCRIPT);
@@ -778,11 +789,11 @@ void ConnectionsDock::_go_to_script(TreeItem &item) {
}
void ConnectionsDock::_handle_signal_menu_option(int option) {
-
TreeItem *item = tree->get_selected();
- if (!item)
+ if (!item) {
return;
+ }
switch (option) {
case CONNECT: {
@@ -797,11 +808,11 @@ void ConnectionsDock::_handle_signal_menu_option(int option) {
}
void ConnectionsDock::_handle_slot_menu_option(int option) {
-
TreeItem *item = tree->get_selected();
- if (!item)
+ if (!item) {
return;
+ }
switch (option) {
case EDIT: {
@@ -819,11 +830,11 @@ void ConnectionsDock::_handle_slot_menu_option(int option) {
}
void ConnectionsDock::_rmb_pressed(Vector2 position) {
-
TreeItem *item = tree->get_selected();
- if (!item)
+ if (!item) {
return;
+ }
Vector2 global_position = tree->get_global_position() + position;
@@ -837,12 +848,10 @@ void ConnectionsDock::_rmb_pressed(Vector2 position) {
}
void ConnectionsDock::_close() {
-
hide();
}
void ConnectionsDock::_connect_pressed() {
-
TreeItem *item = tree->get_selected();
if (!item) {
connect_button->set_disabled(true);
@@ -858,38 +867,26 @@ void ConnectionsDock::_connect_pressed() {
}
void ConnectionsDock::_notification(int p_what) {
-
if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) {
update_tree();
}
}
void ConnectionsDock::_bind_methods() {
-
- ClassDB::bind_method("_make_or_edit_connection", &ConnectionsDock::_make_or_edit_connection);
- ClassDB::bind_method("_disconnect_all", &ConnectionsDock::_disconnect_all);
- ClassDB::bind_method("_tree_item_selected", &ConnectionsDock::_tree_item_selected);
- ClassDB::bind_method("_tree_item_activated", &ConnectionsDock::_tree_item_activated);
- ClassDB::bind_method("_handle_signal_menu_option", &ConnectionsDock::_handle_signal_menu_option);
- ClassDB::bind_method("_handle_slot_menu_option", &ConnectionsDock::_handle_slot_menu_option);
- ClassDB::bind_method("_rmb_pressed", &ConnectionsDock::_rmb_pressed);
- ClassDB::bind_method("_close", &ConnectionsDock::_close);
- ClassDB::bind_method("_connect_pressed", &ConnectionsDock::_connect_pressed);
ClassDB::bind_method("update_tree", &ConnectionsDock::update_tree);
}
void ConnectionsDock::set_node(Node *p_node) {
-
selectedNode = p_node;
update_tree();
}
void ConnectionsDock::update_tree() {
-
tree->clear();
- if (!selectedNode)
+ if (!selectedNode) {
return;
+ }
TreeItem *root = tree->create_item();
@@ -901,64 +898,69 @@ void ConnectionsDock::update_tree() {
StringName base = selectedNode->get_class();
while (base) {
-
List<MethodInfo> node_signals2;
- Ref<Texture> icon;
+ Ref<Texture2D> icon;
String name;
if (!did_script) {
-
+ // Get script signals (including signals from any base scripts).
Ref<Script> scr = selectedNode->get_script();
if (scr.is_valid()) {
scr->get_script_signal_list(&node_signals2);
- if (scr->get_path().is_resource_file())
+ if (scr->get_path().is_resource_file()) {
name = scr->get_path().get_file();
- else
+ } else {
name = scr->get_class();
+ }
- if (has_icon(scr->get_class(), "EditorIcons")) {
- icon = get_icon(scr->get_class(), "EditorIcons");
+ if (has_theme_icon(scr->get_class(), "EditorIcons")) {
+ icon = get_theme_icon(scr->get_class(), "EditorIcons");
}
}
} else {
-
ClassDB::get_signal_list(base, &node_signals2, true);
- if (has_icon(base, "EditorIcons")) {
- icon = get_icon(base, "EditorIcons");
+ if (has_theme_icon(base, "EditorIcons")) {
+ icon = get_theme_icon(base, "EditorIcons");
}
name = base;
}
if (!icon.is_valid()) {
- icon = get_icon("Object", "EditorIcons");
+ icon = get_theme_icon("Object", "EditorIcons");
}
- TreeItem *pitem = NULL;
+ TreeItem *section_item = nullptr;
+ // Create subsections.
if (node_signals2.size()) {
- pitem = tree->create_item(root);
- pitem->set_text(0, name);
- pitem->set_icon(0, icon);
- pitem->set_selectable(0, false);
- pitem->set_editable(0, false);
- pitem->set_custom_bg_color(0, get_color("prop_subsection", "Editor"));
+ section_item = tree->create_item(root);
+ section_item->set_text(0, name);
+ section_item->set_icon(0, icon);
+ section_item->set_selectable(0, false);
+ section_item->set_editable(0, false);
+ section_item->set_custom_bg_color(0, get_theme_color("prop_subsection", "Editor"));
node_signals2.sort();
}
for (List<MethodInfo>::Element *E = node_signals2.front(); E; E = E->next()) {
-
MethodInfo &mi = E->get();
StringName signal_name = mi.name;
String signaldesc = "(";
- PoolStringArray argnames;
+ PackedStringArray argnames;
+
+ String filter_text = search_box->get_text();
+ if (!filter_text.is_subsequence_ofi(signal_name)) {
+ continue;
+ }
+
if (mi.arguments.size()) {
for (int i = 0; i < mi.arguments.size(); i++) {
-
PropertyInfo &pi = mi.arguments[i];
- if (i > 0)
+ if (i > 0) {
signaldesc += ", ";
+ }
String tname = "var";
if (pi.type == Variant::OBJECT && pi.class_name != StringName()) {
tname = pi.class_name.operator String();
@@ -971,20 +973,21 @@ void ConnectionsDock::update_tree() {
}
signaldesc += ")";
- TreeItem *item = tree->create_item(pitem);
- item->set_text(0, String(signal_name) + signaldesc);
+ // Create the children of the subsection - the actual list of signals.
+ TreeItem *signal_item = tree->create_item(section_item);
+ signal_item->set_text(0, String(signal_name) + signaldesc);
Dictionary sinfo;
sinfo["name"] = signal_name;
sinfo["args"] = argnames;
- item->set_metadata(0, sinfo);
- item->set_icon(0, get_icon("Signal", "EditorIcons"));
+ signal_item->set_metadata(0, sinfo);
+ signal_item->set_icon(0, get_theme_icon("Signal", "EditorIcons"));
// Set tooltip with the signal's documentation.
{
String descr;
bool found = false;
- Map<StringName, Map<StringName, String> >::Element *G = descr_cache.find(base);
+ Map<StringName, Map<StringName, String>>::Element *G = descr_cache.find(base);
if (G) {
Map<StringName, String>::Element *F = G->get().find(signal_name);
if (F) {
@@ -999,7 +1002,7 @@ void ConnectionsDock::update_tree() {
while (F && descr == String()) {
for (int i = 0; i < F->get().signals.size(); i++) {
if (F->get().signals[i].name == signal_name.operator String()) {
- descr = F->get().signals[i].description.strip_edges();
+ descr = DTR(F->get().signals[i].description);
break;
}
}
@@ -1013,7 +1016,7 @@ void ConnectionsDock::update_tree() {
}
// "::" separators used in make_custom_tooltip for formatting.
- item->set_tooltip(0, String(signal_name) + "::" + signaldesc + "::" + descr);
+ signal_item->set_tooltip(0, String(signal_name) + "::" + signaldesc + "::" + descr);
}
// List existing connections
@@ -1021,36 +1024,40 @@ void ConnectionsDock::update_tree() {
selectedNode->get_signal_connection_list(signal_name, &connections);
for (List<Object::Connection>::Element *F = connections.front(); F; F = F->next()) {
-
- Object::Connection &c = F->get();
- if (!(c.flags & CONNECT_PERSIST))
+ Connection cn = F->get();
+ if (!(cn.flags & CONNECT_PERSIST)) {
continue;
+ }
+ ConnectDialog::ConnectionData c = cn;
Node *target = Object::cast_to<Node>(c.target);
- if (!target)
+ if (!target) {
continue;
+ }
String path = String(selectedNode->get_path_to(target)) + " :: " + c.method + "()";
- if (c.flags & CONNECT_DEFERRED)
+ if (c.flags & CONNECT_DEFERRED) {
path += " (deferred)";
- if (c.flags & CONNECT_ONESHOT)
+ }
+ if (c.flags & CONNECT_ONESHOT) {
path += " (oneshot)";
+ }
if (c.binds.size()) {
-
path += " binds(";
for (int i = 0; i < c.binds.size(); i++) {
-
- if (i > 0)
+ if (i > 0) {
path += ", ";
+ }
path += c.binds[i].operator String();
}
path += ")";
}
- TreeItem *item2 = tree->create_item(item);
- item2->set_text(0, path);
- item2->set_metadata(0, c);
- item2->set_icon(0, get_icon("Slot", "EditorIcons"));
+ TreeItem *connection_item = tree->create_item(signal_item);
+ connection_item->set_text(0, path);
+ Connection cd = c;
+ connection_item->set_metadata(0, cd);
+ connection_item->set_icon(0, get_theme_icon("Slot", "EditorIcons"));
}
}
@@ -1066,18 +1073,25 @@ void ConnectionsDock::update_tree() {
}
ConnectionsDock::ConnectionsDock(EditorNode *p_editor) {
-
editor = p_editor;
set_name(TTR("Signals"));
VBoxContainer *vbc = this;
+ search_box = memnew(LineEdit);
+ search_box->set_h_size_flags(Control::SIZE_EXPAND_FILL);
+ search_box->set_placeholder(TTR("Filter signals"));
+ search_box->set_right_icon(get_theme_icon("Search", "EditorIcons"));
+ search_box->set_clear_button_enabled(true);
+ search_box->connect("text_changed", callable_mp(this, &ConnectionsDock::_filter_changed));
+ vbc->add_child(search_box);
+
tree = memnew(ConnectionsDockTree);
tree->set_columns(1);
tree->set_select_mode(Tree::SELECT_ROW);
tree->set_hide_root(true);
vbc->add_child(tree);
- tree->set_v_size_flags(SIZE_EXPAND_FILL);
+ tree->set_v_size_flags(Control::SIZE_EXPAND_FILL);
tree->set_allow_rmb_select(true);
connect_button = memnew(Button);
@@ -1085,37 +1099,35 @@ ConnectionsDock::ConnectionsDock(EditorNode *p_editor) {
vbc->add_child(hb);
hb->add_spacer();
hb->add_child(connect_button);
- connect_button->connect("pressed", this, "_connect_pressed");
+ connect_button->connect("pressed", callable_mp(this, &ConnectionsDock::_connect_pressed));
connect_dialog = memnew(ConnectDialog);
- connect_dialog->set_as_toplevel(true);
add_child(connect_dialog);
disconnect_all_dialog = memnew(ConfirmationDialog);
- disconnect_all_dialog->set_as_toplevel(true);
add_child(disconnect_all_dialog);
- disconnect_all_dialog->connect("confirmed", this, "_disconnect_all");
+ disconnect_all_dialog->connect("confirmed", callable_mp(this, &ConnectionsDock::_disconnect_all));
disconnect_all_dialog->set_text(TTR("Are you sure you want to remove all connections from this signal?"));
signal_menu = memnew(PopupMenu);
add_child(signal_menu);
- signal_menu->connect("id_pressed", this, "_handle_signal_menu_option");
+ signal_menu->connect("id_pressed", callable_mp(this, &ConnectionsDock::_handle_signal_menu_option));
signal_menu->add_item(TTR("Connect..."), CONNECT);
signal_menu->add_item(TTR("Disconnect All"), DISCONNECT_ALL);
slot_menu = memnew(PopupMenu);
add_child(slot_menu);
- slot_menu->connect("id_pressed", this, "_handle_slot_menu_option");
+ slot_menu->connect("id_pressed", callable_mp(this, &ConnectionsDock::_handle_slot_menu_option));
slot_menu->add_item(TTR("Edit..."), EDIT);
slot_menu->add_item(TTR("Go To Method"), GO_TO_SCRIPT);
slot_menu->add_item(TTR("Disconnect"), DISCONNECT);
- connect_dialog->connect("connected", this, "_make_or_edit_connection");
- tree->connect("item_selected", this, "_tree_item_selected");
- tree->connect("item_activated", this, "_tree_item_activated");
- tree->connect("item_rmb_selected", this, "_rmb_pressed");
+ connect_dialog->connect("connected", callable_mp(this, &ConnectionsDock::_make_or_edit_connection));
+ tree->connect("item_selected", callable_mp(this, &ConnectionsDock::_tree_item_selected));
+ tree->connect("item_activated", callable_mp(this, &ConnectionsDock::_tree_item_activated));
+ tree->connect("item_rmb_selected", callable_mp(this, &ConnectionsDock::_rmb_pressed));
- add_constant_override("separation", 3 * EDSCALE);
+ add_theme_constant_override("separation", 3 * EDSCALE);
}
ConnectionsDock::~ConnectionsDock() {