VisualScriptEditor Fix in graph position calculation (do not skip zoom)
This commit is contained in:
parent
9ace46a7d2
commit
921e6efe0d
2 changed files with 48 additions and 107 deletions
|
@ -1300,7 +1300,7 @@ void VisualScriptEditor::_create_function_dialog() {
|
||||||
void VisualScriptEditor::_create_function() {
|
void VisualScriptEditor::_create_function() {
|
||||||
String name = _validate_name((func_name_box->get_text() == "") ? "new_func" : func_name_box->get_text());
|
String name = _validate_name((func_name_box->get_text() == "") ? "new_func" : func_name_box->get_text());
|
||||||
selected = name;
|
selected = name;
|
||||||
Vector2 ofs = _get_available_pos();
|
Vector2 pos = _get_available_pos();
|
||||||
|
|
||||||
Ref<VisualScriptFunction> func_node;
|
Ref<VisualScriptFunction> func_node;
|
||||||
func_node.instantiate();
|
func_node.instantiate();
|
||||||
|
@ -1322,7 +1322,7 @@ void VisualScriptEditor::_create_function() {
|
||||||
undo_redo->create_action(TTR("Add Function"));
|
undo_redo->create_action(TTR("Add Function"));
|
||||||
undo_redo->add_do_method(script.ptr(), "add_function", name, func_node_id);
|
undo_redo->add_do_method(script.ptr(), "add_function", name, func_node_id);
|
||||||
undo_redo->add_undo_method(script.ptr(), "remove_function", name);
|
undo_redo->add_undo_method(script.ptr(), "remove_function", name);
|
||||||
undo_redo->add_do_method(script.ptr(), "add_node", func_node_id, func_node, ofs);
|
undo_redo->add_do_method(script.ptr(), "add_node", func_node_id, func_node, pos);
|
||||||
undo_redo->add_undo_method(script.ptr(), "remove_node", func_node_id);
|
undo_redo->add_undo_method(script.ptr(), "remove_node", func_node_id);
|
||||||
undo_redo->add_do_method(this, "_update_members");
|
undo_redo->add_do_method(this, "_update_members");
|
||||||
undo_redo->add_undo_method(this, "_update_members");
|
undo_redo->add_undo_method(this, "_update_members");
|
||||||
|
@ -1417,7 +1417,7 @@ void VisualScriptEditor::_member_button(Object *p_item, int p_column, int p_butt
|
||||||
} else if (p_button == 0) {
|
} else if (p_button == 0) {
|
||||||
String name = _validate_name("new_function");
|
String name = _validate_name("new_function");
|
||||||
selected = name;
|
selected = name;
|
||||||
Vector2 ofs = _get_available_pos();
|
Vector2 pos = _get_available_pos();
|
||||||
|
|
||||||
Ref<VisualScriptFunction> func_node;
|
Ref<VisualScriptFunction> func_node;
|
||||||
func_node.instantiate();
|
func_node.instantiate();
|
||||||
|
@ -1426,7 +1426,7 @@ void VisualScriptEditor::_member_button(Object *p_item, int p_column, int p_butt
|
||||||
|
|
||||||
undo_redo->create_action(TTR("Add Function"));
|
undo_redo->create_action(TTR("Add Function"));
|
||||||
undo_redo->add_do_method(script.ptr(), "add_function", name, fn_id);
|
undo_redo->add_do_method(script.ptr(), "add_function", name, fn_id);
|
||||||
undo_redo->add_do_method(script.ptr(), "add_node", fn_id, func_node, ofs);
|
undo_redo->add_do_method(script.ptr(), "add_node", fn_id, func_node, pos);
|
||||||
undo_redo->add_undo_method(script.ptr(), "remove_function", name);
|
undo_redo->add_undo_method(script.ptr(), "remove_function", name);
|
||||||
undo_redo->add_do_method(script.ptr(), "remove_node", fn_id);
|
undo_redo->add_do_method(script.ptr(), "remove_node", fn_id);
|
||||||
undo_redo->add_do_method(this, "_update_members");
|
undo_redo->add_do_method(this, "_update_members");
|
||||||
|
@ -1621,17 +1621,19 @@ void VisualScriptEditor::_expression_text_changed(const String &p_text, int p_id
|
||||||
updating_graph = false;
|
updating_graph = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 VisualScriptEditor::_get_available_pos(bool centered, Vector2 ofs) const {
|
Vector2 VisualScriptEditor::_get_pos_in_graph(Vector2 p_point) const {
|
||||||
if (centered) {
|
Vector2 pos = (graph->get_scroll_ofs() + p_point) / (graph->get_zoom() * EDSCALE);
|
||||||
ofs = graph->get_scroll_ofs() + graph->get_size() * 0.5;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (graph->is_using_snap()) {
|
if (graph->is_using_snap()) {
|
||||||
int snap = graph->get_snap();
|
int snap = graph->get_snap();
|
||||||
ofs = ofs.snapped(Vector2(snap, snap));
|
pos = pos.snapped(Vector2(snap, snap));
|
||||||
}
|
}
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
|
|
||||||
ofs /= EDSCALE;
|
Vector2 VisualScriptEditor::_get_available_pos(bool p_centered, Vector2 p_pos) const {
|
||||||
|
if (p_centered) {
|
||||||
|
p_pos = _get_pos_in_graph(graph->get_size() * 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
bool exists = false;
|
bool exists = false;
|
||||||
|
@ -1639,8 +1641,8 @@ Vector2 VisualScriptEditor::_get_available_pos(bool centered, Vector2 ofs) const
|
||||||
script->get_node_list(&existing);
|
script->get_node_list(&existing);
|
||||||
for (List<int>::Element *E = existing.front(); E; E = E->next()) {
|
for (List<int>::Element *E = existing.front(); E; E = E->next()) {
|
||||||
Point2 pos = script->get_node_position(E->get());
|
Point2 pos = script->get_node_position(E->get());
|
||||||
if (pos.distance_to(ofs) < 50) {
|
if (pos.distance_to(p_pos) < 50) {
|
||||||
ofs += Vector2(graph->get_snap(), graph->get_snap());
|
p_pos += Vector2(graph->get_snap(), graph->get_snap());
|
||||||
exists = true;
|
exists = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1651,7 +1653,7 @@ Vector2 VisualScriptEditor::_get_available_pos(bool centered, Vector2 ofs) const
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ofs;
|
return p_pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
String VisualScriptEditor::_validate_name(const String &p_name) const {
|
String VisualScriptEditor::_validate_name(const String &p_name) const {
|
||||||
|
@ -2049,16 +2051,9 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 ofs = graph->get_scroll_ofs() + p_point;
|
Vector2 pos = _get_pos_in_graph(p_point);
|
||||||
|
|
||||||
if (graph->is_using_snap()) {
|
int new_id = _create_new_node_from_name(d["node_type"], pos);
|
||||||
int snap = graph->get_snap();
|
|
||||||
ofs = ofs.snapped(Vector2(snap, snap));
|
|
||||||
}
|
|
||||||
|
|
||||||
ofs /= EDSCALE;
|
|
||||||
|
|
||||||
int new_id = _create_new_node_from_name(d["node_type"], ofs);
|
|
||||||
|
|
||||||
Node *node = graph->get_node(itos(new_id));
|
Node *node = graph->get_node(itos(new_id));
|
||||||
if (node) {
|
if (node) {
|
||||||
|
@ -2073,13 +2068,7 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
|
||||||
#else
|
#else
|
||||||
bool use_set = Input::get_singleton()->is_key_pressed(KEY_CTRL);
|
bool use_set = Input::get_singleton()->is_key_pressed(KEY_CTRL);
|
||||||
#endif
|
#endif
|
||||||
Vector2 ofs = graph->get_scroll_ofs() + p_point;
|
Vector2 pos = _get_pos_in_graph(p_point);
|
||||||
if (graph->is_using_snap()) {
|
|
||||||
int snap = graph->get_snap();
|
|
||||||
ofs = ofs.snapped(Vector2(snap, snap));
|
|
||||||
}
|
|
||||||
|
|
||||||
ofs /= EDSCALE;
|
|
||||||
|
|
||||||
Ref<VisualScriptNode> vnode;
|
Ref<VisualScriptNode> vnode;
|
||||||
if (use_set) {
|
if (use_set) {
|
||||||
|
@ -2097,7 +2086,7 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
|
||||||
int new_id = script->get_available_id();
|
int new_id = script->get_available_id();
|
||||||
|
|
||||||
undo_redo->create_action(TTR("Add Node"));
|
undo_redo->create_action(TTR("Add Node"));
|
||||||
undo_redo->add_do_method(script.ptr(), "add_node", new_id, vnode, ofs);
|
undo_redo->add_do_method(script.ptr(), "add_node", new_id, vnode, pos);
|
||||||
undo_redo->add_undo_method(script.ptr(), "remove_node", new_id);
|
undo_redo->add_undo_method(script.ptr(), "remove_node", new_id);
|
||||||
undo_redo->add_do_method(this, "_update_graph");
|
undo_redo->add_do_method(this, "_update_graph");
|
||||||
undo_redo->add_undo_method(this, "_update_graph");
|
undo_redo->add_undo_method(this, "_update_graph");
|
||||||
|
@ -2111,13 +2100,7 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
|
||||||
}
|
}
|
||||||
|
|
||||||
if (String(d["type"]) == "visual_script_function_drag") {
|
if (String(d["type"]) == "visual_script_function_drag") {
|
||||||
Vector2 ofs = graph->get_scroll_ofs() + p_point;
|
Vector2 pos = _get_pos_in_graph(p_point);
|
||||||
if (graph->is_using_snap()) {
|
|
||||||
int snap = graph->get_snap();
|
|
||||||
ofs = ofs.snapped(Vector2(snap, snap));
|
|
||||||
}
|
|
||||||
|
|
||||||
ofs /= EDSCALE;
|
|
||||||
|
|
||||||
Ref<VisualScriptFunctionCall> vnode;
|
Ref<VisualScriptFunctionCall> vnode;
|
||||||
vnode.instantiate();
|
vnode.instantiate();
|
||||||
|
@ -2126,7 +2109,7 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
|
||||||
int new_id = script->get_available_id();
|
int new_id = script->get_available_id();
|
||||||
|
|
||||||
undo_redo->create_action(TTR("Add Node"));
|
undo_redo->create_action(TTR("Add Node"));
|
||||||
undo_redo->add_do_method(script.ptr(), "add_node", new_id, vnode, ofs);
|
undo_redo->add_do_method(script.ptr(), "add_node", new_id, vnode, pos);
|
||||||
undo_redo->add_do_method(vnode.ptr(), "set_base_type", script->get_instance_base_type());
|
undo_redo->add_do_method(vnode.ptr(), "set_base_type", script->get_instance_base_type());
|
||||||
undo_redo->add_do_method(vnode.ptr(), "set_function", d["function"]);
|
undo_redo->add_do_method(vnode.ptr(), "set_function", d["function"]);
|
||||||
|
|
||||||
|
@ -2143,13 +2126,7 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
|
||||||
}
|
}
|
||||||
|
|
||||||
if (String(d["type"]) == "visual_script_signal_drag") {
|
if (String(d["type"]) == "visual_script_signal_drag") {
|
||||||
Vector2 ofs = graph->get_scroll_ofs() + p_point;
|
Vector2 pos = _get_pos_in_graph(p_point);
|
||||||
if (graph->is_using_snap()) {
|
|
||||||
int snap = graph->get_snap();
|
|
||||||
ofs = ofs.snapped(Vector2(snap, snap));
|
|
||||||
}
|
|
||||||
|
|
||||||
ofs /= EDSCALE;
|
|
||||||
|
|
||||||
Ref<VisualScriptEmitSignal> vnode;
|
Ref<VisualScriptEmitSignal> vnode;
|
||||||
vnode.instantiate();
|
vnode.instantiate();
|
||||||
|
@ -2158,7 +2135,7 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
|
||||||
int new_id = script->get_available_id();
|
int new_id = script->get_available_id();
|
||||||
|
|
||||||
undo_redo->create_action(TTR("Add Node"));
|
undo_redo->create_action(TTR("Add Node"));
|
||||||
undo_redo->add_do_method(script.ptr(), "add_node", new_id, vnode, ofs);
|
undo_redo->add_do_method(script.ptr(), "add_node", new_id, vnode, pos);
|
||||||
undo_redo->add_undo_method(script.ptr(), "remove_node", new_id);
|
undo_redo->add_undo_method(script.ptr(), "remove_node", new_id);
|
||||||
undo_redo->add_do_method(this, "_update_graph");
|
undo_redo->add_do_method(this, "_update_graph");
|
||||||
undo_redo->add_undo_method(this, "_update_graph");
|
undo_redo->add_undo_method(this, "_update_graph");
|
||||||
|
@ -2172,13 +2149,7 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
|
||||||
}
|
}
|
||||||
|
|
||||||
if (String(d["type"]) == "resource") {
|
if (String(d["type"]) == "resource") {
|
||||||
Vector2 ofs = graph->get_scroll_ofs() + p_point;
|
Vector2 pos = _get_pos_in_graph(p_point);
|
||||||
if (graph->is_using_snap()) {
|
|
||||||
int snap = graph->get_snap();
|
|
||||||
ofs = ofs.snapped(Vector2(snap, snap));
|
|
||||||
}
|
|
||||||
|
|
||||||
ofs /= EDSCALE;
|
|
||||||
|
|
||||||
Ref<VisualScriptPreload> prnode;
|
Ref<VisualScriptPreload> prnode;
|
||||||
prnode.instantiate();
|
prnode.instantiate();
|
||||||
|
@ -2187,7 +2158,7 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
|
||||||
int new_id = script->get_available_id();
|
int new_id = script->get_available_id();
|
||||||
|
|
||||||
undo_redo->create_action(TTR("Add Preload Node"));
|
undo_redo->create_action(TTR("Add Preload Node"));
|
||||||
undo_redo->add_do_method(script.ptr(), "add_node", new_id, prnode, ofs);
|
undo_redo->add_do_method(script.ptr(), "add_node", new_id, prnode, pos);
|
||||||
undo_redo->add_undo_method(script.ptr(), "remove_node", new_id);
|
undo_redo->add_undo_method(script.ptr(), "remove_node", new_id);
|
||||||
undo_redo->add_do_method(this, "_update_graph");
|
undo_redo->add_do_method(this, "_update_graph");
|
||||||
undo_redo->add_undo_method(this, "_update_graph");
|
undo_redo->add_undo_method(this, "_update_graph");
|
||||||
|
@ -2201,13 +2172,7 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
|
||||||
}
|
}
|
||||||
|
|
||||||
if (String(d["type"]) == "files") {
|
if (String(d["type"]) == "files") {
|
||||||
Vector2 ofs = graph->get_scroll_ofs() + p_point;
|
Vector2 pos = _get_pos_in_graph(p_point);
|
||||||
if (graph->is_using_snap()) {
|
|
||||||
int snap = graph->get_snap();
|
|
||||||
ofs = ofs.snapped(Vector2(snap, snap));
|
|
||||||
}
|
|
||||||
|
|
||||||
ofs /= EDSCALE;
|
|
||||||
|
|
||||||
Array files = d["files"];
|
Array files = d["files"];
|
||||||
|
|
||||||
|
@ -2227,11 +2192,11 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
|
||||||
prnode.instantiate();
|
prnode.instantiate();
|
||||||
prnode->set_preload(res);
|
prnode->set_preload(res);
|
||||||
|
|
||||||
undo_redo->add_do_method(script.ptr(), "add_node", new_id, prnode, ofs);
|
undo_redo->add_do_method(script.ptr(), "add_node", new_id, prnode, pos);
|
||||||
undo_redo->add_undo_method(script.ptr(), "remove_node", new_id);
|
undo_redo->add_undo_method(script.ptr(), "remove_node", new_id);
|
||||||
new_ids.push_back(new_id);
|
new_ids.push_back(new_id);
|
||||||
new_id++;
|
new_id++;
|
||||||
ofs += Vector2(20, 20) * EDSCALE;
|
pos += Vector2(20, 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
undo_redo->add_do_method(this, "_update_graph");
|
undo_redo->add_do_method(this, "_update_graph");
|
||||||
|
@ -2264,13 +2229,7 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
|
||||||
|
|
||||||
Array nodes = d["nodes"];
|
Array nodes = d["nodes"];
|
||||||
|
|
||||||
Vector2 ofs = graph->get_scroll_ofs() + p_point;
|
Vector2 pos = _get_pos_in_graph(p_point);
|
||||||
|
|
||||||
if (graph->is_using_snap()) {
|
|
||||||
int snap = graph->get_snap();
|
|
||||||
ofs = ofs.snapped(Vector2(snap, snap));
|
|
||||||
}
|
|
||||||
ofs /= EDSCALE;
|
|
||||||
|
|
||||||
undo_redo->create_action(TTR("Add Node(s) From Tree"));
|
undo_redo->create_action(TTR("Add Node(s) From Tree"));
|
||||||
int base_id = script->get_available_id();
|
int base_id = script->get_available_id();
|
||||||
|
@ -2305,11 +2264,11 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
|
||||||
selecting_method_id = base_id;
|
selecting_method_id = base_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
undo_redo->add_do_method(script.ptr(), "add_node", base_id, n, ofs);
|
undo_redo->add_do_method(script.ptr(), "add_node", base_id, n, pos);
|
||||||
undo_redo->add_undo_method(script.ptr(), "remove_node", base_id);
|
undo_redo->add_undo_method(script.ptr(), "remove_node", base_id);
|
||||||
|
|
||||||
base_id++;
|
base_id++;
|
||||||
ofs += Vector2(25, 25);
|
pos += Vector2(25, 25);
|
||||||
}
|
}
|
||||||
undo_redo->add_do_method(this, "_update_graph");
|
undo_redo->add_do_method(this, "_update_graph");
|
||||||
undo_redo->add_undo_method(this, "_update_graph");
|
undo_redo->add_undo_method(this, "_update_graph");
|
||||||
|
@ -2331,14 +2290,8 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
|
||||||
}
|
}
|
||||||
|
|
||||||
Node *node = Object::cast_to<Node>(obj);
|
Node *node = Object::cast_to<Node>(obj);
|
||||||
Vector2 ofs = graph->get_scroll_ofs() + p_point;
|
Vector2 pos = _get_pos_in_graph(p_point);
|
||||||
|
|
||||||
if (graph->is_using_snap()) {
|
|
||||||
int snap = graph->get_snap();
|
|
||||||
ofs = ofs.snapped(Vector2(snap, snap));
|
|
||||||
}
|
|
||||||
|
|
||||||
ofs /= EDSCALE;
|
|
||||||
#ifdef OSX_ENABLED
|
#ifdef OSX_ENABLED
|
||||||
bool use_get = Input::get_singleton()->is_key_pressed(KEY_META);
|
bool use_get = Input::get_singleton()->is_key_pressed(KEY_META);
|
||||||
#else
|
#else
|
||||||
|
@ -2375,7 +2328,7 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
|
||||||
vnode = pget;
|
vnode = pget;
|
||||||
}
|
}
|
||||||
|
|
||||||
undo_redo->add_do_method(script.ptr(), "add_node", base_id, vnode, ofs);
|
undo_redo->add_do_method(script.ptr(), "add_node", base_id, vnode, pos);
|
||||||
undo_redo->add_do_method(vnode.ptr(), "set_property", d["property"]);
|
undo_redo->add_do_method(vnode.ptr(), "set_property", d["property"]);
|
||||||
if (!use_get) {
|
if (!use_get) {
|
||||||
undo_redo->add_do_method(vnode.ptr(), "set_default_input_value", 0, d["value"]);
|
undo_redo->add_do_method(vnode.ptr(), "set_default_input_value", 0, d["value"]);
|
||||||
|
@ -2420,7 +2373,7 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
|
||||||
}
|
}
|
||||||
vnode = pget;
|
vnode = pget;
|
||||||
}
|
}
|
||||||
undo_redo->add_do_method(script.ptr(), "add_node", base_id, vnode, ofs);
|
undo_redo->add_do_method(script.ptr(), "add_node", base_id, vnode, pos);
|
||||||
undo_redo->add_do_method(vnode.ptr(), "set_property", d["property"]);
|
undo_redo->add_do_method(vnode.ptr(), "set_property", d["property"]);
|
||||||
if (!use_get) {
|
if (!use_get) {
|
||||||
undo_redo->add_do_method(vnode.ptr(), "set_default_input_value", 0, d["value"]);
|
undo_redo->add_do_method(vnode.ptr(), "set_default_input_value", 0, d["value"]);
|
||||||
|
@ -3009,7 +2962,7 @@ void VisualScriptEditor::_graph_connect_to_empty(const String &p_from, int p_fro
|
||||||
if (!vsn.is_valid()) {
|
if (!vsn.is_valid()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (vsn->get_output_value_port_count()) {
|
if (vsn->get_output_value_port_count() || vsn->get_output_sequence_port_count()) {
|
||||||
port_action_pos = p_release_pos;
|
port_action_pos = p_release_pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3075,13 +3028,6 @@ VisualScriptNode::TypeGuess VisualScriptEditor::_guess_output_type(int p_port_ac
|
||||||
}
|
}
|
||||||
|
|
||||||
void VisualScriptEditor::_port_action_menu(int p_option) {
|
void VisualScriptEditor::_port_action_menu(int p_option) {
|
||||||
Vector2 ofs = graph->get_scroll_ofs() + port_action_pos;
|
|
||||||
if (graph->is_using_snap()) {
|
|
||||||
int snap = graph->get_snap();
|
|
||||||
ofs = ofs.snapped(Vector2(snap, snap));
|
|
||||||
}
|
|
||||||
ofs /= EDSCALE;
|
|
||||||
|
|
||||||
Set<int> vn;
|
Set<int> vn;
|
||||||
|
|
||||||
switch (p_option) {
|
switch (p_option) {
|
||||||
|
@ -3172,13 +3118,7 @@ void VisualScriptEditor::connect_data(Ref<VisualScriptNode> vnode_old, Ref<Visua
|
||||||
}
|
}
|
||||||
|
|
||||||
void VisualScriptEditor::_selected_connect_node(const String &p_text, const String &p_category, const bool p_connecting) {
|
void VisualScriptEditor::_selected_connect_node(const String &p_text, const String &p_category, const bool p_connecting) {
|
||||||
Vector2 ofs = graph->get_scroll_ofs() + port_action_pos;
|
Vector2 pos = _get_pos_in_graph(port_action_pos);
|
||||||
if (graph->is_using_snap()) {
|
|
||||||
int snap = graph->get_snap();
|
|
||||||
ofs = ofs.snapped(Vector2(snap, snap));
|
|
||||||
}
|
|
||||||
ofs /= EDSCALE;
|
|
||||||
ofs /= graph->get_zoom();
|
|
||||||
|
|
||||||
Set<int> vn;
|
Set<int> vn;
|
||||||
|
|
||||||
|
@ -3216,7 +3156,7 @@ void VisualScriptEditor::_selected_connect_node(const String &p_text, const Stri
|
||||||
}
|
}
|
||||||
|
|
||||||
undo_redo->create_action(TTR("Add Node"));
|
undo_redo->create_action(TTR("Add Node"));
|
||||||
undo_redo->add_do_method(script.ptr(), "add_node", new_id, vnode_new, ofs);
|
undo_redo->add_do_method(script.ptr(), "add_node", new_id, vnode_new, pos);
|
||||||
if (vnode_old.is_valid() && p_connecting) {
|
if (vnode_old.is_valid() && p_connecting) {
|
||||||
connect_seq(vnode_old, vnode_new, new_id);
|
connect_seq(vnode_old, vnode_new, new_id);
|
||||||
connect_data(vnode_old, vnode_new, new_id);
|
connect_data(vnode_old, vnode_new, new_id);
|
||||||
|
@ -3279,7 +3219,7 @@ void VisualScriptEditor::_selected_connect_node(const String &p_text, const Stri
|
||||||
|
|
||||||
int new_id = script->get_available_id();
|
int new_id = script->get_available_id();
|
||||||
undo_redo->create_action(TTR("Add Node"));
|
undo_redo->create_action(TTR("Add Node"));
|
||||||
undo_redo->add_do_method(script.ptr(), "add_node", new_id, vnode, ofs);
|
undo_redo->add_do_method(script.ptr(), "add_node", new_id, vnode, pos);
|
||||||
undo_redo->add_undo_method(script.ptr(), "remove_node", new_id);
|
undo_redo->add_undo_method(script.ptr(), "remove_node", new_id);
|
||||||
undo_redo->add_do_method(this, "_update_graph", new_id);
|
undo_redo->add_do_method(this, "_update_graph", new_id);
|
||||||
undo_redo->add_undo_method(this, "_update_graph", new_id);
|
undo_redo->add_undo_method(this, "_update_graph", new_id);
|
||||||
|
@ -3478,9 +3418,9 @@ void VisualScriptEditor::_selected_new_virtual_method(const String &p_text, cons
|
||||||
func_node->add_argument(minfo.arguments[i].type, minfo.arguments[i].name, -1, minfo.arguments[i].hint, minfo.arguments[i].hint_string);
|
func_node->add_argument(minfo.arguments[i].type, minfo.arguments[i].name, -1, minfo.arguments[i].hint, minfo.arguments[i].hint_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 ofs = _get_available_pos();
|
Vector2 pos = _get_available_pos();
|
||||||
|
|
||||||
undo_redo->add_do_method(script.ptr(), "add_node", fn_id, func_node, ofs);
|
undo_redo->add_do_method(script.ptr(), "add_node", fn_id, func_node, pos);
|
||||||
undo_redo->add_undo_method(script.ptr(), "remove_node", fn_id);
|
undo_redo->add_undo_method(script.ptr(), "remove_node", fn_id);
|
||||||
if (minfo.return_val.type != Variant::NIL || minfo.return_val.usage & PROPERTY_USAGE_NIL_IS_VARIANT) {
|
if (minfo.return_val.type != Variant::NIL || minfo.return_val.usage & PROPERTY_USAGE_NIL_IS_VARIANT) {
|
||||||
Ref<VisualScriptReturn> ret_node;
|
Ref<VisualScriptReturn> ret_node;
|
||||||
|
@ -3489,7 +3429,7 @@ void VisualScriptEditor::_selected_new_virtual_method(const String &p_text, cons
|
||||||
ret_node->set_enable_return_value(true);
|
ret_node->set_enable_return_value(true);
|
||||||
ret_node->set_name(name);
|
ret_node->set_name(name);
|
||||||
int nid = script->get_available_id() + 1;
|
int nid = script->get_available_id() + 1;
|
||||||
undo_redo->add_do_method(script.ptr(), "add_node", nid, ret_node, _get_available_pos(false, ofs + Vector2(500, 0)));
|
undo_redo->add_do_method(script.ptr(), "add_node", nid, ret_node, _get_available_pos(false, pos + Vector2(500, 0)));
|
||||||
undo_redo->add_undo_method(script.ptr(), "remove_node", nid);
|
undo_redo->add_undo_method(script.ptr(), "remove_node", nid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3993,7 +3933,7 @@ void VisualScriptEditor::_menu_option(int p_what) {
|
||||||
{
|
{
|
||||||
String new_fn = _validate_name("new_function");
|
String new_fn = _validate_name("new_function");
|
||||||
|
|
||||||
Vector2 ofs = _get_available_pos(false, script->get_node_position(start_node) - Vector2(80, 150));
|
Vector2 pos = _get_available_pos(false, script->get_node_position(start_node) - Vector2(80, 150));
|
||||||
|
|
||||||
Ref<VisualScriptFunction> func_node;
|
Ref<VisualScriptFunction> func_node;
|
||||||
func_node.instantiate();
|
func_node.instantiate();
|
||||||
|
@ -4002,7 +3942,7 @@ void VisualScriptEditor::_menu_option(int p_what) {
|
||||||
undo_redo->create_action(TTR("Create Function"));
|
undo_redo->create_action(TTR("Create Function"));
|
||||||
|
|
||||||
undo_redo->add_do_method(script.ptr(), "add_function", new_fn, fn_id);
|
undo_redo->add_do_method(script.ptr(), "add_function", new_fn, fn_id);
|
||||||
undo_redo->add_do_method(script.ptr(), "add_node", fn_id, func_node, ofs);
|
undo_redo->add_do_method(script.ptr(), "add_node", fn_id, func_node, pos);
|
||||||
undo_redo->add_undo_method(script.ptr(), "remove_function", new_fn);
|
undo_redo->add_undo_method(script.ptr(), "remove_function", new_fn);
|
||||||
undo_redo->add_undo_method(script.ptr(), "remove_node", fn_id);
|
undo_redo->add_undo_method(script.ptr(), "remove_node", fn_id);
|
||||||
undo_redo->add_do_method(this, "_update_members");
|
undo_redo->add_do_method(this, "_update_members");
|
||||||
|
@ -4045,8 +3985,8 @@ void VisualScriptEditor::_menu_option(int p_what) {
|
||||||
|
|
||||||
int ret_id = fn_id + (m++);
|
int ret_id = fn_id + (m++);
|
||||||
selections.insert(ret_id);
|
selections.insert(ret_id);
|
||||||
Vector2 ofsi = _get_available_pos(false, script->get_node_position(G->get()) + Vector2(80, -100));
|
Vector2 posi = _get_available_pos(false, script->get_node_position(G->get()) + Vector2(80, -100));
|
||||||
undo_redo->add_do_method(script.ptr(), "add_node", ret_id, ret_node, ofsi);
|
undo_redo->add_do_method(script.ptr(), "add_node", ret_id, ret_node, posi);
|
||||||
undo_redo->add_undo_method(script.ptr(), "remove_node", ret_id);
|
undo_redo->add_undo_method(script.ptr(), "remove_node", ret_id);
|
||||||
|
|
||||||
undo_redo->add_do_method(script.ptr(), "sequence_connect", G->get(), 0, ret_id);
|
undo_redo->add_do_method(script.ptr(), "sequence_connect", G->get(), 0, ret_id);
|
||||||
|
|
|
@ -226,7 +226,8 @@ class VisualScriptEditor : public ScriptEditorBase {
|
||||||
void _update_node_size(int p_id);
|
void _update_node_size(int p_id);
|
||||||
void _port_name_focus_out(const Node *p_name_box, int p_id, int p_port, bool is_input);
|
void _port_name_focus_out(const Node *p_name_box, int p_id, int p_port, bool is_input);
|
||||||
|
|
||||||
Vector2 _get_available_pos(bool centered = true, Vector2 ofs = Vector2()) const;
|
Vector2 _get_pos_in_graph(Vector2 p_point) const;
|
||||||
|
Vector2 _get_available_pos(bool p_centered = true, Vector2 p_pos = Vector2()) const;
|
||||||
|
|
||||||
bool node_has_sequence_connections(int p_id);
|
bool node_has_sequence_connections(int p_id);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue