2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* connections_dialog.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:11:45 +00:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
2018-01-02 10:27:24 +00:00
|
|
|
/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-02-10 01:10:30 +00: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. */
|
|
|
|
/*************************************************************************/
|
|
|
|
#include "connections_dialog.h"
|
|
|
|
|
|
|
|
#include "scene/gui/label.h"
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "editor_node.h"
|
2017-03-18 23:36:26 +00:00
|
|
|
#include "editor_settings.h"
|
2016-06-11 23:01:17 +00:00
|
|
|
#include "plugins/script_editor_plugin.h"
|
2017-03-18 23:36:26 +00:00
|
|
|
#include "print_string.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
class ConnectDialogBinds : public Object {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
OBJ_TYPE(ConnectDialogBinds, Object);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
public:
|
2014-02-10 01:10:30 +00:00
|
|
|
Vector<Variant> params;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
bool _set(const StringName &p_name, const Variant &p_value) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String name = p_name;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (name.begins_with("bind/")) {
|
2017-03-18 23:36:26 +00:00
|
|
|
int which = name.get_slice("/", 1).to_int() - 1;
|
|
|
|
ERR_FAIL_INDEX_V(which, params.size(), false);
|
|
|
|
params[which] = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
} else
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
bool _get(const StringName &p_name, Variant &r_ret) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String name = p_name;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (name.begins_with("bind/")) {
|
2017-03-18 23:36:26 +00:00
|
|
|
int which = name.get_slice("/", 1).to_int() - 1;
|
|
|
|
ERR_FAIL_INDEX_V(which, params.size(), false);
|
2014-02-10 01:10:30 +00:00
|
|
|
r_ret = params[which];
|
|
|
|
} else
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void _get_property_list(List<PropertyInfo> *p_list) const {
|
|
|
|
|
2017-03-18 23:36:26 +00: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 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void notify_changed() {
|
|
|
|
|
|
|
|
_change_notify();
|
|
|
|
}
|
|
|
|
|
|
|
|
ConnectDialogBinds() {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void ConnectDialog::_notification(int p_what) {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_what == NOTIFICATION_DRAW) {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2016-06-04 00:03:09 +00:00
|
|
|
//RID ci = get_canvas_item();
|
|
|
|
//get_stylebox("panel","PopupMenu")->draw(ci,Rect2(Point2(),get_size()));
|
2016-01-23 22:51:51 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_what == NOTIFICATION_ENTER_TREE) {
|
2016-01-23 22:51:51 +00:00
|
|
|
bind_editor->edit(cdbinds);
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectDialog::_tree_node_selected() {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
//dst_method_list->get_popup()->clear();
|
2017-03-18 23:36:26 +00:00
|
|
|
Node *current = tree->get_selected();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (!current) {
|
|
|
|
make_callback->hide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (current->get_script().is_null())
|
|
|
|
make_callback->hide();
|
|
|
|
else
|
|
|
|
make_callback->show();
|
|
|
|
#if 0
|
|
|
|
List<MethodInfo> methods;
|
|
|
|
current->get_method_list(&methods);
|
|
|
|
for (List<MethodInfo>::Element *E=methods.front();E;E=E->next()) {
|
|
|
|
|
|
|
|
if (E->get().name.length() && E->get().name[0]=='_')
|
|
|
|
continue; // hidden method, not show!
|
|
|
|
|
|
|
|
if (ObjectTypeDB::has_method(node->get_type(),"Node") || ObjectTypeDB::has_method(node->get_type(),"Control",true))
|
|
|
|
continue; //avoid too much unnecesary stuff
|
|
|
|
|
|
|
|
String method=E->get().name+"(";
|
|
|
|
for(int i=0;i<E->get().arguments.size();i++) {
|
|
|
|
|
|
|
|
if (i!=0)
|
|
|
|
method+=", ";
|
|
|
|
method+=Variant::get_type_name(E->get().arguments[i].type);
|
|
|
|
if (E->get().arguments[i].name.length()) {
|
|
|
|
method+=" ";
|
|
|
|
method+=E->get().arguments[i].name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
method+=")";
|
|
|
|
|
|
|
|
//dst_method_list->get_popup()->add_item(method);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
dst_path->set_text(node->get_path_to(current));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectDialog::_dst_method_list_selected(int p_idx) {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
//dst_method->set_text( dst_method_list->get_popup()->get_item_text(p_idx));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectDialog::edit(Node *p_node) {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
node = p_node;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
//dst_method_list->get_popup()->clear();
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
tree->set_selected(NULL);
|
2017-03-18 23:36:26 +00:00
|
|
|
tree->set_marked(node, true);
|
2014-02-10 01:10:30 +00:00
|
|
|
dst_path->set_text("");
|
|
|
|
dst_method->set_text("");
|
|
|
|
deferred->set_pressed(false);
|
2015-11-23 20:38:15 +00:00
|
|
|
oneshot->set_pressed(false);
|
2014-02-10 01:10:30 +00:00
|
|
|
cdbinds->params.clear();
|
|
|
|
cdbinds->notify_changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectDialog::ok_pressed() {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (dst_method->get_text() == "") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-05-04 01:25:37 +00:00
|
|
|
error->set_text(TTR("Method in target Node must be specified!"));
|
2015-04-08 17:02:13 +00:00
|
|
|
error->popup_centered_minsize();
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
Node *target = tree->get_selected();
|
2016-10-04 11:27:08 +00:00
|
|
|
if (target->get_script().is_null()) {
|
|
|
|
if (!target->has_method(dst_method->get_text())) {
|
|
|
|
error->set_text(TTR("Target method not found! Specify a valid method or attach a script to target Node."));
|
|
|
|
error->popup_centered_minsize();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
emit_signal("connected");
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
void ConnectDialog::_cancel_pressed() {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
NodePath ConnectDialog::get_dst_path() const {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
return dst_path->get_text();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ConnectDialog::get_deferred() const {
|
|
|
|
|
|
|
|
return deferred->is_pressed();
|
|
|
|
}
|
|
|
|
|
2015-11-23 20:38:15 +00:00
|
|
|
bool ConnectDialog::get_oneshot() const {
|
|
|
|
|
|
|
|
return oneshot->is_pressed();
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
StringName ConnectDialog::get_dst_method() const {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String txt = dst_method->get_text();
|
|
|
|
if (txt.find("(") != -1)
|
|
|
|
txt = txt.left(txt.find("(")).strip_edges();
|
2016-03-08 23:00:52 +00:00
|
|
|
return txt;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Vector<Variant> ConnectDialog::get_binds() const {
|
|
|
|
|
|
|
|
return cdbinds->params;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectDialog::_add_bind() {
|
|
|
|
|
|
|
|
if (cdbinds->params.size() >= VARIANT_ARG_MAX)
|
|
|
|
return;
|
|
|
|
Variant::Type vt = (Variant::Type)type_list->get_item_ID(type_list->get_selected());
|
|
|
|
|
|
|
|
Variant value;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
switch (vt) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
case Variant::BOOL: value = false; break;
|
2014-02-10 01:10:30 +00:00
|
|
|
case Variant::INT: value = 0; break;
|
|
|
|
case Variant::REAL: value = 0.0; break;
|
|
|
|
case Variant::STRING: value = ""; break;
|
|
|
|
case Variant::VECTOR2: value = Vector2(); break;
|
|
|
|
case Variant::RECT2: value = Rect2(); break;
|
|
|
|
case Variant::VECTOR3: value = Vector3(); break;
|
|
|
|
case Variant::PLANE: value = Plane(); break;
|
|
|
|
case Variant::QUAT: value = Quat(); break;
|
|
|
|
case Variant::_AABB: value = AABB(); break;
|
|
|
|
case Variant::MATRIX3: value = Matrix3(); break;
|
|
|
|
case Variant::TRANSFORM: value = Transform(); break;
|
|
|
|
case Variant::COLOR: value = Color(); break;
|
|
|
|
case Variant::IMAGE: value = Image(); break;
|
|
|
|
|
|
|
|
default: { ERR_FAIL(); } break;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND(value.get_type() == Variant::NIL);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
cdbinds->params.push_back(value);
|
|
|
|
cdbinds->notify_changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectDialog::_remove_bind() {
|
|
|
|
|
|
|
|
String st = bind_editor->get_selected_path();
|
2017-03-18 23:36:26 +00:00
|
|
|
if (st == "")
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
int idx = st.get_slice("/", 1).to_int() - 1;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_INDEX(idx, cdbinds->params.size());
|
2014-02-10 01:10:30 +00:00
|
|
|
cdbinds->params.remove(idx);
|
|
|
|
cdbinds->notify_changed();
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void ConnectDialog::set_dst_node(Node *p_node) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
tree->set_selected(p_node);
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void ConnectDialog::set_dst_method(const StringName &p_method) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
dst_method->set_text(p_method);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectDialog::_bind_methods() {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
//ObjectTypeDB::bind_method("_ok",&ConnectDialog::_ok_pressed);
|
2017-03-18 23:36:26 +00:00
|
|
|
ObjectTypeDB::bind_method("_cancel", &ConnectDialog::_cancel_pressed);
|
2014-02-10 01:10:30 +00:00
|
|
|
//ObjectTypeDB::bind_method("_dst_method_list_selected",&ConnectDialog::_dst_method_list_selected);
|
2017-03-18 23:36:26 +00:00
|
|
|
ObjectTypeDB::bind_method("_tree_node_selected", &ConnectDialog::_tree_node_selected);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ObjectTypeDB::bind_method("_add_bind", &ConnectDialog::_add_bind);
|
|
|
|
ObjectTypeDB::bind_method("_remove_bind", &ConnectDialog::_remove_bind);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ADD_SIGNAL(MethodInfo("connected"));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ConnectDialog::ConnectDialog() {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
VBoxContainer *vbc = memnew(VBoxContainer);
|
2016-06-11 23:34:31 +00:00
|
|
|
add_child(vbc);
|
|
|
|
set_child_rect(vbc);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
HBoxContainer *main_hb = memnew(HBoxContainer);
|
2016-06-11 23:34:31 +00:00
|
|
|
vbc->add_child(main_hb);
|
|
|
|
main_hb->set_v_size_flags(SIZE_EXPAND_FILL);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
VBoxContainer *vbc_left = memnew(VBoxContainer);
|
2016-06-11 23:34:31 +00:00
|
|
|
main_hb->add_child(vbc_left);
|
|
|
|
vbc_left->set_h_size_flags(SIZE_EXPAND_FILL);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
tree = memnew(SceneTreeEditor(false));
|
2017-03-18 23:36:26 +00:00
|
|
|
tree->get_scene_tree()->connect("item_activated", this, "_ok");
|
|
|
|
vbc_left->add_margin_child(TTR("Connect To Node:"), tree, true);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
VBoxContainer *vbc_right = memnew(VBoxContainer);
|
2016-06-11 23:34:31 +00:00
|
|
|
main_hb->add_child(vbc_right);
|
|
|
|
vbc_right->set_h_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
HBoxContainer *add_bind_hb = memnew(HBoxContainer);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
type_list = memnew(OptionButton);
|
2016-06-11 23:34:31 +00:00
|
|
|
type_list->set_h_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
add_bind_hb->add_child(type_list);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
type_list->add_item("bool", Variant::BOOL);
|
|
|
|
type_list->add_item("int", Variant::INT);
|
|
|
|
type_list->add_item("real", Variant::REAL);
|
|
|
|
type_list->add_item("string", Variant::STRING);
|
2014-02-10 01:10:30 +00:00
|
|
|
//type_list->add_separator();
|
2017-03-18 23:36:26 +00: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);
|
|
|
|
type_list->add_item("AABB", Variant::_AABB);
|
|
|
|
type_list->add_item("Matrix3", Variant::MATRIX3);
|
|
|
|
type_list->add_item("Transform", Variant::TRANSFORM);
|
2014-02-10 01:10:30 +00:00
|
|
|
//type_list->add_separator();
|
2017-03-18 23:36:26 +00:00
|
|
|
type_list->add_item("Color", Variant::COLOR);
|
|
|
|
type_list->add_item("Image", Variant::IMAGE);
|
2014-02-10 01:10:30 +00:00
|
|
|
type_list->select(0);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Button *add_bind = memnew(Button);
|
2016-06-11 23:34:31 +00:00
|
|
|
|
2016-05-04 01:25:37 +00:00
|
|
|
add_bind->set_text(TTR("Add"));
|
2016-06-11 23:34:31 +00:00
|
|
|
add_bind_hb->add_child(add_bind);
|
2017-03-18 23:36:26 +00:00
|
|
|
add_bind->connect("pressed", this, "_add_bind");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Button *del_bind = memnew(Button);
|
2016-05-04 01:25:37 +00:00
|
|
|
del_bind->set_text(TTR("Remove"));
|
2016-06-11 23:34:31 +00:00
|
|
|
add_bind_hb->add_child(del_bind);
|
2017-03-18 23:36:26 +00:00
|
|
|
del_bind->connect("pressed", this, "_remove_bind");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
vbc_right->add_margin_child(TTR("Add Extra Call Argument:"), add_bind_hb);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
bind_editor = memnew(PropertyEditor);
|
2016-06-11 23:34:31 +00:00
|
|
|
bind_editor->hide_top_label();
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
vbc_right->add_margin_child(TTR("Extra Call Arguments:"), bind_editor, true);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2016-06-11 23:34:31 +00:00
|
|
|
dst_path = memnew(LineEdit);
|
2017-03-18 23:36:26 +00:00
|
|
|
vbc->add_margin_child(TTR("Path to Node:"), dst_path);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
HBoxContainer *dstm_hb = memnew(HBoxContainer);
|
|
|
|
vbc->add_margin_child("Method In Node:", dstm_hb);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
dst_method = memnew(LineEdit);
|
|
|
|
dst_method->set_h_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
dstm_hb->add_child(dst_method);
|
|
|
|
|
|
|
|
/*dst_method_list = memnew( MenuButton );
|
2016-05-20 23:18:35 +00:00
|
|
|
dst_method_list->set_text("List..");
|
2014-02-10 01:10:30 +00:00
|
|
|
dst_method_list->set_anchor( MARGIN_RIGHT, ANCHOR_END );
|
|
|
|
dst_method_list->set_anchor( MARGIN_LEFT, ANCHOR_END );
|
|
|
|
dst_method_list->set_anchor( MARGIN_TOP, ANCHOR_END );
|
2016-03-08 23:00:52 +00:00
|
|
|
dst_method_list->set_anchor( MARGIN_BOTTOM, ANCHOR_END );
|
2014-02-10 01:10:30 +00:00
|
|
|
dst_method_list->set_begin( Point2( 70,59) );
|
|
|
|
dst_method_list->set_end( Point2( 15,39 ) );
|
|
|
|
*/
|
|
|
|
//add_child(dst_method_list);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
make_callback = memnew(CheckButton);
|
2014-02-10 01:10:30 +00:00
|
|
|
make_callback->set_toggle_mode(true);
|
2017-03-18 23:36:26 +00:00
|
|
|
make_callback->set_pressed(EDITOR_DEF("text_editor/create_signal_callbacks", true));
|
2016-05-18 22:08:12 +00:00
|
|
|
make_callback->set_text(TTR("Make Function"));
|
2014-02-10 01:10:30 +00:00
|
|
|
dstm_hb->add_child(make_callback);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
deferred = memnew(CheckButton);
|
2016-05-04 01:25:37 +00:00
|
|
|
deferred->set_text(TTR("Deferred"));
|
2014-02-10 01:10:30 +00:00
|
|
|
dstm_hb->add_child(deferred);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
oneshot = memnew(CheckButton);
|
2016-05-04 01:25:37 +00:00
|
|
|
oneshot->set_text(TTR("Oneshot"));
|
2015-11-23 20:38:15 +00:00
|
|
|
dstm_hb->add_child(oneshot);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
/*
|
2014-02-10 01:10:30 +00:00
|
|
|
realtime = memnew( CheckButton );
|
|
|
|
realtime->set_anchor( MARGIN_TOP, ANCHOR_END );
|
|
|
|
realtime->set_anchor( MARGIN_BOTTOM, ANCHOR_END );
|
|
|
|
realtime->set_anchor( MARGIN_RIGHT, ANCHOR_END );
|
|
|
|
realtime->set_begin( Point2( 120, button_margin-10 ) );
|
2016-03-08 23:00:52 +00:00
|
|
|
realtime->set_end( Point2( 80, margin ) );
|
2016-05-18 22:08:12 +00:00
|
|
|
realtime->set_text("Realtime");
|
2014-02-10 01:10:30 +00:00
|
|
|
add_child(realtime);
|
|
|
|
*/
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
// dst_method_list->get_popup()->connect("item_pressed", this,"_dst_method_list_selected");
|
|
|
|
tree->connect("node_selected", this, "_tree_node_selected");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
set_as_toplevel(true);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
cdbinds = memnew(ConnectDialogBinds);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
error = memnew(ConfirmationDialog);
|
2014-02-10 01:10:30 +00:00
|
|
|
add_child(error);
|
2016-05-04 01:25:37 +00:00
|
|
|
error->get_ok()->set_text(TTR("Close"));
|
|
|
|
get_ok()->set_text(TTR("Connect"));
|
2017-03-18 23:36:26 +00:00
|
|
|
// error->get_cancel()->set_text("Close");
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ConnectDialog::~ConnectDialog() {
|
|
|
|
memdelete(cdbinds);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2016-06-04 00:03:09 +00:00
|
|
|
void ConnectionsDock::_notification(int p_what) {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_what == NOTIFICATION_DRAW) {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2016-06-04 00:03:09 +00:00
|
|
|
//RID ci = get_canvas_item();
|
|
|
|
//get_stylebox("panel","PopupMenu")->draw(ci,Rect2(Point2(),get_size()));
|
2016-03-08 23:00:52 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2016-06-04 00:03:09 +00:00
|
|
|
void ConnectionsDock::_close() {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
|
|
|
hide();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2016-06-04 00:03:09 +00:00
|
|
|
void ConnectionsDock::_connect() {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
TreeItem *it = tree->get_selected();
|
|
|
|
ERR_FAIL_COND(!it);
|
2017-03-18 23:36:26 +00:00
|
|
|
String signal = it->get_metadata(0).operator Dictionary()["name"];
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
NodePath dst_path = connect_dialog->get_dst_path();
|
2014-02-10 01:10:30 +00:00
|
|
|
Node *target = node->get_node(dst_path);
|
|
|
|
ERR_FAIL_COND(!target);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
StringName dst_method = connect_dialog->get_dst_method();
|
|
|
|
bool defer = connect_dialog->get_deferred();
|
|
|
|
bool oshot = connect_dialog->get_oneshot();
|
2014-02-10 01:10:30 +00:00
|
|
|
Vector<Variant> binds = connect_dialog->get_binds();
|
2017-03-18 23:36:26 +00:00
|
|
|
StringArray args = it->get_metadata(0).operator Dictionary()["args"];
|
|
|
|
int flags = CONNECT_PERSIST | (defer ? CONNECT_DEFERRED : 0) | (oshot ? CONNECT_ONESHOT : 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
undo_redo->create_action(vformat(TTR("Connect '%s' to '%s'"), signal, String(dst_method)));
|
|
|
|
undo_redo->add_do_method(node, "connect", signal, target, dst_method, binds, flags);
|
|
|
|
undo_redo->add_undo_method(node, "disconnect", signal, target, dst_method);
|
|
|
|
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
|
|
|
|
undo_redo->add_undo_method(EditorNode::get_singleton()->get_scene_tree_dock()->get_tree_editor(), "update_tree"); //to force redraw of scene tree
|
2016-06-04 16:17:56 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
undo_redo->commit_action();
|
|
|
|
|
|
|
|
if (connect_dialog->get_make_callback()) {
|
|
|
|
|
|
|
|
print_line("request connect");
|
2017-03-18 23:36:26 +00:00
|
|
|
editor->emit_signal("script_add_function_request", target, dst_method, args);
|
2014-02-10 01:10:30 +00:00
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
update_tree();
|
|
|
|
}
|
|
|
|
|
2016-06-04 00:03:09 +00:00
|
|
|
void ConnectionsDock::_connect_pressed() {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
TreeItem *item = tree->get_selected();
|
|
|
|
if (!item) {
|
|
|
|
//no idea how this happened, but disable
|
2016-06-04 00:03:09 +00:00
|
|
|
connect_button->set_disabled(true);
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
if (item->get_parent() == tree->get_root() || item->get_parent()->get_parent() == tree->get_root()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
//a signal - connect
|
2017-03-18 23:36:26 +00:00
|
|
|
String signal = item->get_metadata(0).operator Dictionary()["name"];
|
|
|
|
String signalname = signal;
|
|
|
|
String midname = node->get_name();
|
|
|
|
for (int i = 0; i < midname.length(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
CharType c = midname[i];
|
2017-03-18 23:36:26 +00:00
|
|
|
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_') {
|
2014-02-10 01:10:30 +00:00
|
|
|
//all good
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (c == ' ') {
|
|
|
|
c = '_';
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
|
|
|
midname.remove(i);
|
|
|
|
i--;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
midname[i] = c;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
connect_dialog->edit(node);
|
|
|
|
connect_dialog->popup_centered_ratio();
|
2017-03-18 23:36:26 +00:00
|
|
|
connect_dialog->set_title(TTR("Connecting Signal:") + " " + signalname);
|
|
|
|
connect_dialog->set_dst_method("_on_" + midname + "_" + signal);
|
|
|
|
connect_dialog->set_dst_node(node->get_owner() ? node->get_owner() : node);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
//a slot- disconnect
|
2017-03-18 23:36:26 +00:00
|
|
|
Connection c = item->get_metadata(0);
|
|
|
|
ERR_FAIL_COND(c.source != node); //shouldn't happen but...bugcheck
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-05-04 01:25:37 +00:00
|
|
|
undo_redo->create_action(TTR("Create Subscription"));
|
2017-03-18 23:36:26 +00:00
|
|
|
undo_redo->add_do_method(node, "disconnect", c.signal, c.target, c.method);
|
|
|
|
undo_redo->add_undo_method(node, "connect", c.signal, c.target, c.method, Vector<Variant>(), c.flags);
|
|
|
|
undo_redo->add_do_method(this, "update_tree");
|
|
|
|
undo_redo->add_undo_method(this, "update_tree");
|
|
|
|
undo_redo->add_do_method(EditorNode::get_singleton()->get_scene_tree_dock()->get_tree_editor(), "update_tree"); //to force redraw of scene tree
|
|
|
|
undo_redo->add_undo_method(EditorNode::get_singleton()->get_scene_tree_dock()->get_tree_editor(), "update_tree"); //to force redraw of scene tree
|
2014-02-10 01:10:30 +00:00
|
|
|
undo_redo->commit_action();
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
c.source->disconnect(c.signal, c.target, c.method);
|
2014-02-10 01:10:30 +00:00
|
|
|
update_tree();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
2016-06-04 00:03:09 +00:00
|
|
|
void ConnectionsDock::_remove() {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
if (!tree->get_selected())
|
|
|
|
return;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
TreeItem *selected=tree->get_selected();
|
|
|
|
if (!selected)
|
|
|
|
return;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
Dictionary meta=selected->get_metadata(0);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
remove_confirm->set_text(String()+"Remove Connection \""+meta["from_event"].operator String()+"\" ?");
|
|
|
|
remove_confirm->popup_centered(Size2(340,80));
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
/*
|
2016-06-04 00:03:09 +00:00
|
|
|
void ConnectionsDock::_remove_confirm() {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
if (!tree->get_selected())
|
|
|
|
return;
|
|
|
|
TreeItem *selected=tree->get_selected();
|
|
|
|
if (!selected)
|
|
|
|
return;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
Dictionary meta=selected->get_metadata(0);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2016-05-20 23:18:35 +00:00
|
|
|
undo_redo->create_action("Remove Subscription");
|
2014-02-10 01:10:30 +00:00
|
|
|
undo_redo->add_do_method(node,"unsubscribe_path_event",meta["from_event"].operator String(),meta["from_path"].operator NodePath(),meta["to_method"].operator String());
|
|
|
|
undo_redo->add_undo_method(node,"subscribe_path_event_persist",meta["from_event"].operator String(),meta["from_path"].operator NodePath(),meta["to_method"].operator String(),Array(),false);
|
|
|
|
undo_redo->add_do_method(this,"update_tree");
|
|
|
|
undo_redo->add_undo_method(this,"update_tree");
|
|
|
|
undo_redo->commit_action();
|
|
|
|
|
|
|
|
}
|
|
|
|
*/
|
2015-03-17 03:45:25 +00:00
|
|
|
|
2016-06-04 00:03:09 +00:00
|
|
|
struct _ConnectionsDockMethodInfoSort {
|
2015-03-17 03:45:25 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
_FORCE_INLINE_ bool operator()(const MethodInfo &a, const MethodInfo &b) const {
|
2015-03-17 03:45:25 +00:00
|
|
|
return a.name < b.name;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-06-04 00:03:09 +00:00
|
|
|
void ConnectionsDock::update_tree() {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
tree->clear();
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
if (!node)
|
|
|
|
return;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
TreeItem *root = tree->create_item();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
List<MethodInfo> node_signals;
|
|
|
|
|
|
|
|
node->get_signal_list(&node_signals);
|
|
|
|
|
2016-06-04 00:03:09 +00:00
|
|
|
//node_signals.sort_custom<_ConnectionsDockMethodInfoSort>();
|
2017-03-18 23:36:26 +00:00
|
|
|
bool did_script = false;
|
2015-06-24 16:29:23 +00:00
|
|
|
StringName base = node->get_type();
|
2015-03-17 03:45:25 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
while (base) {
|
2015-06-24 16:29:23 +00:00
|
|
|
|
|
|
|
List<MethodInfo> node_signals;
|
|
|
|
Ref<Texture> icon;
|
|
|
|
String name;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-06-24 16:29:23 +00:00
|
|
|
if (!did_script) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-06-24 16:29:23 +00:00
|
|
|
Ref<Script> scr = node->get_script();
|
|
|
|
if (scr.is_valid()) {
|
|
|
|
scr->get_script_signal_list(&node_signals);
|
|
|
|
if (scr->get_path().is_resource_file())
|
2017-03-18 23:36:26 +00:00
|
|
|
name = scr->get_path().get_file();
|
2015-06-24 16:29:23 +00:00
|
|
|
else
|
2017-03-18 23:36:26 +00:00
|
|
|
name = scr->get_type();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (has_icon(scr->get_type(), "EditorIcons")) {
|
|
|
|
icon = get_icon(scr->get_type(), "EditorIcons");
|
2015-06-24 16:29:23 +00:00
|
|
|
}
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-06-24 16:29:23 +00:00
|
|
|
} else {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ObjectTypeDB::get_signal_list(base, &node_signals, true);
|
|
|
|
if (has_icon(base, "EditorIcons")) {
|
|
|
|
icon = get_icon(base, "EditorIcons");
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
name = base;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2015-06-24 16:29:23 +00:00
|
|
|
TreeItem *pitem = NULL;
|
|
|
|
|
|
|
|
if (node_signals.size()) {
|
2017-03-18 23:36:26 +00:00
|
|
|
pitem = tree->create_item(root);
|
|
|
|
pitem->set_text(0, name);
|
|
|
|
pitem->set_icon(0, icon);
|
|
|
|
pitem->set_selectable(0, false);
|
|
|
|
pitem->set_editable(0, false);
|
|
|
|
pitem->set_custom_bg_color(0, get_color("prop_subsection", "Editor"));
|
2015-06-24 16:29:23 +00:00
|
|
|
node_signals.sort();
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (List<MethodInfo>::Element *E = node_signals.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
MethodInfo &mi = E->get();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-06-24 16:29:23 +00:00
|
|
|
String signaldesc;
|
2017-03-18 23:36:26 +00:00
|
|
|
signaldesc = mi.name + "(";
|
2015-06-24 16:29:23 +00:00
|
|
|
StringArray argnames;
|
|
|
|
if (mi.arguments.size()) {
|
2017-03-18 23:36:26 +00:00
|
|
|
signaldesc += " ";
|
|
|
|
for (int i = 0; i < mi.arguments.size(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-06-24 16:29:23 +00:00
|
|
|
PropertyInfo &pi = mi.arguments[i];
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (i > 0)
|
|
|
|
signaldesc += ", ";
|
|
|
|
String tname = "var";
|
|
|
|
if (pi.type != Variant::NIL) {
|
|
|
|
tname = Variant::get_type_name(pi.type);
|
2015-06-24 16:29:23 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
signaldesc += tname + " " + (pi.name == "" ? String("arg " + itos(i)) : pi.name);
|
2015-06-24 16:29:23 +00:00
|
|
|
argnames.push_back(pi.name);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
signaldesc += " ";
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
signaldesc += ")";
|
2015-06-24 16:29:23 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
TreeItem *item = tree->create_item(pitem);
|
|
|
|
item->set_text(0, signaldesc);
|
2015-06-24 16:29:23 +00:00
|
|
|
Dictionary sinfo;
|
2017-03-18 23:36:26 +00:00
|
|
|
sinfo["name"] = mi.name;
|
|
|
|
sinfo["args"] = argnames;
|
|
|
|
item->set_metadata(0, sinfo);
|
|
|
|
item->set_icon(0, get_icon("Signal", "EditorIcons"));
|
2015-06-24 16:29:23 +00:00
|
|
|
|
|
|
|
List<Object::Connection> connections;
|
2017-03-18 23:36:26 +00:00
|
|
|
node->get_signal_connection_list(mi.name, &connections);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (List<Object::Connection>::Element *F = connections.front(); F; F = F->next()) {
|
2015-06-24 16:29:23 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Object::Connection &c = F->get();
|
|
|
|
if (!(c.flags & CONNECT_PERSIST))
|
2015-06-24 16:29:23 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
Node *target = c.target->cast_to<Node>();
|
|
|
|
if (!target)
|
|
|
|
continue;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String path = String(node->get_path_to(target)) + " :: " + c.method + "()";
|
|
|
|
if (c.flags & CONNECT_DEFERRED)
|
|
|
|
path += " (deferred)";
|
|
|
|
if (c.flags & CONNECT_ONESHOT)
|
|
|
|
path += " (oneshot)";
|
2015-06-24 16:29:23 +00:00
|
|
|
if (c.binds.size()) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
path += " binds( ";
|
|
|
|
for (int i = 0; i < c.binds.size(); i++) {
|
2015-06-24 16:29:23 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (i > 0)
|
|
|
|
path += ", ";
|
|
|
|
path += c.binds[i].operator String();
|
2015-06-24 16:29:23 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
path += " )";
|
2015-06-24 16:29:23 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
TreeItem *item2 = tree->create_item(item);
|
|
|
|
item2->set_text(0, path);
|
|
|
|
item2->set_metadata(0, c);
|
|
|
|
item2->set_icon(0, get_icon("Slot", "EditorIcons"));
|
2015-06-24 16:29:23 +00:00
|
|
|
}
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-06-24 16:29:23 +00:00
|
|
|
if (!did_script) {
|
2017-03-18 23:36:26 +00:00
|
|
|
did_script = true;
|
2015-06-24 16:29:23 +00:00
|
|
|
} else {
|
2017-03-18 23:36:26 +00:00
|
|
|
base = ObjectTypeDB::type_inherits_from(base);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-04 00:03:09 +00:00
|
|
|
connect_button->set_text(TTR("Connect"));
|
|
|
|
connect_button->set_disabled(true);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void ConnectionsDock::set_node(Node *p_node) {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
node = p_node;
|
2014-02-10 01:10:30 +00:00
|
|
|
update_tree();
|
|
|
|
}
|
|
|
|
|
2016-06-04 00:03:09 +00:00
|
|
|
void ConnectionsDock::_something_selected() {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
TreeItem *item = tree->get_selected();
|
|
|
|
if (!item) {
|
|
|
|
//no idea how this happened, but disable
|
2016-06-04 00:03:09 +00:00
|
|
|
connect_button->set_text(TTR("Connect.."));
|
|
|
|
connect_button->set_disabled(true);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (item->get_parent() == tree->get_root() || item->get_parent()->get_parent() == tree->get_root()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
//a signal - connect
|
2016-06-04 00:03:09 +00:00
|
|
|
connect_button->set_text(TTR("Connect.."));
|
|
|
|
connect_button->set_disabled(false);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
//a slot- disconnect
|
2016-06-04 00:03:09 +00:00
|
|
|
connect_button->set_text(TTR("Disconnect"));
|
|
|
|
connect_button->set_disabled(false);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-11 23:01:17 +00:00
|
|
|
void ConnectionsDock::_something_activated() {
|
|
|
|
|
|
|
|
TreeItem *item = tree->get_selected();
|
|
|
|
|
|
|
|
if (!item)
|
|
|
|
return;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (item->get_parent() == tree->get_root() || item->get_parent()->get_parent() == tree->get_root()) {
|
2016-06-11 23:01:17 +00:00
|
|
|
// a signal - connect
|
2017-03-18 23:36:26 +00:00
|
|
|
String signal = item->get_metadata(0).operator Dictionary()["name"];
|
|
|
|
String midname = node->get_name();
|
|
|
|
for (int i = 0; i < midname.length(); i++) {
|
2016-06-11 23:01:17 +00:00
|
|
|
CharType c = midname[i];
|
2017-03-18 23:36:26 +00:00
|
|
|
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_') {
|
2016-06-11 23:01:17 +00:00
|
|
|
//all good
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (c == ' ') {
|
|
|
|
c = '_';
|
2016-06-11 23:01:17 +00:00
|
|
|
} else {
|
|
|
|
midname.remove(i);
|
|
|
|
i--;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
midname[i] = c;
|
2016-06-11 23:01:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
connect_dialog->edit(node);
|
|
|
|
connect_dialog->popup_centered_ratio();
|
2017-03-18 23:36:26 +00:00
|
|
|
connect_dialog->set_dst_method("_on_" + midname + "_" + signal);
|
|
|
|
connect_dialog->set_dst_node(node->get_owner() ? node->get_owner() : node);
|
2016-06-11 23:01:17 +00:00
|
|
|
} else {
|
|
|
|
// a slot - go to target method
|
2017-03-18 23:36:26 +00:00
|
|
|
Connection c = item->get_metadata(0);
|
|
|
|
ERR_FAIL_COND(c.source != node); //shouldn't happen but...bugcheck
|
2016-06-11 23:01:17 +00:00
|
|
|
|
|
|
|
if (!c.target)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Ref<Script> script = c.target->get_script();
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (script.is_valid() && ScriptEditor::get_singleton()->script_go_to_method(script, c.method)) {
|
|
|
|
editor->call("_editor_select", EditorNode::EDITOR_SCRIPT);
|
2016-06-11 23:01:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-04 00:03:09 +00:00
|
|
|
void ConnectionsDock::_bind_methods() {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ObjectTypeDB::bind_method("_connect", &ConnectionsDock::_connect);
|
|
|
|
ObjectTypeDB::bind_method("_something_selected", &ConnectionsDock::_something_selected);
|
|
|
|
ObjectTypeDB::bind_method("_something_activated", &ConnectionsDock::_something_activated);
|
|
|
|
ObjectTypeDB::bind_method("_close", &ConnectionsDock::_close);
|
|
|
|
ObjectTypeDB::bind_method("_connect_pressed", &ConnectionsDock::_connect_pressed);
|
|
|
|
ObjectTypeDB::bind_method("update_tree", &ConnectionsDock::update_tree);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2016-06-04 00:03:09 +00:00
|
|
|
ConnectionsDock::ConnectionsDock(EditorNode *p_editor) {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
editor = p_editor;
|
2016-06-04 00:03:09 +00:00
|
|
|
set_name(TTR("Signals"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-06-04 00:03:09 +00:00
|
|
|
VBoxContainer *vbc = this;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
tree = memnew(Tree);
|
2014-02-10 01:10:30 +00:00
|
|
|
tree->set_columns(1);
|
|
|
|
tree->set_select_mode(Tree::SELECT_ROW);
|
|
|
|
tree->set_hide_root(true);
|
2016-06-04 00:03:09 +00:00
|
|
|
vbc->add_child(tree);
|
|
|
|
tree->set_v_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
connect_button = memnew(Button);
|
2016-06-04 00:03:09 +00:00
|
|
|
connect_button->set_text("Connect");
|
2017-03-18 23:36:26 +00:00
|
|
|
HBoxContainer *hb = memnew(HBoxContainer);
|
2016-06-04 00:03:09 +00:00
|
|
|
vbc->add_child(hb);
|
|
|
|
hb->add_spacer();
|
|
|
|
hb->add_child(connect_button);
|
2017-03-18 23:36:26 +00:00
|
|
|
connect_button->connect("pressed", this, "_connect_pressed");
|
|
|
|
// add_child(tree);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
connect_dialog = memnew(ConnectDialog);
|
2014-02-10 01:10:30 +00:00
|
|
|
connect_dialog->set_as_toplevel(true);
|
|
|
|
add_child(connect_dialog);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
remove_confirm = memnew(ConfirmationDialog);
|
2014-02-10 01:10:30 +00:00
|
|
|
remove_confirm->set_as_toplevel(true);
|
|
|
|
add_child(remove_confirm);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
|
|
|
/*
|
2014-02-10 01:10:30 +00:00
|
|
|
node_only->set_anchor( MARGIN_TOP, ANCHOR_END );
|
|
|
|
node_only->set_anchor( MARGIN_BOTTOM, ANCHOR_END );
|
|
|
|
node_only->set_anchor( MARGIN_RIGHT, ANCHOR_END );
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
node_only->set_begin( Point2( 20,51) );
|
|
|
|
node_only->set_end( Point2( 10,44) );
|
|
|
|
*/
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
remove_confirm->connect("confirmed", this, "_remove_confirm");
|
|
|
|
connect_dialog->connect("connected", this, "_connect");
|
|
|
|
tree->connect("item_selected", this, "_something_selected");
|
|
|
|
tree->connect("item_activated", this, "_something_activated");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
add_constant_override("separation", 3 * EDSCALE);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ConnectionsDock::~ConnectionsDock() {
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|