From 59738e3fa3f01f85782883d025cd96f9b0d44283 Mon Sep 17 00:00:00 2001 From: Swarnim Arun Date: Sat, 14 Sep 2019 00:44:12 +0530 Subject: [PATCH] Visualscript editor graph unification & refactoring Removes the need to have separate graphs per function for the VisualScript Nodes, and refactoring UI and other improvements such as fuzzy search, right click search boxes and in-graph editable nodes --- .../doc_classes/VisualScriptComposeArray.xml | 15 + .../doc_classes/VisualScriptLists.xml | 95 + modules/visual_script/register_types.cpp | 2 + modules/visual_script/visual_script.cpp | 69 +- modules/visual_script/visual_script.h | 3 + .../visual_script/visual_script_editor.cpp | 2529 ++++++++++++----- modules/visual_script/visual_script_editor.h | 68 +- .../visual_script_func_nodes.cpp | 13 +- modules/visual_script/visual_script_nodes.cpp | 436 +++ modules/visual_script/visual_script_nodes.h | 97 + .../visual_script_property_selector.cpp | 85 +- .../visual_script_property_selector.h | 14 +- scene/gui/tree.cpp | 4 +- 13 files changed, 2705 insertions(+), 725 deletions(-) create mode 100644 modules/visual_script/doc_classes/VisualScriptComposeArray.xml create mode 100644 modules/visual_script/doc_classes/VisualScriptLists.xml diff --git a/modules/visual_script/doc_classes/VisualScriptComposeArray.xml b/modules/visual_script/doc_classes/VisualScriptComposeArray.xml new file mode 100644 index 00000000000..92efbc51d15 --- /dev/null +++ b/modules/visual_script/doc_classes/VisualScriptComposeArray.xml @@ -0,0 +1,15 @@ + + + + A Visual Script Node used to create array from a list of items. + + + A Visual Script Node used to compose array from the list of elements provided with custom in-graph UI hard coded in the VisualScript Editor. + + + + + + + + diff --git a/modules/visual_script/doc_classes/VisualScriptLists.xml b/modules/visual_script/doc_classes/VisualScriptLists.xml new file mode 100644 index 00000000000..eac0b218af0 --- /dev/null +++ b/modules/visual_script/doc_classes/VisualScriptLists.xml @@ -0,0 +1,95 @@ + + + + A Visual Script virtual class for in-graph editable nodes. + + + A Visual Script virtual class that defines the shape and the default behaviour of the nodes that have to be in-graph editable nodes. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/modules/visual_script/register_types.cpp b/modules/visual_script/register_types.cpp index 24b96223d70..49272345fe3 100644 --- a/modules/visual_script/register_types.cpp +++ b/modules/visual_script/register_types.cpp @@ -56,6 +56,8 @@ void register_visual_script_types() { ClassDB::register_virtual_class(); ClassDB::register_class(); ClassDB::register_class(); + ClassDB::register_virtual_class(); + ClassDB::register_class(); ClassDB::register_class(); ClassDB::register_class(); ClassDB::register_class(); diff --git a/modules/visual_script/visual_script.cpp b/modules/visual_script/visual_script.cpp index 6bed1742eb8..0cacd0f0b53 100644 --- a/modules/visual_script/visual_script.cpp +++ b/modules/visual_script/visual_script.cpp @@ -1014,17 +1014,16 @@ void VisualScript::get_script_method_list(List *p_list) const { Ref func = E->get().nodes[E->get().function_id].node; if (func.is_valid()) { - for (int i = 0; i < func->get_argument_count(); i++) { PropertyInfo arg; arg.name = func->get_argument_name(i); arg.type = func->get_argument_type(i); mi.arguments.push_back(arg); } + + p_list->push_back(mi); } } - - p_list->push_back(mi); } } @@ -1137,6 +1136,9 @@ void VisualScript::_set_data(const Dictionary &p_data) { Array funcs = d["functions"]; functions.clear(); + Vector2 last_pos = Vector2(-100 * funcs.size(), -100 * funcs.size()); // this is the center of the last fn box + Vector2 last_size = Vector2(0.0, 0.0); + for (int i = 0; i < funcs.size(); i++) { Dictionary func = funcs[i]; @@ -1149,11 +1151,42 @@ void VisualScript::_set_data(const Dictionary &p_data) { Array nodes = func["nodes"]; - for (int j = 0; j < nodes.size(); j += 3) { + if (!d.has("vs_unify") && nodes.size() > 0) { + Vector2 top_left = nodes[1]; + Vector2 bottom_right = nodes[1]; - add_node(name, nodes[j], nodes[j + 2], nodes[j + 1]); + for (int j = 0; j < nodes.size(); j += 3) { + Point2 pos = nodes[j + 1]; + if (pos.y > top_left.y) { + top_left.y = pos.y; + } + if (pos.y < bottom_right.y) { + bottom_right.y = pos.y; + } + if (pos.x > bottom_right.x) { + bottom_right.x = pos.x; + } + if (pos.x < top_left.x) { + top_left.x = pos.x; + } + } + + Vector2 size = Vector2(bottom_right.x - top_left.x, top_left.y - bottom_right.y); + + Vector2 offset = last_pos + (last_size / 2.0) + (size / 2.0); // dunno I might just keep it in one axis but diagonal feels better.... + + last_pos = offset; + last_size = size; + + for (int j = 0; j < nodes.size(); j += 3) { + add_node(name, nodes[j], nodes[j + 2], offset + nodes[j + 1]); // also add an additional buffer if you want to + } + + } else { + for (int j = 0; j < nodes.size(); j += 3) { + add_node(name, nodes[j], nodes[j + 2], nodes[j + 1]); + } } - Array sequence_connections = func["sequence_connections"]; for (int j = 0; j < sequence_connections.size(); j += 3) { @@ -1254,8 +1287,8 @@ Dictionary VisualScript::_get_data() const { } d["functions"] = funcs; - d["is_tool_script"] = is_tool_script; + d["vs_unify"] = true; return d; } @@ -1330,6 +1363,10 @@ VisualScript::VisualScript() { base_type = "Object"; } +StringName VisualScript::get_default_func() const { + return StringName("f_312843592"); +} + Set VisualScript::get_output_sequence_ports_connected(const String &edited_func, int from_node) { List *sc = memnew(List); get_sequence_connection_list(edited_func, sc); @@ -1403,6 +1440,10 @@ void VisualScriptInstance::get_method_list(List *p_list) const { for (const Map::Element *E = script->functions.front(); E; E = E->next()) { + if (E->key() == script->get_default_func()) { + continue; + } + MethodInfo mi; mi.name = E->key(); if (E->get().function_id >= 0 && E->get().nodes.has(E->get().function_id)) { @@ -1421,8 +1462,6 @@ void VisualScriptInstance::get_method_list(List *p_list) const { if (!vsf->is_sequenced()) { //assumed constant if not sequenced mi.flags |= METHOD_FLAG_CONST; } - - //vsf->Get_ for now at least it does not return.. } } @@ -1431,6 +1470,9 @@ void VisualScriptInstance::get_method_list(List *p_list) const { } bool VisualScriptInstance::has_method(const StringName &p_method) const { + if (p_method == script->get_default_func()) + return false; + return script->functions.has(p_method); } @@ -2002,6 +2044,9 @@ Ref