2023-01-05 13:25:55 +01:00
|
|
|
/**************************************************************************/
|
|
|
|
/* connections_dialog.cpp */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#include "connections_dialog.h"
|
|
|
|
|
2023-01-12 09:41:13 +01:00
|
|
|
#include "core/config/project_settings.h"
|
2023-08-08 11:45:59 +02:00
|
|
|
#include "core/templates/hash_set.h"
|
2020-11-29 04:42:06 +01:00
|
|
|
#include "editor/doc_tools.h"
|
2022-11-19 12:45:49 +01:00
|
|
|
#include "editor/editor_help.h"
|
2023-04-07 18:59:49 +02:00
|
|
|
#include "editor/editor_inspector.h"
|
2022-02-12 02:46:22 +01:00
|
|
|
#include "editor/editor_node.h"
|
|
|
|
#include "editor/editor_scale.h"
|
|
|
|
#include "editor/editor_settings.h"
|
2023-08-13 02:33:39 +02:00
|
|
|
#include "editor/editor_string_names.h"
|
2022-03-25 18:06:46 +01:00
|
|
|
#include "editor/editor_undo_redo_manager.h"
|
2023-04-07 18:59:49 +02:00
|
|
|
#include "editor/gui/scene_tree_editor.h"
|
2021-10-21 15:58:07 +02:00
|
|
|
#include "editor/node_dock.h"
|
2022-02-12 02:46:22 +01:00
|
|
|
#include "editor/scene_tree_dock.h"
|
2016-06-12 01:01:17 +02:00
|
|
|
#include "plugins/script_editor_plugin.h"
|
2023-04-07 18:59:49 +02:00
|
|
|
#include "scene/gui/button.h"
|
|
|
|
#include "scene/gui/check_box.h"
|
|
|
|
#include "scene/gui/label.h"
|
|
|
|
#include "scene/gui/line_edit.h"
|
|
|
|
#include "scene/gui/option_button.h"
|
|
|
|
#include "scene/gui/popup_menu.h"
|
|
|
|
#include "scene/gui/spin_box.h"
|
2022-09-30 12:28:39 +02:00
|
|
|
#include "scene/resources/packed_scene.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-01-03 03:03:46 +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;
|
|
|
|
|
|
|
|
bool _set(const StringName &p_name, const Variant &p_value) {
|
|
|
|
String name = p_name;
|
|
|
|
|
2021-05-12 17:07:53 +02:00
|
|
|
if (name.begins_with("bind/argument_")) {
|
|
|
|
int which = name.get_slice("_", 1).to_int() - 1;
|
2014-02-10 02:10:30 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool _get(const StringName &p_name, Variant &r_ret) const {
|
|
|
|
String name = p_name;
|
|
|
|
|
2021-05-12 17:07:53 +02:00
|
|
|
if (name.begins_with("bind/argument_")) {
|
|
|
|
int which = name.get_slice("_", 1).to_int() - 1;
|
2014-02-10 02:10:30 +01:00
|
|
|
ERR_FAIL_INDEX_V(which, params.size(), false);
|
|
|
|
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 {
|
|
|
|
for (int i = 0; i < params.size(); i++) {
|
2021-05-12 17:07:53 +02:00
|
|
|
p_list->push_back(PropertyInfo(params[i].get_type(), "bind/argument_" + itos(i + 1)));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void notify_changed() {
|
2021-02-10 21:18:45 +01:00
|
|
|
notify_property_list_changed();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
2021-12-09 10:42:46 +01:00
|
|
|
if (method_name.is_empty()) {
|
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
|
|
|
|
2023-04-08 10:31:25 +02:00
|
|
|
if (!TS->is_valid_identifier(method_name.strip_edges())) {
|
2020-06-19 01:21:46 +02:00
|
|
|
error->set_text(TTR("Method name must be a valid identifier."));
|
|
|
|
error->popup_centered();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-04 13:27:08 +02: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;
|
|
|
|
}
|
|
|
|
}
|
2021-07-17 23:22:52 +02:00
|
|
|
emit_signal(SNAME("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.
|
|
|
|
}
|
|
|
|
|
2021-06-16 18:43:34 +02:00
|
|
|
void ConnectDialog::_text_submitted(const String &p_text) {
|
2020-02-27 22:49:16 +01:00
|
|
|
_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);
|
2022-10-06 11:01:29 +02:00
|
|
|
if (!edit_mode) {
|
|
|
|
set_dst_method(generate_method_callback_name(source, signal, current));
|
|
|
|
}
|
2022-09-23 19:13:33 +02:00
|
|
|
_update_method_tree();
|
2020-01-15 18:18:34 +01:00
|
|
|
_update_ok_enabled();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2023-02-04 23:34:14 +01:00
|
|
|
void ConnectDialog::_focus_currently_connected() {
|
|
|
|
tree->set_selected(source);
|
|
|
|
}
|
|
|
|
|
2021-10-01 02:40:07 +02:00
|
|
|
void ConnectDialog::_unbind_count_changed(double p_count) {
|
|
|
|
for (Control *control : bind_controls) {
|
|
|
|
BaseButton *b = Object::cast_to<BaseButton>(control);
|
|
|
|
if (b) {
|
|
|
|
b->set_disabled(p_count > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
EditorInspector *e = Object::cast_to<EditorInspector>(control);
|
|
|
|
if (e) {
|
|
|
|
e->set_read_only(p_count > 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-23 19:13:33 +02:00
|
|
|
void ConnectDialog::_method_selected() {
|
|
|
|
TreeItem *selected_item = method_tree->get_selected();
|
2023-01-29 15:28:07 +01:00
|
|
|
dst_method->set_text(selected_item->get_metadata(0));
|
2022-09-23 19:13:33 +02: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() {
|
2022-04-24 18:38:59 +02:00
|
|
|
Variant::Type type = (Variant::Type)type_list->get_item_id(type_list->get_selected());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Variant value;
|
2022-09-29 11:53:28 +02:00
|
|
|
Callable::CallError err;
|
|
|
|
Variant::construct(type, value, nullptr, 0, err);
|
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();
|
2021-12-09 10:42:46 +01:00
|
|
|
if (st.is_empty()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
int idx = st.get_slice("/", 1).to_int() - 1;
|
|
|
|
|
|
|
|
ERR_FAIL_INDEX(idx, cdbinds->params.size());
|
2021-07-04 00:17:03 +02:00
|
|
|
cdbinds->params.remove_at(idx);
|
2014-02-10 02:10:30 +01:00
|
|
|
cdbinds->notify_changed();
|
|
|
|
}
|
2022-10-06 11:01:29 +02:00
|
|
|
/*
|
|
|
|
* Automatically generates a name for the callback method.
|
|
|
|
*/
|
|
|
|
StringName ConnectDialog::generate_method_callback_name(Node *p_source, String p_signal_name, Node *p_target) {
|
|
|
|
String node_name = p_source->get_name();
|
|
|
|
for (int i = 0; i < node_name.length(); i++) { // TODO: Regex filter may be cleaner.
|
|
|
|
char32_t c = node_name[i];
|
2023-04-08 10:31:25 +02:00
|
|
|
if ((i == 0 && !is_unicode_identifier_start(c)) || (i > 0 && !is_unicode_identifier_continue(c))) {
|
2022-10-06 11:01:29 +02:00
|
|
|
if (c == ' ') {
|
|
|
|
// Replace spaces with underlines.
|
|
|
|
c = '_';
|
|
|
|
} else {
|
|
|
|
// Remove any other characters.
|
|
|
|
node_name.remove_at(i);
|
|
|
|
i--;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
node_name[i] = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
Dictionary subst;
|
|
|
|
subst["NodeName"] = node_name.to_pascal_case();
|
|
|
|
subst["nodeName"] = node_name.to_camel_case();
|
|
|
|
subst["node_name"] = node_name.to_snake_case();
|
|
|
|
|
|
|
|
subst["SignalName"] = p_signal_name.to_pascal_case();
|
|
|
|
subst["signalName"] = p_signal_name.to_camel_case();
|
|
|
|
subst["signal_name"] = p_signal_name.to_snake_case();
|
|
|
|
|
|
|
|
String dst_method;
|
|
|
|
if (p_source == p_target) {
|
2023-01-12 09:41:13 +01:00
|
|
|
dst_method = String(GLOBAL_GET("editor/naming/default_signal_callback_to_self_name")).format(subst);
|
2022-10-06 11:01:29 +02:00
|
|
|
} else {
|
2023-01-12 09:41:13 +01:00
|
|
|
dst_method = String(GLOBAL_GET("editor/naming/default_signal_callback_name")).format(subst);
|
2022-10-06 11:01:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return dst_method;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-09-23 19:13:33 +02:00
|
|
|
void ConnectDialog::_create_method_tree_items(const List<MethodInfo> &p_methods, TreeItem *p_parent_item) {
|
|
|
|
for (const MethodInfo &mi : p_methods) {
|
|
|
|
TreeItem *method_item = method_tree->create_item(p_parent_item);
|
2023-01-29 15:28:07 +01:00
|
|
|
method_item->set_text(0, get_signature(mi));
|
|
|
|
method_item->set_metadata(0, mi.name);
|
2022-09-23 19:13:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
List<MethodInfo> ConnectDialog::_filter_method_list(const List<MethodInfo> &p_methods, const MethodInfo &p_signal, const String &p_search_string) const {
|
|
|
|
bool check_signal = compatible_methods_only->is_pressed();
|
|
|
|
List<MethodInfo> ret;
|
|
|
|
|
|
|
|
for (const MethodInfo &mi : p_methods) {
|
|
|
|
if (!p_search_string.is_empty() && !mi.name.contains(p_search_string)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (check_signal) {
|
|
|
|
if (mi.arguments.size() != p_signal.arguments.size()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool type_mismatch = false;
|
|
|
|
const List<PropertyInfo>::Element *E = p_signal.arguments.front();
|
|
|
|
for (const List<PropertyInfo>::Element *F = mi.arguments.front(); F; F = F->next(), E = E->next()) {
|
|
|
|
Variant::Type stype = E->get().type;
|
|
|
|
Variant::Type mtype = F->get().type;
|
|
|
|
|
|
|
|
if (stype != Variant::NIL && mtype != Variant::NIL && stype != mtype) {
|
|
|
|
type_mismatch = true;
|
|
|
|
break;
|
|
|
|
}
|
2023-01-29 15:28:07 +01:00
|
|
|
|
2023-06-17 03:16:24 +02:00
|
|
|
if (stype == Variant::OBJECT && mtype == Variant::OBJECT && !ClassDB::is_parent_class(E->get().class_name, F->get().class_name)) {
|
2023-01-29 15:28:07 +01:00
|
|
|
type_mismatch = true;
|
|
|
|
break;
|
|
|
|
}
|
2022-09-23 19:13:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (type_mismatch) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ret.push_back(mi);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectDialog::_update_method_tree() {
|
|
|
|
method_tree->clear();
|
|
|
|
|
2023-08-13 02:33:39 +02:00
|
|
|
Color disabled_color = get_theme_color(SNAME("accent_color"), EditorStringName(Editor)) * 0.7;
|
2022-09-23 19:13:33 +02:00
|
|
|
String search_string = method_search->get_text();
|
|
|
|
Node *target = tree->get_selected();
|
|
|
|
if (!target) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MethodInfo signal_info;
|
|
|
|
if (compatible_methods_only->is_pressed()) {
|
|
|
|
List<MethodInfo> signals;
|
|
|
|
source->get_signal_list(&signals);
|
|
|
|
for (const MethodInfo &mi : signals) {
|
|
|
|
if (mi.name == signal) {
|
|
|
|
signal_info = mi;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TreeItem *root_item = method_tree->create_item();
|
|
|
|
root_item->set_text(0, TTR("Methods"));
|
|
|
|
root_item->set_selectable(0, false);
|
|
|
|
|
|
|
|
// If a script is attached, get methods from it.
|
|
|
|
ScriptInstance *si = target->get_script_instance();
|
|
|
|
if (si) {
|
2023-03-06 16:20:30 +01:00
|
|
|
if (si->get_script()->is_built_in()) {
|
|
|
|
si->get_script()->reload();
|
|
|
|
}
|
2022-09-23 19:13:33 +02:00
|
|
|
List<MethodInfo> methods;
|
|
|
|
si->get_method_list(&methods);
|
|
|
|
methods = _filter_method_list(methods, signal_info, search_string);
|
|
|
|
|
2023-04-09 09:40:14 +02:00
|
|
|
if (!methods.is_empty()) {
|
|
|
|
TreeItem *si_item = method_tree->create_item(root_item);
|
|
|
|
si_item->set_text(0, TTR("Attached Script"));
|
2023-08-13 02:33:39 +02:00
|
|
|
si_item->set_icon(0, get_editor_theme_icon(SNAME("Script")));
|
2023-04-09 09:40:14 +02:00
|
|
|
si_item->set_selectable(0, false);
|
|
|
|
|
2022-09-23 19:13:33 +02:00
|
|
|
_create_method_tree_items(methods, si_item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (script_methods_only->is_pressed()) {
|
2023-01-26 00:30:36 +01:00
|
|
|
empty_tree_label->set_visible(root_item->get_first_child() == nullptr);
|
2022-09-23 19:13:33 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-30 14:22:47 +01:00
|
|
|
// Get methods from each class in the hierarchy.
|
2022-09-23 19:13:33 +02:00
|
|
|
StringName current_class = target->get_class_name();
|
|
|
|
do {
|
|
|
|
TreeItem *class_item = method_tree->create_item(root_item);
|
|
|
|
class_item->set_text(0, current_class);
|
2023-08-13 02:33:39 +02:00
|
|
|
Ref<Texture2D> icon = get_editor_theme_icon(SNAME("Node"));
|
|
|
|
if (has_theme_icon(current_class, EditorStringName(EditorIcons))) {
|
|
|
|
icon = get_editor_theme_icon(current_class);
|
2022-09-23 19:13:33 +02:00
|
|
|
}
|
|
|
|
class_item->set_icon(0, icon);
|
|
|
|
class_item->set_selectable(0, false);
|
|
|
|
|
|
|
|
List<MethodInfo> methods;
|
|
|
|
ClassDB::get_method_list(current_class, &methods, true);
|
|
|
|
methods = _filter_method_list(methods, signal_info, search_string);
|
|
|
|
|
|
|
|
if (methods.is_empty()) {
|
|
|
|
class_item->set_custom_color(0, disabled_color);
|
|
|
|
} else {
|
|
|
|
_create_method_tree_items(methods, class_item);
|
|
|
|
}
|
|
|
|
current_class = ClassDB::get_parent_class_nocheck(current_class);
|
|
|
|
} while (current_class != StringName());
|
2023-01-26 00:30:36 +01:00
|
|
|
|
|
|
|
empty_tree_label->set_visible(root_item->get_first_child() == nullptr);
|
2022-09-23 19:13:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectDialog::_method_check_button_pressed(const CheckButton *p_button) {
|
|
|
|
if (p_button == script_methods_only) {
|
|
|
|
EditorSettings::get_singleton()->set_project_metadata("editor_metadata", "show_script_methods_only", p_button->is_pressed());
|
|
|
|
} else if (p_button == compatible_methods_only) {
|
|
|
|
EditorSettings::get_singleton()->set_project_metadata("editor_metadata", "show_compatible_methods_only", p_button->is_pressed());
|
|
|
|
}
|
|
|
|
_update_method_tree();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectDialog::_open_method_popup() {
|
|
|
|
method_popup->popup_centered();
|
|
|
|
method_search->clear();
|
|
|
|
method_search->grab_focus();
|
|
|
|
}
|
|
|
|
|
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) {
|
2020-12-14 19:37:30 +01:00
|
|
|
get_ok_button()->set_disabled(true);
|
2020-01-15 18:18:34 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-09-23 19:13:33 +02:00
|
|
|
if (dst_method->get_text().is_empty()) {
|
2020-12-14 19:37:30 +01:00
|
|
|
get_ok_button()->set_disabled(true);
|
2020-01-15 18:18:34 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-12-14 19:37:30 +01:00
|
|
|
get_ok_button()->set_disabled(false);
|
2020-01-15 18:18:34 +01:00
|
|
|
}
|
|
|
|
|
2018-04-29 09:03:49 +02:00
|
|
|
void ConnectDialog::_notification(int p_what) {
|
2022-02-16 00:52:32 +01:00
|
|
|
switch (p_what) {
|
|
|
|
case NOTIFICATION_ENTER_TREE: {
|
|
|
|
bind_editor->edit(cdbinds);
|
2022-04-24 18:38:59 +02:00
|
|
|
|
2022-08-29 11:04:31 +02:00
|
|
|
[[fallthrough]];
|
|
|
|
}
|
2022-04-24 18:38:59 +02:00
|
|
|
case NOTIFICATION_THEME_CHANGED: {
|
|
|
|
for (int i = 0; i < type_list->get_item_count(); i++) {
|
|
|
|
String type_name = Variant::get_type_name((Variant::Type)type_list->get_item_id(i));
|
2023-08-13 02:33:39 +02:00
|
|
|
type_list->set_item_icon(i, get_editor_theme_icon(type_name));
|
2022-04-24 18:38:59 +02:00
|
|
|
}
|
2022-04-23 19:52:08 +02:00
|
|
|
|
|
|
|
Ref<StyleBox> style = get_theme_stylebox("normal", "LineEdit")->duplicate();
|
|
|
|
if (style.is_valid()) {
|
2023-01-19 17:14:09 +01:00
|
|
|
style->set_content_margin(SIDE_TOP, style->get_content_margin(SIDE_TOP) + 1.0);
|
2022-04-23 19:52:08 +02:00
|
|
|
from_signal->add_theme_style_override("normal", style);
|
|
|
|
}
|
2023-08-13 02:33:39 +02:00
|
|
|
method_search->set_right_icon(get_editor_theme_icon("Search"));
|
|
|
|
open_method_tree->set_icon(get_editor_theme_icon("Edit"));
|
2022-02-16 00:52:32 +01:00
|
|
|
} break;
|
2018-04-29 09:03:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectDialog::_bind_methods() {
|
|
|
|
ADD_SIGNAL(MethodInfo("connected"));
|
|
|
|
}
|
|
|
|
|
|
|
|
Node *ConnectDialog::get_source() const {
|
|
|
|
return source;
|
|
|
|
}
|
|
|
|
|
2023-01-22 21:54:21 +01:00
|
|
|
ConnectDialog::ConnectionData ConnectDialog::get_source_connection_data() const {
|
|
|
|
return source_connection_data;
|
|
|
|
}
|
|
|
|
|
2018-04-29 09:03:49 +02:00
|
|
|
StringName ConnectDialog::get_signal_name() const {
|
|
|
|
return signal;
|
|
|
|
}
|
|
|
|
|
2023-01-22 21:54:21 +01:00
|
|
|
PackedStringArray ConnectDialog::get_signal_args() const {
|
|
|
|
return signal_args;
|
|
|
|
}
|
|
|
|
|
2018-04-29 09:03:49 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void ConnectDialog::set_dst_node(Node *p_node) {
|
|
|
|
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();
|
2022-02-03 17:03:38 +01:00
|
|
|
if (txt.contains("(")) {
|
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;
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void ConnectDialog::set_dst_method(const StringName &p_method) {
|
|
|
|
dst_method->set_text(p_method);
|
|
|
|
}
|
|
|
|
|
2021-10-01 02:40:07 +02:00
|
|
|
int ConnectDialog::get_unbinds() const {
|
|
|
|
return int(unbind_count->get_value());
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2023-01-29 15:28:07 +01:00
|
|
|
String ConnectDialog::get_signature(const MethodInfo &p_method, PackedStringArray *r_arg_names) {
|
|
|
|
PackedStringArray signature;
|
|
|
|
signature.append(p_method.name);
|
|
|
|
signature.append("(");
|
|
|
|
|
|
|
|
for (int i = 0; i < p_method.arguments.size(); i++) {
|
|
|
|
if (i > 0) {
|
|
|
|
signature.append(", ");
|
|
|
|
}
|
|
|
|
|
|
|
|
const PropertyInfo &pi = p_method.arguments[i];
|
|
|
|
String tname = "var";
|
|
|
|
if (pi.type == Variant::OBJECT && pi.class_name != StringName()) {
|
|
|
|
tname = pi.class_name.operator String();
|
|
|
|
} else if (pi.type != Variant::NIL) {
|
|
|
|
tname = Variant::get_type_name(pi.type);
|
|
|
|
}
|
|
|
|
|
|
|
|
signature.append((pi.name.is_empty() ? String("arg " + itos(i)) : pi.name) + ": " + tname);
|
|
|
|
if (r_arg_names) {
|
|
|
|
r_arg_names->push_back(pi.name + ":" + tname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
signature.append(")");
|
|
|
|
return String().join(signature);
|
|
|
|
}
|
|
|
|
|
2018-04-29 09:03:49 +02:00
|
|
|
bool ConnectDialog::get_deferred() const {
|
|
|
|
return deferred->is_pressed();
|
|
|
|
}
|
|
|
|
|
2022-09-01 15:19:23 +02:00
|
|
|
bool ConnectDialog::get_one_shot() const {
|
|
|
|
return one_shot->is_pressed();
|
2018-04-29 09:03:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
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 {
|
2022-01-04 18:24:43 +01:00
|
|
|
return edit_mode;
|
2018-04-29 09:03:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
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.
|
|
|
|
*/
|
2023-01-22 21:54:21 +01:00
|
|
|
void ConnectDialog::init(const ConnectionData &p_cd, const PackedStringArray &p_signal_args, bool p_edit) {
|
2020-01-14 18:58:26 +01:00
|
|
|
set_hide_on_ok(false);
|
|
|
|
|
2022-01-04 18:24:43 +01:00
|
|
|
source = static_cast<Node *>(p_cd.source);
|
|
|
|
signal = p_cd.signal;
|
2023-01-22 21:54:21 +01:00
|
|
|
signal_args = p_signal_args;
|
2018-04-29 09:03:49 +02:00
|
|
|
|
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);
|
|
|
|
|
2022-01-04 18:24:43 +01:00
|
|
|
if (p_cd.target) {
|
|
|
|
set_dst_node(static_cast<Node *>(p_cd.target));
|
|
|
|
set_dst_method(p_cd.method);
|
2019-04-12 04:21:48 +02:00
|
|
|
}
|
2018-04-29 09:03:49 +02:00
|
|
|
|
2020-01-15 18:18:34 +01:00
|
|
|
_update_ok_enabled();
|
|
|
|
|
2022-01-04 18:24:43 +01:00
|
|
|
bool b_deferred = (p_cd.flags & CONNECT_DEFERRED) == CONNECT_DEFERRED;
|
2022-09-01 15:44:42 +02:00
|
|
|
bool b_oneshot = (p_cd.flags & CONNECT_ONE_SHOT) == CONNECT_ONE_SHOT;
|
2018-04-29 09:03:49 +02:00
|
|
|
|
2022-01-04 18:24:43 +01:00
|
|
|
deferred->set_pressed(b_deferred);
|
2022-09-01 15:19:23 +02:00
|
|
|
one_shot->set_pressed(b_oneshot);
|
2022-04-13 01:56:45 +02:00
|
|
|
|
2023-01-22 21:54:21 +01:00
|
|
|
unbind_count->set_max(p_signal_args.size());
|
2022-04-13 01:56:45 +02:00
|
|
|
|
2022-01-04 18:24:43 +01:00
|
|
|
unbind_count->set_value(p_cd.unbinds);
|
|
|
|
_unbind_count_changed(p_cd.unbinds);
|
2018-04-29 09:03:49 +02:00
|
|
|
|
|
|
|
cdbinds->params.clear();
|
2022-01-04 18:24:43 +01:00
|
|
|
cdbinds->params = p_cd.binds;
|
2018-04-29 09:03:49 +02:00
|
|
|
cdbinds->notify_changed();
|
|
|
|
|
2022-01-04 18:24:43 +01:00
|
|
|
edit_mode = p_edit;
|
2023-01-22 21:54:21 +01:00
|
|
|
|
|
|
|
source_connection_data = p_cd;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2023-01-29 15:28:07 +01: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);
|
2023-08-13 02:33:39 +02:00
|
|
|
error_label->add_theme_color_override("font_color", error_label->get_theme_color(SNAME("error_color"), EditorStringName(Editor)));
|
2023-02-04 23:34:14 +01:00
|
|
|
filter_nodes->clear();
|
|
|
|
|
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
|
|
|
|
2022-09-25 17:50:43 +02:00
|
|
|
if (first_popup) {
|
|
|
|
first_popup = false;
|
|
|
|
_advanced_pressed();
|
|
|
|
}
|
2022-10-06 11:01:29 +02:00
|
|
|
|
2019-06-06 04:13:57 +02:00
|
|
|
popup_centered();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectDialog::_advanced_pressed() {
|
|
|
|
if (advanced->is_pressed()) {
|
|
|
|
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 {
|
2021-11-20 09:04:57 +01:00
|
|
|
reset_size();
|
2019-06-06 04:13:57 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-09-25 17:50:43 +02:00
|
|
|
EditorSettings::get_singleton()->set_project_metadata("editor_metadata", "use_advanced_connections", advanced->is_pressed());
|
2020-01-15 18:18:34 +01:00
|
|
|
|
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() {
|
2023-02-01 16:41:23 +01:00
|
|
|
set_min_size(Size2(0, 500) * EDSCALE);
|
2017-01-10 05:49:55 +01:00
|
|
|
|
2016-06-12 01:34:31 +02:00
|
|
|
HBoxContainer *main_hb = memnew(HBoxContainer);
|
2023-02-01 16:41:23 +01:00
|
|
|
add_child(main_hb);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-06-12 01:34:31 +02:00
|
|
|
VBoxContainer *vbc_left = memnew(VBoxContainer);
|
|
|
|
main_hb->add_child(vbc_left);
|
2020-03-06 18:00:16 +01:00
|
|
|
vbc_left->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
2023-02-01 16:41:23 +01:00
|
|
|
vbc_left->set_custom_minimum_size(Vector2(400 * EDSCALE, 0));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2019-04-12 04:21:48 +02:00
|
|
|
from_signal = memnew(LineEdit);
|
2023-01-26 00:30:36 +01:00
|
|
|
vbc_left->add_margin_child(TTR("From Signal:"), from_signal);
|
2019-04-12 04:21:48 +02:00
|
|
|
from_signal->set_editable(false);
|
|
|
|
|
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-11-30 00:37:32 +01:00
|
|
|
tree->set_show_enabled_subscene(true);
|
2023-02-04 23:34:14 +01:00
|
|
|
tree->set_v_size_flags(Control::SIZE_FILL | Control::SIZE_EXPAND);
|
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);
|
|
|
|
|
2023-02-04 23:34:14 +01:00
|
|
|
HBoxContainer *hbc_filter = memnew(HBoxContainer);
|
|
|
|
|
|
|
|
filter_nodes = memnew(LineEdit);
|
|
|
|
hbc_filter->add_child(filter_nodes);
|
|
|
|
filter_nodes->set_h_size_flags(Control::SIZE_FILL | Control::SIZE_EXPAND);
|
|
|
|
filter_nodes->set_placeholder(TTR("Filter Nodes"));
|
|
|
|
filter_nodes->set_clear_button_enabled(true);
|
|
|
|
filter_nodes->connect("text_changed", callable_mp(tree, &SceneTreeEditor::set_filter));
|
|
|
|
|
|
|
|
Button *focus_current = memnew(Button);
|
|
|
|
hbc_filter->add_child(focus_current);
|
|
|
|
focus_current->set_text(TTR("Go to Source"));
|
|
|
|
focus_current->connect("pressed", callable_mp(this, &ConnectDialog::_focus_currently_connected));
|
|
|
|
|
|
|
|
Node *mc = vbc_left->add_margin_child(TTR("Connect to Script:"), hbc_filter, false);
|
2019-04-12 04:21:48 +02:00
|
|
|
connect_to_label = Object::cast_to<Label>(vbc_left->get_child(mc->get_index() - 1));
|
2023-02-04 23:34:14 +01:00
|
|
|
vbc_left->add_child(tree);
|
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
|
|
|
|
2022-09-23 19:13:33 +02:00
|
|
|
method_popup = memnew(AcceptDialog);
|
|
|
|
method_popup->set_title(TTR("Select Method"));
|
|
|
|
method_popup->set_min_size(Vector2(400, 600) * EDSCALE);
|
|
|
|
add_child(method_popup);
|
|
|
|
|
|
|
|
VBoxContainer *method_vbc = memnew(VBoxContainer);
|
|
|
|
method_popup->add_child(method_vbc);
|
|
|
|
|
|
|
|
method_search = memnew(LineEdit);
|
|
|
|
method_vbc->add_child(method_search);
|
|
|
|
method_search->set_placeholder(TTR("Filter Methods"));
|
|
|
|
method_search->set_clear_button_enabled(true);
|
|
|
|
method_search->connect("text_changed", callable_mp(this, &ConnectDialog::_update_method_tree).unbind(1));
|
|
|
|
|
|
|
|
method_tree = memnew(Tree);
|
|
|
|
method_vbc->add_child(method_tree);
|
|
|
|
method_tree->set_v_size_flags(Control::SIZE_EXPAND_FILL);
|
|
|
|
method_tree->set_hide_root(true);
|
|
|
|
method_tree->connect("item_selected", callable_mp(this, &ConnectDialog::_method_selected));
|
|
|
|
method_tree->connect("item_activated", callable_mp((Window *)method_popup, &Window::hide));
|
|
|
|
|
2023-01-26 00:30:36 +01:00
|
|
|
empty_tree_label = memnew(Label(TTR("No method found matching given filters.")));
|
2023-04-09 09:40:14 +02:00
|
|
|
method_popup->add_child(empty_tree_label);
|
|
|
|
empty_tree_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
|
|
|
|
empty_tree_label->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER);
|
|
|
|
empty_tree_label->set_autowrap_mode(TextServer::AUTOWRAP_WORD);
|
2023-01-26 00:30:36 +01:00
|
|
|
|
2022-09-23 19:13:33 +02:00
|
|
|
script_methods_only = memnew(CheckButton(TTR("Script Methods Only")));
|
|
|
|
method_vbc->add_child(script_methods_only);
|
|
|
|
script_methods_only->set_h_size_flags(Control::SIZE_SHRINK_END);
|
|
|
|
script_methods_only->set_pressed(EditorSettings::get_singleton()->get_project_metadata("editor_metadata", "show_script_methods_only", true));
|
|
|
|
script_methods_only->connect("pressed", callable_mp(this, &ConnectDialog::_method_check_button_pressed).bind(script_methods_only));
|
|
|
|
|
|
|
|
compatible_methods_only = memnew(CheckButton(TTR("Compatible Methods Only")));
|
|
|
|
method_vbc->add_child(compatible_methods_only);
|
|
|
|
compatible_methods_only->set_h_size_flags(Control::SIZE_SHRINK_END);
|
|
|
|
compatible_methods_only->set_pressed(EditorSettings::get_singleton()->get_project_metadata("editor_metadata", "show_compatible_methods_only", true));
|
|
|
|
compatible_methods_only->connect("pressed", callable_mp(this, &ConnectDialog::_method_check_button_pressed).bind(compatible_methods_only));
|
|
|
|
|
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);
|
2023-02-01 16:41:23 +01:00
|
|
|
vbc_right->set_custom_minimum_size(Vector2(150 * EDSCALE, 0));
|
2019-04-12 04:21:48 +02:00
|
|
|
vbc_right->hide();
|
2016-06-12 01:34:31 +02:00
|
|
|
|
|
|
|
HBoxContainer *add_bind_hb = memnew(HBoxContainer);
|
2014-02-10 02:10:30 +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);
|
2022-04-24 18:38:59 +02:00
|
|
|
for (int i = 0; i < Variant::VARIANT_MAX; i++) {
|
|
|
|
if (i == Variant::NIL || i == Variant::OBJECT || i == Variant::CALLABLE || i == Variant::SIGNAL || i == Variant::RID) {
|
|
|
|
// These types can't be constructed or serialized properly, so skip them.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
type_list->add_item(Variant::get_type_name(Variant::Type(i)), i);
|
|
|
|
}
|
2021-10-01 02:40:07 +02:00
|
|
|
bind_controls.push_back(type_list);
|
2014-02-10 02:10:30 +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));
|
2021-10-01 02:40:07 +02:00
|
|
|
bind_controls.push_back(add_bind);
|
2014-02-10 02:10:30 +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));
|
2021-10-01 02:40:07 +02:00
|
|
|
bind_controls.push_back(del_bind);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-06-12 01:34:31 +02: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);
|
2021-10-01 02:40:07 +02:00
|
|
|
bind_controls.push_back(bind_editor);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-06-12 01:34:31 +02:00
|
|
|
vbc_right->add_margin_child(TTR("Extra Call Arguments:"), bind_editor, true);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2021-10-01 02:40:07 +02:00
|
|
|
unbind_count = memnew(SpinBox);
|
2022-08-25 12:42:17 +02:00
|
|
|
unbind_count->set_tooltip_text(TTR("Allows to drop arguments sent by signal emitter."));
|
2021-10-01 02:40:07 +02:00
|
|
|
unbind_count->connect("value_changed", callable_mp(this, &ConnectDialog::_unbind_count_changed));
|
|
|
|
|
|
|
|
vbc_right->add_margin_child(TTR("Unbind Signal Arguments:"), unbind_count);
|
|
|
|
|
2022-09-23 19:13:33 +02:00
|
|
|
HBoxContainer *hbc_method = memnew(HBoxContainer);
|
|
|
|
vbc_left->add_margin_child(TTR("Receiver Method:"), hbc_method);
|
|
|
|
|
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);
|
2022-09-23 19:13:33 +02:00
|
|
|
dst_method->connect("text_changed", callable_mp(method_tree, &Tree::deselect_all).unbind(1));
|
2021-06-16 18:43:34 +02:00
|
|
|
dst_method->connect("text_submitted", callable_mp(this, &ConnectDialog::_text_submitted));
|
2022-09-23 19:13:33 +02:00
|
|
|
hbc_method->add_child(dst_method);
|
|
|
|
|
2023-01-26 00:30:36 +01:00
|
|
|
open_method_tree = memnew(Button);
|
|
|
|
hbc_method->add_child(open_method_tree);
|
|
|
|
open_method_tree->set_text("Pick");
|
|
|
|
open_method_tree->connect("pressed", callable_mp(this, &ConnectDialog::_open_method_popup));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2023-01-26 00:30:36 +01:00
|
|
|
advanced = memnew(CheckButton(TTR("Advanced")));
|
2022-04-23 19:52:08 +02:00
|
|
|
vbc_left->add_child(advanced);
|
|
|
|
advanced->set_h_size_flags(Control::SIZE_SHRINK_BEGIN | Control::SIZE_EXPAND);
|
2022-09-25 17:50:43 +02:00
|
|
|
advanced->set_pressed(EditorSettings::get_singleton()->get_project_metadata("editor_metadata", "use_advanced_connections", false));
|
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
|
|
|
|
2022-04-23 19:52:08 +02:00
|
|
|
HBoxContainer *hbox = memnew(HBoxContainer);
|
|
|
|
vbc_right->add_child(hbox);
|
|
|
|
|
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"));
|
2022-08-25 12:42:17 +02:00
|
|
|
deferred->set_tooltip_text(TTR("Defers the signal, storing it in a queue and only firing it at idle time."));
|
2022-04-23 19:52:08 +02:00
|
|
|
hbox->add_child(deferred);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-09-01 15:19:23 +02:00
|
|
|
one_shot = memnew(CheckBox);
|
|
|
|
one_shot->set_h_size_flags(0);
|
2022-04-23 19:52:08 +02:00
|
|
|
one_shot->set_text(TTR("One Shot"));
|
2022-09-01 15:19:23 +02:00
|
|
|
one_shot->set_tooltip_text(TTR("Disconnects the signal after its first emission."));
|
2022-04-23 19:52:08 +02:00
|
|
|
hbox->add_child(one_shot);
|
2015-11-23 21:38:15 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
cdbinds = memnew(ConnectDialogBinds);
|
|
|
|
|
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"));
|
2022-07-08 02:31:19 +02:00
|
|
|
error->set_ok_button_text(TTR("Close"));
|
|
|
|
set_ok_button_text(TTR("Connect"));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ConnectDialog::~ConnectDialog() {
|
|
|
|
memdelete(cdbinds);
|
|
|
|
}
|
|
|
|
|
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 {
|
2023-08-31 21:20:39 +02:00
|
|
|
// `p_text` is expected to be something like this:
|
|
|
|
// - `class|Control||Control brief description.`;
|
|
|
|
// - `signal|gui_input|(event: InputEvent)|gui_input description.`;
|
|
|
|
// - `../../.. :: _on_gui_input()`.
|
|
|
|
// Note that the description can be empty or contain `|`.
|
|
|
|
PackedStringArray slices = p_text.split("|", true, 3);
|
|
|
|
if (slices.size() < 4) {
|
|
|
|
return nullptr; // Use default tooltip instead.
|
|
|
|
}
|
|
|
|
|
|
|
|
String item_type = (slices[0] == "class") ? TTR("Class:") : TTR("Signal:");
|
|
|
|
String item_name = slices[1].strip_edges();
|
|
|
|
String item_params = slices[2].strip_edges();
|
|
|
|
String item_descr = slices[3].strip_edges();
|
|
|
|
|
|
|
|
String text = item_type + " [u][b]" + item_name + "[/b][/u]" + item_params + "\n";
|
|
|
|
if (item_descr.is_empty()) {
|
2022-02-02 14:10:15 +01:00
|
|
|
text += "[i]" + TTR("No description.") + "[/i]";
|
2023-08-31 21:20:39 +02:00
|
|
|
} else {
|
|
|
|
text += item_descr;
|
2022-02-02 14:10:15 +01:00
|
|
|
}
|
2023-08-31 21:20:39 +02:00
|
|
|
|
|
|
|
EditorHelpBit *help_bit = memnew(EditorHelpBit);
|
|
|
|
help_bit->get_rich_text()->set_custom_minimum_size(Size2(360 * EDSCALE, 1));
|
2022-02-02 14:10:15 +01:00
|
|
|
help_bit->set_text(text);
|
|
|
|
|
2019-07-02 15:46:00 +02:00
|
|
|
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
|
|
|
NodePath dst_path = connect_dialog->get_dst_path();
|
2022-01-04 18:24:43 +01:00
|
|
|
Node *target = selected_node->get_node(dst_path);
|
2014-02-10 02:10:30 +01:00
|
|
|
ERR_FAIL_COND(!target);
|
|
|
|
|
2022-01-04 18:24:43 +01:00
|
|
|
ConnectDialog::ConnectionData cd;
|
|
|
|
cd.source = connect_dialog->get_source();
|
|
|
|
cd.target = target;
|
|
|
|
cd.signal = connect_dialog->get_signal_name();
|
|
|
|
cd.method = connect_dialog->get_dst_method_name();
|
|
|
|
cd.unbinds = connect_dialog->get_unbinds();
|
|
|
|
if (cd.unbinds == 0) {
|
|
|
|
cd.binds = connect_dialog->get_binds();
|
2021-10-01 02:40:07 +02:00
|
|
|
}
|
2022-01-04 18:24:43 +01:00
|
|
|
bool b_deferred = connect_dialog->get_deferred();
|
2022-09-01 15:19:23 +02:00
|
|
|
bool b_oneshot = connect_dialog->get_one_shot();
|
2022-09-01 15:44:42 +02:00
|
|
|
cd.flags = CONNECT_PERSIST | (b_deferred ? CONNECT_DEFERRED : 0) | (b_oneshot ? CONNECT_ONE_SHOT : 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;
|
2022-09-29 11:53:28 +02:00
|
|
|
Ref<Script> scr = target->get_script();
|
|
|
|
if (!scr.is_null() && !ClassDB::has_method(target->get_class(), cd.method)) {
|
2019-06-13 17:15:13 +02:00
|
|
|
// There is a chance that the method is inherited from another script.
|
|
|
|
bool found_inherited_function = false;
|
2022-09-29 11:53:28 +02:00
|
|
|
Ref<Script> inherited_scr = scr->get_base_script();
|
|
|
|
while (!inherited_scr.is_null()) {
|
|
|
|
int line = inherited_scr->get_language()->find_function(cd.method, inherited_scr->get_source_code());
|
2019-06-13 17:15:13 +02:00
|
|
|
if (line != -1) {
|
|
|
|
found_inherited_function = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-09-29 11:53:28 +02:00
|
|
|
inherited_scr = inherited_scr->get_base_script();
|
2019-06-13 17:15:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
add_script_function = !found_inherited_function;
|
|
|
|
}
|
2018-07-13 13:58:44 +02:00
|
|
|
|
2018-04-29 00:11:51 +02:00
|
|
|
if (connect_dialog->is_editing()) {
|
2023-01-22 21:54:21 +01:00
|
|
|
_disconnect(connect_dialog->get_source_connection_data());
|
2022-01-04 18:24:43 +01:00
|
|
|
_connect(cd);
|
2018-04-29 09:03:49 +02:00
|
|
|
} else {
|
2022-01-04 18:24:43 +01:00
|
|
|
_connect(cd);
|
2018-04-29 00:11:51 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-07-13 13:58:44 +02:00
|
|
|
if (add_script_function) {
|
2023-01-22 21:54:21 +01:00
|
|
|
PackedStringArray script_function_args = connect_dialog->get_signal_args();
|
|
|
|
script_function_args.resize(script_function_args.size() - cd.unbinds);
|
|
|
|
for (int i = 0; i < cd.binds.size(); i++) {
|
|
|
|
script_function_args.push_back("extra_arg_" + itos(i) + ":" + Variant::get_type_name(cd.binds[i].get_type()));
|
|
|
|
}
|
|
|
|
|
2022-01-27 10:36:51 +01:00
|
|
|
EditorNode::get_singleton()->emit_signal(SNAME("script_add_function_request"), target, cd.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.
|
|
|
|
*/
|
2023-01-22 21:54:21 +01:00
|
|
|
void ConnectionsDock::_connect(const ConnectDialog::ConnectionData &p_cd) {
|
2022-01-04 18:24:43 +01:00
|
|
|
Node *source = Object::cast_to<Node>(p_cd.source);
|
|
|
|
Node *target = Object::cast_to<Node>(p_cd.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
|
|
|
|
2022-01-04 18:24:43 +01:00
|
|
|
Callable callable = p_cd.get_callable();
|
2022-12-23 23:53:16 +01:00
|
|
|
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
|
2022-01-04 18:24:43 +01:00
|
|
|
undo_redo->create_action(vformat(TTR("Connect '%s' to '%s'"), String(p_cd.signal), String(p_cd.method)));
|
2022-07-28 22:56:41 +02:00
|
|
|
undo_redo->add_do_method(source, "connect", p_cd.signal, callable, p_cd.flags);
|
2022-01-04 18:24:43 +01:00
|
|
|
undo_redo->add_undo_method(source, "disconnect", p_cd.signal, callable);
|
2018-04-29 00:11:51 +02:00
|
|
|
undo_redo->add_do_method(this, "update_tree");
|
|
|
|
undo_redo->add_undo_method(this, "update_tree");
|
2021-11-17 21:08:55 +01:00
|
|
|
undo_redo->add_do_method(SceneTreeDock::get_singleton()->get_tree_editor(), "update_tree"); // To force redraw of scene tree.
|
|
|
|
undo_redo->add_undo_method(SceneTreeDock::get_singleton()->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.
|
|
|
|
*/
|
2023-01-22 21:54:21 +01:00
|
|
|
void ConnectionsDock::_disconnect(const ConnectDialog::ConnectionData &p_cd) {
|
|
|
|
ERR_FAIL_COND(p_cd.source != selected_node); // Shouldn't happen but... Bugcheck.
|
2018-04-28 02:08:34 +02:00
|
|
|
|
2022-12-23 23:53:16 +01:00
|
|
|
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
|
2023-01-22 21:54:21 +01:00
|
|
|
undo_redo->create_action(vformat(TTR("Disconnect '%s' from '%s'"), p_cd.signal, p_cd.method));
|
2018-04-29 09:03:49 +02:00
|
|
|
|
2023-01-22 21:54:21 +01:00
|
|
|
Callable callable = p_cd.get_callable();
|
|
|
|
undo_redo->add_do_method(selected_node, "disconnect", p_cd.signal, callable);
|
2023-01-22 22:06:31 +01:00
|
|
|
undo_redo->add_undo_method(selected_node, "connect", p_cd.signal, callable, p_cd.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");
|
2021-11-17 21:08:55 +01:00
|
|
|
undo_redo->add_do_method(SceneTreeDock::get_singleton()->get_tree_editor(), "update_tree"); // To force redraw of scene tree.
|
|
|
|
undo_redo->add_undo_method(SceneTreeDock::get_singleton()->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();
|
2023-08-31 21:20:39 +02:00
|
|
|
if (!item || _get_item_type(*item) != TREE_ITEM_TYPE_SIGNAL) {
|
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
|
|
|
|
2021-03-07 21:07:30 +01:00
|
|
|
TreeItem *child = item->get_first_child();
|
2022-01-04 18:24:43 +01:00
|
|
|
String signal_name = item->get_metadata(0).operator Dictionary()["name"];
|
2022-12-23 23:53:16 +01:00
|
|
|
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
|
2022-01-04 18:24:43 +01:00
|
|
|
undo_redo->create_action(vformat(TTR("Disconnect all from signal: '%s'"), signal_name));
|
2018-04-29 09:03:49 +02:00
|
|
|
|
|
|
|
while (child) {
|
2022-01-04 18:24:43 +01:00
|
|
|
Connection connection = child->get_metadata(0);
|
2022-09-30 12:28:39 +02:00
|
|
|
if (!_is_connection_inherited(connection)) {
|
|
|
|
ConnectDialog::ConnectionData cd = connection;
|
|
|
|
undo_redo->add_do_method(selected_node, "disconnect", cd.signal, cd.get_callable());
|
2023-01-22 22:06:31 +01:00
|
|
|
undo_redo->add_undo_method(selected_node, "connect", cd.signal, cd.get_callable(), cd.flags);
|
2022-09-30 12:28:39 +02:00
|
|
|
}
|
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");
|
2021-11-17 21:08:55 +01:00
|
|
|
undo_redo->add_do_method(SceneTreeDock::get_singleton()->get_tree_editor(), "update_tree");
|
|
|
|
undo_redo->add_undo_method(SceneTreeDock::get_singleton()->get_tree_editor(), "update_tree");
|
2018-04-29 09:03:49 +02:00
|
|
|
|
|
|
|
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();
|
2023-08-31 21:20:39 +02:00
|
|
|
if (item && _get_item_type(*item) == TREE_ITEM_TYPE_SIGNAL) {
|
2018-04-29 09:03:49 +02:00
|
|
|
connect_button->set_text(TTR("Connect..."));
|
2023-08-13 02:33:39 +02:00
|
|
|
connect_button->set_icon(get_editor_theme_icon(SNAME("Instance")));
|
2018-04-29 09:03:49 +02:00
|
|
|
connect_button->set_disabled(false);
|
2023-08-31 21:20:39 +02:00
|
|
|
} else if (item && _get_item_type(*item) == TREE_ITEM_TYPE_CONNECTION) {
|
2018-04-29 09:03:49 +02:00
|
|
|
connect_button->set_text(TTR("Disconnect"));
|
2023-08-13 02:33:39 +02:00
|
|
|
connect_button->set_icon(get_editor_theme_icon(SNAME("Unlinked")));
|
2018-04-29 09:03:49 +02:00
|
|
|
connect_button->set_disabled(false);
|
2023-08-31 21:20:39 +02:00
|
|
|
} else {
|
|
|
|
connect_button->set_text(TTR("Connect..."));
|
2023-08-13 02:33:39 +02:00
|
|
|
connect_button->set_icon(get_editor_theme_icon(SNAME("Instance")));
|
2023-08-31 21:20:39 +02:00
|
|
|
connect_button->set_disabled(true);
|
2018-04-29 09:03:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2023-08-31 21:20:39 +02:00
|
|
|
if (_get_item_type(*item) == TREE_ITEM_TYPE_SIGNAL) {
|
2018-04-29 09:03:49 +02:00
|
|
|
_open_connection_dialog(*item);
|
2023-08-31 21:20:39 +02:00
|
|
|
} else if (_get_item_type(*item) == TREE_ITEM_TYPE_CONNECTION) {
|
|
|
|
_go_to_method(*item);
|
2018-04-29 09:03:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-31 21:20:39 +02:00
|
|
|
ConnectionsDock::TreeItemType ConnectionsDock::_get_item_type(const TreeItem &p_item) const {
|
|
|
|
if (&p_item == tree->get_root()) {
|
|
|
|
return TREE_ITEM_TYPE_ROOT;
|
|
|
|
} else if (p_item.get_parent() == tree->get_root()) {
|
|
|
|
return TREE_ITEM_TYPE_CLASS;
|
|
|
|
} else if (p_item.get_parent()->get_parent() == tree->get_root()) {
|
|
|
|
return TREE_ITEM_TYPE_SIGNAL;
|
|
|
|
} else {
|
|
|
|
return TREE_ITEM_TYPE_CONNECTION;
|
|
|
|
}
|
2018-04-29 09:03:49 +02:00
|
|
|
}
|
|
|
|
|
2022-09-30 12:28:39 +02:00
|
|
|
bool ConnectionsDock::_is_connection_inherited(Connection &p_connection) {
|
2022-12-06 13:50:54 +01:00
|
|
|
return bool(p_connection.flags & CONNECT_INHERITED);
|
2022-09-30 12:28:39 +02:00
|
|
|
}
|
|
|
|
|
2018-04-29 09:03:49 +02:00
|
|
|
/*
|
2019-09-26 03:08:58 +02:00
|
|
|
* Open connection dialog with TreeItem data to CREATE a brand-new connection.
|
|
|
|
*/
|
2022-01-04 18:24:43 +01:00
|
|
|
void ConnectionsDock::_open_connection_dialog(TreeItem &p_item) {
|
2023-01-22 21:54:21 +01:00
|
|
|
Dictionary sinfo = p_item.get_metadata(0);
|
|
|
|
String signal_name = sinfo["name"];
|
|
|
|
PackedStringArray signal_args = sinfo["args"];
|
|
|
|
|
2022-01-04 18:24:43 +01:00
|
|
|
Node *dst_node = selected_node->get_owner() ? selected_node->get_owner() : selected_node;
|
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());
|
|
|
|
}
|
|
|
|
|
2022-01-04 18:24:43 +01:00
|
|
|
ConnectDialog::ConnectionData cd;
|
|
|
|
cd.source = selected_node;
|
2023-01-29 15:28:07 +01:00
|
|
|
cd.signal = StringName(signal_name);
|
2022-01-04 18:24:43 +01:00
|
|
|
cd.target = dst_node;
|
2022-10-06 11:01:29 +02:00
|
|
|
cd.method = ConnectDialog::generate_method_callback_name(cd.source, signal_name, cd.target);
|
2023-01-29 15:28:07 +01:00
|
|
|
connect_dialog->popup_dialog(signal_name + "(" + String(", ").join(signal_args) + ")");
|
2023-01-22 21:54:21 +01:00
|
|
|
connect_dialog->init(cd, signal_args);
|
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.
|
|
|
|
*/
|
2023-01-22 21:54:21 +01:00
|
|
|
void ConnectionsDock::_open_edit_connection_dialog(TreeItem &p_item) {
|
|
|
|
TreeItem *signal_item = p_item.get_parent();
|
|
|
|
ERR_FAIL_COND(!signal_item);
|
|
|
|
|
|
|
|
Connection connection = p_item.get_metadata(0);
|
|
|
|
ConnectDialog::ConnectionData cd = connection;
|
|
|
|
|
|
|
|
Node *src = Object::cast_to<Node>(cd.source);
|
|
|
|
Node *dst = Object::cast_to<Node>(cd.target);
|
2018-04-29 00:11:51 +02:00
|
|
|
|
2018-04-29 09:03:49 +02:00
|
|
|
if (src && dst) {
|
2023-01-22 21:54:21 +01:00
|
|
|
const String &signal_name_ref = cd.signal;
|
|
|
|
PackedStringArray signal_args = signal_item->get_metadata(0).operator Dictionary()["args"];
|
|
|
|
|
|
|
|
connect_dialog->set_title(vformat(TTR("Edit Connection: '%s'"), cd.signal));
|
2022-01-04 18:24:43 +01:00
|
|
|
connect_dialog->popup_dialog(signal_name_ref);
|
2023-01-22 21:54:21 +01:00
|
|
|
connect_dialog->init(cd, signal_args, 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.
|
|
|
|
*/
|
2023-08-31 21:20:39 +02:00
|
|
|
void ConnectionsDock::_go_to_method(TreeItem &p_item) {
|
|
|
|
if (_get_item_type(p_item) != TREE_ITEM_TYPE_CONNECTION) {
|
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
|
|
|
|
2022-01-04 18:24:43 +01:00
|
|
|
Connection connection = p_item.get_metadata(0);
|
|
|
|
ConnectDialog::ConnectionData cd = connection;
|
|
|
|
ERR_FAIL_COND(cd.source != selected_node); // Shouldn't happen but... bugcheck.
|
2018-04-29 09:03:49 +02:00
|
|
|
|
2022-01-04 18:24:43 +01:00
|
|
|
if (!cd.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
|
|
|
|
2022-09-29 11:53:28 +02:00
|
|
|
Ref<Script> scr = cd.target->get_script();
|
2018-04-29 09:03:49 +02:00
|
|
|
|
2022-09-29 11:53:28 +02:00
|
|
|
if (scr.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
|
|
|
|
2022-09-29 11:53:28 +02:00
|
|
|
if (scr.is_valid() && ScriptEditor::get_singleton()->script_goto_method(scr, cd.method)) {
|
2020-12-06 16:09:18 +01:00
|
|
|
EditorNode::get_singleton()->editor_select(EditorNode::EDITOR_SCRIPT);
|
2018-04-29 09:03:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-31 21:20:39 +02:00
|
|
|
void ConnectionsDock::_handle_class_menu_option(int p_option) {
|
|
|
|
switch (p_option) {
|
|
|
|
case CLASS_MENU_OPEN_DOCS:
|
|
|
|
ScriptEditor::get_singleton()->goto_help("class:" + class_menu_doc_class_name);
|
|
|
|
EditorNode::get_singleton()->set_visible_editor(EditorNode::EDITOR_SCRIPT);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectionsDock::_class_menu_about_to_popup() {
|
|
|
|
class_menu->set_item_disabled(class_menu->get_item_index(CLASS_MENU_OPEN_DOCS), class_menu_doc_class_name.is_empty());
|
|
|
|
}
|
|
|
|
|
2022-01-04 18:24:43 +01:00
|
|
|
void ConnectionsDock::_handle_signal_menu_option(int p_option) {
|
2018-04-29 09:03:49 +02:00
|
|
|
TreeItem *item = tree->get_selected();
|
2023-08-31 21:20:39 +02:00
|
|
|
if (!item || _get_item_type(*item) != TREE_ITEM_TYPE_SIGNAL) {
|
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
|
|
|
|
2023-08-28 22:30:09 +02:00
|
|
|
Dictionary meta = item->get_metadata(0);
|
|
|
|
|
2022-01-04 18:24:43 +01:00
|
|
|
switch (p_option) {
|
2023-08-31 21:20:39 +02:00
|
|
|
case SIGNAL_MENU_CONNECT: {
|
2018-04-29 09:03:49 +02:00
|
|
|
_open_connection_dialog(*item);
|
|
|
|
} break;
|
2023-08-31 21:20:39 +02:00
|
|
|
case SIGNAL_MENU_DISCONNECT_ALL: {
|
2023-08-28 22:30:09 +02:00
|
|
|
disconnect_all_dialog->set_text(vformat(TTR("Are you sure you want to remove all connections from the \"%s\" signal?"), meta["name"]));
|
2018-04-29 09:03:49 +02:00
|
|
|
disconnect_all_dialog->popup_centered();
|
|
|
|
} break;
|
2023-08-31 21:20:39 +02:00
|
|
|
case SIGNAL_MENU_COPY_NAME: {
|
2023-08-28 22:30:09 +02:00
|
|
|
DisplayServer::get_singleton()->clipboard_set(meta["name"]);
|
|
|
|
} break;
|
2023-08-31 21:20:39 +02:00
|
|
|
case SIGNAL_MENU_OPEN_DOCS: {
|
2023-08-28 22:30:09 +02:00
|
|
|
ScriptEditor::get_singleton()->goto_help("class_signal:" + String(meta["class"]) + ":" + String(meta["name"]));
|
|
|
|
EditorNode::get_singleton()->set_visible_editor(EditorNode::EDITOR_SCRIPT);
|
2022-08-18 16:08:30 +02:00
|
|
|
} break;
|
2018-04-29 09:03:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-30 12:28:39 +02:00
|
|
|
void ConnectionsDock::_signal_menu_about_to_popup() {
|
2023-08-28 22:30:09 +02:00
|
|
|
TreeItem *item = tree->get_selected();
|
2023-08-31 21:20:39 +02:00
|
|
|
if (!item || _get_item_type(*item) != TREE_ITEM_TYPE_SIGNAL) {
|
2023-08-28 22:30:09 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Dictionary meta = item->get_metadata(0);
|
2022-09-30 12:28:39 +02:00
|
|
|
|
|
|
|
bool disable_disconnect_all = true;
|
2023-08-28 22:30:09 +02:00
|
|
|
for (int i = 0; i < item->get_child_count(); i++) {
|
|
|
|
if (!item->get_child(i)->has_meta("_inherited_connection")) {
|
2022-09-30 12:28:39 +02:00
|
|
|
disable_disconnect_all = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-31 21:20:39 +02:00
|
|
|
signal_menu->set_item_disabled(signal_menu->get_item_index(SIGNAL_MENU_DISCONNECT_ALL), disable_disconnect_all);
|
|
|
|
signal_menu->set_item_disabled(signal_menu->get_item_index(SIGNAL_MENU_OPEN_DOCS), String(meta["class"]).is_empty());
|
2022-09-30 12:28:39 +02:00
|
|
|
}
|
|
|
|
|
2022-01-04 18:24:43 +01:00
|
|
|
void ConnectionsDock::_handle_slot_menu_option(int p_option) {
|
2018-04-29 09:03:49 +02:00
|
|
|
TreeItem *item = tree->get_selected();
|
2023-08-31 21:20:39 +02:00
|
|
|
if (!item || _get_item_type(*item) != TREE_ITEM_TYPE_CONNECTION) {
|
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
|
|
|
|
2022-01-04 18:24:43 +01:00
|
|
|
switch (p_option) {
|
2023-08-31 21:20:39 +02:00
|
|
|
case SLOT_MENU_EDIT: {
|
2023-01-22 21:54:21 +01:00
|
|
|
_open_edit_connection_dialog(*item);
|
2018-04-29 09:03:49 +02:00
|
|
|
} break;
|
2023-08-31 21:20:39 +02:00
|
|
|
case SLOT_MENU_GO_TO_METHOD: {
|
|
|
|
_go_to_method(*item);
|
2018-04-29 09:03:49 +02:00
|
|
|
} break;
|
2023-08-31 21:20:39 +02:00
|
|
|
case SLOT_MENU_DISCONNECT: {
|
2023-01-22 21:54:21 +01:00
|
|
|
Connection connection = item->get_metadata(0);
|
|
|
|
_disconnect(connection);
|
2018-04-29 09:03:49 +02:00
|
|
|
update_tree();
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-30 12:28:39 +02:00
|
|
|
void ConnectionsDock::_slot_menu_about_to_popup() {
|
2023-08-31 21:20:39 +02:00
|
|
|
TreeItem *item = tree->get_selected();
|
|
|
|
if (!item || _get_item_type(*item) != TREE_ITEM_TYPE_CONNECTION) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool connection_is_inherited = item->has_meta("_inherited_connection");
|
2022-09-30 12:28:39 +02:00
|
|
|
|
2023-08-31 21:20:39 +02:00
|
|
|
slot_menu->set_item_disabled(slot_menu->get_item_index(SLOT_MENU_EDIT), connection_is_inherited);
|
|
|
|
slot_menu->set_item_disabled(slot_menu->get_item_index(SLOT_MENU_DISCONNECT), connection_is_inherited);
|
2022-09-30 12:28:39 +02:00
|
|
|
}
|
|
|
|
|
2023-08-31 21:20:39 +02:00
|
|
|
void ConnectionsDock::_rmb_pressed(const Ref<InputEvent> &p_event) {
|
|
|
|
const Ref<InputEventMouseButton> &mb_event = p_event;
|
|
|
|
if (mb_event.is_null() || !mb_event->is_pressed() || mb_event->get_button_index() != MouseButton::RIGHT) {
|
2021-09-18 09:33:18 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-08-31 21:20:39 +02:00
|
|
|
TreeItem *item = tree->get_item_at_position(mb_event->get_position());
|
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
|
|
|
|
2023-08-31 21:20:39 +02:00
|
|
|
Vector2 screen_position = tree->get_screen_position() + mb_event->get_position();
|
2018-04-29 09:03:49 +02:00
|
|
|
|
2023-08-31 21:20:39 +02:00
|
|
|
switch (_get_item_type(*item)) {
|
|
|
|
case TREE_ITEM_TYPE_ROOT:
|
|
|
|
break;
|
|
|
|
case TREE_ITEM_TYPE_CLASS:
|
|
|
|
class_menu_doc_class_name = item->get_metadata(0);
|
|
|
|
class_menu->set_position(screen_position);
|
|
|
|
class_menu->reset_size();
|
|
|
|
class_menu->popup();
|
|
|
|
accept_event(); // Don't collapse item.
|
|
|
|
break;
|
|
|
|
case TREE_ITEM_TYPE_SIGNAL:
|
|
|
|
signal_menu->set_position(screen_position);
|
|
|
|
signal_menu->reset_size();
|
|
|
|
signal_menu->popup();
|
|
|
|
break;
|
|
|
|
case TREE_ITEM_TYPE_CONNECTION:
|
|
|
|
slot_menu->set_position(screen_position);
|
|
|
|
slot_menu->reset_size();
|
|
|
|
slot_menu->popup();
|
|
|
|
break;
|
2018-04-29 09:03:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-08-31 21:20:39 +02:00
|
|
|
if (_get_item_type(*item) == TREE_ITEM_TYPE_SIGNAL) {
|
2018-04-29 09:03:49 +02:00
|
|
|
_open_connection_dialog(*item);
|
2023-08-31 21:20:39 +02:00
|
|
|
} else if (_get_item_type(*item) == TREE_ITEM_TYPE_CONNECTION) {
|
2023-01-22 21:54:21 +01:00
|
|
|
Connection connection = item->get_metadata(0);
|
|
|
|
_disconnect(connection);
|
2018-04-29 09:03:49 +02:00
|
|
|
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) {
|
2022-01-16 08:59:02 +01:00
|
|
|
switch (p_what) {
|
2022-08-29 11:04:31 +02:00
|
|
|
case NOTIFICATION_ENTER_TREE:
|
2022-01-16 08:59:02 +01:00
|
|
|
case NOTIFICATION_THEME_CHANGED: {
|
2023-08-13 02:33:39 +02:00
|
|
|
search_box->set_right_icon(get_editor_theme_icon(SNAME("Search")));
|
2023-08-28 22:30:09 +02:00
|
|
|
|
2023-08-13 02:33:39 +02:00
|
|
|
class_menu->set_item_icon(class_menu->get_item_index(CLASS_MENU_OPEN_DOCS), get_editor_theme_icon(SNAME("Help")));
|
2023-08-31 21:20:39 +02:00
|
|
|
|
2023-08-13 02:33:39 +02:00
|
|
|
signal_menu->set_item_icon(signal_menu->get_item_index(SIGNAL_MENU_CONNECT), get_editor_theme_icon(SNAME("Instance")));
|
|
|
|
signal_menu->set_item_icon(signal_menu->get_item_index(SIGNAL_MENU_DISCONNECT_ALL), get_editor_theme_icon(SNAME("Unlinked")));
|
|
|
|
signal_menu->set_item_icon(signal_menu->get_item_index(SIGNAL_MENU_COPY_NAME), get_editor_theme_icon(SNAME("ActionCopy")));
|
|
|
|
signal_menu->set_item_icon(signal_menu->get_item_index(SIGNAL_MENU_OPEN_DOCS), get_editor_theme_icon(SNAME("Help")));
|
2023-08-28 22:30:09 +02:00
|
|
|
|
2023-08-13 02:33:39 +02:00
|
|
|
slot_menu->set_item_icon(slot_menu->get_item_index(SLOT_MENU_EDIT), get_editor_theme_icon(SNAME("Edit")));
|
|
|
|
slot_menu->set_item_icon(slot_menu->get_item_index(SLOT_MENU_GO_TO_METHOD), get_editor_theme_icon(SNAME("ArrowRight")));
|
|
|
|
slot_menu->set_item_icon(slot_menu->get_item_index(SLOT_MENU_DISCONNECT), get_editor_theme_icon(SNAME("Unlinked")));
|
2022-01-16 08:59:02 +01:00
|
|
|
} break;
|
2022-02-16 00:52:32 +01:00
|
|
|
|
2022-01-16 08:59:02 +01:00
|
|
|
case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
|
|
|
|
update_tree();
|
|
|
|
} break;
|
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) {
|
2022-01-04 18:24:43 +01:00
|
|
|
selected_node = p_node;
|
2018-04-29 09:03:49 +02:00
|
|
|
update_tree();
|
|
|
|
}
|
2015-03-17 04:45:25 +01:00
|
|
|
|
2016-06-04 02:03:09 +02:00
|
|
|
void ConnectionsDock::update_tree() {
|
2023-01-22 19:24:11 +01:00
|
|
|
String prev_selected;
|
|
|
|
if (tree->is_anything_selected()) {
|
|
|
|
prev_selected = tree->get_selected()->get_text(0);
|
|
|
|
}
|
2016-06-04 18:17:56 +02:00
|
|
|
tree->clear();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2022-01-04 18:24:43 +01:00
|
|
|
if (!selected_node) {
|
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
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
TreeItem *root = tree->create_item();
|
2023-08-08 11:45:59 +02:00
|
|
|
DocTools *doc_data = EditorHelp::get_doc_data();
|
|
|
|
EditorData &editor_data = EditorNode::get_editor_data();
|
|
|
|
StringName native_base = selected_node->get_class();
|
|
|
|
Ref<Script> script_base = selected_node->get_script();
|
|
|
|
|
|
|
|
while (native_base != StringName()) {
|
|
|
|
String class_name;
|
|
|
|
String doc_class_name;
|
2023-08-31 21:20:39 +02:00
|
|
|
String class_brief;
|
2023-08-08 11:45:59 +02:00
|
|
|
Ref<Texture2D> class_icon;
|
|
|
|
List<MethodInfo> class_signals;
|
|
|
|
|
|
|
|
if (script_base.is_valid()) {
|
|
|
|
class_name = script_base->get_global_name();
|
|
|
|
if (class_name.is_empty()) {
|
|
|
|
class_name = script_base->get_path().get_file();
|
|
|
|
}
|
2023-08-17 16:44:02 +02:00
|
|
|
|
|
|
|
doc_class_name = script_base->get_global_name();
|
|
|
|
if (doc_class_name.is_empty()) {
|
2023-08-08 11:45:59 +02:00
|
|
|
doc_class_name = script_base->get_path().trim_prefix("res://").quote();
|
2023-08-17 16:44:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// For a script class, the cache is filled each time.
|
|
|
|
if (!doc_class_name.is_empty()) {
|
|
|
|
if (descr_cache.has(doc_class_name)) {
|
|
|
|
descr_cache[doc_class_name].clear();
|
|
|
|
}
|
2023-08-08 11:45:59 +02:00
|
|
|
HashMap<String, DocData::ClassDoc>::ConstIterator F = doc_data->class_list.find(doc_class_name);
|
|
|
|
if (F) {
|
2023-08-31 21:20:39 +02:00
|
|
|
class_brief = F->value.brief_description;
|
2023-08-17 16:44:02 +02:00
|
|
|
for (int i = 0; i < F->value.signals.size(); i++) {
|
|
|
|
descr_cache[doc_class_name][F->value.signals[i].name] = F->value.signals[i].description;
|
|
|
|
}
|
2023-08-28 22:30:09 +02:00
|
|
|
} else {
|
|
|
|
doc_class_name = String();
|
2023-08-08 11:45:59 +02:00
|
|
|
}
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2023-08-08 11:45:59 +02:00
|
|
|
class_icon = editor_data.get_script_icon(script_base);
|
2023-08-13 02:33:39 +02:00
|
|
|
if (class_icon.is_null() && has_theme_icon(native_base, EditorStringName(EditorIcons))) {
|
|
|
|
class_icon = get_editor_theme_icon(native_base);
|
2023-08-08 11:45:59 +02:00
|
|
|
}
|
2015-03-17 04:45:25 +01:00
|
|
|
|
2023-08-08 11:45:59 +02:00
|
|
|
script_base->get_script_signal_list(&class_signals);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2023-08-08 11:45:59 +02:00
|
|
|
// TODO: Core: Add optional parameter to ignore base classes (no_inheritance like in ClassDB).
|
|
|
|
Ref<Script> base = script_base->get_base_script();
|
|
|
|
if (base.is_valid()) {
|
|
|
|
List<MethodInfo> base_signals;
|
|
|
|
base->get_script_signal_list(&base_signals);
|
|
|
|
HashSet<String> base_signal_names;
|
|
|
|
for (List<MethodInfo>::Element *F = base_signals.front(); F; F = F->next()) {
|
|
|
|
base_signal_names.insert(F->get().name);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2023-08-08 11:45:59 +02:00
|
|
|
for (List<MethodInfo>::Element *F = class_signals.front(); F; F = F->next()) {
|
|
|
|
if (base_signal_names.has(F->get().name)) {
|
|
|
|
class_signals.erase(F);
|
|
|
|
}
|
2015-06-24 18:29:23 +02:00
|
|
|
}
|
|
|
|
}
|
2023-08-08 11:45:59 +02:00
|
|
|
|
|
|
|
script_base = base;
|
2015-06-24 18:29:23 +02:00
|
|
|
} else {
|
2023-08-08 11:45:59 +02:00
|
|
|
class_name = native_base;
|
2023-08-17 16:44:02 +02:00
|
|
|
doc_class_name = class_name;
|
|
|
|
|
2023-08-31 21:20:39 +02:00
|
|
|
HashMap<String, DocData::ClassDoc>::ConstIterator F = doc_data->class_list.find(doc_class_name);
|
|
|
|
if (F) {
|
|
|
|
class_brief = DTR(F->value.brief_description);
|
|
|
|
// For a native class, the cache is filled once.
|
|
|
|
if (!descr_cache.has(doc_class_name)) {
|
2023-08-17 16:44:02 +02:00
|
|
|
for (int i = 0; i < F->value.signals.size(); i++) {
|
|
|
|
descr_cache[doc_class_name][F->value.signals[i].name] = DTR(F->value.signals[i].description);
|
|
|
|
}
|
|
|
|
}
|
2023-08-31 21:20:39 +02:00
|
|
|
} else {
|
|
|
|
doc_class_name = String();
|
2023-08-17 16:44:02 +02:00
|
|
|
}
|
2023-08-08 11:45:59 +02:00
|
|
|
|
2023-08-13 02:33:39 +02:00
|
|
|
if (has_theme_icon(native_base, EditorStringName(EditorIcons))) {
|
|
|
|
class_icon = get_editor_theme_icon(native_base);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2023-08-08 11:45:59 +02:00
|
|
|
|
|
|
|
ClassDB::get_signal_list(native_base, &class_signals, true);
|
|
|
|
|
|
|
|
native_base = ClassDB::get_parent_class(native_base);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2023-08-08 11:45:59 +02:00
|
|
|
if (class_icon.is_null()) {
|
2023-08-13 02:33:39 +02:00
|
|
|
class_icon = get_editor_theme_icon(SNAME("Object"));
|
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.
|
2023-08-08 11:45:59 +02:00
|
|
|
if (!class_signals.is_empty()) {
|
|
|
|
class_signals.sort();
|
|
|
|
|
2020-08-08 06:15:46 +02:00
|
|
|
section_item = tree->create_item(root);
|
2023-08-08 11:45:59 +02:00
|
|
|
section_item->set_text(0, class_name);
|
2023-08-31 21:20:39 +02:00
|
|
|
// `|` separators used in `make_custom_tooltip()` for formatting.
|
|
|
|
section_item->set_tooltip_text(0, "class|" + class_name + "||" + class_brief);
|
2023-08-08 11:45:59 +02:00
|
|
|
section_item->set_icon(0, class_icon);
|
2020-08-08 06:15:46 +02:00
|
|
|
section_item->set_selectable(0, false);
|
|
|
|
section_item->set_editable(0, false);
|
2023-08-13 02:33:39 +02:00
|
|
|
section_item->set_custom_bg_color(0, get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor)));
|
2023-08-31 21:20:39 +02:00
|
|
|
section_item->set_metadata(0, doc_class_name);
|
2015-06-24 18:29:23 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2023-08-08 11:45:59 +02:00
|
|
|
for (MethodInfo &mi : class_signals) {
|
2023-08-31 21:20:39 +02:00
|
|
|
const StringName &signal_name = mi.name;
|
2023-01-29 15:28:07 +01:00
|
|
|
if (!search_box->get_text().is_subsequence_ofn(signal_name)) {
|
2020-08-08 06:15:46 +02:00
|
|
|
continue;
|
|
|
|
}
|
2023-01-29 15:28:07 +01:00
|
|
|
PackedStringArray argnames;
|
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);
|
2023-01-29 15:28:07 +01:00
|
|
|
String signame = connect_dialog->get_signature(mi, &argnames);
|
2023-01-22 19:24:11 +01:00
|
|
|
signal_item->set_text(0, signame);
|
|
|
|
|
|
|
|
if (signame == prev_selected) {
|
|
|
|
signal_item->select(0);
|
|
|
|
prev_selected = "";
|
|
|
|
}
|
|
|
|
|
2015-06-24 18:29:23 +02:00
|
|
|
Dictionary sinfo;
|
2023-08-28 22:30:09 +02:00
|
|
|
sinfo["class"] = doc_class_name;
|
2019-07-02 15:46:00 +02:00
|
|
|
sinfo["name"] = signal_name;
|
2015-06-24 18:29:23 +02:00
|
|
|
sinfo["args"] = argnames;
|
2020-08-08 06:15:46 +02:00
|
|
|
signal_item->set_metadata(0, sinfo);
|
2023-08-13 02:33:39 +02:00
|
|
|
signal_item->set_icon(0, get_editor_theme_icon(SNAME("Signal")));
|
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;
|
|
|
|
|
2023-08-08 11:45:59 +02:00
|
|
|
HashMap<StringName, HashMap<StringName, String>>::ConstIterator G = descr_cache.find(doc_class_name);
|
2019-07-02 15:46:00 +02:00
|
|
|
if (G) {
|
2023-08-08 11:45:59 +02:00
|
|
|
HashMap<StringName, String>::ConstIterator F = G->value.find(signal_name);
|
2019-07-02 15:46:00 +02:00
|
|
|
if (F) {
|
2022-05-13 15:04:37 +02:00
|
|
|
descr = F->value;
|
2019-07-02 15:46:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-31 21:20:39 +02:00
|
|
|
// `|` separators used in `make_custom_tooltip()` for formatting.
|
|
|
|
signal_item->set_tooltip_text(0, "signal|" + String(signal_name) + "|" + signame.trim_prefix(mi.name) + "|" + descr);
|
2019-07-02 15:46:00 +02:00
|
|
|
}
|
|
|
|
|
2022-01-04 18:24:43 +01:00
|
|
|
// List existing connections.
|
2022-09-29 11:53:28 +02:00
|
|
|
List<Object::Connection> existing_connections;
|
|
|
|
selected_node->get_signal_connection_list(signal_name, &existing_connections);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-09-29 11:53:28 +02:00
|
|
|
for (const Object::Connection &F : existing_connections) {
|
2022-01-04 18:24:43 +01:00
|
|
|
Connection connection = F;
|
|
|
|
if (!(connection.flags & CONNECT_PERSIST)) {
|
2015-06-24 18:29:23 +02:00
|
|
|
continue;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2022-01-04 18:24:43 +01:00
|
|
|
ConnectDialog::ConnectionData cd = connection;
|
2015-06-24 18:29:23 +02:00
|
|
|
|
2022-01-04 18:24:43 +01:00
|
|
|
Node *target = Object::cast_to<Node>(cd.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
|
|
|
|
2022-01-04 18:24:43 +01:00
|
|
|
String path = String(selected_node->get_path_to(target)) + " :: " + cd.method + "()";
|
|
|
|
if (cd.flags & CONNECT_DEFERRED) {
|
2015-06-24 18:29:23 +02:00
|
|
|
path += " (deferred)";
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2022-09-01 15:44:42 +02:00
|
|
|
if (cd.flags & CONNECT_ONE_SHOT) {
|
|
|
|
path += " (one-shot)";
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2022-01-04 18:24:43 +01:00
|
|
|
if (cd.unbinds > 0) {
|
|
|
|
path += " unbinds(" + itos(cd.unbinds) + ")";
|
|
|
|
} else if (!cd.binds.is_empty()) {
|
2019-09-26 03:08:58 +02:00
|
|
|
path += " binds(";
|
2022-01-04 18:24:43 +01:00
|
|
|
for (int i = 0; i < cd.binds.size(); i++) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (i > 0) {
|
2015-06-24 18:29:23 +02:00
|
|
|
path += ", ";
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2022-01-04 18:24:43 +01:00
|
|
|
path += cd.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);
|
2022-01-04 18:24:43 +01:00
|
|
|
connection_item->set_metadata(0, connection);
|
2023-08-13 02:33:39 +02:00
|
|
|
connection_item->set_icon(0, get_editor_theme_icon(SNAME("Slot")));
|
2022-09-30 12:28:39 +02:00
|
|
|
|
|
|
|
if (_is_connection_inherited(connection)) {
|
|
|
|
// The scene inherits this connection.
|
2023-08-13 02:33:39 +02:00
|
|
|
connection_item->set_custom_color(0, get_theme_color(SNAME("warning_color"), EditorStringName(Editor)));
|
2022-09-30 12:28:39 +02:00
|
|
|
connection_item->set_meta("_inherited_connection", true);
|
|
|
|
}
|
2015-06-24 18:29:23 +02:00
|
|
|
}
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2019-06-12 15:42:08 +02:00
|
|
|
connect_button->set_text(TTR("Connect..."));
|
2023-08-13 02:33:39 +02:00
|
|
|
connect_button->set_icon(get_editor_theme_icon(SNAME("Instance")));
|
2016-06-04 02:03:09 +02:00
|
|
|
connect_button->set_disabled(true);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2022-01-27 10:36:51 +01:00
|
|
|
ConnectionsDock::ConnectionsDock() {
|
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);
|
2022-05-27 06:02:48 +02:00
|
|
|
search_box->set_placeholder(TTR("Filter Signals"));
|
2020-08-08 06:15:46 +02:00
|
|
|
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);
|
2023-01-07 14:05:10 +01:00
|
|
|
tree->set_column_clip_content(0, 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
|
|
|
|
|
|
|
connect_button = memnew(Button);
|
|
|
|
HBoxContainer *hb = memnew(HBoxContainer);
|
|
|
|
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
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
connect_dialog = memnew(ConnectDialog);
|
2021-10-21 15:58:07 +02:00
|
|
|
connect_dialog->connect("connected", callable_mp(NodeDock::get_singleton(), &NodeDock::restore_last_valid_node), CONNECT_DEFERRED);
|
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
|
|
|
|
2023-08-31 21:20:39 +02:00
|
|
|
class_menu = memnew(PopupMenu);
|
|
|
|
class_menu->connect("id_pressed", callable_mp(this, &ConnectionsDock::_handle_class_menu_option));
|
|
|
|
class_menu->connect("about_to_popup", callable_mp(this, &ConnectionsDock::_class_menu_about_to_popup));
|
|
|
|
class_menu->add_item(TTR("Open Documentation"), CLASS_MENU_OPEN_DOCS);
|
|
|
|
add_child(class_menu);
|
|
|
|
|
2018-04-28 02:08:34 +02:00
|
|
|
signal_menu = memnew(PopupMenu);
|
2020-02-21 18:28:45 +01:00
|
|
|
signal_menu->connect("id_pressed", callable_mp(this, &ConnectionsDock::_handle_signal_menu_option));
|
2022-09-30 12:28:39 +02:00
|
|
|
signal_menu->connect("about_to_popup", callable_mp(this, &ConnectionsDock::_signal_menu_about_to_popup));
|
2023-08-31 21:20:39 +02:00
|
|
|
signal_menu->add_item(TTR("Connect..."), SIGNAL_MENU_CONNECT);
|
|
|
|
signal_menu->add_item(TTR("Disconnect All"), SIGNAL_MENU_DISCONNECT_ALL);
|
|
|
|
signal_menu->add_item(TTR("Copy Name"), SIGNAL_MENU_COPY_NAME);
|
2023-08-28 22:30:09 +02:00
|
|
|
signal_menu->add_separator();
|
2023-08-31 21:20:39 +02:00
|
|
|
signal_menu->add_item(TTR("Open Documentation"), SIGNAL_MENU_OPEN_DOCS);
|
|
|
|
add_child(signal_menu);
|
2018-04-28 02:08:34 +02:00
|
|
|
|
|
|
|
slot_menu = memnew(PopupMenu);
|
2020-02-21 18:28:45 +01:00
|
|
|
slot_menu->connect("id_pressed", callable_mp(this, &ConnectionsDock::_handle_slot_menu_option));
|
2022-09-30 12:28:39 +02:00
|
|
|
slot_menu->connect("about_to_popup", callable_mp(this, &ConnectionsDock::_slot_menu_about_to_popup));
|
2023-08-31 21:20:39 +02:00
|
|
|
slot_menu->add_item(TTR("Edit..."), SLOT_MENU_EDIT);
|
|
|
|
slot_menu->add_item(TTR("Go to Method"), SLOT_MENU_GO_TO_METHOD);
|
|
|
|
slot_menu->add_item(TTR("Disconnect"), SLOT_MENU_DISCONNECT);
|
|
|
|
add_child(slot_menu);
|
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));
|
2023-08-31 21:20:39 +02:00
|
|
|
tree->connect("gui_input", callable_mp(this, &ConnectionsDock::_rmb_pressed));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-02-08 10:14:58 +01:00
|
|
|
add_theme_constant_override("separation", 3 * EDSCALE);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2016-06-04 02:03:09 +02:00
|
|
|
ConnectionsDock::~ConnectionsDock() {
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|