From b1f392c25e214b331f87737d9e27aad30e95f201 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Wed, 24 Aug 2022 12:05:37 +0200 Subject: [PATCH] Remove VisualScript module for 4.0 As announced in https://godotengine.org/article/godot-4-will-discontinue-visual-scripting, Godot maintainers have agreed to discontinue the current implementation of our VisualScript language. The way it had been designed was not user-friendly enough and we did not succeed in improving its usability to actually make it a good low-code solution for users who need one. So we prefer to remove it for Godot 4.0 and leave the door open for new, innovative ideas around visual scripting, to be developed as plugins or extensions now that Godot provides sufficient functionality for this (notably via GDExtension and the godot-cpp C++ bindings). The current module has been moved to a dedicated repository (with full Git history extracted with `git filter-branch`): https://github.com/godotengine/godot-visual-script It can still be compiled as a C++ module (for now, but will likely require work to be kept in sync with the engine repository), but our hope is that contributors will port it to GDExtension (which is quite compatibile with the existing C++ module code when using the godot-cpp C++ bindings). --- CONTRIBUTING.md | 6 +- doc/classes/@GlobalScope.xml | 4 +- doc/classes/Object.xml | 2 +- doc/classes/ProjectSettings.xml | 3 - doc/classes/Variant.xml | 1 - editor/plugins/script_editor_plugin.cpp | 1 - modules/visual_script/SCsub | 11 - modules/visual_script/config.py | 63 - .../doc_classes/VisualScript.xml | 357 -- .../VisualScriptBasicTypeConstant.xml | 19 - .../doc_classes/VisualScriptBuiltinFunc.xml | 221 - .../doc_classes/VisualScriptClassConstant.xml | 23 - .../doc_classes/VisualScriptComment.xml | 23 - .../doc_classes/VisualScriptComposeArray.xml | 11 - .../doc_classes/VisualScriptCondition.xml | 18 - .../doc_classes/VisualScriptConstant.xml | 23 - .../doc_classes/VisualScriptConstructor.xml | 35 - .../doc_classes/VisualScriptCustomNode.xml | 166 - .../doc_classes/VisualScriptCustomNodes.xml | 37 - .../doc_classes/VisualScriptDeconstruct.xml | 16 - .../doc_classes/VisualScriptEmitSignal.xml | 20 - .../VisualScriptEngineSingleton.xml | 16 - .../doc_classes/VisualScriptExpression.xml | 11 - .../doc_classes/VisualScriptFunction.xml | 11 - .../doc_classes/VisualScriptFunctionCall.xml | 75 - .../doc_classes/VisualScriptFunctionState.xml | 35 - .../VisualScriptGlobalConstant.xml | 16 - .../doc_classes/VisualScriptIndexGet.xml | 11 - .../doc_classes/VisualScriptIndexSet.xml | 11 - .../doc_classes/VisualScriptInputAction.xml | 33 - .../doc_classes/VisualScriptIterator.xml | 18 - .../doc_classes/VisualScriptLists.xml | 77 - .../doc_classes/VisualScriptLocalVar.xml | 23 - .../doc_classes/VisualScriptLocalVarSet.xml | 25 - .../doc_classes/VisualScriptMathConstant.xml | 49 - .../doc_classes/VisualScriptNode.xml | 47 - .../doc_classes/VisualScriptOperator.xml | 23 - .../doc_classes/VisualScriptPreload.xml | 20 - .../doc_classes/VisualScriptPropertyGet.xml | 48 - .../doc_classes/VisualScriptPropertySet.xml | 84 - .../doc_classes/VisualScriptResourcePath.xml | 13 - .../doc_classes/VisualScriptReturn.xml | 24 - .../doc_classes/VisualScriptSceneNode.xml | 20 - .../doc_classes/VisualScriptSceneTree.xml | 11 - .../doc_classes/VisualScriptSelect.xml | 22 - .../doc_classes/VisualScriptSelf.xml | 15 - .../doc_classes/VisualScriptSequence.xml | 22 - .../doc_classes/VisualScriptSubCall.xml | 11 - .../doc_classes/VisualScriptSwitch.xml | 20 - .../doc_classes/VisualScriptTypeCast.xml | 19 - .../doc_classes/VisualScriptVariableGet.xml | 20 - .../doc_classes/VisualScriptVariableSet.xml | 21 - .../doc_classes/VisualScriptWhile.xml | 17 - .../doc_classes/VisualScriptYield.xml | 30 - .../doc_classes/VisualScriptYieldSignal.xml | 36 - .../editor/visual_script_editor.cpp | 4976 ----------------- .../editor/visual_script_editor.h | 395 -- .../visual_script_property_selector.cpp | 1277 ----- .../editor/visual_script_property_selector.h | 229 - modules/visual_script/icons/VisualScript.svg | 1 - .../icons/VisualScriptInternal.svg | 1 - modules/visual_script/register_types.cpp | 150 - modules/visual_script/register_types.h | 39 - modules/visual_script/visual_script.cpp | 2506 --------- modules/visual_script/visual_script.h | 630 --- .../visual_script_builtin_funcs.cpp | 1380 ----- .../visual_script_builtin_funcs.h | 153 - .../visual_script_expression.cpp | 1570 ------ .../visual_script/visual_script_expression.h | 284 - .../visual_script_flow_control.cpp | 880 --- .../visual_script_flow_control.h | 268 - .../visual_script_func_nodes.cpp | 2444 -------- .../visual_script/visual_script_func_nodes.h | 363 -- modules/visual_script/visual_script_nodes.cpp | 4072 -------------- modules/visual_script/visual_script_nodes.h | 1092 ---- .../visual_script_yield_nodes.cpp | 598 -- .../visual_script/visual_script_yield_nodes.h | 147 - 77 files changed, 5 insertions(+), 25444 deletions(-) delete mode 100644 modules/visual_script/SCsub delete mode 100644 modules/visual_script/config.py delete mode 100644 modules/visual_script/doc_classes/VisualScript.xml delete mode 100644 modules/visual_script/doc_classes/VisualScriptBasicTypeConstant.xml delete mode 100644 modules/visual_script/doc_classes/VisualScriptBuiltinFunc.xml delete mode 100644 modules/visual_script/doc_classes/VisualScriptClassConstant.xml delete mode 100644 modules/visual_script/doc_classes/VisualScriptComment.xml delete mode 100644 modules/visual_script/doc_classes/VisualScriptComposeArray.xml delete mode 100644 modules/visual_script/doc_classes/VisualScriptCondition.xml delete mode 100644 modules/visual_script/doc_classes/VisualScriptConstant.xml delete mode 100644 modules/visual_script/doc_classes/VisualScriptConstructor.xml delete mode 100644 modules/visual_script/doc_classes/VisualScriptCustomNode.xml delete mode 100644 modules/visual_script/doc_classes/VisualScriptCustomNodes.xml delete mode 100644 modules/visual_script/doc_classes/VisualScriptDeconstruct.xml delete mode 100644 modules/visual_script/doc_classes/VisualScriptEmitSignal.xml delete mode 100644 modules/visual_script/doc_classes/VisualScriptEngineSingleton.xml delete mode 100644 modules/visual_script/doc_classes/VisualScriptExpression.xml delete mode 100644 modules/visual_script/doc_classes/VisualScriptFunction.xml delete mode 100644 modules/visual_script/doc_classes/VisualScriptFunctionCall.xml delete mode 100644 modules/visual_script/doc_classes/VisualScriptFunctionState.xml delete mode 100644 modules/visual_script/doc_classes/VisualScriptGlobalConstant.xml delete mode 100644 modules/visual_script/doc_classes/VisualScriptIndexGet.xml delete mode 100644 modules/visual_script/doc_classes/VisualScriptIndexSet.xml delete mode 100644 modules/visual_script/doc_classes/VisualScriptInputAction.xml delete mode 100644 modules/visual_script/doc_classes/VisualScriptIterator.xml delete mode 100644 modules/visual_script/doc_classes/VisualScriptLists.xml delete mode 100644 modules/visual_script/doc_classes/VisualScriptLocalVar.xml delete mode 100644 modules/visual_script/doc_classes/VisualScriptLocalVarSet.xml delete mode 100644 modules/visual_script/doc_classes/VisualScriptMathConstant.xml delete mode 100644 modules/visual_script/doc_classes/VisualScriptNode.xml delete mode 100644 modules/visual_script/doc_classes/VisualScriptOperator.xml delete mode 100644 modules/visual_script/doc_classes/VisualScriptPreload.xml delete mode 100644 modules/visual_script/doc_classes/VisualScriptPropertyGet.xml delete mode 100644 modules/visual_script/doc_classes/VisualScriptPropertySet.xml delete mode 100644 modules/visual_script/doc_classes/VisualScriptResourcePath.xml delete mode 100644 modules/visual_script/doc_classes/VisualScriptReturn.xml delete mode 100644 modules/visual_script/doc_classes/VisualScriptSceneNode.xml delete mode 100644 modules/visual_script/doc_classes/VisualScriptSceneTree.xml delete mode 100644 modules/visual_script/doc_classes/VisualScriptSelect.xml delete mode 100644 modules/visual_script/doc_classes/VisualScriptSelf.xml delete mode 100644 modules/visual_script/doc_classes/VisualScriptSequence.xml delete mode 100644 modules/visual_script/doc_classes/VisualScriptSubCall.xml delete mode 100644 modules/visual_script/doc_classes/VisualScriptSwitch.xml delete mode 100644 modules/visual_script/doc_classes/VisualScriptTypeCast.xml delete mode 100644 modules/visual_script/doc_classes/VisualScriptVariableGet.xml delete mode 100644 modules/visual_script/doc_classes/VisualScriptVariableSet.xml delete mode 100644 modules/visual_script/doc_classes/VisualScriptWhile.xml delete mode 100644 modules/visual_script/doc_classes/VisualScriptYield.xml delete mode 100644 modules/visual_script/doc_classes/VisualScriptYieldSignal.xml delete mode 100644 modules/visual_script/editor/visual_script_editor.cpp delete mode 100644 modules/visual_script/editor/visual_script_editor.h delete mode 100644 modules/visual_script/editor/visual_script_property_selector.cpp delete mode 100644 modules/visual_script/editor/visual_script_property_selector.h delete mode 100644 modules/visual_script/icons/VisualScript.svg delete mode 100644 modules/visual_script/icons/VisualScriptInternal.svg delete mode 100644 modules/visual_script/register_types.cpp delete mode 100644 modules/visual_script/register_types.h delete mode 100644 modules/visual_script/visual_script.cpp delete mode 100644 modules/visual_script/visual_script.h delete mode 100644 modules/visual_script/visual_script_builtin_funcs.cpp delete mode 100644 modules/visual_script/visual_script_builtin_funcs.h delete mode 100644 modules/visual_script/visual_script_expression.cpp delete mode 100644 modules/visual_script/visual_script_expression.h delete mode 100644 modules/visual_script/visual_script_flow_control.cpp delete mode 100644 modules/visual_script/visual_script_flow_control.h delete mode 100644 modules/visual_script/visual_script_func_nodes.cpp delete mode 100644 modules/visual_script/visual_script_func_nodes.h delete mode 100644 modules/visual_script/visual_script_nodes.cpp delete mode 100644 modules/visual_script/visual_script_nodes.h delete mode 100644 modules/visual_script/visual_script_yield_nodes.cpp delete mode 100644 modules/visual_script/visual_script_yield_nodes.h diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 49355d27826..e5565e72edf 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -74,10 +74,10 @@ if your ZIP file isn't accepted by GitHub because it's too large. We recommend always attaching a minimal reproduction project, even if the issue may seem simple to reproduce manually. -**Note for C# users:** If your issue is not Mono-specific, please upload a -minimal reproduction project written in GDScript or VisualScript. +**Note for C# users:** If your issue is not .NET-specific, please upload a +minimal reproduction project written in GDScript. This will make it easier for contributors to reproduce the issue -locally as not everyone has a Mono setup available. +locally as not everyone has a .NET setup available. **If you've been asked by a maintainer to upload a minimal reproduction project, you *must* do so within 7 days.** Otherwise, your bug report will be closed as diff --git a/doc/classes/@GlobalScope.xml b/doc/classes/@GlobalScope.xml index 722177c9e8a..5b089548759 100644 --- a/doc/classes/@GlobalScope.xml +++ b/doc/classes/@GlobalScope.xml @@ -1303,10 +1303,8 @@ The [TranslationServer] singleton. - - The [VisualScriptCustomNodes] singleton. - + The [WorkerThreadPool] singleton. The [XRServer] singleton. diff --git a/doc/classes/Object.xml b/doc/classes/Object.xml index 5f9b6f72060..3c71a02a21d 100644 --- a/doc/classes/Object.xml +++ b/doc/classes/Object.xml @@ -5,7 +5,7 @@ Every class which is not a built-in type inherits from this class. - You can construct Objects from scripting languages, using [code]Object.new()[/code] in GDScript, [code]new Object[/code] in C#, or the "Construct Object" node in VisualScript. + You can construct Objects from scripting languages, using [code]Object.new()[/code] in GDScript, or [code]new Object[/code] in C#. Objects do not manage memory. If a class inherits from Object, you will have to delete instances of it manually. To do so, call the [method free] method from your script or delete the instance from C++. Some classes that extend Object add memory management. This is the case of [RefCounted], which counts references and deletes itself automatically when no longer referenced. [Node], another fundamental type, deletes all its children when freed from memory. Objects export properties, which are mainly useful for storage and editing, but not really so much in programming. Properties are exported in [method _get_property_list] and handled in [method _get] and [method _set]. However, scripting languages and C++ have simpler means to export them. diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml index 0cee71b6139..a2e202b2184 100644 --- a/doc/classes/ProjectSettings.xml +++ b/doc/classes/ProjectSettings.xml @@ -464,9 +464,6 @@ Print more information to standard output when running. It displays information such as memory leaks, which scenes and resources are being loaded, etc. This can also be enabled using the [code]--verbose[/code] or [code]-v[/code] command line argument, even on an exported project. See also [method OS.is_stdout_verbose] and [method @GlobalScope.print_verbose]. - - Maximum call stack in visual scripting, to avoid infinite recursion. - Color of the contact points between collision shapes, visible when "Visible Collision Shapes" is enabled in the Debug menu. diff --git a/doc/classes/Variant.xml b/doc/classes/Variant.xml index 0d6fcd0ef56..6b384d6a772 100644 --- a/doc/classes/Variant.xml +++ b/doc/classes/Variant.xml @@ -23,7 +23,6 @@ [/codeblocks] Godot tracks all scripting API variables within Variants. Without even realizing it, you use Variants all the time. When a particular language enforces its own rules for keeping data typed, then that language is applying its own custom logic over the base Variant scripting API. - GDScript automatically wrap values in them. It keeps all data in plain Variants by default and then optionally enforces custom static typing rules on variable types. - - VisualScript tracks properties inside Variants as well, but it also uses static typing. The GUI interface enforces that properties have a particular type that doesn't change over time. - C# is statically typed, but uses the Mono [code]object[/code] type in place of Godot's Variant class when it needs to represent a dynamic value. [code]object[/code] is the Mono runtime's equivalent of the same concept. The global [method @GlobalScope.typeof] function returns the enumerated value of the Variant type stored in the current variable (see [enum Variant.Type]). [codeblocks] diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index de1776c0eac..a0c9ddb14bc 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -49,7 +49,6 @@ #include "editor/find_in_files.h" #include "editor/node_dock.h" #include "editor/plugins/shader_editor_plugin.h" -#include "modules/visual_script/editor/visual_script_editor.h" #include "scene/main/window.h" #include "scene/scene_string_names.h" #include "script_text_editor.h" diff --git a/modules/visual_script/SCsub b/modules/visual_script/SCsub deleted file mode 100644 index b91cceae099..00000000000 --- a/modules/visual_script/SCsub +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env python - -Import("env") -Import("env_modules") - -env_vs = env_modules.Clone() - -env_vs.add_source_files(env.modules_sources, "*.cpp") - -if env["tools"]: - env_vs.add_source_files(env.modules_sources, "editor/*.cpp") diff --git a/modules/visual_script/config.py b/modules/visual_script/config.py deleted file mode 100644 index e8990c43c8c..00000000000 --- a/modules/visual_script/config.py +++ /dev/null @@ -1,63 +0,0 @@ -def can_build(env, platform): - return True - - -def configure(env): - pass - - -def get_doc_classes(): - return [ - "VisualScriptBasicTypeConstant", - "VisualScriptBuiltinFunc", - "VisualScriptClassConstant", - "VisualScriptComment", - "VisualScriptComposeArray", - "VisualScriptCondition", - "VisualScriptConstant", - "VisualScriptConstructor", - "VisualScriptCustomNode", - "VisualScriptCustomNodes", - "VisualScriptDeconstruct", - "VisualScriptEditor", - "VisualScriptEmitSignal", - "VisualScriptEngineSingleton", - "VisualScriptExpression", - "VisualScriptFunctionCall", - "VisualScriptFunctionState", - "VisualScriptFunction", - "VisualScriptGlobalConstant", - "VisualScriptIndexGet", - "VisualScriptIndexSet", - "VisualScriptInputAction", - "VisualScriptIterator", - "VisualScriptLists", - "VisualScriptLocalVarSet", - "VisualScriptLocalVar", - "VisualScriptMathConstant", - "VisualScriptNode", - "VisualScriptOperator", - "VisualScriptPreload", - "VisualScriptPropertyGet", - "VisualScriptPropertySet", - "VisualScriptResourcePath", - "VisualScriptReturn", - "VisualScriptSceneNode", - "VisualScriptSceneTree", - "VisualScriptSelect", - "VisualScriptSelf", - "VisualScriptSequence", - "VisualScriptSubCall", - "VisualScriptSwitch", - "VisualScriptTypeCast", - "VisualScriptVariableGet", - "VisualScriptVariableSet", - "VisualScriptWhile", - "VisualScript", - "VisualScriptYieldSignal", - "VisualScriptYield", - ] - - -def get_doc_path(): - return "doc_classes" diff --git a/modules/visual_script/doc_classes/VisualScript.xml b/modules/visual_script/doc_classes/VisualScript.xml deleted file mode 100644 index ff6b7a8b5fb..00000000000 --- a/modules/visual_script/doc_classes/VisualScript.xml +++ /dev/null @@ -1,357 +0,0 @@ - - - - A script implemented in the Visual Script programming environment. - - - A script implemented in the Visual Script programming environment. The script extends the functionality of all objects that instance it. - [method Object.set_script] extends an existing object, if that object's class matches one of the script's base classes. - You are most likely to use this class via the Visual Script editor or when writing plugins for it. - - - $DOCS_URL/tutorials/scripting/visual_script/index.html - - - - - - - Add a custom signal with the specified name to the VisualScript. - - - - - - - - Add a function with the specified name to the VisualScript, and assign the root [VisualScriptFunction] node's id as [code]func_node_id[/code]. - - - - - - - - - Add a node to the VisualScript. - - - - - - - - - Add a variable to the VisualScript, optionally giving it a default value or marking it as exported. - - - - - - - - - - Add an argument to a custom signal added with [method add_custom_signal]. - - - - - - - Get the count of a custom signal's arguments. - - - - - - - - Get the name of a custom signal's argument. - - - - - - - - Get the type of a custom signal's argument. - - - - - - - - Remove a specific custom signal's argument. - - - - - - - - - Rename a custom signal's argument. - - - - - - - - - Change the type of a custom signal's argument. - - - - - - - - - Swap two of the arguments of a custom signal. - - - - - - - - - - Connect two data ports. The value of [code]from_node[/code]'s [code]from_port[/code] would be fed into [code]to_node[/code]'s [code]to_port[/code]. - - - - - - - - - - Disconnect two data ports previously connected with [method data_connect]. - - - - - - - Returns the id of a function's entry point node. - - - - - - - Returns a node given its id. - - - - - - - Returns a node's position in pixels. - - - - - - Returns the current position of the center of the screen. - - - - - - - Returns the default (initial) value of a variable. - - - - - - - Returns whether a variable is exported. - - - - - - - Returns the information for a given variable as a dictionary. The information includes its name, type, hint and usage. - - - - - - - Returns whether a signal exists with the specified name. - - - - - - - - - - Returns whether the specified data ports are connected. - - - - - - - Returns whether a function exists with the specified name. - - - - - - - Returns whether a node exists with the given id. - - - - - - - - - Returns whether the specified sequence ports are connected. - - - - - - - Returns whether a variable exists with the specified name. - - - - - - - Remove a custom signal with the given name. - - - - - - - Remove a specific function and its nodes from the script. - - - - - - - Remove the node with the specified id. - - - - - - - Remove a variable with the given name. - - - - - - - - Change the name of a custom signal. - - - - - - - - Change the name of a function. - - - - - - - - Change the name of a variable. - - - - - - - - - Connect two sequence ports. The execution will flow from of [code]from_node[/code]'s [code]from_output[/code] into [code]to_node[/code]. - Unlike [method data_connect], there isn't a [code]to_port[/code], since the target node can have only one sequence port. - - - - - - - - - Disconnect two sequence ports previously connected with [method sequence_connect]. - - - - - - - Set the base type of the script. - - - - - - - - Set the node position in the VisualScript graph. - - - - - - - Set the screen center to the given position. - - - - - - - - Change the default (initial) value of a variable. - - - - - - - - Change whether a variable is exported. - - - - - - - - Set a variable's info, using the same format as [method get_variable_info]. - - - - - - - - Emitted when the ports of a node are changed. - - - - diff --git a/modules/visual_script/doc_classes/VisualScriptBasicTypeConstant.xml b/modules/visual_script/doc_classes/VisualScriptBasicTypeConstant.xml deleted file mode 100644 index 0ed66f44e1f..00000000000 --- a/modules/visual_script/doc_classes/VisualScriptBasicTypeConstant.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - A Visual Script node representing a constant from the base types. - - - A Visual Script node representing a constant from base types, such as [constant Vector3.AXIS_X]. - - - - - - The type to get the constant from. - - - The name of the constant to return. - - - diff --git a/modules/visual_script/doc_classes/VisualScriptBuiltinFunc.xml b/modules/visual_script/doc_classes/VisualScriptBuiltinFunc.xml deleted file mode 100644 index 647b627d25c..00000000000 --- a/modules/visual_script/doc_classes/VisualScriptBuiltinFunc.xml +++ /dev/null @@ -1,221 +0,0 @@ - - - - A Visual Script node used to call built-in functions. - - - A built-in function used inside a [VisualScript]. It is usually a math function or an utility function. - See also [@GDScript], for the same functions in the GDScript language. - - - - - - The function to be executed. - - - - - Returns the sine of the input. - - - Returns the cosine of the input. - - - Returns the tangent of the input. - - - Returns the hyperbolic sine of the input. - - - Returns the hyperbolic cosine of the input. - - - Returns the hyperbolic tangent of the input. - - - Returns the arc sine of the input. - - - Returns the arc cosine of the input. - - - Returns the arc tangent of the input. - - - Returns the arc tangent of the input, using the signs of both parameters to determine the exact angle. - - - Returns the square root of the input. - - - Returns the remainder of one input divided by the other, using floating-point numbers. - - - Returns the positive remainder of one input divided by the other, using floating-point numbers. - - - Returns the input rounded down. - - - Returns the input rounded up. - - - Returns the input rounded to the nearest integer. - - - Returns the absolute value of the input. - - - Returns the sign of the input, turning it into 1, -1, or 0. Useful to determine if the input is positive or negative. - - - Returns the input raised to a given power. - - - Returns the natural logarithm of the input. Note that this is not the typical base-10 logarithm function calculators use. - - - Returns the mathematical constant [b]e[/b] raised to the specified power of the input. [b]e[/b] has an approximate value of 2.71828. - - - Returns whether the input is NaN (Not a Number) or not. NaN is usually produced by dividing 0 by 0, though other ways exist. - - - Returns whether the input is an infinite floating-point number or not. Infinity is usually produced by dividing a number by 0, though other ways exist. - - - Easing function, based on exponent. 0 is constant, 1 is linear, 0 to 1 is ease-in, 1+ is ease out. Negative values are in-out/out in. - - - Returns the number of digit places after the decimal that the first non-zero digit occurs. - - - Returns the input snapped to a given step. - - - Returns a number linearly interpolated between the first two inputs, based on the third input. Uses the formula [code]a + (a - b) * t[/code]. - - - - - - - - - Moves the number toward a value, based on the third input. - - - Randomize the seed (or the internal state) of the random number generator. Current implementation reseeds using a number based on time. - - - Returns a random 32 bits integer value. To obtain a random value between 0 to N (where N is smaller than 2^32 - 1), you can use it with the remainder function. - - - Returns a random floating-point value between 0 and 1. To obtain a random value between 0 to N, you can use it with multiplication. - - - Returns a random 32-bit integer value between the two inputs. - - - Returns a random floating-point value between the two inputs. - - - Returns a normally-distributed pseudo-random number, using Box-Muller transform with the specified mean and a standard deviation. This is also called Gaussian distribution. - - - Set the seed for the random number generator. - - - Returns a random value from the given seed, along with the new seed. - - - Convert the input from degrees to radians. - - - Convert the input from radians to degrees. - - - Convert the input from linear volume to decibel volume. - - - Convert the input from decibel volume to linear volume. - - - - - - - Returns the [code]value[/code] wrapped between [code]0[/code] and the [code]length[/code]. If the limit is reached, the next value the function returned is decreased to the [code]0[/code] side or increased to the [code]length[/code] side (like a triangle wave). If [code]length[/code] is less than zero, it becomes positive. - - - Returns the greater of the two numbers, also known as their maximum. - - - Returns the lesser of the two numbers, also known as their minimum. - - - Returns the input clamped inside the given range, ensuring the result is never outside it. Equivalent to [code]min(max(input, range_low), range_high)[/code]. - - - Returns the nearest power of 2 to the input. - - - Create a [WeakRef] from the input. - - - Convert between types. - - - Returns the type of the input as an integer. Check [enum Variant.Type] for the integers that might be returned. - - - Checks if a type is registered in the [ClassDB]. - - - Returns a character with the given ascii value. - - - Convert the input to a string. - - - Print the given string to the output window. - - - Print the given string to the standard error output. - - - Print the given string to the standard output, without adding a newline. - - - - - Serialize a [Variant] to a string. - - - Deserialize a [Variant] from a string serialized using [constant VAR_TO_STR]. - - - Serialize a [Variant] to a [PackedByteArray]. - - - Deserialize a [Variant] from a [PackedByteArray] serialized using [constant VAR_TO_BYTES]. - - - Returns a number smoothly interpolated between the first two inputs, based on the third input. Similar to [constant MATH_LERP], but interpolates faster at the beginning and slower at the end. Using Hermite interpolation formula: - [codeblock] - var t = clamp((weight - from) / (to - from), 0.0, 1.0) - return t * t * (3.0 - 2.0 * t) - [/codeblock] - - - - - - - - - Represents the size of the [enum BuiltinFunc] enum. - - - diff --git a/modules/visual_script/doc_classes/VisualScriptClassConstant.xml b/modules/visual_script/doc_classes/VisualScriptClassConstant.xml deleted file mode 100644 index 2509084f0ec..00000000000 --- a/modules/visual_script/doc_classes/VisualScriptClassConstant.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - Gets a constant from a given class. - - - This node returns a constant from a given class, such as [constant TYPE_INT]. See the given class' documentation for available constants. - [b]Input Ports:[/b] - none - [b]Output Ports:[/b] - - Data (variant): [code]value[/code] - - - - - - The constant's parent class. - - - The constant to return. See the given class for its available constants. - - - diff --git a/modules/visual_script/doc_classes/VisualScriptComment.xml b/modules/visual_script/doc_classes/VisualScriptComment.xml deleted file mode 100644 index cf4b57ca19c..00000000000 --- a/modules/visual_script/doc_classes/VisualScriptComment.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - A Visual Script node used to annotate the script. - - - A Visual Script node used to display annotations in the script, so that code may be documented. - Comment nodes can be resized so they encompass a group of nodes. - - - - - - The text inside the comment node. - - - The comment node's size (in pixels). - - - The comment node's title. - - - diff --git a/modules/visual_script/doc_classes/VisualScriptComposeArray.xml b/modules/visual_script/doc_classes/VisualScriptComposeArray.xml deleted file mode 100644 index ea73867c4b4..00000000000 --- a/modules/visual_script/doc_classes/VisualScriptComposeArray.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - 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/VisualScriptCondition.xml b/modules/visual_script/doc_classes/VisualScriptCondition.xml deleted file mode 100644 index a29388569fa..00000000000 --- a/modules/visual_script/doc_classes/VisualScriptCondition.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - A Visual Script node which branches the flow. - - - A Visual Script node that checks a [bool] input port. If [code]true[/code], it will exit via the "true" sequence port. If [code]false[/code], it will exit via the "false" sequence port. After exiting either, it exits via the "done" port. Sequence ports may be left disconnected. - [b]Input Ports:[/b] - - Sequence: [code]if (cond) is[/code] - - Data (boolean): [code]cond[/code] - [b]Output Ports:[/b] - - Sequence: [code]true[/code] - - Sequence: [code]false[/code] - - Sequence: [code]done[/code] - - - - diff --git a/modules/visual_script/doc_classes/VisualScriptConstant.xml b/modules/visual_script/doc_classes/VisualScriptConstant.xml deleted file mode 100644 index 645ede90015..00000000000 --- a/modules/visual_script/doc_classes/VisualScriptConstant.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - Gets a contant's value. - - - This node returns a constant's value. - [b]Input Ports:[/b] - none - [b]Output Ports:[/b] - - Data (variant): [code]get[/code] - - - - - - The constant's type. - - - The constant's value. - - - diff --git a/modules/visual_script/doc_classes/VisualScriptConstructor.xml b/modules/visual_script/doc_classes/VisualScriptConstructor.xml deleted file mode 100644 index a003f21ab96..00000000000 --- a/modules/visual_script/doc_classes/VisualScriptConstructor.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - A Visual Script node which calls a base type constructor. - - - A Visual Script node which calls a base type constructor. It can be used for type conversion as well. - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/modules/visual_script/doc_classes/VisualScriptCustomNode.xml b/modules/visual_script/doc_classes/VisualScriptCustomNode.xml deleted file mode 100644 index 6e522b2f84b..00000000000 --- a/modules/visual_script/doc_classes/VisualScriptCustomNode.xml +++ /dev/null @@ -1,166 +0,0 @@ - - - - A scripted Visual Script node. - - - A custom Visual Script node which can be scripted in powerful ways. - - - - - - - - Returns the node's title. - - - - - - Returns the node's category. - - - - - - Returns the count of input value ports. - - - - - - - Returns the specified input port's hint. See the [enum @GlobalScope.PropertyHint] hints. - - - - - - - Returns the specified input port's hint string. - - - - - - - Returns the specified input port's name. - - - - - - - Returns the specified input port's type. See the [enum Variant.Type] values. - - - - - - Returns the amount of output [b]sequence[/b] ports. - - - - - - - Returns the specified [b]sequence[/b] output's name. - - - - - - Returns the amount of output value ports. - - - - - - - Returns the specified output port's hint. See the [enum @GlobalScope.PropertyHint] hints. - - - - - - - Returns the specified output port's hint string. - - - - - - - Returns the specified output port's name. - - - - - - - Returns the specified output port's type. See the [enum Variant.Type] values. - - - - - - Returns the custom node's text, which is shown right next to the input [b]sequence[/b] port (if there is none, on the place that is usually taken by it). - - - - - - Returns the size of the custom node's working memory. See [method _step] for more details. - - - - - - Returns whether the custom node has an input [b]sequence[/b] port. - - - - - - - - - - Execute the custom node's logic, returning the index of the output sequence port to use or a [String] when there is an error. - The [code]inputs[/code] array contains the values of the input ports. - [code]outputs[/code] is an array whose indices should be set to the respective outputs. - The [code]start_mode[/code] is usually [constant START_MODE_BEGIN_SEQUENCE], unless you have used the [code]STEP_*[/code] constants. - [code]working_mem[/code] is an array which can be used to persist information between runs of the custom node. The size needs to be predefined using [method _get_working_memory_size]. - When returning, you can mask the returned value with one of the [code]STEP_*[/code] constants. - - - - - - The start mode used the first time when [method _step] is called. - - - The start mode used when [method _step] is called after coming back from a [constant STEP_PUSH_STACK_BIT]. - - - The start mode used when [method _step] is called after resuming from [constant STEP_YIELD_BIT]. - - - Hint used by [method _step] to tell that control should return to it when there is no other node left to execute. - This is used by [VisualScriptCondition] to redirect the sequence to the "Done" port after the [code]true[/code]/[code]false[/code] branch has finished execution. - - - Hint used by [method _step] to tell that control should return back, either hitting a previous [constant STEP_PUSH_STACK_BIT] or exiting the function. - - - - - Hint used by [method _step] to tell that control should stop and exit the function. - - - Hint used by [method _step] to tell that the function should be yielded. - Using this requires you to have at least one working memory slot, which is used for the [VisualScriptFunctionState]. - - - diff --git a/modules/visual_script/doc_classes/VisualScriptCustomNodes.xml b/modules/visual_script/doc_classes/VisualScriptCustomNodes.xml deleted file mode 100644 index 48d7975051f..00000000000 --- a/modules/visual_script/doc_classes/VisualScriptCustomNodes.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - Manages custom nodes for the Visual Script editor. - - - This singleton can be used to manage (i.e., add or remove) custom nodes for the Visual Script editor. - - - - - - - - - - - Add a custom Visual Script node to the editor. It'll be placed under "Custom Nodes" with the [code]category[/code] as the parameter. - - - - - - - - Remove a custom Visual Script node from the editor. Custom nodes already placed on scripts won't be removed. - - - - - - - Emitted when a custom Visual Script node is added or removed. - - - - diff --git a/modules/visual_script/doc_classes/VisualScriptDeconstruct.xml b/modules/visual_script/doc_classes/VisualScriptDeconstruct.xml deleted file mode 100644 index b544fd9d903..00000000000 --- a/modules/visual_script/doc_classes/VisualScriptDeconstruct.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - A Visual Script node which deconstructs a base type instance into its parts. - - - A Visual Script node which deconstructs a base type instance into its parts. - - - - - - The type to deconstruct. - - - diff --git a/modules/visual_script/doc_classes/VisualScriptEmitSignal.xml b/modules/visual_script/doc_classes/VisualScriptEmitSignal.xml deleted file mode 100644 index c0cefa0ab73..00000000000 --- a/modules/visual_script/doc_classes/VisualScriptEmitSignal.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - Emits a specified signal. - - - Emits a specified signal when it is executed. - [b]Input Ports:[/b] - - Sequence: [code]emit[/code] - [b]Output Ports:[/b] - - Sequence - - - - - - The signal to emit. - - - diff --git a/modules/visual_script/doc_classes/VisualScriptEngineSingleton.xml b/modules/visual_script/doc_classes/VisualScriptEngineSingleton.xml deleted file mode 100644 index f60a048845c..00000000000 --- a/modules/visual_script/doc_classes/VisualScriptEngineSingleton.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - A Visual Script node returning a singleton from [@GlobalScope]. - - - A Visual Script node returning a singleton from [@GlobalScope]. - - - - - - The singleton's name. - - - diff --git a/modules/visual_script/doc_classes/VisualScriptExpression.xml b/modules/visual_script/doc_classes/VisualScriptExpression.xml deleted file mode 100644 index 14750e7c8d5..00000000000 --- a/modules/visual_script/doc_classes/VisualScriptExpression.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - A Visual Script node that can execute a custom expression. - - - A Visual Script node that can execute a custom expression. Values can be provided for the input and the expression result can be retrieved from the output. - - - - diff --git a/modules/visual_script/doc_classes/VisualScriptFunction.xml b/modules/visual_script/doc_classes/VisualScriptFunction.xml deleted file mode 100644 index 74d9f194ebc..00000000000 --- a/modules/visual_script/doc_classes/VisualScriptFunction.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - A Visual Script node representing a function. - - - [VisualScriptFunction] represents a function header. It is the starting point for the function body and can be used to tweak the function's properties (e.g. RPC mode). - - - - diff --git a/modules/visual_script/doc_classes/VisualScriptFunctionCall.xml b/modules/visual_script/doc_classes/VisualScriptFunctionCall.xml deleted file mode 100644 index 543263ff8e1..00000000000 --- a/modules/visual_script/doc_classes/VisualScriptFunctionCall.xml +++ /dev/null @@ -1,75 +0,0 @@ - - - - A Visual Script node for calling a function. - - - [VisualScriptFunctionCall] is created when you add or drag and drop a function onto the Visual Script graph. It allows to tweak parameters of the call, e.g. what object the function is called on. - - - - - - The script to be used when [member call_mode] is set to [constant CALL_MODE_INSTANCE]. - - - The base type to be used when [member call_mode] is set to [constant CALL_MODE_INSTANCE]. - - - The type to be used when [member call_mode] is set to [constant CALL_MODE_BASIC_TYPE]. - - - [code]call_mode[/code] determines the target object on which the method will be called. See [enum CallMode] for options. - - - The name of the function to be called. - - - The node path to use when [member call_mode] is set to [constant CALL_MODE_NODE_PATH]. - - - The mode for RPC calls. See [method Node.rpc] for more details and [enum RPCCallMode] for available options. - - - The singleton to call the method on. Used when [member call_mode] is set to [constant CALL_MODE_SINGLETON]. - - - Number of default arguments that will be used when calling the function. Can't be higher than the number of available default arguments in the method's declaration. - - - If [code]false[/code], call errors (e.g. wrong number of arguments) will be ignored. - - - - - The method will be called on this [Object]. - - - The method will be called on the given [Node] in the scene tree. - - - The method will be called on an instanced node with the given type and script. - - - The method will be called on a GDScript basic type (e.g. [Vector2]). - - - The method will be called on a singleton. - - - The method will be called locally. - - - The method will be called remotely. - - - The method will be called remotely using an unreliable protocol. - - - The method will be called remotely for the given peer. - - - The method will be called remotely for the given peer, using an unreliable protocol. - - - diff --git a/modules/visual_script/doc_classes/VisualScriptFunctionState.xml b/modules/visual_script/doc_classes/VisualScriptFunctionState.xml deleted file mode 100644 index 03fef9c13b2..00000000000 --- a/modules/visual_script/doc_classes/VisualScriptFunctionState.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - A Visual Script node representing a function state. - - - [VisualScriptFunctionState] is returned from [VisualScriptYield] and can be used to resume a paused function call. - - - - - - - - - - - Connects this [VisualScriptFunctionState] to a signal in the given object to automatically resume when it's emitted. - - - - - - Returns whether the function state is valid. - - - - - - - Resumes the function to run from the point it was yielded. - - - - diff --git a/modules/visual_script/doc_classes/VisualScriptGlobalConstant.xml b/modules/visual_script/doc_classes/VisualScriptGlobalConstant.xml deleted file mode 100644 index 42ada992575..00000000000 --- a/modules/visual_script/doc_classes/VisualScriptGlobalConstant.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - A Visual Script node returning a constant from [@GlobalScope]. - - - A Visual Script node returning a constant from [@GlobalScope]. - - - - - - The constant to be used. - - - diff --git a/modules/visual_script/doc_classes/VisualScriptIndexGet.xml b/modules/visual_script/doc_classes/VisualScriptIndexGet.xml deleted file mode 100644 index 8828bf90398..00000000000 --- a/modules/visual_script/doc_classes/VisualScriptIndexGet.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - A Visual Script node for getting a value from an array or a dictionary. - - - [VisualScriptIndexGet] will return the value stored in an array or a dictionary under the given index. - - - - diff --git a/modules/visual_script/doc_classes/VisualScriptIndexSet.xml b/modules/visual_script/doc_classes/VisualScriptIndexSet.xml deleted file mode 100644 index 5c81dcd3393..00000000000 --- a/modules/visual_script/doc_classes/VisualScriptIndexSet.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - A Visual Script node for setting a value in an array or a dictionary. - - - [VisualScriptIndexSet] will set the value stored in an array or a dictionary under the given index to the provided new value. - - - - diff --git a/modules/visual_script/doc_classes/VisualScriptInputAction.xml b/modules/visual_script/doc_classes/VisualScriptInputAction.xml deleted file mode 100644 index 51c2eaf3539..00000000000 --- a/modules/visual_script/doc_classes/VisualScriptInputAction.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - A Visual Script node returning a state of an action. - - - [VisualScriptInputAction] can be used to check if an action is pressed or released. - - - - - - Name of the action. - - - State of the action to check. See [enum Mode] for options. - - - - - [code]True[/code] if action is pressed. - - - [code]True[/code] if action is released (i.e. not pressed). - - - [code]True[/code] on the frame the action was pressed. - - - [code]True[/code] on the frame the action was released. - - - diff --git a/modules/visual_script/doc_classes/VisualScriptIterator.xml b/modules/visual_script/doc_classes/VisualScriptIterator.xml deleted file mode 100644 index ef6846debac..00000000000 --- a/modules/visual_script/doc_classes/VisualScriptIterator.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - Steps through items in a given input. - - - This node steps through each item in a given input. Input can be any sequence data type, such as an [Array] or [String]. When each item has been processed, execution passed out the [code]exit[/code] Sequence port. - [b]Input Ports:[/b] - - Sequence: [code]for (elem) in (input)[/code] - - Data (variant): [code]input[/code] - [b]Output Ports:[/b] - - Sequence: [code]each[/code] - - Sequence: [code]exit[/code] - - Data (variant): [code]elem[/code] - - - - diff --git a/modules/visual_script/doc_classes/VisualScriptLists.xml b/modules/visual_script/doc_classes/VisualScriptLists.xml deleted file mode 100644 index 607965bf71a..00000000000 --- a/modules/visual_script/doc_classes/VisualScriptLists.xml +++ /dev/null @@ -1,77 +0,0 @@ - - - - A Visual Script virtual class for in-graph editable nodes. - - - A Visual Script virtual class that defines the shape and the default behavior of the nodes that have to be in-graph editable nodes. - - - - - - - - - - - Adds an input port to the Visual Script node. - - - - - - - - - Adds an output port to the Visual Script node. - - - - - - - Removes an input port from the Visual Script node. - - - - - - - Removes an output port from the Visual Script node. - - - - - - - - Sets the name of an input port. - - - - - - - - Sets the type of an input port. - - - - - - - - Sets the name of an output port. - - - - - - - - Sets the type of an output port. - - - - diff --git a/modules/visual_script/doc_classes/VisualScriptLocalVar.xml b/modules/visual_script/doc_classes/VisualScriptLocalVar.xml deleted file mode 100644 index dbf9049f0ab..00000000000 --- a/modules/visual_script/doc_classes/VisualScriptLocalVar.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - Gets a local variable's value. - - - Returns a local variable's value. "Var Name" must be supplied, with an optional type. - [b]Input Ports:[/b] - none - [b]Output Ports:[/b] - - Data (variant): [code]get[/code] - - - - - - The local variable's type. - - - The local variable's name. - - - diff --git a/modules/visual_script/doc_classes/VisualScriptLocalVarSet.xml b/modules/visual_script/doc_classes/VisualScriptLocalVarSet.xml deleted file mode 100644 index 1ae4e20f974..00000000000 --- a/modules/visual_script/doc_classes/VisualScriptLocalVarSet.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - Changes a local variable's value. - - - Changes a local variable's value to the given input. The new value is also provided on an output Data port. - [b]Input Ports:[/b] - - Sequence - - Data (variant): [code]set[/code] - [b]Output Ports:[/b] - - Sequence - - Data (variant): [code]get[/code] - - - - - - The local variable's type. - - - The local variable's name. - - - diff --git a/modules/visual_script/doc_classes/VisualScriptMathConstant.xml b/modules/visual_script/doc_classes/VisualScriptMathConstant.xml deleted file mode 100644 index 01c36e763b3..00000000000 --- a/modules/visual_script/doc_classes/VisualScriptMathConstant.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - Commonly used mathematical constants. - - - Provides common math constants, such as Pi, on an output Data port. - [b]Input Ports:[/b] - none - [b]Output Ports:[/b] - - Data (variant): [code]get[/code] - - - - - - The math constant. - - - - - Unity: [code]1[/code]. - - - Pi: [code]3.141593[/code]. - - - Pi divided by two: [code]1.570796[/code]. - - - Tau: [code]6.283185[/code]. - - - Mathematical constant [code]e[/code], the natural log base: [code]2.718282[/code]. - - - Square root of two: [code]1.414214[/code]. - - - Infinity: [code]inf[/code]. - - - Not a number: [code]nan[/code]. - - - Represents the size of the [enum MathConstant] enum. - - - diff --git a/modules/visual_script/doc_classes/VisualScriptNode.xml b/modules/visual_script/doc_classes/VisualScriptNode.xml deleted file mode 100644 index 97c4f8ce768..00000000000 --- a/modules/visual_script/doc_classes/VisualScriptNode.xml +++ /dev/null @@ -1,47 +0,0 @@ - - - - A node which is part of a [VisualScript]. - - - A node which is part of a [VisualScript]. Not to be confused with [Node], which is a part of a [SceneTree]. - - - - - - - - - Returns the default value of a given port. The default value is used when nothing is connected to the port. - - - - - - Returns the [VisualScript] instance the node is bound to. - - - - - - Notify that the node's ports have changed. Usually used in conjunction with [VisualScriptCustomNode] . - - - - - - - - Change the default value of a given port. - - - - - - - Emitted when the available input/output ports are changed. - - - - diff --git a/modules/visual_script/doc_classes/VisualScriptOperator.xml b/modules/visual_script/doc_classes/VisualScriptOperator.xml deleted file mode 100644 index 47ca6ddb907..00000000000 --- a/modules/visual_script/doc_classes/VisualScriptOperator.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - A Visual Script node that performs an operation on two values. - - - [b]Input Ports:[/b] - - Data (variant): [code]A[/code] - - Data (variant): [code]B[/code] - [b]Output Ports:[/b] - - Data (variant): [code]result[/code] - - - - - - The operation to be performed. See [enum Variant.Operator] for available options. - - - The type of the values for this operation. See [enum Variant.Type] for available options. - - - diff --git a/modules/visual_script/doc_classes/VisualScriptPreload.xml b/modules/visual_script/doc_classes/VisualScriptPreload.xml deleted file mode 100644 index 146d6cd9c3a..00000000000 --- a/modules/visual_script/doc_classes/VisualScriptPreload.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - Creates a new [Resource] or loads one from the filesystem. - - - Creates a new [Resource] or loads one from the filesystem. - [b]Input Ports:[/b] - none - [b]Output Ports:[/b] - - Data (object): [code]res[/code] - - - - - - The [Resource] to load. - - - diff --git a/modules/visual_script/doc_classes/VisualScriptPropertyGet.xml b/modules/visual_script/doc_classes/VisualScriptPropertyGet.xml deleted file mode 100644 index 77cd6393a90..00000000000 --- a/modules/visual_script/doc_classes/VisualScriptPropertyGet.xml +++ /dev/null @@ -1,48 +0,0 @@ - - - - A Visual Script node returning a value of a property from an [Object]. - - - [VisualScriptPropertyGet] can return a value of any property from the current object or other objects. - - - - - - The script to be used when [member set_mode] is set to [constant CALL_MODE_INSTANCE]. - - - The base type to be used when [member set_mode] is set to [constant CALL_MODE_INSTANCE]. - - - The type to be used when [member set_mode] is set to [constant CALL_MODE_BASIC_TYPE]. - - - The indexed name of the property to retrieve. See [method Object.get_indexed] for details. - - - The node path to use when [member set_mode] is set to [constant CALL_MODE_NODE_PATH]. - - - The name of the property to retrieve. Changing this will clear [member index]. - - - [code]set_mode[/code] determines the target object from which the property will be retrieved. See [enum CallMode] for options. - - - - - The property will be retrieved from this [Object]. - - - The property will be retrieved from the given [Node] in the scene tree. - - - The property will be retrieved from an instanced node with the given type and script. - - - The property will be retrieved from a GDScript basic type (e.g. [Vector2]). - - - diff --git a/modules/visual_script/doc_classes/VisualScriptPropertySet.xml b/modules/visual_script/doc_classes/VisualScriptPropertySet.xml deleted file mode 100644 index 6cffa328c73..00000000000 --- a/modules/visual_script/doc_classes/VisualScriptPropertySet.xml +++ /dev/null @@ -1,84 +0,0 @@ - - - - A Visual Script node that sets a property of an [Object]. - - - [VisualScriptPropertySet] can set the value of any property from the current object or other objects. - - - - - - The additional operation to perform when assigning. See [enum AssignOp] for options. - - - The script to be used when [member set_mode] is set to [constant CALL_MODE_INSTANCE]. - - - The base type to be used when [member set_mode] is set to [constant CALL_MODE_INSTANCE]. - - - The type to be used when [member set_mode] is set to [constant CALL_MODE_BASIC_TYPE]. - - - The indexed name of the property to set. See [method Object.set_indexed] for details. - - - The node path to use when [member set_mode] is set to [constant CALL_MODE_NODE_PATH]. - - - The name of the property to set. Changing this will clear [member index]. - - - [code]set_mode[/code] determines the target object on which the property will be set. See [enum CallMode] for options. - - - - - The property will be set on this [Object]. - - - The property will be set on the given [Node] in the scene tree. - - - The property will be set on an instanced node with the given type and script. - - - The property will be set on a GDScript basic type (e.g. [Vector2]). - - - The property will be assigned regularly. - - - The value will be added to the property. Equivalent of doing [code]+=[/code]. - - - The value will be subtracted from the property. Equivalent of doing [code]-=[/code]. - - - The property will be multiplied by the value. Equivalent of doing [code]*=[/code]. - - - The property will be divided by the value. Equivalent of doing [code]/=[/code]. - - - A modulo operation will be performed on the property and the value. Equivalent of doing [code]%=[/code]. - - - The property will be binarly shifted to the left by the given value. Equivalent of doing [code]<<[/code]. - - - The property will be binarly shifted to the right by the given value. Equivalent of doing [code]>>[/code]. - - - A binary [code]AND[/code] operation will be performed on the property. Equivalent of doing [code]&=[/code]. - - - A binary [code]OR[/code] operation will be performed on the property. Equivalent of doing [code]|=[/code]. - - - A binary [code]XOR[/code] operation will be performed on the property. Equivalent of doing [code]^=[/code]. - - - diff --git a/modules/visual_script/doc_classes/VisualScriptResourcePath.xml b/modules/visual_script/doc_classes/VisualScriptResourcePath.xml deleted file mode 100644 index 6ca8260ade9..00000000000 --- a/modules/visual_script/doc_classes/VisualScriptResourcePath.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - diff --git a/modules/visual_script/doc_classes/VisualScriptReturn.xml b/modules/visual_script/doc_classes/VisualScriptReturn.xml deleted file mode 100644 index 1d593927823..00000000000 --- a/modules/visual_script/doc_classes/VisualScriptReturn.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - Exits a function and returns an optional value. - - - Ends the execution of a function and returns control to the calling function. Optionally, it can return a [Variant] value. - [b]Input Ports:[/b] - - Sequence - - Data (variant): [code]result[/code] (optional) - [b]Output Ports:[/b] - none - - - - - - If [code]true[/code], the [code]return[/code] input port is available. - - - The return value's data type. - - - diff --git a/modules/visual_script/doc_classes/VisualScriptSceneNode.xml b/modules/visual_script/doc_classes/VisualScriptSceneNode.xml deleted file mode 100644 index a769d11d941..00000000000 --- a/modules/visual_script/doc_classes/VisualScriptSceneNode.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - Node reference. - - - A direct reference to a node. - [b]Input Ports:[/b] - none - [b]Output Ports:[/b] - - Data: [code]node[/code] (obj) - - - - - - The node's path in the scene tree. - - - diff --git a/modules/visual_script/doc_classes/VisualScriptSceneTree.xml b/modules/visual_script/doc_classes/VisualScriptSceneTree.xml deleted file mode 100644 index 84ab90892f8..00000000000 --- a/modules/visual_script/doc_classes/VisualScriptSceneTree.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - A Visual Script node for accessing [SceneTree] methods. - - - A Visual Script node for accessing [SceneTree] methods. - - - - diff --git a/modules/visual_script/doc_classes/VisualScriptSelect.xml b/modules/visual_script/doc_classes/VisualScriptSelect.xml deleted file mode 100644 index 1aa916f7795..00000000000 --- a/modules/visual_script/doc_classes/VisualScriptSelect.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - Chooses between two input values. - - - Chooses between two input values based on a Boolean condition. - [b]Input Ports:[/b] - - Data (boolean): [code]cond[/code] - - Data (variant): [code]a[/code] - - Data (variant): [code]b[/code] - [b]Output Ports:[/b] - - Data (variant): [code]out[/code] - - - - - - The input variables' type. - - - diff --git a/modules/visual_script/doc_classes/VisualScriptSelf.xml b/modules/visual_script/doc_classes/VisualScriptSelf.xml deleted file mode 100644 index 8cc59dbccdc..00000000000 --- a/modules/visual_script/doc_classes/VisualScriptSelf.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - Outputs a reference to the current instance. - - - Provides a reference to the node running the visual script. - [b]Input Ports:[/b] - none - [b]Output Ports:[/b] - - Data (object): [code]instance[/code] - - - - diff --git a/modules/visual_script/doc_classes/VisualScriptSequence.xml b/modules/visual_script/doc_classes/VisualScriptSequence.xml deleted file mode 100644 index 9adbc30e0d2..00000000000 --- a/modules/visual_script/doc_classes/VisualScriptSequence.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - Executes a series of Sequence ports. - - - Steps through a series of one or more output Sequence ports. The [code]current[/code] data port outputs the currently executing item. - [b]Input Ports:[/b] - - Sequence: [code]in order[/code] - [b]Output Ports:[/b] - - Sequence: [code]1[/code] - - Sequence: [code]2 - n[/code] (optional) - - Data (int): [code]current[/code] - - - - - - The number of steps in the sequence. - - - diff --git a/modules/visual_script/doc_classes/VisualScriptSubCall.xml b/modules/visual_script/doc_classes/VisualScriptSubCall.xml deleted file mode 100644 index 535e89fc829..00000000000 --- a/modules/visual_script/doc_classes/VisualScriptSubCall.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - Calls a method called [code]_subcall[/code] in this object. - - - [VisualScriptSubCall] will call method named [code]_subcall[/code] in the current script. It will fail if the method doesn't exist or the provided arguments are wrong. - - - - diff --git a/modules/visual_script/doc_classes/VisualScriptSwitch.xml b/modules/visual_script/doc_classes/VisualScriptSwitch.xml deleted file mode 100644 index 7befe89f508..00000000000 --- a/modules/visual_script/doc_classes/VisualScriptSwitch.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - Branches program flow based on a given input's value. - - - Branches the flow based on an input's value. Use [b]Case Count[/b] in the Inspector to set the number of branches and each comparison's optional type. - [b]Input Ports:[/b] - - Sequence: [code]'input' is[/code] - - Data (variant): [code]=[/code] - - Data (variant): [code]=[/code] (optional) - - Data (variant): [code]input[/code] - [b]Output Ports:[/b] - - Sequence - - Sequence (optional) - - Sequence: [code]done[/code] - - - - diff --git a/modules/visual_script/doc_classes/VisualScriptTypeCast.xml b/modules/visual_script/doc_classes/VisualScriptTypeCast.xml deleted file mode 100644 index ec84a756018..00000000000 --- a/modules/visual_script/doc_classes/VisualScriptTypeCast.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - A Visual Script node that casts the given value to another type. - - - [VisualScriptTypeCast] will perform a type conversion to an [Object]-derived type. - - - - - - The target script class to be converted to. If none, only the [member base_type] will be used. - - - The target type to be converted to. - - - diff --git a/modules/visual_script/doc_classes/VisualScriptVariableGet.xml b/modules/visual_script/doc_classes/VisualScriptVariableGet.xml deleted file mode 100644 index 8d99b4b9d0d..00000000000 --- a/modules/visual_script/doc_classes/VisualScriptVariableGet.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - Gets a variable's value. - - - Returns a variable's value. "Var Name" must be supplied, with an optional type. - [b]Input Ports:[/b] - none - [b]Output Ports:[/b] - - Data (variant): [code]value[/code] - - - - - - The variable's name. - - - diff --git a/modules/visual_script/doc_classes/VisualScriptVariableSet.xml b/modules/visual_script/doc_classes/VisualScriptVariableSet.xml deleted file mode 100644 index 4f568cc0f63..00000000000 --- a/modules/visual_script/doc_classes/VisualScriptVariableSet.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - Changes a variable's value. - - - Changes a variable's value to the given input. - [b]Input Ports:[/b] - - Sequence - - Data (variant): [code]set[/code] - [b]Output Ports:[/b] - - Sequence - - - - - - The variable's name. - - - diff --git a/modules/visual_script/doc_classes/VisualScriptWhile.xml b/modules/visual_script/doc_classes/VisualScriptWhile.xml deleted file mode 100644 index 4e7cccef176..00000000000 --- a/modules/visual_script/doc_classes/VisualScriptWhile.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - Conditional loop. - - - Loops while a condition is [code]true[/code]. Execution continues out the [code]exit[/code] Sequence port when the loop terminates. - [b]Input Ports:[/b] - - Sequence: [code]while(cond)[/code] - - Data (bool): [code]cond[/code] - [b]Output Ports:[/b] - - Sequence: [code]repeat[/code] - - Sequence: [code]exit[/code] - - - - diff --git a/modules/visual_script/doc_classes/VisualScriptYield.xml b/modules/visual_script/doc_classes/VisualScriptYield.xml deleted file mode 100644 index ec757a3ac42..00000000000 --- a/modules/visual_script/doc_classes/VisualScriptYield.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - A Visual Script node used to pause a function execution. - - - [VisualScriptYield] will pause the function call and return [VisualScriptFunctionState], which can be used to resume the function. - - - - - - The mode to use for yielding. See [enum YieldMode] for available options. - - - The time to wait when [member mode] is set to [constant YIELD_WAIT]. - - - - - Yields during an idle frame. - - - Yields during a physics frame. - - - Yields a function and waits the given time. - - - diff --git a/modules/visual_script/doc_classes/VisualScriptYieldSignal.xml b/modules/visual_script/doc_classes/VisualScriptYieldSignal.xml deleted file mode 100644 index c3f4bc49c5e..00000000000 --- a/modules/visual_script/doc_classes/VisualScriptYieldSignal.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - A Visual Script node yielding for a signal. - - - [VisualScriptYieldSignal] will pause the function execution until the provided signal is emitted. - - - - - - The base type to be used when [member call_mode] is set to [constant CALL_MODE_INSTANCE]. - - - [code]call_mode[/code] determines the target object to wait for the signal emission. See [enum CallMode] for options. - - - The node path to use when [member call_mode] is set to [constant CALL_MODE_NODE_PATH]. - - - The signal name to be waited for. - - - - - A signal from this [Object] will be used. - - - A signal from the given [Node] in the scene tree will be used. - - - A signal from an instanced node with the given type will be used. - - - diff --git a/modules/visual_script/editor/visual_script_editor.cpp b/modules/visual_script/editor/visual_script_editor.cpp deleted file mode 100644 index fec48d18075..00000000000 --- a/modules/visual_script/editor/visual_script_editor.cpp +++ /dev/null @@ -1,4976 +0,0 @@ -/*************************************************************************/ -/* visual_script_editor.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* 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 "visual_script_editor.h" - -#include "../visual_script_expression.h" -#include "../visual_script_flow_control.h" -#include "../visual_script_func_nodes.h" -#include "../visual_script_nodes.h" -#include "core/input/input.h" -#include "core/object/class_db.h" -#include "core/object/script_language.h" -#include "core/os/keyboard.h" -#include "core/variant/variant.h" -#include "editor/editor_node.h" -#include "editor/editor_resource_preview.h" -#include "editor/editor_scale.h" -#include "editor/editor_settings.h" -#include "editor/editor_undo_redo_manager.h" -#include "scene/gui/check_button.h" -#include "scene/gui/graph_edit.h" -#include "scene/gui/separator.h" -#include "scene/gui/view_panner.h" -#include "scene/main/window.h" - -#ifdef TOOLS_ENABLED - -void VisualScriptEditedProperty::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_edited_property", "value"), &VisualScriptEditedProperty::set_edited_property); - ClassDB::bind_method(D_METHOD("get_edited_property"), &VisualScriptEditedProperty::get_edited_property); - - ADD_PROPERTY(PropertyInfo(Variant::NIL, "edited_property", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT), "set_edited_property", "get_edited_property"); -} - -void VisualScriptEditedProperty::set_edited_property(Variant p_variant) { - edited_property = p_variant; -} - -Variant VisualScriptEditedProperty::get_edited_property() const { - return edited_property; -} - -///////////////// - -class VisualScriptEditorSignalEdit : public Object { - GDCLASS(VisualScriptEditorSignalEdit, Object); - - StringName sig; - -public: - Ref undo_redo; - Ref script; - -protected: - static void _bind_methods() { - ClassDB::bind_method("_sig_changed", &VisualScriptEditorSignalEdit::_sig_changed); - ADD_SIGNAL(MethodInfo("changed")); - } - - void _sig_changed() { - notify_property_list_changed(); - emit_signal(SNAME("changed")); - } - - bool _set(const StringName &p_name, const Variant &p_value) { - if (sig == StringName()) { - return false; - } - - if (p_name == "argument_count") { - int new_argc = p_value; - int argc = script->custom_signal_get_argument_count(sig); - if (argc == new_argc) { - return true; - } - - undo_redo->create_action(TTR("Change Signal Arguments")); - - if (new_argc < argc) { - for (int i = new_argc; i < argc; i++) { - undo_redo->add_do_method(script.ptr(), "custom_signal_remove_argument", sig, new_argc); - undo_redo->add_undo_method(script.ptr(), "custom_signal_add_argument", sig, script->custom_signal_get_argument_name(sig, i), script->custom_signal_get_argument_type(sig, i), -1); - } - } else if (new_argc > argc) { - for (int i = argc; i < new_argc; i++) { - undo_redo->add_do_method(script.ptr(), "custom_signal_add_argument", sig, Variant::NIL, "arg" + itos(i + 1), -1); - undo_redo->add_undo_method(script.ptr(), "custom_signal_remove_argument", sig, argc); - } - } - - undo_redo->add_do_method(this, "_sig_changed"); - undo_redo->add_undo_method(this, "_sig_changed"); - - undo_redo->commit_action(); - - return true; - } - if (String(p_name).begins_with("argument/")) { - int idx = String(p_name).get_slice("/", 1).to_int() - 1; - ERR_FAIL_INDEX_V(idx, script->custom_signal_get_argument_count(sig), false); - String what = String(p_name).get_slice("/", 2); - if (what == "type") { - int old_type = script->custom_signal_get_argument_type(sig, idx); - int new_type = p_value; - undo_redo->create_action(TTR("Change Argument Type")); - undo_redo->add_do_method(script.ptr(), "custom_signal_set_argument_type", sig, idx, new_type); - undo_redo->add_undo_method(script.ptr(), "custom_signal_set_argument_type", sig, idx, old_type); - undo_redo->commit_action(); - - return true; - } - - if (what == "name") { - String old_name = script->custom_signal_get_argument_name(sig, idx); - String new_name = p_value; - undo_redo->create_action(TTR("Change Argument name")); - undo_redo->add_do_method(script.ptr(), "custom_signal_set_argument_name", sig, idx, new_name); - undo_redo->add_undo_method(script.ptr(), "custom_signal_set_argument_name", sig, idx, old_name); - undo_redo->commit_action(); - return true; - } - } - - return false; - } - - bool _get(const StringName &p_name, Variant &r_ret) const { - if (sig == StringName()) { - return false; - } - - if (p_name == "argument_count") { - r_ret = script->custom_signal_get_argument_count(sig); - return true; - } - if (String(p_name).begins_with("argument/")) { - int idx = String(p_name).get_slice("/", 1).to_int() - 1; - ERR_FAIL_INDEX_V(idx, script->custom_signal_get_argument_count(sig), false); - String what = String(p_name).get_slice("/", 2); - if (what == "type") { - r_ret = script->custom_signal_get_argument_type(sig, idx); - return true; - } - if (what == "name") { - r_ret = script->custom_signal_get_argument_name(sig, idx); - return true; - } - } - - return false; - } - void _get_property_list(List *p_list) const { - if (sig == StringName()) { - return; - } - - p_list->push_back(PropertyInfo(Variant::INT, "argument_count", PROPERTY_HINT_RANGE, "0,256")); - String argt = "Variant"; - for (int i = 1; i < Variant::VARIANT_MAX; i++) { - argt += "," + Variant::get_type_name(Variant::Type(i)); - } - - for (int i = 0; i < script->custom_signal_get_argument_count(sig); i++) { - p_list->push_back(PropertyInfo(Variant::INT, "argument/" + itos(i + 1) + "/type", PROPERTY_HINT_ENUM, argt)); - p_list->push_back(PropertyInfo(Variant::STRING, "argument/" + itos(i + 1) + "/name")); - } - } - -public: - void edit(const StringName &p_sig) { - sig = p_sig; - notify_property_list_changed(); - } -}; - -class VisualScriptEditorVariableEdit : public Object { - GDCLASS(VisualScriptEditorVariableEdit, Object); - - StringName var; - -public: - Ref undo_redo; - Ref script; - -protected: - static void _bind_methods() { - ClassDB::bind_method("_var_changed", &VisualScriptEditorVariableEdit::_var_changed); - ClassDB::bind_method("_var_value_changed", &VisualScriptEditorVariableEdit::_var_value_changed); - ADD_SIGNAL(MethodInfo("changed")); - } - - void _var_changed() { - notify_property_list_changed(); - emit_signal(SNAME("changed")); - } - void _var_value_changed() { - emit_signal(SNAME("changed")); - } - - bool _set(const StringName &p_name, const Variant &p_value) { - if (var == StringName()) { - return false; - } - - if (String(p_name) == "value") { - undo_redo->create_action(TTR("Set Variable Default Value")); - Variant current = script->get_variable_default_value(var); - undo_redo->add_do_method(script.ptr(), "set_variable_default_value", var, p_value); - undo_redo->add_undo_method(script.ptr(), "set_variable_default_value", var, current); - undo_redo->add_do_method(this, "_var_value_changed"); - undo_redo->add_undo_method(this, "_var_value_changed"); - undo_redo->commit_action(); - return true; - } - - Dictionary d = script->call("get_variable_info", var); - - if (String(p_name) == "type") { - Dictionary dc = d.duplicate(); - dc["type"] = p_value; - undo_redo->create_action(TTR("Set Variable Type")); - undo_redo->add_do_method(script.ptr(), "set_variable_info", var, dc); - undo_redo->add_undo_method(script.ptr(), "set_variable_info", var, d); - - // Setting the default value. - Variant::Type type = (Variant::Type)(int)p_value; - if (type != Variant::NIL) { - Variant default_value; - Callable::CallError ce; - Variant::construct(type, default_value, nullptr, 0, ce); - if (ce.error == Callable::CallError::CALL_OK) { - undo_redo->add_do_method(script.ptr(), "set_variable_default_value", var, default_value); - undo_redo->add_undo_method(script.ptr(), "set_variable_default_value", var, dc["value"]); - } - } - - undo_redo->add_do_method(this, "_var_changed"); - undo_redo->add_undo_method(this, "_var_changed"); - undo_redo->commit_action(); - return true; - } - - if (String(p_name) == "hint") { - Dictionary dc = d.duplicate(); - dc["hint"] = p_value; - undo_redo->create_action(TTR("Set Variable Type")); - undo_redo->add_do_method(script.ptr(), "set_variable_info", var, dc); - undo_redo->add_undo_method(script.ptr(), "set_variable_info", var, d); - undo_redo->add_do_method(this, "_var_changed"); - undo_redo->add_undo_method(this, "_var_changed"); - undo_redo->commit_action(); - return true; - } - - if (String(p_name) == "hint_string") { - Dictionary dc = d.duplicate(); - dc["hint_string"] = p_value; - undo_redo->create_action(TTR("Set Variable Type")); - undo_redo->add_do_method(script.ptr(), "set_variable_info", var, dc); - undo_redo->add_undo_method(script.ptr(), "set_variable_info", var, d); - undo_redo->add_do_method(this, "_var_changed"); - undo_redo->add_undo_method(this, "_var_changed"); - undo_redo->commit_action(); - return true; - } - - if (String(p_name) == "export") { - script->set_variable_export(var, p_value); - InspectorDock::get_inspector_singleton()->update_tree(); - return true; - } - - return false; - } - - bool _get(const StringName &p_name, Variant &r_ret) const { - if (var == StringName()) { - return false; - } - - if (String(p_name) == "value") { - r_ret = script->get_variable_default_value(var); - return true; - } - - PropertyInfo pinfo = script->get_variable_info(var); - - if (String(p_name) == "type") { - r_ret = pinfo.type; - return true; - } - if (String(p_name) == "hint") { - r_ret = pinfo.hint; - return true; - } - if (String(p_name) == "hint_string") { - r_ret = pinfo.hint_string; - return true; - } - - if (String(p_name) == "export") { - r_ret = script->get_variable_export(var); - return true; - } - - return false; - } - void _get_property_list(List *p_list) const { - if (var == StringName()) { - return; - } - - String argt = "Variant"; - for (int i = 1; i < Variant::VARIANT_MAX; i++) { - argt += "," + Variant::get_type_name(Variant::Type(i)); - } - p_list->push_back(PropertyInfo(Variant::INT, "type", PROPERTY_HINT_ENUM, argt)); - p_list->push_back(PropertyInfo(script->get_variable_info(var).type, "value", script->get_variable_info(var).hint, script->get_variable_info(var).hint_string, PROPERTY_USAGE_DEFAULT)); - // Update this when PropertyHint changes. - p_list->push_back(PropertyInfo(Variant::INT, "hint", PROPERTY_HINT_ENUM, "None,Range,ExpRange,Enum,ExpEasing,Length,SpriteFrame,KeyAccel,Flags,Layers2dRender,Layers2dPhysics,Layer3dRender,Layer3dPhysics,File,Dir,GlobalFile,GlobalDir,ResourceType,MultilineText,PlaceholderText,ColorNoAlpha,ImageCompressLossy,ImageCompressLossLess,ObjectId,String,NodePathToEditedNode,MethodOfVariantType,MethodOfBaseType,MethodOfInstance,MethodOfScript,PropertyOfVariantType,PropertyOfBaseType,PropertyOfInstance,PropertyOfScript,ObjectTooBig,NodePathValidTypes")); - p_list->push_back(PropertyInfo(Variant::STRING, "hint_string")); - p_list->push_back(PropertyInfo(Variant::BOOL, "export")); - } - -public: - void edit(const StringName &p_var) { - var = p_var; - notify_property_list_changed(); - } -}; - -static Color _color_from_type(Variant::Type p_type, bool dark_theme = true) { - Color color; - if (dark_theme) { - switch (p_type) { - case Variant::NIL: - color = Color(0.41, 0.93, 0.74); - break; - - case Variant::BOOL: - color = Color(0.55, 0.65, 0.94); - break; - case Variant::INT: - color = Color(0.49, 0.78, 0.94); - break; - case Variant::FLOAT: - color = Color(0.38, 0.85, 0.96); - break; - case Variant::STRING: - color = Color(0.42, 0.65, 0.93); - break; - - case Variant::VECTOR2: - color = Color(0.74, 0.57, 0.95); - break; - case Variant::VECTOR2I: - color = Color(0.74, 0.57, 0.95); - break; - case Variant::RECT2: - color = Color(0.95, 0.57, 0.65); - break; - case Variant::RECT2I: - color = Color(0.95, 0.57, 0.65); - break; - case Variant::VECTOR3: - color = Color(0.84, 0.49, 0.93); - break; - case Variant::VECTOR3I: - color = Color(0.84, 0.49, 0.93); - break; - case Variant::VECTOR4: - color = Color(0.84, 0.49, 0.94); - break; - case Variant::VECTOR4I: - color = Color(0.84, 0.49, 0.94); - break; - case Variant::TRANSFORM2D: - color = Color(0.77, 0.93, 0.41); - break; - case Variant::PLANE: - color = Color(0.97, 0.44, 0.44); - break; - case Variant::QUATERNION: - color = Color(0.93, 0.41, 0.64); - break; - case Variant::AABB: - color = Color(0.93, 0.47, 0.57); - break; - case Variant::BASIS: - color = Color(0.89, 0.93, 0.41); - break; - case Variant::TRANSFORM3D: - color = Color(0.96, 0.66, 0.43); - break; - - case Variant::COLOR: - color = Color(0.62, 1.0, 0.44); - break; - case Variant::NODE_PATH: - color = Color(0.41, 0.58, 0.93); - break; - case Variant::RID: - color = Color(0.41, 0.93, 0.6); - break; - case Variant::OBJECT: - color = Color(0.47, 0.95, 0.91); - break; - case Variant::DICTIONARY: - color = Color(0.47, 0.93, 0.69); - break; - - case Variant::ARRAY: - color = Color(0.88, 0.88, 0.88); - break; - case Variant::PACKED_BYTE_ARRAY: - color = Color(0.67, 0.96, 0.78); - break; - case Variant::PACKED_INT32_ARRAY: - color = Color(0.69, 0.86, 0.96); - break; - case Variant::PACKED_FLOAT32_ARRAY: - color = Color(0.59, 0.91, 0.97); - break; - case Variant::PACKED_INT64_ARRAY: - color = Color(0.69, 0.86, 0.96); - break; - case Variant::PACKED_FLOAT64_ARRAY: - color = Color(0.59, 0.91, 0.97); - break; - case Variant::PACKED_STRING_ARRAY: - color = Color(0.62, 0.77, 0.95); - break; - case Variant::PACKED_VECTOR2_ARRAY: - color = Color(0.82, 0.7, 0.96); - break; - case Variant::PACKED_VECTOR3_ARRAY: - color = Color(0.87, 0.61, 0.95); - break; - case Variant::PACKED_COLOR_ARRAY: - color = Color(0.91, 1.0, 0.59); - break; - - default: - color.set_hsv(p_type / float(Variant::VARIANT_MAX), 0.7, 0.7); - } - } else { - switch (p_type) { - case Variant::NIL: - color = Color(0.15, 0.89, 0.63); - break; - - case Variant::BOOL: - color = Color(0.43, 0.56, 0.92); - break; - case Variant::INT: - color = Color(0.31, 0.7, 0.91); - break; - case Variant::FLOAT: - color = Color(0.15, 0.8, 0.94); - break; - case Variant::STRING: - color = Color(0.27, 0.56, 0.91); - break; - - case Variant::VECTOR2: - color = Color(0.68, 0.46, 0.93); - break; - case Variant::VECTOR2I: - color = Color(0.68, 0.46, 0.93); - break; - case Variant::RECT2: - color = Color(0.93, 0.46, 0.56); - break; - case Variant::RECT2I: - color = Color(0.93, 0.46, 0.56); - break; - case Variant::VECTOR3: - color = Color(0.86, 0.42, 0.93); - break; - case Variant::VECTOR3I: - color = Color(0.86, 0.42, 0.93); - break; - case Variant::TRANSFORM2D: - color = Color(0.59, 0.81, 0.1); - break; - case Variant::PLANE: - color = Color(0.97, 0.44, 0.44); - break; - case Variant::QUATERNION: - color = Color(0.93, 0.41, 0.64); - break; - case Variant::AABB: - color = Color(0.93, 0.47, 0.57); - break; - case Variant::BASIS: - color = Color(0.7, 0.73, 0.1); - break; - case Variant::TRANSFORM3D: - color = Color(0.96, 0.56, 0.28); - break; - - case Variant::COLOR: - color = Color(0.24, 0.75, 0.0); - break; - case Variant::NODE_PATH: - color = Color(0.41, 0.58, 0.93); - break; - case Variant::RID: - color = Color(0.17, 0.9, 0.45); - break; - case Variant::OBJECT: - color = Color(0.07, 0.84, 0.76); - break; - case Variant::DICTIONARY: - color = Color(0.34, 0.91, 0.62); - break; - - case Variant::ARRAY: - color = Color(0.45, 0.45, 0.45); - break; - case Variant::PACKED_BYTE_ARRAY: - color = Color(0.38, 0.92, 0.6); - break; - case Variant::PACKED_INT32_ARRAY: - color = Color(0.38, 0.73, 0.92); - break; - case Variant::PACKED_FLOAT32_ARRAY: - color = Color(0.25, 0.83, 0.95); - break; - case Variant::PACKED_INT64_ARRAY: - color = Color(0.38, 0.73, 0.92); - break; - case Variant::PACKED_FLOAT64_ARRAY: - color = Color(0.25, 0.83, 0.95); - break; - case Variant::PACKED_STRING_ARRAY: - color = Color(0.38, 0.62, 0.92); - break; - case Variant::PACKED_VECTOR2_ARRAY: - color = Color(0.62, 0.36, 0.92); - break; - case Variant::PACKED_VECTOR3_ARRAY: - color = Color(0.79, 0.35, 0.92); - break; - case Variant::PACKED_COLOR_ARRAY: - color = Color(0.57, 0.73, 0.0); - break; - - default: - color.set_hsv(p_type / float(Variant::VARIANT_MAX), 0.3, 0.3); - } - } - - return color; -} - -void VisualScriptEditor::_update_graph_connections() { - graph->clear_connections(); - - List sequence_conns; - script->get_sequence_connection_list(&sequence_conns); - - for (const VisualScript::SequenceConnection &E : sequence_conns) { - graph->connect_node(itos(E.from_node), E.from_output, itos(E.to_node), 0); - } - - List data_conns; - script->get_data_connection_list(&data_conns); - - for (VisualScript::DataConnection &dc : data_conns) { - Ref from_node = script->get_node(dc.from_node); - Ref to_node = script->get_node(dc.to_node); - - if (to_node->has_input_sequence_port()) { - dc.to_port++; - } - - dc.from_port += from_node->get_output_sequence_port_count(); - - graph->connect_node(itos(dc.from_node), dc.from_port, itos(dc.to_node), dc.to_port); - } -} - -void VisualScriptEditor::_update_graph(int p_only_id) { - if (updating_graph) { - return; - } - - updating_graph = true; - - //byebye all nodes - if (p_only_id >= 0) { - if (graph->has_node(itos(p_only_id))) { - Node *gid = graph->get_node(itos(p_only_id)); - if (gid) { - memdelete(gid); - } - } - } else { - for (int i = 0; i < graph->get_child_count(); i++) { - if (Object::cast_to(graph->get_child(i))) { - memdelete(graph->get_child(i)); - i--; - } - } - } - graph->show(); - select_func_text->hide(); - - Ref type_icons[Variant::VARIANT_MAX] = { - Control::get_theme_icon(SNAME("Variant"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("bool"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("int"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("float"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("String"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("Vector2"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("Vector2i"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("Rect2"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("Rect2i"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("Vector3"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("Vector3i"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("Transform2D"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("Plane"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("Quaternion"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("AABB"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("Basis"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("Transform3D"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("Color"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("StringName"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("NodePath"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("RID"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("MiniObject"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("Callable"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("Signal"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("Dictionary"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("Array"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("PackedByteArray"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("PackedInt32Array"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("PackedInt64Array"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("PackedFloat32Array"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("PackedFloat64Array"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("PackedStringArray"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("PackedVector2Array"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("PackedVector3Array"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("PackedColorArray"), SNAME("EditorIcons")) - }; - - // Visual script specific theme for MSDF font. - Ref vstheme; - vstheme.instantiate(); - Ref label_font = EditorNode::get_singleton()->get_editor_theme()->get_font("main_msdf", "EditorFonts"); - vstheme->set_font("font", "Label", label_font); - vstheme->set_font("font", "LineEdit", label_font); - vstheme->set_font("font", "Button", label_font); - - Ref seq_port = Control::get_theme_icon(SNAME("VisualShaderPort"), SNAME("EditorIcons")); - List node_ids; - script->get_node_list(&node_ids); - - List ids; - script->get_node_list(&ids); - - for (int &E : ids) { - if (p_only_id >= 0 && p_only_id != E) { - continue; - } - - Ref node = script->get_node(E); - Vector2 pos = script->get_node_position(E); - - GraphNode *gnode = memnew(GraphNode); - gnode->set_title(node->get_caption()); - gnode->set_position_offset(pos * EDSCALE); - if (error_line == E) { - gnode->set_overlay(GraphNode::OVERLAY_POSITION); - } else if (node->is_breakpoint()) { - gnode->set_overlay(GraphNode::OVERLAY_BREAKPOINT); - } - - gnode->set_meta("__vnode", node); - gnode->set_name(itos(E)); - gnode->connect("dragged", callable_mp(this, &VisualScriptEditor::_node_moved).bind(E)); - gnode->connect("close_request", callable_mp(this, &VisualScriptEditor::_remove_node).bind(E), CONNECT_DEFERRED); - - { - Ref v = node; - if (!v.is_valid()) { - gnode->set_show_close_button(true); - } - } - - bool has_gnode_text = false; - - Ref nd_list = node; - bool is_vslist = nd_list.is_valid(); - if (is_vslist) { - HBoxContainer *hbnc = memnew(HBoxContainer); - if (nd_list->is_input_port_editable()) { - has_gnode_text = true; - Button *btn = memnew(Button); - btn->set_text(TTR("Add Input Port")); - hbnc->add_child(btn); - btn->connect("pressed", callable_mp(this, &VisualScriptEditor::_add_input_port).bind(E), CONNECT_DEFERRED); - } - if (nd_list->is_output_port_editable()) { - if (nd_list->is_input_port_editable()) { - hbnc->add_spacer(); - } - has_gnode_text = true; - Button *btn = memnew(Button); - btn->set_text(TTR("Add Output Port")); - hbnc->add_child(btn); - btn->connect("pressed", callable_mp(this, &VisualScriptEditor::_add_output_port).bind(E), CONNECT_DEFERRED); - } - gnode->add_child(hbnc); - } else if (Object::cast_to(node.ptr())) { - has_gnode_text = true; - LineEdit *line_edit = memnew(LineEdit); - line_edit->set_text(node->get_text()); - line_edit->set_expand_to_text_length_enabled(true); - line_edit->add_theme_font_override("font", get_theme_font(SNAME("source"), SNAME("EditorFonts"))); - gnode->add_child(line_edit); - line_edit->connect("text_changed", callable_mp(this, &VisualScriptEditor::_expression_text_changed).bind(E)); - } else { - String text = node->get_text(); - if (!text.is_empty()) { - has_gnode_text = true; - Label *label = memnew(Label); - label->set_text(text); - gnode->add_child(label); - } - } - - if (Object::cast_to(node.ptr())) { - Ref vsc = node; - gnode->set_comment(true); - gnode->set_resizable(true); - gnode->set_custom_minimum_size(vsc->get_size() * EDSCALE); - gnode->connect("resize_request", callable_mp(this, &VisualScriptEditor::_comment_node_resized).bind(E)); - } - - if (node_styles.has(node->get_category())) { - Ref sbf = node_styles[node->get_category()]; - if (gnode->is_comment()) { - sbf = EditorNode::get_singleton()->get_theme_base()->get_theme()->get_stylebox(SNAME("comment"), SNAME("GraphNode")); - } - - Color c = sbf->get_border_color(); - c = ((c.r + c.g + c.b) / 3) < 0.7 ? Color(1.0, 1.0, 1.0, 0.85) : Color(0.0, 0.0, 0.0, 0.85); - Color ic = c; - gnode->add_theme_color_override("title_color", c); - c.a = 1; - gnode->add_theme_color_override("close_color", c); - gnode->add_theme_color_override("resizer_color", ic); - gnode->add_theme_style_override("frame", sbf); - } - - const Color mono_color = get_theme_color(SNAME("mono_color"), SNAME("Editor")); - - int slot_idx = 0; - - bool single_seq_output = node->get_output_sequence_port_count() == 1 && node->get_output_sequence_port_text(0) == String(); - if ((node->has_input_sequence_port() || single_seq_output) || has_gnode_text) { - // IF has_gnode_text is true BUT we have no sequence ports to draw (in here), - // we still draw the disabled default ones to shift up the slots by one, - // so the slots DON'T start with the content text. - - // IF has_gnode_text is false, but we DO want to draw default sequence ports, - // we draw a dummy text to take up the position of the sequence nodes, so all the other ports are still aligned correctly. - if (!has_gnode_text) { - Label *dummy = memnew(Label); - dummy->set_text(" "); - gnode->add_child(dummy); - } - gnode->set_slot(0, node->has_input_sequence_port(), TYPE_SEQUENCE, mono_color, single_seq_output, TYPE_SEQUENCE, mono_color, seq_port, seq_port); - slot_idx++; - } - - int mixed_seq_ports = 0; - - if (!single_seq_output) { - if (node->has_mixed_input_and_sequence_ports()) { - mixed_seq_ports = node->get_output_sequence_port_count(); - } else { - for (int i = 0; i < node->get_output_sequence_port_count(); i++) { - Label *text2 = memnew(Label); - text2->set_text(node->get_output_sequence_port_text(i)); - text2->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_RIGHT); - gnode->add_child(text2); - gnode->set_slot(slot_idx, false, 0, Color(), true, TYPE_SEQUENCE, mono_color, seq_port, seq_port); - slot_idx++; - } - } - } - - for (int i = 0; i < MAX(node->get_output_value_port_count(), MAX(mixed_seq_ports, node->get_input_value_port_count())); i++) { - bool left_ok = false; - Variant::Type left_type = Variant::NIL; - String left_name; - - if (i < node->get_input_value_port_count()) { - PropertyInfo pi = node->get_input_value_port_info(i); - left_ok = true; - left_type = pi.type; - left_name = pi.name; - } - - bool right_ok = false; - Variant::Type right_type = Variant::NIL; - String right_name; - - if (i >= mixed_seq_ports && i < node->get_output_value_port_count() + mixed_seq_ports) { - PropertyInfo pi = node->get_output_value_port_info(i - mixed_seq_ports); - right_ok = true; - right_type = pi.type; - right_name = pi.name; - } - VBoxContainer *vbc = memnew(VBoxContainer); - HBoxContainer *hbc = memnew(HBoxContainer); - HBoxContainer *hbc2 = memnew(HBoxContainer); - vbc->add_child(hbc); - vbc->add_child(hbc2); - if (left_ok) { - Ref t; - if (left_type >= 0 && left_type < Variant::VARIANT_MAX) { - t = type_icons[left_type]; - } - if (t.is_valid()) { - TextureRect *tf = memnew(TextureRect); - tf->set_texture(t); - tf->set_stretch_mode(TextureRect::STRETCH_KEEP_CENTERED); - hbc->add_child(tf); - } - - if (is_vslist) { - if (nd_list->is_input_port_name_editable()) { - LineEdit *name_box = memnew(LineEdit); - hbc->add_child(name_box); - name_box->set_custom_minimum_size(Size2(60 * EDSCALE, 0)); - name_box->set_text(left_name); - name_box->set_expand_to_text_length_enabled(true); - name_box->connect("resized", callable_mp(this, &VisualScriptEditor::_update_node_size).bind(E)); - name_box->connect("focus_exited", callable_mp(this, &VisualScriptEditor::_port_name_focus_out).bind(name_box, E, i, true)); - } else { - hbc->add_child(memnew(Label(left_name))); - } - - if (nd_list->is_input_port_type_editable()) { - OptionButton *opbtn = memnew(OptionButton); - for (int j = Variant::NIL; j < Variant::VARIANT_MAX; j++) { - opbtn->add_item(Variant::get_type_name(Variant::Type(j))); - } - opbtn->select(left_type); - opbtn->set_custom_minimum_size(Size2(100 * EDSCALE, 0)); - hbc->add_child(opbtn); - opbtn->connect("item_selected", callable_mp(this, &VisualScriptEditor::_change_port_type).bind(E, i, true), CONNECT_DEFERRED); - } - - Button *rmbtn = memnew(Button); - rmbtn->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Remove"), SNAME("EditorIcons"))); - hbc->add_child(rmbtn); - rmbtn->connect("pressed", callable_mp(this, &VisualScriptEditor::_remove_input_port).bind(E, i), CONNECT_DEFERRED); - } else { - hbc->add_child(memnew(Label(left_name))); - } - - if (left_type != Variant::NIL && !script->is_input_value_port_connected(E, i)) { - PropertyInfo pi = node->get_input_value_port_info(i); - Button *button = memnew(Button); - Variant value = node->get_default_input_value(i); - if (value.get_type() != left_type) { - //different type? for now convert - //not the same, reconvert - Callable::CallError ce; - const Variant *existingp = &value; - Variant::construct(left_type, value, &existingp, 1, ce); - } - - if (left_type == Variant::COLOR) { - button->set_custom_minimum_size(Size2(30, 0) * EDSCALE); - button->connect("draw", callable_mp(this, &VisualScriptEditor::_draw_color_over_button).bind(button, value)); - } else if (left_type == Variant::OBJECT && Ref(value).is_valid()) { - Ref res = value; - Array arr; - arr.push_back(button->get_instance_id()); - arr.push_back(String(value)); - EditorResourcePreview::get_singleton()->queue_edited_resource_preview(res, this, "_button_resource_previewed", arr); - - } else if (pi.type == Variant::INT && pi.hint == PROPERTY_HINT_ENUM) { - bool found = false; - const Vector options = pi.hint_string.split(","); - int64_t current_val = 0; - for (const String &option : options) { - Vector text_split = option.split(":"); - if (text_split.size() != 1) { - current_val = text_split[1].to_int(); - } - if (value.operator int() == current_val) { - button->set_text(text_split[0]); - found = true; - break; - } - current_val += 1; - } - if (!found) { - button->set_text(value); - } - } else if (pi.type == Variant::INT && pi.hint == PROPERTY_HINT_FLAGS) { - Vector value_texts; - const Vector options = pi.hint_string.split(","); - uint32_t v = value; - for (const String &option : options) { - uint32_t current_val; - Vector text_split = option.split(":"); - if (text_split.size() != -1) { - current_val = text_split[1].to_int(); - } else { - current_val = 1 << i; - } - if ((v & current_val) == current_val) { - value_texts.push_back(text_split[0]); - } - } - if (value_texts.size() != 0) { - String value_text = value_texts[0]; - for (const String &text : value_texts) { - value_text += " | " + text; - } - button->set_text(value_text); - } else { - button->set_text(value); - } - } else { - button->set_text(value); - } - button->connect("pressed", callable_mp(this, &VisualScriptEditor::_default_value_edited).bind(button, E, i)); - hbc2->add_child(button); - } - } else { - Control *c = memnew(Control); - c->set_custom_minimum_size(Size2(10, 0) * EDSCALE); - hbc->add_child(c); - } - - hbc->add_spacer(); - hbc2->add_spacer(); - - if (i < mixed_seq_ports) { - Label *text2 = memnew(Label); - text2->set_text(node->get_output_sequence_port_text(i)); - text2->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_RIGHT); - hbc->add_child(text2); - } - - if (right_ok) { - if (is_vslist) { - Button *rmbtn = memnew(Button); - rmbtn->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Remove"), SNAME("EditorIcons"))); - hbc->add_child(rmbtn); - rmbtn->connect("pressed", callable_mp(this, &VisualScriptEditor::_remove_output_port).bind(E, i), CONNECT_DEFERRED); - - if (nd_list->is_output_port_type_editable()) { - OptionButton *opbtn = memnew(OptionButton); - for (int j = Variant::NIL; j < Variant::VARIANT_MAX; j++) { - opbtn->add_item(Variant::get_type_name(Variant::Type(j))); - } - opbtn->select(right_type); - opbtn->set_custom_minimum_size(Size2(100 * EDSCALE, 0)); - hbc->add_child(opbtn); - opbtn->connect("item_selected", callable_mp(this, &VisualScriptEditor::_change_port_type).bind(E, i, false), CONNECT_DEFERRED); - } - - if (nd_list->is_output_port_name_editable()) { - LineEdit *name_box = memnew(LineEdit); - hbc->add_child(name_box); - name_box->set_custom_minimum_size(Size2(60 * EDSCALE, 0)); - name_box->set_text(right_name); - name_box->set_expand_to_text_length_enabled(true); - name_box->connect("resized", callable_mp(this, &VisualScriptEditor::_update_node_size).bind(E)); - name_box->connect("focus_exited", callable_mp(this, &VisualScriptEditor::_port_name_focus_out).bind(name_box, E, i, false)); - } else { - hbc->add_child(memnew(Label(right_name))); - } - } else { - hbc->add_child(memnew(Label(right_name))); - } - - Ref t; - if (right_type >= 0 && right_type < Variant::VARIANT_MAX) { - t = type_icons[right_type]; - } - if (t.is_valid()) { - TextureRect *tf = memnew(TextureRect); - tf->set_texture(t); - tf->set_stretch_mode(TextureRect::STRETCH_KEEP_CENTERED); - hbc->add_child(tf); - } - } - - gnode->add_child(vbc); - - bool dark_theme = get_theme_constant(SNAME("dark_theme"), SNAME("Editor")); - if (i < mixed_seq_ports) { - gnode->set_slot(slot_idx, left_ok, left_type, _color_from_type(left_type, dark_theme), true, TYPE_SEQUENCE, mono_color, Ref(), seq_port); - } else { - gnode->set_slot(slot_idx, left_ok, left_type, _color_from_type(left_type, dark_theme), right_ok, right_type, _color_from_type(right_type, dark_theme)); - } - - slot_idx++; - } - graph->add_child(gnode); - gnode->set_theme(vstheme); - if (gnode->is_comment()) { - graph->move_child(gnode, 0); - } - } - - _update_graph_connections(); - - float graph_minimap_opacity = EditorSettings::get_singleton()->get("editors/visual_editors/minimap_opacity"); - graph->set_minimap_opacity(graph_minimap_opacity); - - float graph_lines_curvature = EditorSettings::get_singleton()->get("editors/visual_editors/lines_curvature"); - graph->set_connection_lines_curvature(graph_lines_curvature); - - // Use default_func instead of default_func for now I think that should be good stop gap solution to ensure not breaking anything. - graph->call_deferred(SNAME("set_scroll_ofs"), script->get_scroll() * EDSCALE); - updating_graph = false; -} - -void VisualScriptEditor::_change_port_type(int p_select, int p_id, int p_port, bool is_input) { - Ref vsn = script->get_node(p_id); - if (!vsn.is_valid()) { - return; - } - - undo_redo->create_action(TTR("Change Port Type")); - if (is_input) { - undo_redo->add_do_method(vsn.ptr(), "set_input_data_port_type", p_port, Variant::Type(p_select)); - undo_redo->add_undo_method(vsn.ptr(), "set_input_data_port_type", p_port, vsn->get_input_value_port_info(p_port).type); - } else { - undo_redo->add_do_method(vsn.ptr(), "set_output_data_port_type", p_port, Variant::Type(p_select)); - undo_redo->add_undo_method(vsn.ptr(), "set_output_data_port_type", p_port, vsn->get_output_value_port_info(p_port).type); - } - undo_redo->commit_action(); -} - -void VisualScriptEditor::_update_node_size(int p_id) { - Node *node = graph->get_node(itos(p_id)); - if (Object::cast_to(node)) { - Object::cast_to(node)->reset_size(); // Shrink if text is smaller. - } -} - -void VisualScriptEditor::_port_name_focus_out(const Node *p_name_box, int p_id, int p_port, bool is_input) { - Ref vsn = script->get_node(p_id); - if (!vsn.is_valid()) { - return; - } - - String text; - - if (Object::cast_to(p_name_box)) { - text = Object::cast_to(p_name_box)->get_text(); - } else { - return; - } - - undo_redo->create_action(TTR("Change Port Name")); - if (is_input) { - undo_redo->add_do_method(vsn.ptr(), "set_input_data_port_name", p_port, text); - undo_redo->add_undo_method(vsn.ptr(), "set_input_data_port_name", p_port, vsn->get_input_value_port_info(p_port).name); - } else { - undo_redo->add_do_method(vsn.ptr(), "set_output_data_port_name", p_port, text); - undo_redo->add_undo_method(vsn.ptr(), "set_output_data_port_name", p_port, vsn->get_output_value_port_info(p_port).name); - } - undo_redo->commit_action(); -} - -void VisualScriptEditor::_update_members() { - ERR_FAIL_COND(!script.is_valid()); - - updating_members = true; - - members->clear(); - TreeItem *root = members->create_item(); - - TreeItem *functions = members->create_item(root); - functions->set_selectable(0, false); - functions->set_text(0, TTR("Functions:")); - functions->add_button(0, Control::get_theme_icon(SNAME("Override"), SNAME("EditorIcons")), 1, false, TTR("Override an existing built-in function.")); - functions->add_button(0, Control::get_theme_icon(SNAME("Add"), SNAME("EditorIcons")), 0, false, TTR("Create a new function.")); - functions->set_custom_color(0, Control::get_theme_color(SNAME("mono_color"), SNAME("Editor"))); - - List func_names; - script->get_function_list(&func_names); - func_names.sort_custom(); - for (const StringName &E : func_names) { - TreeItem *ti = members->create_item(functions); - ti->set_text(0, E); - ti->set_selectable(0, true); - ti->set_metadata(0, E); - ti->add_button(0, Control::get_theme_icon(SNAME("Edit"), SNAME("EditorIcons")), 0); - if (selected == E) { - ti->select(0); - } - } - - TreeItem *variables = members->create_item(root); - variables->set_selectable(0, false); - variables->set_text(0, TTR("Variables:")); - variables->add_button(0, Control::get_theme_icon(SNAME("Add"), SNAME("EditorIcons")), -1, false, TTR("Create a new variable.")); - variables->set_custom_color(0, Control::get_theme_color(SNAME("mono_color"), SNAME("Editor"))); - - Ref type_icons[Variant::VARIANT_MAX] = { - Control::get_theme_icon(SNAME("Variant"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("bool"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("int"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("float"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("String"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("Vector2"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("Vector2i"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("Rect2"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("Rect2i"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("Vector3"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("Vector3i"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("Transform2D"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("Plane"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("Quaternion"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("AABB"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("Basis"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("Transform3D"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("Color"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("StringName"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("NodePath"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("RID"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("MiniObject"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("Callable"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("Signal"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("Dictionary"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("Array"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("PackedByteArray"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("PackedInt32Array"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("PackedInt64Array"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("PackedFloat32Array"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("PackedFloat64Array"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("PackedStringArray"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("PackedVector2Array"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("PackedVector3Array"), SNAME("EditorIcons")), - Control::get_theme_icon(SNAME("PackedColorArray"), SNAME("EditorIcons")) - }; - - List var_names; - script->get_variable_list(&var_names); - var_names.sort_custom(); - for (const StringName &E : var_names) { - TreeItem *ti = members->create_item(variables); - - ti->set_text(0, E); - - ti->set_suffix(0, "= " + _sanitized_variant_text(E)); - ti->set_icon(0, type_icons[script->get_variable_info(E).type]); - - ti->set_selectable(0, true); - ti->set_editable(0, true); - ti->set_metadata(0, E); - if (selected == E) { - ti->select(0); - } - } - - TreeItem *_signals = members->create_item(root); - _signals->set_selectable(0, false); - _signals->set_text(0, TTR("Signals:")); - _signals->add_button(0, Control::get_theme_icon(SNAME("Add"), SNAME("EditorIcons")), -1, false, TTR("Create a new signal.")); - _signals->set_custom_color(0, Control::get_theme_color(SNAME("mono_color"), SNAME("Editor"))); - - List signal_names; - script->get_custom_signal_list(&signal_names); - for (const StringName &E : signal_names) { - TreeItem *ti = members->create_item(_signals); - ti->set_text(0, E); - ti->set_selectable(0, true); - ti->set_editable(0, true); - ti->set_metadata(0, E); - if (selected == E) { - ti->select(0); - } - } - - String base_type = script->get_instance_base_type(); - String icon_type = base_type; - if (!Control::has_theme_icon(base_type, SNAME("EditorIcons"))) { - icon_type = "Object"; - } - - base_type_select->set_text(base_type); - base_type_select->set_icon(Control::get_theme_icon(icon_type, SNAME("EditorIcons"))); - - updating_members = false; -} - -String VisualScriptEditor::_sanitized_variant_text(const StringName &property_name) { - Variant var = script->get_variable_default_value(property_name); - - if (script->get_variable_info(property_name).type != Variant::NIL) { - Callable::CallError ce; - const Variant *converted = &var; - Variant n; - Variant::construct(script->get_variable_info(property_name).type, n, &converted, 1, ce); - var = n; - } - - return String(var); -} - -void VisualScriptEditor::_member_selected() { - if (updating_members) { - return; - } - - TreeItem *ti = members->get_selected(); - ERR_FAIL_COND(!ti); - - selected = ti->get_metadata(0); - - if (ti->get_parent() == members->get_root()->get_first_child()) { -#ifdef MACOS_ENABLED - bool held_ctrl = Input::get_singleton()->is_key_pressed(Key::META); -#else - bool held_ctrl = Input::get_singleton()->is_key_pressed(Key::CTRL); -#endif - if (held_ctrl) { - ERR_FAIL_COND(!script->has_function(selected)); - _center_on_node(script->get_function_node_id(selected)); - } - } -} - -void VisualScriptEditor::_member_edited() { - if (updating_members) { - return; - } - - TreeItem *ti = members->get_edited(); - ERR_FAIL_COND(!ti); - - String name = ti->get_metadata(0); - String new_name = ti->get_text(0); - - if (name == new_name) { - return; - } - - if (!new_name.is_valid_identifier()) { - EditorNode::get_singleton()->show_warning(TTR("Name is not a valid identifier:") + " " + new_name); - updating_members = true; - ti->set_text(0, name); - updating_members = false; - return; - } - - if (script->has_function(new_name) || script->has_variable(new_name) || script->has_custom_signal(new_name)) { - EditorNode::get_singleton()->show_warning(TTR("Name already in use by another func/var/signal:") + " " + new_name); - updating_members = true; - ti->set_text(0, name); - updating_members = false; - return; - } - - TreeItem *root = members->get_root(); - - if (ti->get_parent() == root->get_first_child()) { - selected = new_name; - - int node_id = script->get_function_node_id(name); - Ref func; - if (script->has_node(node_id)) { - func = script->get_node(node_id); - } - undo_redo->create_action(TTR("Rename Function")); - undo_redo->add_do_method(script.ptr(), "rename_function", name, new_name); - undo_redo->add_undo_method(script.ptr(), "rename_function", new_name, name); - if (func.is_valid()) { - undo_redo->add_do_method(func.ptr(), "set_name", new_name); - undo_redo->add_undo_method(func.ptr(), "set_name", name); - } - - // Also fix all function calls. - List lst; - script->get_node_list(&lst); - for (int &F : lst) { - Ref fncall = script->get_node(F); - if (!fncall.is_valid()) { - continue; - } - if (fncall->get_function() == name) { - undo_redo->add_do_method(fncall.ptr(), "set_function", new_name); - undo_redo->add_undo_method(fncall.ptr(), "set_function", name); - } - } - - undo_redo->add_do_method(this, "_update_members"); - undo_redo->add_undo_method(this, "_update_members"); - undo_redo->add_do_method(this, "_update_graph"); - undo_redo->add_undo_method(this, "_update_graph"); - undo_redo->add_do_method(this, "emit_signal", "edited_script_changed"); - undo_redo->add_undo_method(this, "emit_signal", "edited_script_changed"); - undo_redo->commit_action(); - - return; // Or crash because it will become invalid. - } - - if (ti->get_parent() == root->get_first_child()->get_next()) { - selected = new_name; - undo_redo->create_action(TTR("Rename Variable")); - undo_redo->add_do_method(script.ptr(), "rename_variable", name, new_name); - undo_redo->add_undo_method(script.ptr(), "rename_variable", new_name, name); - - // Also fix all variable setter & getter calls - List lst; - script->get_node_list(&lst); - for (int &P : lst) { - Ref pset = script->get_node(P); - if (pset.is_valid() && pset->get_property() == name) { - undo_redo->add_do_method(pset.ptr(), "set_property", new_name); - undo_redo->add_undo_method(pset.ptr(), "set_property", name); - } - Ref pget = script->get_node(P); - if (pget.is_valid() && pget->get_property() == name) { - undo_redo->add_do_method(pget.ptr(), "set_property", new_name); - undo_redo->add_undo_method(pget.ptr(), "set_property", name); - } - } - - undo_redo->add_do_method(this, "_update_members"); - undo_redo->add_undo_method(this, "_update_members"); - undo_redo->add_do_method(this, "_update_graph"); - undo_redo->add_undo_method(this, "_update_graph"); - undo_redo->add_do_method(this, "emit_signal", "edited_script_changed"); - undo_redo->add_undo_method(this, "emit_signal", "edited_script_changed"); - undo_redo->commit_action(); - - return; // Or crash because it will become invalid. - } - - if (ti->get_parent() == root->get_first_child()->get_next()->get_next()) { - selected = new_name; - undo_redo->create_action(TTR("Rename Signal")); - undo_redo->add_do_method(script.ptr(), "rename_custom_signal", name, new_name); - undo_redo->add_undo_method(script.ptr(), "rename_custom_signal", new_name, name); - - // Also fix all signal emitting nodes - List lst; - script->get_node_list(&lst); - for (int &P : lst) { - Ref psig = script->get_node(P); - if (psig.is_valid() && psig->get_signal() == name) { - undo_redo->add_do_method(psig.ptr(), "set_signal", new_name); - undo_redo->add_undo_method(psig.ptr(), "set_signal", name); - } - } - - undo_redo->add_do_method(this, "_update_members"); - undo_redo->add_undo_method(this, "_update_members"); - undo_redo->add_do_method(this, "emit_signal", "edited_script_changed"); - undo_redo->add_undo_method(this, "emit_signal", "edited_script_changed"); - undo_redo->commit_action(); - - return; // Or crash because it will become invalid. - } -} - -void VisualScriptEditor::_create_function_dialog() { - function_create_dialog->popup_centered(); - func_name_box->set_text(""); - func_name_box->grab_focus(); - for (int i = 0; i < func_input_vbox->get_child_count(); i++) { - Node *nd = func_input_vbox->get_child(i); - nd->queue_delete(); - } -} - -void VisualScriptEditor::_create_function() { - String name = _validate_name((func_name_box->get_text().is_empty()) ? "new_func" : func_name_box->get_text()); - selected = name; - Vector2 pos = _get_available_pos(); - - Ref func_node; - func_node.instantiate(); - func_node->set_name(name); - - for (int i = 0; i < func_input_vbox->get_child_count(); i++) { - OptionButton *opbtn = Object::cast_to(func_input_vbox->get_child(i)->get_child(3)); - LineEdit *lne = Object::cast_to(func_input_vbox->get_child(i)->get_child(1)); - if (!opbtn || !lne) { - continue; - } - Variant::Type arg_type = Variant::Type(opbtn->get_selected()); - String arg_name = lne->get_text(); - func_node->add_argument(arg_type, arg_name); - } - - int func_node_id = script->get_available_id(); - - undo_redo->create_action(TTR("Add Function")); - 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_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_do_method(this, "_update_members"); - undo_redo->add_undo_method(this, "_update_members"); - undo_redo->add_do_method(this, "_update_graph"); - undo_redo->add_undo_method(this, "_update_graph"); - undo_redo->add_do_method(this, "emit_signal", "edited_script_changed"); - undo_redo->add_undo_method(this, "emit_signal", "edited_script_changed"); - undo_redo->commit_action(); - - _update_graph(); -} - -void VisualScriptEditor::_add_node_dialog() { - _generic_search(graph->get_global_position() + Vector2(55, 80), true); -} - -void VisualScriptEditor::_add_func_input() { - HBoxContainer *hbox = memnew(HBoxContainer); - hbox->set_h_size_flags(SIZE_EXPAND_FILL); - - Label *name_label = memnew(Label); - name_label->set_text(TTR("Name:")); - hbox->add_child(name_label); - - LineEdit *name_box = memnew(LineEdit); - name_box->set_h_size_flags(SIZE_EXPAND_FILL); - name_box->set_text("input"); - name_box->connect("focus_entered", callable_mp(this, &VisualScriptEditor::_deselect_input_names)); - hbox->add_child(name_box); - - Label *type_label = memnew(Label); - type_label->set_text(TTR("Type:")); - hbox->add_child(type_label); - - OptionButton *type_box = memnew(OptionButton); - type_box->set_custom_minimum_size(Size2(120 * EDSCALE, 0)); - for (int i = Variant::NIL; i < Variant::VARIANT_MAX; i++) { - type_box->add_item(Variant::get_type_name(Variant::Type(i))); - } - type_box->select(1); - hbox->add_child(type_box); - - Button *delete_button = memnew(Button); - delete_button->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Remove"), SNAME("EditorIcons"))); - delete_button->set_tooltip(vformat(TTR("Delete input port"))); - hbox->add_child(delete_button); - - for (int i = 0; i < func_input_vbox->get_child_count(); i++) { - LineEdit *line_edit = (LineEdit *)func_input_vbox->get_child(i)->get_child(1); - line_edit->deselect(); - } - - func_input_vbox->add_child(hbox); - hbox->set_meta("id", hbox->get_index()); - - delete_button->connect("pressed", callable_mp(this, &VisualScriptEditor::_remove_func_input).bind(hbox)); - - name_box->select_all(); - name_box->grab_focus(); -} - -void VisualScriptEditor::_remove_func_input(Node *p_node) { - func_input_vbox->remove_child(p_node); - p_node->queue_delete(); -} - -void VisualScriptEditor::_deselect_input_names() { - int cn = func_input_vbox->get_child_count(); - for (int i = 0; i < cn; i++) { - LineEdit *lne = Object::cast_to(func_input_vbox->get_child(i)->get_child(1)); - if (lne) { - lne->deselect(); - } - } -} - -void VisualScriptEditor::_member_button(Object *p_item, int p_column, int p_button, MouseButton p_mouse_button) { - if (p_mouse_button != MouseButton::LEFT) { - return; - } - - TreeItem *ti = Object::cast_to(p_item); - - TreeItem *root = members->get_root(); - - if (ti->get_parent() == root) { - //main buttons - if (ti == root->get_first_child()) { - // Add function, this one uses menu. - - if (p_button == 1) { - // Ensure script base exists otherwise use custom base type. - ERR_FAIL_COND(script.is_null()); - new_virtual_method_select->select_method_from_base_type(script->get_instance_base_type(), true); - return; - } else if (p_button == 0) { - String name = _validate_name("new_function"); - selected = name; - Vector2 pos = _get_available_pos(); - - Ref func_node; - func_node.instantiate(); - func_node->set_name(name); - int fn_id = script->get_available_id(); - - 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_node", fn_id, func_node, pos); - undo_redo->add_undo_method(script.ptr(), "remove_function", name); - undo_redo->add_undo_method(script.ptr(), "remove_node", fn_id); - undo_redo->add_do_method(this, "_update_members"); - undo_redo->add_undo_method(this, "_update_members"); - undo_redo->add_do_method(this, "_update_graph"); - undo_redo->add_undo_method(this, "_update_graph"); - undo_redo->add_do_method(this, "emit_signal", "edited_script_changed"); - undo_redo->add_undo_method(this, "emit_signal", "edited_script_changed"); - undo_redo->commit_action(); - - _update_graph(); - } - - return; // Or crash because it will become invalid. - } - - if (ti == root->get_first_child()->get_next()) { - // Add variable. - String name = _validate_name("new_variable"); - selected = name; - - undo_redo->create_action(TTR("Add Variable")); - undo_redo->add_do_method(script.ptr(), "add_variable", name); - undo_redo->add_undo_method(script.ptr(), "remove_variable", name); - undo_redo->add_do_method(this, "_update_members"); - undo_redo->add_undo_method(this, "_update_members"); - undo_redo->add_do_method(this, "emit_signal", "edited_script_changed"); - undo_redo->add_undo_method(this, "emit_signal", "edited_script_changed"); - undo_redo->commit_action(); - return; // Or crash because it will become invalid. - } - - if (ti == root->get_first_child()->get_next()->get_next()) { - // Add variable. - String name = _validate_name("new_signal"); - selected = name; - - undo_redo->create_action(TTR("Add Signal")); - undo_redo->add_do_method(script.ptr(), "add_custom_signal", name); - undo_redo->add_undo_method(script.ptr(), "remove_custom_signal", name); - undo_redo->add_do_method(this, "_update_members"); - undo_redo->add_undo_method(this, "_update_members"); - undo_redo->add_do_method(this, "emit_signal", "edited_script_changed"); - undo_redo->add_undo_method(this, "emit_signal", "edited_script_changed"); - undo_redo->commit_action(); - return; // Or crash because it will become invalid. - } - } else if (ti->get_parent() == root->get_first_child()) { - selected = ti->get_text(0); - function_name_edit->set_position(get_screen_position() + get_local_mouse_position() - Vector2(60, -10)); - function_name_edit->popup(); - function_name_box->set_text(selected); - function_name_box->select_all(); - function_name_box->grab_focus(); - } -} - -void VisualScriptEditor::_add_input_port(int p_id) { - Ref vsn = script->get_node(p_id); - if (!vsn.is_valid()) { - return; - } - - updating_graph = true; - - undo_redo->create_action(TTR("Add Input Port"), UndoRedo::MERGE_ENDS); - undo_redo->add_do_method(vsn.ptr(), "add_input_data_port", Variant::NIL, "arg", -1); - undo_redo->add_do_method(this, "_update_graph", p_id); - - undo_redo->add_undo_method(vsn.ptr(), "remove_input_data_port", vsn->get_input_value_port_count()); - undo_redo->add_undo_method(this, "_update_graph", p_id); - - updating_graph = false; - - undo_redo->commit_action(); -} - -void VisualScriptEditor::_add_output_port(int p_id) { - Ref vsn = script->get_node(p_id); - if (!vsn.is_valid()) { - return; - } - - updating_graph = true; - - undo_redo->create_action(TTR("Add Output Port"), UndoRedo::MERGE_ENDS); - undo_redo->add_do_method(vsn.ptr(), "add_output_data_port", Variant::NIL, "arg", -1); - undo_redo->add_do_method(this, "_update_graph", p_id); - - undo_redo->add_undo_method(vsn.ptr(), "remove_output_data_port", vsn->get_output_value_port_count()); - undo_redo->add_undo_method(this, "_update_graph", p_id); - - updating_graph = false; - - undo_redo->commit_action(); -} - -void VisualScriptEditor::_remove_input_port(int p_id, int p_port) { - Ref vsn = script->get_node(p_id); - if (!vsn.is_valid()) { - return; - } - - updating_graph = true; - - undo_redo->create_action(TTR("Remove Input Port"), UndoRedo::MERGE_ENDS); - - int conn_from = -1, conn_port = -1; - script->get_input_value_port_connection_source(p_id, p_port, &conn_from, &conn_port); - - if (conn_from != -1) { - undo_redo->add_do_method(script.ptr(), "data_disconnect", conn_from, conn_port, p_id, p_port); - } - - undo_redo->add_do_method(vsn.ptr(), "remove_input_data_port", p_port); - undo_redo->add_do_method(this, "_update_graph", p_id); - - if (conn_from != -1) { - undo_redo->add_undo_method(script.ptr(), "data_connect", conn_from, conn_port, p_id, p_port); - } - - undo_redo->add_undo_method(vsn.ptr(), "add_input_data_port", vsn->get_input_value_port_info(p_port).type, vsn->get_input_value_port_info(p_port).name, p_port); - undo_redo->add_undo_method(this, "_update_graph", p_id); - - updating_graph = false; - - undo_redo->commit_action(); -} - -void VisualScriptEditor::_remove_output_port(int p_id, int p_port) { - Ref vsn = script->get_node(p_id); - if (!vsn.is_valid()) { - return; - } - - updating_graph = true; - - undo_redo->create_action(TTR("Remove Output Port"), UndoRedo::MERGE_ENDS); - - List data_connections; - script->get_data_connection_list(&data_connections); - - HashMap> conn_map; - for (const VisualScript::DataConnection &E : data_connections) { - if (E.from_node == p_id && E.from_port == p_port) { - // Push into the connections map. - if (!conn_map.has(E.to_node)) { - conn_map.insert(E.to_node, RBSet()); - } - conn_map[E.to_node].insert(E.to_port); - } - } - - undo_redo->add_do_method(vsn.ptr(), "remove_output_data_port", p_port); - undo_redo->add_do_method(this, "_update_graph", p_id); - - for (const KeyValue> &E : conn_map) { - for (const int &F : E.value) { - undo_redo->add_undo_method(script.ptr(), "data_connect", p_id, p_port, E.key, F); - } - } - - undo_redo->add_undo_method(vsn.ptr(), "add_output_data_port", vsn->get_output_value_port_info(p_port).type, vsn->get_output_value_port_info(p_port).name, p_port); - undo_redo->add_undo_method(this, "_update_graph", p_id); - - updating_graph = false; - - undo_redo->commit_action(); -} - -void VisualScriptEditor::_expression_text_changed(const String &p_text, int p_id) { - Ref vse = script->get_node(p_id); - if (!vse.is_valid()) { - return; - } - - updating_graph = true; - - undo_redo->create_action(TTR("Change Expression"), UndoRedo::MERGE_ENDS); - undo_redo->add_do_property(vse.ptr(), "expression", p_text); - undo_redo->add_undo_property(vse.ptr(), "expression", vse->get("expression")); - undo_redo->add_do_method(this, "_update_graph", p_id); - undo_redo->add_undo_method(this, "_update_graph", p_id); - undo_redo->commit_action(); - - Node *node = graph->get_node(itos(p_id)); - if (Object::cast_to(node)) { - Object::cast_to(node)->reset_size(); // Shrink if text is smaller. - } - - updating_graph = false; -} - -Vector2 VisualScriptEditor::_get_pos_in_graph(Vector2 p_point) const { - Vector2 pos = (graph->get_scroll_ofs() + p_point) / (graph->get_zoom() * EDSCALE); - if (graph->is_using_snap()) { - int snap = graph->get_snap(); - pos = pos.snapped(Vector2(snap, snap)); - } - return pos; -} - -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) { - bool exists = false; - List existing; - script->get_node_list(&existing); - for (int &E : existing) { - Point2 pos = script->get_node_position(E); - if (pos.distance_to(p_pos) < 50) { - p_pos += Vector2(graph->get_snap(), graph->get_snap()); - exists = true; - break; - } - } - if (exists) { - continue; - } - break; - } - - return p_pos; -} - -String VisualScriptEditor::_validate_name(const String &p_name) const { - String valid = p_name; - - int counter = 1; - while (true) { - bool exists = script->has_function(valid) || script->has_variable(valid) || script->has_custom_signal(valid); - - if (exists) { - counter++; - valid = p_name + "_" + itos(counter); - continue; - } - - break; - } - - return valid; -} - -void VisualScriptEditor::_on_nodes_copy() { - clipboard->nodes.clear(); - clipboard->data_connections.clear(); - clipboard->sequence_connections.clear(); - - for (int i = 0; i < graph->get_child_count(); i++) { - GraphNode *gn = Object::cast_to(graph->get_child(i)); - if (gn) { - if (gn->is_selected()) { - int id = gn->get_name().operator String().to_int(); - Ref node = script->get_node(id); - if (Object::cast_to(*node)) { - EditorNode::get_singleton()->show_warning(TTR("Can't copy the function node.")); - return; - } - if (node.is_valid()) { - clipboard->nodes[id] = node->duplicate(true); - clipboard->nodes_positions[id] = script->get_node_position(id); - } - } - } - } - - if (clipboard->nodes.is_empty()) { - return; - } - - List sequence_connections; - script->get_sequence_connection_list(&sequence_connections); - - for (const VisualScript::SequenceConnection &E : sequence_connections) { - if (clipboard->nodes.has(E.from_node) && clipboard->nodes.has(E.to_node)) { - clipboard->sequence_connections.insert(E); - } - } - - List data_connections; - script->get_data_connection_list(&data_connections); - - for (const VisualScript::DataConnection &E : data_connections) { - if (clipboard->nodes.has(E.from_node) && clipboard->nodes.has(E.to_node)) { - clipboard->data_connections.insert(E); - } - } -} - -void VisualScriptEditor::_on_nodes_paste() { - if (clipboard->nodes.is_empty()) { - EditorNode::get_singleton()->show_warning(TTR("Clipboard is empty!")); - return; - } - - HashMap remap; - - undo_redo->create_action(TTR("Paste VisualScript Nodes")); - int idc = script->get_available_id() + 1; - - RBSet to_select; - - RBSet existing_positions; - - { - List nodes; - script->get_node_list(&nodes); - for (int &E : nodes) { - Vector2 pos = script->get_node_position(E).snapped(Vector2(2, 2)); - existing_positions.insert(pos); - } - } - - bool first_paste = true; - Vector2 position_offset = Vector2(0, 0); - - for (KeyValue> &E : clipboard->nodes) { - Ref node = E.value->duplicate(); - - int new_id = idc++; - to_select.insert(new_id); - - remap[E.key] = new_id; - - Vector2 paste_pos = clipboard->nodes_positions[E.key]; - - if (first_paste) { - position_offset = _get_pos_in_graph(mouse_up_position - graph->get_global_position()) - paste_pos; - first_paste = false; - } - - paste_pos += position_offset; - - while (existing_positions.has(paste_pos.snapped(Vector2(2, 2)))) { - paste_pos += Vector2(20, 20) * EDSCALE; - } - - undo_redo->add_do_method(script.ptr(), "add_node", new_id, node, paste_pos); - undo_redo->add_undo_method(script.ptr(), "remove_node", new_id); - } - - for (const VisualScript::SequenceConnection &E : clipboard->sequence_connections) { - undo_redo->add_do_method(script.ptr(), "sequence_connect", remap[E.from_node], E.from_output, remap[E.to_node]); - undo_redo->add_undo_method(script.ptr(), "sequence_disconnect", remap[E.from_node], E.from_output, remap[E.to_node]); - } - - for (const VisualScript::DataConnection &E : clipboard->data_connections) { - undo_redo->add_do_method(script.ptr(), "data_connect", remap[E.from_node], E.from_port, remap[E.to_node], E.to_port); - undo_redo->add_undo_method(script.ptr(), "data_disconnect", remap[E.from_node], E.from_port, remap[E.to_node], E.to_port); - } - - undo_redo->add_do_method(this, "_update_graph"); - undo_redo->add_undo_method(this, "_update_graph"); - - undo_redo->commit_action(); - - for (int i = 0; i < graph->get_child_count(); i++) { - GraphNode *gn = Object::cast_to(graph->get_child(i)); - if (gn) { - int id = gn->get_name().operator String().to_int(); - gn->set_selected(to_select.has(id)); - } - } -} - -void VisualScriptEditor::_on_nodes_delete() { - // Delete all the selected nodes. - - List to_erase; - - for (int i = 0; i < graph->get_child_count(); i++) { - GraphNode *gn = Object::cast_to(graph->get_child(i)); - if (gn) { - if (gn->is_selected() && gn->is_close_button_visible()) { - to_erase.push_back(gn->get_name().operator String().to_int()); - } - } - } - - if (to_erase.is_empty()) { - return; - } - - undo_redo->create_action(TTR("Remove VisualScript Nodes")); - - for (int &F : to_erase) { - int cr_node = F; - - undo_redo->add_do_method(script.ptr(), "remove_node", cr_node); - undo_redo->add_undo_method(script.ptr(), "add_node", cr_node, script->get_node(cr_node), script->get_node_position(cr_node)); - - List sequence_conns; - script->get_sequence_connection_list(&sequence_conns); - - for (const VisualScript::SequenceConnection &E : sequence_conns) { - if (E.from_node == cr_node || E.to_node == cr_node) { - undo_redo->add_undo_method(script.ptr(), "sequence_connect", E.from_node, E.from_output, E.to_node); - } - } - - List data_conns; - script->get_data_connection_list(&data_conns); - - for (const VisualScript::DataConnection &E : data_conns) { - if (E.from_node == F || E.to_node == F) { - undo_redo->add_undo_method(script.ptr(), "data_connect", E.from_node, E.from_port, E.to_node, E.to_port); - } - } - } - undo_redo->add_do_method(this, "_update_graph"); - undo_redo->add_undo_method(this, "_update_graph"); - - undo_redo->commit_action(); -} - -void VisualScriptEditor::_on_nodes_duplicate() { - RBSet to_duplicate; - - for (int i = 0; i < graph->get_child_count(); i++) { - GraphNode *gn = Object::cast_to(graph->get_child(i)); - if (gn) { - if (gn->is_selected() && gn->is_close_button_visible()) { - int id = gn->get_name().operator String().to_int(); - to_duplicate.insert(id); - } - } - } - - if (to_duplicate.is_empty()) { - return; - } - - undo_redo->create_action(TTR("Duplicate VisualScript Nodes")); - int idc = script->get_available_id() + 1; - - RBSet to_select; - HashMap remap; - - for (const int &F : to_duplicate) { - // Duplicate from the specific function but place it into the default func as it would lack the connections. - Ref node = script->get_node(F); - - Ref dupe = node->duplicate(true); - - int new_id = idc++; - remap.insert(F, new_id); - - to_select.insert(new_id); - undo_redo->add_do_method(script.ptr(), "add_node", new_id, dupe, script->get_node_position(F) + Vector2(20, 20)); - undo_redo->add_undo_method(script.ptr(), "remove_node", new_id); - } - - List seqs; - script->get_sequence_connection_list(&seqs); - for (const VisualScript::SequenceConnection &E : seqs) { - if (to_duplicate.has(E.from_node) && to_duplicate.has(E.to_node)) { - undo_redo->add_do_method(script.ptr(), "sequence_connect", remap[E.from_node], E.from_output, remap[E.to_node]); - } - } - - List data; - script->get_data_connection_list(&data); - for (const VisualScript::DataConnection &E : data) { - if (to_duplicate.has(E.from_node) && to_duplicate.has(E.to_node)) { - undo_redo->add_do_method(script.ptr(), "data_connect", remap[E.from_node], E.from_port, remap[E.to_node], E.to_port); - } - } - - undo_redo->add_do_method(this, "_update_graph"); - undo_redo->add_undo_method(this, "_update_graph"); - - undo_redo->commit_action(); - - for (int i = 0; i < graph->get_child_count(); i++) { - GraphNode *gn = Object::cast_to(graph->get_child(i)); - if (gn) { - int id = gn->get_name().operator String().to_int(); - gn->set_selected(to_select.has(id)); - } - } - - if (to_select.size()) { - EditorNode::get_singleton()->push_item(script->get_node(to_select.front()->get()).ptr()); - } -} - -void VisualScriptEditor::_generic_search(Vector2 pos, bool node_centered) { - if (node_centered) { - port_action_pos = graph->get_size() / 2.0f; - } else { - port_action_pos = graph->get_viewport()->get_mouse_position() - graph->get_global_position(); - } - - new_connect_node_select->select_from_visual_script(script, false); // do not reset text -} - -void VisualScriptEditor::input(const Ref &p_event) { - ERR_FAIL_COND(p_event.is_null()); - - // GUI input for VS Editor Plugin - Ref key = p_event; - - if (key.is_valid() && key->is_pressed()) { - mouse_up_position = get_screen_position() + get_local_mouse_position(); - } -} - -void VisualScriptEditor::_graph_gui_input(const Ref &p_event) { - Ref key = p_event; - - if (key.is_valid() && key->is_pressed() && key->get_button_mask() == MouseButton::RIGHT) { - bool is_empty_selection = true; - - for (int i = 0; i < graph->get_child_count(); i++) { - GraphNode *gn = Object::cast_to(graph->get_child(i)); - if (gn && gn->is_selected()) { - is_empty_selection = false; - break; - } - } - if (is_empty_selection && clipboard->nodes.is_empty()) { - _generic_search(); - } else { - popup_menu->set_item_disabled(int(EDIT_CUT_NODES), is_empty_selection); - popup_menu->set_item_disabled(int(EDIT_COPY_NODES), is_empty_selection); - popup_menu->set_item_disabled(int(EDIT_PASTE_NODES), clipboard->nodes.is_empty()); - popup_menu->set_item_disabled(int(EDIT_DELETE_NODES), is_empty_selection); - popup_menu->set_item_disabled(int(EDIT_DUPLICATE_NODES), is_empty_selection); - popup_menu->set_item_disabled(int(EDIT_CLEAR_COPY_BUFFER), clipboard->nodes.is_empty()); - - popup_menu->set_position(mouse_up_position); - popup_menu->popup(); - } - } -} - -void VisualScriptEditor::_members_gui_input(const Ref &p_event) { - Ref key = p_event; - if (key.is_valid() && key->is_pressed() && !key->is_echo()) { - if (members->has_focus()) { - TreeItem *ti = members->get_selected(); - if (ti) { - TreeItem *root = members->get_root(); - if (ti->get_parent() == root->get_first_child()) { - member_type = MEMBER_FUNCTION; - } - if (ti->get_parent() == root->get_first_child()->get_next()) { - member_type = MEMBER_VARIABLE; - } - if (ti->get_parent() == root->get_first_child()->get_next()->get_next()) { - member_type = MEMBER_SIGNAL; - } - member_name = ti->get_text(0); - } - if (ED_IS_SHORTCUT("ui_graph_delete", p_event)) { - _member_option(MEMBER_REMOVE); - } - if (ED_IS_SHORTCUT("visual_script_editor/edit_member", p_event)) { - _member_option(MEMBER_EDIT); - } - } - } - - Ref btn = p_event; - if (btn.is_valid() && btn->is_double_click()) { - TreeItem *ti = members->get_selected(); - if (ti && ti->get_parent() == members->get_root()->get_first_child()) { // to check if it's a function - _center_on_node(script->get_function_node_id(ti->get_metadata(0))); - } - } -} - -void VisualScriptEditor::_rename_function(const String &name, const String &new_name) { - if (!new_name.is_valid_identifier()) { - EditorNode::get_singleton()->show_warning(TTR("Name is not a valid identifier:") + " " + new_name); - return; - } - - if (script->has_function(new_name) || script->has_variable(new_name) || script->has_custom_signal(new_name)) { - EditorNode::get_singleton()->show_warning(TTR("Name already in use by another func/var/signal:") + " " + new_name); - return; - } - - int node_id = script->get_function_node_id(name); - Ref func; - if (script->has_node(node_id)) { - func = script->get_node(node_id); - } - undo_redo->create_action(TTR("Rename Function")); - undo_redo->add_do_method(script.ptr(), "rename_function", name, new_name); - undo_redo->add_undo_method(script.ptr(), "rename_function", new_name, name); - if (func.is_valid()) { - undo_redo->add_do_method(func.ptr(), "set_name", new_name); - undo_redo->add_undo_method(func.ptr(), "set_name", name); - } - - // Also fix all function calls. - List lst; - script->get_node_list(&lst); - for (int &F : lst) { - Ref fncall = script->get_node(F); - if (!fncall.is_valid()) { - continue; - } - if (fncall->get_function() == name) { - undo_redo->add_do_method(fncall.ptr(), "set_function", new_name); - undo_redo->add_undo_method(fncall.ptr(), "set_function", name); - } - } - - undo_redo->add_do_method(this, "_update_members"); - undo_redo->add_undo_method(this, "_update_members"); - undo_redo->add_do_method(this, "_update_graph"); - undo_redo->add_undo_method(this, "_update_graph"); - undo_redo->add_do_method(this, "emit_signal", "edited_script_changed"); - undo_redo->add_undo_method(this, "emit_signal", "edited_script_changed"); - undo_redo->commit_action(); -} - -void VisualScriptEditor::_fn_name_box_input(const Ref &p_event) { - if (!function_name_edit->is_visible()) { - return; - } - - Ref key = p_event; - if (key.is_valid() && key->is_pressed() && key->get_keycode() == Key::ENTER) { - function_name_edit->hide(); - _on_fn_name_box_confirmed(); - function_name_box->clear(); - } -} - -void VisualScriptEditor::_on_fn_name_box_confirmed() { - _rename_function(selected, function_name_box->get_text()); -} - -Variant VisualScriptEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) { - if (p_from == members) { - TreeItem *it = members->get_item_at_position(p_point); - if (!it) { - return Variant(); - } - - String type = it->get_metadata(0); - - if (type.is_empty()) { - return Variant(); - } - - Dictionary dd; - TreeItem *root = members->get_root(); - - if (it->get_parent() == root->get_first_child()) { - dd["type"] = "visual_script_function_drag"; - dd["function"] = type; - } else if (it->get_parent() == root->get_first_child()->get_next()) { - dd["type"] = "visual_script_variable_drag"; - dd["variable"] = type; - } else if (it->get_parent() == root->get_first_child()->get_next()->get_next()) { - dd["type"] = "visual_script_signal_drag"; - dd["signal"] = type; - - } else { - return Variant(); - } - - Label *label = memnew(Label); - label->set_text(it->get_text(0)); - set_drag_preview(label); - return dd; - } - return Variant(); -} - -bool VisualScriptEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const { - if (p_from == graph) { - Dictionary d = p_data; - if (d.has("type") && - (String(d["type"]) == "visual_script_node_drag" || - String(d["type"]) == "visual_script_function_drag" || - String(d["type"]) == "visual_script_variable_drag" || - String(d["type"]) == "visual_script_signal_drag" || - String(d["type"]) == "obj_property" || - String(d["type"]) == "resource" || - String(d["type"]) == "files" || - String(d["type"]) == "nodes")) { - if (String(d["type"]) == "obj_property") { -#ifdef MACOS_ENABLED - const_cast(this)->_show_hint(vformat(TTR("Hold %s to drop a Getter. Hold Shift to drop a generic signature."), find_keycode_name(Key::META))); -#else - const_cast(this)->_show_hint(TTR("Hold Ctrl to drop a Getter. Hold Shift to drop a generic signature.")); -#endif - } - - if (String(d["type"]) == "nodes") { -#ifdef MACOS_ENABLED - const_cast(this)->_show_hint(vformat(TTR("Hold %s to drop a simple reference to the node."), find_keycode_name(Key::META))); -#else - const_cast(this)->_show_hint(TTR("Hold Ctrl to drop a simple reference to the node.")); -#endif - } - - if (String(d["type"]) == "visual_script_variable_drag") { -#ifdef MACOS_ENABLED - const_cast(this)->_show_hint(vformat(TTR("Hold %s to drop a Variable Setter."), find_keycode_name(Key::META))); -#else - const_cast(this)->_show_hint(TTR("Hold Ctrl to drop a Variable Setter.")); -#endif - } - - return true; - } - } - - return false; -} - -static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const Ref