2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* connections_dialog.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
2020-01-01 11:16:22 +01:00
|
|
|
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
|
2014-02-10 02:10:30 +01:00
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/*************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#include "connections_dialog.h"
|
|
|
|
|
2018-09-11 18:13:45 +02:00
|
|
|
#include "core/print_string.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
#include "editor_node.h"
|
2019-12-24 08:17:23 +01:00
|
|
|
#include "editor_scale.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "editor_settings.h"
|
2016-06-12 01:01:17 +02:00
|
|
|
#include "plugins/script_editor_plugin.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "scene/gui/label.h"
|
2018-04-28 02:08:34 +02:00
|
|
|
#include "scene/gui/popup_menu.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2019-04-12 04:21:48 +02:00
|
|
|
static Node *_find_first_script(Node *p_root, Node *p_node) {
|
|
|
|
if (p_node != p_root && p_node->get_owner() != p_root) {
|
2020-04-02 01:20:12 +02:00
|
|
|
return nullptr;
|
2019-04-12 04:21:48 +02:00
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-02 01:20:12 +02:00
|
|
|
return nullptr;
|
2019-04-12 04:21:48 +02:00
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
class ConnectDialogBinds : public Object {
|
2017-03-05 16:44:50 +01:00
|
|
|
GDCLASS(ConnectDialogBinds, Object);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
public:
|
2014-02-10 02:10:30 +01:00
|
|
|
Vector<Variant> params;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool _set(const StringName &p_name, const Variant &p_value) {
|
|
|
|
String name = p_name;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (name.begins_with("bind/")) {
|
2017-03-05 16:44:50 +01:00
|
|
|
int which = name.get_slice("/", 1).to_int() - 1;
|
|
|
|
ERR_FAIL_INDEX_V(which, params.size(), false);
|
2018-07-25 03:11:03 +02:00
|
|
|
params.write[which] = p_value;
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2014-02-10 02:10:30 +01:00
|
|
|
return false;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool _get(const StringName &p_name, Variant &r_ret) const {
|
|
|
|
String name = p_name;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (name.begins_with("bind/")) {
|
2017-03-05 16:44:50 +01:00
|
|
|
int which = name.get_slice("/", 1).to_int() - 1;
|
|
|
|
ERR_FAIL_INDEX_V(which, params.size(), false);
|
2014-02-10 02:10:30 +01:00
|
|
|
r_ret = params[which];
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2014-02-10 02:10:30 +01:00
|
|
|
return false;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void _get_property_list(List<PropertyInfo> *p_list) const {
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < params.size(); i++) {
|
|
|
|
p_list->push_back(PropertyInfo(params[i].get_type(), "bind/" + itos(i + 1)));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void notify_changed() {
|
|
|
|
_change_notify();
|
|
|
|
}
|
|
|
|
|
|
|
|
ConnectDialogBinds() {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-04-29 09:03:49 +02:00
|
|
|
/*
|
2019-09-26 03:08:58 +02:00
|
|
|
* Signal automatically called by parent dialog.
|
|
|
|
*/
|
2014-02-10 02:10:30 +01:00
|
|
|
void ConnectDialog::ok_pressed() {
|
2020-06-19 01:21:46 +02:00
|
|
|
String method_name = dst_method->get_text();
|
|
|
|
|
|
|
|
if (method_name == "") {
|
2019-04-17 01:37:07 +02:00
|
|
|
error->set_text(TTR("Method in target node must be specified."));
|
2020-03-06 18:00:16 +01:00
|
|
|
error->popup_centered();
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
|
|
|
}
|
2020-06-19 01:21:46 +02:00
|
|
|
|
|
|
|
if (!method_name.strip_edges().is_valid_identifier()) {
|
|
|
|
error->set_text(TTR("Method name must be a valid identifier."));
|
|
|
|
error->popup_centered();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Node *target = tree->get_selected();
|
2020-02-16 13:45:10 +01:00
|
|
|
if (!target) {
|
|
|
|
return; // Nothing selected in the tree, not an error.
|
|
|
|
}
|
2016-10-04 13:27:08 +02:00
|
|
|
if (target->get_script().is_null()) {
|
2020-06-19 01:21:46 +02:00
|
|
|
if (!target->has_method(method_name)) {
|
2019-04-17 01:37:07 +02:00
|
|
|
error->set_text(TTR("Target method not found. Specify a valid method or attach a script to the target node."));
|
2020-03-06 18:00:16 +01:00
|
|
|
error->popup_centered();
|
2016-10-04 13:27:08 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
emit_signal("connected");
|
2020-01-14 18:58:26 +01:00
|
|
|
hide();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2018-04-29 09:03:49 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void ConnectDialog::_cancel_pressed() {
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
2020-02-27 22:49:16 +01:00
|
|
|
void ConnectDialog::_item_activated() {
|
|
|
|
_ok_pressed(); // From AcceptDialog.
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectDialog::_text_entered(const String &p_text) {
|
|
|
|
_ok_pressed(); // From AcceptDialog.
|
|
|
|
}
|
|
|
|
|
2018-04-29 09:03:49 +02:00
|
|
|
/*
|
2019-09-26 03:08:58 +02:00
|
|
|
* Called each time a target node is selected within the target node tree.
|
|
|
|
*/
|
2018-04-29 09:03:49 +02:00
|
|
|
void ConnectDialog::_tree_node_selected() {
|
|
|
|
Node *current = tree->get_selected();
|
2018-04-29 00:11:51 +02:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!current) {
|
2019-04-23 18:36:30 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2019-04-23 18:36:30 +02:00
|
|
|
|
2019-04-12 04:21:48 +02:00
|
|
|
dst_path = source->get_path_to(current);
|
2020-01-15 18:18:34 +01:00
|
|
|
_update_ok_enabled();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2018-04-29 09:03:49 +02:00
|
|
|
/*
|
2019-09-26 03:08:58 +02:00
|
|
|
* Adds a new parameter bind to connection.
|
|
|
|
*/
|
2014-02-10 02:10:30 +01:00
|
|
|
void ConnectDialog::_add_bind() {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (cdbinds->params.size() >= VARIANT_ARG_MAX) {
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-08-07 12:17:31 +02:00
|
|
|
Variant::Type vt = (Variant::Type)type_list->get_item_id(type_list->get_selected());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Variant value;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (vt) {
|
2020-05-10 13:00:47 +02:00
|
|
|
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;
|
2019-04-09 17:08:36 +02:00
|
|
|
default: {
|
|
|
|
ERR_FAIL();
|
|
|
|
} break;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND(value.get_type() == Variant::NIL);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
cdbinds->params.push_back(value);
|
|
|
|
cdbinds->notify_changed();
|
|
|
|
}
|
|
|
|
|
2018-04-29 09:03:49 +02:00
|
|
|
/*
|
2019-09-26 03:08:58 +02:00
|
|
|
* Remove parameter bind from connection.
|
|
|
|
*/
|
2014-02-10 02:10:30 +01:00
|
|
|
void ConnectDialog::_remove_bind() {
|
|
|
|
String st = bind_editor->get_selected_path();
|
2020-05-14 16:41:43 +02:00
|
|
|
if (st == "") {
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
int idx = st.get_slice("/", 1).to_int() - 1;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_INDEX(idx, cdbinds->params.size());
|
2014-02-10 02:10:30 +01:00
|
|
|
cdbinds->params.remove(idx);
|
|
|
|
cdbinds->notify_changed();
|
|
|
|
}
|
|
|
|
|
2020-01-15 18:18:34 +01:00
|
|
|
/*
|
|
|
|
* Enables or disables the connect button. The connect button is enabled if a
|
|
|
|
* node is selected and valid in the selected mode.
|
|
|
|
*/
|
|
|
|
void ConnectDialog::_update_ok_enabled() {
|
|
|
|
Node *target = tree->get_selected();
|
|
|
|
|
|
|
|
if (target == nullptr) {
|
|
|
|
get_ok()->set_disabled(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!advanced->is_pressed() && target->get_script().is_null()) {
|
|
|
|
get_ok()->set_disabled(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
get_ok()->set_disabled(false);
|
|
|
|
}
|
|
|
|
|
2018-04-29 09:03:49 +02:00
|
|
|
void ConnectDialog::_notification(int p_what) {
|
|
|
|
if (p_what == NOTIFICATION_ENTER_TREE) {
|
|
|
|
bind_editor->edit(cdbinds);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectDialog::_bind_methods() {
|
|
|
|
ClassDB::bind_method("_cancel", &ConnectDialog::_cancel_pressed);
|
2020-01-15 18:18:34 +01:00
|
|
|
ClassDB::bind_method("_update_ok_enabled", &ConnectDialog::_update_ok_enabled);
|
2018-04-29 09:03:49 +02:00
|
|
|
|
|
|
|
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 {
|
2019-04-12 04:21:48 +02:00
|
|
|
return dst_path;
|
2018-04-29 09:03:49 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void ConnectDialog::set_dst_node(Node *p_node) {
|
2014-02-10 02:10:30 +01:00
|
|
|
tree->set_selected(p_node);
|
|
|
|
}
|
|
|
|
|
2018-04-29 09:03:49 +02:00
|
|
|
StringName ConnectDialog::get_dst_method_name() const {
|
|
|
|
String txt = dst_method->get_text();
|
2020-05-14 16:41:43 +02:00
|
|
|
if (txt.find("(") != -1) {
|
2018-04-29 09:03:49 +02:00
|
|
|
txt = txt.left(txt.find("(")).strip_edges();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-04-29 09:03:49 +02:00
|
|
|
return txt;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void ConnectDialog::set_dst_method(const StringName &p_method) {
|
2014-02-10 02:10:30 +01:00
|
|
|
dst_method->set_text(p_method);
|
|
|
|
}
|
|
|
|
|
2018-04-29 09:03:49 +02:00
|
|
|
Vector<Variant> ConnectDialog::get_binds() const {
|
|
|
|
return cdbinds->params;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-04-29 09:03:49 +02:00
|
|
|
bool ConnectDialog::get_deferred() const {
|
|
|
|
return deferred->is_pressed();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ConnectDialog::get_oneshot() const {
|
|
|
|
return oneshot->is_pressed();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2019-09-26 03:08:58 +02:00
|
|
|
* Returns true if ConnectDialog is being used to edit an existing connection.
|
|
|
|
*/
|
2018-04-29 09:03:49 +02:00
|
|
|
bool ConnectDialog::is_editing() const {
|
|
|
|
return bEditMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2019-09-26 03:08:58 +02:00
|
|
|
* Initialize ConnectDialog and populate fields with expected data.
|
|
|
|
* If creating a connection from scratch, sensible defaults are used.
|
|
|
|
* If editing an existing connection, previous data is retained.
|
|
|
|
*/
|
2020-02-19 20:27:19 +01:00
|
|
|
void ConnectDialog::init(ConnectionData c, bool bEdit) {
|
2020-01-14 18:58:26 +01:00
|
|
|
set_hide_on_ok(false);
|
|
|
|
|
2018-04-29 09:03:49 +02:00
|
|
|
source = static_cast<Node *>(c.source);
|
|
|
|
signal = c.signal;
|
|
|
|
|
2020-04-02 01:20:12 +02:00
|
|
|
tree->set_selected(nullptr);
|
2018-04-29 09:03:49 +02:00
|
|
|
tree->set_marked(source, true);
|
|
|
|
|
2019-04-12 04:21:48 +02:00
|
|
|
if (c.target) {
|
|
|
|
set_dst_node(static_cast<Node *>(c.target));
|
|
|
|
set_dst_method(c.method);
|
|
|
|
}
|
2018-04-29 09:03:49 +02:00
|
|
|
|
2020-01-15 18:18:34 +01:00
|
|
|
_update_ok_enabled();
|
|
|
|
|
2018-04-29 09:03:49 +02:00
|
|
|
bool bDeferred = (c.flags & CONNECT_DEFERRED) == CONNECT_DEFERRED;
|
|
|
|
bool bOneshot = (c.flags & CONNECT_ONESHOT) == CONNECT_ONESHOT;
|
|
|
|
|
|
|
|
deferred->set_pressed(bDeferred);
|
|
|
|
oneshot->set_pressed(bOneshot);
|
|
|
|
|
|
|
|
cdbinds->params.clear();
|
|
|
|
cdbinds->params = c.binds;
|
|
|
|
cdbinds->notify_changed();
|
|
|
|
|
|
|
|
bEditMode = bEdit;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2019-06-06 04:13:57 +02:00
|
|
|
void ConnectDialog::popup_dialog(const String &p_for_signal) {
|
2019-04-12 04:21:48 +02:00
|
|
|
from_signal->set_text(p_for_signal);
|
2020-03-12 13:37:40 +01:00
|
|
|
error_label->add_theme_color_override("font_color", error_label->get_theme_color("error_color", "Editor"));
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!advanced->is_pressed()) {
|
2019-06-06 04:13:57 +02:00
|
|
|
error_label->set_visible(!_find_first_script(get_tree()->get_edited_scene_root(), get_tree()->get_edited_scene_root()));
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2019-04-12 04:21:48 +02:00
|
|
|
|
2019-06-06 04:13:57 +02:00
|
|
|
popup_centered();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectDialog::_advanced_pressed() {
|
|
|
|
if (advanced->is_pressed()) {
|
2020-03-06 18:00:16 +01:00
|
|
|
set_min_size(Size2(900, 500) * EDSCALE);
|
2019-06-06 04:13:57 +02:00
|
|
|
connect_to_label->set_text(TTR("Connect to Node:"));
|
2019-04-12 04:21:48 +02:00
|
|
|
tree->set_connect_to_script_mode(false);
|
2019-06-06 04:13:57 +02:00
|
|
|
|
|
|
|
vbc_right->show();
|
2019-04-12 04:21:48 +02:00
|
|
|
error_label->hide();
|
|
|
|
} else {
|
2020-03-06 18:00:16 +01:00
|
|
|
set_min_size(Size2(600, 500) * EDSCALE);
|
2019-06-06 04:13:57 +02:00
|
|
|
set_size(Size2());
|
|
|
|
connect_to_label->set_text(TTR("Connect to Script:"));
|
2019-04-12 04:21:48 +02:00
|
|
|
tree->set_connect_to_script_mode(true);
|
|
|
|
|
2019-06-06 04:13:57 +02:00
|
|
|
vbc_right->hide();
|
|
|
|
error_label->set_visible(!_find_first_script(get_tree()->get_edited_scene_root(), get_tree()->get_edited_scene_root()));
|
2019-04-12 04:21:48 +02:00
|
|
|
}
|
|
|
|
|
2020-01-15 18:18:34 +01:00
|
|
|
_update_ok_enabled();
|
|
|
|
|
2020-03-06 18:00:16 +01:00
|
|
|
popup_centered();
|
2019-04-12 04:21:48 +02:00
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
ConnectDialog::ConnectDialog() {
|
2020-03-06 18:00:16 +01:00
|
|
|
set_min_size(Size2(600, 500) * EDSCALE);
|
2019-06-06 04:13:57 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
VBoxContainer *vbc = memnew(VBoxContainer);
|
2016-06-12 01:34:31 +02:00
|
|
|
add_child(vbc);
|
2017-01-10 05:49:55 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
HBoxContainer *main_hb = memnew(HBoxContainer);
|
2016-06-12 01:34:31 +02:00
|
|
|
vbc->add_child(main_hb);
|
2020-03-06 18:00:16 +01:00
|
|
|
main_hb->set_v_size_flags(Control::SIZE_EXPAND_FILL);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
VBoxContainer *vbc_left = memnew(VBoxContainer);
|
2016-06-12 01:34:31 +02:00
|
|
|
main_hb->add_child(vbc_left);
|
2020-03-06 18:00:16 +01:00
|
|
|
vbc_left->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2019-04-12 04:21:48 +02:00
|
|
|
from_signal = memnew(LineEdit);
|
|
|
|
from_signal->set_editable(false);
|
|
|
|
vbc_left->add_margin_child(TTR("From Signal:"), from_signal);
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
tree = memnew(SceneTreeEditor(false));
|
2019-06-06 04:13:57 +02:00
|
|
|
tree->set_connecting_signal(true);
|
2020-02-27 22:49:16 +01:00
|
|
|
tree->get_scene_tree()->connect("item_activated", callable_mp(this, &ConnectDialog::_item_activated));
|
2020-02-21 18:28:45 +01:00
|
|
|
tree->connect("node_selected", callable_mp(this, &ConnectDialog::_tree_node_selected));
|
2019-04-12 04:21:48 +02:00
|
|
|
tree->set_connect_to_script_mode(true);
|
|
|
|
|
2019-06-13 17:15:13 +02:00
|
|
|
Node *mc = vbc_left->add_margin_child(TTR("Connect to Script:"), tree, true);
|
2019-04-12 04:21:48 +02:00
|
|
|
connect_to_label = Object::cast_to<Label>(vbc_left->get_child(mc->get_index() - 1));
|
2018-04-29 09:03:49 +02:00
|
|
|
|
2019-04-12 04:21:48 +02:00
|
|
|
error_label = memnew(Label);
|
|
|
|
error_label->set_text(TTR("Scene does not contain any script."));
|
|
|
|
vbc_left->add_child(error_label);
|
|
|
|
error_label->hide();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2019-04-12 04:21:48 +02:00
|
|
|
vbc_right = memnew(VBoxContainer);
|
2016-06-12 01:34:31 +02:00
|
|
|
main_hb->add_child(vbc_right);
|
2020-03-06 18:00:16 +01:00
|
|
|
vbc_right->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
2019-04-12 04:21:48 +02:00
|
|
|
vbc_right->hide();
|
2016-06-12 01:34:31 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
HBoxContainer *add_bind_hb = memnew(HBoxContainer);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
type_list = memnew(OptionButton);
|
2020-03-06 18:00:16 +01:00
|
|
|
type_list->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
2016-06-12 01:34:31 +02:00
|
|
|
add_bind_hb->add_child(type_list);
|
2017-03-05 16:44:50 +01:00
|
|
|
type_list->add_item("bool", Variant::BOOL);
|
|
|
|
type_list->add_item("int", Variant::INT);
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
|
|
|
type_list->add_item("real", Variant::FLOAT);
|
2019-06-06 04:13:57 +02:00
|
|
|
type_list->add_item("String", Variant::STRING);
|
2020-02-20 22:58:05 +01:00
|
|
|
type_list->add_item("StringName", Variant::STRING_NAME);
|
2017-03-05 16:44:50 +01:00
|
|
|
type_list->add_item("Vector2", Variant::VECTOR2);
|
|
|
|
type_list->add_item("Rect2", Variant::RECT2);
|
|
|
|
type_list->add_item("Vector3", Variant::VECTOR3);
|
|
|
|
type_list->add_item("Plane", Variant::PLANE);
|
|
|
|
type_list->add_item("Quat", Variant::QUAT);
|
2017-11-17 03:09:00 +01:00
|
|
|
type_list->add_item("AABB", Variant::AABB);
|
2017-03-05 16:44:50 +01:00
|
|
|
type_list->add_item("Basis", Variant::BASIS);
|
|
|
|
type_list->add_item("Transform", Variant::TRANSFORM);
|
|
|
|
type_list->add_item("Color", Variant::COLOR);
|
2014-02-10 02:10:30 +01:00
|
|
|
type_list->select(0);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Button *add_bind = memnew(Button);
|
2016-05-04 03:25:37 +02:00
|
|
|
add_bind->set_text(TTR("Add"));
|
2016-06-12 01:34:31 +02:00
|
|
|
add_bind_hb->add_child(add_bind);
|
2020-02-21 18:28:45 +01:00
|
|
|
add_bind->connect("pressed", callable_mp(this, &ConnectDialog::_add_bind));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Button *del_bind = memnew(Button);
|
2016-05-04 03:25:37 +02:00
|
|
|
del_bind->set_text(TTR("Remove"));
|
2016-06-12 01:34:31 +02:00
|
|
|
add_bind_hb->add_child(del_bind);
|
2020-02-21 18:28:45 +01:00
|
|
|
del_bind->connect("pressed", callable_mp(this, &ConnectDialog::_remove_bind));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
vbc_right->add_margin_child(TTR("Add Extra Call Argument:"), add_bind_hb);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-09-11 15:53:50 +02:00
|
|
|
bind_editor = memnew(EditorInspector);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
vbc_right->add_margin_child(TTR("Extra Call Arguments:"), bind_editor, true);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
HBoxContainer *dstm_hb = memnew(HBoxContainer);
|
2019-12-21 07:57:15 +01:00
|
|
|
vbc_left->add_margin_child(TTR("Receiver Method:"), dstm_hb);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
dst_method = memnew(LineEdit);
|
2020-03-06 18:00:16 +01:00
|
|
|
dst_method->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
2020-02-27 22:49:16 +01:00
|
|
|
dst_method->connect("text_entered", callable_mp(this, &ConnectDialog::_text_entered));
|
2014-02-10 02:10:30 +01:00
|
|
|
dstm_hb->add_child(dst_method);
|
|
|
|
|
2019-06-06 04:13:57 +02:00
|
|
|
advanced = memnew(CheckButton);
|
2019-04-12 04:21:48 +02:00
|
|
|
dstm_hb->add_child(advanced);
|
2019-06-06 04:13:57 +02:00
|
|
|
advanced->set_text(TTR("Advanced"));
|
2020-02-21 18:28:45 +01:00
|
|
|
advanced->connect("pressed", callable_mp(this, &ConnectDialog::_advanced_pressed));
|
2019-04-12 04:21:48 +02:00
|
|
|
|
2019-06-06 04:13:57 +02:00
|
|
|
deferred = memnew(CheckBox);
|
|
|
|
deferred->set_h_size_flags(0);
|
2016-05-04 03:25:37 +02:00
|
|
|
deferred->set_text(TTR("Deferred"));
|
2019-06-06 04:13:57 +02:00
|
|
|
deferred->set_tooltip(TTR("Defers the signal, storing it in a queue and only firing it at idle time."));
|
2019-04-12 04:21:48 +02:00
|
|
|
vbc_right->add_child(deferred);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2019-06-06 04:13:57 +02:00
|
|
|
oneshot = memnew(CheckBox);
|
|
|
|
oneshot->set_h_size_flags(0);
|
2016-05-04 03:25:37 +02:00
|
|
|
oneshot->set_text(TTR("Oneshot"));
|
2019-06-06 04:13:57 +02:00
|
|
|
oneshot->set_tooltip(TTR("Disconnects the signal after its first emission."));
|
2019-04-12 04:21:48 +02:00
|
|
|
vbc_right->add_child(oneshot);
|
2015-11-23 21:38:15 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
cdbinds = memnew(ConnectDialogBinds);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2019-04-17 01:37:07 +02:00
|
|
|
error = memnew(AcceptDialog);
|
2014-02-10 02:10:30 +01:00
|
|
|
add_child(error);
|
2019-04-17 01:37:07 +02:00
|
|
|
error->set_title(TTR("Cannot connect signal"));
|
2016-05-04 03:25:37 +02:00
|
|
|
error->get_ok()->set_text(TTR("Close"));
|
|
|
|
get_ok()->set_text(TTR("Connect"));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ConnectDialog::~ConnectDialog() {
|
|
|
|
memdelete(cdbinds);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2019-06-12 15:42:08 +02:00
|
|
|
//////////////////////////////////////////
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2019-07-02 15:46:00 +02:00
|
|
|
// 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);
|
2020-03-12 13:37:40 +01:00
|
|
|
help_bit->add_theme_style_override("panel", get_theme_stylebox("panel", "TooltipPanel"));
|
2019-07-02 15:46:00 +02:00
|
|
|
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->call_deferred("set_text", text); //hack so it uses proper theme once inside scene
|
|
|
|
return help_bit;
|
|
|
|
}
|
|
|
|
|
2018-04-29 09:03:49 +02:00
|
|
|
struct _ConnectionsDockMethodInfoSort {
|
|
|
|
_FORCE_INLINE_ bool operator()(const MethodInfo &a, const MethodInfo &b) const {
|
|
|
|
return a.name < b.name;
|
|
|
|
}
|
|
|
|
};
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-08-08 06:15:46 +02:00
|
|
|
void ConnectionsDock::_filter_changed(const String &p_text) {
|
|
|
|
update_tree();
|
|
|
|
}
|
|
|
|
|
2018-04-29 09:03:49 +02:00
|
|
|
/*
|
2019-09-26 03:08:58 +02:00
|
|
|
* Post-ConnectDialog callback for creating/editing connections.
|
|
|
|
* Creates or edits connections based on state of the ConnectDialog when "Connect" is pressed.
|
|
|
|
*/
|
2018-04-29 00:11:51 +02:00
|
|
|
void ConnectionsDock::_make_or_edit_connection() {
|
2014-02-10 02:10:30 +01:00
|
|
|
TreeItem *it = tree->get_selected();
|
|
|
|
ERR_FAIL_COND(!it);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
NodePath dst_path = connect_dialog->get_dst_path();
|
2018-04-29 09:03:49 +02:00
|
|
|
Node *target = selectedNode->get_node(dst_path);
|
2014-02-10 02:10:30 +01:00
|
|
|
ERR_FAIL_COND(!target);
|
|
|
|
|
2020-02-19 20:27:19 +01:00
|
|
|
ConnectDialog::ConnectionData cToMake;
|
2018-04-29 00:11:51 +02:00
|
|
|
cToMake.source = connect_dialog->get_source();
|
|
|
|
cToMake.target = target;
|
2018-04-29 09:03:49 +02:00
|
|
|
cToMake.signal = connect_dialog->get_signal_name();
|
|
|
|
cToMake.method = connect_dialog->get_dst_method_name();
|
2018-04-29 00:11:51 +02:00
|
|
|
cToMake.binds = connect_dialog->get_binds();
|
2017-03-05 16:44:50 +01:00
|
|
|
bool defer = connect_dialog->get_deferred();
|
|
|
|
bool oshot = connect_dialog->get_oneshot();
|
2018-04-29 00:11:51 +02:00
|
|
|
cToMake.flags = CONNECT_PERSIST | (defer ? CONNECT_DEFERRED : 0) | (oshot ? CONNECT_ONESHOT : 0);
|
2018-04-29 09:03:49 +02:00
|
|
|
|
2019-06-13 17:15:13 +02:00
|
|
|
// Conditions to add function: must have a script and must not have the method already
|
|
|
|
// (in the class, the script itself, or inherited).
|
|
|
|
bool add_script_function = false;
|
|
|
|
Ref<Script> script = target->get_script();
|
|
|
|
if (!target->get_script().is_null() && !ClassDB::has_method(target->get_class(), cToMake.method)) {
|
|
|
|
// There is a chance that the method is inherited from another script.
|
|
|
|
bool found_inherited_function = false;
|
|
|
|
Ref<Script> inherited_script = script->get_base_script();
|
|
|
|
while (!inherited_script.is_null()) {
|
|
|
|
int line = inherited_script->get_language()->find_function(cToMake.method, inherited_script->get_source_code());
|
|
|
|
if (line != -1) {
|
|
|
|
found_inherited_function = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
inherited_script = inherited_script->get_base_script();
|
|
|
|
}
|
|
|
|
|
|
|
|
add_script_function = !found_inherited_function;
|
|
|
|
}
|
2020-02-17 22:06:54 +01:00
|
|
|
PackedStringArray script_function_args;
|
2018-07-13 13:58:44 +02:00
|
|
|
if (add_script_function) {
|
2019-06-12 15:42:08 +02:00
|
|
|
// Pick up args here before "it" is deleted by update_tree.
|
2018-07-13 13:58:44 +02:00
|
|
|
script_function_args = it->get_metadata(0).operator Dictionary()["args"];
|
2018-09-16 21:01:17 +02:00
|
|
|
for (int i = 0; i < cToMake.binds.size(); i++) {
|
2020-02-17 22:06:54 +01:00
|
|
|
script_function_args.push_back("extra_arg_" + itos(i) + ":" + Variant::get_type_name(cToMake.binds[i].get_type()));
|
2018-09-16 21:01:17 +02:00
|
|
|
}
|
2018-07-13 13:58:44 +02:00
|
|
|
}
|
|
|
|
|
2018-04-29 00:11:51 +02:00
|
|
|
if (connect_dialog->is_editing()) {
|
2018-04-29 09:03:49 +02:00
|
|
|
_disconnect(*it);
|
2018-04-29 00:11:51 +02:00
|
|
|
_connect(cToMake);
|
2018-04-29 09:03:49 +02:00
|
|
|
} else {
|
2018-04-29 00:11:51 +02:00
|
|
|
_connect(cToMake);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2019-06-13 17:15:13 +02:00
|
|
|
// IMPORTANT NOTE: _disconnect and _connect cause an update_tree, which will delete the object "it" is pointing to.
|
2020-04-02 01:20:12 +02:00
|
|
|
it = nullptr;
|
2018-07-13 13:58:44 +02:00
|
|
|
|
|
|
|
if (add_script_function) {
|
|
|
|
editor->emit_signal("script_add_function_request", target, cToMake.method, script_function_args);
|
2014-02-10 02:10:30 +01:00
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
update_tree();
|
|
|
|
}
|
|
|
|
|
2018-04-29 09:03:49 +02:00
|
|
|
/*
|
2019-09-26 03:08:58 +02:00
|
|
|
* Creates single connection w/ undo-redo functionality.
|
|
|
|
*/
|
2020-02-19 20:27:19 +01:00
|
|
|
void ConnectionsDock::_connect(ConnectDialog::ConnectionData cToMake) {
|
2018-04-29 09:03:49 +02:00
|
|
|
Node *source = static_cast<Node *>(cToMake.source);
|
|
|
|
Node *target = static_cast<Node *>(cToMake.target);
|
2018-04-29 00:11:51 +02:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!source || !target) {
|
2018-04-29 00:11:51 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-04-29 09:03:49 +02:00
|
|
|
|
2018-04-29 00:11:51 +02:00
|
|
|
undo_redo->create_action(vformat(TTR("Connect '%s' to '%s'"), String(cToMake.signal), String(cToMake.method)));
|
2018-04-29 09:03:49 +02:00
|
|
|
|
2020-02-19 20:27:19 +01:00
|
|
|
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);
|
2018-04-29 00:11:51 +02:00
|
|
|
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
|
2018-04-29 09:03:49 +02:00
|
|
|
undo_redo->add_undo_method(EditorNode::get_singleton()->get_scene_tree_dock()->get_tree_editor(), "update_tree");
|
2018-04-29 00:11:51 +02:00
|
|
|
|
|
|
|
undo_redo->commit_action();
|
|
|
|
}
|
|
|
|
|
2018-04-29 09:03:49 +02:00
|
|
|
/*
|
2019-09-26 03:08:58 +02:00
|
|
|
* Break single connection w/ undo-redo functionality.
|
|
|
|
*/
|
2018-04-29 09:03:49 +02:00
|
|
|
void ConnectionsDock::_disconnect(TreeItem &item) {
|
2020-02-19 20:27:19 +01:00
|
|
|
Connection cd = item.get_metadata(0);
|
|
|
|
ConnectDialog::ConnectionData c = cd;
|
|
|
|
|
2019-06-12 15:42:08 +02:00
|
|
|
ERR_FAIL_COND(c.source != selectedNode); // Shouldn't happen but... Bugcheck.
|
2018-04-28 02:08:34 +02:00
|
|
|
|
|
|
|
undo_redo->create_action(vformat(TTR("Disconnect '%s' from '%s'"), c.signal, c.method));
|
2018-04-29 09:03:49 +02:00
|
|
|
|
2020-02-19 20:27:19 +01:00
|
|
|
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);
|
2018-04-28 02:08:34 +02:00
|
|
|
undo_redo->add_do_method(this, "update_tree");
|
|
|
|
undo_redo->add_undo_method(this, "update_tree");
|
2019-06-12 15:42:08 +02:00
|
|
|
undo_redo->add_do_method(EditorNode::get_singleton()->get_scene_tree_dock()->get_tree_editor(), "update_tree"); // To force redraw of scene tree.
|
2018-04-29 00:11:51 +02:00
|
|
|
undo_redo->add_undo_method(EditorNode::get_singleton()->get_scene_tree_dock()->get_tree_editor(), "update_tree");
|
2018-04-29 09:03:49 +02:00
|
|
|
|
2018-04-28 02:08:34 +02:00
|
|
|
undo_redo->commit_action();
|
2018-04-29 09:03:49 +02:00
|
|
|
}
|
2018-04-28 02:08:34 +02:00
|
|
|
|
2018-04-29 09:03:49 +02:00
|
|
|
/*
|
2019-09-26 03:08:58 +02:00
|
|
|
* Break all connections of currently selected signal.
|
|
|
|
* Can undo-redo as a single action.
|
|
|
|
*/
|
2018-04-29 09:03:49 +02:00
|
|
|
void ConnectionsDock::_disconnect_all() {
|
|
|
|
TreeItem *item = tree->get_selected();
|
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!_is_item_signal(*item)) {
|
2018-04-29 09:03:49 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-04-29 09:03:49 +02:00
|
|
|
|
|
|
|
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) {
|
2020-02-19 20:27:19 +01:00
|
|
|
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);
|
2018-04-29 09:03:49 +02:00
|
|
|
child = child->get_next();
|
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
|
|
|
undo_redo->add_undo_method(EditorNode::get_singleton()->get_scene_tree_dock()->get_tree_editor(), "update_tree");
|
|
|
|
|
|
|
|
undo_redo->commit_action();
|
2018-04-28 02:08:34 +02:00
|
|
|
}
|
|
|
|
|
2018-04-29 09:03:49 +02:00
|
|
|
void ConnectionsDock::_tree_item_selected() {
|
|
|
|
TreeItem *item = tree->get_selected();
|
2019-06-12 15:42:08 +02:00
|
|
|
if (!item) { // Unlikely. Disable button just in case.
|
2018-04-29 09:03:49 +02:00
|
|
|
connect_button->set_text(TTR("Connect..."));
|
|
|
|
connect_button->set_disabled(true);
|
|
|
|
} else if (_is_item_signal(*item)) {
|
|
|
|
connect_button->set_text(TTR("Connect..."));
|
|
|
|
connect_button->set_disabled(false);
|
|
|
|
} else {
|
|
|
|
connect_button->set_text(TTR("Disconnect"));
|
|
|
|
connect_button->set_disabled(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-12 15:42:08 +02:00
|
|
|
void ConnectionsDock::_tree_item_activated() { // "Activation" on double-click.
|
2018-04-29 09:03:49 +02:00
|
|
|
|
|
|
|
TreeItem *item = tree->get_selected();
|
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!item) {
|
2018-04-29 09:03:49 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-04-29 09:03:49 +02:00
|
|
|
|
|
|
|
if (_is_item_signal(*item)) {
|
|
|
|
_open_connection_dialog(*item);
|
|
|
|
} else {
|
|
|
|
_go_to_script(*item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ConnectionsDock::_is_item_signal(TreeItem &item) {
|
|
|
|
return (item.get_parent() == tree->get_root() || item.get_parent()->get_parent() == tree->get_root());
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2019-09-26 03:08:58 +02:00
|
|
|
* Open connection dialog with TreeItem data to CREATE a brand-new connection.
|
|
|
|
*/
|
2018-04-29 09:03:49 +02:00
|
|
|
void ConnectionsDock::_open_connection_dialog(TreeItem &item) {
|
|
|
|
String signal = item.get_metadata(0).operator Dictionary()["name"];
|
2019-06-26 15:08:25 +02:00
|
|
|
const String &signalname = signal;
|
2018-04-29 09:03:49 +02:00
|
|
|
String midname = selectedNode->get_name();
|
|
|
|
for (int i = 0; i < midname.length(); i++) { //TODO: Regex filter may be cleaner.
|
2020-07-27 12:43:20 +02:00
|
|
|
char32_t c = midname[i];
|
2018-04-29 09:03:49 +02:00
|
|
|
if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_')) {
|
|
|
|
if (c == ' ') {
|
2019-06-12 15:42:08 +02:00
|
|
|
// Replace spaces with underlines.
|
2018-04-29 09:03:49 +02:00
|
|
|
c = '_';
|
|
|
|
} else {
|
2019-06-12 15:42:08 +02:00
|
|
|
// Remove any other characters.
|
2018-04-29 09:03:49 +02:00
|
|
|
midname.remove(i);
|
|
|
|
i--;
|
|
|
|
continue;
|
|
|
|
}
|
2018-04-28 02:08:34 +02:00
|
|
|
}
|
|
|
|
midname[i] = c;
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2018-04-29 09:03:49 +02:00
|
|
|
Node *dst_node = selectedNode->get_owner() ? selectedNode->get_owner() : selectedNode;
|
2019-04-12 04:21:48 +02:00
|
|
|
if (!dst_node || dst_node->get_script().is_null()) {
|
|
|
|
dst_node = _find_first_script(get_tree()->get_edited_scene_root(), get_tree()->get_edited_scene_root());
|
|
|
|
}
|
|
|
|
|
2018-04-29 00:11:51 +02:00
|
|
|
StringName dst_method = "_on_" + midname + "_" + signal;
|
|
|
|
|
2020-02-19 20:27:19 +01:00
|
|
|
ConnectDialog::ConnectionData c;
|
2018-04-29 09:03:49 +02:00
|
|
|
c.source = selectedNode;
|
2018-04-29 00:11:51 +02:00
|
|
|
c.signal = StringName(signalname);
|
|
|
|
c.target = dst_node;
|
|
|
|
c.method = dst_method;
|
2019-06-06 04:13:57 +02:00
|
|
|
connect_dialog->popup_dialog(signalname);
|
2018-04-29 00:11:51 +02:00
|
|
|
connect_dialog->init(c);
|
2019-04-12 04:21:48 +02:00
|
|
|
connect_dialog->set_title(TTR("Connect a Signal to a Method"));
|
2018-04-29 00:11:51 +02:00
|
|
|
}
|
|
|
|
|
2018-04-29 09:03:49 +02:00
|
|
|
/*
|
2019-09-26 03:08:58 +02:00
|
|
|
* Open connection dialog with Connection data to EDIT an existing connection.
|
|
|
|
*/
|
2020-02-19 20:27:19 +01:00
|
|
|
void ConnectionsDock::_open_connection_dialog(ConnectDialog::ConnectionData cToEdit) {
|
2018-04-29 09:03:49 +02:00
|
|
|
Node *src = static_cast<Node *>(cToEdit.source);
|
|
|
|
Node *dst = static_cast<Node *>(cToEdit.target);
|
2018-04-29 00:11:51 +02:00
|
|
|
|
2018-04-29 09:03:49 +02:00
|
|
|
if (src && dst) {
|
2020-09-15 11:54:57 +02:00
|
|
|
const String &signalname = cToEdit.signal;
|
2019-04-12 04:21:48 +02:00
|
|
|
connect_dialog->set_title(TTR("Edit Connection:") + cToEdit.signal);
|
2020-09-15 11:54:57 +02:00
|
|
|
connect_dialog->popup_dialog(signalname);
|
2019-04-12 04:21:48 +02:00
|
|
|
connect_dialog->init(cToEdit, true);
|
2018-04-29 00:11:51 +02:00
|
|
|
}
|
2018-04-28 02:08:34 +02:00
|
|
|
}
|
|
|
|
|
2018-04-29 09:03:49 +02:00
|
|
|
/*
|
2019-09-26 03:08:58 +02:00
|
|
|
* Open slot method location in script editor.
|
|
|
|
*/
|
2018-04-29 09:03:49 +02:00
|
|
|
void ConnectionsDock::_go_to_script(TreeItem &item) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (_is_item_signal(item)) {
|
2018-04-29 09:03:49 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-04-29 09:03:49 +02:00
|
|
|
|
2020-02-19 20:27:19 +01:00
|
|
|
Connection cd = item.get_metadata(0);
|
|
|
|
ConnectDialog::ConnectionData c = cd;
|
2018-04-29 09:03:49 +02:00
|
|
|
ERR_FAIL_COND(c.source != selectedNode); //shouldn't happen but...bugcheck
|
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!c.target) {
|
2018-04-29 09:03:49 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-04-29 09:03:49 +02:00
|
|
|
|
|
|
|
Ref<Script> script = c.target->get_script();
|
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (script.is_null()) {
|
2018-04-29 09:03:49 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-04-29 09:03:49 +02:00
|
|
|
|
|
|
|
if (script.is_valid() && ScriptEditor::get_singleton()->script_goto_method(script, c.method)) {
|
|
|
|
editor->call("_editor_select", EditorNode::EDITOR_SCRIPT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectionsDock::_handle_signal_menu_option(int option) {
|
|
|
|
TreeItem *item = tree->get_selected();
|
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!item) {
|
2018-04-29 09:03:49 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-04-29 09:03:49 +02:00
|
|
|
|
|
|
|
switch (option) {
|
|
|
|
case CONNECT: {
|
|
|
|
_open_connection_dialog(*item);
|
|
|
|
} break;
|
|
|
|
case DISCONNECT_ALL: {
|
2018-08-28 20:15:04 +02:00
|
|
|
StringName signal_name = item->get_metadata(0).operator Dictionary()["name"];
|
|
|
|
disconnect_all_dialog->set_text(vformat(TTR("Are you sure you want to remove all connections from the \"%s\" signal?"), signal_name));
|
2018-04-29 09:03:49 +02:00
|
|
|
disconnect_all_dialog->popup_centered();
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectionsDock::_handle_slot_menu_option(int option) {
|
|
|
|
TreeItem *item = tree->get_selected();
|
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!item) {
|
2018-04-29 09:03:49 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-04-29 09:03:49 +02:00
|
|
|
|
|
|
|
switch (option) {
|
|
|
|
case EDIT: {
|
|
|
|
Connection c = item->get_metadata(0);
|
|
|
|
_open_connection_dialog(c);
|
|
|
|
} break;
|
|
|
|
case GO_TO_SCRIPT: {
|
|
|
|
_go_to_script(*item);
|
|
|
|
} break;
|
|
|
|
case DISCONNECT: {
|
|
|
|
_disconnect(*item);
|
|
|
|
update_tree();
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectionsDock::_rmb_pressed(Vector2 position) {
|
|
|
|
TreeItem *item = tree->get_selected();
|
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!item) {
|
2018-04-29 09:03:49 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-04-29 09:03:49 +02:00
|
|
|
|
|
|
|
Vector2 global_position = tree->get_global_position() + position;
|
|
|
|
|
|
|
|
if (_is_item_signal(*item)) {
|
|
|
|
signal_menu->set_position(global_position);
|
|
|
|
signal_menu->popup();
|
|
|
|
} else {
|
|
|
|
slot_menu->set_position(global_position);
|
|
|
|
slot_menu->popup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectionsDock::_close() {
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
2018-04-28 02:08:34 +02:00
|
|
|
void ConnectionsDock::_connect_pressed() {
|
2014-02-10 02:10:30 +01:00
|
|
|
TreeItem *item = tree->get_selected();
|
|
|
|
if (!item) {
|
2016-06-04 02:03:09 +02:00
|
|
|
connect_button->set_disabled(true);
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-29 09:03:49 +02:00
|
|
|
if (_is_item_signal(*item)) {
|
|
|
|
_open_connection_dialog(*item);
|
2014-02-10 02:10:30 +01:00
|
|
|
} else {
|
2018-04-29 09:03:49 +02:00
|
|
|
_disconnect(*item);
|
|
|
|
update_tree();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
2015-03-17 04:45:25 +01:00
|
|
|
|
2018-04-29 09:03:49 +02:00
|
|
|
void ConnectionsDock::_notification(int p_what) {
|
|
|
|
if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) {
|
|
|
|
update_tree();
|
2015-03-17 04:45:25 +01:00
|
|
|
}
|
2018-04-29 09:03:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectionsDock::_bind_methods() {
|
|
|
|
ClassDB::bind_method("update_tree", &ConnectionsDock::update_tree);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectionsDock::set_node(Node *p_node) {
|
|
|
|
selectedNode = p_node;
|
|
|
|
update_tree();
|
|
|
|
}
|
2015-03-17 04:45:25 +01:00
|
|
|
|
2016-06-04 02:03:09 +02:00
|
|
|
void ConnectionsDock::update_tree() {
|
2017-03-05 16:44:50 +01:00
|
|
|
tree->clear();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!selectedNode) {
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
TreeItem *root = tree->create_item();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
List<MethodInfo> node_signals;
|
|
|
|
|
2018-04-29 09:03:49 +02:00
|
|
|
selectedNode->get_signal_list(&node_signals);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool did_script = false;
|
2018-04-29 09:03:49 +02:00
|
|
|
StringName base = selectedNode->get_class();
|
2015-03-17 04:45:25 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
while (base) {
|
2019-02-12 21:10:08 +01:00
|
|
|
List<MethodInfo> node_signals2;
|
2019-06-11 20:43:37 +02:00
|
|
|
Ref<Texture2D> icon;
|
2015-06-24 18:29:23 +02:00
|
|
|
String name;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-06-24 18:29:23 +02:00
|
|
|
if (!did_script) {
|
2020-08-08 06:15:46 +02:00
|
|
|
// Get script signals (including signals from any base scripts).
|
2018-04-29 09:03:49 +02:00
|
|
|
Ref<Script> scr = selectedNode->get_script();
|
2015-06-24 18:29:23 +02:00
|
|
|
if (scr.is_valid()) {
|
2019-02-12 21:10:08 +01:00
|
|
|
scr->get_script_signal_list(&node_signals2);
|
2020-05-14 16:41:43 +02:00
|
|
|
if (scr->get_path().is_resource_file()) {
|
2017-03-05 16:44:50 +01:00
|
|
|
name = scr->get_path().get_file();
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
name = scr->get_class();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-03-12 13:37:40 +01:00
|
|
|
if (has_theme_icon(scr->get_class(), "EditorIcons")) {
|
|
|
|
icon = get_theme_icon(scr->get_class(), "EditorIcons");
|
2015-06-24 18:29:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2019-02-12 21:10:08 +01:00
|
|
|
ClassDB::get_signal_list(base, &node_signals2, true);
|
2020-03-12 13:37:40 +01:00
|
|
|
if (has_theme_icon(base, "EditorIcons")) {
|
|
|
|
icon = get_theme_icon(base, "EditorIcons");
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
name = base;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2019-08-17 18:36:16 +02:00
|
|
|
if (!icon.is_valid()) {
|
2020-03-12 13:37:40 +01:00
|
|
|
icon = get_theme_icon("Object", "EditorIcons");
|
2019-08-17 18:36:16 +02:00
|
|
|
}
|
|
|
|
|
2020-08-08 06:15:46 +02:00
|
|
|
TreeItem *section_item = nullptr;
|
2015-06-24 18:29:23 +02:00
|
|
|
|
2020-08-08 06:15:46 +02:00
|
|
|
// Create subsections.
|
2019-02-12 21:10:08 +01:00
|
|
|
if (node_signals2.size()) {
|
2020-08-08 06:15:46 +02:00
|
|
|
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"));
|
2019-02-12 21:10:08 +01:00
|
|
|
node_signals2.sort();
|
2015-06-24 18:29:23 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2019-02-12 21:10:08 +01:00
|
|
|
for (List<MethodInfo>::Element *E = node_signals2.front(); E; E = E->next()) {
|
2017-03-05 16:44:50 +01:00
|
|
|
MethodInfo &mi = E->get();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2019-07-02 15:46:00 +02:00
|
|
|
StringName signal_name = mi.name;
|
|
|
|
String signaldesc = "(";
|
2020-02-17 22:06:54 +01:00
|
|
|
PackedStringArray argnames;
|
2020-08-08 06:15:46 +02:00
|
|
|
|
|
|
|
String filter_text = search_box->get_text();
|
|
|
|
if (!filter_text.is_subsequence_ofi(signal_name)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-06-24 18:29:23 +02:00
|
|
|
if (mi.arguments.size()) {
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < mi.arguments.size(); i++) {
|
2015-06-24 18:29:23 +02:00
|
|
|
PropertyInfo &pi = mi.arguments[i];
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (i > 0) {
|
2017-03-05 16:44:50 +01:00
|
|
|
signaldesc += ", ";
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
String tname = "var";
|
2018-05-30 04:16:59 +02:00
|
|
|
if (pi.type == Variant::OBJECT && pi.class_name != StringName()) {
|
|
|
|
tname = pi.class_name.operator String();
|
|
|
|
} else if (pi.type != Variant::NIL) {
|
2017-03-05 16:44:50 +01:00
|
|
|
tname = Variant::get_type_name(pi.type);
|
2015-06-24 18:29:23 +02:00
|
|
|
}
|
2019-09-26 03:08:58 +02:00
|
|
|
signaldesc += (pi.name == "" ? String("arg " + itos(i)) : pi.name) + ": " + tname;
|
2017-03-05 16:44:50 +01:00
|
|
|
argnames.push_back(pi.name + ":" + tname);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
signaldesc += ")";
|
2015-06-24 18:29:23 +02:00
|
|
|
|
2020-08-08 06:15:46 +02:00
|
|
|
// 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);
|
2015-06-24 18:29:23 +02:00
|
|
|
Dictionary sinfo;
|
2019-07-02 15:46:00 +02:00
|
|
|
sinfo["name"] = signal_name;
|
2017-03-05 16:44:50 +01:00
|
|
|
sinfo["args"] = argnames;
|
2020-08-08 06:15:46 +02:00
|
|
|
signal_item->set_metadata(0, sinfo);
|
|
|
|
signal_item->set_icon(0, get_theme_icon("Signal", "EditorIcons"));
|
2015-06-24 18:29:23 +02:00
|
|
|
|
2019-08-17 18:36:16 +02:00
|
|
|
// Set tooltip with the signal's documentation.
|
2019-07-02 15:46:00 +02:00
|
|
|
{
|
|
|
|
String descr;
|
|
|
|
bool found = false;
|
|
|
|
|
2020-03-17 07:33:00 +01:00
|
|
|
Map<StringName, Map<StringName, String>>::Element *G = descr_cache.find(base);
|
2019-07-02 15:46:00 +02:00
|
|
|
if (G) {
|
|
|
|
Map<StringName, String>::Element *F = G->get().find(signal_name);
|
|
|
|
if (F) {
|
|
|
|
found = true;
|
|
|
|
descr = F->get();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found) {
|
|
|
|
DocData *dd = EditorHelp::get_doc_data();
|
|
|
|
Map<String, DocData::ClassDoc>::Element *F = dd->class_list.find(base);
|
|
|
|
while (F && descr == String()) {
|
|
|
|
for (int i = 0; i < F->get().signals.size(); i++) {
|
|
|
|
if (F->get().signals[i].name == signal_name.operator String()) {
|
2020-05-28 12:02:12 +02:00
|
|
|
descr = DTR(F->get().signals[i].description);
|
2019-07-02 15:46:00 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!F->get().inherits.empty()) {
|
|
|
|
F = dd->class_list.find(F->get().inherits);
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
descr_cache[base][signal_name] = descr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// "::" separators used in make_custom_tooltip for formatting.
|
2020-08-08 06:15:46 +02:00
|
|
|
signal_item->set_tooltip(0, String(signal_name) + "::" + signaldesc + "::" + descr);
|
2019-07-02 15:46:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// List existing connections
|
2015-06-24 18:29:23 +02:00
|
|
|
List<Object::Connection> connections;
|
2019-07-02 15:46:00 +02:00
|
|
|
selectedNode->get_signal_connection_list(signal_name, &connections);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (List<Object::Connection>::Element *F = connections.front(); F; F = F->next()) {
|
2020-02-28 14:32:36 +01:00
|
|
|
Connection cn = F->get();
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!(cn.flags & CONNECT_PERSIST)) {
|
2015-06-24 18:29:23 +02:00
|
|
|
continue;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2020-02-28 14:32:36 +01:00
|
|
|
ConnectDialog::ConnectionData c = cn;
|
2015-06-24 18:29:23 +02:00
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
Node *target = Object::cast_to<Node>(c.target);
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!target) {
|
2015-06-24 18:29:23 +02:00
|
|
|
continue;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-06-24 18:29:23 +02:00
|
|
|
|
2018-04-29 09:03:49 +02:00
|
|
|
String path = String(selectedNode->get_path_to(target)) + " :: " + c.method + "()";
|
2020-05-14 16:41:43 +02:00
|
|
|
if (c.flags & CONNECT_DEFERRED) {
|
2017-03-05 16:44:50 +01:00
|
|
|
path += " (deferred)";
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
|
|
|
if (c.flags & CONNECT_ONESHOT) {
|
2017-03-05 16:44:50 +01:00
|
|
|
path += " (oneshot)";
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-06-24 18:29:23 +02:00
|
|
|
if (c.binds.size()) {
|
2019-09-26 03:08:58 +02:00
|
|
|
path += " binds(";
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < c.binds.size(); i++) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (i > 0) {
|
2017-03-05 16:44:50 +01:00
|
|
|
path += ", ";
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
path += c.binds[i].operator String();
|
2015-06-24 18:29:23 +02:00
|
|
|
}
|
2019-09-26 03:08:58 +02:00
|
|
|
path += ")";
|
2015-06-24 18:29:23 +02:00
|
|
|
}
|
|
|
|
|
2020-08-08 06:15:46 +02:00
|
|
|
TreeItem *connection_item = tree->create_item(signal_item);
|
|
|
|
connection_item->set_text(0, path);
|
2020-02-19 20:27:19 +01:00
|
|
|
Connection cd = c;
|
2020-08-08 06:15:46 +02:00
|
|
|
connection_item->set_metadata(0, cd);
|
|
|
|
connection_item->set_icon(0, get_theme_icon("Slot", "EditorIcons"));
|
2015-06-24 18:29:23 +02:00
|
|
|
}
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-06-24 18:29:23 +02:00
|
|
|
if (!did_script) {
|
2017-03-05 16:44:50 +01:00
|
|
|
did_script = true;
|
2015-06-24 18:29:23 +02:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
base = ClassDB::get_parent_class(base);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-12 15:42:08 +02:00
|
|
|
connect_button->set_text(TTR("Connect..."));
|
2016-06-04 02:03:09 +02:00
|
|
|
connect_button->set_disabled(true);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2016-06-04 02:03:09 +02:00
|
|
|
ConnectionsDock::ConnectionsDock(EditorNode *p_editor) {
|
2017-03-05 16:44:50 +01:00
|
|
|
editor = p_editor;
|
2016-06-04 02:03:09 +02:00
|
|
|
set_name(TTR("Signals"));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-06-04 02:03:09 +02:00
|
|
|
VBoxContainer *vbc = this;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2020-08-08 06:15:46 +02:00
|
|
|
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);
|
|
|
|
|
2019-07-02 15:46:00 +02:00
|
|
|
tree = memnew(ConnectionsDockTree);
|
2014-02-10 02:10:30 +01:00
|
|
|
tree->set_columns(1);
|
|
|
|
tree->set_select_mode(Tree::SELECT_ROW);
|
|
|
|
tree->set_hide_root(true);
|
2016-06-04 02:03:09 +02:00
|
|
|
vbc->add_child(tree);
|
2020-03-06 18:00:16 +01:00
|
|
|
tree->set_v_size_flags(Control::SIZE_EXPAND_FILL);
|
2018-04-28 02:08:34 +02:00
|
|
|
tree->set_allow_rmb_select(true);
|
2016-06-04 02:03:09 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
connect_button = memnew(Button);
|
|
|
|
HBoxContainer *hb = memnew(HBoxContainer);
|
2016-06-04 02:03:09 +02:00
|
|
|
vbc->add_child(hb);
|
|
|
|
hb->add_spacer();
|
|
|
|
hb->add_child(connect_button);
|
2020-02-21 18:28:45 +01:00
|
|
|
connect_button->connect("pressed", callable_mp(this, &ConnectionsDock::_connect_pressed));
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
connect_dialog = memnew(ConnectDialog);
|
2014-02-10 02:10:30 +01:00
|
|
|
add_child(connect_dialog);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2018-04-29 09:03:49 +02:00
|
|
|
disconnect_all_dialog = memnew(ConfirmationDialog);
|
|
|
|
add_child(disconnect_all_dialog);
|
2020-02-21 18:28:45 +01:00
|
|
|
disconnect_all_dialog->connect("confirmed", callable_mp(this, &ConnectionsDock::_disconnect_all));
|
2018-04-29 09:03:49 +02:00
|
|
|
disconnect_all_dialog->set_text(TTR("Are you sure you want to remove all connections from this signal?"));
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2018-04-28 02:08:34 +02:00
|
|
|
signal_menu = memnew(PopupMenu);
|
|
|
|
add_child(signal_menu);
|
2020-02-21 18:28:45 +01:00
|
|
|
signal_menu->connect("id_pressed", callable_mp(this, &ConnectionsDock::_handle_signal_menu_option));
|
2018-04-29 09:03:49 +02:00
|
|
|
signal_menu->add_item(TTR("Connect..."), CONNECT);
|
|
|
|
signal_menu->add_item(TTR("Disconnect All"), DISCONNECT_ALL);
|
2018-04-28 02:08:34 +02:00
|
|
|
|
|
|
|
slot_menu = memnew(PopupMenu);
|
|
|
|
add_child(slot_menu);
|
2020-02-21 18:28:45 +01:00
|
|
|
slot_menu->connect("id_pressed", callable_mp(this, &ConnectionsDock::_handle_slot_menu_option));
|
2018-04-29 09:03:49 +02:00
|
|
|
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);
|
2018-04-28 02:08:34 +02:00
|
|
|
|
2020-02-21 18:28:45 +01:00
|
|
|
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));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-03-12 13:37:40 +01:00
|
|
|
add_theme_constant_override("separation", 3 * EDSCALE);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ConnectionsDock::~ConnectionsDock() {
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|