summaryrefslogtreecommitdiff
path: root/modules/visual_script
diff options
context:
space:
mode:
Diffstat (limited to 'modules/visual_script')
-rw-r--r--modules/visual_script/SCsub3
-rw-r--r--modules/visual_script/config.py1
-rw-r--r--modules/visual_script/doc_classes/VisualScript.xml377
-rw-r--r--modules/visual_script/doc_classes/VisualScriptBasicTypeConstant.xml6
-rw-r--r--modules/visual_script/doc_classes/VisualScriptBuiltinFunc.xml141
-rw-r--r--modules/visual_script/doc_classes/VisualScriptClassConstant.xml10
-rw-r--r--modules/visual_script/doc_classes/VisualScriptComment.xml8
-rw-r--r--modules/visual_script/doc_classes/VisualScriptComposeArray.xml6
-rw-r--r--modules/visual_script/doc_classes/VisualScriptCondition.xml6
-rw-r--r--modules/visual_script/doc_classes/VisualScriptConstant.xml6
-rw-r--r--modules/visual_script/doc_classes/VisualScriptConstructor.xml22
-rw-r--r--modules/visual_script/doc_classes/VisualScriptCustomNode.xml155
-rw-r--r--modules/visual_script/doc_classes/VisualScriptCustomNodes.xml (renamed from modules/visual_script/doc_classes/VisualScriptEditor.xml)27
-rw-r--r--modules/visual_script/doc_classes/VisualScriptDeconstruct.xml6
-rw-r--r--modules/visual_script/doc_classes/VisualScriptEmitSignal.xml8
-rw-r--r--modules/visual_script/doc_classes/VisualScriptEngineSingleton.xml6
-rw-r--r--modules/visual_script/doc_classes/VisualScriptExpression.xml8
-rw-r--r--modules/visual_script/doc_classes/VisualScriptFunction.xml8
-rw-r--r--modules/visual_script/doc_classes/VisualScriptFunctionCall.xml30
-rw-r--r--modules/visual_script/doc_classes/VisualScriptFunctionState.xml30
-rw-r--r--modules/visual_script/doc_classes/VisualScriptGlobalConstant.xml9
-rw-r--r--modules/visual_script/doc_classes/VisualScriptIndexGet.xml8
-rw-r--r--modules/visual_script/doc_classes/VisualScriptIndexSet.xml8
-rw-r--r--modules/visual_script/doc_classes/VisualScriptInputAction.xml14
-rw-r--r--modules/visual_script/doc_classes/VisualScriptIterator.xml6
-rw-r--r--modules/visual_script/doc_classes/VisualScriptLists.xml84
-rw-r--r--modules/visual_script/doc_classes/VisualScriptLocalVar.xml8
-rw-r--r--modules/visual_script/doc_classes/VisualScriptLocalVarSet.xml8
-rw-r--r--modules/visual_script/doc_classes/VisualScriptMathConstant.xml4
-rw-r--r--modules/visual_script/doc_classes/VisualScriptNode.xml25
-rw-r--r--modules/visual_script/doc_classes/VisualScriptOperator.xml9
-rw-r--r--modules/visual_script/doc_classes/VisualScriptPreload.xml6
-rw-r--r--modules/visual_script/doc_classes/VisualScriptPropertyGet.xml21
-rw-r--r--modules/visual_script/doc_classes/VisualScriptPropertySet.xml33
-rw-r--r--modules/visual_script/doc_classes/VisualScriptResourcePath.xml6
-rw-r--r--modules/visual_script/doc_classes/VisualScriptReturn.xml6
-rw-r--r--modules/visual_script/doc_classes/VisualScriptSceneNode.xml6
-rw-r--r--modules/visual_script/doc_classes/VisualScriptSceneTree.xml8
-rw-r--r--modules/visual_script/doc_classes/VisualScriptSelect.xml6
-rw-r--r--modules/visual_script/doc_classes/VisualScriptSelf.xml6
-rw-r--r--modules/visual_script/doc_classes/VisualScriptSequence.xml6
-rw-r--r--modules/visual_script/doc_classes/VisualScriptSubCall.xml16
-rw-r--r--modules/visual_script/doc_classes/VisualScriptSwitch.xml6
-rw-r--r--modules/visual_script/doc_classes/VisualScriptTypeCast.xml12
-rw-r--r--modules/visual_script/doc_classes/VisualScriptVariableGet.xml8
-rw-r--r--modules/visual_script/doc_classes/VisualScriptVariableSet.xml8
-rw-r--r--modules/visual_script/doc_classes/VisualScriptWhile.xml6
-rw-r--r--modules/visual_script/doc_classes/VisualScriptYield.xml11
-rw-r--r--modules/visual_script/doc_classes/VisualScriptYieldSignal.xml17
-rw-r--r--modules/visual_script/editor/visual_script_editor.cpp (renamed from modules/visual_script/visual_script_editor.cpp)2058
-rw-r--r--modules/visual_script/editor/visual_script_editor.h (renamed from modules/visual_script/visual_script_editor.h)171
-rw-r--r--modules/visual_script/editor/visual_script_property_selector.cpp1276
-rw-r--r--modules/visual_script/editor/visual_script_property_selector.h229
-rw-r--r--modules/visual_script/icons/VisualScript.svg2
-rw-r--r--modules/visual_script/icons/VisualScriptInternal.svg1
-rw-r--r--modules/visual_script/register_types.cpp180
-rw-r--r--modules/visual_script/register_types.h10
-rw-r--r--modules/visual_script/visual_script.cpp592
-rw-r--r--modules/visual_script/visual_script.h162
-rw-r--r--modules/visual_script/visual_script_builtin_funcs.cpp165
-rw-r--r--modules/visual_script/visual_script_builtin_funcs.h15
-rw-r--r--modules/visual_script/visual_script_expression.cpp89
-rw-r--r--modules/visual_script/visual_script_expression.h6
-rw-r--r--modules/visual_script/visual_script_flow_control.cpp122
-rw-r--r--modules/visual_script/visual_script_flow_control.h18
-rw-r--r--modules/visual_script/visual_script_func_nodes.cpp385
-rw-r--r--modules/visual_script/visual_script_func_nodes.h14
-rw-r--r--modules/visual_script/visual_script_nodes.cpp794
-rw-r--r--modules/visual_script/visual_script_nodes.h100
-rw-r--r--modules/visual_script/visual_script_property_selector.cpp724
-rw-r--r--modules/visual_script/visual_script_property_selector.h91
-rw-r--r--modules/visual_script/visual_script_yield_nodes.cpp85
-rw-r--r--modules/visual_script/visual_script_yield_nodes.h14
73 files changed, 4747 insertions, 3791 deletions
diff --git a/modules/visual_script/SCsub b/modules/visual_script/SCsub
index 16faea08d7..b91cceae09 100644
--- a/modules/visual_script/SCsub
+++ b/modules/visual_script/SCsub
@@ -6,3 +6,6 @@ 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
index b15479797c..e8990c43c8 100644
--- a/modules/visual_script/config.py
+++ b/modules/visual_script/config.py
@@ -17,6 +17,7 @@ def get_doc_classes():
"VisualScriptConstant",
"VisualScriptConstructor",
"VisualScriptCustomNode",
+ "VisualScriptCustomNodes",
"VisualScriptDeconstruct",
"VisualScriptEditor",
"VisualScriptEmitSignal",
diff --git a/modules/visual_script/doc_classes/VisualScript.xml b/modules/visual_script/doc_classes/VisualScript.xml
index 5112ea43a7..5807c98d32 100644
--- a/modules/visual_script/doc_classes/VisualScript.xml
+++ b/modules/visual_script/doc_classes/VisualScript.xml
@@ -1,468 +1,346 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualScript" inherits="Script" version="4.0">
+<class name="VisualScript" inherits="Script" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
A script implemented in the Visual Script programming environment.
</brief_description>
<description>
- A script implemented in the Visual Script programming environment. The script extends the functionality of all objects that instance it.
+ 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.
</description>
<tutorials>
- <link title="VisualScript tutorial index">https://docs.godotengine.org/en/latest/getting_started/scripting/visual_script/index.html</link>
+ <link title="VisualScript documentation index">$DOCS_URL/tutorials/scripting/visual_script/index.html</link>
</tutorials>
<methods>
<method name="add_custom_signal">
- <return type="void">
- </return>
- <argument index="0" name="name" type="StringName">
- </argument>
+ <return type="void" />
+ <argument index="0" name="name" type="StringName" />
<description>
Add a custom signal with the specified name to the VisualScript.
</description>
</method>
<method name="add_function">
- <return type="void">
- </return>
- <argument index="0" name="name" type="StringName">
- </argument>
- <argument index="1" name="func_node_id" type="int">
- </argument>
+ <return type="void" />
+ <argument index="0" name="name" type="StringName" />
+ <argument index="1" name="func_node_id" type="int" />
<description>
Add a function with the specified name to the VisualScript, and assign the root [VisualScriptFunction] node's id as [code]func_node_id[/code].
</description>
</method>
<method name="add_node">
- <return type="void">
- </return>
- <argument index="0" name="id" type="int">
- </argument>
- <argument index="1" name="node" type="VisualScriptNode">
- </argument>
- <argument index="2" name="position" type="Vector2" default="Vector2( 0, 0 )">
- </argument>
+ <return type="void" />
+ <argument index="0" name="id" type="int" />
+ <argument index="1" name="node" type="VisualScriptNode" />
+ <argument index="2" name="position" type="Vector2" default="Vector2(0, 0)" />
<description>
Add a node to the VisualScript.
</description>
</method>
<method name="add_variable">
- <return type="void">
- </return>
- <argument index="0" name="name" type="StringName">
- </argument>
- <argument index="1" name="default_value" type="Variant" default="null">
- </argument>
- <argument index="2" name="export" type="bool" default="false">
- </argument>
+ <return type="void" />
+ <argument index="0" name="name" type="StringName" />
+ <argument index="1" name="default_value" type="Variant" default="null" />
+ <argument index="2" name="export" type="bool" default="false" />
<description>
Add a variable to the VisualScript, optionally giving it a default value or marking it as exported.
</description>
</method>
<method name="custom_signal_add_argument">
- <return type="void">
- </return>
- <argument index="0" name="name" type="StringName">
- </argument>
- <argument index="1" name="type" type="int" enum="Variant.Type">
- </argument>
- <argument index="2" name="argname" type="String">
- </argument>
- <argument index="3" name="index" type="int" default="-1">
- </argument>
+ <return type="void" />
+ <argument index="0" name="name" type="StringName" />
+ <argument index="1" name="type" type="int" enum="Variant.Type" />
+ <argument index="2" name="argname" type="String" />
+ <argument index="3" name="index" type="int" default="-1" />
<description>
Add an argument to a custom signal added with [method add_custom_signal].
</description>
</method>
<method name="custom_signal_get_argument_count" qualifiers="const">
- <return type="int">
- </return>
- <argument index="0" name="name" type="StringName">
- </argument>
+ <return type="int" />
+ <argument index="0" name="name" type="StringName" />
<description>
Get the count of a custom signal's arguments.
</description>
</method>
<method name="custom_signal_get_argument_name" qualifiers="const">
- <return type="String">
- </return>
- <argument index="0" name="name" type="StringName">
- </argument>
- <argument index="1" name="argidx" type="int">
- </argument>
+ <return type="String" />
+ <argument index="0" name="name" type="StringName" />
+ <argument index="1" name="argidx" type="int" />
<description>
Get the name of a custom signal's argument.
</description>
</method>
<method name="custom_signal_get_argument_type" qualifiers="const">
- <return type="int" enum="Variant.Type">
- </return>
- <argument index="0" name="name" type="StringName">
- </argument>
- <argument index="1" name="argidx" type="int">
- </argument>
+ <return type="int" enum="Variant.Type" />
+ <argument index="0" name="name" type="StringName" />
+ <argument index="1" name="argidx" type="int" />
<description>
Get the type of a custom signal's argument.
</description>
</method>
<method name="custom_signal_remove_argument">
- <return type="void">
- </return>
- <argument index="0" name="name" type="StringName">
- </argument>
- <argument index="1" name="argidx" type="int">
- </argument>
+ <return type="void" />
+ <argument index="0" name="name" type="StringName" />
+ <argument index="1" name="argidx" type="int" />
<description>
Remove a specific custom signal's argument.
</description>
</method>
<method name="custom_signal_set_argument_name">
- <return type="void">
- </return>
- <argument index="0" name="name" type="StringName">
- </argument>
- <argument index="1" name="argidx" type="int">
- </argument>
- <argument index="2" name="argname" type="String">
- </argument>
+ <return type="void" />
+ <argument index="0" name="name" type="StringName" />
+ <argument index="1" name="argidx" type="int" />
+ <argument index="2" name="argname" type="String" />
<description>
Rename a custom signal's argument.
</description>
</method>
<method name="custom_signal_set_argument_type">
- <return type="void">
- </return>
- <argument index="0" name="name" type="StringName">
- </argument>
- <argument index="1" name="argidx" type="int">
- </argument>
- <argument index="2" name="type" type="int" enum="Variant.Type">
- </argument>
+ <return type="void" />
+ <argument index="0" name="name" type="StringName" />
+ <argument index="1" name="argidx" type="int" />
+ <argument index="2" name="type" type="int" enum="Variant.Type" />
<description>
Change the type of a custom signal's argument.
</description>
</method>
<method name="custom_signal_swap_argument">
- <return type="void">
- </return>
- <argument index="0" name="name" type="StringName">
- </argument>
- <argument index="1" name="argidx" type="int">
- </argument>
- <argument index="2" name="withidx" type="int">
- </argument>
+ <return type="void" />
+ <argument index="0" name="name" type="StringName" />
+ <argument index="1" name="argidx" type="int" />
+ <argument index="2" name="withidx" type="int" />
<description>
Swap two of the arguments of a custom signal.
</description>
</method>
<method name="data_connect">
- <return type="void">
- </return>
- <argument index="0" name="from_node" type="int">
- </argument>
- <argument index="1" name="from_port" type="int">
- </argument>
- <argument index="2" name="to_node" type="int">
- </argument>
- <argument index="3" name="to_port" type="int">
- </argument>
+ <return type="void" />
+ <argument index="0" name="from_node" type="int" />
+ <argument index="1" name="from_port" type="int" />
+ <argument index="2" name="to_node" type="int" />
+ <argument index="3" name="to_port" type="int" />
<description>
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].
</description>
</method>
<method name="data_disconnect">
- <return type="void">
- </return>
- <argument index="0" name="from_node" type="int">
- </argument>
- <argument index="1" name="from_port" type="int">
- </argument>
- <argument index="2" name="to_node" type="int">
- </argument>
- <argument index="3" name="to_port" type="int">
- </argument>
+ <return type="void" />
+ <argument index="0" name="from_node" type="int" />
+ <argument index="1" name="from_port" type="int" />
+ <argument index="2" name="to_node" type="int" />
+ <argument index="3" name="to_port" type="int" />
<description>
Disconnect two data ports previously connected with [method data_connect].
</description>
</method>
<method name="get_function_node_id" qualifiers="const">
- <return type="int">
- </return>
- <argument index="0" name="name" type="StringName">
- </argument>
+ <return type="int" />
+ <argument index="0" name="name" type="StringName" />
<description>
Returns the id of a function's entry point node.
</description>
</method>
<method name="get_node" qualifiers="const">
- <return type="VisualScriptNode">
- </return>
- <argument index="0" name="id" type="int">
- </argument>
+ <return type="VisualScriptNode" />
+ <argument index="0" name="id" type="int" />
<description>
Returns a node given its id.
</description>
</method>
<method name="get_node_position" qualifiers="const">
- <return type="Vector2">
- </return>
- <argument index="0" name="id" type="int">
- </argument>
+ <return type="Vector2" />
+ <argument index="0" name="id" type="int" />
<description>
Returns a node's position in pixels.
</description>
</method>
<method name="get_scroll" qualifiers="const">
- <return type="Vector2">
- </return>
+ <return type="Vector2" />
<description>
Returns the current position of the center of the screen.
</description>
</method>
<method name="get_variable_default_value" qualifiers="const">
- <return type="Variant">
- </return>
- <argument index="0" name="name" type="StringName">
- </argument>
+ <return type="Variant" />
+ <argument index="0" name="name" type="StringName" />
<description>
Returns the default (initial) value of a variable.
</description>
</method>
<method name="get_variable_export" qualifiers="const">
- <return type="bool">
- </return>
- <argument index="0" name="name" type="StringName">
- </argument>
+ <return type="bool" />
+ <argument index="0" name="name" type="StringName" />
<description>
Returns whether a variable is exported.
</description>
</method>
<method name="get_variable_info" qualifiers="const">
- <return type="Dictionary">
- </return>
- <argument index="0" name="name" type="StringName">
- </argument>
+ <return type="Dictionary" />
+ <argument index="0" name="name" type="StringName" />
<description>
Returns the information for a given variable as a dictionary. The information includes its name, type, hint and usage.
</description>
</method>
<method name="has_custom_signal" qualifiers="const">
- <return type="bool">
- </return>
- <argument index="0" name="name" type="StringName">
- </argument>
+ <return type="bool" />
+ <argument index="0" name="name" type="StringName" />
<description>
Returns whether a signal exists with the specified name.
</description>
</method>
<method name="has_data_connection" qualifiers="const">
- <return type="bool">
- </return>
- <argument index="0" name="from_node" type="int">
- </argument>
- <argument index="1" name="from_port" type="int">
- </argument>
- <argument index="2" name="to_node" type="int">
- </argument>
- <argument index="3" name="to_port" type="int">
- </argument>
+ <return type="bool" />
+ <argument index="0" name="from_node" type="int" />
+ <argument index="1" name="from_port" type="int" />
+ <argument index="2" name="to_node" type="int" />
+ <argument index="3" name="to_port" type="int" />
<description>
Returns whether the specified data ports are connected.
</description>
</method>
<method name="has_function" qualifiers="const">
- <return type="bool">
- </return>
- <argument index="0" name="name" type="StringName">
- </argument>
+ <return type="bool" />
+ <argument index="0" name="name" type="StringName" />
<description>
Returns whether a function exists with the specified name.
</description>
</method>
<method name="has_node" qualifiers="const">
- <return type="bool">
- </return>
- <argument index="0" name="id" type="int">
- </argument>
+ <return type="bool" />
+ <argument index="0" name="id" type="int" />
<description>
Returns whether a node exists with the given id.
</description>
</method>
<method name="has_sequence_connection" qualifiers="const">
- <return type="bool">
- </return>
- <argument index="0" name="from_node" type="int">
- </argument>
- <argument index="1" name="from_output" type="int">
- </argument>
- <argument index="2" name="to_node" type="int">
- </argument>
+ <return type="bool" />
+ <argument index="0" name="from_node" type="int" />
+ <argument index="1" name="from_output" type="int" />
+ <argument index="2" name="to_node" type="int" />
<description>
Returns whether the specified sequence ports are connected.
</description>
</method>
<method name="has_variable" qualifiers="const">
- <return type="bool">
- </return>
- <argument index="0" name="name" type="StringName">
- </argument>
+ <return type="bool" />
+ <argument index="0" name="name" type="StringName" />
<description>
Returns whether a variable exists with the specified name.
</description>
</method>
<method name="remove_custom_signal">
- <return type="void">
- </return>
- <argument index="0" name="name" type="StringName">
- </argument>
+ <return type="void" />
+ <argument index="0" name="name" type="StringName" />
<description>
Remove a custom signal with the given name.
</description>
</method>
<method name="remove_function">
- <return type="void">
- </return>
- <argument index="0" name="name" type="StringName">
- </argument>
+ <return type="void" />
+ <argument index="0" name="name" type="StringName" />
<description>
Remove a specific function and its nodes from the script.
</description>
</method>
<method name="remove_node">
- <return type="void">
- </return>
- <argument index="0" name="id" type="int">
- </argument>
+ <return type="void" />
+ <argument index="0" name="id" type="int" />
<description>
Remove the node with the specified id.
</description>
</method>
<method name="remove_variable">
- <return type="void">
- </return>
- <argument index="0" name="name" type="StringName">
- </argument>
+ <return type="void" />
+ <argument index="0" name="name" type="StringName" />
<description>
Remove a variable with the given name.
</description>
</method>
<method name="rename_custom_signal">
- <return type="void">
- </return>
- <argument index="0" name="name" type="StringName">
- </argument>
- <argument index="1" name="new_name" type="StringName">
- </argument>
+ <return type="void" />
+ <argument index="0" name="name" type="StringName" />
+ <argument index="1" name="new_name" type="StringName" />
<description>
Change the name of a custom signal.
</description>
</method>
<method name="rename_function">
- <return type="void">
- </return>
- <argument index="0" name="name" type="StringName">
- </argument>
- <argument index="1" name="new_name" type="StringName">
- </argument>
+ <return type="void" />
+ <argument index="0" name="name" type="StringName" />
+ <argument index="1" name="new_name" type="StringName" />
<description>
Change the name of a function.
</description>
</method>
<method name="rename_variable">
- <return type="void">
- </return>
- <argument index="0" name="name" type="StringName">
- </argument>
- <argument index="1" name="new_name" type="StringName">
- </argument>
+ <return type="void" />
+ <argument index="0" name="name" type="StringName" />
+ <argument index="1" name="new_name" type="StringName" />
<description>
Change the name of a variable.
</description>
</method>
<method name="sequence_connect">
- <return type="void">
- </return>
- <argument index="0" name="from_node" type="int">
- </argument>
- <argument index="1" name="from_output" type="int">
- </argument>
- <argument index="2" name="to_node" type="int">
- </argument>
+ <return type="void" />
+ <argument index="0" name="from_node" type="int" />
+ <argument index="1" name="from_output" type="int" />
+ <argument index="2" name="to_node" type="int" />
<description>
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.
</description>
</method>
<method name="sequence_disconnect">
- <return type="void">
- </return>
- <argument index="0" name="from_node" type="int">
- </argument>
- <argument index="1" name="from_output" type="int">
- </argument>
- <argument index="2" name="to_node" type="int">
- </argument>
+ <return type="void" />
+ <argument index="0" name="from_node" type="int" />
+ <argument index="1" name="from_output" type="int" />
+ <argument index="2" name="to_node" type="int" />
<description>
Disconnect two sequence ports previously connected with [method sequence_connect].
</description>
</method>
<method name="set_instance_base_type">
- <return type="void">
- </return>
- <argument index="0" name="type" type="StringName">
- </argument>
+ <return type="void" />
+ <argument index="0" name="type" type="StringName" />
<description>
Set the base type of the script.
</description>
</method>
<method name="set_node_position">
- <return type="void">
- </return>
- <argument index="0" name="id" type="int">
- </argument>
- <argument index="1" name="position" type="Vector2">
- </argument>
+ <return type="void" />
+ <argument index="0" name="id" type="int" />
+ <argument index="1" name="position" type="Vector2" />
<description>
Set the node position in the VisualScript graph.
</description>
</method>
<method name="set_scroll">
- <return type="void">
- </return>
- <argument index="0" name="ofs" type="Vector2">
- </argument>
+ <return type="void" />
+ <argument index="0" name="offset" type="Vector2" />
<description>
Set the screen center to the given position.
</description>
</method>
<method name="set_variable_default_value">
- <return type="void">
- </return>
- <argument index="0" name="name" type="StringName">
- </argument>
- <argument index="1" name="value" type="Variant">
- </argument>
+ <return type="void" />
+ <argument index="0" name="name" type="StringName" />
+ <argument index="1" name="value" type="Variant" />
<description>
Change the default (initial) value of a variable.
</description>
</method>
<method name="set_variable_export">
- <return type="void">
- </return>
- <argument index="0" name="name" type="StringName">
- </argument>
- <argument index="1" name="enable" type="bool">
- </argument>
+ <return type="void" />
+ <argument index="0" name="name" type="StringName" />
+ <argument index="1" name="enable" type="bool" />
<description>
Change whether a variable is exported.
</description>
</method>
<method name="set_variable_info">
- <return type="void">
- </return>
- <argument index="0" name="name" type="StringName">
- </argument>
- <argument index="1" name="value" type="Dictionary">
- </argument>
+ <return type="void" />
+ <argument index="0" name="name" type="StringName" />
+ <argument index="1" name="value" type="Dictionary" />
<description>
Set a variable's info, using the same format as [method get_variable_info].
</description>
@@ -470,13 +348,10 @@
</methods>
<signals>
<signal name="node_ports_changed">
- <argument index="0" name="id" type="int">
- </argument>
+ <argument index="0" name="id" type="int" />
<description>
Emitted when the ports of a node are changed.
</description>
</signal>
</signals>
- <constants>
- </constants>
</class>
diff --git a/modules/visual_script/doc_classes/VisualScriptBasicTypeConstant.xml b/modules/visual_script/doc_classes/VisualScriptBasicTypeConstant.xml
index 4d07f878a2..0ed66f44e1 100644
--- a/modules/visual_script/doc_classes/VisualScriptBasicTypeConstant.xml
+++ b/modules/visual_script/doc_classes/VisualScriptBasicTypeConstant.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualScriptBasicTypeConstant" inherits="VisualScriptNode" version="4.0">
+<class name="VisualScriptBasicTypeConstant" inherits="VisualScriptNode" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
A Visual Script node representing a constant from the base types.
</brief_description>
@@ -8,8 +8,6 @@
</description>
<tutorials>
</tutorials>
- <methods>
- </methods>
<members>
<member name="basic_type" type="int" setter="set_basic_type" getter="get_basic_type" enum="Variant.Type" default="0">
The type to get the constant from.
@@ -18,6 +16,4 @@
The name of the constant to return.
</member>
</members>
- <constants>
- </constants>
</class>
diff --git a/modules/visual_script/doc_classes/VisualScriptBuiltinFunc.xml b/modules/visual_script/doc_classes/VisualScriptBuiltinFunc.xml
index 219ffd01d3..647b627d25 100644
--- a/modules/visual_script/doc_classes/VisualScriptBuiltinFunc.xml
+++ b/modules/visual_script/doc_classes/VisualScriptBuiltinFunc.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualScriptBuiltinFunc" inherits="VisualScriptNode" version="4.0">
+<class name="VisualScriptBuiltinFunc" inherits="VisualScriptNode" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
A Visual Script node used to call built-in functions.
</brief_description>
@@ -9,8 +9,6 @@
</description>
<tutorials>
</tutorials>
- <methods>
- </methods>
<members>
<member name="function" type="int" setter="set_func" getter="get_func" enum="VisualScriptBuiltinFunc.BuiltinFunc" default="0">
The function to be executed.
@@ -18,150 +16,149 @@
</members>
<constants>
<constant name="MATH_SIN" value="0" enum="BuiltinFunc">
- Return the sine of the input.
+ Returns the sine of the input.
</constant>
<constant name="MATH_COS" value="1" enum="BuiltinFunc">
- Return the cosine of the input.
+ Returns the cosine of the input.
</constant>
<constant name="MATH_TAN" value="2" enum="BuiltinFunc">
- Return the tangent of the input.
+ Returns the tangent of the input.
</constant>
<constant name="MATH_SINH" value="3" enum="BuiltinFunc">
- Return the hyperbolic sine of the input.
+ Returns the hyperbolic sine of the input.
</constant>
<constant name="MATH_COSH" value="4" enum="BuiltinFunc">
- Return the hyperbolic cosine of the input.
+ Returns the hyperbolic cosine of the input.
</constant>
<constant name="MATH_TANH" value="5" enum="BuiltinFunc">
- Return the hyperbolic tangent of the input.
+ Returns the hyperbolic tangent of the input.
</constant>
<constant name="MATH_ASIN" value="6" enum="BuiltinFunc">
- Return the arc sine of the input.
+ Returns the arc sine of the input.
</constant>
<constant name="MATH_ACOS" value="7" enum="BuiltinFunc">
- Return the arc cosine of the input.
+ Returns the arc cosine of the input.
</constant>
<constant name="MATH_ATAN" value="8" enum="BuiltinFunc">
- Return the arc tangent of the input.
+ Returns the arc tangent of the input.
</constant>
<constant name="MATH_ATAN2" value="9" enum="BuiltinFunc">
- Return the arc tangent of the input, using the signs of both parameters to determine the exact angle.
+ Returns the arc tangent of the input, using the signs of both parameters to determine the exact angle.
</constant>
<constant name="MATH_SQRT" value="10" enum="BuiltinFunc">
- Return the square root of the input.
+ Returns the square root of the input.
</constant>
<constant name="MATH_FMOD" value="11" enum="BuiltinFunc">
- Return the remainder of one input divided by the other, using floating-point numbers.
+ Returns the remainder of one input divided by the other, using floating-point numbers.
</constant>
<constant name="MATH_FPOSMOD" value="12" enum="BuiltinFunc">
- Return the positive 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.
</constant>
<constant name="MATH_FLOOR" value="13" enum="BuiltinFunc">
- Return the input rounded down.
+ Returns the input rounded down.
</constant>
<constant name="MATH_CEIL" value="14" enum="BuiltinFunc">
- Return the input rounded up.
+ Returns the input rounded up.
</constant>
<constant name="MATH_ROUND" value="15" enum="BuiltinFunc">
- Return the input rounded to the nearest integer.
+ Returns the input rounded to the nearest integer.
</constant>
<constant name="MATH_ABS" value="16" enum="BuiltinFunc">
- Return the absolute value of the input.
+ Returns the absolute value of the input.
</constant>
<constant name="MATH_SIGN" value="17" enum="BuiltinFunc">
- Return the sign of the input, turning it into 1, -1, or 0. Useful to determine if the input is positive or negative.
+ Returns the sign of the input, turning it into 1, -1, or 0. Useful to determine if the input is positive or negative.
</constant>
<constant name="MATH_POW" value="18" enum="BuiltinFunc">
- Return the input raised to a given power.
+ Returns the input raised to a given power.
</constant>
<constant name="MATH_LOG" value="19" enum="BuiltinFunc">
- Return the natural logarithm of the input. Note that this is not the typical base-10 logarithm function calculators use.
+ Returns the natural logarithm of the input. Note that this is not the typical base-10 logarithm function calculators use.
</constant>
<constant name="MATH_EXP" value="20" enum="BuiltinFunc">
- Return 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 the mathematical constant [b]e[/b] raised to the specified power of the input. [b]e[/b] has an approximate value of 2.71828.
</constant>
<constant name="MATH_ISNAN" value="21" enum="BuiltinFunc">
- Return 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 NaN (Not a Number) or not. NaN is usually produced by dividing 0 by 0, though other ways exist.
</constant>
<constant name="MATH_ISINF" value="22" enum="BuiltinFunc">
- Return 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.
+ 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.
</constant>
<constant name="MATH_EASE" value="23" enum="BuiltinFunc">
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.
</constant>
<constant name="MATH_STEP_DECIMALS" value="24" enum="BuiltinFunc">
- Return the number of digit places after the decimal that the first non-zero digit occurs.
+ Returns the number of digit places after the decimal that the first non-zero digit occurs.
</constant>
<constant name="MATH_SNAPPED" value="25" enum="BuiltinFunc">
- Return the input snapped to a given step.
+ Returns the input snapped to a given step.
</constant>
<constant name="MATH_LERP" value="26" enum="BuiltinFunc">
- Return a number linearly interpolated between the first two inputs, based on the third input. Uses the formula [code]a + (a - b) * t[/code].
+ Returns a number linearly interpolated between the first two inputs, based on the third input. Uses the formula [code]a + (a - b) * t[/code].
</constant>
- <constant name="MATH_INVERSE_LERP" value="27" enum="BuiltinFunc">
+ <constant name="MATH_CUBIC_INTERPOLATE" value="27" enum="BuiltinFunc">
</constant>
- <constant name="MATH_RANGE_LERP" value="28" enum="BuiltinFunc">
+ <constant name="MATH_INVERSE_LERP" value="28" enum="BuiltinFunc">
</constant>
- <constant name="MATH_MOVE_TOWARD" value="29" enum="BuiltinFunc">
- Moves the number toward a value, based on the third input.
+ <constant name="MATH_RANGE_LERP" value="29" enum="BuiltinFunc">
</constant>
- <constant name="MATH_DECTIME" value="30" enum="BuiltinFunc">
- Return the result of [code]value[/code] decreased by [code]step[/code] * [code]amount[/code].
+ <constant name="MATH_MOVE_TOWARD" value="30" enum="BuiltinFunc">
+ Moves the number toward a value, based on the third input.
</constant>
<constant name="MATH_RANDOMIZE" value="31" enum="BuiltinFunc">
Randomize the seed (or the internal state) of the random number generator. Current implementation reseeds using a number based on time.
</constant>
<constant name="MATH_RANDI" value="32" enum="BuiltinFunc">
- Return 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 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.
</constant>
<constant name="MATH_RANDF" value="33" enum="BuiltinFunc">
- Return 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 floating-point value between 0 and 1. To obtain a random value between 0 to N, you can use it with multiplication.
+ </constant>
+ <constant name="MATH_RANDI_RANGE" value="34" enum="BuiltinFunc">
+ Returns a random 32-bit integer value between the two inputs.
</constant>
- <constant name="MATH_RANDF_RANGE" value="34" enum="BuiltinFunc">
- Return a random floating-point value between the two inputs.
+ <constant name="MATH_RANDF_RANGE" value="35" enum="BuiltinFunc">
+ Returns a random floating-point value between the two inputs.
</constant>
- <constant name="MATH_RANDI_RANGE" value="35" enum="BuiltinFunc">
- Return a random 32-bit integer value between the two inputs.
+ <constant name="MATH_RANDFN" value="36" enum="BuiltinFunc">
+ 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.
</constant>
- <constant name="MATH_SEED" value="36" enum="BuiltinFunc">
+ <constant name="MATH_SEED" value="37" enum="BuiltinFunc">
Set the seed for the random number generator.
</constant>
- <constant name="MATH_RANDSEED" value="37" enum="BuiltinFunc">
- Return a random value from the given seed, along with the new seed.
+ <constant name="MATH_RANDSEED" value="38" enum="BuiltinFunc">
+ Returns a random value from the given seed, along with the new seed.
</constant>
- <constant name="MATH_DEG2RAD" value="38" enum="BuiltinFunc">
+ <constant name="MATH_DEG2RAD" value="39" enum="BuiltinFunc">
Convert the input from degrees to radians.
</constant>
- <constant name="MATH_RAD2DEG" value="39" enum="BuiltinFunc">
+ <constant name="MATH_RAD2DEG" value="40" enum="BuiltinFunc">
Convert the input from radians to degrees.
</constant>
- <constant name="MATH_LINEAR2DB" value="40" enum="BuiltinFunc">
+ <constant name="MATH_LINEAR2DB" value="41" enum="BuiltinFunc">
Convert the input from linear volume to decibel volume.
</constant>
- <constant name="MATH_DB2LINEAR" value="41" enum="BuiltinFunc">
+ <constant name="MATH_DB2LINEAR" value="42" enum="BuiltinFunc">
Convert the input from decibel volume to linear volume.
</constant>
- <constant name="MATH_POLAR2CARTESIAN" value="42" enum="BuiltinFunc">
- Converts a 2D point expressed in the polar coordinate system (a distance from the origin [code]r[/code] and an angle [code]th[/code]) to the cartesian coordinate system (X and Y axis).
+ <constant name="MATH_WRAP" value="43" enum="BuiltinFunc">
</constant>
- <constant name="MATH_CARTESIAN2POLAR" value="43" enum="BuiltinFunc">
- Converts a 2D point expressed in the cartesian coordinate system (X and Y axis) to the polar coordinate system (a distance from the origin and an angle).
+ <constant name="MATH_WRAPF" value="44" enum="BuiltinFunc">
</constant>
- <constant name="MATH_WRAP" value="44" enum="BuiltinFunc">
- </constant>
- <constant name="MATH_WRAPF" value="45" enum="BuiltinFunc">
+ <constant name="MATH_PINGPONG" value="45" enum="BuiltinFunc">
+ 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.
</constant>
<constant name="LOGIC_MAX" value="46" enum="BuiltinFunc">
- Return the greater of the two numbers, also known as their maximum.
+ Returns the greater of the two numbers, also known as their maximum.
</constant>
<constant name="LOGIC_MIN" value="47" enum="BuiltinFunc">
- Return the lesser of the two numbers, also known as their minimum.
+ Returns the lesser of the two numbers, also known as their minimum.
</constant>
<constant name="LOGIC_CLAMP" value="48" enum="BuiltinFunc">
- Return 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 input clamped inside the given range, ensuring the result is never outside it. Equivalent to [code]min(max(input, range_low), range_high)[/code].
</constant>
<constant name="LOGIC_NEAREST_PO2" value="49" enum="BuiltinFunc">
- Return the nearest power of 2 to the input.
+ Returns the nearest power of 2 to the input.
</constant>
<constant name="OBJ_WEAKREF" value="50" enum="BuiltinFunc">
Create a [WeakRef] from the input.
@@ -170,13 +167,13 @@
Convert between types.
</constant>
<constant name="TYPE_OF" value="52" enum="BuiltinFunc">
- Return the type of the input as an integer. Check [enum Variant.Type] for the integers that might be returned.
+ Returns the type of the input as an integer. Check [enum Variant.Type] for the integers that might be returned.
</constant>
<constant name="TYPE_EXISTS" value="53" enum="BuiltinFunc">
Checks if a type is registered in the [ClassDB].
</constant>
<constant name="TEXT_CHAR" value="54" enum="BuiltinFunc">
- Return a character with the given ascii value.
+ Returns a character with the given ascii value.
</constant>
<constant name="TEXT_STR" value="55" enum="BuiltinFunc">
Convert the input to a string.
@@ -190,32 +187,34 @@
<constant name="TEXT_PRINTRAW" value="58" enum="BuiltinFunc">
Print the given string to the standard output, without adding a newline.
</constant>
- <constant name="VAR_TO_STR" value="59" enum="BuiltinFunc">
+ <constant name="TEXT_PRINT_VERBOSE" value="59" enum="BuiltinFunc">
+ </constant>
+ <constant name="VAR_TO_STR" value="60" enum="BuiltinFunc">
Serialize a [Variant] to a string.
</constant>
- <constant name="STR_TO_VAR" value="60" enum="BuiltinFunc">
+ <constant name="STR_TO_VAR" value="61" enum="BuiltinFunc">
Deserialize a [Variant] from a string serialized using [constant VAR_TO_STR].
</constant>
- <constant name="VAR_TO_BYTES" value="61" enum="BuiltinFunc">
+ <constant name="VAR_TO_BYTES" value="62" enum="BuiltinFunc">
Serialize a [Variant] to a [PackedByteArray].
</constant>
- <constant name="BYTES_TO_VAR" value="62" enum="BuiltinFunc">
+ <constant name="BYTES_TO_VAR" value="63" enum="BuiltinFunc">
Deserialize a [Variant] from a [PackedByteArray] serialized using [constant VAR_TO_BYTES].
</constant>
- <constant name="MATH_SMOOTHSTEP" value="63" enum="BuiltinFunc">
- Return 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:
+ <constant name="MATH_SMOOTHSTEP" value="64" enum="BuiltinFunc">
+ 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]
</constant>
- <constant name="MATH_POSMOD" value="64" enum="BuiltinFunc">
+ <constant name="MATH_POSMOD" value="65" enum="BuiltinFunc">
</constant>
- <constant name="MATH_LERP_ANGLE" value="65" enum="BuiltinFunc">
+ <constant name="MATH_LERP_ANGLE" value="66" enum="BuiltinFunc">
</constant>
- <constant name="TEXT_ORD" value="66" enum="BuiltinFunc">
+ <constant name="TEXT_ORD" value="67" enum="BuiltinFunc">
</constant>
- <constant name="FUNC_MAX" value="67" enum="BuiltinFunc">
+ <constant name="FUNC_MAX" value="68" enum="BuiltinFunc">
Represents the size of the [enum BuiltinFunc] enum.
</constant>
</constants>
diff --git a/modules/visual_script/doc_classes/VisualScriptClassConstant.xml b/modules/visual_script/doc_classes/VisualScriptClassConstant.xml
index de5d731cc0..2509084f0e 100644
--- a/modules/visual_script/doc_classes/VisualScriptClassConstant.xml
+++ b/modules/visual_script/doc_classes/VisualScriptClassConstant.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualScriptClassConstant" inherits="VisualScriptNode" version="4.0">
+<class name="VisualScriptClassConstant" inherits="VisualScriptNode" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
Gets a constant from a given class.
</brief_description>
@@ -12,16 +12,12 @@
</description>
<tutorials>
</tutorials>
- <methods>
- </methods>
<members>
- <member name="base_type" type="StringName" setter="set_base_type" getter="get_base_type" default="@&quot;Object&quot;">
+ <member name="base_type" type="StringName" setter="set_base_type" getter="get_base_type" default="&amp;&quot;Object&quot;">
The constant's parent class.
</member>
- <member name="constant" type="StringName" setter="set_class_constant" getter="get_class_constant" default="@&quot;&quot;">
+ <member name="constant" type="StringName" setter="set_class_constant" getter="get_class_constant" default="&amp;&quot;&quot;">
The constant to return. See the given class for its available constants.
</member>
</members>
- <constants>
- </constants>
</class>
diff --git a/modules/visual_script/doc_classes/VisualScriptComment.xml b/modules/visual_script/doc_classes/VisualScriptComment.xml
index 243338ea52..cf4b57ca19 100644
--- a/modules/visual_script/doc_classes/VisualScriptComment.xml
+++ b/modules/visual_script/doc_classes/VisualScriptComment.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualScriptComment" inherits="VisualScriptNode" version="4.0">
+<class name="VisualScriptComment" inherits="VisualScriptNode" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
A Visual Script node used to annotate the script.
</brief_description>
@@ -9,19 +9,15 @@
</description>
<tutorials>
</tutorials>
- <methods>
- </methods>
<members>
<member name="description" type="String" setter="set_description" getter="get_description" default="&quot;&quot;">
The text inside the comment node.
</member>
- <member name="size" type="Vector2" setter="set_size" getter="get_size" default="Vector2( 150, 150 )">
+ <member name="size" type="Vector2" setter="set_size" getter="get_size" default="Vector2(150, 150)">
The comment node's size (in pixels).
</member>
<member name="title" type="String" setter="set_title" getter="get_title" default="&quot;Comment&quot;">
The comment node's title.
</member>
</members>
- <constants>
- </constants>
</class>
diff --git a/modules/visual_script/doc_classes/VisualScriptComposeArray.xml b/modules/visual_script/doc_classes/VisualScriptComposeArray.xml
index dec182abf6..ea73867c4b 100644
--- a/modules/visual_script/doc_classes/VisualScriptComposeArray.xml
+++ b/modules/visual_script/doc_classes/VisualScriptComposeArray.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualScriptComposeArray" inherits="VisualScriptLists" version="4.0">
+<class name="VisualScriptComposeArray" inherits="VisualScriptLists" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
A Visual Script Node used to create array from a list of items.
</brief_description>
@@ -8,8 +8,4 @@
</description>
<tutorials>
</tutorials>
- <methods>
- </methods>
- <constants>
- </constants>
</class>
diff --git a/modules/visual_script/doc_classes/VisualScriptCondition.xml b/modules/visual_script/doc_classes/VisualScriptCondition.xml
index a9981c1f57..a29388569f 100644
--- a/modules/visual_script/doc_classes/VisualScriptCondition.xml
+++ b/modules/visual_script/doc_classes/VisualScriptCondition.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualScriptCondition" inherits="VisualScriptNode" version="4.0">
+<class name="VisualScriptCondition" inherits="VisualScriptNode" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
A Visual Script node which branches the flow.
</brief_description>
@@ -15,8 +15,4 @@
</description>
<tutorials>
</tutorials>
- <methods>
- </methods>
- <constants>
- </constants>
</class>
diff --git a/modules/visual_script/doc_classes/VisualScriptConstant.xml b/modules/visual_script/doc_classes/VisualScriptConstant.xml
index 69676c4bba..645ede9001 100644
--- a/modules/visual_script/doc_classes/VisualScriptConstant.xml
+++ b/modules/visual_script/doc_classes/VisualScriptConstant.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualScriptConstant" inherits="VisualScriptNode" version="4.0">
+<class name="VisualScriptConstant" inherits="VisualScriptNode" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
Gets a contant's value.
</brief_description>
@@ -12,8 +12,6 @@
</description>
<tutorials>
</tutorials>
- <methods>
- </methods>
<members>
<member name="type" type="int" setter="set_constant_type" getter="get_constant_type" enum="Variant.Type" default="0">
The constant's type.
@@ -22,6 +20,4 @@
The constant's value.
</member>
</members>
- <constants>
- </constants>
</class>
diff --git a/modules/visual_script/doc_classes/VisualScriptConstructor.xml b/modules/visual_script/doc_classes/VisualScriptConstructor.xml
index 2f162e78b6..5ec17350bd 100644
--- a/modules/visual_script/doc_classes/VisualScriptConstructor.xml
+++ b/modules/visual_script/doc_classes/VisualScriptConstructor.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualScriptConstructor" inherits="VisualScriptNode" version="4.0">
+<class name="VisualScriptConstructor" inherits="VisualScriptNode" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
A Visual Script node which calls a base type constructor.
</brief_description>
@@ -10,34 +10,26 @@
</tutorials>
<methods>
<method name="get_constructor" qualifiers="const">
- <return type="Dictionary">
- </return>
+ <return type="Dictionary" />
<description>
</description>
</method>
<method name="get_constructor_type" qualifiers="const">
- <return type="int" enum="Variant.Type">
- </return>
+ <return type="int" enum="Variant.Type" />
<description>
</description>
</method>
<method name="set_constructor">
- <return type="void">
- </return>
- <argument index="0" name="constructor" type="Dictionary">
- </argument>
+ <return type="void" />
+ <argument index="0" name="constructor" type="Dictionary" />
<description>
</description>
</method>
<method name="set_constructor_type">
- <return type="void">
- </return>
- <argument index="0" name="type" type="int" enum="Variant.Type">
- </argument>
+ <return type="void" />
+ <argument index="0" name="type" type="int" enum="Variant.Type" />
<description>
</description>
</method>
</methods>
- <constants>
- </constants>
</class>
diff --git a/modules/visual_script/doc_classes/VisualScriptCustomNode.xml b/modules/visual_script/doc_classes/VisualScriptCustomNode.xml
index 1c23b58507..97b89fb987 100644
--- a/modules/visual_script/doc_classes/VisualScriptCustomNode.xml
+++ b/modules/visual_script/doc_classes/VisualScriptCustomNode.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualScriptCustomNode" inherits="VisualScriptNode" version="4.0">
+<class name="VisualScriptCustomNode" inherits="VisualScriptNode" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
A scripted Visual Script node.
</brief_description>
@@ -9,124 +9,129 @@
<tutorials>
</tutorials>
<methods>
- <method name="_get_caption" qualifiers="virtual">
- <return type="String">
- </return>
+ <method name="_get_caption" qualifiers="virtual const">
+ <return type="String" />
<description>
- Return the node's title.
+ Returns the node's title.
</description>
</method>
- <method name="_get_category" qualifiers="virtual">
- <return type="String">
- </return>
+ <method name="_get_category" qualifiers="virtual const">
+ <return type="String" />
<description>
- Return the node's category.
+ Returns the node's category.
</description>
</method>
- <method name="_get_input_value_port_count" qualifiers="virtual">
- <return type="int">
- </return>
+ <method name="_get_input_value_port_count" qualifiers="virtual const">
+ <return type="int" />
<description>
- Return the count of input value ports.
+ Returns the count of input value ports.
</description>
</method>
- <method name="_get_input_value_port_name" qualifiers="virtual">
- <return type="String">
- </return>
- <argument index="0" name="idx" type="int">
- </argument>
+ <method name="_get_input_value_port_hint" qualifiers="virtual const">
+ <return type="int" />
+ <argument index="0" name="input_idx" type="int" />
<description>
- Return the specified input port's name.
+ Returns the specified input port's hint. See the [enum @GlobalScope.PropertyHint] hints.
</description>
</method>
- <method name="_get_input_value_port_type" qualifiers="virtual">
- <return type="int">
- </return>
- <argument index="0" name="idx" type="int">
- </argument>
+ <method name="_get_input_value_port_hint_string" qualifiers="virtual const">
+ <return type="String" />
+ <argument index="0" name="input_idx" type="int" />
<description>
- Return the specified input port's type. See the [enum Variant.Type] values.
+ Returns the specified input port's hint string.
</description>
</method>
- <method name="_get_output_sequence_port_count" qualifiers="virtual">
- <return type="int">
- </return>
+ <method name="_get_input_value_port_name" qualifiers="virtual const">
+ <return type="String" />
+ <argument index="0" name="input_idx" type="int" />
<description>
- Return the amount of output [b]sequence[/b] ports.
+ Returns the specified input port's name.
</description>
</method>
- <method name="_get_output_sequence_port_text" qualifiers="virtual">
- <return type="String">
- </return>
- <argument index="0" name="idx" type="int">
- </argument>
+ <method name="_get_input_value_port_type" qualifiers="virtual const">
+ <return type="int" />
+ <argument index="0" name="input_idx" type="int" />
<description>
- Return the specified [b]sequence[/b] output's name.
+ Returns the specified input port's type. See the [enum Variant.Type] values.
</description>
</method>
- <method name="_get_output_value_port_count" qualifiers="virtual">
- <return type="int">
- </return>
+ <method name="_get_output_sequence_port_count" qualifiers="virtual const">
+ <return type="int" />
<description>
- Return the amount of output value ports.
+ Returns the amount of output [b]sequence[/b] ports.
</description>
</method>
- <method name="_get_output_value_port_name" qualifiers="virtual">
- <return type="String">
- </return>
- <argument index="0" name="idx" type="int">
- </argument>
+ <method name="_get_output_sequence_port_text" qualifiers="virtual const">
+ <return type="String" />
+ <argument index="0" name="seq_idx" type="int" />
<description>
- Return the specified output's name.
+ Returns the specified [b]sequence[/b] output's name.
</description>
</method>
- <method name="_get_output_value_port_type" qualifiers="virtual">
- <return type="int">
- </return>
- <argument index="0" name="idx" type="int">
- </argument>
+ <method name="_get_output_value_port_count" qualifiers="virtual const">
+ <return type="int" />
<description>
- Return the specified output's type. See the [enum Variant.Type] values.
+ Returns the amount of output value ports.
</description>
</method>
- <method name="_get_text" qualifiers="virtual">
- <return type="String">
- </return>
+ <method name="_get_output_value_port_hint" qualifiers="virtual const">
+ <return type="int" />
+ <argument index="0" name="output_idx" type="int" />
<description>
- Return 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 specified output port's hint. See the [enum @GlobalScope.PropertyHint] hints.
</description>
</method>
- <method name="_get_working_memory_size" qualifiers="virtual">
- <return type="int">
- </return>
+ <method name="_get_output_value_port_hint_string" qualifiers="virtual const">
+ <return type="String" />
+ <argument index="0" name="output_idx" type="int" />
<description>
- Return the size of the custom node's working memory. See [method _step] for more details.
+ Returns the specified output port's hint string.
</description>
</method>
- <method name="_has_input_sequence_port" qualifiers="virtual">
- <return type="bool">
- </return>
+ <method name="_get_output_value_port_name" qualifiers="virtual const">
+ <return type="String" />
+ <argument index="0" name="output_idx" type="int" />
<description>
- Return whether the custom node has an input [b]sequence[/b] port.
+ Returns the specified output port's name.
</description>
</method>
- <method name="_step" qualifiers="virtual">
- <return type="Variant">
- </return>
- <argument index="0" name="inputs" type="Array">
- </argument>
- <argument index="1" name="outputs" type="Array">
- </argument>
- <argument index="2" name="start_mode" type="int">
- </argument>
- <argument index="3" name="working_mem" type="Array">
- </argument>
+ <method name="_get_output_value_port_type" qualifiers="virtual const">
+ <return type="int" />
+ <argument index="0" name="output_idx" type="int" />
+ <description>
+ Returns the specified output port's type. See the [enum Variant.Type] values.
+ </description>
+ </method>
+ <method name="_get_text" qualifiers="virtual const">
+ <return type="String" />
+ <description>
+ 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).
+ </description>
+ </method>
+ <method name="_get_working_memory_size" qualifiers="virtual const">
+ <return type="int" />
+ <description>
+ Returns the size of the custom node's working memory. See [method _step] for more details.
+ </description>
+ </method>
+ <method name="_has_input_sequence_port" qualifiers="virtual const">
+ <return type="bool" />
+ <description>
+ Returns whether the custom node has an input [b]sequence[/b] port.
+ </description>
+ </method>
+ <method name="_step" qualifiers="virtual const">
+ <return type="Variant" />
+ <argument index="0" name="inputs" type="Array" />
+ <argument index="1" name="outputs" type="Array" />
+ <argument index="2" name="start_mode" type="int" />
+ <argument index="3" name="working_mem" type="Array" />
<description>
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.
+ [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.
</description>
</method>
diff --git a/modules/visual_script/doc_classes/VisualScriptEditor.xml b/modules/visual_script/doc_classes/VisualScriptCustomNodes.xml
index 186cd21239..f04c862174 100644
--- a/modules/visual_script/doc_classes/VisualScriptEditor.xml
+++ b/modules/visual_script/doc_classes/VisualScriptCustomNodes.xml
@@ -1,32 +1,27 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualScriptEditor" inherits="Object" version="4.0">
+<class name="VisualScriptCustomNodes" inherits="Object" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
+ Manages custom nodes for the Visual Script editor.
</brief_description>
<description>
+ This singleton can be used to manage (i.e., add or remove) custom nodes for the Visual Script editor.
</description>
<tutorials>
</tutorials>
<methods>
<method name="add_custom_node">
- <return type="void">
- </return>
- <argument index="0" name="name" type="String">
- </argument>
- <argument index="1" name="category" type="String">
- </argument>
- <argument index="2" name="script" type="Script">
- </argument>
+ <return type="void" />
+ <argument index="0" name="name" type="String" />
+ <argument index="1" name="category" type="String" />
+ <argument index="2" name="script" type="Script" />
<description>
Add a custom Visual Script node to the editor. It'll be placed under "Custom Nodes" with the [code]category[/code] as the parameter.
</description>
</method>
<method name="remove_custom_node">
- <return type="void">
- </return>
- <argument index="0" name="name" type="String">
- </argument>
- <argument index="1" name="category" type="String">
- </argument>
+ <return type="void" />
+ <argument index="0" name="name" type="String" />
+ <argument index="1" name="category" type="String" />
<description>
Remove a custom Visual Script node from the editor. Custom nodes already placed on scripts won't be removed.
</description>
@@ -39,6 +34,4 @@
</description>
</signal>
</signals>
- <constants>
- </constants>
</class>
diff --git a/modules/visual_script/doc_classes/VisualScriptDeconstruct.xml b/modules/visual_script/doc_classes/VisualScriptDeconstruct.xml
index 530c80530e..b544fd9d90 100644
--- a/modules/visual_script/doc_classes/VisualScriptDeconstruct.xml
+++ b/modules/visual_script/doc_classes/VisualScriptDeconstruct.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualScriptDeconstruct" inherits="VisualScriptNode" version="4.0">
+<class name="VisualScriptDeconstruct" inherits="VisualScriptNode" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
A Visual Script node which deconstructs a base type instance into its parts.
</brief_description>
@@ -8,13 +8,9 @@
</description>
<tutorials>
</tutorials>
- <methods>
- </methods>
<members>
<member name="type" type="int" setter="set_deconstruct_type" getter="get_deconstruct_type" enum="Variant.Type" default="0">
The type to deconstruct.
</member>
</members>
- <constants>
- </constants>
</class>
diff --git a/modules/visual_script/doc_classes/VisualScriptEmitSignal.xml b/modules/visual_script/doc_classes/VisualScriptEmitSignal.xml
index 5c9c8d3eca..c0cefa0ab7 100644
--- a/modules/visual_script/doc_classes/VisualScriptEmitSignal.xml
+++ b/modules/visual_script/doc_classes/VisualScriptEmitSignal.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualScriptEmitSignal" inherits="VisualScriptNode" version="4.0">
+<class name="VisualScriptEmitSignal" inherits="VisualScriptNode" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
Emits a specified signal.
</brief_description>
@@ -12,13 +12,9 @@
</description>
<tutorials>
</tutorials>
- <methods>
- </methods>
<members>
- <member name="signal" type="StringName" setter="set_signal" getter="get_signal" default="@&quot;&quot;">
+ <member name="signal" type="StringName" setter="set_signal" getter="get_signal" default="&amp;&quot;&quot;">
The signal to emit.
</member>
</members>
- <constants>
- </constants>
</class>
diff --git a/modules/visual_script/doc_classes/VisualScriptEngineSingleton.xml b/modules/visual_script/doc_classes/VisualScriptEngineSingleton.xml
index 8b7fd3a612..f60a048845 100644
--- a/modules/visual_script/doc_classes/VisualScriptEngineSingleton.xml
+++ b/modules/visual_script/doc_classes/VisualScriptEngineSingleton.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualScriptEngineSingleton" inherits="VisualScriptNode" version="4.0">
+<class name="VisualScriptEngineSingleton" inherits="VisualScriptNode" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
A Visual Script node returning a singleton from [@GlobalScope].
</brief_description>
@@ -8,13 +8,9 @@
</description>
<tutorials>
</tutorials>
- <methods>
- </methods>
<members>
<member name="constant" type="String" setter="set_singleton" getter="get_singleton" default="&quot;&quot;">
The singleton's name.
</member>
</members>
- <constants>
- </constants>
</class>
diff --git a/modules/visual_script/doc_classes/VisualScriptExpression.xml b/modules/visual_script/doc_classes/VisualScriptExpression.xml
index 5253f7bc7d..14750e7c8d 100644
--- a/modules/visual_script/doc_classes/VisualScriptExpression.xml
+++ b/modules/visual_script/doc_classes/VisualScriptExpression.xml
@@ -1,13 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualScriptExpression" inherits="VisualScriptNode" version="4.0">
+<class name="VisualScriptExpression" inherits="VisualScriptNode" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
+ A Visual Script node that can execute a custom expression.
</brief_description>
<description>
+ 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.
</description>
<tutorials>
</tutorials>
- <methods>
- </methods>
- <constants>
- </constants>
</class>
diff --git a/modules/visual_script/doc_classes/VisualScriptFunction.xml b/modules/visual_script/doc_classes/VisualScriptFunction.xml
index 873d26a5be..74d9f194eb 100644
--- a/modules/visual_script/doc_classes/VisualScriptFunction.xml
+++ b/modules/visual_script/doc_classes/VisualScriptFunction.xml
@@ -1,13 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualScriptFunction" inherits="VisualScriptNode" version="4.0">
+<class name="VisualScriptFunction" inherits="VisualScriptNode" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
+ A Visual Script node representing a function.
</brief_description>
<description>
+ [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).
</description>
<tutorials>
</tutorials>
- <methods>
- </methods>
- <constants>
- </constants>
</class>
diff --git a/modules/visual_script/doc_classes/VisualScriptFunctionCall.xml b/modules/visual_script/doc_classes/VisualScriptFunctionCall.xml
index 2d0fac1fa0..543263ff8e 100644
--- a/modules/visual_script/doc_classes/VisualScriptFunctionCall.xml
+++ b/modules/visual_script/doc_classes/VisualScriptFunctionCall.xml
@@ -1,55 +1,75 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualScriptFunctionCall" inherits="VisualScriptNode" version="4.0">
+<class name="VisualScriptFunctionCall" inherits="VisualScriptNode" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
+ A Visual Script node for calling a function.
</brief_description>
<description>
+ [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.
</description>
<tutorials>
</tutorials>
- <methods>
- </methods>
<members>
<member name="base_script" type="String" setter="set_base_script" getter="get_base_script">
+ The script to be used when [member call_mode] is set to [constant CALL_MODE_INSTANCE].
</member>
- <member name="base_type" type="StringName" setter="set_base_type" getter="get_base_type" default="@&quot;Object&quot;">
+ <member name="base_type" type="StringName" setter="set_base_type" getter="get_base_type" default="&amp;&quot;Object&quot;">
+ The base type to be used when [member call_mode] is set to [constant CALL_MODE_INSTANCE].
</member>
<member name="basic_type" type="int" setter="set_basic_type" getter="get_basic_type" enum="Variant.Type">
+ The type to be used when [member call_mode] is set to [constant CALL_MODE_BASIC_TYPE].
</member>
<member name="call_mode" type="int" setter="set_call_mode" getter="get_call_mode" enum="VisualScriptFunctionCall.CallMode" default="0">
+ [code]call_mode[/code] determines the target object on which the method will be called. See [enum CallMode] for options.
</member>
- <member name="function" type="StringName" setter="set_function" getter="get_function" default="@&quot;&quot;">
+ <member name="function" type="StringName" setter="set_function" getter="get_function" default="&amp;&quot;&quot;">
+ The name of the function to be called.
</member>
<member name="node_path" type="NodePath" setter="set_base_path" getter="get_base_path">
+ The node path to use when [member call_mode] is set to [constant CALL_MODE_NODE_PATH].
</member>
<member name="rpc_call_mode" type="int" setter="set_rpc_call_mode" getter="get_rpc_call_mode" enum="VisualScriptFunctionCall.RPCCallMode" default="0">
+ The mode for RPC calls. See [method Node.rpc] for more details and [enum RPCCallMode] for available options.
</member>
<member name="singleton" type="StringName" setter="set_singleton" getter="get_singleton">
+ The singleton to call the method on. Used when [member call_mode] is set to [constant CALL_MODE_SINGLETON].
</member>
<member name="use_default_args" type="int" setter="set_use_default_args" getter="get_use_default_args">
+ 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.
</member>
<member name="validate" type="bool" setter="set_validate" getter="get_validate" default="true">
+ If [code]false[/code], call errors (e.g. wrong number of arguments) will be ignored.
</member>
</members>
<constants>
<constant name="CALL_MODE_SELF" value="0" enum="CallMode">
+ The method will be called on this [Object].
</constant>
<constant name="CALL_MODE_NODE_PATH" value="1" enum="CallMode">
+ The method will be called on the given [Node] in the scene tree.
</constant>
<constant name="CALL_MODE_INSTANCE" value="2" enum="CallMode">
+ The method will be called on an instanced node with the given type and script.
</constant>
<constant name="CALL_MODE_BASIC_TYPE" value="3" enum="CallMode">
+ The method will be called on a GDScript basic type (e.g. [Vector2]).
</constant>
<constant name="CALL_MODE_SINGLETON" value="4" enum="CallMode">
+ The method will be called on a singleton.
</constant>
<constant name="RPC_DISABLED" value="0" enum="RPCCallMode">
+ The method will be called locally.
</constant>
<constant name="RPC_RELIABLE" value="1" enum="RPCCallMode">
+ The method will be called remotely.
</constant>
<constant name="RPC_UNRELIABLE" value="2" enum="RPCCallMode">
+ The method will be called remotely using an unreliable protocol.
</constant>
<constant name="RPC_RELIABLE_TO_ID" value="3" enum="RPCCallMode">
+ The method will be called remotely for the given peer.
</constant>
<constant name="RPC_UNRELIABLE_TO_ID" value="4" enum="RPCCallMode">
+ The method will be called remotely for the given peer, using an unreliable protocol.
</constant>
</constants>
</class>
diff --git a/modules/visual_script/doc_classes/VisualScriptFunctionState.xml b/modules/visual_script/doc_classes/VisualScriptFunctionState.xml
index 68083614a6..ef09c9d4a0 100644
--- a/modules/visual_script/doc_classes/VisualScriptFunctionState.xml
+++ b/modules/visual_script/doc_classes/VisualScriptFunctionState.xml
@@ -1,39 +1,35 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualScriptFunctionState" inherits="Reference" version="4.0">
+<class name="VisualScriptFunctionState" inherits="RefCounted" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
+ A Visual Script node representing a function state.
</brief_description>
<description>
+ [VisualScriptFunctionState] is returned from [VisualScriptYield] and can be used to resume a paused function call.
</description>
<tutorials>
</tutorials>
<methods>
<method name="connect_to_signal">
- <return type="void">
- </return>
- <argument index="0" name="obj" type="Object">
- </argument>
- <argument index="1" name="signals" type="String">
- </argument>
- <argument index="2" name="args" type="Array">
- </argument>
+ <return type="void" />
+ <argument index="0" name="obj" type="Object" />
+ <argument index="1" name="signals" type="String" />
+ <argument index="2" name="args" type="Array" />
<description>
+ Connects this [VisualScriptFunctionState] to a signal in the given object to automatically resume when it's emitted.
</description>
</method>
<method name="is_valid" qualifiers="const">
- <return type="bool">
- </return>
+ <return type="bool" />
<description>
+ Returns whether the function state is valid.
</description>
</method>
<method name="resume">
- <return type="Variant">
- </return>
- <argument index="0" name="args" type="Array" default="null">
- </argument>
+ <return type="Variant" />
+ <argument index="0" name="args" type="Array" default="[]" />
<description>
+ Resumes the function to run from the point it was yielded.
</description>
</method>
</methods>
- <constants>
- </constants>
</class>
diff --git a/modules/visual_script/doc_classes/VisualScriptGlobalConstant.xml b/modules/visual_script/doc_classes/VisualScriptGlobalConstant.xml
index ef17bd8a28..42ada99257 100644
--- a/modules/visual_script/doc_classes/VisualScriptGlobalConstant.xml
+++ b/modules/visual_script/doc_classes/VisualScriptGlobalConstant.xml
@@ -1,17 +1,16 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualScriptGlobalConstant" inherits="VisualScriptNode" version="4.0">
+<class name="VisualScriptGlobalConstant" inherits="VisualScriptNode" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
+ A Visual Script node returning a constant from [@GlobalScope].
</brief_description>
<description>
+ A Visual Script node returning a constant from [@GlobalScope].
</description>
<tutorials>
</tutorials>
- <methods>
- </methods>
<members>
<member name="constant" type="int" setter="set_global_constant" getter="get_global_constant" default="0">
+ The constant to be used.
</member>
</members>
- <constants>
- </constants>
</class>
diff --git a/modules/visual_script/doc_classes/VisualScriptIndexGet.xml b/modules/visual_script/doc_classes/VisualScriptIndexGet.xml
index bb1618a655..8828bf9039 100644
--- a/modules/visual_script/doc_classes/VisualScriptIndexGet.xml
+++ b/modules/visual_script/doc_classes/VisualScriptIndexGet.xml
@@ -1,13 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualScriptIndexGet" inherits="VisualScriptNode" version="4.0">
+<class name="VisualScriptIndexGet" inherits="VisualScriptNode" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
+ A Visual Script node for getting a value from an array or a dictionary.
</brief_description>
<description>
+ [VisualScriptIndexGet] will return the value stored in an array or a dictionary under the given index.
</description>
<tutorials>
</tutorials>
- <methods>
- </methods>
- <constants>
- </constants>
</class>
diff --git a/modules/visual_script/doc_classes/VisualScriptIndexSet.xml b/modules/visual_script/doc_classes/VisualScriptIndexSet.xml
index 4ff96f7211..5c81dcd339 100644
--- a/modules/visual_script/doc_classes/VisualScriptIndexSet.xml
+++ b/modules/visual_script/doc_classes/VisualScriptIndexSet.xml
@@ -1,13 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualScriptIndexSet" inherits="VisualScriptNode" version="4.0">
+<class name="VisualScriptIndexSet" inherits="VisualScriptNode" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
+ A Visual Script node for setting a value in an array or a dictionary.
</brief_description>
<description>
+ [VisualScriptIndexSet] will set the value stored in an array or a dictionary under the given index to the provided new value.
</description>
<tutorials>
</tutorials>
- <methods>
- </methods>
- <constants>
- </constants>
</class>
diff --git a/modules/visual_script/doc_classes/VisualScriptInputAction.xml b/modules/visual_script/doc_classes/VisualScriptInputAction.xml
index 6c296fdb4b..51c2eaf353 100644
--- a/modules/visual_script/doc_classes/VisualScriptInputAction.xml
+++ b/modules/visual_script/doc_classes/VisualScriptInputAction.xml
@@ -1,27 +1,33 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualScriptInputAction" inherits="VisualScriptNode" version="4.0">
+<class name="VisualScriptInputAction" inherits="VisualScriptNode" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
+ A Visual Script node returning a state of an action.
</brief_description>
<description>
+ [VisualScriptInputAction] can be used to check if an action is pressed or released.
</description>
<tutorials>
</tutorials>
- <methods>
- </methods>
<members>
- <member name="action" type="StringName" setter="set_action_name" getter="get_action_name" default="@&quot;&quot;">
+ <member name="action" type="StringName" setter="set_action_name" getter="get_action_name" default="&amp;&quot;&quot;">
+ Name of the action.
</member>
<member name="mode" type="int" setter="set_action_mode" getter="get_action_mode" enum="VisualScriptInputAction.Mode" default="0">
+ State of the action to check. See [enum Mode] for options.
</member>
</members>
<constants>
<constant name="MODE_PRESSED" value="0" enum="Mode">
+ [code]True[/code] if action is pressed.
</constant>
<constant name="MODE_RELEASED" value="1" enum="Mode">
+ [code]True[/code] if action is released (i.e. not pressed).
</constant>
<constant name="MODE_JUST_PRESSED" value="2" enum="Mode">
+ [code]True[/code] on the frame the action was pressed.
</constant>
<constant name="MODE_JUST_RELEASED" value="3" enum="Mode">
+ [code]True[/code] on the frame the action was released.
</constant>
</constants>
</class>
diff --git a/modules/visual_script/doc_classes/VisualScriptIterator.xml b/modules/visual_script/doc_classes/VisualScriptIterator.xml
index 1d4ab4daa9..ef6846deba 100644
--- a/modules/visual_script/doc_classes/VisualScriptIterator.xml
+++ b/modules/visual_script/doc_classes/VisualScriptIterator.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualScriptIterator" inherits="VisualScriptNode" version="4.0">
+<class name="VisualScriptIterator" inherits="VisualScriptNode" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
Steps through items in a given input.
</brief_description>
@@ -15,8 +15,4 @@
</description>
<tutorials>
</tutorials>
- <methods>
- </methods>
- <constants>
- </constants>
</class>
diff --git a/modules/visual_script/doc_classes/VisualScriptLists.xml b/modules/visual_script/doc_classes/VisualScriptLists.xml
index 8a7254b46a..27a81fce2f 100644
--- a/modules/visual_script/doc_classes/VisualScriptLists.xml
+++ b/modules/visual_script/doc_classes/VisualScriptLists.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualScriptLists" inherits="VisualScriptNode" version="4.0">
+<class name="VisualScriptLists" inherits="VisualScriptNode" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
A Visual Script virtual class for in-graph editable nodes.
</brief_description>
@@ -10,86 +10,68 @@
</tutorials>
<methods>
<method name="add_input_data_port">
- <return type="void">
- </return>
- <argument index="0" name="type" type="int" enum="Variant.Type">
- </argument>
- <argument index="1" name="name" type="String">
- </argument>
- <argument index="2" name="index" type="int">
- </argument>
+ <return type="void" />
+ <argument index="0" name="type" type="int" enum="Variant.Type" />
+ <argument index="1" name="name" type="String" />
+ <argument index="2" name="index" type="int" />
<description>
+ Adds an input port to the Visual Script node.
</description>
</method>
<method name="add_output_data_port">
- <return type="void">
- </return>
- <argument index="0" name="type" type="int" enum="Variant.Type">
- </argument>
- <argument index="1" name="name" type="String">
- </argument>
- <argument index="2" name="index" type="int">
- </argument>
+ <return type="void" />
+ <argument index="0" name="type" type="int" enum="Variant.Type" />
+ <argument index="1" name="name" type="String" />
+ <argument index="2" name="index" type="int" />
<description>
+ Adds an output port to the Visual Script node.
</description>
</method>
<method name="remove_input_data_port">
- <return type="void">
- </return>
- <argument index="0" name="index" type="int">
- </argument>
+ <return type="void" />
+ <argument index="0" name="index" type="int" />
<description>
+ Removes an input port from the Visual Script node.
</description>
</method>
<method name="remove_output_data_port">
- <return type="void">
- </return>
- <argument index="0" name="index" type="int">
- </argument>
+ <return type="void" />
+ <argument index="0" name="index" type="int" />
<description>
+ Removes an output port from the Visual Script node.
</description>
</method>
<method name="set_input_data_port_name">
- <return type="void">
- </return>
- <argument index="0" name="index" type="int">
- </argument>
- <argument index="1" name="name" type="String">
- </argument>
+ <return type="void" />
+ <argument index="0" name="index" type="int" />
+ <argument index="1" name="name" type="String" />
<description>
+ Sets the name of an input port.
</description>
</method>
<method name="set_input_data_port_type">
- <return type="void">
- </return>
- <argument index="0" name="index" type="int">
- </argument>
- <argument index="1" name="type" type="int" enum="Variant.Type">
- </argument>
+ <return type="void" />
+ <argument index="0" name="index" type="int" />
+ <argument index="1" name="type" type="int" enum="Variant.Type" />
<description>
+ Sets the type of an input port.
</description>
</method>
<method name="set_output_data_port_name">
- <return type="void">
- </return>
- <argument index="0" name="index" type="int">
- </argument>
- <argument index="1" name="name" type="String">
- </argument>
+ <return type="void" />
+ <argument index="0" name="index" type="int" />
+ <argument index="1" name="name" type="String" />
<description>
+ Sets the name of an output port.
</description>
</method>
<method name="set_output_data_port_type">
- <return type="void">
- </return>
- <argument index="0" name="index" type="int">
- </argument>
- <argument index="1" name="type" type="int" enum="Variant.Type">
- </argument>
+ <return type="void" />
+ <argument index="0" name="index" type="int" />
+ <argument index="1" name="type" type="int" enum="Variant.Type" />
<description>
+ Sets the type of an output port.
</description>
</method>
</methods>
- <constants>
- </constants>
</class>
diff --git a/modules/visual_script/doc_classes/VisualScriptLocalVar.xml b/modules/visual_script/doc_classes/VisualScriptLocalVar.xml
index c3741eea89..dbf9049f0a 100644
--- a/modules/visual_script/doc_classes/VisualScriptLocalVar.xml
+++ b/modules/visual_script/doc_classes/VisualScriptLocalVar.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualScriptLocalVar" inherits="VisualScriptNode" version="4.0">
+<class name="VisualScriptLocalVar" inherits="VisualScriptNode" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
Gets a local variable's value.
</brief_description>
@@ -12,16 +12,12 @@
</description>
<tutorials>
</tutorials>
- <methods>
- </methods>
<members>
<member name="type" type="int" setter="set_var_type" getter="get_var_type" enum="Variant.Type" default="0">
The local variable's type.
</member>
- <member name="var_name" type="StringName" setter="set_var_name" getter="get_var_name" default="@&quot;new_local&quot;">
+ <member name="var_name" type="StringName" setter="set_var_name" getter="get_var_name" default="&amp;&quot;new_local&quot;">
The local variable's name.
</member>
</members>
- <constants>
- </constants>
</class>
diff --git a/modules/visual_script/doc_classes/VisualScriptLocalVarSet.xml b/modules/visual_script/doc_classes/VisualScriptLocalVarSet.xml
index 619bbb90ca..1ae4e20f97 100644
--- a/modules/visual_script/doc_classes/VisualScriptLocalVarSet.xml
+++ b/modules/visual_script/doc_classes/VisualScriptLocalVarSet.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualScriptLocalVarSet" inherits="VisualScriptNode" version="4.0">
+<class name="VisualScriptLocalVarSet" inherits="VisualScriptNode" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
Changes a local variable's value.
</brief_description>
@@ -14,16 +14,12 @@
</description>
<tutorials>
</tutorials>
- <methods>
- </methods>
<members>
<member name="type" type="int" setter="set_var_type" getter="get_var_type" enum="Variant.Type" default="0">
The local variable's type.
</member>
- <member name="var_name" type="StringName" setter="set_var_name" getter="get_var_name" default="@&quot;new_local&quot;">
+ <member name="var_name" type="StringName" setter="set_var_name" getter="get_var_name" default="&amp;&quot;new_local&quot;">
The local variable's name.
</member>
</members>
- <constants>
- </constants>
</class>
diff --git a/modules/visual_script/doc_classes/VisualScriptMathConstant.xml b/modules/visual_script/doc_classes/VisualScriptMathConstant.xml
index 18a1f030bc..01c36e763b 100644
--- a/modules/visual_script/doc_classes/VisualScriptMathConstant.xml
+++ b/modules/visual_script/doc_classes/VisualScriptMathConstant.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualScriptMathConstant" inherits="VisualScriptNode" version="4.0">
+<class name="VisualScriptMathConstant" inherits="VisualScriptNode" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
Commonly used mathematical constants.
</brief_description>
@@ -12,8 +12,6 @@
</description>
<tutorials>
</tutorials>
- <methods>
- </methods>
<members>
<member name="constant" type="int" setter="set_math_constant" getter="get_math_constant" enum="VisualScriptMathConstant.MathConstant" default="0">
The math constant.
diff --git a/modules/visual_script/doc_classes/VisualScriptNode.xml b/modules/visual_script/doc_classes/VisualScriptNode.xml
index 82a023f3e4..2eb99dc25f 100644
--- a/modules/visual_script/doc_classes/VisualScriptNode.xml
+++ b/modules/visual_script/doc_classes/VisualScriptNode.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualScriptNode" inherits="Resource" version="4.0">
+<class name="VisualScriptNode" inherits="Resource" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
A node which is part of a [VisualScript].
</brief_description>
@@ -10,35 +10,28 @@
</tutorials>
<methods>
<method name="get_default_input_value" qualifiers="const">
- <return type="Variant">
- </return>
- <argument index="0" name="port_idx" type="int">
- </argument>
+ <return type="Variant" />
+ <argument index="0" name="port_idx" type="int" />
<description>
Returns the default value of a given port. The default value is used when nothing is connected to the port.
</description>
</method>
<method name="get_visual_script" qualifiers="const">
- <return type="VisualScript">
- </return>
+ <return type="VisualScript" />
<description>
Returns the [VisualScript] instance the node is bound to.
</description>
</method>
<method name="ports_changed_notify">
- <return type="void">
- </return>
+ <return type="void" />
<description>
Notify that the node's ports have changed. Usually used in conjunction with [VisualScriptCustomNode] .
</description>
</method>
<method name="set_default_input_value">
- <return type="void">
- </return>
- <argument index="0" name="port_idx" type="int">
- </argument>
- <argument index="1" name="value" type="Variant">
- </argument>
+ <return type="void" />
+ <argument index="0" name="port_idx" type="int" />
+ <argument index="1" name="value" type="Variant" />
<description>
Change the default value of a given port.
</description>
@@ -51,6 +44,4 @@
</description>
</signal>
</signals>
- <constants>
- </constants>
</class>
diff --git a/modules/visual_script/doc_classes/VisualScriptOperator.xml b/modules/visual_script/doc_classes/VisualScriptOperator.xml
index c8ce0f2732..47ca6ddb90 100644
--- a/modules/visual_script/doc_classes/VisualScriptOperator.xml
+++ b/modules/visual_script/doc_classes/VisualScriptOperator.xml
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualScriptOperator" inherits="VisualScriptNode" version="4.0">
+<class name="VisualScriptOperator" inherits="VisualScriptNode" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
+ A Visual Script node that performs an operation on two values.
</brief_description>
<description>
[b]Input Ports:[/b]
@@ -11,14 +12,12 @@
</description>
<tutorials>
</tutorials>
- <methods>
- </methods>
<members>
<member name="operator" type="int" setter="set_operator" getter="get_operator" enum="Variant.Operator" default="6">
+ The operation to be performed. See [enum Variant.Operator] for available options.
</member>
<member name="type" type="int" setter="set_typed" getter="get_typed" enum="Variant.Type" default="0">
+ The type of the values for this operation. See [enum Variant.Type] for available options.
</member>
</members>
- <constants>
- </constants>
</class>
diff --git a/modules/visual_script/doc_classes/VisualScriptPreload.xml b/modules/visual_script/doc_classes/VisualScriptPreload.xml
index e11af6c805..146d6cd9c3 100644
--- a/modules/visual_script/doc_classes/VisualScriptPreload.xml
+++ b/modules/visual_script/doc_classes/VisualScriptPreload.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualScriptPreload" inherits="VisualScriptNode" version="4.0">
+<class name="VisualScriptPreload" inherits="VisualScriptNode" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
Creates a new [Resource] or loads one from the filesystem.
</brief_description>
@@ -12,13 +12,9 @@
</description>
<tutorials>
</tutorials>
- <methods>
- </methods>
<members>
<member name="resource" type="Resource" setter="set_preload" getter="get_preload">
The [Resource] to load.
</member>
</members>
- <constants>
- </constants>
</class>
diff --git a/modules/visual_script/doc_classes/VisualScriptPropertyGet.xml b/modules/visual_script/doc_classes/VisualScriptPropertyGet.xml
index 1c22070ab1..77cd6393a9 100644
--- a/modules/visual_script/doc_classes/VisualScriptPropertyGet.xml
+++ b/modules/visual_script/doc_classes/VisualScriptPropertyGet.xml
@@ -1,37 +1,48 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualScriptPropertyGet" inherits="VisualScriptNode" version="4.0">
+<class name="VisualScriptPropertyGet" inherits="VisualScriptNode" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
+ A Visual Script node returning a value of a property from an [Object].
</brief_description>
<description>
+ [VisualScriptPropertyGet] can return a value of any property from the current object or other objects.
</description>
<tutorials>
</tutorials>
- <methods>
- </methods>
<members>
<member name="base_script" type="String" setter="set_base_script" getter="get_base_script">
+ The script to be used when [member set_mode] is set to [constant CALL_MODE_INSTANCE].
</member>
- <member name="base_type" type="StringName" setter="set_base_type" getter="get_base_type" default="@&quot;Object&quot;">
+ <member name="base_type" type="StringName" setter="set_base_type" getter="get_base_type" default="&amp;&quot;Object&quot;">
+ The base type to be used when [member set_mode] is set to [constant CALL_MODE_INSTANCE].
</member>
<member name="basic_type" type="int" setter="set_basic_type" getter="get_basic_type" enum="Variant.Type">
+ The type to be used when [member set_mode] is set to [constant CALL_MODE_BASIC_TYPE].
</member>
<member name="index" type="StringName" setter="set_index" getter="get_index">
+ The indexed name of the property to retrieve. See [method Object.get_indexed] for details.
</member>
<member name="node_path" type="NodePath" setter="set_base_path" getter="get_base_path">
+ The node path to use when [member set_mode] is set to [constant CALL_MODE_NODE_PATH].
</member>
- <member name="property" type="StringName" setter="set_property" getter="get_property" default="@&quot;&quot;">
+ <member name="property" type="StringName" setter="set_property" getter="get_property" default="&amp;&quot;&quot;">
+ The name of the property to retrieve. Changing this will clear [member index].
</member>
<member name="set_mode" type="int" setter="set_call_mode" getter="get_call_mode" enum="VisualScriptPropertyGet.CallMode" default="0">
+ [code]set_mode[/code] determines the target object from which the property will be retrieved. See [enum CallMode] for options.
</member>
</members>
<constants>
<constant name="CALL_MODE_SELF" value="0" enum="CallMode">
+ The property will be retrieved from this [Object].
</constant>
<constant name="CALL_MODE_NODE_PATH" value="1" enum="CallMode">
+ The property will be retrieved from the given [Node] in the scene tree.
</constant>
<constant name="CALL_MODE_INSTANCE" value="2" enum="CallMode">
+ The property will be retrieved from an instanced node with the given type and script.
</constant>
<constant name="CALL_MODE_BASIC_TYPE" value="3" enum="CallMode">
+ The property will be retrieved from a GDScript basic type (e.g. [Vector2]).
</constant>
</constants>
</class>
diff --git a/modules/visual_script/doc_classes/VisualScriptPropertySet.xml b/modules/visual_script/doc_classes/VisualScriptPropertySet.xml
index 629576e261..6cffa328c7 100644
--- a/modules/visual_script/doc_classes/VisualScriptPropertySet.xml
+++ b/modules/visual_script/doc_classes/VisualScriptPropertySet.xml
@@ -1,61 +1,84 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualScriptPropertySet" inherits="VisualScriptNode" version="4.0">
+<class name="VisualScriptPropertySet" inherits="VisualScriptNode" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
+ A Visual Script node that sets a property of an [Object].
</brief_description>
<description>
+ [VisualScriptPropertySet] can set the value of any property from the current object or other objects.
</description>
<tutorials>
</tutorials>
- <methods>
- </methods>
<members>
<member name="assign_op" type="int" setter="set_assign_op" getter="get_assign_op" enum="VisualScriptPropertySet.AssignOp" default="0">
+ The additional operation to perform when assigning. See [enum AssignOp] for options.
</member>
<member name="base_script" type="String" setter="set_base_script" getter="get_base_script">
+ The script to be used when [member set_mode] is set to [constant CALL_MODE_INSTANCE].
</member>
- <member name="base_type" type="StringName" setter="set_base_type" getter="get_base_type" default="@&quot;Object&quot;">
+ <member name="base_type" type="StringName" setter="set_base_type" getter="get_base_type" default="&amp;&quot;Object&quot;">
+ The base type to be used when [member set_mode] is set to [constant CALL_MODE_INSTANCE].
</member>
<member name="basic_type" type="int" setter="set_basic_type" getter="get_basic_type" enum="Variant.Type">
+ The type to be used when [member set_mode] is set to [constant CALL_MODE_BASIC_TYPE].
</member>
<member name="index" type="StringName" setter="set_index" getter="get_index">
+ The indexed name of the property to set. See [method Object.set_indexed] for details.
</member>
<member name="node_path" type="NodePath" setter="set_base_path" getter="get_base_path">
+ The node path to use when [member set_mode] is set to [constant CALL_MODE_NODE_PATH].
</member>
- <member name="property" type="StringName" setter="set_property" getter="get_property" default="@&quot;&quot;">
+ <member name="property" type="StringName" setter="set_property" getter="get_property" default="&amp;&quot;&quot;">
+ The name of the property to set. Changing this will clear [member index].
</member>
<member name="set_mode" type="int" setter="set_call_mode" getter="get_call_mode" enum="VisualScriptPropertySet.CallMode" default="0">
+ [code]set_mode[/code] determines the target object on which the property will be set. See [enum CallMode] for options.
</member>
</members>
<constants>
<constant name="CALL_MODE_SELF" value="0" enum="CallMode">
+ The property will be set on this [Object].
</constant>
<constant name="CALL_MODE_NODE_PATH" value="1" enum="CallMode">
+ The property will be set on the given [Node] in the scene tree.
</constant>
<constant name="CALL_MODE_INSTANCE" value="2" enum="CallMode">
+ The property will be set on an instanced node with the given type and script.
</constant>
<constant name="CALL_MODE_BASIC_TYPE" value="3" enum="CallMode">
+ The property will be set on a GDScript basic type (e.g. [Vector2]).
</constant>
<constant name="ASSIGN_OP_NONE" value="0" enum="AssignOp">
+ The property will be assigned regularly.
</constant>
<constant name="ASSIGN_OP_ADD" value="1" enum="AssignOp">
+ The value will be added to the property. Equivalent of doing [code]+=[/code].
</constant>
<constant name="ASSIGN_OP_SUB" value="2" enum="AssignOp">
+ The value will be subtracted from the property. Equivalent of doing [code]-=[/code].
</constant>
<constant name="ASSIGN_OP_MUL" value="3" enum="AssignOp">
+ The property will be multiplied by the value. Equivalent of doing [code]*=[/code].
</constant>
<constant name="ASSIGN_OP_DIV" value="4" enum="AssignOp">
+ The property will be divided by the value. Equivalent of doing [code]/=[/code].
</constant>
<constant name="ASSIGN_OP_MOD" value="5" enum="AssignOp">
+ A modulo operation will be performed on the property and the value. Equivalent of doing [code]%=[/code].
</constant>
<constant name="ASSIGN_OP_SHIFT_LEFT" value="6" enum="AssignOp">
+ The property will be binarly shifted to the left by the given value. Equivalent of doing [code]&lt;&lt;[/code].
</constant>
<constant name="ASSIGN_OP_SHIFT_RIGHT" value="7" enum="AssignOp">
+ The property will be binarly shifted to the right by the given value. Equivalent of doing [code]&gt;&gt;[/code].
</constant>
<constant name="ASSIGN_OP_BIT_AND" value="8" enum="AssignOp">
+ A binary [code]AND[/code] operation will be performed on the property. Equivalent of doing [code]&amp;=[/code].
</constant>
<constant name="ASSIGN_OP_BIT_OR" value="9" enum="AssignOp">
+ A binary [code]OR[/code] operation will be performed on the property. Equivalent of doing [code]|=[/code].
</constant>
<constant name="ASSIGN_OP_BIT_XOR" value="10" enum="AssignOp">
+ A binary [code]XOR[/code] operation will be performed on the property. Equivalent of doing [code]^=[/code].
</constant>
</constants>
</class>
diff --git a/modules/visual_script/doc_classes/VisualScriptResourcePath.xml b/modules/visual_script/doc_classes/VisualScriptResourcePath.xml
index ea891be05f..6ca8260ade 100644
--- a/modules/visual_script/doc_classes/VisualScriptResourcePath.xml
+++ b/modules/visual_script/doc_classes/VisualScriptResourcePath.xml
@@ -1,17 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualScriptResourcePath" inherits="VisualScriptNode" version="4.0">
+<class name="VisualScriptResourcePath" inherits="VisualScriptNode" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
</brief_description>
<description>
</description>
<tutorials>
</tutorials>
- <methods>
- </methods>
<members>
<member name="path" type="String" setter="set_resource_path" getter="get_resource_path" default="&quot;&quot;">
</member>
</members>
- <constants>
- </constants>
</class>
diff --git a/modules/visual_script/doc_classes/VisualScriptReturn.xml b/modules/visual_script/doc_classes/VisualScriptReturn.xml
index 502628925d..1d59392782 100644
--- a/modules/visual_script/doc_classes/VisualScriptReturn.xml
+++ b/modules/visual_script/doc_classes/VisualScriptReturn.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualScriptReturn" inherits="VisualScriptNode" version="4.0">
+<class name="VisualScriptReturn" inherits="VisualScriptNode" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
Exits a function and returns an optional value.
</brief_description>
@@ -13,8 +13,6 @@
</description>
<tutorials>
</tutorials>
- <methods>
- </methods>
<members>
<member name="return_enabled" type="bool" setter="set_enable_return_value" getter="is_return_value_enabled" default="false">
If [code]true[/code], the [code]return[/code] input port is available.
@@ -23,6 +21,4 @@
The return value's data type.
</member>
</members>
- <constants>
- </constants>
</class>
diff --git a/modules/visual_script/doc_classes/VisualScriptSceneNode.xml b/modules/visual_script/doc_classes/VisualScriptSceneNode.xml
index ffe187a00e..a769d11d94 100644
--- a/modules/visual_script/doc_classes/VisualScriptSceneNode.xml
+++ b/modules/visual_script/doc_classes/VisualScriptSceneNode.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualScriptSceneNode" inherits="VisualScriptNode" version="4.0">
+<class name="VisualScriptSceneNode" inherits="VisualScriptNode" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
Node reference.
</brief_description>
@@ -12,13 +12,9 @@
</description>
<tutorials>
</tutorials>
- <methods>
- </methods>
<members>
<member name="node_path" type="NodePath" setter="set_node_path" getter="get_node_path" default="NodePath(&quot;.&quot;)">
The node's path in the scene tree.
</member>
</members>
- <constants>
- </constants>
</class>
diff --git a/modules/visual_script/doc_classes/VisualScriptSceneTree.xml b/modules/visual_script/doc_classes/VisualScriptSceneTree.xml
index 191d4b6977..84ab90892f 100644
--- a/modules/visual_script/doc_classes/VisualScriptSceneTree.xml
+++ b/modules/visual_script/doc_classes/VisualScriptSceneTree.xml
@@ -1,13 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualScriptSceneTree" inherits="VisualScriptNode" version="4.0">
+<class name="VisualScriptSceneTree" inherits="VisualScriptNode" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
+ A Visual Script node for accessing [SceneTree] methods.
</brief_description>
<description>
+ A Visual Script node for accessing [SceneTree] methods.
</description>
<tutorials>
</tutorials>
- <methods>
- </methods>
- <constants>
- </constants>
</class>
diff --git a/modules/visual_script/doc_classes/VisualScriptSelect.xml b/modules/visual_script/doc_classes/VisualScriptSelect.xml
index 1dbc066e32..1aa916f779 100644
--- a/modules/visual_script/doc_classes/VisualScriptSelect.xml
+++ b/modules/visual_script/doc_classes/VisualScriptSelect.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualScriptSelect" inherits="VisualScriptNode" version="4.0">
+<class name="VisualScriptSelect" inherits="VisualScriptNode" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
Chooses between two input values.
</brief_description>
@@ -14,13 +14,9 @@
</description>
<tutorials>
</tutorials>
- <methods>
- </methods>
<members>
<member name="type" type="int" setter="set_typed" getter="get_typed" enum="Variant.Type" default="0">
The input variables' type.
</member>
</members>
- <constants>
- </constants>
</class>
diff --git a/modules/visual_script/doc_classes/VisualScriptSelf.xml b/modules/visual_script/doc_classes/VisualScriptSelf.xml
index bb24f158c1..8cc59dbccd 100644
--- a/modules/visual_script/doc_classes/VisualScriptSelf.xml
+++ b/modules/visual_script/doc_classes/VisualScriptSelf.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualScriptSelf" inherits="VisualScriptNode" version="4.0">
+<class name="VisualScriptSelf" inherits="VisualScriptNode" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
Outputs a reference to the current instance.
</brief_description>
@@ -12,8 +12,4 @@
</description>
<tutorials>
</tutorials>
- <methods>
- </methods>
- <constants>
- </constants>
</class>
diff --git a/modules/visual_script/doc_classes/VisualScriptSequence.xml b/modules/visual_script/doc_classes/VisualScriptSequence.xml
index 664722574d..9adbc30e0d 100644
--- a/modules/visual_script/doc_classes/VisualScriptSequence.xml
+++ b/modules/visual_script/doc_classes/VisualScriptSequence.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualScriptSequence" inherits="VisualScriptNode" version="4.0">
+<class name="VisualScriptSequence" inherits="VisualScriptNode" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
Executes a series of Sequence ports.
</brief_description>
@@ -14,13 +14,9 @@
</description>
<tutorials>
</tutorials>
- <methods>
- </methods>
<members>
<member name="steps" type="int" setter="set_steps" getter="get_steps" default="1">
The number of steps in the sequence.
</member>
</members>
- <constants>
- </constants>
</class>
diff --git a/modules/visual_script/doc_classes/VisualScriptSubCall.xml b/modules/visual_script/doc_classes/VisualScriptSubCall.xml
index cb3b04b583..535e89fc82 100644
--- a/modules/visual_script/doc_classes/VisualScriptSubCall.xml
+++ b/modules/visual_script/doc_classes/VisualScriptSubCall.xml
@@ -1,21 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualScriptSubCall" inherits="VisualScriptNode" version="4.0">
+<class name="VisualScriptSubCall" inherits="VisualScriptNode" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
+ Calls a method called [code]_subcall[/code] in this object.
</brief_description>
<description>
+ [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.
</description>
<tutorials>
</tutorials>
- <methods>
- <method name="_subcall" qualifiers="virtual">
- <return type="Variant">
- </return>
- <argument index="0" name="arguments" type="Variant">
- </argument>
- <description>
- </description>
- </method>
- </methods>
- <constants>
- </constants>
</class>
diff --git a/modules/visual_script/doc_classes/VisualScriptSwitch.xml b/modules/visual_script/doc_classes/VisualScriptSwitch.xml
index 74504948f0..7befe89f50 100644
--- a/modules/visual_script/doc_classes/VisualScriptSwitch.xml
+++ b/modules/visual_script/doc_classes/VisualScriptSwitch.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualScriptSwitch" inherits="VisualScriptNode" version="4.0">
+<class name="VisualScriptSwitch" inherits="VisualScriptNode" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
Branches program flow based on a given input's value.
</brief_description>
@@ -17,8 +17,4 @@
</description>
<tutorials>
</tutorials>
- <methods>
- </methods>
- <constants>
- </constants>
</class>
diff --git a/modules/visual_script/doc_classes/VisualScriptTypeCast.xml b/modules/visual_script/doc_classes/VisualScriptTypeCast.xml
index 80a8d31041..ec84a75601 100644
--- a/modules/visual_script/doc_classes/VisualScriptTypeCast.xml
+++ b/modules/visual_script/doc_classes/VisualScriptTypeCast.xml
@@ -1,19 +1,19 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualScriptTypeCast" inherits="VisualScriptNode" version="4.0">
+<class name="VisualScriptTypeCast" inherits="VisualScriptNode" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
+ A Visual Script node that casts the given value to another type.
</brief_description>
<description>
+ [VisualScriptTypeCast] will perform a type conversion to an [Object]-derived type.
</description>
<tutorials>
</tutorials>
- <methods>
- </methods>
<members>
<member name="base_script" type="String" setter="set_base_script" getter="get_base_script" default="&quot;&quot;">
+ The target script class to be converted to. If none, only the [member base_type] will be used.
</member>
- <member name="base_type" type="StringName" setter="set_base_type" getter="get_base_type" default="@&quot;Object&quot;">
+ <member name="base_type" type="StringName" setter="set_base_type" getter="get_base_type" default="&amp;&quot;Object&quot;">
+ The target type to be converted to.
</member>
</members>
- <constants>
- </constants>
</class>
diff --git a/modules/visual_script/doc_classes/VisualScriptVariableGet.xml b/modules/visual_script/doc_classes/VisualScriptVariableGet.xml
index d182e14e4d..8d99b4b9d0 100644
--- a/modules/visual_script/doc_classes/VisualScriptVariableGet.xml
+++ b/modules/visual_script/doc_classes/VisualScriptVariableGet.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualScriptVariableGet" inherits="VisualScriptNode" version="4.0">
+<class name="VisualScriptVariableGet" inherits="VisualScriptNode" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
Gets a variable's value.
</brief_description>
@@ -12,13 +12,9 @@
</description>
<tutorials>
</tutorials>
- <methods>
- </methods>
<members>
- <member name="var_name" type="StringName" setter="set_variable" getter="get_variable" default="@&quot;&quot;">
+ <member name="var_name" type="StringName" setter="set_variable" getter="get_variable" default="&amp;&quot;&quot;">
The variable's name.
</member>
</members>
- <constants>
- </constants>
</class>
diff --git a/modules/visual_script/doc_classes/VisualScriptVariableSet.xml b/modules/visual_script/doc_classes/VisualScriptVariableSet.xml
index 3bd392dd85..4f568cc0f6 100644
--- a/modules/visual_script/doc_classes/VisualScriptVariableSet.xml
+++ b/modules/visual_script/doc_classes/VisualScriptVariableSet.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualScriptVariableSet" inherits="VisualScriptNode" version="4.0">
+<class name="VisualScriptVariableSet" inherits="VisualScriptNode" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
Changes a variable's value.
</brief_description>
@@ -13,13 +13,9 @@
</description>
<tutorials>
</tutorials>
- <methods>
- </methods>
<members>
- <member name="var_name" type="StringName" setter="set_variable" getter="get_variable" default="@&quot;&quot;">
+ <member name="var_name" type="StringName" setter="set_variable" getter="get_variable" default="&amp;&quot;&quot;">
The variable's name.
</member>
</members>
- <constants>
- </constants>
</class>
diff --git a/modules/visual_script/doc_classes/VisualScriptWhile.xml b/modules/visual_script/doc_classes/VisualScriptWhile.xml
index f187957ad2..4e7cccef17 100644
--- a/modules/visual_script/doc_classes/VisualScriptWhile.xml
+++ b/modules/visual_script/doc_classes/VisualScriptWhile.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualScriptWhile" inherits="VisualScriptNode" version="4.0">
+<class name="VisualScriptWhile" inherits="VisualScriptNode" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
Conditional loop.
</brief_description>
@@ -14,8 +14,4 @@
</description>
<tutorials>
</tutorials>
- <methods>
- </methods>
- <constants>
- </constants>
</class>
diff --git a/modules/visual_script/doc_classes/VisualScriptYield.xml b/modules/visual_script/doc_classes/VisualScriptYield.xml
index 0a8d529a48..ec757a3ac4 100644
--- a/modules/visual_script/doc_classes/VisualScriptYield.xml
+++ b/modules/visual_script/doc_classes/VisualScriptYield.xml
@@ -1,25 +1,30 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualScriptYield" inherits="VisualScriptNode" version="4.0">
+<class name="VisualScriptYield" inherits="VisualScriptNode" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
+ A Visual Script node used to pause a function execution.
</brief_description>
<description>
+ [VisualScriptYield] will pause the function call and return [VisualScriptFunctionState], which can be used to resume the function.
</description>
<tutorials>
</tutorials>
- <methods>
- </methods>
<members>
<member name="mode" type="int" setter="set_yield_mode" getter="get_yield_mode" enum="VisualScriptYield.YieldMode" default="1">
+ The mode to use for yielding. See [enum YieldMode] for available options.
</member>
<member name="wait_time" type="float" setter="set_wait_time" getter="get_wait_time">
+ The time to wait when [member mode] is set to [constant YIELD_WAIT].
</member>
</members>
<constants>
<constant name="YIELD_FRAME" value="1" enum="YieldMode">
+ Yields during an idle frame.
</constant>
<constant name="YIELD_PHYSICS_FRAME" value="2" enum="YieldMode">
+ Yields during a physics frame.
</constant>
<constant name="YIELD_WAIT" value="3" enum="YieldMode">
+ Yields a function and waits the given time.
</constant>
</constants>
</class>
diff --git a/modules/visual_script/doc_classes/VisualScriptYieldSignal.xml b/modules/visual_script/doc_classes/VisualScriptYieldSignal.xml
index 483cdfeaf8..c3f4bc49c5 100644
--- a/modules/visual_script/doc_classes/VisualScriptYieldSignal.xml
+++ b/modules/visual_script/doc_classes/VisualScriptYieldSignal.xml
@@ -1,29 +1,36 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualScriptYieldSignal" inherits="VisualScriptNode" version="4.0">
+<class name="VisualScriptYieldSignal" inherits="VisualScriptNode" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
+ A Visual Script node yielding for a signal.
</brief_description>
<description>
+ [VisualScriptYieldSignal] will pause the function execution until the provided signal is emitted.
</description>
<tutorials>
</tutorials>
- <methods>
- </methods>
<members>
- <member name="base_type" type="StringName" setter="set_base_type" getter="get_base_type" default="@&quot;Object&quot;">
+ <member name="base_type" type="StringName" setter="set_base_type" getter="get_base_type" default="&amp;&quot;Object&quot;">
+ The base type to be used when [member call_mode] is set to [constant CALL_MODE_INSTANCE].
</member>
<member name="call_mode" type="int" setter="set_call_mode" getter="get_call_mode" enum="VisualScriptYieldSignal.CallMode" default="0">
+ [code]call_mode[/code] determines the target object to wait for the signal emission. See [enum CallMode] for options.
</member>
<member name="node_path" type="NodePath" setter="set_base_path" getter="get_base_path">
+ The node path to use when [member call_mode] is set to [constant CALL_MODE_NODE_PATH].
</member>
- <member name="signal" type="StringName" setter="set_signal" getter="get_signal" default="@&quot;&quot;">
+ <member name="signal" type="StringName" setter="set_signal" getter="get_signal" default="&amp;&quot;&quot;">
+ The signal name to be waited for.
</member>
</members>
<constants>
<constant name="CALL_MODE_SELF" value="0" enum="CallMode">
+ A signal from this [Object] will be used.
</constant>
<constant name="CALL_MODE_NODE_PATH" value="1" enum="CallMode">
+ A signal from the given [Node] in the scene tree will be used.
</constant>
<constant name="CALL_MODE_INSTANCE" value="2" enum="CallMode">
+ A signal from an instanced node with the given type will be used.
</constant>
</constants>
</class>
diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/editor/visual_script_editor.cpp
index 3b2cd50544..ceea0eaf1d 100644
--- a/modules/visual_script/visual_script_editor.cpp
+++ b/modules/visual_script/editor/visual_script_editor.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -30,6 +30,10 @@
#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"
@@ -38,11 +42,8 @@
#include "editor/editor_node.h"
#include "editor/editor_resource_preview.h"
#include "editor/editor_scale.h"
+#include "scene/gui/view_panner.h"
#include "scene/main/window.h"
-#include "visual_script_expression.h"
-#include "visual_script_flow_control.h"
-#include "visual_script_func_nodes.h"
-#include "visual_script_nodes.h"
#ifdef TOOLS_ENABLED
class VisualScriptEditorSignalEdit : public Object {
@@ -62,7 +63,7 @@ protected:
void _sig_changed() {
notify_property_list_changed();
- emit_signal("changed");
+ emit_signal(SNAME("changed"));
}
bool _set(const StringName &p_name, const Variant &p_value) {
@@ -196,10 +197,10 @@ protected:
void _var_changed() {
notify_property_list_changed();
- emit_signal("changed");
+ emit_signal(SNAME("changed"));
}
void _var_value_changed() {
- emit_signal("changed");
+ emit_signal(SNAME("changed"));
}
bool _set(const StringName &p_name, const Variant &p_value) {
@@ -271,7 +272,7 @@ protected:
if (String(p_name) == "export") {
script->set_variable_export(var, p_value);
- EditorNode::get_singleton()->get_inspector()->update_tree();
+ InspectorDock::get_inspector_singleton()->update_tree();
return true;
}
@@ -381,7 +382,7 @@ static Color _color_from_type(Variant::Type p_type, bool dark_theme = true) {
case Variant::PLANE:
color = Color(0.97, 0.44, 0.44);
break;
- case Variant::QUAT:
+ case Variant::QUATERNION:
color = Color(0.93, 0.41, 0.64);
break;
case Variant::AABB:
@@ -390,7 +391,7 @@ static Color _color_from_type(Variant::Type p_type, bool dark_theme = true) {
case Variant::BASIS:
color = Color(0.89, 0.93, 0.41);
break;
- case Variant::TRANSFORM:
+ case Variant::TRANSFORM3D:
color = Color(0.96, 0.66, 0.43);
break;
@@ -487,7 +488,7 @@ static Color _color_from_type(Variant::Type p_type, bool dark_theme = true) {
case Variant::PLANE:
color = Color(0.97, 0.44, 0.44);
break;
- case Variant::QUAT:
+ case Variant::QUATERNION:
color = Color(0.93, 0.41, 0.64);
break;
case Variant::AABB:
@@ -496,7 +497,7 @@ static Color _color_from_type(Variant::Type p_type, bool dark_theme = true) {
case Variant::BASIS:
color = Color(0.7, 0.73, 0.1);
break;
- case Variant::TRANSFORM:
+ case Variant::TRANSFORM3D:
color = Color(0.96, 0.56, 0.28);
break;
@@ -561,18 +562,16 @@ void VisualScriptEditor::_update_graph_connections() {
List<VisualScript::SequenceConnection> sequence_conns;
script->get_sequence_connection_list(&sequence_conns);
- for (List<VisualScript::SequenceConnection>::Element *E = sequence_conns.front(); E; E = E->next()) {
- graph->connect_node(itos(E->get().from_node), E->get().from_output, itos(E->get().to_node), 0);
+ for (const VisualScript::SequenceConnection &E : sequence_conns) {
+ graph->connect_node(itos(E.from_node), E.from_output, itos(E.to_node), 0);
}
List<VisualScript::DataConnection> data_conns;
script->get_data_connection_list(&data_conns);
- for (List<VisualScript::DataConnection>::Element *E = data_conns.front(); E; E = E->next()) {
- VisualScript::DataConnection dc = E->get();
-
- Ref<VisualScriptNode> from_node = script->get_node(E->get().from_node);
- Ref<VisualScriptNode> to_node = script->get_node(E->get().to_node);
+ for (VisualScript::DataConnection &dc : data_conns) {
+ Ref<VisualScriptNode> from_node = script->get_node(dc.from_node);
+ Ref<VisualScriptNode> to_node = script->get_node(dc.to_node);
if (to_node->has_input_sequence_port()) {
dc.to_port++;
@@ -580,7 +579,7 @@ void VisualScriptEditor::_update_graph_connections() {
dc.from_port += from_node->get_output_sequence_port_count();
- graph->connect_node(itos(E->get().from_node), dc.from_port, itos(E->get().to_node), dc.to_port);
+ graph->connect_node(itos(dc.from_node), dc.from_port, itos(dc.to_node), dc.to_port);
}
}
@@ -611,69 +610,79 @@ void VisualScriptEditor::_update_graph(int p_only_id) {
select_func_text->hide();
Ref<Texture2D> type_icons[Variant::VARIANT_MAX] = {
- Control::get_theme_icon("Variant", "EditorIcons"),
- Control::get_theme_icon("bool", "EditorIcons"),
- Control::get_theme_icon("int", "EditorIcons"),
- Control::get_theme_icon("float", "EditorIcons"),
- Control::get_theme_icon("String", "EditorIcons"),
- Control::get_theme_icon("Vector2", "EditorIcons"),
- Control::get_theme_icon("Vector2i", "EditorIcons"),
- Control::get_theme_icon("Rect2", "EditorIcons"),
- Control::get_theme_icon("Rect2i", "EditorIcons"),
- Control::get_theme_icon("Vector3", "EditorIcons"),
- Control::get_theme_icon("Vector3i", "EditorIcons"),
- Control::get_theme_icon("Transform2D", "EditorIcons"),
- Control::get_theme_icon("Plane", "EditorIcons"),
- Control::get_theme_icon("Quat", "EditorIcons"),
- Control::get_theme_icon("AABB", "EditorIcons"),
- Control::get_theme_icon("Basis", "EditorIcons"),
- Control::get_theme_icon("Transform", "EditorIcons"),
- Control::get_theme_icon("Color", "EditorIcons"),
- Control::get_theme_icon("NodePath", "EditorIcons"),
- Control::get_theme_icon("RID", "EditorIcons"),
- Control::get_theme_icon("MiniObject", "EditorIcons"),
- Control::get_theme_icon("Callable", "EditorIcons"),
- Control::get_theme_icon("Signal", "EditorIcons"),
- Control::get_theme_icon("Dictionary", "EditorIcons"),
- Control::get_theme_icon("Array", "EditorIcons"),
- Control::get_theme_icon("PackedByteArray", "EditorIcons"),
- Control::get_theme_icon("PackedInt32Array", "EditorIcons"),
- Control::get_theme_icon("PackedFloat32Array", "EditorIcons"),
- Control::get_theme_icon("PackedStringArray", "EditorIcons"),
- Control::get_theme_icon("PackedVector2Array", "EditorIcons"),
- Control::get_theme_icon("PackedVector3Array", "EditorIcons"),
- Control::get_theme_icon("PackedColorArray", "EditorIcons")
+ 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"))
};
- Ref<Texture2D> seq_port = Control::get_theme_icon("VisualShaderPort", "EditorIcons");
+ // Visual script specific theme for MSDF font.
+ Ref<Theme> vstheme;
+ vstheme.instantiate();
+ Ref<Font> 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<Texture2D> seq_port = Control::get_theme_icon(SNAME("VisualShaderPort"), SNAME("EditorIcons"));
List<int> node_ids;
script->get_node_list(&node_ids);
List<int> ids;
script->get_node_list(&ids);
- StringName editor_icons = "EditorIcons";
- for (List<int>::Element *E = ids.front(); E; E = E->next()) {
- if (p_only_id >= 0 && p_only_id != E->get()) {
+ for (int &E : ids) {
+ if (p_only_id >= 0 && p_only_id != E) {
continue;
}
- Ref<VisualScriptNode> node = script->get_node(E->get());
- Vector2 pos = script->get_node_position(E->get());
+ Ref<VisualScriptNode> 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->get()) {
+ 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->get()));
- gnode->connect("dragged", callable_mp(this, &VisualScriptEditor::_node_moved), varray(E->get()));
- gnode->connect("close_request", callable_mp(this, &VisualScriptEditor::_remove_node), varray(E->get()), CONNECT_DEFERRED);
+ gnode->set_name(itos(E));
+ gnode->connect("dragged", callable_mp(this, &VisualScriptEditor::_node_moved), varray(E));
+ gnode->connect("close_request", callable_mp(this, &VisualScriptEditor::_remove_node), varray(E), CONNECT_DEFERRED);
{
Ref<VisualScriptFunction> v = node;
@@ -693,7 +702,7 @@ void VisualScriptEditor::_update_graph(int p_only_id) {
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), varray(E->get()), CONNECT_DEFERRED);
+ btn->connect("pressed", callable_mp(this, &VisualScriptEditor::_add_input_port), varray(E), CONNECT_DEFERRED);
}
if (nd_list->is_output_port_editable()) {
if (nd_list->is_input_port_editable()) {
@@ -703,17 +712,17 @@ void VisualScriptEditor::_update_graph(int p_only_id) {
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), varray(E->get()), CONNECT_DEFERRED);
+ btn->connect("pressed", callable_mp(this, &VisualScriptEditor::_add_output_port), varray(E), CONNECT_DEFERRED);
}
gnode->add_child(hbnc);
} else if (Object::cast_to<VisualScriptExpression>(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(true);
- line_edit->add_theme_font_override("font", get_theme_font("source", "EditorFonts"));
+ 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), varray(E->get()));
+ line_edit->connect("text_changed", callable_mp(this, &VisualScriptEditor::_expression_text_changed), varray(E));
} else {
String text = node->get_text();
if (!text.is_empty()) {
@@ -729,38 +738,26 @@ void VisualScriptEditor::_update_graph(int p_only_id) {
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), varray(E->get()));
+ gnode->connect("resize_request", callable_mp(this, &VisualScriptEditor::_comment_node_resized), varray(E));
}
if (node_styles.has(node->get_category())) {
Ref<StyleBoxFlat> sbf = node_styles[node->get_category()];
if (gnode->is_comment()) {
- sbf = EditorNode::get_singleton()->get_theme_base()->get_theme()->get_stylebox("comment", "GraphNode");
+ 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;
- c.a = 1;
- if (EditorSettings::get_singleton()->get("interface/theme/use_graph_node_headers")) {
- Color mono_color;
- if (((c.r + c.g + c.b) / 3) < 0.7) {
- mono_color = Color(1.0, 1.0, 1.0);
- ic = Color(0.0, 0.0, 0.0, 0.7);
- } else {
- mono_color = Color(0.0, 0.0, 0.0);
- ic = Color(1.0, 1.0, 1.0, 0.7);
- }
- mono_color.a = 0.85;
- c = mono_color;
- }
gnode->add_theme_color_override("title_color", c);
- c.a = 0.7;
+ 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("mono_color", "Editor");
+ const Color mono_color = get_theme_color(SNAME("mono_color"), SNAME("Editor"));
int slot_idx = 0;
@@ -790,7 +787,7 @@ void VisualScriptEditor::_update_graph(int p_only_id) {
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_align(Label::ALIGN_RIGHT);
+ 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++;
@@ -843,9 +840,9 @@ void VisualScriptEditor::_update_graph(int p_only_id) {
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(true);
- name_box->connect("resized", callable_mp(this, &VisualScriptEditor::_update_node_size), varray(E->get()));
- name_box->connect("focus_exited", callable_mp(this, &VisualScriptEditor::_port_name_focus_out), varray(name_box, E->get(), i, true));
+ name_box->set_expand_to_text_length_enabled(true);
+ name_box->connect("resized", callable_mp(this, &VisualScriptEditor::_update_node_size), varray(E));
+ name_box->connect("focus_exited", callable_mp(this, &VisualScriptEditor::_port_name_focus_out), varray(name_box, E, i, true));
} else {
hbc->add_child(memnew(Label(left_name)));
}
@@ -858,18 +855,18 @@ void VisualScriptEditor::_update_graph(int p_only_id) {
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), varray(E->get(), i, true), CONNECT_DEFERRED);
+ opbtn->connect("item_selected", callable_mp(this, &VisualScriptEditor::_change_port_type), varray(E, i, true), CONNECT_DEFERRED);
}
Button *rmbtn = memnew(Button);
- rmbtn->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon("Remove", "EditorIcons"));
+ 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), varray(E->get(), i), CONNECT_DEFERRED);
+ rmbtn->connect("pressed", callable_mp(this, &VisualScriptEditor::_remove_input_port), varray(E, i), CONNECT_DEFERRED);
} else {
hbc->add_child(memnew(Label(left_name)));
}
- if (left_type != Variant::NIL && !script->is_input_value_port_connected(E->get(), i)) {
+ 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);
@@ -892,11 +889,53 @@ void VisualScriptEditor::_update_graph(int p_only_id) {
EditorResourcePreview::get_singleton()->queue_edited_resource_preview(res, this, "_button_resource_previewed", arr);
} else if (pi.type == Variant::INT && pi.hint == PROPERTY_HINT_ENUM) {
- button->set_text(pi.hint_string.get_slice(",", value));
+ bool found = false;
+ const Vector<String> options = pi.hint_string.split(",");
+ int64_t current_val = 0;
+ for (const String &option : options) {
+ Vector<String> 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<String> value_texts;
+ const Vector<String> options = pi.hint_string.split(",");
+ uint32_t v = value;
+ for (const String &option : options) {
+ uint32_t current_val;
+ Vector<String> 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), varray(button, E->get(), i));
+ button->connect("pressed", callable_mp(this, &VisualScriptEditor::_default_value_edited), varray(button, E, i));
hbc2->add_child(button);
}
} else {
@@ -911,16 +950,16 @@ void VisualScriptEditor::_update_graph(int p_only_id) {
if (i < mixed_seq_ports) {
Label *text2 = memnew(Label);
text2->set_text(node->get_output_sequence_port_text(i));
- text2->set_align(Label::ALIGN_RIGHT);
+ 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("Remove", "EditorIcons"));
+ 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), varray(E->get(), i), CONNECT_DEFERRED);
+ rmbtn->connect("pressed", callable_mp(this, &VisualScriptEditor::_remove_output_port), varray(E, i), CONNECT_DEFERRED);
if (nd_list->is_output_port_type_editable()) {
OptionButton *opbtn = memnew(OptionButton);
@@ -930,7 +969,7 @@ void VisualScriptEditor::_update_graph(int p_only_id) {
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), varray(E->get(), i, false), CONNECT_DEFERRED);
+ opbtn->connect("item_selected", callable_mp(this, &VisualScriptEditor::_change_port_type), varray(E, i, false), CONNECT_DEFERRED);
}
if (nd_list->is_output_port_name_editable()) {
@@ -938,9 +977,9 @@ void VisualScriptEditor::_update_graph(int p_only_id) {
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(true);
- name_box->connect("resized", callable_mp(this, &VisualScriptEditor::_update_node_size), varray(E->get()));
- name_box->connect("focus_exited", callable_mp(this, &VisualScriptEditor::_port_name_focus_out), varray(name_box, E->get(), i, false));
+ name_box->set_expand_to_text_length_enabled(true);
+ name_box->connect("resized", callable_mp(this, &VisualScriptEditor::_update_node_size), varray(E));
+ name_box->connect("focus_exited", callable_mp(this, &VisualScriptEditor::_port_name_focus_out), varray(name_box, E, i, false));
} else {
hbc->add_child(memnew(Label(right_name)));
}
@@ -962,7 +1001,7 @@ void VisualScriptEditor::_update_graph(int p_only_id) {
gnode->add_child(vbc);
- bool dark_theme = get_theme_constant("dark_theme", "Editor");
+ 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<Texture2D>(), seq_port);
} else {
@@ -971,9 +1010,8 @@ void VisualScriptEditor::_update_graph(int p_only_id) {
slot_idx++;
}
-
graph->add_child(gnode);
-
+ gnode->set_theme(vstheme);
if (gnode->is_comment()) {
graph->move_child(gnode, 0);
}
@@ -984,8 +1022,11 @@ void VisualScriptEditor::_update_graph(int p_only_id) {
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("set_scroll_ofs", script->get_scroll() * EDSCALE);
+ graph->call_deferred(SNAME("set_scroll_ofs"), script->get_scroll() * EDSCALE);
updating_graph = false;
}
@@ -995,7 +1036,7 @@ void VisualScriptEditor::_change_port_type(int p_select, int p_id, int p_port, b
return;
}
- undo_redo->create_action("Change Port Type");
+ 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);
@@ -1009,7 +1050,7 @@ void VisualScriptEditor::_change_port_type(int p_select, int p_id, int p_port, b
void VisualScriptEditor::_update_node_size(int p_id) {
Node *node = graph->get_node(itos(p_id));
if (Object::cast_to<Control>(node)) {
- Object::cast_to<Control>(node)->set_size(Vector2(1, 1)); // Shrink if text is smaller.
+ Object::cast_to<Control>(node)->reset_size(); // Shrink if text is smaller.
}
}
@@ -1027,7 +1068,7 @@ void VisualScriptEditor::_port_name_focus_out(const Node *p_name_box, int p_id,
return;
}
- undo_redo->create_action("Change Port Name");
+ 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);
@@ -1049,20 +1090,20 @@ void VisualScriptEditor::_update_members() {
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("Override", "EditorIcons"), 1, false, TTR("Override an existing built-in function."));
- functions->add_button(0, Control::get_theme_icon("Add", "EditorIcons"), 0, false, TTR("Create a new function."));
- functions->set_custom_color(0, Control::get_theme_color("mono_color", "Editor"));
+ 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<StringName> func_names;
script->get_function_list(&func_names);
func_names.sort_custom<StringName::AlphCompare>();
- for (List<StringName>::Element *E = func_names.front(); E; E = E->next()) {
+ for (const StringName &E : func_names) {
TreeItem *ti = members->create_item(functions);
- ti->set_text(0, E->get());
+ ti->set_text(0, E);
ti->set_selectable(0, true);
- ti->set_metadata(0, E->get());
- ti->add_button(0, Control::get_theme_icon("Edit", "EditorIcons"), 0);
- if (selected == E->get()) {
+ ti->set_metadata(0, E);
+ ti->add_button(0, Control::get_theme_icon(SNAME("Edit"), SNAME("EditorIcons")), 0);
+ if (selected == E) {
ti->select(0);
}
}
@@ -1070,58 +1111,62 @@ void VisualScriptEditor::_update_members() {
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("Add", "EditorIcons"), -1, false, TTR("Create a new variable."));
- variables->set_custom_color(0, Control::get_theme_color("mono_color", "Editor"));
+ 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<Texture2D> type_icons[Variant::VARIANT_MAX] = {
- Control::get_theme_icon("Variant", "EditorIcons"),
- Control::get_theme_icon("bool", "EditorIcons"),
- Control::get_theme_icon("int", "EditorIcons"),
- Control::get_theme_icon("float", "EditorIcons"),
- Control::get_theme_icon("String", "EditorIcons"),
- Control::get_theme_icon("Vector2", "EditorIcons"),
- Control::get_theme_icon("Vector2i", "EditorIcons"),
- Control::get_theme_icon("Rect2", "EditorIcons"),
- Control::get_theme_icon("Rect2i", "EditorIcons"),
- Control::get_theme_icon("Vector3", "EditorIcons"),
- Control::get_theme_icon("Vector3i", "EditorIcons"),
- Control::get_theme_icon("Transform2D", "EditorIcons"),
- Control::get_theme_icon("Plane", "EditorIcons"),
- Control::get_theme_icon("Quat", "EditorIcons"),
- Control::get_theme_icon("AABB", "EditorIcons"),
- Control::get_theme_icon("Basis", "EditorIcons"),
- Control::get_theme_icon("Transform", "EditorIcons"),
- Control::get_theme_icon("Color", "EditorIcons"),
- Control::get_theme_icon("NodePath", "EditorIcons"),
- Control::get_theme_icon("RID", "EditorIcons"),
- Control::get_theme_icon("MiniObject", "EditorIcons"),
- Control::get_theme_icon("Callable", "EditorIcons"),
- Control::get_theme_icon("Signal", "EditorIcons"),
- Control::get_theme_icon("Dictionary", "EditorIcons"),
- Control::get_theme_icon("Array", "EditorIcons"),
- Control::get_theme_icon("PackedByteArray", "EditorIcons"),
- Control::get_theme_icon("PackedInt32Array", "EditorIcons"),
- Control::get_theme_icon("PackedFloat32Array", "EditorIcons"),
- Control::get_theme_icon("PackedStringArray", "EditorIcons"),
- Control::get_theme_icon("PackedVector2Array", "EditorIcons"),
- Control::get_theme_icon("PackedVector3Array", "EditorIcons"),
- Control::get_theme_icon("PackedColorArray", "EditorIcons")
+ 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<StringName> var_names;
script->get_variable_list(&var_names);
- for (List<StringName>::Element *E = var_names.front(); E; E = E->next()) {
+ var_names.sort_custom<StringName::AlphCompare>();
+ for (const StringName &E : var_names) {
TreeItem *ti = members->create_item(variables);
- ti->set_text(0, E->get());
+ ti->set_text(0, E);
- ti->set_suffix(0, "= " + _sanitized_variant_text(E->get()));
- ti->set_icon(0, type_icons[script->get_variable_info(E->get()).type]);
+ 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->get());
- if (selected == E->get()) {
+ ti->set_metadata(0, E);
+ if (selected == E) {
ti->select(0);
}
}
@@ -1129,30 +1174,30 @@ void VisualScriptEditor::_update_members() {
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("Add", "EditorIcons"), -1, false, TTR("Create a new signal."));
- _signals->set_custom_color(0, Control::get_theme_color("mono_color", "Editor"));
+ _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<StringName> signal_names;
script->get_custom_signal_list(&signal_names);
- for (List<StringName>::Element *E = signal_names.front(); E; E = E->next()) {
+ for (const StringName &E : signal_names) {
TreeItem *ti = members->create_item(_signals);
- ti->set_text(0, E->get());
+ ti->set_text(0, E);
ti->set_selectable(0, true);
ti->set_editable(0, true);
- ti->set_metadata(0, E->get());
- if (selected == E->get()) {
+ 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, "EditorIcons")) {
+ 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, "EditorIcons"));
+ base_type_select->set_icon(Control::get_theme_icon(icon_type, SNAME("EditorIcons")));
updating_members = false;
}
@@ -1181,11 +1226,11 @@ void VisualScriptEditor::_member_selected() {
selected = ti->get_metadata(0);
- if (ti->get_parent() == members->get_root()->get_children()) {
+ if (ti->get_parent() == members->get_root()->get_first_child()) {
#ifdef OSX_ENABLED
- bool held_ctrl = Input::get_singleton()->is_key_pressed(KEY_META);
+ bool held_ctrl = Input::get_singleton()->is_key_pressed(Key::META);
#else
- bool held_ctrl = Input::get_singleton()->is_key_pressed(KEY_CONTROL);
+ bool held_ctrl = Input::get_singleton()->is_key_pressed(Key::CTRL);
#endif
if (held_ctrl) {
ERR_FAIL_COND(!script->has_function(selected));
@@ -1227,7 +1272,7 @@ void VisualScriptEditor::_member_edited() {
TreeItem *root = members->get_root();
- if (ti->get_parent() == root->get_children()) {
+ if (ti->get_parent() == root->get_first_child()) {
selected = new_name;
int node_id = script->get_function_node_id(name);
@@ -1246,8 +1291,8 @@ void VisualScriptEditor::_member_edited() {
// Also fix all function calls.
List<int> lst;
script->get_node_list(&lst);
- for (List<int>::Element *F = lst.front(); F; F = F->next()) {
- Ref<VisualScriptFunctionCall> fncall = script->get_node(F->get());
+ for (int &F : lst) {
+ Ref<VisualScriptFunctionCall> fncall = script->get_node(F);
if (!fncall.is_valid()) {
continue;
}
@@ -1268,11 +1313,28 @@ void VisualScriptEditor::_member_edited() {
return; // Or crash because it will become invalid.
}
- if (ti->get_parent() == root->get_children()->get_next()) {
+ 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<int> lst;
+ script->get_node_list(&lst);
+ for (int &P : lst) {
+ Ref<VisualScriptPropertySet> 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<VisualScriptPropertyGet> 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");
@@ -1284,11 +1346,23 @@ void VisualScriptEditor::_member_edited() {
return; // Or crash because it will become invalid.
}
- if (ti->get_parent() == root->get_children()->get_next()->get_next()) {
+ 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<int> lst;
+ script->get_node_list(&lst);
+ for (int &P : lst) {
+ Ref<VisualScriptEmitSignal> 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");
@@ -1310,12 +1384,12 @@ void VisualScriptEditor::_create_function_dialog() {
}
void VisualScriptEditor::_create_function() {
- String name = _validate_name((func_name_box->get_text() == "") ? "new_func" : func_name_box->get_text());
+ String name = _validate_name((func_name_box->get_text().is_empty()) ? "new_func" : func_name_box->get_text());
selected = name;
- Vector2 ofs = _get_available_pos();
+ Vector2 pos = _get_available_pos();
Ref<VisualScriptFunction> func_node;
- func_node.instance();
+ func_node.instantiate();
func_node->set_name(name);
for (int i = 0; i < func_input_vbox->get_child_count(); i++) {
@@ -1334,7 +1408,7 @@ void VisualScriptEditor::_create_function() {
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, ofs);
+ undo_redo->add_do_method(script.ptr(), "add_node", func_node_id, func_node, pos);
undo_redo->add_undo_method(script.ptr(), "remove_node", func_node_id);
undo_redo->add_do_method(this, "_update_members");
undo_redo->add_undo_method(this, "_update_members");
@@ -1348,7 +1422,7 @@ void VisualScriptEditor::_create_function() {
}
void VisualScriptEditor::_add_node_dialog() {
- _generic_search(script->get_instance_base_type(), graph->get_global_position() + Vector2(55, 80), true);
+ _generic_search(graph->get_global_position() + Vector2(55, 80), true);
}
void VisualScriptEditor::_add_func_input() {
@@ -1378,7 +1452,7 @@ void VisualScriptEditor::_add_func_input() {
hbox->add_child(type_box);
Button *delete_button = memnew(Button);
- delete_button->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon("Remove", "EditorIcons"));
+ 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);
@@ -1411,36 +1485,40 @@ void VisualScriptEditor::_deselect_input_names() {
}
}
-void VisualScriptEditor::_member_button(Object *p_item, int p_column, int p_button) {
+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<TreeItem>(p_item);
TreeItem *root = members->get_root();
if (ti->get_parent() == root) {
//main buttons
- if (ti == root->get_children()) {
+ 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(), String(), true);
+ 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 ofs = _get_available_pos();
+ Vector2 pos = _get_available_pos();
Ref<VisualScriptFunction> func_node;
- func_node.instance();
+ 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, ofs);
+ undo_redo->add_do_method(script.ptr(), "add_node", fn_id, func_node, pos);
undo_redo->add_undo_method(script.ptr(), "remove_function", name);
- undo_redo->add_do_method(script.ptr(), "remove_node", fn_id);
+ undo_redo->add_undo_method(script.ptr(), "remove_node", fn_id);
undo_redo->add_do_method(this, "_update_members");
undo_redo->add_undo_method(this, "_update_members");
undo_redo->add_do_method(this, "_update_graph");
@@ -1455,7 +1533,7 @@ void VisualScriptEditor::_member_button(Object *p_item, int p_column, int p_butt
return; // Or crash because it will become invalid.
}
- if (ti == root->get_children()->get_next()) {
+ if (ti == root->get_first_child()->get_next()) {
// Add variable.
String name = _validate_name("new_variable");
selected = name;
@@ -1471,7 +1549,7 @@ void VisualScriptEditor::_member_button(Object *p_item, int p_column, int p_butt
return; // Or crash because it will become invalid.
}
- if (ti == root->get_children()->get_next()->get_next()) {
+ if (ti == root->get_first_child()->get_next()->get_next()) {
// Add variable.
String name = _validate_name("new_signal");
selected = name;
@@ -1486,12 +1564,13 @@ void VisualScriptEditor::_member_button(Object *p_item, int p_column, int p_butt
undo_redo->commit_action();
return; // Or crash because it will become invalid.
}
- } else if (ti->get_parent() == root->get_children()) {
+ } else if (ti->get_parent() == root->get_first_child()) {
selected = ti->get_text(0);
- function_name_edit->set_position(Input::get_singleton()->get_mouse_position() - Vector2(60, -10));
+ 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();
}
}
@@ -1580,25 +1659,23 @@ void VisualScriptEditor::_remove_output_port(int p_id, int p_port) {
List<VisualScript::DataConnection> data_connections;
script->get_data_connection_list(&data_connections);
- HashMap<int, Set<int>> conn_map;
- for (const List<VisualScript::DataConnection>::Element *E = data_connections.front(); E; E = E->next()) {
- if (E->get().from_node == p_id && E->get().from_port == p_port) {
+ HashMap<int, RBSet<int>> 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->get().to_node)) {
- conn_map.set(E->get().to_node, Set<int>());
+ if (!conn_map.has(E.to_node)) {
+ conn_map.insert(E.to_node, RBSet<int>());
}
- conn_map[E->get().to_node].insert(E->get().to_port);
+ 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);
- List<int> keys;
- conn_map.get_key_list(&keys);
- for (const List<int>::Element *E = keys.front(); E; E = E->next()) {
- for (const Set<int>::Element *F = conn_map[E->get()].front(); F; F = F->next()) {
- undo_redo->add_undo_method(script.ptr(), "data_connect", p_id, p_port, E->get(), F->get());
+ for (const KeyValue<int, RBSet<int>> &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);
}
}
@@ -1627,32 +1704,34 @@ void VisualScriptEditor::_expression_text_changed(const String &p_text, int p_id
Node *node = graph->get_node(itos(p_id));
if (Object::cast_to<Control>(node)) {
- Object::cast_to<Control>(node)->set_size(Vector2(1, 1)); // Shrink if text is smaller.
+ Object::cast_to<Control>(node)->reset_size(); // Shrink if text is smaller.
}
updating_graph = false;
}
-Vector2 VisualScriptEditor::_get_available_pos(bool centered, Vector2 ofs) const {
- if (centered) {
- ofs = graph->get_scroll_ofs() + graph->get_size() * 0.5;
- }
-
+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();
- ofs = ofs.snapped(Vector2(snap, snap));
+ pos = pos.snapped(Vector2(snap, snap));
}
+ return pos;
+}
- ofs /= EDSCALE;
+Vector2 VisualScriptEditor::_get_available_pos(bool p_centered, Vector2 p_pos) const {
+ if (p_centered) {
+ p_pos = _get_pos_in_graph(graph->get_size() * 0.5);
+ }
while (true) {
bool exists = false;
List<int> existing;
script->get_node_list(&existing);
- for (List<int>::Element *E = existing.front(); E; E = E->next()) {
- Point2 pos = script->get_node_position(E->get());
- if (pos.distance_to(ofs) < 50) {
- ofs += Vector2(graph->get_snap(), graph->get_snap());
+ 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;
}
@@ -1663,7 +1742,7 @@ Vector2 VisualScriptEditor::_get_available_pos(bool centered, Vector2 ofs) const
break;
}
- return ofs;
+ return p_pos;
}
String VisualScriptEditor::_validate_name(const String &p_name) const {
@@ -1685,6 +1764,128 @@ String VisualScriptEditor::_validate_name(const String &p_name) const {
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<GraphNode>(graph->get_child(i));
+ if (gn) {
+ if (gn->is_selected()) {
+ int id = gn->get_name().operator String().to_int();
+ Ref<VisualScriptNode> node = script->get_node(id);
+ if (Object::cast_to<VisualScriptFunction>(*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<VisualScript::SequenceConnection> 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<VisualScript::DataConnection> 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<int, int> remap;
+
+ undo_redo->create_action(TTR("Paste VisualScript Nodes"));
+ int idc = script->get_available_id() + 1;
+
+ RBSet<int> to_select;
+
+ RBSet<Vector2> existing_positions;
+
+ {
+ List<int> 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<int, Ref<VisualScriptNode>> &E : clipboard->nodes) {
+ Ref<VisualScriptNode> 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<GraphNode>(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.
@@ -1705,8 +1906,8 @@ void VisualScriptEditor::_on_nodes_delete() {
undo_redo->create_action(TTR("Remove VisualScript Nodes"));
- for (List<int>::Element *F = to_erase.front(); F; F = F->next()) {
- int cr_node = F->get();
+ 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));
@@ -1714,18 +1915,18 @@ void VisualScriptEditor::_on_nodes_delete() {
List<VisualScript::SequenceConnection> sequence_conns;
script->get_sequence_connection_list(&sequence_conns);
- for (List<VisualScript::SequenceConnection>::Element *E = sequence_conns.front(); E; E = E->next()) {
- if (E->get().from_node == cr_node || E->get().to_node == cr_node) {
- undo_redo->add_undo_method(script.ptr(), "sequence_connect", E->get().from_node, E->get().from_output, E->get().to_node);
+ 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<VisualScript::DataConnection> data_conns;
script->get_data_connection_list(&data_conns);
- for (List<VisualScript::DataConnection>::Element *E = data_conns.front(); E; E = E->next()) {
- if (E->get().from_node == F->get() || E->get().to_node == F->get()) {
- undo_redo->add_undo_method(script.ptr(), "data_connect", E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port);
+ 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);
}
}
}
@@ -1736,7 +1937,7 @@ void VisualScriptEditor::_on_nodes_delete() {
}
void VisualScriptEditor::_on_nodes_duplicate() {
- Set<int> to_duplicate;
+ RBSet<int> to_duplicate;
for (int i = 0; i < graph->get_child_count(); i++) {
GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i));
@@ -1755,36 +1956,36 @@ void VisualScriptEditor::_on_nodes_duplicate() {
undo_redo->create_action(TTR("Duplicate VisualScript Nodes"));
int idc = script->get_available_id() + 1;
- Set<int> to_select;
+ RBSet<int> to_select;
HashMap<int, int> remap;
- for (Set<int>::Element *F = to_duplicate.front(); F; F = F->next()) {
+ 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<VisualScriptNode> node = script->get_node(F->get());
+ Ref<VisualScriptNode> node = script->get_node(F);
Ref<VisualScriptNode> dupe = node->duplicate(true);
int new_id = idc++;
- remap.set(F->get(), new_id);
+ 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->get()) + Vector2(20, 20));
+ 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<VisualScript::SequenceConnection> seqs;
script->get_sequence_connection_list(&seqs);
- for (List<VisualScript::SequenceConnection>::Element *E = seqs.front(); E; E = E->next()) {
- if (to_duplicate.has(E->get().from_node) && to_duplicate.has(E->get().to_node)) {
- undo_redo->add_do_method(script.ptr(), "sequence_connect", remap[E->get().from_node], E->get().from_output, remap[E->get().to_node]);
+ 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<VisualScript::DataConnection> data;
script->get_data_connection_list(&data);
- for (List<VisualScript::DataConnection>::Element *E = data.front(); E; E = E->next()) {
- if (to_duplicate.has(E->get().from_node) && to_duplicate.has(E->get().to_node)) {
- undo_redo->add_do_method(script.ptr(), "data_connect", remap[E->get().from_node], E->get().from_port, remap[E->get().to_node], E->get().to_port);
+ 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);
}
}
@@ -1806,42 +2007,53 @@ void VisualScriptEditor::_on_nodes_duplicate() {
}
}
-void VisualScriptEditor::_generic_search(String p_base_type, Vector2 pos, bool node_centered) {
+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(p_base_type, false, false); // neither connecting nor reset text
-
- // Ensure that the dialog fits inside the graph.
- Size2 bounds = graph->get_global_position() + graph->get_size() - new_connect_node_select->get_size();
- pos.x = pos.x > bounds.x ? bounds.x : pos.x;
- pos.y = pos.y > bounds.y ? bounds.y : pos.y;
-
- if (pos != Vector2()) {
- new_connect_node_select->set_position(pos);
- }
+ new_connect_node_select->select_from_visual_script(script, false); // do not reset text
}
-void VisualScriptEditor::_input(const Ref<InputEvent> &p_event) {
+void VisualScriptEditor::input(const Ref<InputEvent> &p_event) {
+ ERR_FAIL_COND(p_event.is_null());
+
// GUI input for VS Editor Plugin
Ref<InputEventMouseButton> key = p_event;
- if (key.is_valid() && !key->is_pressed()) {
- mouse_up_position = Input::get_singleton()->get_mouse_position();
+ if (key.is_valid() && key->is_pressed()) {
+ mouse_up_position = get_screen_position() + get_local_mouse_position();
}
}
void VisualScriptEditor::_graph_gui_input(const Ref<InputEvent> &p_event) {
Ref<InputEventMouseButton> key = p_event;
- if (key.is_valid() && key->is_pressed() && key->get_button_mask() == BUTTON_RIGHT) {
- saved_position = graph->get_local_mouse_position();
+ if (key.is_valid() && key->is_pressed() && key->get_button_mask() == MouseButton::RIGHT) {
+ bool is_empty_selection = true;
- Point2 gpos = Input::get_singleton()->get_mouse_position();
- _generic_search(script->get_instance_base_type(), gpos);
+ for (int i = 0; i < graph->get_child_count(); i++) {
+ GraphNode *gn = Object::cast_to<GraphNode>(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();
+ }
}
}
@@ -1852,18 +2064,18 @@ void VisualScriptEditor::_members_gui_input(const Ref<InputEvent> &p_event) {
TreeItem *ti = members->get_selected();
if (ti) {
TreeItem *root = members->get_root();
- if (ti->get_parent() == root->get_children()) {
+ if (ti->get_parent() == root->get_first_child()) {
member_type = MEMBER_FUNCTION;
}
- if (ti->get_parent() == root->get_children()->get_next()) {
+ if (ti->get_parent() == root->get_first_child()->get_next()) {
member_type = MEMBER_VARIABLE;
}
- if (ti->get_parent() == root->get_children()->get_next()->get_next()) {
+ 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("visual_script_editor/delete_selected", p_event)) {
+ if (ED_IS_SHORTCUT("ui_graph_delete", p_event)) {
_member_option(MEMBER_REMOVE);
}
if (ED_IS_SHORTCUT("visual_script_editor/edit_member", p_event)) {
@@ -1873,9 +2085,9 @@ void VisualScriptEditor::_members_gui_input(const Ref<InputEvent> &p_event) {
}
Ref<InputEventMouseButton> btn = p_event;
- if (btn.is_valid() && btn->is_doubleclick()) {
+ if (btn.is_valid() && btn->is_double_click()) {
TreeItem *ti = members->get_selected();
- if (ti && ti->get_parent() == members->get_root()->get_children()) { // to check if it's a function
+ 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)));
}
}
@@ -1908,8 +2120,8 @@ void VisualScriptEditor::_rename_function(const String &name, const String &new_
// Also fix all function calls.
List<int> lst;
script->get_node_list(&lst);
- for (List<int>::Element *F = lst.front(); F; F = F->next()) {
- Ref<VisualScriptFunctionCall> fncall = script->get_node(F->get());
+ for (int &F : lst) {
+ Ref<VisualScriptFunctionCall> fncall = script->get_node(F);
if (!fncall.is_valid()) {
continue;
}
@@ -1934,13 +2146,17 @@ void VisualScriptEditor::_fn_name_box_input(const Ref<InputEvent> &p_event) {
}
Ref<InputEventKey> key = p_event;
- if (key.is_valid() && key->is_pressed() && key->get_keycode() == KEY_ENTER) {
+ if (key.is_valid() && key->is_pressed() && key->get_keycode() == Key::ENTER) {
function_name_edit->hide();
- _rename_function(selected, function_name_box->get_text());
+ _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);
@@ -1950,20 +2166,20 @@ Variant VisualScriptEditor::get_drag_data_fw(const Point2 &p_point, Control *p_f
String type = it->get_metadata(0);
- if (type == String()) {
+ if (type.is_empty()) {
return Variant();
}
Dictionary dd;
TreeItem *root = members->get_root();
- if (it->get_parent() == root->get_children()) {
+ if (it->get_parent() == root->get_first_child()) {
dd["type"] = "visual_script_function_drag";
dd["function"] = type;
- } else if (it->get_parent() == root->get_children()->get_next()) {
+ } 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_children()->get_next()->get_next()) {
+ } else if (it->get_parent() == root->get_first_child()->get_next()->get_next()) {
dd["type"] = "visual_script_signal_drag";
dd["signal"] = type;
@@ -1993,7 +2209,7 @@ bool VisualScriptEditor::can_drop_data_fw(const Point2 &p_point, const Variant &
String(d["type"]) == "nodes")) {
if (String(d["type"]) == "obj_property") {
#ifdef OSX_ENABLED
- const_cast<VisualScriptEditor *>(this)->_show_hint(vformat(TTR("Hold %s to drop a Getter. Hold Shift to drop a generic signature."), find_keycode_name(KEY_META)));
+ const_cast<VisualScriptEditor *>(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<VisualScriptEditor *>(this)->_show_hint(TTR("Hold Ctrl to drop a Getter. Hold Shift to drop a generic signature."));
#endif
@@ -2001,7 +2217,7 @@ bool VisualScriptEditor::can_drop_data_fw(const Point2 &p_point, const Variant &
if (String(d["type"]) == "nodes") {
#ifdef OSX_ENABLED
- const_cast<VisualScriptEditor *>(this)->_show_hint(vformat(TTR("Hold %s to drop a simple reference to the node."), find_keycode_name(KEY_META)));
+ const_cast<VisualScriptEditor *>(this)->_show_hint(vformat(TTR("Hold %s to drop a simple reference to the node."), find_keycode_name(Key::META)));
#else
const_cast<VisualScriptEditor *>(this)->_show_hint(TTR("Hold Ctrl to drop a simple reference to the node."));
#endif
@@ -2009,7 +2225,7 @@ bool VisualScriptEditor::can_drop_data_fw(const Point2 &p_point, const Variant &
if (String(d["type"]) == "visual_script_variable_drag") {
#ifdef OSX_ENABLED
- const_cast<VisualScriptEditor *>(this)->_show_hint(vformat(TTR("Hold %s to drop a Variable Setter."), find_keycode_name(KEY_META)));
+ const_cast<VisualScriptEditor *>(this)->_show_hint(vformat(TTR("Hold %s to drop a Variable Setter."), find_keycode_name(Key::META)));
#else
const_cast<VisualScriptEditor *>(this)->_show_hint(TTR("Hold Ctrl to drop a Variable Setter."));
#endif
@@ -2059,16 +2275,9 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
return;
}
- Vector2 ofs = graph->get_scroll_ofs() + p_point;
-
- if (graph->is_using_snap()) {
- int snap = graph->get_snap();
- ofs = ofs.snapped(Vector2(snap, snap));
- }
-
- ofs /= EDSCALE;
+ Vector2 pos = _get_pos_in_graph(p_point);
- int new_id = _create_new_node_from_name(d["node_type"], ofs);
+ int new_id = _create_new_node_from_name(d["node_type"], pos);
Node *node = graph->get_node(itos(new_id));
if (node) {
@@ -2079,35 +2288,29 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
if (String(d["type"]) == "visual_script_variable_drag") {
#ifdef OSX_ENABLED
- bool use_set = Input::get_singleton()->is_key_pressed(KEY_META);
+ bool use_set = Input::get_singleton()->is_key_pressed(Key::META);
#else
- bool use_set = Input::get_singleton()->is_key_pressed(KEY_CONTROL);
+ bool use_set = Input::get_singleton()->is_key_pressed(Key::CTRL);
#endif
- Vector2 ofs = graph->get_scroll_ofs() + p_point;
- if (graph->is_using_snap()) {
- int snap = graph->get_snap();
- ofs = ofs.snapped(Vector2(snap, snap));
- }
-
- ofs /= EDSCALE;
+ Vector2 pos = _get_pos_in_graph(p_point);
Ref<VisualScriptNode> vnode;
if (use_set) {
- Ref<VisualScriptVariableSet> vnodes;
- vnodes.instance();
- vnodes->set_variable(d["variable"]);
- vnode = vnodes;
+ Ref<VisualScriptPropertySet> pset;
+ pset.instantiate();
+ vnode = pset;
} else {
- Ref<VisualScriptVariableGet> vnodeg;
- vnodeg.instance();
- vnodeg->set_variable(d["variable"]);
- vnode = vnodeg;
+ Ref<VisualScriptPropertyGet> pget;
+ pget.instantiate();
+ vnode = pget;
}
int new_id = script->get_available_id();
-
undo_redo->create_action(TTR("Add Node"));
- undo_redo->add_do_method(script.ptr(), "add_node", new_id, vnode, ofs);
+ undo_redo->add_do_method(vnode.ptr(), "set_property", d["variable"]);
+ undo_redo->add_do_method(vnode.ptr(), "set_base_script", script->get_path());
+
+ undo_redo->add_do_method(script.ptr(), "add_node", new_id, vnode, pos);
undo_redo->add_undo_method(script.ptr(), "remove_node", new_id);
undo_redo->add_do_method(this, "_update_graph");
undo_redo->add_undo_method(this, "_update_graph");
@@ -2121,22 +2324,16 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
}
if (String(d["type"]) == "visual_script_function_drag") {
- Vector2 ofs = graph->get_scroll_ofs() + p_point;
- if (graph->is_using_snap()) {
- int snap = graph->get_snap();
- ofs = ofs.snapped(Vector2(snap, snap));
- }
-
- ofs /= EDSCALE;
+ Vector2 pos = _get_pos_in_graph(p_point);
Ref<VisualScriptFunctionCall> vnode;
- vnode.instance();
+ vnode.instantiate();
vnode->set_call_mode(VisualScriptFunctionCall::CALL_MODE_SELF);
int new_id = script->get_available_id();
undo_redo->create_action(TTR("Add Node"));
- undo_redo->add_do_method(script.ptr(), "add_node", new_id, vnode, ofs);
+ undo_redo->add_do_method(script.ptr(), "add_node", new_id, vnode, pos);
undo_redo->add_do_method(vnode.ptr(), "set_base_type", script->get_instance_base_type());
undo_redo->add_do_method(vnode.ptr(), "set_function", d["function"]);
@@ -2153,22 +2350,16 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
}
if (String(d["type"]) == "visual_script_signal_drag") {
- Vector2 ofs = graph->get_scroll_ofs() + p_point;
- if (graph->is_using_snap()) {
- int snap = graph->get_snap();
- ofs = ofs.snapped(Vector2(snap, snap));
- }
-
- ofs /= EDSCALE;
+ Vector2 pos = _get_pos_in_graph(p_point);
Ref<VisualScriptEmitSignal> vnode;
- vnode.instance();
+ vnode.instantiate();
vnode->set_signal(d["signal"]);
int new_id = script->get_available_id();
undo_redo->create_action(TTR("Add Node"));
- undo_redo->add_do_method(script.ptr(), "add_node", new_id, vnode, ofs);
+ undo_redo->add_do_method(script.ptr(), "add_node", new_id, vnode, pos);
undo_redo->add_undo_method(script.ptr(), "remove_node", new_id);
undo_redo->add_do_method(this, "_update_graph");
undo_redo->add_undo_method(this, "_update_graph");
@@ -2182,22 +2373,16 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
}
if (String(d["type"]) == "resource") {
- Vector2 ofs = graph->get_scroll_ofs() + p_point;
- if (graph->is_using_snap()) {
- int snap = graph->get_snap();
- ofs = ofs.snapped(Vector2(snap, snap));
- }
-
- ofs /= EDSCALE;
+ Vector2 pos = _get_pos_in_graph(p_point);
Ref<VisualScriptPreload> prnode;
- prnode.instance();
+ prnode.instantiate();
prnode->set_preload(d["resource"]);
int new_id = script->get_available_id();
undo_redo->create_action(TTR("Add Preload Node"));
- undo_redo->add_do_method(script.ptr(), "add_node", new_id, prnode, ofs);
+ undo_redo->add_do_method(script.ptr(), "add_node", new_id, prnode, pos);
undo_redo->add_undo_method(script.ptr(), "remove_node", new_id);
undo_redo->add_do_method(this, "_update_graph");
undo_redo->add_undo_method(this, "_update_graph");
@@ -2211,13 +2396,12 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
}
if (String(d["type"]) == "files") {
- Vector2 ofs = graph->get_scroll_ofs() + p_point;
- if (graph->is_using_snap()) {
- int snap = graph->get_snap();
- ofs = ofs.snapped(Vector2(snap, snap));
- }
-
- ofs /= EDSCALE;
+#ifdef OSX_ENABLED
+ bool use_preload = Input::get_singleton()->is_key_pressed(Key::META);
+#else
+ bool use_preload = Input::get_singleton()->is_key_pressed(Key::CTRL);
+#endif
+ Vector2 pos = _get_pos_in_graph(p_point);
Array files = d["files"];
@@ -2225,23 +2409,32 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
int new_id = script->get_available_id();
if (files.size()) {
- undo_redo->create_action(TTR("Add Preload Node"));
+ undo_redo->create_action(TTR("Add Node(s)"));
for (int i = 0; i < files.size(); i++) {
Ref<Resource> res = ResourceLoader::load(files[i]);
if (!res.is_valid()) {
continue;
}
+ Ref<Script> drop_script = ResourceLoader::load(files[i]);
+ if (drop_script.is_valid() && drop_script->is_tool() && drop_script->get_instance_base_type() == "VisualScriptCustomNode" && !use_preload) {
+ Ref<VisualScriptCustomNode> vscn;
+ vscn.instantiate();
+ vscn->set_script(drop_script);
+
+ undo_redo->add_do_method(script.ptr(), "add_node", new_id, vscn, pos);
+ undo_redo->add_undo_method(script.ptr(), "remove_node", new_id);
+ } else {
+ Ref<VisualScriptPreload> prnode;
+ prnode.instantiate();
+ prnode->set_preload(res);
- Ref<VisualScriptPreload> prnode;
- prnode.instance();
- prnode->set_preload(res);
-
- undo_redo->add_do_method(script.ptr(), "add_node", new_id, prnode, ofs);
- undo_redo->add_undo_method(script.ptr(), "remove_node", new_id);
+ undo_redo->add_do_method(script.ptr(), "add_node", new_id, prnode, pos);
+ undo_redo->add_undo_method(script.ptr(), "remove_node", new_id);
+ }
new_ids.push_back(new_id);
new_id++;
- ofs += Vector2(20, 20) * EDSCALE;
+ pos += Vector2(20, 20);
}
undo_redo->add_do_method(this, "_update_graph");
@@ -2249,8 +2442,8 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
undo_redo->commit_action();
}
- for (List<int>::Element *E = new_ids.front(); E; E = E->next()) {
- Node *node = graph->get_node(itos(E->get()));
+ for (int &E : new_ids) {
+ Node *node = graph->get_node(itos(E));
if (node) {
graph->set_selected(node);
_node_selected(node);
@@ -2267,59 +2460,47 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
}
#ifdef OSX_ENABLED
- bool use_node = Input::get_singleton()->is_key_pressed(KEY_META);
+ bool use_node = Input::get_singleton()->is_key_pressed(Key::META);
#else
- bool use_node = Input::get_singleton()->is_key_pressed(KEY_CONTROL);
+ bool use_node = Input::get_singleton()->is_key_pressed(Key::CTRL);
#endif
Array nodes = d["nodes"];
- Vector2 ofs = graph->get_scroll_ofs() + p_point;
-
- if (graph->is_using_snap()) {
- int snap = graph->get_snap();
- ofs = ofs.snapped(Vector2(snap, snap));
- }
- ofs /= EDSCALE;
+ Vector2 pos = _get_pos_in_graph(p_point);
undo_redo->create_action(TTR("Add Node(s) From Tree"));
int base_id = script->get_available_id();
- if (nodes.size() > 1) {
- use_node = true;
- }
-
- for (int i = 0; i < nodes.size(); i++) {
- NodePath np = nodes[i];
- Node *node = get_node(np);
- if (!node) {
- continue;
- }
+ if (use_node || nodes.size() > 1) {
+ for (int i = 0; i < nodes.size(); i++) {
+ NodePath np = nodes[i];
+ Node *node = get_node(np);
+ if (!node) {
+ continue;
+ }
- Ref<VisualScriptNode> n;
+ Ref<VisualScriptNode> n;
- if (use_node) {
Ref<VisualScriptSceneNode> scene_node;
- scene_node.instance();
+ scene_node.instantiate();
scene_node->set_node_path(sn->get_path_to(node));
n = scene_node;
- } else {
- // ! Doesn't work properly.
- Ref<VisualScriptFunctionCall> call;
- call.instance();
- call->set_call_mode(VisualScriptFunctionCall::CALL_MODE_NODE_PATH);
- call->set_base_path(sn->get_path_to(node));
- call->set_base_type(node->get_class());
- n = call;
- method_select->select_from_instance(node, "", true, node->get_class());
- selecting_method_id = base_id;
- }
- undo_redo->add_do_method(script.ptr(), "add_node", base_id, n, ofs);
- undo_redo->add_undo_method(script.ptr(), "remove_node", base_id);
+ undo_redo->add_do_method(script.ptr(), "add_node", base_id, n, pos);
+ undo_redo->add_undo_method(script.ptr(), "remove_node", base_id);
- base_id++;
- ofs += Vector2(25, 25);
+ base_id++;
+ pos += Vector2(25, 25);
+ }
+
+ } else {
+ NodePath np = nodes[0];
+ Node *node = get_node(np);
+ drop_position = pos;
+ drop_node = node;
+ drop_path = sn->get_path_to(node);
+ new_connect_node_select->select_from_instance(node, false);
}
undo_redo->add_do_method(this, "_update_graph");
undo_redo->add_undo_method(this, "_update_graph");
@@ -2329,7 +2510,7 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
if (String(d["type"]) == "obj_property") {
Node *sn = _find_script_node(get_tree()->get_edited_scene_root(), get_tree()->get_edited_scene_root(), script);
- if (!sn && !Input::get_singleton()->is_key_pressed(KEY_SHIFT)) {
+ if (!sn && !Input::get_singleton()->is_key_pressed(Key::SHIFT)) {
EditorNode::get_singleton()->show_warning(vformat(TTR("Can't drop properties because script '%s' is not used in this scene.\nDrop holding 'Shift' to just copy the signature."), get_name()));
return;
}
@@ -2341,21 +2522,15 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
}
Node *node = Object::cast_to<Node>(obj);
- Vector2 ofs = graph->get_scroll_ofs() + p_point;
-
- if (graph->is_using_snap()) {
- int snap = graph->get_snap();
- ofs = ofs.snapped(Vector2(snap, snap));
- }
+ Vector2 pos = _get_pos_in_graph(p_point);
- ofs /= EDSCALE;
#ifdef OSX_ENABLED
- bool use_get = Input::get_singleton()->is_key_pressed(KEY_META);
+ bool use_get = Input::get_singleton()->is_key_pressed(Key::META);
#else
- bool use_get = Input::get_singleton()->is_key_pressed(KEY_CONTROL);
+ bool use_get = Input::get_singleton()->is_key_pressed(Key::CTRL);
#endif
- if (!node || Input::get_singleton()->is_key_pressed(KEY_SHIFT)) {
+ if (!node || Input::get_singleton()->is_key_pressed(Key::SHIFT)) {
if (use_get) {
undo_redo->create_action(TTR("Add Getter Property"));
} else {
@@ -2368,25 +2543,23 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
if (!use_get) {
Ref<VisualScriptPropertySet> pset;
- pset.instance();
+ pset.instantiate();
pset->set_call_mode(VisualScriptPropertySet::CALL_MODE_INSTANCE);
pset->set_base_type(obj->get_class());
- /*if (use_value) {
- pset->set_use_builtin_value(true);
- pset->set_builtin_value(d["value"]);
- }*/
vnode = pset;
} else {
Ref<VisualScriptPropertyGet> pget;
- pget.instance();
+ pget.instantiate();
pget->set_call_mode(VisualScriptPropertyGet::CALL_MODE_INSTANCE);
pget->set_base_type(obj->get_class());
-
vnode = pget;
}
- undo_redo->add_do_method(script.ptr(), "add_node", base_id, vnode, ofs);
+ undo_redo->add_do_method(script.ptr(), "add_node", base_id, vnode, pos);
undo_redo->add_do_method(vnode.ptr(), "set_property", d["property"]);
+ if (!obj->get_script().is_null()) {
+ undo_redo->add_do_method(vnode.ptr(), "set_base_script", Ref<Script>(obj->get_script())->get_path());
+ }
if (!use_get) {
undo_redo->add_do_method(vnode.ptr(), "set_default_input_value", 0, d["value"]);
}
@@ -2410,18 +2583,17 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
if (!use_get) {
Ref<VisualScriptPropertySet> pset;
- pset.instance();
+ pset.instantiate();
if (sn == node) {
pset->set_call_mode(VisualScriptPropertySet::CALL_MODE_SELF);
} else {
pset->set_call_mode(VisualScriptPropertySet::CALL_MODE_NODE_PATH);
pset->set_base_path(sn->get_path_to(node));
}
-
vnode = pset;
} else {
Ref<VisualScriptPropertyGet> pget;
- pget.instance();
+ pget.instantiate();
if (sn == node) {
pget->set_call_mode(VisualScriptPropertyGet::CALL_MODE_SELF);
} else {
@@ -2430,11 +2602,15 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
}
vnode = pget;
}
- undo_redo->add_do_method(script.ptr(), "add_node", base_id, vnode, ofs);
+ undo_redo->add_do_method(script.ptr(), "add_node", base_id, vnode, pos);
undo_redo->add_do_method(vnode.ptr(), "set_property", d["property"]);
+ if (!obj->get_script().is_null()) {
+ undo_redo->add_do_method(vnode.ptr(), "set_base_script", Ref<Script>(obj->get_script())->get_path());
+ }
if (!use_get) {
undo_redo->add_do_method(vnode.ptr(), "set_default_input_value", 0, d["value"]);
}
+
undo_redo->add_undo_method(script.ptr(), "remove_node", base_id);
undo_redo->add_do_method(this, "_update_graph");
@@ -2444,21 +2620,13 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
}
}
-void VisualScriptEditor::_selected_method(const String &p_method, const String &p_type, const bool p_connecting) {
- Ref<VisualScriptFunctionCall> vsfc = script->get_node(selecting_method_id);
- if (!vsfc.is_valid()) {
- return;
- }
- vsfc->set_function(p_method);
-}
-
void VisualScriptEditor::_draw_color_over_button(Object *obj, Color p_color) {
Button *button = Object::cast_to<Button>(obj);
if (!button) {
return;
}
- Ref<StyleBox> normal = get_theme_stylebox("normal", "Button");
+ Ref<StyleBox> normal = get_theme_stylebox(SNAME("normal"), SNAME("Button"));
button->draw_rect(Rect2(normal->get_offset(), button->get_size() - normal->get_minimum_size()), p_color);
}
@@ -2488,11 +2656,11 @@ void VisualScriptEditor::_button_resource_previewed(const String &p_path, const
void VisualScriptEditor::apply_code() {
}
-RES VisualScriptEditor::get_edited_resource() const {
+Ref<Resource> VisualScriptEditor::get_edited_resource() const {
return script;
}
-void VisualScriptEditor::set_edited_resource(const RES &p_res) {
+void VisualScriptEditor::set_edited_resource(const Ref<Resource> &p_res) {
ERR_FAIL_COND(script.is_valid());
ERR_FAIL_COND(p_res.is_null());
script = p_res;
@@ -2504,7 +2672,7 @@ void VisualScriptEditor::set_edited_resource(const RES &p_res) {
script->connect("node_ports_changed", callable_mp(this, &VisualScriptEditor::_node_ports_changed));
_update_graph();
- call_deferred("_update_members");
+ call_deferred(SNAME("_update_members"));
}
void VisualScriptEditor::enable_editor() {
@@ -2520,25 +2688,37 @@ void VisualScriptEditor::reload_text() {
String VisualScriptEditor::get_name() {
String name;
- if (script->get_path().find("local://") == -1 && script->get_path().find("::") == -1) {
- name = script->get_path().get_file();
- if (is_unsaved()) {
- if (script->get_path().is_empty()) {
- name = TTR("[unsaved]");
- }
- name += "(*)";
+ name = script->get_path().get_file();
+ if (name.is_empty()) {
+ // This appears for newly created built-in scripts before saving the scene.
+ name = TTR("[unsaved]");
+ } else if (script->is_built_in()) {
+ const String &script_name = script->get_name();
+ if (!script_name.is_empty()) {
+ // If the built-in script has a custom resource name defined,
+ // display the built-in script name as follows: `ResourceName (scene_file.tscn)`
+ name = vformat("%s (%s)", script_name, name.get_slice("::", 0));
}
- } else if (script->get_name() != "") {
- name = script->get_name();
- } else {
- name = script->get_class() + "(" + itos(script->get_instance_id()) + ")";
+ }
+
+ if (is_unsaved()) {
+ name += "(*)";
}
return name;
}
Ref<Texture2D> VisualScriptEditor::get_theme_icon() {
- return Control::get_theme_icon("VisualScript", "EditorIcons");
+ String icon_name = "VisualScript";
+ if (script->is_built_in()) {
+ icon_name += "Internal";
+ }
+
+ if (Control::has_theme_icon(icon_name, "EditorIcons")) {
+ return Control::get_theme_icon(icon_name, SNAME("EditorIcons"));
+ }
+
+ return Control::get_theme_icon(SNAME("VisualScript"), SNAME("EditorIcons"));
}
bool VisualScriptEditor::is_unsaved() {
@@ -2592,7 +2772,7 @@ void VisualScriptEditor::_center_on_node(int p_id) {
if (gn) {
gn->set_selected(true);
- Vector2 new_scroll = gn->get_position_offset() - graph->get_size() * 0.5 + gn->get_size() * 0.5;
+ Vector2 new_scroll = gn->get_position_offset() * graph->get_zoom() - graph->get_size() * 0.5 + gn->get_size() * 0.5;
graph->set_scroll_ofs(new_scroll);
script->set_scroll(new_scroll / EDSCALE);
script->set_edited(true);
@@ -2606,16 +2786,11 @@ void VisualScriptEditor::goto_line(int p_line, bool p_with_error) {
error_line = p_line;
}
- List<StringName> functions;
- script->get_function_list(&functions);
- for (List<StringName>::Element *E = functions.front(); E; E = E->next()) {
- if (script->has_node(p_line)) {
- _update_graph();
- _update_members();
+ if (script->has_node(p_line)) {
+ _update_graph();
+ _update_members();
- call_deferred("call_deferred", "_center_on_node", E->get(), p_line); //editor might be just created and size might not exist yet
- return;
- }
+ call_deferred(SNAME("call_deferred"), "_center_on_node", p_line); // The editor might be just created and size might not exist yet.
}
}
@@ -2654,13 +2829,13 @@ Array VisualScriptEditor::get_breakpoints() {
Array breakpoints;
List<StringName> functions;
script->get_function_list(&functions);
- for (List<StringName>::Element *E = functions.front(); E; E = E->next()) {
+ for (int i = 0; i < functions.size(); i++) {
List<int> nodes;
script->get_node_list(&nodes);
- for (List<int>::Element *F = nodes.front(); F; F = F->next()) {
- Ref<VisualScriptNode> vsn = script->get_node(F->get());
+ for (int &F : nodes) {
+ Ref<VisualScriptNode> vsn = script->get_node(F);
if (vsn->is_breakpoint()) {
- breakpoints.push_back(F->get() - 1); // Subtract 1 because breakpoints in text start from zero.
+ breakpoints.push_back(F - 1); // Subtract 1 because breakpoints in text start from zero.
}
}
}
@@ -2676,12 +2851,12 @@ void VisualScriptEditor::add_callback(const String &p_function, PackedStringArra
}
Ref<VisualScriptFunction> func;
- func.instance();
+ func.instantiate();
for (int i = 0; i < p_args.size(); i++) {
String name = p_args[i];
Variant::Type type = Variant::NIL;
- if (name.find(":") != -1) {
+ if (name.contains(":")) {
String tt = name.get_slice(":", 1);
name = name.get_slice(":", 0);
for (int j = 0; j < Variant::VARIANT_MAX; j++) {
@@ -2721,7 +2896,11 @@ void VisualScriptEditor::set_debugger_active(bool p_active) {
}
}
-void VisualScriptEditor::set_tooltip_request_func(String p_method, Object *p_obj) {
+Control *VisualScriptEditor::get_base_editor() const {
+ return graph;
+}
+
+void VisualScriptEditor::set_tooltip_request_func(const Callable &p_toolip_callback) {
}
Control *VisualScriptEditor::get_edit_menu() {
@@ -2744,7 +2923,7 @@ void VisualScriptEditor::clear_edit_menu() {
void VisualScriptEditor::_change_base_type_callback() {
String bt = select_base_type->get_selected_type();
- ERR_FAIL_COND(bt == String());
+ ERR_FAIL_COND(bt.is_empty());
undo_redo->create_action(TTR("Change Base Type"));
undo_redo->add_do_method(script.ptr(), "set_instance_base_type", bt);
undo_redo->add_undo_method(script.ptr(), "set_instance_base_type", script->get_instance_base_type());
@@ -2825,18 +3004,18 @@ void VisualScriptEditor::_remove_node(int p_id) {
List<VisualScript::SequenceConnection> sequence_conns;
script->get_sequence_connection_list(&sequence_conns);
- for (List<VisualScript::SequenceConnection>::Element *E = sequence_conns.front(); E; E = E->next()) {
- if (E->get().from_node == p_id || E->get().to_node == p_id) {
- undo_redo->add_undo_method(script.ptr(), "sequence_connect", E->get().from_node, E->get().from_output, E->get().to_node);
+ for (const VisualScript::SequenceConnection &E : sequence_conns) {
+ if (E.from_node == p_id || E.to_node == p_id) {
+ undo_redo->add_undo_method(script.ptr(), "sequence_connect", E.from_node, E.from_output, E.to_node);
}
}
List<VisualScript::DataConnection> data_conns;
script->get_data_connection_list(&data_conns);
- for (List<VisualScript::DataConnection>::Element *E = data_conns.front(); E; E = E->next()) {
- if (E->get().from_node == p_id || E->get().to_node == p_id) {
- undo_redo->add_undo_method(script.ptr(), "data_connect", E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port);
+ for (const VisualScript::DataConnection &E : data_conns) {
+ if (E.from_node == p_id || E.to_node == p_id) {
+ undo_redo->add_undo_method(script.ptr(), "data_connect", E.from_node, E.from_port, E.to_node, E.to_port);
}
}
@@ -2854,9 +3033,9 @@ bool VisualScriptEditor::node_has_sequence_connections(int p_id) {
List<VisualScript::SequenceConnection> sequence_conns;
script->get_sequence_connection_list(&sequence_conns);
- for (List<VisualScript::SequenceConnection>::Element *E = sequence_conns.front(); E; E = E->next()) {
- int from = E->get().from_node;
- int to = E->get().to_node;
+ for (const VisualScript::SequenceConnection &E : sequence_conns) {
+ int from = E.from_node;
+ int to = E.to_node;
if (to == p_id || from == p_id) {
return true;
@@ -2889,6 +3068,20 @@ void VisualScriptEditor::_graph_connected(const String &p_from, int p_from_slot,
ERR_FAIL_COND(from_seq != to_seq);
+ // Checking to prevent warnings.
+ if (from_seq) {
+ if (script->has_sequence_connection(p_from.to_int(), from_port, p_to.to_int())) {
+ return;
+ }
+ } else if (script->has_data_connection(p_from.to_int(), from_port, p_to.to_int(), to_port)) {
+ return;
+ }
+
+ // Preventing connection to itself.
+ if (p_from.to_int() == p_to.to_int()) {
+ return;
+ }
+
// Do all the checks here.
StringName func; // This the func where we store the one the nodes at the end of the resolution on having multiple nodes.
@@ -2941,9 +3134,8 @@ void VisualScriptEditor::_graph_connected(const String &p_from, int p_from_slot,
if (!converted) {
undo_redo->add_do_method(script.ptr(), "data_connect", p_from.to_int(), from_port, p_to.to_int(), to_port);
undo_redo->add_undo_method(script.ptr(), "data_disconnect", p_from.to_int(), from_port, p_to.to_int(), to_port);
- }
- // Update nodes in graph
- if (!converted) {
+
+ // Update nodes in graph
undo_redo->add_do_method(this, "_update_graph", p_from.to_int());
undo_redo->add_do_method(this, "_update_graph", p_to.to_int());
undo_redo->add_undo_method(this, "_update_graph", p_from.to_int());
@@ -3015,9 +3207,9 @@ void VisualScriptEditor::_graph_connect_to_empty(const String &p_from, int p_fro
if (!vsn.is_valid()) {
return;
}
- if (vsn->get_output_value_port_count())
-
+ if (vsn->get_output_value_port_count() || vsn->get_output_sequence_port_count()) {
port_action_pos = p_release_pos;
+ }
if (p_from_slot < vsn->get_output_sequence_port_count()) {
port_action_node = p_from.to_int();
@@ -3030,7 +3222,7 @@ void VisualScriptEditor::_graph_connect_to_empty(const String &p_from, int p_fro
}
}
-VisualScriptNode::TypeGuess VisualScriptEditor::_guess_output_type(int p_port_action_node, int p_port_action_output, Set<int> &visited_nodes) {
+VisualScriptNode::TypeGuess VisualScriptEditor::_guess_output_type(int p_port_action_node, int p_port_action_output, RBSet<int> &visited_nodes) {
VisualScriptNode::TypeGuess tg;
tg.type = Variant::NIL;
@@ -3042,7 +3234,7 @@ VisualScriptNode::TypeGuess VisualScriptEditor::_guess_output_type(int p_port_ac
Ref<VisualScriptNode> node = script->get_node(p_port_action_node);
- if (!node.is_valid()) {
+ if (!node.is_valid() || node->get_output_value_port_count() <= p_port_action_output) {
return tg;
}
@@ -3081,19 +3273,12 @@ VisualScriptNode::TypeGuess VisualScriptEditor::_guess_output_type(int p_port_ac
}
void VisualScriptEditor::_port_action_menu(int p_option) {
- Vector2 ofs = graph->get_scroll_ofs() + port_action_pos;
- if (graph->is_using_snap()) {
- int snap = graph->get_snap();
- ofs = ofs.snapped(Vector2(snap, snap));
- }
- ofs /= EDSCALE;
-
- Set<int> vn;
+ RBSet<int> vn;
switch (p_option) {
case CREATE_CALL_SET_GET: {
Ref<VisualScriptFunctionCall> n;
- n.instance();
+ n.instantiate();
VisualScriptNode::TypeGuess tg = _guess_output_type(port_action_node, port_action_output, vn);
@@ -3103,19 +3288,34 @@ void VisualScriptEditor::_port_action_menu(int p_option) {
n->set_base_type("Object");
}
String type_string;
+ String base_script = "";
if (script->get_node(port_action_node)->get_output_value_port_count() > 0) {
type_string = script->get_node(port_action_node)->get_output_value_port_info(port_action_output).hint_string;
+ VisualScriptFunctionCall *vsfc = Object::cast_to<VisualScriptFunctionCall>(*script->get_node(port_action_node));
+ if (vsfc) {
+ base_script = vsfc->get_base_script();
+ } else {
+ VisualScriptPropertyGet *vspg = Object::cast_to<VisualScriptPropertyGet>(*script->get_node(port_action_node));
+ if (vspg) {
+ base_script = vspg->get_base_script();
+ } else {
+ VisualScriptPropertySet *vsps = Object::cast_to<VisualScriptPropertySet>(*script->get_node(port_action_node));
+ if (vsps) {
+ base_script = vsps->get_base_script();
+ }
+ }
+ }
}
if (tg.type == Variant::OBJECT) {
if (tg.script.is_valid()) {
- new_connect_node_select->select_from_script(tg.script, "");
+ new_connect_node_select->select_from_script(tg.script);
} else if (type_string != String()) {
- new_connect_node_select->select_from_base_type(type_string);
+ new_connect_node_select->select_from_base_type(type_string, base_script);
} else {
- new_connect_node_select->select_from_base_type(n->get_base_type());
+ new_connect_node_select->select_from_base_type(n->get_base_type(), base_script);
}
} else if (tg.type == Variant::NIL) {
- new_connect_node_select->select_from_base_type("");
+ new_connect_node_select->select_from_base_type("", base_script);
} else {
new_connect_node_select->select_from_basic_type(tg.type);
}
@@ -3133,7 +3333,7 @@ void VisualScriptEditor::_port_action_menu(int p_option) {
property_info = script->get_node(port_action_node)->get_output_value_port_info(port_action_output);
}
if (tg.type == Variant::OBJECT) {
- if (property_info.type == Variant::OBJECT && property_info.hint_string != String()) {
+ if (property_info.type == Variant::OBJECT && !property_info.hint_string.is_empty()) {
new_connect_node_select->select_from_action(property_info.hint_string);
} else {
new_connect_node_select->select_from_action("");
@@ -3178,130 +3378,218 @@ void VisualScriptEditor::connect_data(Ref<VisualScriptNode> vnode_old, Ref<Visua
}
void VisualScriptEditor::_selected_connect_node(const String &p_text, const String &p_category, const bool p_connecting) {
- Vector2 ofs = graph->get_scroll_ofs() + port_action_pos;
- if (graph->is_using_snap()) {
- int snap = graph->get_snap();
- ofs = ofs.snapped(Vector2(snap, snap));
- }
- ofs /= EDSCALE;
- ofs /= graph->get_zoom();
-
- Set<int> vn;
+#ifdef OSX_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
+ Vector2 pos = _get_pos_in_graph(port_action_pos);
+ RBSet<int> vn;
bool port_node_exists = true;
- // if (func == StringName()) {
- // func = default_func;
- // port_node_exists = false;
- // }
+ if (drop_position != Vector2()) {
+ pos = drop_position;
+ }
+ drop_position = Vector2();
- if (p_category == "visualscript") {
- Ref<VisualScriptNode> vnode_new = VisualScriptLanguage::singleton->create_node_from_name(p_text);
- Ref<VisualScriptNode> vnode_old;
- if (port_node_exists && p_connecting) {
- vnode_old = script->get_node(port_action_node);
- }
- int new_id = script->get_available_id();
+ Ref<VisualScriptNode> vnode;
+ Ref<VisualScriptNode> vnode_old;
+ if (port_node_exists && p_connecting) {
+ vnode_old = script->get_node(port_action_node);
+ }
- if (Object::cast_to<VisualScriptOperator>(vnode_new.ptr()) && vnode_old.is_valid()) {
- Variant::Type type = vnode_old->get_output_value_port_info(port_action_output).type;
- Object::cast_to<VisualScriptOperator>(vnode_new.ptr())->set_typed(type);
- }
+ if (p_category.begins_with("VisualScriptNode")) {
+ Ref<VisualScriptNode> n = VisualScriptLanguage::singleton->create_node_from_name(p_text);
- if (Object::cast_to<VisualScriptTypeCast>(vnode_new.ptr()) && vnode_old.is_valid()) {
+ if (Object::cast_to<VisualScriptTypeCast>(n.ptr()) && vnode_old.is_valid()) {
Variant::Type type = vnode_old->get_output_value_port_info(port_action_output).type;
String hint_name = vnode_old->get_output_value_port_info(port_action_output).hint_string;
if (type == Variant::OBJECT) {
- Object::cast_to<VisualScriptTypeCast>(vnode_new.ptr())->set_base_type(hint_name);
+ Object::cast_to<VisualScriptTypeCast>(n.ptr())->set_base_type(hint_name);
} else if (type == Variant::NIL) {
- Object::cast_to<VisualScriptTypeCast>(vnode_new.ptr())->set_base_type("");
+ Object::cast_to<VisualScriptTypeCast>(n.ptr())->set_base_type("");
} else {
- Object::cast_to<VisualScriptTypeCast>(vnode_new.ptr())->set_base_type(Variant::get_type_name(type));
+ Object::cast_to<VisualScriptTypeCast>(n.ptr())->set_base_type(Variant::get_type_name(type));
}
}
-
- undo_redo->create_action(TTR("Add Node"));
- undo_redo->add_do_method(script.ptr(), "add_node", new_id, vnode_new, ofs);
- if (vnode_old.is_valid() && p_connecting) {
- connect_seq(vnode_old, vnode_new, new_id);
- connect_data(vnode_old, vnode_new, new_id);
- }
-
- undo_redo->add_undo_method(script.ptr(), "remove_node", new_id);
- undo_redo->add_do_method(this, "_update_graph");
- undo_redo->add_undo_method(this, "_update_graph");
- undo_redo->commit_action();
- return;
+ vnode = n;
}
- Ref<VisualScriptNode> vnode;
- Ref<VisualScriptPropertySet> script_prop_set;
-
- if (p_category == String("method")) {
+ if (p_category == String("Class") && !p_connecting) {
Ref<VisualScriptFunctionCall> n;
- n.instance();
- vnode = n;
- } else if (p_category == String("set")) {
- Ref<VisualScriptPropertySet> n;
- n.instance();
- vnode = n;
- script_prop_set = n;
- } else if (p_category == String("get")) {
- Ref<VisualScriptPropertyGet> n;
- n.instance();
- n->set_property(p_text);
+ n.instantiate();
+ n->set_call_mode(VisualScriptFunctionCall::CALL_MODE_SINGLETON);
+ n->set_singleton("ClassDB");
+ n->set_function("instantiate");
+ // Did not find a way to edit the input port value
vnode = n;
- }
-
- if (p_category == String("action")) {
- if (p_text == "VisualScriptCondition") {
- Ref<VisualScriptCondition> n;
- n.instance();
- vnode = n;
+ } else if (p_category == String("class_method")) {
+ Ref<VisualScriptFunctionCall> n;
+ n.instantiate();
+ if (!drop_path.is_empty()) {
+ if (drop_path == ".") {
+ n->set_call_mode(VisualScriptFunctionCall::CALL_MODE_SELF);
+ } else {
+ n->set_call_mode(VisualScriptFunctionCall::CALL_MODE_NODE_PATH);
+ n->set_base_path(drop_path);
+ }
+ } else {
+ n->set_call_mode(VisualScriptFunctionCall::CALL_MODE_INSTANCE);
}
- if (p_text == "VisualScriptSwitch") {
- Ref<VisualScriptSwitch> n;
- n.instance();
- vnode = n;
- } else if (p_text == "VisualScriptSequence") {
- Ref<VisualScriptSequence> n;
- n.instance();
+ if (drop_node) {
+ n->set_base_type(drop_node->get_class());
+ if (drop_node->get_script_instance()) {
+ n->set_base_script(drop_node->get_script_instance()->get_script()->get_path());
+ }
+ }
+ vnode = n;
+ } else if (p_category == String("class_property")) {
+ Vector<String> property_path = p_text.split(":");
+ if (held_ctrl) {
+ Ref<VisualScriptPropertySet> n;
+ n.instantiate();
+ n->set_property(property_path[1]);
+ if (!drop_path.is_empty()) {
+ if (drop_path == ".") {
+ n->set_call_mode(VisualScriptPropertySet::CALL_MODE_SELF);
+ } else {
+ n->set_call_mode(VisualScriptPropertySet::CALL_MODE_NODE_PATH);
+ n->set_base_path(drop_path);
+ }
+ }
+ if (drop_node) {
+ n->set_base_type(drop_node->get_class());
+ if (drop_node->get_script_instance()) {
+ n->set_base_script(drop_node->get_script_instance()->get_script()->get_path());
+ }
+ }
vnode = n;
- } else if (p_text == "VisualScriptIterator") {
- Ref<VisualScriptIterator> n;
- n.instance();
+ } else {
+ Ref<VisualScriptPropertyGet> n;
+ n.instantiate();
+ n->set_property(property_path[1]);
+ if (!drop_path.is_empty()) {
+ if (drop_path == ".") {
+ n->set_call_mode(VisualScriptPropertyGet::CALL_MODE_SELF);
+ } else {
+ n->set_call_mode(VisualScriptPropertyGet::CALL_MODE_NODE_PATH);
+ n->set_base_path(drop_path);
+ }
+ }
+ if (drop_node) {
+ n->set_base_type(drop_node->get_class());
+ if (drop_node->get_script_instance()) {
+ n->set_base_script(drop_node->get_script_instance()->get_script()->get_path());
+ }
+ }
vnode = n;
- } else if (p_text == "VisualScriptWhile") {
- Ref<VisualScriptWhile> n;
- n.instance();
+ }
+ } else if (p_category == String("class_constant")) {
+ Vector<String> property_path = p_text.split(":");
+ if (ClassDB::class_exists(property_path[0])) {
+ Ref<VisualScriptClassConstant> n;
+ n.instantiate();
+ n->set_base_type(property_path[0]);
+ n->set_class_constant(property_path[1]);
vnode = n;
- } else if (p_text == "VisualScriptReturn") {
- Ref<VisualScriptReturn> n;
- n.instance();
+ } else {
+ Ref<VisualScriptBasicTypeConstant> n;
+ n.instantiate();
+ if (property_path[0] == "Nil") {
+ n->set_basic_type(Variant::NIL);
+ } else if (property_path[0] == "bool") {
+ n->set_basic_type(Variant::BOOL);
+ } else if (property_path[0] == "int") {
+ n->set_basic_type(Variant::INT);
+ } else if (property_path[0] == "float") {
+ n->set_basic_type(Variant::FLOAT);
+ } else if (property_path[0] == "String") {
+ n->set_basic_type(Variant::STRING);
+ } else if (property_path[0] == "Vector2") {
+ n->set_basic_type(Variant::VECTOR2);
+ } else if (property_path[0] == "Vector2i") {
+ n->set_basic_type(Variant::VECTOR2I);
+ } else if (property_path[0] == "Rect2") {
+ n->set_basic_type(Variant::RECT2);
+ } else if (property_path[0] == "Rect2i") {
+ n->set_basic_type(Variant::RECT2I);
+ } else if (property_path[0] == "Transform2D") {
+ n->set_basic_type(Variant::TRANSFORM2D);
+ } else if (property_path[0] == "Vector3") {
+ n->set_basic_type(Variant::VECTOR3);
+ } else if (property_path[0] == "Vector3i") {
+ n->set_basic_type(Variant::VECTOR3I);
+ } else if (property_path[0] == "Plane") {
+ n->set_basic_type(Variant::PLANE);
+ } else if (property_path[0] == "ABB") {
+ n->set_basic_type(Variant::AABB);
+ } else if (property_path[0] == "Quaternion") {
+ n->set_basic_type(Variant::QUATERNION);
+ } else if (property_path[0] == "Basis") {
+ n->set_basic_type(Variant::BASIS);
+ } else if (property_path[0] == "Transform3D") {
+ n->set_basic_type(Variant::TRANSFORM3D);
+ } else if (property_path[0] == "Color") {
+ n->set_basic_type(Variant::COLOR);
+ } else if (property_path[0] == "RID") {
+ n->set_basic_type(Variant::RID);
+ } else if (property_path[0] == "Object") {
+ n->set_basic_type(Variant::OBJECT);
+ } else if (property_path[0] == "Callable") {
+ n->set_basic_type(Variant::CALLABLE);
+ } else if (property_path[0] == "Signal") {
+ n->set_basic_type(Variant::SIGNAL);
+ } else if (property_path[0] == "StringName") {
+ n->set_basic_type(Variant::STRING_NAME);
+ } else if (property_path[0] == "NodePath") {
+ n->set_basic_type(Variant::NODE_PATH);
+ } else if (property_path[0] == "Dictionary") {
+ n->set_basic_type(Variant::DICTIONARY);
+ } else if (property_path[0] == "Array") {
+ n->set_basic_type(Variant::ARRAY);
+ } else if (property_path[0] == "PackedByteArray") {
+ n->set_basic_type(Variant::PACKED_BYTE_ARRAY);
+ } else if (property_path[0] == "PackedInt32Array") {
+ n->set_basic_type(Variant::PACKED_INT32_ARRAY);
+ } else if (property_path[0] == "PackedInt64Array") {
+ n->set_basic_type(Variant::PACKED_INT64_ARRAY);
+ } else if (property_path[0] == "PackedFloat32Array") {
+ n->set_basic_type(Variant::PACKED_FLOAT32_ARRAY);
+ } else if (property_path[0] == "PackedStringArray") {
+ n->set_basic_type(Variant::PACKED_STRING_ARRAY);
+ } else if (property_path[0] == "PackedVector2Array") {
+ n->set_basic_type(Variant::PACKED_VECTOR2_ARRAY);
+ } else if (property_path[0] == "PackedVector3Array") {
+ n->set_basic_type(Variant::PACKED_VECTOR3_ARRAY);
+ } else if (property_path[0] == "PackedColorArray") {
+ n->set_basic_type(Variant::PACKED_COLOR_ARRAY);
+ }
+ n->set_basic_type_constant(property_path[1]);
vnode = n;
}
- }
- int new_id = script->get_available_id();
- undo_redo->create_action(TTR("Add Node"));
- undo_redo->add_do_method(script.ptr(), "add_node", new_id, vnode, ofs);
- undo_redo->add_undo_method(script.ptr(), "remove_node", new_id);
- undo_redo->add_do_method(this, "_update_graph", new_id);
- undo_redo->add_undo_method(this, "_update_graph", new_id);
- undo_redo->commit_action();
+ } else if (p_category == String("class_signal")) {
+ Vector<String> property_path = p_text.split(":");
+ ERR_FAIL_COND(!(script->has_custom_signal(property_path[1]) || ClassDB::has_signal(script->get_instance_base_type(), property_path[1])));
- if (script_prop_set.is_valid()) {
- script_prop_set->set_property(p_text);
+ Ref<VisualScriptEmitSignal> n;
+ n.instantiate();
+ n->set_signal(property_path[1]);
+ vnode = n;
+ }
+ if (vnode == nullptr) {
+ print_error("Category not handled: " + p_category.quote());
}
- port_action_new_node = new_id;
-
- Ref<VisualScriptNode> vsn = script->get_node(port_action_new_node);
+ if (Object::cast_to<VisualScriptFunctionCall>(vnode.ptr()) && p_category != "Class" && p_category != "VisualScriptNode") {
+ Vector<String> property_path = p_text.split(":");
+ String class_of_method = property_path[0];
+ String method_name = property_path[1];
- if (Object::cast_to<VisualScriptFunctionCall>(vsn.ptr())) {
- Ref<VisualScriptFunctionCall> vsfc = vsn;
- vsfc->set_function(p_text);
+ Ref<VisualScriptFunctionCall> vsfc = vnode;
+ vsfc->set_function(method_name);
if (port_node_exists && p_connecting) {
VisualScriptNode::TypeGuess tg = _guess_output_type(port_action_node, port_action_output, vn);
@@ -3315,10 +3603,10 @@ void VisualScriptEditor::_selected_connect_node(const String &p_text, const Stri
PropertyHint hint = script->get_node(port_action_node)->get_output_value_port_info(port_action_output).hint;
String base_type = script->get_node(port_action_node)->get_output_value_port_info(port_action_output).hint_string;
- if (base_type != String() && hint == PROPERTY_HINT_TYPE_STRING) {
+ if (!base_type.is_empty() && hint == PROPERTY_HINT_TYPE_STRING) {
vsfc->set_base_type(base_type);
}
- if (p_text == "call" || p_text == "call_deferred") {
+ if (method_name == "call" || method_name == "call_deferred") {
vsfc->set_function(String(""));
}
}
@@ -3336,8 +3624,8 @@ void VisualScriptEditor::_selected_connect_node(const String &p_text, const Stri
}
if (port_node_exists && p_connecting) {
- if (Object::cast_to<VisualScriptPropertySet>(vsn.ptr())) {
- Ref<VisualScriptPropertySet> vsp = vsn;
+ if (Object::cast_to<VisualScriptPropertySet>(vnode.ptr())) {
+ Ref<VisualScriptPropertySet> vsp = vnode;
VisualScriptNode::TypeGuess tg = _guess_output_type(port_action_node, port_action_output, vn);
if (tg.type == Variant::OBJECT) {
@@ -3350,7 +3638,7 @@ void VisualScriptEditor::_selected_connect_node(const String &p_text, const Stri
PropertyHint hint = script->get_node(port_action_node)->get_output_value_port_info(port_action_output).hint;
String base_type = script->get_node(port_action_node)->get_output_value_port_info(port_action_output).hint_string;
- if (base_type != String() && hint == PROPERTY_HINT_TYPE_STRING) {
+ if (!base_type.is_empty() && hint == PROPERTY_HINT_TYPE_STRING) {
vsp->set_base_type(base_type);
}
}
@@ -3366,8 +3654,8 @@ void VisualScriptEditor::_selected_connect_node(const String &p_text, const Stri
}
}
- if (Object::cast_to<VisualScriptPropertyGet>(vsn.ptr())) {
- Ref<VisualScriptPropertyGet> vsp = vsn;
+ if (Object::cast_to<VisualScriptPropertyGet>(vnode.ptr())) {
+ Ref<VisualScriptPropertyGet> vsp = vnode;
VisualScriptNode::TypeGuess tg = _guess_output_type(port_action_node, port_action_output, vn);
if (tg.type == Variant::OBJECT) {
@@ -3379,7 +3667,7 @@ void VisualScriptEditor::_selected_connect_node(const String &p_text, const Stri
} else if (script->get_node(port_action_node).is_valid()) {
PropertyHint hint = script->get_node(port_action_node)->get_output_value_port_info(port_action_output).hint;
String base_type = script->get_node(port_action_node)->get_output_value_port_info(port_action_output).hint_string;
- if (base_type != String() && hint == PROPERTY_HINT_TYPE_STRING) {
+ if (!base_type.is_empty() && hint == PROPERTY_HINT_TYPE_STRING) {
vsp->set_base_type(base_type);
}
}
@@ -3395,13 +3683,90 @@ void VisualScriptEditor::_selected_connect_node(const String &p_text, const Stri
}
}
}
+ if (vnode == nullptr) {
+ print_error("Not able to create node from category: \"" + p_category + "\" and text \"" + p_text + "\" Not created");
+ return;
+ }
+
+ int new_id = script->get_available_id();
+ undo_redo->create_action(TTR("Add Node"));
+ undo_redo->add_do_method(script.ptr(), "add_node", new_id, vnode, pos);
+ undo_redo->add_undo_method(script.ptr(), "remove_node", new_id);
+ undo_redo->add_do_method(this, "_update_graph", new_id);
+ undo_redo->add_undo_method(this, "_update_graph", new_id);
+ undo_redo->commit_action();
+
+ port_action_new_node = new_id;
+
+ String base_script = "";
+ String base_type = "";
if (port_node_exists) {
- Ref<VisualScriptNode> vnode_old = script->get_node(port_action_node);
+ if (vnode_old.is_valid()) {
+ if (Object::cast_to<VisualScriptTypeCast>(vnode_old.ptr())) {
+ base_type = Object::cast_to<VisualScriptTypeCast>(vnode_old.ptr())->get_base_type();
+ base_script = Object::cast_to<VisualScriptTypeCast>(vnode_old.ptr())->get_base_script();
+ } else if (Object::cast_to<VisualScriptFunctionCall>(vnode_old.ptr())) {
+ base_type = Object::cast_to<VisualScriptFunctionCall>(vnode_old.ptr())->get_base_type();
+ base_script = Object::cast_to<VisualScriptFunctionCall>(vnode_old.ptr())->get_base_script();
+ } else if (Object::cast_to<VisualScriptPropertySet>(vnode_old.ptr())) {
+ base_type = Object::cast_to<VisualScriptPropertySet>(vnode_old.ptr())->get_base_type();
+ base_script = Object::cast_to<VisualScriptPropertySet>(vnode_old.ptr())->get_base_script();
+ } else if (Object::cast_to<VisualScriptPropertyGet>(vnode_old.ptr())) {
+ base_type = Object::cast_to<VisualScriptPropertyGet>(vnode_old.ptr())->get_base_type();
+ base_script = Object::cast_to<VisualScriptPropertyGet>(vnode_old.ptr())->get_base_script();
+ }
+ }
+
+ Vector<String> property_path = p_text.split(":");
+ if (ClassDB::is_parent_class(script->get_instance_base_type(), property_path[0]) || script->get_path().ends_with(property_path[0].unquote())) {
+ if (!p_connecting) {
+ base_type = script->get_instance_base_type();
+ base_script = script->get_path();
+ }
+ } else {
+ base_type = property_path[0];
+ base_script = "";
+ }
+
+ if (drop_node) {
+ Ref<Script> script = drop_node->get_script();
+ if (script != nullptr) {
+ base_script = script->get_path();
+ }
+ }
+
if (vnode_old.is_valid() && p_connecting) {
+ if (base_type == "") {
+ base_type = property_path[0];
+ } else if (ClassDB::is_parent_class(property_path[0], base_type)) {
+ base_type = property_path[0];
+ }
connect_seq(vnode_old, vnode, port_action_new_node);
connect_data(vnode_old, vnode, port_action_new_node);
}
}
+ if (Object::cast_to<VisualScriptTypeCast>(vnode.ptr())) {
+ Object::cast_to<VisualScriptTypeCast>(vnode.ptr())->set_base_type(base_type);
+ Object::cast_to<VisualScriptTypeCast>(vnode.ptr())->set_base_script(base_script);
+ } else if (Object::cast_to<VisualScriptFunctionCall>(vnode.ptr())) {
+ if (base_type_map.has(base_type)) {
+ Object::cast_to<VisualScriptFunctionCall>(vnode.ptr())->set_basic_type(base_type_map[base_type]);
+ Object::cast_to<VisualScriptFunctionCall>(vnode.ptr())->set_call_mode(VisualScriptFunctionCall::CALL_MODE_BASIC_TYPE);
+ } else {
+ Object::cast_to<VisualScriptFunctionCall>(vnode.ptr())->set_base_type(base_type);
+ Object::cast_to<VisualScriptFunctionCall>(vnode.ptr())->set_base_script(base_script);
+ }
+ } else if (Object::cast_to<VisualScriptPropertySet>(vnode.ptr())) {
+ Object::cast_to<VisualScriptPropertySet>(vnode.ptr())->set_base_type(base_type);
+ Object::cast_to<VisualScriptPropertySet>(vnode.ptr())->set_base_script(base_script);
+ } else if (Object::cast_to<VisualScriptPropertyGet>(vnode.ptr())) {
+ Object::cast_to<VisualScriptPropertyGet>(vnode.ptr())->set_base_type(base_type);
+ Object::cast_to<VisualScriptPropertyGet>(vnode.ptr())->set_base_script(base_script);
+ }
+
+ drop_path = String();
+ drop_node = nullptr;
+
_update_graph(port_action_new_node);
}
@@ -3429,7 +3794,7 @@ void VisualScriptEditor::connect_seq(Ref<VisualScriptNode> vnode_old, Ref<Visual
undo_redo->add_do_method(script.ptr(), "sequence_connect", port_action_node, pass_port, new_id);
undo_redo->add_undo_method(script.ptr(), "sequence_disconnect", port_action_node, pass_port, new_id);
} else if (vnode_old->get_output_value_port_info(port_action_output).name == String("return") &&
- !script->get_output_sequence_ports_connected(port_action_node).has(return_port)) {
+ !script->get_output_sequence_ports_connected(port_action_node).has(return_port)) {
undo_redo->add_do_method(script.ptr(), "sequence_connect", port_action_node, return_port, new_id);
undo_redo->add_undo_method(script.ptr(), "sequence_disconnect", port_action_node, return_port, new_id);
} else {
@@ -3451,7 +3816,7 @@ void VisualScriptEditor::connect_seq(Ref<VisualScriptNode> vnode_old, Ref<Visual
}
void VisualScriptEditor::_selected_new_virtual_method(const String &p_text, const String &p_category, const bool p_connecting) {
- String name = p_text;
+ String name = p_text.substr(p_text.find_char(':') + 1);
if (script->has_function(name)) {
EditorNode::get_singleton()->show_warning(vformat(TTR("Script already has function '%s'"), name));
return;
@@ -3462,9 +3827,9 @@ void VisualScriptEditor::_selected_new_virtual_method(const String &p_text, cons
List<MethodInfo> methods;
bool found = false;
ClassDB::get_virtual_methods(script->get_instance_base_type(), &methods);
- for (List<MethodInfo>::Element *E = methods.front(); E; E = E->next()) {
- if (E->get().name == name) {
- minfo = E->get();
+ for (const MethodInfo &E : methods) {
+ if (E.name == name) {
+ minfo = E;
found = true;
}
}
@@ -3474,7 +3839,7 @@ void VisualScriptEditor::_selected_new_virtual_method(const String &p_text, cons
selected = name;
Ref<VisualScriptFunction> func_node;
- func_node.instance();
+ func_node.instantiate();
func_node->set_name(name);
int fn_id = script->get_available_id();
undo_redo->create_action(TTR("Add Function"));
@@ -3484,18 +3849,18 @@ void VisualScriptEditor::_selected_new_virtual_method(const String &p_text, cons
func_node->add_argument(minfo.arguments[i].type, minfo.arguments[i].name, -1, minfo.arguments[i].hint, minfo.arguments[i].hint_string);
}
- Vector2 ofs = _get_available_pos();
+ Vector2 pos = _get_available_pos();
- undo_redo->add_do_method(script.ptr(), "add_node", fn_id, func_node, ofs);
+ undo_redo->add_do_method(script.ptr(), "add_node", fn_id, func_node, pos);
undo_redo->add_undo_method(script.ptr(), "remove_node", fn_id);
if (minfo.return_val.type != Variant::NIL || minfo.return_val.usage & PROPERTY_USAGE_NIL_IS_VARIANT) {
Ref<VisualScriptReturn> ret_node;
- ret_node.instance();
+ ret_node.instantiate();
ret_node->set_return_type(minfo.return_val.type);
ret_node->set_enable_return_value(true);
ret_node->set_name(name);
int nid = script->get_available_id() + 1;
- undo_redo->add_do_method(script.ptr(), "add_node", nid, ret_node, _get_available_pos(false, ofs + Vector2(500, 0)));
+ undo_redo->add_do_method(script.ptr(), "add_node", nid, ret_node, _get_available_pos(false, pos + Vector2(500, 0)));
undo_redo->add_undo_method(script.ptr(), "remove_node", nid);
}
@@ -3557,8 +3922,8 @@ void VisualScriptEditor::_default_value_edited(Node *p_button, int p_id, int p_i
Variant::construct(pinfo.type, existing, &existingp, 1, ce);
}
- default_value_edit->set_position(Object::cast_to<Control>(p_button)->get_global_position() + Vector2(0, Object::cast_to<Control>(p_button)->get_size().y));
- default_value_edit->set_size(Size2(1, 1));
+ default_value_edit->set_position(Object::cast_to<Control>(p_button)->get_screen_position() + Vector2(0, Object::cast_to<Control>(p_button)->get_size().y) * graph->get_zoom());
+ default_value_edit->reset_size();
if (pinfo.type == Variant::NODE_PATH) {
Node *edited_scene = get_tree()->get_edited_scene_root();
@@ -3599,8 +3964,22 @@ void VisualScriptEditor::_hide_timer() {
hint_text->hide();
}
+void VisualScriptEditor::_toggle_scripts_pressed() {
+ ScriptEditor::get_singleton()->toggle_scripts_panel();
+ update_toggle_scripts_button();
+}
+
void VisualScriptEditor::_notification(int p_what) {
switch (p_what) {
+ case NOTIFICATION_ENTER_TREE:
+ case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
+ graph->get_panner()->setup((ViewPanner::ControlScheme)EDITOR_GET("editors/panning/sub_editors_panning_scheme").operator int(), ED_GET_SHORTCUT("canvas_item_editor/pan_view"), bool(EditorSettings::get_singleton()->get("editors/panning/simple_panning")));
+ graph->set_warped_panning(bool(EditorSettings::get_singleton()->get("editors/panning/warped_mouse_panning")));
+ graph->set_minimap_opacity(EditorSettings::get_singleton()->get("editors/visual_editors/minimap_opacity"));
+ graph->set_connection_lines_curvature(EditorSettings::get_singleton()->get("editors/visual_editors/lines_curvature"));
+ _update_graph();
+ } break;
+
case NOTIFICATION_READY: {
variable_editor->connect("changed", callable_mp(this, &VisualScriptEditor::_update_members));
variable_editor->connect("changed", callable_mp(this, &VisualScriptEditor::_update_graph), varray(-1), CONNECT_DEFERRED);
@@ -3613,40 +3992,43 @@ void VisualScriptEditor::_notification(int p_what) {
return;
}
- edit_variable_edit->add_theme_style_override("bg", get_theme_stylebox("bg", "Tree"));
- edit_signal_edit->add_theme_style_override("bg", get_theme_stylebox("bg", "Tree"));
- func_input_scroll->add_theme_style_override("bg", get_theme_stylebox("bg", "Tree"));
+ update_toggle_scripts_button();
+
+ edit_variable_edit->add_theme_style_override("bg", get_theme_stylebox(SNAME("bg"), SNAME("Tree")));
+ edit_signal_edit->add_theme_style_override("bg", get_theme_stylebox(SNAME("bg"), SNAME("Tree")));
+ func_input_scroll->add_theme_style_override("bg", get_theme_stylebox(SNAME("bg"), SNAME("Tree")));
Ref<Theme> tm = EditorNode::get_singleton()->get_theme_base()->get_theme();
bool dark_theme = tm->get_constant("dark_theme", "Editor");
- List<Pair<String, Color>> colors;
if (dark_theme) {
- colors.push_back(Pair<String, Color>("flow_control", Color(0.96, 0.96, 0.96)));
- colors.push_back(Pair<String, Color>("functions", Color(0.96, 0.52, 0.51)));
- colors.push_back(Pair<String, Color>("data", Color(0.5, 0.96, 0.81)));
- colors.push_back(Pair<String, Color>("operators", Color(0.67, 0.59, 0.87)));
- colors.push_back(Pair<String, Color>("custom", Color(0.5, 0.73, 0.96)));
- colors.push_back(Pair<String, Color>("constants", Color(0.96, 0.5, 0.69)));
+ node_colors["flow_control"] = Color(0.96, 0.96, 0.96);
+ node_colors["functions"] = Color(0.96, 0.52, 0.51);
+ node_colors["data"] = Color(0.5, 0.96, 0.81);
+ node_colors["operators"] = Color(0.67, 0.59, 0.87);
+ node_colors["custom"] = Color(0.5, 0.73, 0.96);
+ node_colors["constants"] = Color(0.96, 0.5, 0.69);
} else {
- colors.push_back(Pair<String, Color>("flow_control", Color(0.26, 0.26, 0.26)));
- colors.push_back(Pair<String, Color>("functions", Color(0.95, 0.4, 0.38)));
- colors.push_back(Pair<String, Color>("data", Color(0.07, 0.73, 0.51)));
- colors.push_back(Pair<String, Color>("operators", Color(0.51, 0.4, 0.82)));
- colors.push_back(Pair<String, Color>("custom", Color(0.31, 0.63, 0.95)));
- colors.push_back(Pair<String, Color>("constants", Color(0.94, 0.18, 0.49)));
+ node_colors["flow_control"] = Color(0.26, 0.26, 0.26);
+ node_colors["functions"] = Color(0.95, 0.4, 0.38);
+ node_colors["data"] = Color(0.07, 0.73, 0.51);
+ node_colors["operators"] = Color(0.51, 0.4, 0.82);
+ node_colors["custom"] = Color(0.31, 0.63, 0.95);
+ node_colors["constants"] = Color(0.94, 0.18, 0.49);
}
- for (List<Pair<String, Color>>::Element *E = colors.front(); E; E = E->next()) {
- Ref<StyleBoxFlat> sb = tm->get_stylebox("frame", "GraphNode");
+ for (const KeyValue<StringName, Color> &E : node_colors) {
+ const Ref<StyleBoxFlat> sb = tm->get_stylebox(SNAME("frame"), SNAME("GraphNode"));
+
if (!sb.is_null()) {
Ref<StyleBoxFlat> frame_style = sb->duplicate();
- Color c = sb->get_border_color();
- Color cn = E->get().second;
- cn.a = c.a;
- frame_style->set_border_color(cn);
- node_styles[E->get().first] = frame_style;
+ // Adjust the border color to be close to the GraphNode's background color.
+ // This keeps the node's title area from being too distracting.
+ Color color = dark_theme ? E.value.darkened(0.75) : E.value.lightened(0.75);
+ color.a = 0.9;
+ frame_style->set_border_color(color);
+ node_styles[E.key] = frame_style;
}
}
@@ -3655,7 +4037,9 @@ void VisualScriptEditor::_notification(int p_what) {
_update_graph();
}
} break;
+
case NOTIFICATION_VISIBILITY_CHANGED: {
+ update_toggle_scripts_button();
members_section->set_visible(is_visible_in_tree());
} break;
}
@@ -3705,13 +4089,16 @@ void VisualScriptEditor::_comment_node_resized(const Vector2 &p_new_size, int p_
undo_redo->commit_action();
gn->set_custom_minimum_size(new_size);
- gn->set_size(Size2(1, 1));
+ gn->reset_size();
graph->set_block_minimum_size_adjust(false);
updating_graph = false;
}
void VisualScriptEditor::_menu_option(int p_what) {
switch (p_what) {
+ case EDIT_ADD_NODE: {
+ _generic_search();
+ } break;
case EDIT_DELETE_NODES: {
_on_nodes_delete();
} break;
@@ -3733,134 +4120,32 @@ void VisualScriptEditor::_menu_option(int p_what) {
_update_graph();
- for (List<String>::Element *E = reselect.front(); E; E = E->next()) {
- GraphNode *gn = Object::cast_to<GraphNode>(graph->get_node(E->get()));
+ for (const String &E : reselect) {
+ GraphNode *gn = Object::cast_to<GraphNode>(graph->get_node(E));
gn->set_selected(true);
}
} break;
case EDIT_FIND_NODE_TYPE: {
- _generic_search(script->get_instance_base_type());
+ _generic_search();
+ } break;
+ case EDIT_COPY_NODES: {
+ _on_nodes_copy();
} break;
- case EDIT_COPY_NODES:
case EDIT_CUT_NODES: {
- 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<GraphNode>(graph->get_child(i));
- if (gn) {
- if (gn->is_selected()) {
- int id = gn->get_name().operator String().to_int();
- Ref<VisualScriptNode> node = script->get_node(id);
- if (Object::cast_to<VisualScriptFunction>(*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()) {
- break;
- }
-
- List<VisualScript::SequenceConnection> sequence_connections;
- script->get_sequence_connection_list(&sequence_connections);
-
- for (List<VisualScript::SequenceConnection>::Element *E = sequence_connections.front(); E; E = E->next()) {
- if (clipboard->nodes.has(E->get().from_node) && clipboard->nodes.has(E->get().to_node)) {
- clipboard->sequence_connections.insert(E->get());
- }
- }
-
- List<VisualScript::DataConnection> data_connections;
- script->get_data_connection_list(&data_connections);
-
- for (List<VisualScript::DataConnection>::Element *E = data_connections.front(); E; E = E->next()) {
- if (clipboard->nodes.has(E->get().from_node) && clipboard->nodes.has(E->get().to_node)) {
- clipboard->data_connections.insert(E->get());
- }
- }
- if (p_what == EDIT_CUT_NODES) {
- _on_nodes_delete(); // oh yeah, also delete on cut
- }
-
+ _on_nodes_copy();
+ _on_nodes_delete();
} break;
case EDIT_PASTE_NODES: {
- if (clipboard->nodes.is_empty()) {
- EditorNode::get_singleton()->show_warning(TTR("Clipboard is empty!"));
- break;
- }
-
- Map<int, int> remap;
-
- undo_redo->create_action(TTR("Paste VisualScript Nodes"));
- int idc = script->get_available_id() + 1;
-
- Set<int> to_select;
-
- Set<Vector2> existing_positions;
-
- {
- List<int> nodes;
- script->get_node_list(&nodes);
- for (List<int>::Element *E = nodes.front(); E; E = E->next()) {
- Vector2 pos = script->get_node_position(E->get()).snapped(Vector2(2, 2));
- existing_positions.insert(pos);
- }
- }
-
- for (Map<int, Ref<VisualScriptNode>>::Element *E = clipboard->nodes.front(); E; E = E->next()) {
- Ref<VisualScriptNode> node = E->get()->duplicate();
-
- int new_id = idc++;
- to_select.insert(new_id);
-
- remap[E->key()] = new_id;
-
- Vector2 paste_pos = clipboard->nodes_positions[E->key()];
-
- 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 (Set<VisualScript::SequenceConnection>::Element *E = clipboard->sequence_connections.front(); E; E = E->next()) {
- undo_redo->add_do_method(script.ptr(), "sequence_connect", remap[E->get().from_node], E->get().from_output, remap[E->get().to_node]);
- undo_redo->add_undo_method(script.ptr(), "sequence_disconnect", remap[E->get().from_node], E->get().from_output, remap[E->get().to_node]);
- }
-
- for (Set<VisualScript::DataConnection>::Element *E = clipboard->data_connections.front(); E; E = E->next()) {
- undo_redo->add_do_method(script.ptr(), "data_connect", remap[E->get().from_node], E->get().from_port, remap[E->get().to_node], E->get().to_port);
- undo_redo->add_undo_method(script.ptr(), "data_disconnect", remap[E->get().from_node], E->get().from_port, remap[E->get().to_node], E->get().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<GraphNode>(graph->get_child(i));
- if (gn) {
- int id = gn->get_name().operator String().to_int();
- gn->set_selected(to_select.has(id));
- }
- }
+ _on_nodes_paste();
+ } break;
+ case EDIT_DUPLICATE_NODES: {
+ _on_nodes_duplicate();
} break;
case EDIT_CREATE_FUNCTION: {
// Create Function.
- Map<int, Ref<VisualScriptNode>> nodes;
- Set<int> selections;
+ HashMap<int, Ref<VisualScriptNode>> nodes;
+ RBSet<int> selections;
for (int i = 0; i < graph->get_child_count(); i++) {
GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i));
if (gn) {
@@ -3883,18 +4168,18 @@ void VisualScriptEditor::_menu_option(int p_what) {
return; // nothing to be done if there are no valid nodes selected
}
- Set<VisualScript::SequenceConnection> seqmove;
- Set<VisualScript::DataConnection> datamove;
+ RBSet<VisualScript::SequenceConnection> seqmove;
+ RBSet<VisualScript::DataConnection> datamove;
- Set<VisualScript::SequenceConnection> seqext;
- Set<VisualScript::DataConnection> dataext;
+ RBSet<VisualScript::SequenceConnection> seqext;
+ RBSet<VisualScript::DataConnection> dataext;
int start_node = -1;
- Set<int> end_nodes;
+ RBSet<int> end_nodes;
if (nodes.size() == 1) {
- Ref<VisualScriptNode> nd = script->get_node(nodes.front()->key());
+ Ref<VisualScriptNode> nd = script->get_node(nodes.begin()->key);
if (nd.is_valid() && nd->has_input_sequence_port()) {
- start_node = nodes.front()->key();
+ start_node = nodes.begin()->key;
} else {
EditorNode::get_singleton()->show_warning(TTR("Select at least one node with sequence port."));
return;
@@ -3909,16 +4194,16 @@ void VisualScriptEditor::_menu_option(int p_what) {
// the user wants to connect the nodes.
int top_nd = -1;
Vector2 top;
- for (Map<int, Ref<VisualScriptNode>>::Element *E = nodes.front(); E; E = E->next()) {
- Ref<VisualScriptNode> nd = script->get_node(E->key());
+ for (const KeyValue<int, Ref<VisualScriptNode>> &E : nodes) {
+ Ref<VisualScriptNode> nd = script->get_node(E.key);
if (nd.is_valid() && nd->has_input_sequence_port()) {
if (top_nd < 0) {
- top_nd = E->key();
+ top_nd = E.key;
top = script->get_node_position(top_nd);
}
- Vector2 pos = script->get_node_position(E->key());
+ Vector2 pos = script->get_node_position(E.key);
if (top.y > pos.y) {
- top_nd = E->key();
+ top_nd = E.key;
top = pos;
}
}
@@ -3932,24 +4217,24 @@ void VisualScriptEditor::_menu_option(int p_what) {
}
} else {
// Pick the node with input sequence.
- Set<int> nodes_from;
- Set<int> nodes_to;
- for (List<VisualScript::SequenceConnection>::Element *E = seqs.front(); E; E = E->next()) {
- if (nodes.has(E->get().from_node) && nodes.has(E->get().to_node)) {
- seqmove.insert(E->get());
- nodes_from.insert(E->get().from_node);
- } else if (nodes.has(E->get().from_node) && !nodes.has(E->get().to_node)) {
- seqext.insert(E->get());
- } else if (!nodes.has(E->get().from_node) && nodes.has(E->get().to_node)) {
+ RBSet<int> nodes_from;
+ RBSet<int> nodes_to;
+ for (const VisualScript::SequenceConnection &E : seqs) {
+ if (nodes.has(E.from_node) && nodes.has(E.to_node)) {
+ seqmove.insert(E);
+ nodes_from.insert(E.from_node);
+ } else if (nodes.has(E.from_node) && !nodes.has(E.to_node)) {
+ seqext.insert(E);
+ } else if (!nodes.has(E.from_node) && nodes.has(E.to_node)) {
if (start_node == -1) {
- seqext.insert(E->get());
- start_node = E->get().to_node;
+ seqext.insert(E);
+ start_node = E.to_node;
} else {
EditorNode::get_singleton()->show_warning(TTR("Try to only have one sequence input in selection."));
return;
}
}
- nodes_to.insert(E->get().to_node);
+ nodes_to.insert(E.to_node);
}
// To use to add return nodes.
@@ -3959,9 +4244,9 @@ void VisualScriptEditor::_menu_option(int p_what) {
// If we still don't have a start node then,
// run through the nodes and select the first tree node,
// i.e. node without any input sequence but output sequence.
- for (Set<int>::Element *E = nodes_from.front(); E; E = E->next()) {
- if (!nodes_to.has(E->get())) {
- start_node = E->get();
+ for (const int &E : nodes_from) {
+ if (!nodes_to.has(E)) {
+ start_node = E;
}
}
}
@@ -3977,20 +4262,20 @@ void VisualScriptEditor::_menu_option(int p_what) {
{
List<VisualScript::DataConnection> dats;
script->get_data_connection_list(&dats);
- for (List<VisualScript::DataConnection>::Element *E = dats.front(); E; E = E->next()) {
- if (nodes.has(E->get().from_node) && nodes.has(E->get().to_node)) {
- datamove.insert(E->get());
- } else if (!nodes.has(E->get().from_node) && nodes.has(E->get().to_node)) {
+ for (const VisualScript::DataConnection &E : dats) {
+ if (nodes.has(E.from_node) && nodes.has(E.to_node)) {
+ datamove.insert(E);
+ } else if (!nodes.has(E.from_node) && nodes.has(E.to_node)) {
// Add all these as inputs for the Function.
- Ref<VisualScriptNode> node = script->get_node(E->get().to_node);
+ Ref<VisualScriptNode> node = script->get_node(E.to_node);
if (node.is_valid()) {
- dataext.insert(E->get());
- PropertyInfo pi = node->get_input_value_port_info(E->get().to_port);
+ dataext.insert(E);
+ PropertyInfo pi = node->get_input_value_port_info(E.to_port);
inputs.push_back(pi.type);
- input_connections.push_back(Pair<int, int>(E->get().to_node, E->get().to_port));
+ input_connections.push_back(Pair<int, int>(E.to_node, E.to_port));
}
- } else if (nodes.has(E->get().from_node) && !nodes.has(E->get().to_node)) {
- dataext.insert(E->get());
+ } else if (nodes.has(E.from_node) && !nodes.has(E.to_node)) {
+ dataext.insert(E);
}
}
}
@@ -3998,16 +4283,16 @@ void VisualScriptEditor::_menu_option(int p_what) {
{
String new_fn = _validate_name("new_function");
- Vector2 ofs = _get_available_pos(false, script->get_node_position(start_node) - Vector2(80, 150));
+ Vector2 pos = _get_available_pos(false, script->get_node_position(start_node) - Vector2(80, 150));
Ref<VisualScriptFunction> func_node;
- func_node.instance();
+ func_node.instantiate();
func_node->set_name(new_fn);
undo_redo->create_action(TTR("Create Function"));
undo_redo->add_do_method(script.ptr(), "add_function", new_fn, fn_id);
- undo_redo->add_do_method(script.ptr(), "add_node", fn_id, func_node, ofs);
+ undo_redo->add_do_method(script.ptr(), "add_node", fn_id, func_node, pos);
undo_redo->add_undo_method(script.ptr(), "remove_function", new_fn);
undo_redo->add_undo_method(script.ptr(), "remove_node", fn_id);
undo_redo->add_do_method(this, "_update_members");
@@ -4030,13 +4315,13 @@ void VisualScriptEditor::_menu_option(int p_what) {
// Move the nodes.
// Handles reconnection of sequence connections on undo, start here in case of issues.
- for (Set<VisualScript::SequenceConnection>::Element *E = seqext.front(); E; E = E->next()) {
- undo_redo->add_do_method(script.ptr(), "sequence_disconnect", E->get().from_node, E->get().from_output, E->get().to_node);
- undo_redo->add_undo_method(script.ptr(), "sequence_connect", E->get().from_node, E->get().from_output, E->get().to_node);
+ for (const VisualScript::SequenceConnection &E : seqext) {
+ undo_redo->add_do_method(script.ptr(), "sequence_disconnect", E.from_node, E.from_output, E.to_node);
+ undo_redo->add_undo_method(script.ptr(), "sequence_connect", E.from_node, E.from_output, E.to_node);
}
- for (Set<VisualScript::DataConnection>::Element *E = dataext.front(); E; E = E->next()) {
- undo_redo->add_do_method(script.ptr(), "data_disconnect", E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port);
- undo_redo->add_undo_method(script.ptr(), "data_connect", E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port);
+ for (const VisualScript::DataConnection &E : dataext) {
+ undo_redo->add_do_method(script.ptr(), "data_disconnect", E.from_node, E.from_port, E.to_node, E.to_port);
+ undo_redo->add_undo_method(script.ptr(), "data_connect", E.from_node, E.from_port, E.to_node, E.to_port);
}
// I don't really think we need support for non sequenced functions at this moment.
@@ -4044,24 +4329,24 @@ void VisualScriptEditor::_menu_option(int p_what) {
// Could fail with the new changes, start here when searching for bugs in create function shortcut.
int m = 1;
- for (Set<int>::Element *G = end_nodes.front(); G; G = G->next()) {
+ for (const int &G : end_nodes) {
Ref<VisualScriptReturn> ret_node;
- ret_node.instance();
+ ret_node.instantiate();
int ret_id = fn_id + (m++);
selections.insert(ret_id);
- Vector2 ofsi = _get_available_pos(false, script->get_node_position(G->get()) + Vector2(80, -100));
- undo_redo->add_do_method(script.ptr(), "add_node", ret_id, ret_node, ofsi);
+ Vector2 posi = _get_available_pos(false, script->get_node_position(G) + Vector2(80, -100));
+ undo_redo->add_do_method(script.ptr(), "add_node", ret_id, ret_node, posi);
undo_redo->add_undo_method(script.ptr(), "remove_node", ret_id);
- undo_redo->add_do_method(script.ptr(), "sequence_connect", G->get(), 0, ret_id);
+ undo_redo->add_do_method(script.ptr(), "sequence_connect", G, 0, ret_id);
// Add data outputs from each of the end_nodes.
- Ref<VisualScriptNode> vsn = script->get_node(G->get());
+ Ref<VisualScriptNode> vsn = script->get_node(G);
if (vsn.is_valid() && vsn->get_output_value_port_count() > 0) {
ret_node->set_enable_return_value(true);
// Use the zeroth data port cause that's the likely one that is planned to be used.
ret_node->set_return_type(vsn->get_output_value_port_info(0).type);
- undo_redo->add_do_method(script.ptr(), "data_connect", G->get(), 0, ret_id, 0);
+ undo_redo->add_do_method(script.ptr(), "data_connect", G, 0, ret_id, 0);
}
}
@@ -4084,16 +4369,22 @@ void VisualScriptEditor::_menu_option(int p_what) {
case REFRESH_GRAPH: {
_update_graph();
} break;
+ case EDIT_CLEAR_COPY_BUFFER: {
+ clipboard->nodes.clear();
+ clipboard->nodes_positions.clear();
+ clipboard->data_connections.clear();
+ clipboard->sequence_connections.clear();
+ } break;
}
}
// This is likely going to be very slow and I am not sure if I should keep it,
// but I hope that it will not be a problem considering that we won't be creating functions so frequently,
// and cyclic connections would be a problem but hopefully we won't let them get to this point.
-void VisualScriptEditor::_get_ends(int p_node, const List<VisualScript::SequenceConnection> &p_seqs, const Set<int> &p_selected, Set<int> &r_end_nodes) {
- for (const List<VisualScript::SequenceConnection>::Element *E = p_seqs.front(); E; E = E->next()) {
- int from = E->get().from_node;
- int to = E->get().to_node;
+void VisualScriptEditor::_get_ends(int p_node, const List<VisualScript::SequenceConnection> &p_seqs, const RBSet<int> &p_selected, RBSet<int> &r_end_nodes) {
+ for (const VisualScript::SequenceConnection &E : p_seqs) {
+ int from = E.from_node;
+ int to = E.to_node;
if (from == p_node && p_selected.has(to)) {
// This is an interior connection move forward to the to node.
@@ -4104,49 +4395,53 @@ void VisualScriptEditor::_get_ends(int p_node, const List<VisualScript::Sequence
}
}
-void VisualScriptEditor::_member_rmb_selected(const Vector2 &p_pos) {
+void VisualScriptEditor::_member_rmb_selected(const Vector2 &p_pos, MouseButton p_button) {
+ if (p_button != MouseButton::RIGHT) {
+ return;
+ }
+
TreeItem *ti = members->get_selected();
ERR_FAIL_COND(!ti);
member_popup->clear();
- member_popup->set_position(members->get_global_position() + p_pos);
- member_popup->set_size(Vector2());
+ member_popup->set_position(members->get_screen_position() + p_pos);
+ member_popup->reset_size();
- function_name_edit->set_position(members->get_global_position() + p_pos);
- function_name_edit->set_size(Vector2());
+ function_name_edit->set_position(members->get_screen_position() + p_pos);
+ function_name_edit->reset_size();
TreeItem *root = members->get_root();
- Ref<Texture2D> del_icon = Control::get_theme_icon("Remove", "EditorIcons");
+ Ref<Texture2D> del_icon = Control::get_theme_icon(SNAME("Remove"), SNAME("EditorIcons"));
- Ref<Texture2D> edit_icon = Control::get_theme_icon("Edit", "EditorIcons");
+ Ref<Texture2D> edit_icon = Control::get_theme_icon(SNAME("Edit"), SNAME("EditorIcons"));
- if (ti->get_parent() == root->get_children()) {
+ if (ti->get_parent() == root->get_first_child()) {
member_type = MEMBER_FUNCTION;
member_name = ti->get_text(0);
member_popup->add_icon_shortcut(edit_icon, ED_GET_SHORTCUT("visual_script_editor/edit_member"), MEMBER_EDIT);
member_popup->add_separator();
- member_popup->add_icon_shortcut(del_icon, ED_GET_SHORTCUT("visual_script_editor/delete_selected"), MEMBER_REMOVE);
+ member_popup->add_icon_shortcut(del_icon, ED_GET_SHORTCUT("ui_graph_delete"), MEMBER_REMOVE);
member_popup->popup();
return;
}
- if (ti->get_parent() == root->get_children()->get_next()) {
+ if (ti->get_parent() == root->get_first_child()->get_next()) {
member_type = MEMBER_VARIABLE;
member_name = ti->get_text(0);
member_popup->add_icon_shortcut(edit_icon, ED_GET_SHORTCUT("visual_script_editor/edit_member"), MEMBER_EDIT);
member_popup->add_separator();
- member_popup->add_icon_shortcut(del_icon, ED_GET_SHORTCUT("visual_script_editor/delete_selected"), MEMBER_REMOVE);
+ member_popup->add_icon_shortcut(del_icon, ED_GET_SHORTCUT("ui_graph_delete"), MEMBER_REMOVE);
member_popup->popup();
return;
}
- if (ti->get_parent() == root->get_children()->get_next()->get_next()) {
+ if (ti->get_parent() == root->get_first_child()->get_next()->get_next()) {
member_type = MEMBER_SIGNAL;
member_name = ti->get_text(0);
member_popup->add_icon_shortcut(edit_icon, ED_GET_SHORTCUT("visual_script_editor/edit_member"), MEMBER_EDIT);
member_popup->add_separator();
- member_popup->add_icon_shortcut(del_icon, ED_GET_SHORTCUT("visual_script_editor/delete_selected"), MEMBER_REMOVE);
+ member_popup->add_icon_shortcut(del_icon, ED_GET_SHORTCUT("ui_graph_delete"), MEMBER_REMOVE);
member_popup->popup();
return;
}
@@ -4167,16 +4462,16 @@ void VisualScriptEditor::_member_option(int p_option) {
undo_redo->add_undo_method(script.ptr(), "add_node", fn_node, script->get_node(fn_node), script->get_node_position(fn_node));
List<VisualScript::SequenceConnection> seqcons;
script->get_sequence_connection_list(&seqcons);
- for (const List<VisualScript::SequenceConnection>::Element *E = seqcons.front(); E; E = E->next()) {
- if (E->get().from_node == fn_node) {
- undo_redo->add_undo_method(script.ptr(), "sequence_connect", fn_node, E->get().from_output, E->get().to_node);
+ for (const VisualScript::SequenceConnection &E : seqcons) {
+ if (E.from_node == fn_node) {
+ undo_redo->add_undo_method(script.ptr(), "sequence_connect", fn_node, E.from_output, E.to_node);
}
}
List<VisualScript::DataConnection> datcons;
script->get_data_connection_list(&datcons);
- for (const List<VisualScript::DataConnection>::Element *E = datcons.front(); E; E = E->next()) {
- if (E->get().from_node == fn_node) {
- undo_redo->add_undo_method(script.ptr(), "data_connect", fn_node, E->get().from_port, E->get().to_node, E->get().to_port);
+ for (const VisualScript::DataConnection &E : datcons) {
+ if (E.from_node == fn_node) {
+ undo_redo->add_undo_method(script.ptr(), "data_connect", fn_node, E.from_port, E.to_node, E.to_port);
}
}
undo_redo->add_do_method(this, "_update_members");
@@ -4189,6 +4484,7 @@ void VisualScriptEditor::_member_option(int p_option) {
function_name_edit->popup();
function_name_box->set_text(selected);
function_name_box->select_all();
+ function_name_box->grab_focus();
}
} break;
case MEMBER_VARIABLE: {
@@ -4238,6 +4534,15 @@ void VisualScriptEditor::add_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_h
void VisualScriptEditor::set_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_highlighter) {
}
+void VisualScriptEditor::update_toggle_scripts_button() {
+ if (is_layout_rtl()) {
+ toggle_scripts_button->set_icon(Control::get_theme_icon(ScriptEditor::get_singleton()->is_scripts_panel_toggled() ? SNAME("Forward") : SNAME("Back"), SNAME("EditorIcons")));
+ } else {
+ toggle_scripts_button->set_icon(Control::get_theme_icon(ScriptEditor::get_singleton()->is_scripts_panel_toggled() ? SNAME("Back") : SNAME("Forward"), SNAME("EditorIcons")));
+ }
+ toggle_scripts_button->set_tooltip(vformat("%s (%s)", TTR("Toggle Scripts Panel"), ED_GET_SHORTCUT("script_editor/toggle_scripts_panel")->get_as_text()));
+}
+
void VisualScriptEditor::_bind_methods() {
ClassDB::bind_method("_move_node", &VisualScriptEditor::_move_node);
ClassDB::bind_method("_update_graph", &VisualScriptEditor::_update_graph, DEFVAL(-1));
@@ -4248,27 +4553,20 @@ void VisualScriptEditor::_bind_methods() {
ClassDB::bind_method("_create_new_node_from_name", &VisualScriptEditor::_create_new_node_from_name);
- ClassDB::bind_method("get_drag_data_fw", &VisualScriptEditor::get_drag_data_fw);
- ClassDB::bind_method("can_drop_data_fw", &VisualScriptEditor::can_drop_data_fw);
- ClassDB::bind_method("drop_data_fw", &VisualScriptEditor::drop_data_fw);
-
- ClassDB::bind_method("_input", &VisualScriptEditor::_input);
+ ClassDB::bind_method("_get_drag_data_fw", &VisualScriptEditor::get_drag_data_fw);
+ ClassDB::bind_method("_can_drop_data_fw", &VisualScriptEditor::can_drop_data_fw);
+ ClassDB::bind_method("_drop_data_fw", &VisualScriptEditor::drop_data_fw);
ClassDB::bind_method("_update_graph_connections", &VisualScriptEditor::_update_graph_connections);
ClassDB::bind_method("_update_members", &VisualScriptEditor::_update_members);
ClassDB::bind_method("_generic_search", &VisualScriptEditor::_generic_search);
-
- ClassDB::bind_method(D_METHOD("add_syntax_highlighter", "highlighter"), &VisualScriptEditor::add_syntax_highlighter);
}
VisualScriptEditor::VisualScriptEditor() {
if (!clipboard) {
clipboard = memnew(Clipboard);
}
- updating_graph = false;
- saved_pos_dirty = false;
- saved_position = Vector2(0, 0);
edit_menu = memnew(MenuButton);
edit_menu->set_shortcut_context(this);
@@ -4288,7 +4586,7 @@ VisualScriptEditor::VisualScriptEditor() {
members_section = memnew(VBoxContainer);
// Add but wait until done setting up this.
- ScriptEditor::get_singleton()->get_left_list_split()->call_deferred("add_child", members_section);
+ ScriptEditor::get_singleton()->get_left_list_split()->call_deferred(SNAME("add_child"), members_section);
members_section->set_v_size_flags(SIZE_EXPAND_FILL);
CheckButton *tool_script_check = memnew(CheckButton);
@@ -4302,11 +4600,11 @@ VisualScriptEditor::VisualScriptEditor() {
members_section->add_margin_child(TTR("Members:"), members, true);
members->set_custom_minimum_size(Size2(0, 50 * EDSCALE));
members->set_hide_root(true);
- members->connect("button_pressed", callable_mp(this, &VisualScriptEditor::_member_button));
+ members->connect("button_clicked", callable_mp(this, &VisualScriptEditor::_member_button));
members->connect("item_edited", callable_mp(this, &VisualScriptEditor::_member_edited));
members->connect("cell_selected", callable_mp(this, &VisualScriptEditor::_member_selected), varray(), CONNECT_DEFERRED);
members->connect("gui_input", callable_mp(this, &VisualScriptEditor::_members_gui_input));
- members->connect("item_rmb_selected", callable_mp(this, &VisualScriptEditor::_member_rmb_selected));
+ members->connect("item_mouse_selected", callable_mp(this, &VisualScriptEditor::_member_rmb_selected));
members->set_allow_rmb_select(true);
members->set_allow_reselect(true);
members->set_hide_folding(true);
@@ -4317,10 +4615,12 @@ VisualScriptEditor::VisualScriptEditor() {
member_popup->connect("id_pressed", callable_mp(this, &VisualScriptEditor::_member_option));
function_name_edit = memnew(AcceptDialog);
+ function_name_edit->set_title(TTR("Rename Function"));
function_name_box = memnew(LineEdit);
function_name_edit->add_child(function_name_box);
function_name_box->connect("gui_input", callable_mp(this, &VisualScriptEditor::_fn_name_box_input));
- function_name_box->set_expand_to_text_length(true);
+ function_name_edit->get_ok_button()->connect("pressed", callable_mp(this, &VisualScriptEditor::_on_fn_name_box_confirmed));
+ function_name_box->set_expand_to_text_length_enabled(true);
add_child(function_name_edit);
/// Actual Graph ///
@@ -4329,18 +4629,33 @@ VisualScriptEditor::VisualScriptEditor() {
add_child(graph);
graph->set_v_size_flags(Control::SIZE_EXPAND_FILL);
graph->set_anchors_and_offsets_preset(Control::PRESET_WIDE);
+ graph->set_show_zoom_label(true);
graph->connect("node_selected", callable_mp(this, &VisualScriptEditor::_node_selected));
graph->connect("begin_node_move", callable_mp(this, &VisualScriptEditor::_begin_node_move));
graph->connect("end_node_move", callable_mp(this, &VisualScriptEditor::_end_node_move));
+ graph->connect("copy_nodes_request", callable_mp(this, &VisualScriptEditor::_on_nodes_copy));
+ graph->connect("paste_nodes_request", callable_mp(this, &VisualScriptEditor::_on_nodes_paste));
graph->connect("delete_nodes_request", callable_mp(this, &VisualScriptEditor::_on_nodes_delete));
graph->connect("duplicate_nodes_request", callable_mp(this, &VisualScriptEditor::_on_nodes_duplicate));
graph->connect("gui_input", callable_mp(this, &VisualScriptEditor::_graph_gui_input));
graph->set_drag_forwarding(this);
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);
graph->hide();
graph->connect("scroll_offset_changed", callable_mp(this, &VisualScriptEditor::_graph_ofs_changed));
+ status_bar = memnew(HBoxContainer);
+ add_child(status_bar);
+ status_bar->set_h_size_flags(SIZE_EXPAND_FILL);
+ status_bar->set_custom_minimum_size(Size2(0, 24 * EDSCALE));
+
+ toggle_scripts_button = memnew(Button);
+ toggle_scripts_button->set_flat(true);
+ toggle_scripts_button->connect("pressed", callable_mp(this, &VisualScriptEditor::_toggle_scripts_pressed));
+ status_bar->add_child(toggle_scripts_button);
+
/// Add Buttons to Top Bar/Zoom bar.
HBoxContainer *graph_hbc = graph->get_zoom_hbox();
@@ -4408,8 +4723,8 @@ VisualScriptEditor::VisualScriptEditor() {
select_func_text = memnew(Label);
select_func_text->set_text(TTR("Select or create a function to edit its graph."));
- select_func_text->set_align(Label::ALIGN_CENTER);
- select_func_text->set_valign(Label::VALIGN_CENTER);
+ select_func_text->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
+ select_func_text->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER);
select_func_text->set_h_size_flags(SIZE_EXPAND_FILL);
add_child(select_func_text);
@@ -4417,8 +4732,8 @@ VisualScriptEditor::VisualScriptEditor() {
hint_text->set_anchor_and_offset(SIDE_TOP, ANCHOR_END, -100);
hint_text->set_anchor_and_offset(SIDE_BOTTOM, ANCHOR_END, 0);
hint_text->set_anchor_and_offset(SIDE_RIGHT, ANCHOR_END, 0);
- hint_text->set_align(Label::ALIGN_CENTER);
- hint_text->set_valign(Label::VALIGN_CENTER);
+ hint_text->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
+ hint_text->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER);
graph->add_child(hint_text);
hint_text_timer = memnew(Timer);
@@ -4472,19 +4787,12 @@ VisualScriptEditor::VisualScriptEditor() {
undo_redo = EditorNode::get_singleton()->get_undo_redo();
- updating_members = false;
-
set_process_input(true);
default_value_edit = memnew(CustomPropertyEditor);
add_child(default_value_edit);
default_value_edit->connect("variant_changed", callable_mp(this, &VisualScriptEditor::_default_value_changed));
- method_select = memnew(VisualScriptPropertySelector);
- add_child(method_select);
- method_select->connect("selected", callable_mp(this, &VisualScriptEditor::_selected_method));
- error_line = -1;
-
new_connect_node_select = memnew(VisualScriptPropertySelector);
add_child(new_connect_node_select);
new_connect_node_select->connect("selected", callable_mp(this, &VisualScriptEditor::_selected_connect_node));
@@ -4493,6 +4801,47 @@ VisualScriptEditor::VisualScriptEditor() {
new_virtual_method_select = memnew(VisualScriptPropertySelector);
add_child(new_virtual_method_select);
new_virtual_method_select->connect("selected", callable_mp(this, &VisualScriptEditor::_selected_new_virtual_method));
+
+ popup_menu = memnew(PopupMenu);
+ add_child(popup_menu);
+ popup_menu->add_item(TTR("Add Node"), EDIT_ADD_NODE);
+ popup_menu->add_separator();
+ popup_menu->add_item(TTR("Cut"), EDIT_CUT_NODES);
+ popup_menu->add_item(TTR("Copy"), EDIT_COPY_NODES);
+ popup_menu->add_item(TTR("Paste"), EDIT_PASTE_NODES);
+ popup_menu->add_item(TTR("Delete"), EDIT_DELETE_NODES);
+ popup_menu->add_item(TTR("Duplicate"), EDIT_DUPLICATE_NODES);
+ popup_menu->add_item(TTR("Clear Copy Buffer"), EDIT_CLEAR_COPY_BUFFER);
+ popup_menu->connect("id_pressed", callable_mp(this, &VisualScriptEditor::_menu_option));
+
+ base_type_map.insert("String", Variant::STRING);
+ base_type_map.insert("Vector2", Variant::VECTOR2);
+ base_type_map.insert("Vector2i", Variant::VECTOR2I);
+ base_type_map.insert("Rect2", Variant::RECT2);
+ base_type_map.insert("Rect2i", Variant::RECT2I);
+ base_type_map.insert("Vector3", Variant::VECTOR3);
+ base_type_map.insert("Vector3i", Variant::VECTOR3I);
+ base_type_map.insert("Transform2D", Variant::TRANSFORM2D);
+ base_type_map.insert("Plane", Variant::PLANE);
+ base_type_map.insert("Quaternion", Variant::QUATERNION);
+ base_type_map.insert("AABB", Variant::AABB);
+ base_type_map.insert("Basis", Variant::BASIS);
+ base_type_map.insert("Transform3D", Variant::TRANSFORM3D);
+ base_type_map.insert("Color", Variant::COLOR);
+ base_type_map.insert("NodePath", Variant::NODE_PATH);
+ base_type_map.insert("RID", Variant::RID);
+ base_type_map.insert("Callable", Variant::CALLABLE);
+ base_type_map.insert("Dictionary", Variant::DICTIONARY);
+ base_type_map.insert("Array", Variant::ARRAY);
+ base_type_map.insert("PackedByteArray", Variant::PACKED_BYTE_ARRAY);
+ base_type_map.insert("PackedInt32Array", Variant::PACKED_INT32_ARRAY);
+ base_type_map.insert("PackedFloat32Array", Variant::PACKED_FLOAT32_ARRAY);
+ base_type_map.insert("PackedInt64Array", Variant::PACKED_INT64_ARRAY);
+ base_type_map.insert("PackedFloat64Array", Variant::PACKED_FLOAT64_ARRAY);
+ base_type_map.insert("PackedStringArray", Variant::PACKED_STRING_ARRAY);
+ base_type_map.insert("PackedVector2Array", Variant::PACKED_VECTOR2_ARRAY);
+ base_type_map.insert("PackedVector3Array", Variant::PACKED_VECTOR3_ARRAY);
+ base_type_map.insert("PackedColorArray", Variant::PACKED_COLOR_ARRAY);
}
VisualScriptEditor::~VisualScriptEditor() {
@@ -4501,7 +4850,7 @@ VisualScriptEditor::~VisualScriptEditor() {
memdelete(variable_editor);
}
-static ScriptEditorBase *create_editor(const RES &p_resource) {
+static ScriptEditorBase *create_editor(const Ref<Resource> &p_resource) {
if (Object::cast_to<VisualScript>(*p_resource)) {
return memnew(VisualScriptEditor);
}
@@ -4520,11 +4869,11 @@ void VisualScriptEditor::free_clipboard() {
static void register_editor_callback() {
ScriptEditor::register_create_script_editor_function(create_editor);
- ED_SHORTCUT("visual_script_editor/toggle_breakpoint", TTR("Toggle Breakpoint"), KEY_F9);
- ED_SHORTCUT("visual_script_editor/find_node_type", TTR("Find Node Type"), KEY_MASK_CMD + KEY_F);
- ED_SHORTCUT("visual_script_editor/create_function", TTR("Make Function"), KEY_MASK_CMD + KEY_G);
- ED_SHORTCUT("visual_script_editor/refresh_nodes", TTR("Refresh Graph"), KEY_MASK_CMD + KEY_R);
- ED_SHORTCUT("visual_script_editor/edit_member", TTR("Edit Member"), KEY_MASK_CMD + KEY_E);
+ ED_SHORTCUT("visual_script_editor/toggle_breakpoint", TTR("Toggle Breakpoint"), Key::F9);
+ ED_SHORTCUT("visual_script_editor/find_node_type", TTR("Find Node Type"), KeyModifierMask::CMD + Key::F);
+ ED_SHORTCUT("visual_script_editor/create_function", TTR("Make Function"), KeyModifierMask::CMD + Key::G);
+ ED_SHORTCUT("visual_script_editor/refresh_nodes", TTR("Refresh Graph"), KeyModifierMask::CMD + Key::R);
+ ED_SHORTCUT("visual_script_editor/edit_member", TTR("Edit Member"), KeyModifierMask::CMD + Key::E);
}
void VisualScriptEditor::register_editor() {
@@ -4532,44 +4881,47 @@ void VisualScriptEditor::register_editor() {
EditorNode::add_plugin_init_callback(register_editor_callback);
}
-Ref<VisualScriptNode> _VisualScriptEditor::create_node_custom(const String &p_name) {
+void VisualScriptEditor::validate() {
+}
+
+// VisualScriptCustomNodes
+
+Ref<VisualScriptNode> VisualScriptCustomNodes::create_node_custom(const String &p_name) {
Ref<VisualScriptCustomNode> node;
- node.instance();
+ node.instantiate();
node->set_script(singleton->custom_nodes[p_name]);
return node;
}
-_VisualScriptEditor *_VisualScriptEditor::singleton = nullptr;
-Map<String, REF> _VisualScriptEditor::custom_nodes;
+VisualScriptCustomNodes *VisualScriptCustomNodes::singleton = nullptr;
+HashMap<String, Ref<RefCounted>> VisualScriptCustomNodes::custom_nodes;
-_VisualScriptEditor::_VisualScriptEditor() {
+VisualScriptCustomNodes::VisualScriptCustomNodes() {
singleton = this;
}
-_VisualScriptEditor::~_VisualScriptEditor() {
+VisualScriptCustomNodes::~VisualScriptCustomNodes() {
custom_nodes.clear();
}
-void _VisualScriptEditor::add_custom_node(const String &p_name, const String &p_category, const Ref<Script> &p_script) {
+void VisualScriptCustomNodes::add_custom_node(const String &p_name, const String &p_category, const Ref<Script> &p_script) {
String node_name = "custom/" + p_category + "/" + p_name;
custom_nodes.insert(node_name, p_script);
- VisualScriptLanguage::singleton->add_register_func(node_name, &_VisualScriptEditor::create_node_custom);
- emit_signal("custom_nodes_updated");
+ VisualScriptLanguage::singleton->add_register_func(node_name, &VisualScriptCustomNodes::create_node_custom);
+ emit_signal(SNAME("custom_nodes_updated"));
}
-void _VisualScriptEditor::remove_custom_node(const String &p_name, const String &p_category) {
+void VisualScriptCustomNodes::remove_custom_node(const String &p_name, const String &p_category) {
String node_name = "custom/" + p_category + "/" + p_name;
custom_nodes.erase(node_name);
VisualScriptLanguage::singleton->remove_register_func(node_name);
- emit_signal("custom_nodes_updated");
+ emit_signal(SNAME("custom_nodes_updated"));
}
-void _VisualScriptEditor::_bind_methods() {
- ClassDB::bind_method(D_METHOD("add_custom_node", "name", "category", "script"), &_VisualScriptEditor::add_custom_node);
- ClassDB::bind_method(D_METHOD("remove_custom_node", "name", "category"), &_VisualScriptEditor::remove_custom_node);
+void VisualScriptCustomNodes::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("add_custom_node", "name", "category", "script"), &VisualScriptCustomNodes::add_custom_node);
+ ClassDB::bind_method(D_METHOD("remove_custom_node", "name", "category"), &VisualScriptCustomNodes::remove_custom_node);
ADD_SIGNAL(MethodInfo("custom_nodes_updated"));
}
-void VisualScriptEditor::validate() {
-}
#endif
diff --git a/modules/visual_script/visual_script_editor.h b/modules/visual_script/editor/visual_script_editor.h
index bb6f194286..fd59d22cbe 100644
--- a/modules/visual_script/visual_script_editor.h
+++ b/modules/visual_script/editor/visual_script_editor.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -31,11 +31,11 @@
#ifndef VISUALSCRIPT_EDITOR_H
#define VISUALSCRIPT_EDITOR_H
+#include "../visual_script.h"
#include "editor/create_dialog.h"
#include "editor/plugins/script_editor_plugin.h"
#include "editor/property_editor.h"
#include "scene/gui/graph_edit.h"
-#include "visual_script.h"
#include "visual_script_property_selector.h"
class VisualScriptEditorSignalEdit;
@@ -43,24 +43,30 @@ class VisualScriptEditorVariableEdit;
#ifdef TOOLS_ENABLED
+// TODO: Maybe this class should be refactored.
+// See https://github.com/godotengine/godot/issues/51913
class VisualScriptEditor : public ScriptEditorBase {
GDCLASS(VisualScriptEditor, ScriptEditorBase);
enum {
TYPE_SEQUENCE = 1000,
INDEX_BASE_SEQUENCE = 1024
-
};
enum {
- EDIT_DELETE_NODES,
- EDIT_TOGGLE_BREAKPOINT,
- EDIT_FIND_NODE_TYPE,
- EDIT_COPY_NODES,
+ EDIT_ADD_NODE,
+ EDIT_SEPARATOR, // popup menu separator - ignored
EDIT_CUT_NODES,
+ EDIT_COPY_NODES,
EDIT_PASTE_NODES,
+ EDIT_DELETE_NODES,
+ EDIT_DUPLICATE_NODES,
+ EDIT_CLEAR_COPY_BUFFER,
+
EDIT_CREATE_FUNCTION,
- REFRESH_GRAPH
+ EDIT_TOGGLE_BREAKPOINT,
+ EDIT_FIND_NODE_TYPE,
+ REFRESH_GRAPH,
};
enum PortAction {
@@ -71,7 +77,6 @@ class VisualScriptEditor : public ScriptEditorBase {
enum MemberAction {
MEMBER_EDIT,
MEMBER_REMOVE
-
};
enum MemberType {
@@ -80,53 +85,55 @@ class VisualScriptEditor : public ScriptEditorBase {
MEMBER_SIGNAL
};
- VBoxContainer *members_section;
- MenuButton *edit_menu;
+ VBoxContainer *members_section = nullptr;
+ MenuButton *edit_menu = nullptr;
Ref<VisualScript> script;
- Button *base_type_select;
+ Button *base_type_select = nullptr;
- LineEdit *func_name_box;
- ScrollContainer *func_input_scroll;
- VBoxContainer *func_input_vbox;
- ConfirmationDialog *function_create_dialog;
+ LineEdit *func_name_box = nullptr;
+ ScrollContainer *func_input_scroll = nullptr;
+ VBoxContainer *func_input_vbox = nullptr;
+ ConfirmationDialog *function_create_dialog = nullptr;
- GraphEdit *graph;
+ GraphEdit *graph = nullptr;
+ HBoxContainer *status_bar = nullptr;
+ Button *toggle_scripts_button = nullptr;
- VisualScriptEditorSignalEdit *signal_editor;
+ VisualScriptEditorSignalEdit *signal_editor = nullptr;
- AcceptDialog *edit_signal_dialog;
- EditorInspector *edit_signal_edit;
+ AcceptDialog *edit_signal_dialog = nullptr;
+ EditorInspector *edit_signal_edit = nullptr;
- VisualScriptPropertySelector *method_select;
- VisualScriptPropertySelector *new_connect_node_select;
- VisualScriptPropertySelector *new_virtual_method_select;
+ VisualScriptPropertySelector *method_select = nullptr;
+ VisualScriptPropertySelector *new_connect_node_select = nullptr;
+ VisualScriptPropertySelector *new_virtual_method_select = nullptr;
- VisualScriptEditorVariableEdit *variable_editor;
+ VisualScriptEditorVariableEdit *variable_editor = nullptr;
- AcceptDialog *edit_variable_dialog;
- EditorInspector *edit_variable_edit;
+ AcceptDialog *edit_variable_dialog = nullptr;
+ EditorInspector *edit_variable_edit = nullptr;
- CustomPropertyEditor *default_value_edit;
+ CustomPropertyEditor *default_value_edit = nullptr;
- UndoRedo *undo_redo;
+ UndoRedo *undo_redo = nullptr;
- Tree *members;
- AcceptDialog *function_name_edit;
- LineEdit *function_name_box;
+ Tree *members = nullptr;
+ AcceptDialog *function_name_edit = nullptr;
+ LineEdit *function_name_box = nullptr;
- Label *hint_text;
- Timer *hint_text_timer;
+ Label *hint_text = nullptr;
+ Timer *hint_text_timer = nullptr;
- Label *select_func_text;
+ Label *select_func_text = nullptr;
- bool updating_graph;
+ bool updating_graph = false;
void _show_hint(const String &p_hint);
void _hide_timer();
- CreateDialog *select_base_type;
+ CreateDialog *select_base_type = nullptr;
struct VirtualInMenu {
String name;
@@ -135,12 +142,14 @@ class VisualScriptEditor : public ScriptEditorBase {
Vector<Pair<Variant::Type, String>> args;
};
+ HashMap<StringName, Color> node_colors;
HashMap<StringName, Ref<StyleBox>> node_styles;
+ HashMap<StringName, Variant::Type> base_type_map;
void _update_graph_connections();
void _update_graph(int p_only_id = -1);
- bool updating_members;
+ bool updating_members = false;
void _update_members();
String _sanitized_variant_text(const StringName &property_name);
@@ -150,27 +159,27 @@ class VisualScriptEditor : public ScriptEditorBase {
String _validate_name(const String &p_name) const;
struct Clipboard {
- Map<int, Ref<VisualScriptNode>> nodes;
- Map<int, Vector2> nodes_positions;
+ HashMap<int, Ref<VisualScriptNode>> nodes;
+ HashMap<int, Vector2> nodes_positions;
- Set<VisualScript::SequenceConnection> sequence_connections;
- Set<VisualScript::DataConnection> data_connections;
+ RBSet<VisualScript::SequenceConnection> sequence_connections;
+ RBSet<VisualScript::DataConnection> data_connections;
};
static Clipboard *clipboard;
- PopupMenu *member_popup;
+ PopupMenu *popup_menu = nullptr;
+ PopupMenu *member_popup = nullptr;
MemberType member_type;
String member_name;
PortAction port_action;
- int port_action_node;
- int port_action_output;
+ int port_action_node = 0;
+ int port_action_output = 0;
Vector2 port_action_pos;
- int port_action_new_node;
+ int port_action_new_node = 0;
- bool saved_pos_dirty;
- Vector2 saved_position;
+ bool saved_pos_dirty = false;
Vector2 mouse_up_position;
@@ -178,6 +187,9 @@ class VisualScriptEditor : public ScriptEditorBase {
void connect_data(Ref<VisualScriptNode> vnode_old, Ref<VisualScriptNode> vnode, int new_id);
+ NodePath drop_path;
+ Node *drop_node = nullptr;
+ Vector2 drop_position;
void _selected_connect_node(const String &p_text, const String &p_category, const bool p_connecting = true);
void connect_seq(Ref<VisualScriptNode> vnode_old, Ref<VisualScriptNode> vnode_new, int new_id);
@@ -185,7 +197,7 @@ class VisualScriptEditor : public ScriptEditorBase {
int _create_new_node_from_name(const String &p_text, const Vector2 &p_point);
void _selected_new_virtual_method(const String &p_text, const String &p_category, const bool p_connecting);
- int error_line;
+ int error_line = -1;
void _node_selected(Node *p_node);
void _center_on_node(int p_id);
@@ -201,7 +213,7 @@ class VisualScriptEditor : public ScriptEditorBase {
void _end_node_move();
void _move_node(int p_id, const Vector2 &p_to);
- void _get_ends(int p_node, const List<VisualScript::SequenceConnection> &p_seqs, const Set<int> &p_selected, Set<int> &r_end_nodes);
+ void _get_ends(int p_node, const List<VisualScript::SequenceConnection> &p_seqs, const RBSet<int> &p_selected, RBSet<int> &r_end_nodes);
void _node_moved(Vector2 p_from, Vector2 p_to, int p_id);
void _remove_node(int p_id);
@@ -214,7 +226,7 @@ class VisualScriptEditor : public ScriptEditorBase {
void _update_available_nodes();
- void _member_button(Object *p_item, int p_column, int p_button);
+ void _member_button(Object *p_item, int p_column, int p_button, MouseButton p_mouse_button);
void _expression_text_changed(const String &p_text, int p_id);
void _add_input_port(int p_id);
@@ -225,16 +237,18 @@ class VisualScriptEditor : public ScriptEditorBase {
void _update_node_size(int p_id);
void _port_name_focus_out(const Node *p_name_box, int p_id, int p_port, bool is_input);
- Vector2 _get_available_pos(bool centered = true, Vector2 ofs = Vector2()) const;
+ Vector2 _get_pos_in_graph(Vector2 p_point) const;
+ Vector2 _get_available_pos(bool p_centered = true, Vector2 p_pos = Vector2()) const;
bool node_has_sequence_connections(int p_id);
- void _generic_search(String p_base_type = "", Vector2 pos = Vector2(), bool node_centered = false);
+ void _generic_search(Vector2 pos = Vector2(), bool node_centered = false);
- void _input(const Ref<InputEvent> &p_event);
+ virtual void input(const Ref<InputEvent> &p_event) override;
void _graph_gui_input(const Ref<InputEvent> &p_event);
void _members_gui_input(const Ref<InputEvent> &p_event);
void _fn_name_box_input(const Ref<InputEvent> &p_event);
+ void _on_fn_name_box_confirmed();
void _rename_function(const String &p_name, const String &p_new_name);
void _create_function_dialog();
@@ -246,6 +260,8 @@ class VisualScriptEditor : public ScriptEditorBase {
void _node_item_selected();
void _node_item_unselected();
+ void _on_nodes_copy();
+ void _on_nodes_paste();
void _on_nodes_delete();
void _on_nodes_duplicate();
@@ -253,12 +269,12 @@ class VisualScriptEditor : public ScriptEditorBase {
bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
- int editing_id;
- int editing_input;
+ int editing_id = 0;
+ int editing_input = 0;
- bool can_swap;
- int data_disconnect_node;
- int data_disconnect_port;
+ bool can_swap = false;
+ int data_disconnect_node = 0;
+ int data_disconnect_port = 0;
void _default_value_changed();
void _default_value_edited(Node *p_button, int p_id, int p_input_port);
@@ -268,17 +284,16 @@ class VisualScriptEditor : public ScriptEditorBase {
void _graph_ofs_changed(const Vector2 &p_ofs);
void _comment_node_resized(const Vector2 &p_new_size, int p_node);
- int selecting_method_id;
- void _selected_method(const String &p_method, const String &p_type, const bool p_connecting);
-
void _draw_color_over_button(Object *obj, Color p_color);
void _button_resource_previewed(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, Variant p_ud);
- VisualScriptNode::TypeGuess _guess_output_type(int p_port_action_node, int p_port_action_output, Set<int> &p_visited_nodes);
+ VisualScriptNode::TypeGuess _guess_output_type(int p_port_action_node, int p_port_action_output, RBSet<int> &p_visited_nodes);
- void _member_rmb_selected(const Vector2 &p_pos);
+ void _member_rmb_selected(const Vector2 &p_pos, MouseButton p_button);
void _member_option(int p_option);
+ void _toggle_scripts_pressed();
+
protected:
void _notification(int p_what);
static void _bind_methods();
@@ -288,8 +303,8 @@ public:
virtual void set_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_highlighter) override;
virtual void apply_code() override;
- virtual RES get_edited_resource() const override;
- virtual void set_edited_resource(const RES &p_res) override;
+ virtual Ref<Resource> get_edited_resource() const override;
+ virtual void set_edited_resource(const Ref<Resource> &p_res) override;
virtual void enable_editor() override;
virtual Vector<String> get_functions() override;
virtual void reload_text() override;
@@ -309,46 +324,54 @@ public:
virtual void tag_saved_version() override;
virtual void reload(bool p_soft) override;
virtual Array get_breakpoints() override;
+ virtual void set_breakpoint(int p_line, bool p_enable) override{};
+ virtual void clear_breakpoints() override{};
virtual void add_callback(const String &p_function, PackedStringArray p_args) override;
virtual void update_settings() override;
virtual bool show_members_overview() override;
virtual void set_debugger_active(bool p_active) override;
- virtual void set_tooltip_request_func(String p_method, Object *p_obj) override;
+ virtual void set_tooltip_request_func(const Callable &p_toolip_callback) override;
virtual Control *get_edit_menu() override;
virtual void clear_edit_menu() override;
+ virtual void set_find_replace_bar(FindReplaceBar *p_bar) override { p_bar->hide(); }; // Not needed here.
virtual bool can_lose_focus_on_node_selection() override { return false; }
virtual void validate() override;
+ virtual Control *get_base_editor() const override;
+
static void register_editor();
static void free_clipboard();
+ void update_toggle_scripts_button() override;
+
VisualScriptEditor();
~VisualScriptEditor();
};
// Singleton
-class _VisualScriptEditor : public Object {
- GDCLASS(_VisualScriptEditor, Object);
+class VisualScriptCustomNodes : public Object {
+ GDCLASS(VisualScriptCustomNodes, Object);
friend class VisualScriptLanguage;
protected:
static void _bind_methods();
- static _VisualScriptEditor *singleton;
+ static VisualScriptCustomNodes *singleton;
- static Map<String, REF> custom_nodes;
+ static HashMap<String, Ref<RefCounted>> custom_nodes;
static Ref<VisualScriptNode> create_node_custom(const String &p_name);
public:
- static _VisualScriptEditor *get_singleton() { return singleton; }
+ static VisualScriptCustomNodes *get_singleton() { return singleton; }
void add_custom_node(const String &p_name, const String &p_category, const Ref<Script> &p_script);
void remove_custom_node(const String &p_name, const String &p_category);
- _VisualScriptEditor();
- ~_VisualScriptEditor();
+ VisualScriptCustomNodes();
+ ~VisualScriptCustomNodes();
};
+
#endif
#endif // VISUALSCRIPT_EDITOR_H
diff --git a/modules/visual_script/editor/visual_script_property_selector.cpp b/modules/visual_script/editor/visual_script_property_selector.cpp
new file mode 100644
index 0000000000..ae30655301
--- /dev/null
+++ b/modules/visual_script/editor/visual_script_property_selector.cpp
@@ -0,0 +1,1276 @@
+/*************************************************************************/
+/* visual_script_property_selector.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_property_selector.h"
+
+#include "../visual_script.h"
+#include "../visual_script_builtin_funcs.h"
+#include "../visual_script_flow_control.h"
+#include "../visual_script_func_nodes.h"
+#include "../visual_script_nodes.h"
+#include "core/os/keyboard.h"
+#include "editor/doc_tools.h"
+#include "editor/editor_feature_profile.h"
+#include "editor/editor_scale.h"
+#include "scene/main/node.h"
+#include "scene/main/window.h"
+
+void VisualScriptPropertySelector::_update_icons() {
+ search_box->set_right_icon(results_tree->get_theme_icon(SNAME("Search"), SNAME("EditorIcons")));
+ search_box->set_clear_button_enabled(true);
+ search_box->add_theme_icon_override("right_icon", results_tree->get_theme_icon(SNAME("Search"), SNAME("EditorIcons")));
+
+ search_visual_script_nodes->set_icon(results_tree->get_theme_icon(SNAME("VisualScript"), SNAME("EditorIcons")));
+ search_classes->set_icon(results_tree->get_theme_icon(SNAME("Object"), SNAME("EditorIcons")));
+ search_methods->set_icon(results_tree->get_theme_icon(SNAME("MemberMethod"), SNAME("EditorIcons")));
+ search_operators->set_icon(results_tree->get_theme_icon(SNAME("Add"), SNAME("EditorIcons")));
+ search_signals->set_icon(results_tree->get_theme_icon(SNAME("MemberSignal"), SNAME("EditorIcons")));
+ search_constants->set_icon(results_tree->get_theme_icon(SNAME("MemberConstant"), SNAME("EditorIcons")));
+ search_properties->set_icon(results_tree->get_theme_icon(SNAME("MemberProperty"), SNAME("EditorIcons")));
+ search_theme_items->set_icon(results_tree->get_theme_icon(SNAME("MemberTheme"), SNAME("EditorIcons")));
+
+ case_sensitive_button->set_icon(results_tree->get_theme_icon(SNAME("MatchCase"), SNAME("EditorIcons")));
+ hierarchy_button->set_icon(results_tree->get_theme_icon(SNAME("ClassList"), SNAME("EditorIcons")));
+}
+
+void VisualScriptPropertySelector::_sbox_input(const Ref<InputEvent> &p_ie) {
+ Ref<InputEventKey> k = p_ie;
+
+ if (k.is_valid()) {
+ switch (k->get_keycode()) {
+ case Key::UP:
+ case Key::DOWN:
+ case Key::PAGEUP:
+ case Key::PAGEDOWN: {
+ results_tree->gui_input(k);
+ search_box->accept_event();
+ } break;
+ default:
+ break;
+ }
+ }
+}
+
+void VisualScriptPropertySelector::_update_results_i(int p_int) {
+ _update_results();
+}
+
+void VisualScriptPropertySelector::_update_results_s(String p_string) {
+ _update_results();
+}
+
+void VisualScriptPropertySelector::_update_results_search_all() {
+ if (search_classes->is_pressed()) {
+ scope_combo->select(COMBO_ALL);
+ }
+ _update_results();
+}
+
+void VisualScriptPropertySelector::_update_results() {
+ _update_icons();
+ search_runner = Ref<SearchRunner>(memnew(SearchRunner(this, results_tree)));
+ set_process(true);
+}
+
+void VisualScriptPropertySelector::_confirmed() {
+ TreeItem *ti = results_tree->get_selected();
+ if (!ti) {
+ return;
+ }
+ emit_signal(SNAME("selected"), ti->get_metadata(0), ti->get_metadata(1), connecting);
+ set_visible(false);
+}
+
+void VisualScriptPropertySelector::_item_selected() {
+ help_bit->set_text(results_tree->get_selected()->get_meta("description", "No description available"));
+}
+
+void VisualScriptPropertySelector::_hide_requested() {
+ _cancel_pressed(); // From AcceptDialog.
+}
+
+void VisualScriptPropertySelector::_notification(int p_what) {
+ switch (p_what) {
+ case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
+ _update_icons();
+ } break;
+
+ case NOTIFICATION_ENTER_TREE: {
+ connect("confirmed", callable_mp(this, &VisualScriptPropertySelector::_confirmed));
+ } break;
+
+ case NOTIFICATION_PROCESS: {
+ // Update background search.
+ if (search_runner.is_valid()) {
+ if (search_runner->work()) {
+ // Search done.
+ get_ok_button()->set_disabled(!results_tree->get_selected());
+
+ search_runner = Ref<SearchRunner>();
+ set_process(false);
+ }
+ } else {
+ // if one is valid
+ set_process(false);
+ }
+ } break;
+ }
+}
+
+void VisualScriptPropertySelector::select_method_from_base_type(const String &p_base, const bool p_virtuals_only, const bool p_connecting, bool clear_text) {
+ set_title(TTR("Select method from base type"));
+ base_type = p_base;
+ base_script = "";
+ type = Variant::NIL;
+ connecting = p_connecting;
+
+ if (clear_text) {
+ if (p_virtuals_only) {
+ search_box->set_text("._"); // show all _methods
+ search_box->set_caret_column(2);
+ } else {
+ search_box->set_text("."); // show all methods
+ search_box->set_caret_column(1);
+ }
+ }
+
+ search_visual_script_nodes->set_pressed(false);
+ search_classes->set_pressed(false);
+ search_methods->set_pressed(true);
+ search_operators->set_pressed(false);
+ search_signals->set_pressed(false);
+ search_constants->set_pressed(false);
+ search_properties->set_pressed(false);
+ search_theme_items->set_pressed(false);
+
+ scope_combo->select(COMBO_BASE);
+
+ results_tree->clear();
+ show_window(.5f);
+ search_box->grab_focus();
+
+ _update_results();
+}
+
+void VisualScriptPropertySelector::select_from_base_type(const String &p_base, const String &p_base_script, bool p_virtuals_only, const bool p_connecting, bool clear_text) {
+ set_title(TTR("Select from base type"));
+ base_type = p_base;
+ base_script = p_base_script.trim_prefix("res://").quote(); // filepath to EditorHelp::get_doc_data().name
+ type = Variant::NIL;
+ connecting = p_connecting;
+
+ if (clear_text) {
+ if (p_virtuals_only) {
+ search_box->set_text("_");
+ } else {
+ search_box->set_text(" ");
+ }
+ }
+ search_box->select_all();
+
+ search_visual_script_nodes->set_pressed(false);
+ search_classes->set_pressed(false);
+ search_methods->set_pressed(true);
+ search_operators->set_pressed(false);
+ search_signals->set_pressed(true);
+ search_constants->set_pressed(false);
+ search_properties->set_pressed(true);
+ search_theme_items->set_pressed(false);
+
+ scope_combo->select(COMBO_RELATED);
+
+ results_tree->clear();
+ show_window(.5f);
+ search_box->grab_focus();
+ _update_results();
+}
+
+void VisualScriptPropertySelector::select_from_script(const Ref<Script> &p_script, const bool p_connecting, bool clear_text) {
+ set_title(TTR("Select from script"));
+ ERR_FAIL_COND(p_script.is_null());
+
+ base_type = p_script->get_instance_base_type();
+ base_script = p_script->get_path().trim_prefix("res://").quote(); // filepath to EditorHelp::get_doc_data().name
+ type = Variant::NIL;
+ script = p_script->get_instance_id();
+ connecting = p_connecting;
+
+ if (clear_text) {
+ search_box->set_text("");
+ }
+ search_box->select_all();
+
+ search_visual_script_nodes->set_pressed(false);
+ search_classes->set_pressed(true);
+ search_methods->set_pressed(true);
+ search_operators->set_pressed(true);
+ search_signals->set_pressed(true);
+ search_constants->set_pressed(true);
+ search_properties->set_pressed(true);
+ search_theme_items->set_pressed(false);
+
+ scope_combo->select(COMBO_BASE);
+
+ results_tree->clear();
+ show_window(.5f);
+ search_box->grab_focus();
+ _update_results();
+}
+
+void VisualScriptPropertySelector::select_from_basic_type(Variant::Type p_type, const bool p_connecting, bool clear_text) {
+ set_title(TTR("Select from basic type"));
+ ERR_FAIL_COND(p_type == Variant::NIL);
+ base_type = Variant::get_type_name(p_type);
+ base_script = "";
+ type = p_type;
+ connecting = p_connecting;
+
+ if (clear_text) {
+ search_box->set_text(" ");
+ }
+ search_box->select_all();
+
+ search_visual_script_nodes->set_pressed(false);
+ search_classes->set_pressed(false);
+ search_methods->set_pressed(true);
+ search_operators->set_pressed(true);
+ search_signals->set_pressed(false);
+ search_constants->set_pressed(true);
+ search_properties->set_pressed(true);
+ search_theme_items->set_pressed(false);
+
+ scope_combo->select(COMBO_BASE);
+
+ results_tree->clear();
+ show_window(.5f);
+ search_box->grab_focus();
+
+ _update_results();
+}
+
+void VisualScriptPropertySelector::select_from_action(const String &p_type, const bool p_connecting, bool clear_text) {
+ set_title(TTR("Select from action"));
+ base_type = p_type;
+ base_script = "";
+ type = Variant::NIL;
+ connecting = p_connecting;
+
+ if (clear_text) {
+ search_box->set_text("");
+ }
+ search_box->select_all();
+
+ search_visual_script_nodes->set_pressed(true);
+ search_classes->set_pressed(false);
+ search_methods->set_pressed(false);
+ search_operators->set_pressed(false);
+ search_signals->set_pressed(false);
+ search_constants->set_pressed(false);
+ search_properties->set_pressed(false);
+ search_theme_items->set_pressed(false);
+
+ scope_combo->select(COMBO_RELATED);
+
+ results_tree->clear();
+ show_window(.5f);
+ search_box->grab_focus();
+ _update_results();
+}
+
+void VisualScriptPropertySelector::select_from_instance(Object *p_instance, const bool p_connecting, bool clear_text) {
+ set_title(TTR("Select from instance"));
+ base_type = p_instance->get_class();
+
+ const Ref<Script> &p_script = p_instance->get_script();
+ if (p_script == nullptr) {
+ base_script = "";
+ } else {
+ base_script = p_script->get_path().trim_prefix("res://").quote(); // filepath to EditorHelp::get_doc_data().name
+ }
+
+ type = Variant::NIL;
+ connecting = p_connecting;
+
+ if (clear_text) {
+ search_box->set_text(" ");
+ }
+ search_box->select_all();
+
+ search_visual_script_nodes->set_pressed(false);
+ search_classes->set_pressed(false);
+ search_methods->set_pressed(true);
+ search_operators->set_pressed(false);
+ search_signals->set_pressed(true);
+ search_constants->set_pressed(true);
+ search_properties->set_pressed(true);
+ search_theme_items->set_pressed(false);
+
+ scope_combo->select(COMBO_BASE);
+
+ results_tree->clear();
+ show_window(.5f);
+ search_box->grab_focus();
+ _update_results();
+}
+
+void VisualScriptPropertySelector::select_from_visual_script(const Ref<Script> &p_script, bool clear_text) {
+ set_title(TTR("Select from visual script"));
+ base_type = p_script->get_instance_base_type();
+ if (p_script == nullptr) {
+ base_script = "";
+ } else {
+ base_script = p_script->get_path().trim_prefix("res://").quote(); // filepath to EditorHelp::get_doc_data().name
+ }
+ type = Variant::NIL;
+ connecting = false;
+
+ if (clear_text) {
+ search_box->set_text(" ");
+ }
+ search_box->select_all();
+
+ search_visual_script_nodes->set_pressed(true);
+ search_classes->set_pressed(false);
+ search_methods->set_pressed(true);
+ search_operators->set_pressed(false);
+ search_signals->set_pressed(true);
+ search_constants->set_pressed(true);
+ search_properties->set_pressed(true);
+ search_theme_items->set_pressed(false);
+
+ scope_combo->select(COMBO_BASE);
+
+ results_tree->clear();
+ show_window(.5f);
+ search_box->grab_focus();
+ _update_results();
+}
+
+void VisualScriptPropertySelector::show_window(float p_screen_ratio) {
+ popup_centered_ratio(p_screen_ratio);
+}
+
+void VisualScriptPropertySelector::_bind_methods() {
+ ADD_SIGNAL(MethodInfo("selected", PropertyInfo(Variant::STRING, "name"), PropertyInfo(Variant::STRING, "category"), PropertyInfo(Variant::BOOL, "connecting")));
+}
+
+VisualScriptPropertySelector::VisualScriptPropertySelector() {
+ vbox = memnew(VBoxContainer);
+ add_child(vbox);
+
+ HBoxContainer *hbox = memnew(HBoxContainer);
+ hbox->set_alignment(hbox->ALIGNMENT_CENTER);
+ vbox->add_child(hbox);
+
+ case_sensitive_button = memnew(Button);
+ case_sensitive_button->set_flat(true);
+ case_sensitive_button->set_tooltip(TTR("Case Sensitive"));
+ case_sensitive_button->connect("pressed", callable_mp(this, &VisualScriptPropertySelector::_update_results));
+ case_sensitive_button->set_toggle_mode(true);
+ case_sensitive_button->set_focus_mode(Control::FOCUS_NONE);
+ hbox->add_child(case_sensitive_button);
+
+ hierarchy_button = memnew(Button);
+ hierarchy_button->set_flat(true);
+ hierarchy_button->set_tooltip(TTR("Show Hierarchy"));
+ hierarchy_button->connect("pressed", callable_mp(this, &VisualScriptPropertySelector::_update_results));
+ hierarchy_button->set_toggle_mode(true);
+ hierarchy_button->set_pressed(true);
+ hierarchy_button->set_focus_mode(Control::FOCUS_NONE);
+ hbox->add_child(hierarchy_button);
+
+ hbox->add_child(memnew(VSeparator));
+
+ search_visual_script_nodes = memnew(Button);
+ search_visual_script_nodes->set_flat(true);
+ search_visual_script_nodes->set_tooltip(TTR("Search Visual Script Nodes"));
+ search_visual_script_nodes->connect("pressed", callable_mp(this, &VisualScriptPropertySelector::_update_results));
+ search_visual_script_nodes->set_toggle_mode(true);
+ search_visual_script_nodes->set_pressed(true);
+ search_visual_script_nodes->set_focus_mode(Control::FOCUS_NONE);
+ hbox->add_child(search_visual_script_nodes);
+
+ search_classes = memnew(Button);
+ search_classes->set_flat(true);
+ search_classes->set_tooltip(TTR("Search Classes"));
+ search_classes->connect("pressed", callable_mp(this, &VisualScriptPropertySelector::_update_results_search_all));
+ search_classes->set_toggle_mode(true);
+ search_classes->set_pressed(true);
+ search_classes->set_focus_mode(Control::FOCUS_NONE);
+ hbox->add_child(search_classes);
+
+ search_operators = memnew(Button);
+ search_operators->set_flat(true);
+ search_operators->set_tooltip(TTR("Search Operators"));
+ search_operators->connect("pressed", callable_mp(this, &VisualScriptPropertySelector::_update_results));
+ search_operators->set_toggle_mode(true);
+ search_operators->set_pressed(true);
+ search_operators->set_focus_mode(Control::FOCUS_NONE);
+ hbox->add_child(search_operators);
+
+ hbox->add_child(memnew(VSeparator));
+
+ search_methods = memnew(Button);
+ search_methods->set_flat(true);
+ search_methods->set_tooltip(TTR("Search Methods"));
+ search_methods->connect("pressed", callable_mp(this, &VisualScriptPropertySelector::_update_results));
+ search_methods->set_toggle_mode(true);
+ search_methods->set_pressed(true);
+ search_methods->set_focus_mode(Control::FOCUS_NONE);
+ hbox->add_child(search_methods);
+
+ search_signals = memnew(Button);
+ search_signals->set_flat(true);
+ search_signals->set_tooltip(TTR("Search Signals"));
+ search_signals->connect("pressed", callable_mp(this, &VisualScriptPropertySelector::_update_results));
+ search_signals->set_toggle_mode(true);
+ search_signals->set_pressed(true);
+ search_signals->set_focus_mode(Control::FOCUS_NONE);
+ hbox->add_child(search_signals);
+
+ search_constants = memnew(Button);
+ search_constants->set_flat(true);
+ search_constants->set_tooltip(TTR("Search Constants"));
+ search_constants->connect("pressed", callable_mp(this, &VisualScriptPropertySelector::_update_results));
+ search_constants->set_toggle_mode(true);
+ search_constants->set_pressed(true);
+ search_constants->set_focus_mode(Control::FOCUS_NONE);
+ hbox->add_child(search_constants);
+
+ search_properties = memnew(Button);
+ search_properties->set_flat(true);
+ search_properties->set_tooltip(TTR("Search Properties"));
+ search_properties->connect("pressed", callable_mp(this, &VisualScriptPropertySelector::_update_results));
+ search_properties->set_toggle_mode(true);
+ search_properties->set_pressed(true);
+ search_properties->set_focus_mode(Control::FOCUS_NONE);
+ hbox->add_child(search_properties);
+
+ search_theme_items = memnew(Button);
+ search_theme_items->set_flat(true);
+ search_theme_items->set_tooltip(TTR("Search Theme Items"));
+ search_theme_items->connect("pressed", callable_mp(this, &VisualScriptPropertySelector::_update_results));
+ search_theme_items->set_toggle_mode(true);
+ search_theme_items->set_pressed(true);
+ search_theme_items->set_focus_mode(Control::FOCUS_NONE);
+ hbox->add_child(search_theme_items);
+
+ scope_combo = memnew(OptionButton);
+ scope_combo->set_custom_minimum_size(Size2(200, 0) * EDSCALE);
+ scope_combo->set_tooltip(TTR("Select the search limits"));
+ scope_combo->set_stretch_ratio(0); // Fixed width.
+ scope_combo->add_item(TTR("Search Related"), SCOPE_RELATED);
+ scope_combo->add_separator();
+ scope_combo->add_item(TTR("Search Base"), SCOPE_BASE);
+ scope_combo->add_item(TTR("Search Inheriters"), SCOPE_INHERITERS);
+ scope_combo->add_item(TTR("Search Unrelated"), SCOPE_UNRELATED);
+ scope_combo->add_item(TTR("Search All"), SCOPE_ALL);
+ scope_combo->connect("item_selected", callable_mp(this, &VisualScriptPropertySelector::_update_results_i));
+ hbox->add_child(scope_combo);
+
+ search_box = memnew(LineEdit);
+ search_box->set_tooltip(TTR("Enter \" \" to show all filtered options\nEnter \".\" to show all filtered methods, operators and constructors\nUse CTRL_KEY to drop property setters"));
+ search_box->set_custom_minimum_size(Size2(200, 0) * EDSCALE);
+ search_box->set_h_size_flags(Control::SIZE_EXPAND_FILL);
+ search_box->connect("text_changed", callable_mp(this, &VisualScriptPropertySelector::_update_results_s));
+ search_box->connect("gui_input", callable_mp(this, &VisualScriptPropertySelector::_sbox_input));
+ register_text_enter(search_box);
+ vbox->add_child(search_box);
+
+ results_tree = memnew(Tree);
+ results_tree->set_v_size_flags(Control::SIZE_EXPAND_FILL);
+ results_tree->set_hide_root(true);
+ results_tree->set_hide_folding(false);
+ results_tree->set_columns(2);
+ results_tree->set_column_title(0, TTR("Name"));
+ results_tree->set_column_clip_content(0, true);
+ results_tree->set_column_title(1, TTR("Member Type"));
+ results_tree->set_column_expand(1, false);
+ results_tree->set_column_custom_minimum_width(1, 150 * EDSCALE);
+ results_tree->set_column_clip_content(1, true);
+ results_tree->set_custom_minimum_size(Size2(0, 100) * EDSCALE);
+ results_tree->set_select_mode(Tree::SELECT_ROW);
+ results_tree->connect("item_activated", callable_mp(this, &VisualScriptPropertySelector::_confirmed));
+ results_tree->connect("item_selected", callable_mp(this, &VisualScriptPropertySelector::_item_selected));
+ vbox->add_child(results_tree);
+
+ ScrollContainer *scroller = memnew(ScrollContainer);
+ scroller->set_horizontal_scroll_mode(ScrollContainer::SCROLL_MODE_DISABLED);
+ scroller->set_v_size_flags(Control::SIZE_EXPAND_FILL);
+ scroller->set_custom_minimum_size(Size2(600, 400) * EDSCALE);
+ vbox->add_child(scroller);
+
+ help_bit = memnew(EditorHelpBit);
+ help_bit->set_h_size_flags(Control::SIZE_EXPAND_FILL);
+ help_bit->set_v_size_flags(Control::SIZE_EXPAND_FILL);
+ scroller->add_child(help_bit);
+
+ help_bit->connect("request_hide", callable_mp(this, &VisualScriptPropertySelector::_hide_requested));
+ get_ok_button()->set_text(TTR("Open"));
+ get_ok_button()->set_disabled(true);
+ set_hide_on_ok(false);
+}
+
+bool VisualScriptPropertySelector::SearchRunner::_is_class_disabled_by_feature_profile(const StringName &p_class) {
+ Ref<EditorFeatureProfile> profile = EditorFeatureProfileManager::get_singleton()->get_current_profile();
+ if (profile.is_null()) {
+ return false;
+ }
+
+ StringName class_name = p_class;
+ while (class_name != StringName()) {
+ if (!ClassDB::class_exists(class_name)) {
+ return false;
+ }
+
+ if (profile->is_class_disabled(class_name)) {
+ return true;
+ }
+ class_name = ClassDB::get_parent_class(class_name);
+ }
+
+ return false;
+}
+
+bool VisualScriptPropertySelector::SearchRunner::_is_class_disabled_by_scope(const StringName &p_class) {
+ bool is_base_script = false;
+ if (p_class == selector_ui->base_script) {
+ is_base_script = true;
+ }
+ bool is_base = false;
+ if (selector_ui->base_type == p_class) {
+ is_base = true;
+ }
+ bool is_parent = false;
+ if ((ClassDB::is_parent_class(selector_ui->base_type, p_class)) && !is_base) {
+ is_parent = true;
+ }
+
+ bool is_inheriter = false;
+ List<StringName> inheriters;
+ ClassDB::get_inheriters_from_class(selector_ui->base_type, &inheriters);
+ if (inheriters.find(p_class)) {
+ is_inheriter = true;
+ }
+
+ if (scope_flags & SCOPE_BASE) {
+ if (is_base_script || is_base || is_parent) {
+ return false;
+ }
+ }
+ if (scope_flags & SCOPE_INHERITERS) {
+ if (is_base_script || is_base || is_inheriter) {
+ return false;
+ }
+ }
+ // if (scope_flags & SCOPE_RELATED) {
+ // /* code */
+ // }
+ if (scope_flags & SCOPE_UNRELATED) {
+ if (!is_base_script && !is_base && !is_inheriter) {
+ return false;
+ }
+ }
+ return true;
+}
+
+bool VisualScriptPropertySelector::SearchRunner::_slice() {
+ bool phase_done = false;
+ switch (phase) {
+ case PHASE_INIT:
+ phase_done = _phase_init();
+ break;
+ case PHASE_MATCH_CLASSES_INIT:
+ phase_done = _phase_match_classes_init();
+ break;
+ case PHASE_NODE_CLASSES_INIT:
+ phase_done = _phase_node_classes_init();
+ break;
+ case PHASE_NODE_CLASSES_BUILD:
+ phase_done = _phase_node_classes_build();
+ break;
+ case PHASE_MATCH_CLASSES:
+ phase_done = _phase_match_classes();
+ break;
+ case PHASE_CLASS_ITEMS_INIT:
+ phase_done = _phase_class_items_init();
+ break;
+ case PHASE_CLASS_ITEMS:
+ phase_done = _phase_class_items();
+ break;
+ case PHASE_MEMBER_ITEMS_INIT:
+ phase_done = _phase_member_items_init();
+ break;
+ case PHASE_MEMBER_ITEMS:
+ phase_done = _phase_member_items();
+ break;
+ case PHASE_SELECT_MATCH:
+ phase_done = _phase_select_match();
+ break;
+ case PHASE_MAX:
+ return true;
+ default:
+ WARN_PRINT("Invalid or unhandled phase in EditorHelpSearch::Runner, aborting search.");
+ return true;
+ };
+
+ if (phase_done) {
+ phase++;
+ }
+ return false;
+}
+
+bool VisualScriptPropertySelector::SearchRunner::_phase_init() {
+ search_flags = 0; // selector_ui->filter_combo->get_selected_id();
+ if (selector_ui->search_visual_script_nodes->is_pressed()) {
+ search_flags |= SEARCH_VISUAL_SCRIPT_NODES;
+ }
+ if (selector_ui->search_classes->is_pressed()) {
+ search_flags |= SEARCH_CLASSES;
+ }
+ // if (selector_ui->search_constructors->is_pressed()) {
+ search_flags |= SEARCH_CONSTRUCTORS;
+ // }
+ if (selector_ui->search_methods->is_pressed()) {
+ search_flags |= SEARCH_METHODS;
+ }
+ if (selector_ui->search_operators->is_pressed()) {
+ search_flags |= SEARCH_OPERATORS;
+ }
+ if (selector_ui->search_signals->is_pressed()) {
+ search_flags |= SEARCH_SIGNALS;
+ }
+ if (selector_ui->search_constants->is_pressed()) {
+ search_flags |= SEARCH_CONSTANTS;
+ }
+ if (selector_ui->search_properties->is_pressed()) {
+ search_flags |= SEARCH_PROPERTIES;
+ }
+ if (selector_ui->search_theme_items->is_pressed()) {
+ search_flags |= SEARCH_THEME_ITEMS;
+ }
+ if (selector_ui->case_sensitive_button->is_pressed()) {
+ search_flags |= SEARCH_CASE_SENSITIVE;
+ }
+ if (selector_ui->hierarchy_button->is_pressed()) {
+ search_flags |= SEARCH_SHOW_HIERARCHY;
+ }
+ scope_flags = selector_ui->scope_combo->get_selected_id();
+
+ return true;
+}
+
+bool VisualScriptPropertySelector::SearchRunner::_phase_match_classes_init() {
+ combined_docs = EditorHelp::get_doc_data()->class_list;
+ matches.clear();
+ matched_item = nullptr;
+ match_highest_score = 0;
+
+ if (
+ (selector_ui->base_script.unquote() != "") &&
+ (selector_ui->base_script.unquote() != ".") &&
+ !combined_docs.has(selector_ui->base_script)) {
+ String file_path = "res://" + selector_ui->base_script.unquote(); // EditorHelp::get_doc_data().name to filepath
+ Ref<Script> script;
+ script = ResourceLoader::load(file_path);
+ if (!script.is_null()) {
+ DocData::ClassDoc class_doc = DocData::ClassDoc();
+
+ class_doc.name = selector_ui->base_script;
+
+ class_doc.inherits = script->get_instance_base_type();
+ class_doc.brief_description = ".vs files not supported by EditorHelp::get_doc_data()";
+ class_doc.description = "";
+
+ Object *obj = ObjectDB::get_instance(script->get_instance_id());
+ if (Object::cast_to<Script>(obj)) {
+ List<MethodInfo> methods;
+ Object::cast_to<Script>(obj)->get_script_method_list(&methods);
+ for (List<MethodInfo>::Element *M = methods.front(); M; M = M->next()) {
+ class_doc.methods.push_back(_get_method_doc(M->get()));
+ }
+
+ List<MethodInfo> signals;
+ Object::cast_to<Script>(obj)->get_script_signal_list(&signals);
+ for (List<MethodInfo>::Element *S = signals.front(); S; S = S->next()) {
+ class_doc.signals.push_back(_get_method_doc(S->get()));
+ }
+
+ List<PropertyInfo> properties;
+ Object::cast_to<Script>(obj)->get_script_property_list(&properties);
+ for (List<PropertyInfo>::Element *P = properties.front(); P; P = P->next()) {
+ DocData::PropertyDoc pd = DocData::PropertyDoc();
+ pd.name = P->get().name;
+ pd.type = Variant::get_type_name(P->get().type);
+ class_doc.properties.push_back(pd);
+ }
+ }
+ combined_docs.insert(class_doc.name, class_doc);
+ }
+ }
+ iterator_doc = combined_docs.begin();
+ return true;
+}
+
+bool VisualScriptPropertySelector::SearchRunner::_phase_node_classes_init() {
+ VisualScriptLanguage::singleton->get_registered_node_names(&vs_nodes);
+ _add_class_doc("functions", "", "");
+ _add_class_doc("operators", "", "");
+ return true;
+}
+
+bool VisualScriptPropertySelector::SearchRunner::_phase_node_classes_build() {
+ if (vs_nodes.is_empty()) {
+ return true;
+ }
+ String registered_node_name = vs_nodes[0];
+ vs_nodes.pop_front();
+
+ Vector<String> path = registered_node_name.split("/");
+ if (path[0] == "constants") {
+ _add_class_doc(registered_node_name, "", "constants");
+ } else if (path[0] == "custom") {
+ _add_class_doc(registered_node_name, "", "custom");
+ } else if (path[0] == "data") {
+ _add_class_doc(registered_node_name, "", "data");
+ } else if (path[0] == "flow_control") {
+ _add_class_doc(registered_node_name, "", "flow_control");
+ } else if (path[0] == "functions") {
+ if (path[1] == "built_in") {
+ _add_class_doc(registered_node_name, "functions", "built_in");
+ } else if (path[1] == "by_type") {
+ // No action is required.
+ // Using function references from ClassDB to remove confusion for users.
+ } else if (path[1] == "constructors") {
+ _add_class_doc(registered_node_name, "", "constructors");
+ } else if (path[1] == "deconstruct") {
+ _add_class_doc(registered_node_name, "", "deconstruct");
+ } else if (path[1] == "wait") {
+ _add_class_doc(registered_node_name, "functions", "yield");
+ } else {
+ _add_class_doc(registered_node_name, "functions", "");
+ }
+ } else if (path[0] == "index") {
+ _add_class_doc(registered_node_name, "", "index");
+ } else if (path[0] == "operators") {
+ if (path[1] == "bitwise") {
+ _add_class_doc(registered_node_name, "operators", "bitwise");
+ } else if (path[1] == "compare") {
+ _add_class_doc(registered_node_name, "operators", "compare");
+ } else if (path[1] == "logic") {
+ _add_class_doc(registered_node_name, "operators", "logic");
+ } else if (path[1] == "math") {
+ _add_class_doc(registered_node_name, "operators", "math");
+ } else {
+ _add_class_doc(registered_node_name, "operators", "");
+ }
+ }
+ return false;
+}
+
+bool VisualScriptPropertySelector::SearchRunner::_phase_match_classes() {
+ DocData::ClassDoc &class_doc = iterator_doc->value;
+ if (
+ (!_is_class_disabled_by_feature_profile(class_doc.name) && !_is_class_disabled_by_scope(class_doc.name)) ||
+ _match_visual_script(class_doc)) {
+ if (class_doc.inherits == "VisualScriptCustomNode") {
+ class_doc.script_path = "res://" + class_doc.name.unquote();
+ Ref<Script> script = ResourceLoader::load(class_doc.script_path);
+ Ref<VisualScriptCustomNode> vsn;
+ vsn.instantiate();
+ vsn->set_script(script);
+ class_doc.name = vsn->get_caption();
+ if (combined_docs.has(vsn->get_category())) {
+ class_doc.inherits = vsn->get_category();
+ } else if (combined_docs.has("VisualScriptNode/" + vsn->get_category())) {
+ class_doc.inherits = "VisualScriptNode/" + vsn->get_category();
+ } else if (combined_docs.has("VisualScriptCustomNode/" + vsn->get_category())) {
+ class_doc.inherits = "VisualScriptCustomNode/" + vsn->get_category();
+ } else {
+ class_doc.inherits = "";
+ }
+ class_doc.category = "VisualScriptCustomNode/" + vsn->get_category();
+ class_doc.brief_description = "";
+ class_doc.constructors.clear();
+ class_doc.methods.clear();
+ class_doc.operators.clear();
+ class_doc.signals.clear();
+ class_doc.constants.clear();
+ class_doc.enums.clear();
+ class_doc.properties.clear();
+ class_doc.theme_properties.clear();
+ }
+
+ matches[class_doc.name] = ClassMatch();
+ ClassMatch &match = matches[class_doc.name];
+
+ match.category = class_doc.category;
+ match.doc = &class_doc;
+ // Match class name.
+ if (search_flags & SEARCH_CLASSES || _match_visual_script(class_doc)) {
+ if (term == "") {
+ match.name = !_match_is_hidden(class_doc);
+ } else {
+ match.name = _match_string(term, class_doc.name);
+ }
+ // match.name = term == "" || _match_string(term, class_doc.name);
+ }
+
+ // Match members if the term is long enough.
+ if (term.length() >= 0) {
+ if (search_flags & SEARCH_CONSTRUCTORS) {
+ for (int i = 0; i < class_doc.constructors.size(); i++) {
+ String method_name = (search_flags & SEARCH_CASE_SENSITIVE) ? class_doc.constructors[i].name : class_doc.constructors[i].name.to_lower();
+ if (method_name.find(term) > -1 ||
+ term == " " ||
+ (term.begins_with(".") && method_name.begins_with(term.substr(1))) ||
+ (term.ends_with("(") && method_name.ends_with(term.left(term.length() - 1).strip_edges())) ||
+ (term.begins_with(".") && term.ends_with("(") && method_name == term.substr(1, term.length() - 2).strip_edges())) {
+ match.constructors.push_back(const_cast<DocData::MethodDoc *>(&class_doc.constructors[i]));
+ }
+ }
+ }
+ if (search_flags & SEARCH_METHODS) {
+ for (int i = 0; i < class_doc.methods.size(); i++) {
+ String method_name = (search_flags & SEARCH_CASE_SENSITIVE) ? class_doc.methods[i].name : class_doc.methods[i].name.to_lower();
+ if (method_name.find(term) > -1 ||
+ term == " " ||
+ (term.begins_with(".") && method_name.begins_with(term.substr(1))) ||
+ (term.ends_with("(") && method_name.ends_with(term.left(term.length() - 1).strip_edges())) ||
+ (term.begins_with(".") && term.ends_with("(") && method_name == term.substr(1, term.length() - 2).strip_edges())) {
+ match.methods.push_back(const_cast<DocData::MethodDoc *>(&class_doc.methods[i]));
+ }
+ }
+ }
+ if (search_flags & SEARCH_OPERATORS) {
+ for (int i = 0; i < class_doc.operators.size(); i++) {
+ String method_name = (search_flags & SEARCH_CASE_SENSITIVE) ? class_doc.operators[i].name : class_doc.operators[i].name.to_lower();
+ if (method_name.find(term) > -1 ||
+ term == " " ||
+ (term.begins_with(".") && method_name.begins_with(term.substr(1))) ||
+ (term.ends_with("(") && method_name.ends_with(term.left(term.length() - 1).strip_edges())) ||
+ (term.begins_with(".") && term.ends_with("(") && method_name == term.substr(1, term.length() - 2).strip_edges())) {
+ match.operators.push_back(const_cast<DocData::MethodDoc *>(&class_doc.operators[i]));
+ }
+ }
+ }
+ if (search_flags & SEARCH_SIGNALS) {
+ for (int i = 0; i < class_doc.signals.size(); i++) {
+ if (_match_string(term, class_doc.signals[i].name) ||
+ term == " ") {
+ match.signals.push_back(const_cast<DocData::MethodDoc *>(&class_doc.signals[i]));
+ }
+ }
+ }
+ if (search_flags & SEARCH_CONSTANTS) {
+ for (int i = 0; i < class_doc.constants.size(); i++) {
+ if (_match_string(term, class_doc.constants[i].name) ||
+ term == " ") {
+ match.constants.push_back(const_cast<DocData::ConstantDoc *>(&class_doc.constants[i]));
+ }
+ }
+ }
+ if (search_flags & SEARCH_PROPERTIES) {
+ for (int i = 0; i < class_doc.properties.size(); i++) {
+ if (_match_string(term, class_doc.properties[i].name) ||
+ term == " " ||
+ _match_string(term, class_doc.properties[i].getter) ||
+ _match_string(term, class_doc.properties[i].setter)) {
+ match.properties.push_back(const_cast<DocData::PropertyDoc *>(&class_doc.properties[i]));
+ }
+ }
+ }
+ if (search_flags & SEARCH_THEME_ITEMS) {
+ for (int i = 0; i < class_doc.theme_properties.size(); i++) {
+ if (_match_string(term, class_doc.theme_properties[i].name) ||
+ term == " ") {
+ match.theme_properties.push_back(const_cast<DocData::ThemeItemDoc *>(&class_doc.theme_properties[i]));
+ }
+ }
+ }
+ }
+ }
+
+ ++iterator_doc;
+ return !iterator_doc;
+}
+
+bool VisualScriptPropertySelector::SearchRunner::_phase_class_items_init() {
+ results_tree->clear();
+ iterator_match = matches.begin();
+
+ root_item = results_tree->create_item();
+ class_items.clear();
+
+ return true;
+}
+
+bool VisualScriptPropertySelector::SearchRunner::_phase_class_items() {
+ if (!iterator_match) {
+ return true;
+ }
+
+ ClassMatch &match = iterator_match->value;
+
+ if (search_flags & SEARCH_SHOW_HIERARCHY) {
+ if (match.required()) {
+ _create_class_hierarchy(match);
+ }
+ } else {
+ if (match.name) {
+ _create_class_item(root_item, match.doc, true);
+ }
+ }
+
+ ++iterator_match;
+ return !iterator_match;
+}
+
+bool VisualScriptPropertySelector::SearchRunner::_phase_member_items_init() {
+ iterator_match = matches.begin();
+
+ return true;
+}
+
+bool VisualScriptPropertySelector::SearchRunner::_phase_member_items() {
+ if (!iterator_match) {
+ return true;
+ }
+
+ ClassMatch &match = iterator_match->value;
+
+ TreeItem *parent = (search_flags & SEARCH_SHOW_HIERARCHY) ? class_items[match.doc->name] : root_item;
+ bool constructor_created = false;
+ for (int i = 0; i < match.methods.size(); i++) {
+ String text = match.methods[i]->name;
+ if (!constructor_created) {
+ if (match.doc->name == match.methods[i]->name) {
+ text += " " + TTR("(constructors)");
+ constructor_created = true;
+ }
+ } else {
+ if (match.doc->name == match.methods[i]->name) {
+ continue;
+ }
+ }
+ _create_method_item(parent, match.doc, text, match.methods[i]);
+ }
+ for (int i = 0; i < match.signals.size(); i++) {
+ _create_signal_item(parent, match.doc, match.signals[i]);
+ }
+ for (int i = 0; i < match.constants.size(); i++) {
+ _create_constant_item(parent, match.doc, match.constants[i]);
+ }
+ for (int i = 0; i < match.properties.size(); i++) {
+ _create_property_item(parent, match.doc, match.properties[i]);
+ }
+ for (int i = 0; i < match.theme_properties.size(); i++) {
+ _create_theme_property_item(parent, match.doc, match.theme_properties[i]);
+ }
+
+ ++iterator_match;
+ return !iterator_match;
+}
+
+bool VisualScriptPropertySelector::SearchRunner::_phase_select_match() {
+ if (matched_item) {
+ matched_item->select(0);
+ }
+ return true;
+}
+
+bool VisualScriptPropertySelector::SearchRunner::_match_string(const String &p_term, const String &p_string) const {
+ if (search_flags & SEARCH_CASE_SENSITIVE) {
+ return p_string.find(p_term) > -1;
+ } else {
+ return p_string.findn(p_term) > -1;
+ }
+}
+
+bool VisualScriptPropertySelector::SearchRunner::_match_visual_script(DocData::ClassDoc &class_doc) {
+ if (class_doc.category.ends_with("_class")) {
+ if (class_doc.category.begins_with("VisualScript") && search_flags & SEARCH_CLASSES) {
+ if (matches.has(class_doc.inherits)) {
+ return true;
+ }
+ }
+ return false;
+ }
+ if (class_doc.category.begins_with("VisualScript") && search_flags & SEARCH_VISUAL_SCRIPT_NODES) {
+ return true;
+ }
+ if (class_doc.name.begins_with("operators") && search_flags & SEARCH_OPERATORS) {
+ return true;
+ }
+ if (class_doc.category.begins_with("VisualScriptNode/deconstruct")) {
+ if (class_doc.name.find(selector_ui->base_type, 0) > -1) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+bool VisualScriptPropertySelector::SearchRunner::_match_is_hidden(DocData::ClassDoc &class_doc) {
+ if (class_doc.category.begins_with("VisualScript")) {
+ if (class_doc.name.begins_with("flow_control")) {
+ return false;
+ } else if (class_doc.name.begins_with("operators")) {
+ return !(search_flags & SEARCH_OPERATORS);
+ } else if (class_doc.name.begins_with("functions/built_in/print")) {
+ return false;
+ }
+ return true;
+ }
+ return false;
+}
+
+void VisualScriptPropertySelector::SearchRunner::_match_item(TreeItem *p_item, const String &p_text) {
+ float inverse_length = 1.f / float(p_text.length());
+
+ // Favor types where search term is a substring close to the start of the type.
+ float w = 0.5f;
+ int pos = p_text.findn(term);
+ float score = (pos > -1) ? 1.0f - w * MIN(1, 3 * pos * inverse_length) : MAX(0.f, .9f - w);
+
+ // Favor shorter items: they resemble the search term more.
+ w = 0.1f;
+ score *= (1 - w) + w * (term.length() * inverse_length);
+
+ if (match_highest_score == 0 || score > match_highest_score) {
+ matched_item = p_item;
+ match_highest_score = score;
+ }
+}
+
+void VisualScriptPropertySelector::SearchRunner::_add_class_doc(String class_name, String inherits, String category) {
+ DocData::ClassDoc class_doc = DocData::ClassDoc();
+ class_doc.name = class_name;
+ class_doc.inherits = inherits;
+ class_doc.category = "VisualScriptNode/" + category;
+ class_doc.brief_description = category;
+ combined_docs.insert(class_doc.name, class_doc);
+}
+
+DocData::MethodDoc VisualScriptPropertySelector::SearchRunner::_get_method_doc(MethodInfo method_info) {
+ DocData::MethodDoc method_doc = DocData::MethodDoc();
+ method_doc.name = method_info.name;
+ method_doc.return_type = Variant::get_type_name(method_info.return_val.type);
+ method_doc.description = "No description available";
+ for (List<PropertyInfo>::Element *P = method_info.arguments.front(); P; P = P->next()) {
+ DocData::ArgumentDoc argument_doc = DocData::ArgumentDoc();
+ argument_doc.name = P->get().name;
+ argument_doc.type = Variant::get_type_name(P->get().type);
+ method_doc.arguments.push_back(argument_doc);
+ }
+ return method_doc;
+}
+
+TreeItem *VisualScriptPropertySelector::SearchRunner::_create_class_hierarchy(const ClassMatch &p_match) {
+ if (class_items.has(p_match.doc->name)) {
+ return class_items[p_match.doc->name];
+ }
+
+ // Ensure parent nodes are created first.
+ TreeItem *parent = root_item;
+ if (p_match.doc->inherits != "") {
+ if (class_items.has(p_match.doc->inherits)) {
+ parent = class_items[p_match.doc->inherits];
+ } else if (matches.has(p_match.doc->inherits)) {
+ ClassMatch &base_match = matches[p_match.doc->inherits];
+ parent = _create_class_hierarchy(base_match);
+ }
+ }
+
+ TreeItem *class_item = _create_class_item(parent, p_match.doc, !p_match.name);
+ class_items[p_match.doc->name] = class_item;
+ return class_item;
+}
+
+TreeItem *VisualScriptPropertySelector::SearchRunner::_create_class_item(TreeItem *p_parent, const DocData::ClassDoc *p_doc, bool p_gray) {
+ Ref<Texture2D> icon = empty_icon;
+ String text_0 = p_doc->name;
+ String text_1 = "Class";
+
+ String what = "Class";
+ String details = p_doc->name;
+ if (p_doc->category.begins_with("VisualScriptCustomNode/")) {
+ Vector<String> path = p_doc->name.split("/");
+ icon = ui_service->get_theme_icon(SNAME("VisualScript"), SNAME("EditorIcons"));
+ text_0 = path[path.size() - 1];
+ text_1 = "VisualScriptCustomNode";
+ what = "VisualScriptCustomNode";
+ details = "CustomNode";
+ } else if (p_doc->category.begins_with("VisualScriptNode/")) {
+ Vector<String> path = p_doc->name.split("/");
+ icon = ui_service->get_theme_icon(SNAME("VisualScript"), SNAME("EditorIcons"));
+ text_0 = path[path.size() - 1];
+ if (p_doc->category.begins_with("VisualScriptNode/deconstruct")) {
+ text_0 = "deconstruct " + text_0;
+ }
+ text_1 = "VisualScriptNode";
+ what = "VisualScriptNode";
+ details = p_doc->name;
+
+ if (path.size() == 1) {
+ if (path[0] == "functions" || path[0] == "operators") {
+ text_1 = "VisualScript";
+ p_gray = true;
+ what = "no_result";
+ details = "";
+ }
+ }
+
+ } else {
+ if (p_doc->name.is_quoted()) {
+ text_0 = p_doc->name.unquote().get_file();
+ if (ui_service->has_theme_icon(p_doc->inherits, "EditorIcons")) {
+ icon = ui_service->get_theme_icon(p_doc->inherits, "EditorIcons");
+ }
+ } else if (ui_service->has_theme_icon(p_doc->name, "EditorIcons")) {
+ icon = ui_service->get_theme_icon(p_doc->name, "EditorIcons");
+ } else if (ClassDB::class_exists(p_doc->name) && ClassDB::is_parent_class(p_doc->name, "Object")) {
+ icon = ui_service->get_theme_icon(SNAME("Object"), SNAME("EditorIcons"));
+ }
+ }
+ String tooltip = p_doc->brief_description.strip_edges();
+
+ TreeItem *item = results_tree->create_item(p_parent);
+ item->set_icon(0, icon);
+ item->set_text(0, text_0);
+ item->set_text(1, TTR(text_1));
+ item->set_tooltip(0, tooltip);
+ item->set_tooltip(1, tooltip);
+ item->set_metadata(0, details);
+ item->set_metadata(1, what);
+ if (p_gray) {
+ item->set_custom_color(0, disabled_color);
+ item->set_custom_color(1, disabled_color);
+ }
+
+ _match_item(item, p_doc->name);
+
+ return item;
+}
+
+TreeItem *VisualScriptPropertySelector::SearchRunner::_create_method_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const String &p_text, const DocData::MethodDoc *p_doc) {
+ String tooltip = p_doc->return_type + " " + p_class_doc->name + "." + p_doc->name + "(";
+ for (int i = 0; i < p_doc->arguments.size(); i++) {
+ const DocData::ArgumentDoc &arg = p_doc->arguments[i];
+ tooltip += arg.type + " " + arg.name;
+ if (arg.default_value != "") {
+ tooltip += " = " + arg.default_value;
+ }
+ if (i < p_doc->arguments.size() - 1) {
+ tooltip += ", ";
+ }
+ }
+ tooltip += ")";
+ return _create_member_item(p_parent, p_class_doc->name, "MemberMethod", p_doc->name, p_text, TTRC("Method"), "method", tooltip, p_doc->description);
+}
+
+TreeItem *VisualScriptPropertySelector::SearchRunner::_create_signal_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::MethodDoc *p_doc) {
+ String tooltip = p_doc->return_type + " " + p_class_doc->name + "." + p_doc->name + "(";
+ for (int i = 0; i < p_doc->arguments.size(); i++) {
+ const DocData::ArgumentDoc &arg = p_doc->arguments[i];
+ tooltip += arg.type + " " + arg.name;
+ if (arg.default_value != "") {
+ tooltip += " = " + arg.default_value;
+ }
+ if (i < p_doc->arguments.size() - 1) {
+ tooltip += ", ";
+ }
+ }
+ tooltip += ")";
+ return _create_member_item(p_parent, p_class_doc->name, "MemberSignal", p_doc->name, p_doc->name, TTRC("Signal"), "signal", tooltip, p_doc->description);
+}
+
+TreeItem *VisualScriptPropertySelector::SearchRunner::_create_constant_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::ConstantDoc *p_doc) {
+ String tooltip = p_class_doc->name + "." + p_doc->name;
+ return _create_member_item(p_parent, p_class_doc->name, "MemberConstant", p_doc->name, p_doc->name, TTRC("Constant"), "constant", tooltip, p_doc->description);
+}
+
+TreeItem *VisualScriptPropertySelector::SearchRunner::_create_property_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::PropertyDoc *p_doc) {
+ String tooltip = p_doc->type + " " + p_class_doc->name + "." + p_doc->name;
+ tooltip += "\n " + p_class_doc->name + "." + p_doc->setter + "(value) setter";
+ tooltip += "\n " + p_class_doc->name + "." + p_doc->getter + "() getter";
+ return _create_member_item(p_parent, p_class_doc->name, "MemberProperty", p_doc->name, p_doc->name, TTRC("Property"), "property", tooltip, p_doc->description);
+}
+
+TreeItem *VisualScriptPropertySelector::SearchRunner::_create_theme_property_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::ThemeItemDoc *p_doc) {
+ String tooltip = p_doc->type + " " + p_class_doc->name + "." + p_doc->name;
+ return _create_member_item(p_parent, p_class_doc->name, "MemberTheme", p_doc->name, p_doc->name, TTRC("Theme Property"), "theme_item", tooltip, p_doc->description);
+}
+
+TreeItem *VisualScriptPropertySelector::SearchRunner::_create_member_item(TreeItem *p_parent, const String &p_class_name, const String &p_icon, const String &p_name, const String &p_text, const String &p_type, const String &p_metatype, const String &p_tooltip, const String &p_description) {
+ Ref<Texture2D> icon;
+ String text;
+ if (search_flags & SEARCH_SHOW_HIERARCHY) {
+ icon = ui_service->get_theme_icon(p_icon, SNAME("EditorIcons"));
+ text = p_text;
+ } else {
+ icon = ui_service->get_theme_icon(p_icon, SNAME("EditorIcons"));
+ text = p_class_name + "." + p_text;
+ }
+
+ TreeItem *item = results_tree->create_item(p_parent);
+ item->set_icon(0, icon);
+ item->set_text(0, text);
+ item->set_text(1, TTRGET(p_type));
+ item->set_tooltip(0, p_tooltip);
+ item->set_tooltip(1, p_tooltip);
+ item->set_metadata(0, p_class_name + ":" + p_name);
+ item->set_metadata(1, "class_" + p_metatype);
+ item->set_meta("description", p_description);
+
+ _match_item(item, p_name);
+
+ return item;
+}
+
+bool VisualScriptPropertySelector::SearchRunner::work(uint64_t slot) {
+ // Return true when the search has been completed, otherwise false.
+ const uint64_t until = OS::get_singleton()->get_ticks_usec() + slot;
+ while (!_slice()) {
+ if (OS::get_singleton()->get_ticks_usec() > until) {
+ return false;
+ }
+ }
+ return true;
+}
+
+VisualScriptPropertySelector::SearchRunner::SearchRunner(VisualScriptPropertySelector *p_selector_ui, Tree *p_results_tree) :
+ selector_ui(p_selector_ui),
+ ui_service(p_selector_ui->vbox),
+ results_tree(p_results_tree),
+ term(p_selector_ui->search_box->get_text()),
+ empty_icon(ui_service->get_theme_icon(SNAME("ArrowRight"), SNAME("EditorIcons"))),
+ disabled_color(ui_service->get_theme_color(SNAME("disabled_font_color"), SNAME("Editor"))) {
+}
diff --git a/modules/visual_script/editor/visual_script_property_selector.h b/modules/visual_script/editor/visual_script_property_selector.h
new file mode 100644
index 0000000000..91d81bba47
--- /dev/null
+++ b/modules/visual_script/editor/visual_script_property_selector.h
@@ -0,0 +1,229 @@
+/*************************************************************************/
+/* visual_script_property_selector.h */
+/*************************************************************************/
+/* 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. */
+/*************************************************************************/
+
+#ifndef VISUALSCRIPT_PROPERTYSELECTOR_H
+#define VISUALSCRIPT_PROPERTYSELECTOR_H
+
+#include "../visual_script.h"
+#include "editor/editor_help.h"
+#include "editor/property_editor.h"
+#include "scene/gui/rich_text_label.h"
+
+class VisualScriptPropertySelector : public ConfirmationDialog {
+ GDCLASS(VisualScriptPropertySelector, ConfirmationDialog);
+
+ enum SearchFlags {
+ SEARCH_CLASSES = 1 << 0,
+ SEARCH_CONSTRUCTORS = 1 << 1,
+ SEARCH_METHODS = 1 << 2,
+ SEARCH_OPERATORS = 1 << 3,
+ SEARCH_SIGNALS = 1 << 4,
+ SEARCH_CONSTANTS = 1 << 5,
+ SEARCH_PROPERTIES = 1 << 6,
+ SEARCH_THEME_ITEMS = 1 << 7,
+ SEARCH_VISUAL_SCRIPT_NODES = 1 << 8,
+ SEARCH_ALL = SEARCH_CLASSES | SEARCH_CONSTRUCTORS | SEARCH_METHODS | SEARCH_OPERATORS | SEARCH_SIGNALS | SEARCH_CONSTANTS | SEARCH_PROPERTIES | SEARCH_THEME_ITEMS,
+ SEARCH_CASE_SENSITIVE = 1 << 29,
+ SEARCH_SHOW_HIERARCHY = 1 << 30,
+ };
+
+ enum ScopeFlags {
+ SCOPE_BASE = 1 << 0,
+ SCOPE_INHERITERS = 1 << 1,
+ SCOPE_UNRELATED = 1 << 2,
+ SCOPE_RELATED = SCOPE_BASE | SCOPE_INHERITERS,
+ SCOPE_ALL = SCOPE_BASE | SCOPE_INHERITERS | SCOPE_UNRELATED
+ };
+
+ enum ScopeCombo {
+ COMBO_RELATED,
+ COMBO_SEPARATOR,
+ COMBO_BASE,
+ COMBO_INHERITERS,
+ COMBO_UNRELATED,
+ COMBO_ALL,
+ };
+
+ LineEdit *search_box = nullptr;
+
+ Button *case_sensitive_button = nullptr;
+ Button *hierarchy_button = nullptr;
+
+ Button *search_visual_script_nodes = nullptr;
+ Button *search_classes = nullptr;
+ Button *search_operators = nullptr;
+
+ Button *search_methods = nullptr;
+ Button *search_signals = nullptr;
+ Button *search_constants = nullptr;
+ Button *search_properties = nullptr;
+ Button *search_theme_items = nullptr;
+
+ OptionButton *scope_combo = nullptr;
+ Tree *results_tree = nullptr;
+
+ class SearchRunner;
+ Ref<SearchRunner> search_runner;
+
+ void _update_icons();
+
+ void _sbox_input(const Ref<InputEvent> &p_ie);
+ void _update_results_i(int p_int);
+ void _update_results_s(String p_string);
+ void _update_results_search_all();
+ void _update_results();
+
+ void _confirmed();
+ void _item_selected();
+ void _hide_requested();
+
+ EditorHelpBit *help_bit = nullptr;
+
+ bool properties = false;
+ bool visual_script_generic = false;
+ bool connecting = false;
+ String selected;
+ Variant::Type type;
+ String base_type;
+ String base_script;
+ ObjectID script;
+ Object *instance = nullptr;
+ bool virtuals_only = false;
+ VBoxContainer *vbox = nullptr;
+
+protected:
+ void _notification(int p_what);
+ static void _bind_methods();
+
+public:
+ void select_method_from_base_type(const String &p_base, const bool p_virtuals_only = false, const bool p_connecting = true, bool clear_text = true);
+ void select_from_base_type(const String &p_base, const String &p_base_script = "", bool p_virtuals_only = false, const bool p_connecting = true, bool clear_text = true);
+ void select_from_script(const Ref<Script> &p_script, const bool p_connecting = true, bool clear_text = true);
+ void select_from_basic_type(Variant::Type p_type, const bool p_connecting = true, bool clear_text = true);
+ void select_from_action(const String &p_type, const bool p_connecting = true, bool clear_text = true);
+ void select_from_instance(Object *p_instance, const bool p_connecting = true, bool clear_text = true);
+ void select_from_visual_script(const Ref<Script> &p_script, bool clear_text = true);
+
+ void show_window(float p_screen_ratio);
+
+ VisualScriptPropertySelector();
+};
+
+class VisualScriptPropertySelector::SearchRunner : public RefCounted {
+ enum Phase {
+ PHASE_INIT,
+ PHASE_MATCH_CLASSES_INIT,
+ PHASE_NODE_CLASSES_INIT,
+ PHASE_NODE_CLASSES_BUILD,
+ PHASE_MATCH_CLASSES,
+ PHASE_CLASS_ITEMS_INIT,
+ PHASE_CLASS_ITEMS,
+ PHASE_MEMBER_ITEMS_INIT,
+ PHASE_MEMBER_ITEMS,
+ PHASE_SELECT_MATCH,
+ PHASE_MAX
+ };
+ int phase = 0;
+
+ struct ClassMatch {
+ DocData::ClassDoc *doc;
+ bool name = false;
+ String category = "";
+ Vector<DocData::MethodDoc *> constructors;
+ Vector<DocData::MethodDoc *> methods;
+ Vector<DocData::MethodDoc *> operators;
+ Vector<DocData::MethodDoc *> signals;
+ Vector<DocData::ConstantDoc *> constants;
+ Vector<DocData::PropertyDoc *> properties;
+ Vector<DocData::ThemeItemDoc *> theme_properties;
+
+ bool required() {
+ return name || methods.size() || signals.size() || constants.size() || properties.size() || theme_properties.size();
+ }
+ };
+
+ VisualScriptPropertySelector *selector_ui = nullptr;
+ Control *ui_service = nullptr;
+ Tree *results_tree = nullptr;
+ String term;
+ int search_flags = 0;
+ int scope_flags = 0;
+
+ Ref<Texture2D> empty_icon;
+ Color disabled_color;
+
+ HashMap<String, DocData::ClassDoc>::Iterator iterator_doc;
+ HashMap<String, ClassMatch> matches;
+ HashMap<String, ClassMatch>::Iterator iterator_match;
+ TreeItem *root_item = nullptr;
+ HashMap<String, TreeItem *> class_items;
+ TreeItem *matched_item = nullptr;
+ float match_highest_score = 0;
+
+ HashMap<String, DocData::ClassDoc> combined_docs;
+ List<String> vs_nodes;
+
+ bool _is_class_disabled_by_feature_profile(const StringName &p_class);
+ bool _is_class_disabled_by_scope(const StringName &p_class);
+
+ bool _slice();
+ bool _phase_init();
+ bool _phase_match_classes_init();
+ bool _phase_node_classes_init();
+ bool _phase_node_classes_build();
+ bool _phase_match_classes();
+ bool _phase_class_items_init();
+ bool _phase_class_items();
+ bool _phase_member_items_init();
+ bool _phase_member_items();
+ bool _phase_select_match();
+
+ bool _match_string(const String &p_term, const String &p_string) const;
+ bool _match_visual_script(DocData::ClassDoc &class_doc);
+ bool _match_is_hidden(DocData::ClassDoc &class_doc);
+ void _match_item(TreeItem *p_item, const String &p_text);
+ void _add_class_doc(String class_name, String inherits, String category);
+ DocData::MethodDoc _get_method_doc(MethodInfo method_info);
+ TreeItem *_create_class_hierarchy(const ClassMatch &p_match);
+ TreeItem *_create_class_item(TreeItem *p_parent, const DocData::ClassDoc *p_doc, bool p_gray);
+ TreeItem *_create_method_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const String &p_text, const DocData::MethodDoc *p_doc);
+ TreeItem *_create_signal_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::MethodDoc *p_doc);
+ TreeItem *_create_constant_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::ConstantDoc *p_doc);
+ TreeItem *_create_property_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::PropertyDoc *p_doc);
+ TreeItem *_create_theme_property_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::ThemeItemDoc *p_doc);
+ TreeItem *_create_member_item(TreeItem *p_parent, const String &p_class_name, const String &p_icon, const String &p_name, const String &p_text, const String &p_type, const String &p_metatype, const String &p_tooltip, const String &p_description);
+
+public:
+ bool work(uint64_t slot = 100000);
+
+ SearchRunner(VisualScriptPropertySelector *p_selector_ui, Tree *p_results_tree);
+};
+
+#endif // VISUALSCRIPT_PROPERTYSELECTOR_H
diff --git a/modules/visual_script/icons/VisualScript.svg b/modules/visual_script/icons/VisualScript.svg
index 2352ba5d87..bc698247c9 100644
--- a/modules/visual_script/icons/VisualScript.svg
+++ b/modules/visual_script/icons/VisualScript.svg
@@ -1 +1 @@
-<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><g transform="translate(0 -1036.4)"><ellipse cx="3" cy="1039.4" fill="#6e6e6e"/><path d="m7 1-.56445 2.2578a5 5 0 0 0 -.68945.2793l-1.9883-1.1934-1.4141 1.4141 1.1953 1.9941a5 5 0 0 0 -.28516.68555l-2.2539.5625v2h5.2715a2 2 0 0 1 -.27148-1 2 2 0 0 1 2-2 2 2 0 0 1 2 2 2 2 0 0 1 -.26953 1h5.2695v-2l-2.2578-.56445a5 5 0 0 0 -.2793-.6875l1.1934-1.9902-1.4141-1.4141-1.9941 1.1953a5 5 0 0 0 -.68555-.28516l-.5625-2.2539h-2zm-4 9v6h2a3 3 0 0 0 3-3v-3h-2v3a1 1 0 0 1 -1 1v-4zm8 0a2 2 0 0 0 -1.7324 1 2 2 0 0 0 0 2 2 2 0 0 0 1.7324 1h-2v2h2a2 2 0 0 0 1.7324-1 2 2 0 0 0 0-2 2 2 0 0 0 -1.7324-1h2v-2z" fill="#e0e0e0" transform="translate(0 1036.4)"/></g></svg>
+<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><g transform="translate(0 -1036.4)"><ellipse cx="3" cy="1039.4" fill="#e0e0e0"/><path d="m7 1-.56445 2.2578a5 5 0 0 0 -.68945.2793l-1.9883-1.1934-1.4141 1.4141 1.1953 1.9941a5 5 0 0 0 -.28516.68555l-2.2539.5625v2h5.2715a2 2 0 0 1 -.27148-1 2 2 0 0 1 2-2 2 2 0 0 1 2 2 2 2 0 0 1 -.26953 1h5.2695v-2l-2.2578-.56445a5 5 0 0 0 -.2793-.6875l1.1934-1.9902-1.4141-1.4141-1.9941 1.1953a5 5 0 0 0 -.68555-.28516l-.5625-2.2539h-2zm-4 9v6h2a3 3 0 0 0 3-3v-3h-2v3a1 1 0 0 1 -1 1v-4zm8 0a2 2 0 0 0 -1.7324 1 2 2 0 0 0 0 2 2 2 0 0 0 1.7324 1h-2v2h2a2 2 0 0 0 1.7324-1 2 2 0 0 0 0-2 2 2 0 0 0 -1.7324-1h2v-2z" fill="#e0e0e0" transform="translate(0 1036.4)"/></g></svg>
diff --git a/modules/visual_script/icons/VisualScriptInternal.svg b/modules/visual_script/icons/VisualScriptInternal.svg
new file mode 100644
index 0000000000..8ab39ad929
--- /dev/null
+++ b/modules/visual_script/icons/VisualScriptInternal.svg
@@ -0,0 +1 @@
+<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><circle cx="3" cy="3.000024" fill="#e0e0e0" r="0"/><path d="m11 10a2 2 0 0 0 -1.7324 1 2 2 0 0 0 0 2 2 2 0 0 0 1.7324 1h-2v2h2a2 2 0 0 0 1.7324-1 2 2 0 0 0 0-2 2 2 0 0 0 -1.7324-1h2v-2z" fill="#e0e0e0"/><path d="m3 10v6h2a3 3 0 0 0 3-3v-3h-2v3a1 1 0 0 1 -1 1v-4z" fill="#e0e0e0"/><path d="m7 1-.56445 2.2578a5 5 0 0 0 -.68945.2793l-1.9883-1.1934-1.4141 1.4141 1.1953 1.9941a5 5 0 0 0 -.28516.68555l-2.2539.5625v2h5.2715a2 2 0 0 1 -.27148-1 2 2 0 0 1 2-2 2 2 0 0 1 2 2 2 2 0 0 1 -.26953 1h5.2695v-2l-2.2578-.56445a5 5 0 0 0 -.2793-.6875l1.1934-1.9902-1.4141-1.4141-1.9941 1.1953a5 5 0 0 0 -.68555-.28516l-.5625-2.2539h-2z" fill="none" stroke="#e0e0e0"/></svg>
diff --git a/modules/visual_script/register_types.cpp b/modules/visual_script/register_types.cpp
index 4c7b66e368..04a7442d0a 100644
--- a/modules/visual_script/register_types.cpp
+++ b/modules/visual_script/register_types.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -34,7 +34,6 @@
#include "core/io/resource_loader.h"
#include "visual_script.h"
#include "visual_script_builtin_funcs.h"
-#include "visual_script_editor.h"
#include "visual_script_expression.h"
#include "visual_script_flow_control.h"
#include "visual_script_func_nodes.h"
@@ -42,99 +41,110 @@
#include "visual_script_yield_nodes.h"
VisualScriptLanguage *visual_script_language = nullptr;
+
#ifdef TOOLS_ENABLED
-static _VisualScriptEditor *vs_editor_singleton = nullptr;
+#include "editor/visual_script_editor.h"
+static VisualScriptCustomNodes *vs_custom_nodes_singleton = nullptr;
#endif
-void register_visual_script_types() {
- visual_script_language = memnew(VisualScriptLanguage);
- //script_language_gd->init();
- ScriptServer::register_language(visual_script_language);
-
- ClassDB::register_class<VisualScript>();
- ClassDB::register_virtual_class<VisualScriptNode>();
- ClassDB::register_class<VisualScriptFunctionState>();
- ClassDB::register_class<VisualScriptFunction>();
- ClassDB::register_virtual_class<VisualScriptLists>();
- ClassDB::register_class<VisualScriptComposeArray>();
- ClassDB::register_class<VisualScriptOperator>();
- ClassDB::register_class<VisualScriptVariableSet>();
- ClassDB::register_class<VisualScriptVariableGet>();
- ClassDB::register_class<VisualScriptConstant>();
- ClassDB::register_class<VisualScriptIndexGet>();
- ClassDB::register_class<VisualScriptIndexSet>();
- ClassDB::register_class<VisualScriptGlobalConstant>();
- ClassDB::register_class<VisualScriptClassConstant>();
- ClassDB::register_class<VisualScriptMathConstant>();
- ClassDB::register_class<VisualScriptBasicTypeConstant>();
- ClassDB::register_class<VisualScriptEngineSingleton>();
- ClassDB::register_class<VisualScriptSceneNode>();
- ClassDB::register_class<VisualScriptSceneTree>();
- ClassDB::register_class<VisualScriptResourcePath>();
- ClassDB::register_class<VisualScriptSelf>();
- ClassDB::register_class<VisualScriptCustomNode>();
- ClassDB::register_class<VisualScriptSubCall>();
- ClassDB::register_class<VisualScriptComment>();
- ClassDB::register_class<VisualScriptConstructor>();
- ClassDB::register_class<VisualScriptLocalVar>();
- ClassDB::register_class<VisualScriptLocalVarSet>();
- ClassDB::register_class<VisualScriptInputAction>();
- ClassDB::register_class<VisualScriptDeconstruct>();
- ClassDB::register_class<VisualScriptPreload>();
- ClassDB::register_class<VisualScriptTypeCast>();
-
- ClassDB::register_class<VisualScriptFunctionCall>();
- ClassDB::register_class<VisualScriptPropertySet>();
- ClassDB::register_class<VisualScriptPropertyGet>();
- //ClassDB::register_type<VisualScriptScriptCall>();
- ClassDB::register_class<VisualScriptEmitSignal>();
-
- ClassDB::register_class<VisualScriptReturn>();
- ClassDB::register_class<VisualScriptCondition>();
- ClassDB::register_class<VisualScriptWhile>();
- ClassDB::register_class<VisualScriptIterator>();
- ClassDB::register_class<VisualScriptSequence>();
- //ClassDB::register_class<VisualScriptInputFilter>();
- ClassDB::register_class<VisualScriptSwitch>();
- ClassDB::register_class<VisualScriptSelect>();
-
- ClassDB::register_class<VisualScriptYield>();
- ClassDB::register_class<VisualScriptYieldSignal>();
-
- ClassDB::register_class<VisualScriptBuiltinFunc>();
-
- ClassDB::register_class<VisualScriptExpression>();
-
- register_visual_script_nodes();
- register_visual_script_func_nodes();
- register_visual_script_builtin_func_node();
- register_visual_script_flow_control_nodes();
- register_visual_script_yield_nodes();
- register_visual_script_expression_node();
+void initialize_visual_script_module(ModuleInitializationLevel p_level) {
+ if (p_level == MODULE_INITIALIZATION_LEVEL_SERVERS) {
+ visual_script_language = memnew(VisualScriptLanguage);
+ //script_language_gd->init();
+ ScriptServer::register_language(visual_script_language);
+
+ GDREGISTER_CLASS(VisualScript);
+ GDREGISTER_ABSTRACT_CLASS(VisualScriptNode);
+ GDREGISTER_CLASS(VisualScriptFunctionState);
+ GDREGISTER_CLASS(VisualScriptFunction);
+ GDREGISTER_ABSTRACT_CLASS(VisualScriptLists);
+ GDREGISTER_CLASS(VisualScriptComposeArray);
+ GDREGISTER_CLASS(VisualScriptOperator);
+ GDREGISTER_CLASS(VisualScriptVariableSet);
+ GDREGISTER_CLASS(VisualScriptVariableGet);
+ GDREGISTER_CLASS(VisualScriptConstant);
+ GDREGISTER_CLASS(VisualScriptIndexGet);
+ GDREGISTER_CLASS(VisualScriptIndexSet);
+ GDREGISTER_CLASS(VisualScriptGlobalConstant);
+ GDREGISTER_CLASS(VisualScriptClassConstant);
+ GDREGISTER_CLASS(VisualScriptMathConstant);
+ GDREGISTER_CLASS(VisualScriptBasicTypeConstant);
+ GDREGISTER_CLASS(VisualScriptEngineSingleton);
+ GDREGISTER_CLASS(VisualScriptSceneNode);
+ GDREGISTER_CLASS(VisualScriptSceneTree);
+ GDREGISTER_CLASS(VisualScriptResourcePath);
+ GDREGISTER_CLASS(VisualScriptSelf);
+ GDREGISTER_CLASS(VisualScriptCustomNode);
+ GDREGISTER_CLASS(VisualScriptSubCall);
+ GDREGISTER_CLASS(VisualScriptComment);
+ GDREGISTER_CLASS(VisualScriptConstructor);
+ GDREGISTER_CLASS(VisualScriptLocalVar);
+ GDREGISTER_CLASS(VisualScriptLocalVarSet);
+ GDREGISTER_CLASS(VisualScriptInputAction);
+ GDREGISTER_CLASS(VisualScriptDeconstruct);
+ GDREGISTER_CLASS(VisualScriptPreload);
+ GDREGISTER_CLASS(VisualScriptTypeCast);
+
+ GDREGISTER_CLASS(VisualScriptFunctionCall);
+ GDREGISTER_CLASS(VisualScriptPropertySet);
+ GDREGISTER_CLASS(VisualScriptPropertyGet);
+ //ClassDB::register_type<VisualScriptScriptCall>();
+ GDREGISTER_CLASS(VisualScriptEmitSignal);
+
+ GDREGISTER_CLASS(VisualScriptReturn);
+ GDREGISTER_CLASS(VisualScriptCondition);
+ GDREGISTER_CLASS(VisualScriptWhile);
+ GDREGISTER_CLASS(VisualScriptIterator);
+ GDREGISTER_CLASS(VisualScriptSequence);
+ //GDREGISTER_CLASS(VisualScriptInputFilter);
+ GDREGISTER_CLASS(VisualScriptSwitch);
+ GDREGISTER_CLASS(VisualScriptSelect);
+
+ GDREGISTER_CLASS(VisualScriptYield);
+ GDREGISTER_CLASS(VisualScriptYieldSignal);
+
+ GDREGISTER_CLASS(VisualScriptBuiltinFunc);
+
+ GDREGISTER_CLASS(VisualScriptExpression);
+
+ register_visual_script_nodes();
+ register_visual_script_func_nodes();
+ register_visual_script_builtin_func_node();
+ register_visual_script_flow_control_nodes();
+ register_visual_script_yield_nodes();
+ register_visual_script_expression_node();
+ }
#ifdef TOOLS_ENABLED
- ClassDB::set_current_api(ClassDB::API_EDITOR);
- ClassDB::register_class<_VisualScriptEditor>();
- ClassDB::set_current_api(ClassDB::API_CORE);
- vs_editor_singleton = memnew(_VisualScriptEditor);
- Engine::get_singleton()->add_singleton(Engine::Singleton("VisualScriptEditor", _VisualScriptEditor::get_singleton()));
-
- VisualScriptEditor::register_editor();
+ if (p_level == MODULE_INITIALIZATION_LEVEL_EDITOR) {
+ ClassDB::set_current_api(ClassDB::API_EDITOR);
+ GDREGISTER_CLASS(VisualScriptCustomNodes);
+ ClassDB::set_current_api(ClassDB::API_CORE);
+ vs_custom_nodes_singleton = memnew(VisualScriptCustomNodes);
+ Engine::get_singleton()->add_singleton(Engine::Singleton("VisualScriptCustomNodes", VisualScriptCustomNodes::get_singleton()));
+
+ VisualScriptEditor::register_editor();
+ }
#endif
}
-void unregister_visual_script_types() {
- unregister_visual_script_nodes();
+void uninitialize_visual_script_module(ModuleInitializationLevel p_level) {
+ if (p_level == MODULE_INITIALIZATION_LEVEL_SERVERS) {
+ unregister_visual_script_nodes();
- ScriptServer::unregister_language(visual_script_language);
+ ScriptServer::unregister_language(visual_script_language);
+
+ if (visual_script_language) {
+ memdelete(visual_script_language);
+ }
+ }
#ifdef TOOLS_ENABLED
- VisualScriptEditor::free_clipboard();
- if (vs_editor_singleton) {
- memdelete(vs_editor_singleton);
+ if (p_level == MODULE_INITIALIZATION_LEVEL_EDITOR) {
+ VisualScriptEditor::free_clipboard();
+ if (vs_custom_nodes_singleton) {
+ memdelete(vs_custom_nodes_singleton);
+ }
}
#endif
- if (visual_script_language) {
- memdelete(visual_script_language);
- }
}
diff --git a/modules/visual_script/register_types.h b/modules/visual_script/register_types.h
index b02a93ebc1..90f84de11c 100644
--- a/modules/visual_script/register_types.h
+++ b/modules/visual_script/register_types.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -31,7 +31,9 @@
#ifndef VISUAL_SCRIPT_REGISTER_TYPES_H
#define VISUAL_SCRIPT_REGISTER_TYPES_H
-void register_visual_script_types();
-void unregister_visual_script_types();
+#include "modules/register_module_types.h"
+
+void initialize_visual_script_module(ModuleInitializationLevel p_level);
+void uninitialize_visual_script_module(ModuleInitializationLevel p_level);
#endif // VISUAL_SCRIPT_REGISTER_TYPES_H
diff --git a/modules/visual_script/visual_script.cpp b/modules/visual_script/visual_script.cpp
index e91ae46a57..c4fafb6676 100644
--- a/modules/visual_script/visual_script.cpp
+++ b/modules/visual_script/visual_script.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -46,7 +46,7 @@ bool VisualScriptNode::is_breakpoint() const {
}
void VisualScriptNode::ports_changed_notify() {
- emit_signal("ports_changed");
+ emit_signal(SNAME("ports_changed"));
}
void VisualScriptNode::set_default_input_value(int p_port, const Variant &p_value) {
@@ -113,7 +113,7 @@ void VisualScriptNode::_bind_methods() {
ClassDB::bind_method(D_METHOD("_set_default_input_values", "values"), &VisualScriptNode::_set_default_input_values);
ClassDB::bind_method(D_METHOD("_get_default_input_values"), &VisualScriptNode::_get_default_input_values);
- ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "_default_input_values", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_default_input_values", "_get_default_input_values");
+ ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "_default_input_values", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "_set_default_input_values", "_get_default_input_values");
ADD_SIGNAL(MethodInfo("ports_changed"));
}
@@ -209,8 +209,9 @@ Vector2 VisualScript::get_scroll() const {
}
void VisualScript::get_function_list(List<StringName> *r_functions) const {
- functions.get_key_list(r_functions);
- // r_functions->sort_custom<StringName::AlphCompare>(); // Don't force sorting.
+ for (const KeyValue<StringName, Function> &E : functions) {
+ r_functions->push_back(E.key);
+ }
}
int VisualScript::get_function_node_id(const StringName &p_name) const {
@@ -229,12 +230,12 @@ void VisualScript::_node_ports_changed(int p_id) {
{
List<SequenceConnection> to_remove;
- for (Set<SequenceConnection>::Element *E = sequence_connections.front(); E; E = E->next()) {
- if (E->get().from_node == p_id && E->get().from_output >= vsn->get_output_sequence_port_count()) {
- to_remove.push_back(E->get());
+ for (const SequenceConnection &E : sequence_connections) {
+ if (E.from_node == p_id && E.from_output >= vsn->get_output_sequence_port_count()) {
+ to_remove.push_back(E);
}
- if (E->get().to_node == p_id && !vsn->has_input_sequence_port()) {
- to_remove.push_back(E->get());
+ if (E.to_node == p_id && !vsn->has_input_sequence_port()) {
+ to_remove.push_back(E);
}
}
@@ -247,12 +248,12 @@ void VisualScript::_node_ports_changed(int p_id) {
{
List<DataConnection> to_remove;
- for (Set<DataConnection>::Element *E = data_connections.front(); E; E = E->next()) {
- if (E->get().from_node == p_id && E->get().from_port >= vsn->get_output_value_port_count()) {
- to_remove.push_back(E->get());
+ for (const DataConnection &E : data_connections) {
+ if (E.from_node == p_id && E.from_port >= vsn->get_output_value_port_count()) {
+ to_remove.push_back(E);
}
- if (E->get().to_node == p_id && E->get().to_port >= vsn->get_input_value_port_count()) {
- to_remove.push_back(E->get());
+ if (E.to_node == p_id && E.to_port >= vsn->get_input_value_port_count()) {
+ to_remove.push_back(E);
}
}
@@ -264,13 +265,14 @@ void VisualScript::_node_ports_changed(int p_id) {
#ifdef TOOLS_ENABLED
set_edited(true); // Something changed, let's set as edited.
- emit_signal("node_ports_changed", p_id);
+ emit_signal(SNAME("node_ports_changed"), p_id);
#endif
}
void VisualScript::add_node(int p_id, const Ref<VisualScriptNode> &p_node, const Point2 &p_pos) {
ERR_FAIL_COND(instances.size());
ERR_FAIL_COND(nodes.has(p_id)); // ID can exist only one in script.
+ ERR_FAIL_COND(p_node.is_null());
NodeData nd;
nd.node = p_node;
@@ -290,9 +292,9 @@ void VisualScript::remove_node(int p_id) {
{
List<SequenceConnection> to_remove;
- for (Set<SequenceConnection>::Element *E = sequence_connections.front(); E; E = E->next()) {
- if (E->get().from_node == p_id || E->get().to_node == p_id) {
- to_remove.push_back(E->get());
+ for (const SequenceConnection &E : sequence_connections) {
+ if (E.from_node == p_id || E.to_node == p_id) {
+ to_remove.push_back(E);
}
}
@@ -305,9 +307,9 @@ void VisualScript::remove_node(int p_id) {
{
List<DataConnection> to_remove;
- for (Set<DataConnection>::Element *E = data_connections.front(); E; E = E->next()) {
- if (E->get().from_node == p_id || E->get().to_node == p_id) {
- to_remove.push_back(E->get());
+ for (const DataConnection &E : data_connections) {
+ if (E.from_node == p_id || E.to_node == p_id) {
+ to_remove.push_back(E);
}
}
@@ -345,7 +347,9 @@ Point2 VisualScript::get_node_position(int p_id) const {
}
void VisualScript::get_node_list(List<int> *r_nodes) const {
- nodes.get_key_list(r_nodes);
+ for (const KeyValue<int, NodeData> &E : nodes) {
+ r_nodes->push_back(E.key);
+ }
}
void VisualScript::sequence_connect(int p_from_node, int p_from_output, int p_to_node) {
@@ -380,8 +384,8 @@ bool VisualScript::has_sequence_connection(int p_from_node, int p_from_output, i
}
void VisualScript::get_sequence_connection_list(List<SequenceConnection> *r_connection) const {
- for (const Set<SequenceConnection>::Element *E = sequence_connections.front(); E; E = E->next()) {
- r_connection->push_back(E->get());
+ for (const SequenceConnection &E : sequence_connections) {
+ r_connection->push_back(E);
}
}
@@ -422,8 +426,8 @@ bool VisualScript::has_data_connection(int p_from_node, int p_from_port, int p_t
}
bool VisualScript::is_input_value_port_connected(int p_node, int p_port) const {
- for (const Set<DataConnection>::Element *E = data_connections.front(); E; E = E->next()) {
- if (E->get().to_node == p_node && E->get().to_port == p_port) {
+ for (const DataConnection &E : data_connections) {
+ if (E.to_node == p_node && E.to_port == p_port) {
return true;
}
}
@@ -431,10 +435,10 @@ bool VisualScript::is_input_value_port_connected(int p_node, int p_port) const {
}
bool VisualScript::get_input_value_port_connection_source(int p_node, int p_port, int *r_node, int *r_port) const {
- for (const Set<DataConnection>::Element *E = data_connections.front(); E; E = E->next()) {
- if (E->get().to_node == p_node && E->get().to_port == p_port) {
- *r_node = E->get().from_node;
- *r_port = E->get().from_port;
+ for (const DataConnection &E : data_connections) {
+ if (E.to_node == p_node && E.to_port == p_port) {
+ *r_node = E.from_node;
+ *r_port = E.from_port;
return true;
}
}
@@ -442,8 +446,8 @@ bool VisualScript::get_input_value_port_connection_source(int p_node, int p_port
}
void VisualScript::get_data_connection_list(List<DataConnection> *r_connection) const {
- for (const Set<DataConnection>::Element *E = data_connections.front(); E; E = E->next()) {
- r_connection->push_back(E->get());
+ for (const DataConnection &E : data_connections) {
+ r_connection->push_back(E);
}
}
@@ -562,8 +566,9 @@ Dictionary VisualScript::_get_variable_info(const StringName &p_name) const {
}
void VisualScript::get_variable_list(List<StringName> *r_variables) const {
- variables.get_key_list(r_variables);
- // r_variables->sort_custom<StringName::AlphCompare>(); // Don't force it.
+ for (const KeyValue<StringName, Variable> &E : variables) {
+ r_variables->push_back(E.key);
+ }
}
void VisualScript::set_instance_base_type(const StringName &p_type) {
@@ -588,14 +593,14 @@ void VisualScript::rename_variable(const StringName &p_name, const StringName &p
variables.erase(p_name);
List<int> ids;
get_node_list(&ids);
- for (List<int>::Element *E = ids.front(); E; E = E->next()) {
- Ref<VisualScriptVariableGet> nodeget = get_node(E->get());
+ for (int &E : ids) {
+ Ref<VisualScriptVariableGet> nodeget = get_node(E);
if (nodeget.is_valid()) {
if (nodeget->get_variable() == p_name) {
nodeget->set_variable(p_new_name);
}
} else {
- Ref<VisualScriptVariableSet> nodeset = get_node(E->get());
+ Ref<VisualScriptVariableSet> nodeset = get_node(E);
if (nodeset.is_valid()) {
if (nodeset->get_variable() == p_name) {
nodeset->set_variable(p_new_name);
@@ -660,7 +665,7 @@ void VisualScript::custom_signal_remove_argument(const StringName &p_func, int p
ERR_FAIL_COND(instances.size());
ERR_FAIL_COND(!custom_signals.has(p_func));
ERR_FAIL_INDEX(p_argidx, custom_signals[p_func].size());
- custom_signals[p_func].remove(p_argidx);
+ custom_signals[p_func].remove_at(p_argidx);
}
int VisualScript::custom_signal_get_argument_count(const StringName &p_func) const {
@@ -701,8 +706,8 @@ void VisualScript::rename_custom_signal(const StringName &p_name, const StringNa
}
void VisualScript::get_custom_signal_list(List<StringName> *r_custom_signals) const {
- for (const Map<StringName, Vector<Argument>>::Element *E = custom_signals.front(); E; E = E->next()) {
- r_custom_signals->push_back(E->key());
+ for (const KeyValue<StringName, Vector<Argument>> &E : custom_signals) {
+ r_custom_signals->push_back(E.key);
}
r_custom_signals->sort_custom<StringName::AlphCompare>();
@@ -712,12 +717,11 @@ int VisualScript::get_available_id() const {
// This is infinitely increasing,
// so one might want to implement a better solution,
// if the there is a case for huge number of nodes to be added to visual script.
- List<int> nds;
- nodes.get_key_list(&nds);
+
int max = -1;
- for (const List<int>::Element *E = nds.front(); E; E = E->next()) {
- if (E->get() > max) {
- max = E->get();
+ for (const KeyValue<int, NodeData> &E : nodes) {
+ if (E.key > max) {
+ max = E.key;
}
}
return (max + 1);
@@ -725,7 +729,7 @@ int VisualScript::get_available_id() const {
/////////////////////////////////
-bool VisualScript::can_instance() const {
+bool VisualScript::can_instantiate() const {
return true; // ScriptServer::is_scripting_enabled();
}
@@ -747,24 +751,21 @@ void VisualScript::_update_placeholders() {
return; // No bother if no placeholders.
}
List<PropertyInfo> pinfo;
- Map<StringName, Variant> values;
-
- List<StringName> keys;
- variables.get_key_list(&keys);
+ HashMap<StringName, Variant> values;
- for (List<StringName>::Element *E = keys.front(); E; E = E->next()) {
- if (!variables[E->get()]._export) {
+ for (const KeyValue<StringName, Variable> &E : variables) {
+ if (!variables[E.key]._export) {
continue;
}
- PropertyInfo p = variables[E->get()].info;
- p.name = String(E->get());
+ PropertyInfo p = variables[E.key].info;
+ p.name = String(E.key);
pinfo.push_back(p);
- values[p.name] = variables[E->get()].default_value;
+ values[p.name] = variables[E.key].default_value;
}
- for (Set<PlaceHolderScriptInstance *>::Element *E = placeholders.front(); E; E = E->next()) {
- E->get()->update(pinfo, values);
+ for (PlaceHolderScriptInstance *E : placeholders) {
+ E->update(pinfo, values);
}
}
@@ -778,19 +779,17 @@ ScriptInstance *VisualScript::instance_create(Object *p_this) {
placeholders.insert(sins);
List<PropertyInfo> pinfo;
- Map<StringName, Variant> values;
+ HashMap<StringName, Variant> values;
- List<StringName> keys;
- variables.get_key_list(&keys);
-
- for (const List<StringName>::Element *E = keys.front(); E; E = E->next()) {
- if (!variables[E->get()]._export)
+ for (const KeyValue<StringName, Variable> &E : variables) {
+ if (!variables[E.key]._export) {
continue;
+ }
- PropertyInfo p = variables[E->get()].info;
- p.name = String(E->get());
+ PropertyInfo p = variables[E.key].info;
+ p.name = String(E.key);
pinfo.push_back(p);
- values[p.name] = variables[E->get()].default_value;
+ values[p.name] = variables[E.key].default_value;
}
sins->update(pinfo, values);
@@ -846,13 +845,13 @@ bool VisualScript::has_script_signal(const StringName &p_signal) const {
}
void VisualScript::get_script_signal_list(List<MethodInfo> *r_signals) const {
- for (const Map<StringName, Vector<Argument>>::Element *E = custom_signals.front(); E; E = E->next()) {
+ for (const KeyValue<StringName, Vector<Argument>> &E : custom_signals) {
MethodInfo mi;
- mi.name = E->key();
- for (int i = 0; i < E->get().size(); i++) {
+ mi.name = E.key;
+ for (int i = 0; i < E.value.size(); i++) {
PropertyInfo arg;
- arg.type = E->get()[i].type;
- arg.name = E->get()[i].name;
+ arg.type = E.value[i].type;
+ arg.name = E.value[i].name;
mi.arguments.push_back(arg);
}
@@ -870,14 +869,11 @@ bool VisualScript::get_property_default_value(const StringName &p_property, Vari
}
void VisualScript::get_script_method_list(List<MethodInfo> *p_list) const {
- List<StringName> funcs;
- functions.get_key_list(&funcs);
-
- for (List<StringName>::Element *E = funcs.front(); E; E = E->next()) {
+ for (const KeyValue<StringName, Function> &E : functions) {
MethodInfo mi;
- mi.name = E->get();
- if (functions[E->get()].func_id >= 0) {
- Ref<VisualScriptFunction> func = nodes[functions[E->get()].func_id].node;
+ mi.name = E.key;
+ if (functions[E.key].func_id >= 0) {
+ Ref<VisualScriptFunction> func = nodes[functions[E.key].func_id].node;
if (func.is_valid()) {
for (int i = 0; i < func->get_argument_count(); i++) {
PropertyInfo arg;
@@ -927,10 +923,11 @@ void VisualScript::get_script_property_list(List<PropertyInfo> *p_list) const {
List<StringName> vars;
get_variable_list(&vars);
- for (List<StringName>::Element *E = vars.front(); E; E = E->next()) {
- //if (!variables[E->get()]._export)
- // continue;
- PropertyInfo pi = variables[E->get()].info;
+ for (const StringName &E : vars) {
+ if (!variables[E]._export) {
+ continue;
+ }
+ PropertyInfo pi = variables[E].info;
pi.usage |= PROPERTY_USAGE_SCRIPT_VARIABLE;
p_list->push_back(pi);
}
@@ -942,10 +939,8 @@ int VisualScript::get_member_line(const StringName &p_member) const {
#ifdef TOOLS_ENABLED
bool VisualScript::are_subnodes_edited() const {
- List<int> keys;
- nodes.get_key_list(&keys);
- for (const List<int>::Element *F = keys.front(); F; F = F->next()) {
- if (nodes[F->get()].node->is_edited()) {
+ for (const KeyValue<int, NodeData> &F : nodes) {
+ if (F.value.node->is_edited()) {
return true;
}
}
@@ -953,60 +948,10 @@ bool VisualScript::are_subnodes_edited() const {
}
#endif
-Vector<ScriptNetData> VisualScript::get_rpc_methods() const {
+const Vector<Multiplayer::RPCConfig> VisualScript::get_rpc_methods() const {
return rpc_functions;
}
-uint16_t VisualScript::get_rpc_method_id(const StringName &p_method) const {
- for (int i = 0; i < rpc_functions.size(); i++) {
- if (rpc_functions[i].name == p_method) {
- return i;
- }
- }
- return UINT16_MAX;
-}
-
-StringName VisualScript::get_rpc_method(const uint16_t p_rpc_method_id) const {
- ERR_FAIL_COND_V(p_rpc_method_id >= rpc_functions.size(), StringName());
- return rpc_functions[p_rpc_method_id].name;
-}
-
-MultiplayerAPI::RPCMode VisualScript::get_rpc_mode_by_id(const uint16_t p_rpc_method_id) const {
- ERR_FAIL_COND_V(p_rpc_method_id >= rpc_functions.size(), MultiplayerAPI::RPC_MODE_DISABLED);
- return rpc_functions[p_rpc_method_id].mode;
-}
-
-MultiplayerAPI::RPCMode VisualScript::get_rpc_mode(const StringName &p_method) const {
- return get_rpc_mode_by_id(get_rpc_method_id(p_method));
-}
-
-Vector<ScriptNetData> VisualScript::get_rset_properties() const {
- return rpc_variables;
-}
-
-uint16_t VisualScript::get_rset_property_id(const StringName &p_variable) const {
- for (int i = 0; i < rpc_variables.size(); i++) {
- if (rpc_variables[i].name == p_variable) {
- return i;
- }
- }
- return UINT16_MAX;
-}
-
-StringName VisualScript::get_rset_property(const uint16_t p_rset_property_id) const {
- ERR_FAIL_COND_V(p_rset_property_id >= rpc_variables.size(), StringName());
- return rpc_variables[p_rset_property_id].name;
-}
-
-MultiplayerAPI::RPCMode VisualScript::get_rset_mode_by_id(const uint16_t p_rset_variable_id) const {
- ERR_FAIL_COND_V(p_rset_variable_id >= rpc_variables.size(), MultiplayerAPI::RPC_MODE_DISABLED);
- return rpc_variables[p_rset_variable_id].mode;
-}
-
-MultiplayerAPI::RPCMode VisualScript::get_rset_mode(const StringName &p_variable) const {
- return get_rset_mode_by_id(get_rset_property_id(p_variable));
-}
-
void VisualScript::_set_data(const Dictionary &p_data) {
Dictionary d = p_data;
if (d.has("base_type")) {
@@ -1064,17 +1009,15 @@ void VisualScript::_set_data(const Dictionary &p_data) {
// Takes all the rpc methods.
rpc_functions.clear();
- rpc_variables.clear();
- List<StringName> fns;
- functions.get_key_list(&fns);
- for (const List<StringName>::Element *E = fns.front(); E; E = E->next()) {
- if (functions[E->get()].func_id >= 0 && nodes.has(functions[E->get()].func_id)) {
- Ref<VisualScriptFunction> vsf = nodes[functions[E->get()].func_id].node;
+ for (const KeyValue<StringName, Function> &E : functions) {
+ if (E.value.func_id >= 0 && nodes.has(E.value.func_id)) {
+ Ref<VisualScriptFunction> vsf = nodes[E.value.func_id].node;
if (vsf.is_valid()) {
- if (vsf->get_rpc_mode() != MultiplayerAPI::RPC_MODE_DISABLED) {
- ScriptNetData nd;
- nd.name = E->get();
- nd.mode = vsf->get_rpc_mode();
+ if (vsf->get_rpc_mode() != Multiplayer::RPC_MODE_DISABLED) {
+ Multiplayer::RPCConfig nd;
+ nd.name = E.key;
+ nd.rpc_mode = vsf->get_rpc_mode();
+ nd.transfer_mode = Multiplayer::TRANSFER_MODE_RELIABLE; // TODO
if (rpc_functions.find(nd) == -1) {
rpc_functions.push_back(nd);
}
@@ -1084,7 +1027,7 @@ void VisualScript::_set_data(const Dictionary &p_data) {
}
// Sort so we are 100% that they are always the same.
- rpc_functions.sort_custom<SortNetData>();
+ rpc_functions.sort_custom<Multiplayer::SortRPCConfig>();
}
Dictionary VisualScript::_get_data() const {
@@ -1092,25 +1035,23 @@ Dictionary VisualScript::_get_data() const {
d["base_type"] = base_type;
Array vars;
- List<StringName> var_names;
- variables.get_key_list(&var_names);
- for (const List<StringName>::Element *E = var_names.front(); E; E = E->next()) {
- Dictionary var = _get_variable_info(E->get());
- var["name"] = E->get(); // Make sure it's the right one.
- var["default_value"] = variables[E->get()].default_value;
- var["export"] = variables[E->get()]._export;
+ for (const KeyValue<StringName, Variable> &E : variables) {
+ Dictionary var = _get_variable_info(E.key);
+ var["name"] = E.key; // Make sure it's the right one.
+ var["default_value"] = E.value.default_value;
+ var["export"] = E.value._export;
vars.push_back(var);
}
d["variables"] = vars;
Array sigs;
- for (const Map<StringName, Vector<Argument>>::Element *E = custom_signals.front(); E; E = E->next()) {
+ for (const KeyValue<StringName, Vector<Argument>> &E : custom_signals) {
Dictionary cs;
- cs["name"] = E->key();
+ cs["name"] = E.key;
Array args;
- for (int i = 0; i < E->get().size(); i++) {
- args.push_back(E->get()[i].name);
- args.push_back(E->get()[i].type);
+ for (int i = 0; i < E.value.size(); i++) {
+ args.push_back(E.value[i].name);
+ args.push_back(E.value[i].type);
}
cs["arguments"] = args;
@@ -1120,40 +1061,36 @@ Dictionary VisualScript::_get_data() const {
d["signals"] = sigs;
Array funcs;
- List<StringName> func_names;
- functions.get_key_list(&func_names);
- for (const List<StringName>::Element *E = func_names.front(); E; E = E->next()) {
+ for (const KeyValue<StringName, Function> &E : functions) {
Dictionary func;
- func["name"] = E->get();
- func["function_id"] = functions[E->get()].func_id;
+ func["name"] = E.key;
+ func["function_id"] = E.value.func_id;
funcs.push_back(func);
}
d["functions"] = funcs;
Array nds;
- List<int> node_ids;
- nodes.get_key_list(&node_ids);
- for (const List<int>::Element *F = node_ids.front(); F; F = F->next()) {
- nds.push_back(F->get());
- nds.push_back(nodes[F->get()].pos);
- nds.push_back(nodes[F->get()].node);
+ for (const KeyValue<int, NodeData> &F : nodes) {
+ nds.push_back(F.key);
+ nds.push_back(F.value.pos);
+ nds.push_back(F.value.node);
}
d["nodes"] = nds;
Array seqconns;
- for (const Set<SequenceConnection>::Element *F = sequence_connections.front(); F; F = F->next()) {
- seqconns.push_back(F->get().from_node);
- seqconns.push_back(F->get().from_output);
- seqconns.push_back(F->get().to_node);
+ for (const SequenceConnection &F : sequence_connections) {
+ seqconns.push_back(F.from_node);
+ seqconns.push_back(F.from_output);
+ seqconns.push_back(F.to_node);
}
d["sequence_connections"] = seqconns;
Array dataconns;
- for (const Set<DataConnection>::Element *F = data_connections.front(); F; F = F->next()) {
- dataconns.push_back(F->get().from_node);
- dataconns.push_back(F->get().from_port);
- dataconns.push_back(F->get().to_node);
- dataconns.push_back(F->get().to_port);
+ for (const DataConnection &F : data_connections) {
+ dataconns.push_back(F.from_node);
+ dataconns.push_back(F.from_port);
+ dataconns.push_back(F.to_node);
+ dataconns.push_back(F.to_port);
}
d["data_connections"] = dataconns;
@@ -1168,7 +1105,7 @@ void VisualScript::_bind_methods() {
ClassDB::bind_method(D_METHOD("has_function", "name"), &VisualScript::has_function);
ClassDB::bind_method(D_METHOD("remove_function", "name"), &VisualScript::remove_function);
ClassDB::bind_method(D_METHOD("rename_function", "name", "new_name"), &VisualScript::rename_function);
- ClassDB::bind_method(D_METHOD("set_scroll", "ofs"), &VisualScript::set_scroll);
+ ClassDB::bind_method(D_METHOD("set_scroll", "offset"), &VisualScript::set_scroll);
ClassDB::bind_method(D_METHOD("get_scroll"), &VisualScript::get_scroll);
ClassDB::bind_method(D_METHOD("add_node", "id", "node", "position"), &VisualScript::add_node, DEFVAL(Point2()));
@@ -1212,15 +1149,12 @@ void VisualScript::_bind_methods() {
ClassDB::bind_method(D_METHOD("remove_custom_signal", "name"), &VisualScript::remove_custom_signal);
ClassDB::bind_method(D_METHOD("rename_custom_signal", "name", "new_name"), &VisualScript::rename_custom_signal);
- //ClassDB::bind_method(D_METHOD("set_variable_info","name","info"),&VScript::set_variable_info);
- //ClassDB::bind_method(D_METHOD("get_variable_info","name"),&VScript::set_variable_info);
-
ClassDB::bind_method(D_METHOD("set_instance_base_type", "type"), &VisualScript::set_instance_base_type);
ClassDB::bind_method(D_METHOD("_set_data", "data"), &VisualScript::_set_data);
ClassDB::bind_method(D_METHOD("_get_data"), &VisualScript::_get_data);
- ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_data", "_get_data");
+ ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "_set_data", "_get_data");
ADD_SIGNAL(MethodInfo("node_ports_changed", PropertyInfo(Variant::INT, "id")));
}
@@ -1234,10 +1168,10 @@ bool VisualScript::inherits_script(const Ref<Script> &p_script) const {
return this == p_script.ptr(); // There is no inheritance in visual scripts, so this is enough.
}
-Set<int> VisualScript::get_output_sequence_ports_connected(int from_node) {
+RBSet<int> VisualScript::get_output_sequence_ports_connected(int from_node) {
List<VisualScript::SequenceConnection> *sc = memnew(List<VisualScript::SequenceConnection>);
get_sequence_connection_list(sc);
- Set<int> connected;
+ RBSet<int> connected;
for (List<VisualScript::SequenceConnection>::Element *E = sc->front(); E; E = E->next()) {
if (E->get().from_node == from_node) {
connected.insert(E->get().from_output);
@@ -1249,45 +1183,41 @@ Set<int> VisualScript::get_output_sequence_ports_connected(int from_node) {
VisualScript::~VisualScript() {
// Remove all nodes and stuff that hold data refs.
- List<int> nds;
- nodes.get_key_list(&nds);
- for (const List<int>::Element *E = nds.front(); E; E = E->next()) {
- remove_node(E->get());
+ for (const KeyValue<int, NodeData> &E : nodes) {
+ remove_node(E.key);
}
}
////////////////////////////////////////////
bool VisualScriptInstance::set(const StringName &p_name, const Variant &p_value) {
- Map<StringName, Variant>::Element *E = variables.find(p_name);
+ HashMap<StringName, Variant>::Iterator E = variables.find(p_name);
if (!E) {
return false;
}
- E->get() = p_value;
+ E->value = p_value;
return true;
}
bool VisualScriptInstance::get(const StringName &p_name, Variant &r_ret) const {
- const Map<StringName, Variant>::Element *E = variables.find(p_name);
+ HashMap<StringName, Variant>::ConstIterator E = variables.find(p_name);
if (!E) {
return false;
}
- r_ret = E->get();
+ r_ret = E->value;
return true;
}
void VisualScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const {
- List<StringName> vars;
- script->variables.get_key_list(&vars);
- for (const List<StringName>::Element *E = vars.front(); E; E = E->next()) {
- if (!script->variables[E->get()]._export) {
+ for (const KeyValue<StringName, VisualScript::Variable> &E : script->variables) {
+ if (!E.value._export) {
continue;
}
- PropertyInfo p = script->variables[E->get()].info;
- p.name = String(E->get());
+ PropertyInfo p = E.value.info;
+ p.name = String(E.key);
p.usage |= PROPERTY_USAGE_SCRIPT_VARIABLE;
p_properties->push_back(p);
}
@@ -1309,13 +1239,11 @@ Variant::Type VisualScriptInstance::get_property_type(const StringName &p_name,
}
void VisualScriptInstance::get_method_list(List<MethodInfo> *p_list) const {
- List<StringName> fns;
- script->functions.get_key_list(&fns);
- for (const List<StringName>::Element *E = fns.front(); E; E = E->next()) {
+ for (const KeyValue<StringName, VisualScript::Function> &E : script->functions) {
MethodInfo mi;
- mi.name = E->get();
- if (script->functions[E->get()].func_id >= 0 && script->nodes.has(script->functions[E->get()].func_id)) {
- Ref<VisualScriptFunction> vsf = script->nodes[script->functions[E->get()].func_id].node;
+ mi.name = E.key;
+ if (E.value.func_id >= 0 && script->nodes.has(E.value.func_id)) {
+ Ref<VisualScriptFunction> vsf = script->nodes[E.value.func_id].node;
if (vsf.is_valid()) {
for (int i = 0; i < vsf->get_argument_count(); i++) {
PropertyInfo arg;
@@ -1387,9 +1315,9 @@ void VisualScriptInstance::_dependency_step(VisualScriptNodeInstance *node, int
}
Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p_stack, int p_stack_size, VisualScriptNodeInstance *p_node, int p_flow_stack_pos, int p_pass, bool p_resuming_yield, Callable::CallError &r_error) {
- Map<StringName, Function>::Element *F = functions.find(p_method);
+ HashMap<StringName, Function>::Iterator F = functions.find(p_method);
ERR_FAIL_COND_V(!F, Variant());
- Function *f = &F->get();
+ Function *f = &F->value;
// This call goes separate, so it can be yielded and suspended.
Variant *variant_stack = (Variant *)p_stack;
@@ -1536,7 +1464,7 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p
state->flow_stack_pos = flow_stack_pos;
state->stack.resize(p_stack_size);
state->pass = p_pass;
- copymem(state->stack.ptrw(), p_stack, p_stack_size);
+ memcpy(state->stack.ptrw(), p_stack, p_stack_size);
// Step 2, run away, return directly.
r_error.error = Callable::CallError::CALL_OK;
@@ -1600,13 +1528,13 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p
// If no exit bit was set, and has sequence outputs, guess next node.
if (output >= node->sequence_output_count) {
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
- error_str = RTR("Node returned an invalid sequence output: ") + itos(output);
+ error_str = RTR("Node returned an invalid sequence output:") + " " + itos(output);
error = true;
break;
}
next = node->sequence_outputs[output];
- VSDEBUG("GOT NEXT NODE - " + (next ? itos(next->get_id()) : "NULL"));
+ VSDEBUG("GOT NEXT NODE - " + (next ? itos(next->get_id()) : "Null"));
}
if (flow_stack) {
@@ -1654,7 +1582,7 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p
if (!found) {
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
- error_str = RTR("Found sequence bit but not the node in the stack, report bug!");
+ error_str = RTR("Found sequence bit but not the node in the stack (please report).");
error = true;
break;
}
@@ -1666,7 +1594,7 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p
// Check for stack overflow.
if (flow_stack_pos + 1 >= flow_max) {
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
- error_str = RTR("Stack overflow with stack depth: ") + itos(output);
+ error_str = vformat(RTR("Stack overflow (stack size: %s). Check for infinite recursion in your script."), output);
error = true;
break;
}
@@ -1713,8 +1641,8 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p
String err_func = p_method;
int err_line = current_node_id; // Not a line but it works as one.
- if (node && (r_error.error != Callable::CallError::CALL_ERROR_INVALID_METHOD || error_str == String())) {
- if (error_str != String()) {
+ if (node && (r_error.error != Callable::CallError::CALL_ERROR_INVALID_METHOD || error_str.is_empty())) {
+ if (!error_str.is_empty()) {
error_str += " ";
}
@@ -1736,7 +1664,7 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p
// debugger break did not happen
if (!VisualScriptLanguage::singleton->debug_break(error_str, false)) {
- _err_print_error(err_func.utf8().get_data(), err_file.utf8().get_data(), err_line, error_str.utf8().get_data(), ERR_HANDLER_SCRIPT);
+ _err_print_error(err_func.utf8().get_data(), err_file.utf8().get_data(), err_line, error_str.utf8().get_data(), false, ERR_HANDLER_SCRIPT);
}
//}
@@ -1758,10 +1686,10 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p
return return_value;
}
-Variant VisualScriptInstance::call(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
+Variant VisualScriptInstance::callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
r_error.error = Callable::CallError::CALL_OK; //ok by default
- Map<StringName, Function>::Element *F = functions.find(p_method);
+ HashMap<StringName, Function>::Iterator F = functions.find(p_method);
if (!F) {
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
return Variant();
@@ -1769,7 +1697,7 @@ Variant VisualScriptInstance::call(const StringName &p_method, const Variant **p
VSDEBUG("CALLING: " + String(p_method));
- Function *f = &F->get();
+ Function *f = &F->value;
int total_stack_size = 0;
@@ -1801,16 +1729,16 @@ Variant VisualScriptInstance::call(const StringName &p_method, const Variant **p
sequence_bits[i] = false; // All starts as false.
}
- zeromem(pass_stack, f->pass_stack_size * sizeof(int));
+ memset(pass_stack, 0, f->pass_stack_size * sizeof(int));
- Map<int, VisualScriptNodeInstance *>::Element *E = instances.find(f->node);
+ HashMap<int, VisualScriptNodeInstance *>::Iterator E = instances.find(f->node);
if (!E) {
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
ERR_FAIL_V_MSG(Variant(), "No VisualScriptFunction node in function.");
}
- VisualScriptNodeInstance *node = E->get();
+ VisualScriptNodeInstance *node = E->value;
if (flow_stack) {
flow_stack[0] = node->get_id();
@@ -1851,13 +1779,13 @@ void VisualScriptInstance::notification(int p_notification) {
Variant what = p_notification;
const Variant *whatp = &what;
Callable::CallError ce;
- call(VisualScriptLanguage::singleton->notification, &whatp, 1, ce); // Do as call.
+ callp(VisualScriptLanguage::singleton->notification, &whatp, 1, ce); // Do as call.
}
String VisualScriptInstance::to_string(bool *r_valid) {
if (has_method(CoreStringNames::get_singleton()->_to_string)) {
Callable::CallError ce;
- Variant ret = call(CoreStringNames::get_singleton()->_to_string, nullptr, 0, ce);
+ Variant ret = callp(CoreStringNames::get_singleton()->_to_string, nullptr, 0, ce);
if (ce.error == Callable::CallError::CALL_OK) {
if (ret.get_type() != Variant::STRING) {
if (r_valid) {
@@ -1881,46 +1809,10 @@ Ref<Script> VisualScriptInstance::get_script() const {
return script;
}
-Vector<ScriptNetData> VisualScriptInstance::get_rpc_methods() const {
+const Vector<Multiplayer::RPCConfig> VisualScriptInstance::get_rpc_methods() const {
return script->get_rpc_methods();
}
-uint16_t VisualScriptInstance::get_rpc_method_id(const StringName &p_method) const {
- return script->get_rpc_method_id(p_method);
-}
-
-StringName VisualScriptInstance::get_rpc_method(const uint16_t p_rpc_method_id) const {
- return script->get_rpc_method(p_rpc_method_id);
-}
-
-MultiplayerAPI::RPCMode VisualScriptInstance::get_rpc_mode_by_id(const uint16_t p_rpc_method_id) const {
- return script->get_rpc_mode_by_id(p_rpc_method_id);
-}
-
-MultiplayerAPI::RPCMode VisualScriptInstance::get_rpc_mode(const StringName &p_method) const {
- return script->get_rpc_mode(p_method);
-}
-
-Vector<ScriptNetData> VisualScriptInstance::get_rset_properties() const {
- return script->get_rset_properties();
-}
-
-uint16_t VisualScriptInstance::get_rset_property_id(const StringName &p_variable) const {
- return script->get_rset_property_id(p_variable);
-}
-
-StringName VisualScriptInstance::get_rset_property(const uint16_t p_rset_property_id) const {
- return script->get_rset_property(p_rset_property_id);
-}
-
-MultiplayerAPI::RPCMode VisualScriptInstance::get_rset_mode_by_id(const uint16_t p_rset_variable_id) const {
- return script->get_rset_mode_by_id(p_rset_variable_id);
-}
-
-MultiplayerAPI::RPCMode VisualScriptInstance::get_rset_mode(const StringName &p_variable) const {
- return script->get_rset_mode(p_variable);
-}
-
void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_owner) {
script = p_script;
owner = p_owner;
@@ -1929,41 +1821,17 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o
max_input_args = 0;
max_output_args = 0;
- if (Object::cast_to<Node>(p_owner)) {
- // Turn on these if they exist and base is a node.
- Node *node = Object::cast_to<Node>(p_owner);
- if (p_script->functions.has("_process")) {
- node->set_process(true);
- }
- if (p_script->functions.has("_physics_process")) {
- node->set_physics_process(true);
- }
- if (p_script->functions.has("_input")) {
- node->set_process_input(true);
- }
- if (p_script->functions.has("_unhandled_input")) {
- node->set_process_unhandled_input(true);
- }
- if (p_script->functions.has("_unhandled_key_input")) {
- node->set_process_unhandled_key_input(true);
- }
- }
-
// Setup variables.
{
- List<StringName> keys;
- script->variables.get_key_list(&keys);
- for (const List<StringName>::Element *E = keys.front(); E; E = E->next()) {
- variables[E->get()] = script->variables[E->get()].default_value;
+ for (const KeyValue<StringName, VisualScript::Variable> &E : script->variables) {
+ variables[E.key] = E.value.default_value;
}
}
// Setup functions from sequence trees.
{
- List<StringName> keys;
- script->functions.get_key_list(&keys);
- for (const List<StringName>::Element *E = keys.front(); E; E = E->next()) {
- const VisualScript::Function vsfn = p_script->functions[E->get()];
+ for (const KeyValue<StringName, VisualScript::Function> &E : script->functions) {
+ const VisualScript::Function &vsfn = E.value;
Function function;
function.node = vsfn.func_id;
function.max_stack = 0;
@@ -1971,10 +1839,10 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o
function.pass_stack_size = 0;
function.node_count = 0;
- Map<StringName, int> local_var_indices;
+ HashMap<StringName, int> local_var_indices;
if (function.node < 0) {
- VisualScriptLanguage::singleton->debug_break_parse(get_script()->get_path(), 0, "No start node in function: " + String(E->get()));
+ VisualScriptLanguage::singleton->debug_break_parse(get_script()->get_path(), 0, "No start node in function: " + String(E.key));
ERR_CONTINUE(function.node < 0);
}
@@ -1982,7 +1850,7 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o
Ref<VisualScriptFunction> func_node = script->get_node(vsfn.func_id);
if (func_node.is_null()) {
- VisualScriptLanguage::singleton->debug_break_parse(get_script()->get_path(), 0, "No VisualScriptFunction typed start node in function: " + String(E->get()));
+ VisualScriptLanguage::singleton->debug_break_parse(get_script()->get_path(), 0, "No VisualScriptFunction typed start node in function: " + String(E.key));
}
ERR_CONTINUE(!func_node.is_valid());
@@ -1993,42 +1861,41 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o
max_input_args = MAX(max_input_args, function.argument_count);
}
// Function nodes graphs.
- Set<VisualScript::SequenceConnection> seqconns;
- Set<VisualScript::DataConnection> dataconns;
- Set<int> node_ids;
+ RBSet<VisualScript::SequenceConnection> seqconns;
+ RBSet<VisualScript::DataConnection> dataconns;
+ RBSet<int> node_ids;
node_ids.insert(function.node);
{
List<int> nd_queue;
nd_queue.push_back(function.node);
while (!nd_queue.is_empty()) {
- for (const Set<VisualScript::SequenceConnection>::Element *F = script->sequence_connections.front(); F; F = F->next()) {
- if (nd_queue.front()->get() == F->get().from_node && !node_ids.has(F->get().to_node)) {
- nd_queue.push_back(F->get().to_node);
- node_ids.insert(F->get().to_node);
+ for (const VisualScript::SequenceConnection &F : script->sequence_connections) {
+ if (nd_queue.front()->get() == F.from_node && !node_ids.has(F.to_node)) {
+ nd_queue.push_back(F.to_node);
+ node_ids.insert(F.to_node);
}
- if (nd_queue.front()->get() == F->get().from_node && !seqconns.has(F->get())) {
- seqconns.insert(F->get());
+ if (nd_queue.front()->get() == F.from_node && !seqconns.has(F)) {
+ seqconns.insert(F);
}
}
nd_queue.pop_front();
}
HashMap<int, HashMap<int, Pair<int, int>>> dc_lut; // :: to -> to_port -> (from, from_port)
- for (const Set<VisualScript::DataConnection>::Element *F = script->data_connections.front(); F; F = F->next()) {
- dc_lut[F->get().to_node][F->get().to_port] = Pair<int, int>(F->get().from_node, F->get().from_port);
+ for (const VisualScript::DataConnection &F : script->data_connections) {
+ dc_lut[F.to_node][F.to_port] = Pair<int, int>(F.from_node, F.from_port);
}
- for (const Set<int>::Element *F = node_ids.front(); F; F = F->next()) {
- nd_queue.push_back(F->get());
+ for (const int &F : node_ids) {
+ nd_queue.push_back(F);
}
List<int> dc_keys;
while (!nd_queue.is_empty()) {
int ky = nd_queue.front()->get();
- dc_lut[ky].get_key_list(&dc_keys);
- for (const List<int>::Element *F = dc_keys.front(); F; F = F->next()) {
+ for (const KeyValue<int, Pair<int, int>> &F : dc_lut[ky]) {
VisualScript::DataConnection dc;
- dc.from_node = dc_lut[ky][F->get()].first;
- dc.from_port = dc_lut[ky][F->get()].second;
+ dc.from_node = F.value.first;
+ dc.from_port = F.value.second;
dc.to_node = ky;
- dc.to_port = F->get();
+ dc.to_port = F.key;
dataconns.insert(dc);
nd_queue.push_back(dc.from_node);
node_ids.insert(dc.from_node);
@@ -2040,22 +1907,22 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o
//Multiple passes are required to set up this complex thing..
//First create the nodes.
- for (const Set<int>::Element *F = node_ids.front(); F; F = F->next()) {
- Ref<VisualScriptNode> node = script->nodes[F->get()].node;
+ for (const int &F : node_ids) {
+ Ref<VisualScriptNode> node = script->nodes[F].node;
- VisualScriptNodeInstance *instance = node->instance(this); // Create instance.
+ VisualScriptNodeInstance *instance = node->instantiate(this); // Create instance.
ERR_FAIL_COND(!instance);
instance->base = node.ptr();
- instance->id = F->get();
+ instance->id = F;
instance->input_port_count = node->get_input_value_port_count();
- instance->input_ports = NULL;
+ instance->input_ports = nullptr;
instance->output_port_count = node->get_output_value_port_count();
- instance->output_ports = NULL;
+ instance->output_ports = nullptr;
instance->sequence_output_count = node->get_output_sequence_port_count();
instance->sequence_index = function.node_count++;
- instance->sequence_outputs = NULL;
+ instance->sequence_outputs = nullptr;
instance->pass_idx = -1;
if (instance->input_port_count) {
@@ -2075,7 +1942,7 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o
if (instance->sequence_output_count) {
instance->sequence_outputs = memnew_arr(VisualScriptNodeInstance *, instance->sequence_output_count);
for (int i = 0; i < instance->sequence_output_count; i++) {
- instance->sequence_outputs[i] = NULL; // If it remains null, flow ends here.
+ instance->sequence_outputs[i] = nullptr; // If it remains null, flow ends here.
}
}
@@ -2085,10 +1952,11 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o
StringName var_name;
- if (Object::cast_to<VisualScriptLocalVar>(*node))
+ if (Object::cast_to<VisualScriptLocalVar>(*node)) {
var_name = String(Object::cast_to<VisualScriptLocalVar>(*node)->get_var_name()).strip_edges();
- else
+ } else {
var_name = String(Object::cast_to<VisualScriptLocalVarSet>(*node)->get_var_name()).strip_edges();
+ }
if (!local_var_indices.has(var_name)) {
local_var_indices[var_name] = function.max_stack;
@@ -2107,14 +1975,14 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o
max_input_args = MAX(max_input_args, instance->input_port_count);
max_output_args = MAX(max_output_args, instance->output_port_count);
- instances[F->get()] = instance;
+ instances[F] = instance;
}
function.trash_pos = function.max_stack++; // create pos for trash
// Second pass, do data connections.
- for (const Set<VisualScript::DataConnection>::Element *F = dataconns.front(); F; F = F->next()) {
- VisualScript::DataConnection dc = F->get();
+ for (const VisualScript::DataConnection &F : dataconns) {
+ VisualScript::DataConnection dc = F;
ERR_CONTINUE(!instances.has(dc.from_node));
VisualScriptNodeInstance *from = instances[dc.from_node];
ERR_CONTINUE(!instances.has(dc.to_node));
@@ -2140,8 +2008,8 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o
}
// Third pass, do sequence connections.
- for (const Set<VisualScript::SequenceConnection>::Element *F = seqconns.front(); F; F = F->next()) {
- VisualScript::SequenceConnection sc = F->get();
+ for (const VisualScript::SequenceConnection &F : seqconns) {
+ VisualScript::SequenceConnection sc = F;
ERR_CONTINUE(!instances.has(sc.from_node));
VisualScriptNodeInstance *from = instances[sc.from_node];
ERR_CONTINUE(!instances.has(sc.to_node));
@@ -2154,11 +2022,11 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o
//fourth pass:
// 1) unassigned input ports to default values
// 2) connect unassigned output ports to trash
- for (const Set<int>::Element *F = node_ids.front(); F; F = F->next()) {
- ERR_CONTINUE(!instances.has(F->get()));
+ for (const int &F : node_ids) {
+ ERR_CONTINUE(!instances.has(F));
- Ref<VisualScriptNode> node = script->nodes[F->get()].node;
- VisualScriptNodeInstance *instance = instances[F->get()];
+ Ref<VisualScriptNode> node = script->nodes[F].node;
+ VisualScriptNodeInstance *instance = instances[F];
// Connect to default values.
for (int i = 0; i < instance->input_port_count; i++) {
@@ -2177,7 +2045,7 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o
}
}
- functions[E->get()] = function;
+ functions[E.key] = function;
}
}
}
@@ -2196,8 +2064,8 @@ VisualScriptInstance::~VisualScriptInstance() {
script->instances.erase(owner);
}
- for (Map<int, VisualScriptNodeInstance *>::Element *E = instances.front(); E; E = E->next()) {
- memdelete(E->get());
+ for (const KeyValue<int, VisualScriptNodeInstance *> &E : instances) {
+ memdelete(E.value);
}
}
@@ -2252,6 +2120,7 @@ Variant VisualScriptFunctionState::_signal_callback(const Variant **p_args, int
}
void VisualScriptFunctionState::connect_to_signal(Object *p_obj, const String &p_signal, Array p_binds) {
+ ERR_FAIL_NULL(p_obj);
Vector<Variant> binds;
for (int i = 0; i < p_binds.size(); i++) {
binds.push_back(p_binds[i]);
@@ -2287,7 +2156,7 @@ Variant VisualScriptFunctionState::resume(Array p_args) {
void VisualScriptFunctionState::_bind_methods() {
ClassDB::bind_method(D_METHOD("connect_to_signal", "obj", "signals", "args"), &VisualScriptFunctionState::connect_to_signal);
- ClassDB::bind_method(D_METHOD("resume", "args"), &VisualScriptFunctionState::resume, DEFVAL(Variant()));
+ ClassDB::bind_method(D_METHOD("resume", "args"), &VisualScriptFunctionState::resume, DEFVAL(Array()));
ClassDB::bind_method(D_METHOD("is_valid"), &VisualScriptFunctionState::is_valid);
ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "_signal_callback", &VisualScriptFunctionState::_signal_callback, MethodInfo("_signal_callback"));
}
@@ -2333,29 +2202,28 @@ void VisualScriptLanguage::finish() {
void VisualScriptLanguage::get_reserved_words(List<String> *p_words) const {
}
-void VisualScriptLanguage::get_comment_delimiters(List<String> *p_delimiters) const {
+bool VisualScriptLanguage::is_control_flow_keyword(String p_keyword) const {
+ return false;
}
-void VisualScriptLanguage::get_string_delimiters(List<String> *p_delimiters) const {
+void VisualScriptLanguage::get_comment_delimiters(List<String> *p_delimiters) const {
}
-Ref<Script> VisualScriptLanguage::get_template(const String &p_class_name, const String &p_base_class_name) const {
- Ref<VisualScript> script;
- script.instance();
- script->set_instance_base_type(p_base_class_name);
- return script;
+void VisualScriptLanguage::get_string_delimiters(List<String> *p_delimiters) const {
}
bool VisualScriptLanguage::is_using_templates() {
- return true;
+ return false;
}
-void VisualScriptLanguage::make_template(const String &p_class_name, const String &p_base_class_name, Ref<Script> &p_script) {
- Ref<VisualScript> script = p_script;
+Ref<Script> VisualScriptLanguage::make_template(const String &p_template, const String &p_class_name, const String &p_base_class_name) const {
+ Ref<VisualScript> script;
+ script.instantiate();
script->set_instance_base_type(p_base_class_name);
+ return script;
}
-bool VisualScriptLanguage::validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path, List<String> *r_functions, List<ScriptLanguage::Warning> *r_warnings, Set<int> *r_safe_lines) const {
+bool VisualScriptLanguage::validate(const String &p_script, const String &p_path, List<String> *r_functions, List<ScriptLanguage::ScriptError> *r_errors, List<ScriptLanguage::Warning> *r_warnings, HashSet<int> *r_safe_lines) const {
return false;
}
@@ -2468,7 +2336,6 @@ void VisualScriptLanguage::debug_get_stack_level_locals(int p_level, List<String
const StringName *f = _call_stack[l].function;
ERR_FAIL_COND(!_call_stack[l].instance->functions.has(*f));
- //VisualScriptInstance::Function *func = &_call_stack[l].instance->functions[*f];
VisualScriptNodeInstance *node = _call_stack[l].instance->instances[*_call_stack[l].current_id];
ERR_FAIL_COND(!node);
@@ -2478,7 +2345,7 @@ void VisualScriptLanguage::debug_get_stack_level_locals(int p_level, List<String
for (int i = 0; i < node->input_port_count; i++) {
String name = node->get_base_node()->get_input_value_port_info(i).name;
- if (name == String()) {
+ if (name.is_empty()) {
name = "in_" + itos(i);
}
@@ -2498,7 +2365,7 @@ void VisualScriptLanguage::debug_get_stack_level_locals(int p_level, List<String
for (int i = 0; i < node->output_port_count; i++) {
String name = node->get_base_node()->get_output_value_port_info(i).name;
- if (name == String()) {
+ if (name.is_empty()) {
name = "out_" + itos(i);
}
@@ -2514,21 +2381,6 @@ void VisualScriptLanguage::debug_get_stack_level_locals(int p_level, List<String
p_locals->push_back("working_mem/mem_" + itos(i));
p_values->push_back((*_call_stack[l].work_mem)[i]);
}
-
- /*
- ERR_FAIL_INDEX(p_level,_debug_call_stack_pos);
-
-
- VisualFunction *f = _call_stack[l].function;
-
- List<Pair<StringName,int> > locals;
-
- f->debug_get_stack_member_state(*_call_stack[l].line,&locals);
- for( List<Pair<StringName,int> >::Element *E = locals.front();E;E=E->next() ) {
- p_locals->push_back(E->get().first);
- p_values->push_back(_call_stack[l].stack[E->get().second]);
- }
-*/
}
void VisualScriptLanguage::debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems, int p_max_depth) {
@@ -2546,10 +2398,10 @@ void VisualScriptLanguage::debug_get_stack_level_members(int p_level, List<Strin
List<StringName> vars;
vs->get_variable_list(&vars);
- for (List<StringName>::Element *E = vars.front(); E; E = E->next()) {
+ for (const StringName &E : vars) {
Variant v;
- if (_call_stack[l].instance->get_variable(E->get(), &v)) {
- p_members->push_back("variables/" + E->get());
+ if (_call_stack[l].instance->get_variable(E, &v)) {
+ p_members->push_back("variables/" + E);
p_values->push_back(v);
}
}
@@ -2614,8 +2466,8 @@ Ref<VisualScriptNode> VisualScriptLanguage::create_node_from_name(const String &
}
void VisualScriptLanguage::get_registered_node_names(List<String> *r_names) {
- for (Map<String, VisualScriptNodeRegisterFunc>::Element *E = register_funcs.front(); E; E = E->next()) {
- r_names->push_back(E->key());
+ for (const KeyValue<String, VisualScriptNodeRegisterFunc> &E : register_funcs) {
+ r_names->push_back(E.key);
}
}
diff --git a/modules/visual_script/visual_script.h b/modules/visual_script/visual_script.h
index 72362e0ef4..c2e4d0e597 100644
--- a/modules/visual_script/visual_script.h
+++ b/modules/visual_script/visual_script.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -36,6 +36,7 @@
#include "core/doc_data.h"
#include "core/object/script_language.h"
#include "core/os/thread.h"
+#include "core/templates/rb_set.h"
class VisualScriptInstance;
class VisualScriptNodeInstance;
@@ -87,7 +88,7 @@ public:
void set_breakpoint(bool p_breakpoint);
bool is_breakpoint() const;
- virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) = 0;
+ virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) = 0;
struct TypeGuess {
Variant::Type type = Variant::NIL;
@@ -214,8 +215,8 @@ private:
HashMap<int, NodeData> nodes; // Can be a sparse map.
- Set<SequenceConnection> sequence_connections;
- Set<DataConnection> data_connections;
+ RBSet<SequenceConnection> sequence_connections;
+ RBSet<DataConnection> data_connections;
Vector2 scroll;
@@ -233,16 +234,15 @@ private:
HashMap<StringName, Function> functions;
HashMap<StringName, Variable> variables;
- Map<StringName, Vector<Argument>> custom_signals;
- Vector<ScriptNetData> rpc_functions;
- Vector<ScriptNetData> rpc_variables;
+ HashMap<StringName, Vector<Argument>> custom_signals;
+ Vector<Multiplayer::RPCConfig> rpc_functions;
- Map<Object *, VisualScriptInstance *> instances;
+ HashMap<Object *, VisualScriptInstance *> instances;
bool is_tool_script;
#ifdef TOOLS_ENABLED
- Set<PlaceHolderScriptInstance *> placeholders;
+ RBSet<PlaceHolderScriptInstance *> placeholders;
// void _update_placeholder(PlaceHolderScriptInstance *p_placeholder);
virtual void _placeholder_erased(PlaceHolderScriptInstance *p_placeholder) override;
void _update_placeholders();
@@ -284,7 +284,7 @@ public:
void sequence_disconnect(int p_from_node, int p_from_output, int p_to_node);
bool has_sequence_connection(int p_from_node, int p_from_output, int p_to_node) const;
void get_sequence_connection_list(List<SequenceConnection> *r_connection) const;
- Set<int> get_output_sequence_ports_connected(int from_node);
+ RBSet<int> get_output_sequence_ports_connected(int from_node);
void data_connect(int p_from_node, int p_from_port, int p_to_node, int p_to_port);
void data_disconnect(int p_from_node, int p_from_port, int p_to_node, int p_to_port);
@@ -318,7 +318,7 @@ public:
void custom_signal_swap_argument(const StringName &p_func, int p_argidx, int p_with_argidx);
void remove_custom_signal(const StringName &p_name);
void rename_custom_signal(const StringName &p_name, const StringName &p_new_name);
- Set<int> get_output_sequence_ports_connected(const String &edited_func, int from_node);
+ RBSet<int> get_output_sequence_ports_connected(const String &edited_func, int from_node);
void get_custom_signal_list(List<StringName> *r_custom_signals) const;
@@ -326,7 +326,7 @@ public:
void set_instance_base_type(const StringName &p_type);
- virtual bool can_instance() const override;
+ virtual bool can_instantiate() const override;
virtual Ref<Script> get_base_script() const override;
virtual StringName get_instance_base_type() const override;
@@ -339,8 +339,8 @@ public:
virtual Error reload(bool p_keep_state = false) override;
#ifdef TOOLS_ENABLED
- virtual const Vector<DocData::ClassDoc> &get_documentation() const override {
- static Vector<DocData::ClassDoc> docs;
+ virtual Vector<DocData::ClassDoc> get_documentation() const override {
+ Vector<DocData::ClassDoc> docs;
return docs;
}
#endif // TOOLS_ENABLED
@@ -363,17 +363,7 @@ public:
virtual int get_member_line(const StringName &p_member) const override;
- virtual Vector<ScriptNetData> get_rpc_methods() const override;
- virtual uint16_t get_rpc_method_id(const StringName &p_method) const override;
- virtual StringName get_rpc_method(const uint16_t p_rpc_method_id) const override;
- virtual MultiplayerAPI::RPCMode get_rpc_mode_by_id(const uint16_t p_rpc_method_id) const override;
- virtual MultiplayerAPI::RPCMode get_rpc_mode(const StringName &p_method) const override;
-
- virtual Vector<ScriptNetData> get_rset_properties() const override;
- virtual uint16_t get_rset_property_id(const StringName &p_property) const override;
- virtual StringName get_rset_property(const uint16_t p_rset_property_id) const override;
- virtual MultiplayerAPI::RPCMode get_rset_mode_by_id(const uint16_t p_rpc_method_id) const override;
- virtual MultiplayerAPI::RPCMode get_rset_mode(const StringName &p_variable) const override;
+ virtual const Vector<Multiplayer::RPCConfig> get_rpc_methods() const override;
#ifdef TOOLS_ENABLED
virtual bool are_subnodes_edited() const;
@@ -387,8 +377,8 @@ class VisualScriptInstance : public ScriptInstance {
Object *owner = nullptr;
Ref<VisualScript> script;
- Map<StringName, Variant> variables; // Using variable path, not script.
- Map<int, VisualScriptNodeInstance *> instances;
+ HashMap<StringName, Variant> variables; // Using variable path, not script.
+ HashMap<int, VisualScriptNodeInstance *> instances;
struct Function {
int node = 0;
@@ -400,7 +390,7 @@ class VisualScriptInstance : public ScriptInstance {
int argument_count = 0;
};
- Map<StringName, Function> functions;
+ HashMap<StringName, Function> functions;
Vector<Variant> default_values;
int max_input_args = 0;
@@ -421,27 +411,27 @@ public:
virtual void get_method_list(List<MethodInfo> *p_list) const;
virtual bool has_method(const StringName &p_method) const;
- virtual Variant call(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error);
+ virtual Variant callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error);
virtual void notification(int p_notification);
String to_string(bool *r_valid);
bool set_variable(const StringName &p_variable, const Variant &p_value) {
- Map<StringName, Variant>::Element *E = variables.find(p_variable);
+ HashMap<StringName, Variant>::Iterator E = variables.find(p_variable);
if (!E) {
return false;
}
- E->get() = p_value;
+ E->value = p_value;
return true;
}
bool get_variable(const StringName &p_variable, Variant *r_variable) const {
- const Map<StringName, Variant>::Element *E = variables.find(p_variable);
+ HashMap<StringName, Variant>::ConstIterator E = variables.find(p_variable);
if (!E) {
return false;
}
- *r_variable = E->get();
+ *r_variable = E->value;
return true;
}
@@ -454,24 +444,14 @@ public:
virtual ScriptLanguage *get_language();
- virtual Vector<ScriptNetData> get_rpc_methods() const;
- virtual uint16_t get_rpc_method_id(const StringName &p_method) const;
- virtual StringName get_rpc_method(const uint16_t p_rpc_method_id) const;
- virtual MultiplayerAPI::RPCMode get_rpc_mode_by_id(const uint16_t p_rpc_method_id) const;
- virtual MultiplayerAPI::RPCMode get_rpc_mode(const StringName &p_method) const;
-
- virtual Vector<ScriptNetData> get_rset_properties() const;
- virtual uint16_t get_rset_property_id(const StringName &p_property) const;
- virtual StringName get_rset_property(const uint16_t p_rset_property_id) const;
- virtual MultiplayerAPI::RPCMode get_rset_mode_by_id(const uint16_t p_rpc_method_id) const;
- virtual MultiplayerAPI::RPCMode get_rset_mode(const StringName &p_variable) const;
+ virtual const Vector<Multiplayer::RPCConfig> get_rpc_methods() const;
VisualScriptInstance();
~VisualScriptInstance();
};
-class VisualScriptFunctionState : public Reference {
- GDCLASS(VisualScriptFunctionState, Reference);
+class VisualScriptFunctionState : public RefCounted {
+ GDCLASS(VisualScriptFunctionState, RefCounted);
friend class VisualScriptInstance;
ObjectID instance_id;
@@ -501,7 +481,7 @@ public:
typedef Ref<VisualScriptNode> (*VisualScriptNodeRegisterFunc)(const String &p_type);
class VisualScriptLanguage : public ScriptLanguage {
- Map<String, VisualScriptNodeRegisterFunc> register_funcs;
+ HashMap<String, VisualScriptNodeRegisterFunc> register_funcs;
struct CallLevel {
Variant *stack = nullptr;
@@ -516,7 +496,7 @@ class VisualScriptLanguage : public ScriptLanguage {
String _debug_error;
int _debug_call_stack_pos = 0;
int _debug_max_call_stack;
- CallLevel *_call_stack;
+ CallLevel *_call_stack = nullptr;
public:
StringName notification = "_notification";
@@ -542,7 +522,7 @@ public:
if (_debug_call_stack_pos >= _debug_max_call_stack) {
// Stack overflow.
- _debug_error = "Stack Overflow (Stack Size: " + itos(_debug_max_call_stack) + ")";
+ _debug_error = vformat("Stack overflow (stack size: %s). Check for infinite recursion in your script.", _debug_max_call_stack);
EngineDebugger::get_script_debugger()->debug(this);
return;
}
@@ -565,7 +545,7 @@ public:
}
if (_debug_call_stack_pos == 0) {
- _debug_error = "Stack Underflow (Engine Bug)";
+ _debug_error = "Stack underflow (engine bug), please report.";
EngineDebugger::get_script_debugger()->debug(this);
return;
}
@@ -575,56 +555,56 @@ public:
//////////////////////////////////////
- virtual String get_name() const;
+ virtual String get_name() const override;
/* LANGUAGE FUNCTIONS */
- virtual void init();
- virtual String get_type() const;
- virtual String get_extension() const;
- virtual Error execute_file(const String &p_path);
- virtual void finish();
+ virtual void init() override;
+ virtual String get_type() const override;
+ virtual String get_extension() const override;
+ virtual Error execute_file(const String &p_path) override;
+ virtual void finish() override;
/* EDITOR FUNCTIONS */
- virtual void get_reserved_words(List<String> *p_words) const;
- virtual void get_comment_delimiters(List<String> *p_delimiters) const;
- virtual void get_string_delimiters(List<String> *p_delimiters) const;
- virtual Ref<Script> get_template(const String &p_class_name, const String &p_base_class_name) const;
- virtual bool is_using_templates();
- virtual void make_template(const String &p_class_name, const String &p_base_class_name, Ref<Script> &p_script);
- virtual bool validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path = "", List<String> *r_functions = nullptr, List<ScriptLanguage::Warning> *r_warnings = nullptr, Set<int> *r_safe_lines = nullptr) const;
- virtual Script *create_script() const;
- virtual bool has_named_classes() const;
- virtual bool supports_builtin_mode() const;
- virtual int find_function(const String &p_function, const String &p_code) const;
- virtual String make_function(const String &p_class, const String &p_name, const PackedStringArray &p_args) const;
- virtual void auto_indent_code(String &p_code, int p_from_line, int p_to_line) const;
- virtual void add_global_constant(const StringName &p_variable, const Variant &p_value);
+ virtual void get_reserved_words(List<String> *p_words) const override;
+ virtual bool is_control_flow_keyword(String p_keyword) const override;
+ virtual void get_comment_delimiters(List<String> *p_delimiters) const override;
+ virtual void get_string_delimiters(List<String> *p_delimiters) const override;
+ virtual bool is_using_templates() override;
+ virtual Ref<Script> make_template(const String &p_template, const String &p_class_name, const String &p_base_class_name) const override;
+ virtual bool validate(const String &p_script, const String &p_path = "", List<String> *r_functions = nullptr, List<ScriptLanguage::ScriptError> *r_errors = nullptr, List<ScriptLanguage::Warning> *r_warnings = nullptr, HashSet<int> *r_safe_lines = nullptr) const override;
+ virtual Script *create_script() const override;
+ virtual bool has_named_classes() const override;
+ virtual bool supports_builtin_mode() const override;
+ virtual int find_function(const String &p_function, const String &p_code) const override;
+ virtual String make_function(const String &p_class, const String &p_name, const PackedStringArray &p_args) const override;
+ virtual void auto_indent_code(String &p_code, int p_from_line, int p_to_line) const override;
+ virtual void add_global_constant(const StringName &p_variable, const Variant &p_value) override;
/* DEBUGGER FUNCTIONS */
- virtual String debug_get_error() const;
- virtual int debug_get_stack_level_count() const;
- virtual int debug_get_stack_level_line(int p_level) const;
- virtual String debug_get_stack_level_function(int p_level) const;
- virtual String debug_get_stack_level_source(int p_level) const;
- virtual void debug_get_stack_level_locals(int p_level, List<String> *p_locals, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1);
- virtual void debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1);
- virtual void debug_get_globals(List<String> *p_locals, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1);
- virtual String debug_parse_stack_level_expression(int p_level, const String &p_expression, int p_max_subitems = -1, int p_max_depth = -1);
-
- virtual void reload_all_scripts();
- virtual void reload_tool_script(const Ref<Script> &p_script, bool p_soft_reload);
+ virtual String debug_get_error() const override;
+ virtual int debug_get_stack_level_count() const override;
+ virtual int debug_get_stack_level_line(int p_level) const override;
+ virtual String debug_get_stack_level_function(int p_level) const override;
+ virtual String debug_get_stack_level_source(int p_level) const override;
+ virtual void debug_get_stack_level_locals(int p_level, List<String> *p_locals, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1) override;
+ virtual void debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1) override;
+ virtual void debug_get_globals(List<String> *p_locals, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1) override;
+ virtual String debug_parse_stack_level_expression(int p_level, const String &p_expression, int p_max_subitems = -1, int p_max_depth = -1) override;
+
+ virtual void reload_all_scripts() override;
+ virtual void reload_tool_script(const Ref<Script> &p_script, bool p_soft_reload) override;
/* LOADER FUNCTIONS */
- virtual void get_recognized_extensions(List<String> *p_extensions) const;
- virtual void get_public_functions(List<MethodInfo> *p_functions) const;
- virtual void get_public_constants(List<Pair<String, Variant>> *p_constants) const;
+ virtual void get_recognized_extensions(List<String> *p_extensions) const override;
+ virtual void get_public_functions(List<MethodInfo> *p_functions) const override;
+ virtual void get_public_constants(List<Pair<String, Variant>> *p_constants) const override;
- virtual void profiling_start();
- virtual void profiling_stop();
+ virtual void profiling_start() override;
+ virtual void profiling_stop() override;
- virtual int profiling_get_accumulated_data(ProfilingInfo *p_info_arr, int p_info_max);
- virtual int profiling_get_frame_data(ProfilingInfo *p_info_arr, int p_info_max);
+ virtual int profiling_get_accumulated_data(ProfilingInfo *p_info_arr, int p_info_max) override;
+ virtual int profiling_get_frame_data(ProfilingInfo *p_info_arr, int p_info_max) override;
void add_register_func(const String &p_name, VisualScriptNodeRegisterFunc p_func);
void remove_register_func(const String &p_name);
@@ -639,7 +619,7 @@ public:
template <class T>
static Ref<VisualScriptNode> create_node_generic(const String &p_name) {
Ref<T> node;
- node.instance();
+ node.instantiate();
return node;
}
diff --git a/modules/visual_script/visual_script_builtin_funcs.cpp b/modules/visual_script/visual_script_builtin_funcs.cpp
index 7ca14fbca8..44e792869d 100644
--- a/modules/visual_script/visual_script_builtin_funcs.cpp
+++ b/modules/visual_script/visual_script_builtin_funcs.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -33,7 +33,7 @@
#include "core/io/marshalls.h"
#include "core/math/math_funcs.h"
#include "core/object/class_db.h"
-#include "core/object/reference.h"
+#include "core/object/ref_counted.h"
#include "core/os/os.h"
#include "core/variant/variant_parser.h"
@@ -65,25 +65,25 @@ const char *VisualScriptBuiltinFunc::func_name[VisualScriptBuiltinFunc::FUNC_MAX
"step_decimals",
"snapped",
"lerp",
+ "cubic_interpolate",
"inverse_lerp",
"range_lerp",
"move_toward",
- "dectime",
"randomize",
"randi",
"randf",
- "randf_range",
"randi_range",
+ "randf_range",
+ "randfn",
"seed",
"rand_seed",
"deg2rad",
"rad2deg",
"linear2db",
"db2linear",
- "polar2cartesian",
- "cartesian2polar",
"wrapi",
"wrapf",
+ "pingpong",
"max",
"min",
"clamp",
@@ -97,6 +97,7 @@ const char *VisualScriptBuiltinFunc::func_name[VisualScriptBuiltinFunc::FUNC_MAX
"print",
"printerr",
"printraw",
+ "print_verbose",
"var2str",
"str2var",
"var2bytes",
@@ -132,6 +133,8 @@ bool VisualScriptBuiltinFunc::has_input_sequence_port() const {
case TEXT_PRINT:
case TEXT_PRINTERR:
case TEXT_PRINTRAW:
+ case TEXT_PRINT_VERBOSE:
+ case MATH_SEED:
return true;
default:
return false;
@@ -179,6 +182,7 @@ int VisualScriptBuiltinFunc::get_func_argument_count(BuiltinFunc p_func) {
case TEXT_PRINT:
case TEXT_PRINTERR:
case TEXT_PRINTRAW:
+ case TEXT_PRINT_VERBOSE:
case VAR_TO_STR:
case STR_TO_VAR:
case TYPE_EXISTS:
@@ -189,13 +193,13 @@ int VisualScriptBuiltinFunc::get_func_argument_count(BuiltinFunc p_func) {
case MATH_FMOD:
case MATH_FPOSMOD:
case MATH_POSMOD:
+ case MATH_PINGPONG:
case MATH_POW:
case MATH_EASE:
case MATH_SNAPPED:
- case MATH_RANDF_RANGE:
case MATH_RANDI_RANGE:
- case MATH_POLAR2CARTESIAN:
- case MATH_CARTESIAN2POLAR:
+ case MATH_RANDF_RANGE:
+ case MATH_RANDFN:
case LOGIC_MAX:
case LOGIC_MIN:
case TYPE_CONVERT:
@@ -205,11 +209,11 @@ int VisualScriptBuiltinFunc::get_func_argument_count(BuiltinFunc p_func) {
case MATH_INVERSE_LERP:
case MATH_SMOOTHSTEP:
case MATH_MOVE_TOWARD:
- case MATH_DECTIME:
case MATH_WRAP:
case MATH_WRAPF:
case LOGIC_CLAMP:
return 3;
+ case MATH_CUBIC_INTERPOLATE:
case MATH_RANGE_LERP:
return 5;
case FUNC_MAX: {
@@ -228,6 +232,7 @@ int VisualScriptBuiltinFunc::get_output_value_port_count() const {
case TEXT_PRINT:
case TEXT_PRINTERR:
case TEXT_PRINTRAW:
+ case TEXT_PRINT_VERBOSE:
case MATH_SEED:
return 0;
case MATH_RANDSEED:
@@ -326,6 +331,19 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const
return PropertyInfo(Variant::FLOAT, "weight");
}
} break;
+ case MATH_CUBIC_INTERPOLATE: {
+ if (p_idx == 0) {
+ return PropertyInfo(Variant::FLOAT, "from");
+ } else if (p_idx == 1) {
+ return PropertyInfo(Variant::FLOAT, "to");
+ } else if (p_idx == 2) {
+ return PropertyInfo(Variant::FLOAT, "pre");
+ } else if (p_idx == 3) {
+ return PropertyInfo(Variant::FLOAT, "post");
+ } else {
+ return PropertyInfo(Variant::FLOAT, "weight");
+ }
+ } break;
case MATH_RANGE_LERP: {
if (p_idx == 0) {
return PropertyInfo(Variant::FLOAT, "value");
@@ -348,19 +366,17 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const
return PropertyInfo(Variant::FLOAT, "delta");
}
} break;
- case MATH_DECTIME: {
- if (p_idx == 0) {
- return PropertyInfo(Variant::FLOAT, "value");
- } else if (p_idx == 1) {
- return PropertyInfo(Variant::FLOAT, "amount");
- } else {
- return PropertyInfo(Variant::FLOAT, "step");
- }
- } break;
case MATH_RANDOMIZE:
case MATH_RANDI:
case MATH_RANDF: {
} break;
+ case MATH_RANDI_RANGE: {
+ if (p_idx == 0) {
+ return PropertyInfo(Variant::INT, "from");
+ } else {
+ return PropertyInfo(Variant::INT, "to");
+ }
+ } break;
case MATH_RANDF_RANGE: {
if (p_idx == 0) {
return PropertyInfo(Variant::FLOAT, "from");
@@ -368,11 +384,11 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const
return PropertyInfo(Variant::FLOAT, "to");
}
} break;
- case MATH_RANDI_RANGE: {
+ case MATH_RANDFN: {
if (p_idx == 0) {
- return PropertyInfo(Variant::INT, "from");
+ return PropertyInfo(Variant::FLOAT, "mean");
} else {
- return PropertyInfo(Variant::INT, "to");
+ return PropertyInfo(Variant::FLOAT, "deviation");
}
} break;
case MATH_SEED:
@@ -391,18 +407,11 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const
case MATH_DB2LINEAR: {
return PropertyInfo(Variant::FLOAT, "db");
} break;
- case MATH_POLAR2CARTESIAN: {
+ case MATH_PINGPONG: {
if (p_idx == 0) {
- return PropertyInfo(Variant::FLOAT, "r");
- } else {
- return PropertyInfo(Variant::FLOAT, "th");
- }
- } break;
- case MATH_CARTESIAN2POLAR: {
- if (p_idx == 0) {
- return PropertyInfo(Variant::FLOAT, "x");
+ return PropertyInfo(Variant::FLOAT, "value");
} else {
- return PropertyInfo(Variant::FLOAT, "y");
+ return PropertyInfo(Variant::FLOAT, "length");
}
} break;
case MATH_WRAP: {
@@ -452,7 +461,8 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const
case TEXT_STR:
case TEXT_PRINT:
case TEXT_PRINTERR:
- case TEXT_PRINTRAW: {
+ case TEXT_PRINTRAW:
+ case TEXT_PRINT_VERBOSE: {
return PropertyInfo(Variant::NIL, "value");
} break;
case STR_TO_VAR: {
@@ -530,21 +540,19 @@ PropertyInfo VisualScriptBuiltinFunc::get_output_value_port_info(int p_idx) cons
} break;
case MATH_SNAPPED:
case MATH_LERP:
+ case MATH_CUBIC_INTERPOLATE:
case MATH_LERP_ANGLE:
case MATH_INVERSE_LERP:
case MATH_RANGE_LERP:
case MATH_SMOOTHSTEP:
case MATH_MOVE_TOWARD:
- case MATH_DECTIME: {
- t = Variant::FLOAT;
-
- } break;
case MATH_RANDOMIZE: {
} break;
case MATH_RANDI: {
t = Variant::INT;
} break;
case MATH_RANDF:
+ case MATH_RANDFN:
case MATH_RANDF_RANGE: {
t = Variant::FLOAT;
} break;
@@ -564,13 +572,10 @@ PropertyInfo VisualScriptBuiltinFunc::get_output_value_port_info(int p_idx) cons
case MATH_RAD2DEG:
case MATH_LINEAR2DB:
case MATH_WRAPF:
+ case MATH_PINGPONG:
case MATH_DB2LINEAR: {
t = Variant::FLOAT;
} break;
- case MATH_POLAR2CARTESIAN:
- case MATH_CARTESIAN2POLAR: {
- t = Variant::VECTOR2;
- } break;
case MATH_WRAP: {
t = Variant::INT;
} break;
@@ -608,6 +613,8 @@ PropertyInfo VisualScriptBuiltinFunc::get_output_value_port_info(int p_idx) cons
} break;
case TEXT_PRINTRAW: {
} break;
+ case TEXT_PRINT_VERBOSE: {
+ } break;
case VAR_TO_STR: {
t = Variant::STRING;
} break;
@@ -723,7 +730,7 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in
case VisualScriptBuiltinFunc::MATH_POSMOD: {
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
- *r_return = Math::posmod((int)*p_inputs[0], (int)*p_inputs[1]);
+ *r_return = Math::posmod((int64_t)*p_inputs[0], (int64_t)*p_inputs[1]);
} break;
case VisualScriptBuiltinFunc::MATH_FLOOR: {
VALIDATE_ARG_NUM(0);
@@ -804,6 +811,14 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in
VALIDATE_ARG_NUM(2);
*r_return = Math::lerp((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]);
} break;
+ case VisualScriptBuiltinFunc::MATH_CUBIC_INTERPOLATE: {
+ VALIDATE_ARG_NUM(0);
+ VALIDATE_ARG_NUM(1);
+ VALIDATE_ARG_NUM(2);
+ VALIDATE_ARG_NUM(3);
+ VALIDATE_ARG_NUM(4);
+ *r_return = Math::cubic_interpolate((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2], (double)*p_inputs[3], (double)*p_inputs[4]);
+ } break;
case VisualScriptBuiltinFunc::MATH_LERP_ANGLE: {
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
@@ -836,12 +851,6 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in
VALIDATE_ARG_NUM(2);
*r_return = Math::move_toward((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]);
} break;
- case VisualScriptBuiltinFunc::MATH_DECTIME: {
- VALIDATE_ARG_NUM(0);
- VALIDATE_ARG_NUM(1);
- VALIDATE_ARG_NUM(2);
- *r_return = Math::dectime((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]);
- } break;
case VisualScriptBuiltinFunc::MATH_RANDOMIZE: {
Math::randomize();
@@ -852,15 +861,20 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in
case VisualScriptBuiltinFunc::MATH_RANDF: {
*r_return = Math::randf();
} break;
+ case VisualScriptBuiltinFunc::MATH_RANDI_RANGE: {
+ VALIDATE_ARG_NUM(0);
+ VALIDATE_ARG_NUM(1);
+ *r_return = Math::random((int)*p_inputs[0], (int)*p_inputs[1]);
+ } break;
case VisualScriptBuiltinFunc::MATH_RANDF_RANGE: {
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
*r_return = Math::random((double)*p_inputs[0], (double)*p_inputs[1]);
} break;
- case VisualScriptBuiltinFunc::MATH_RANDI_RANGE: {
+ case VisualScriptBuiltinFunc::MATH_RANDFN: {
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
- *r_return = Math::random((int)*p_inputs[0], (int)*p_inputs[1]);
+ *r_return = Math::randfn((double)*p_inputs[0], (double)*p_inputs[1]);
} break;
case VisualScriptBuiltinFunc::MATH_SEED: {
VALIDATE_ARG_NUM(0);
@@ -894,19 +908,10 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in
VALIDATE_ARG_NUM(0);
*r_return = Math::db2linear((double)*p_inputs[0]);
} break;
- case VisualScriptBuiltinFunc::MATH_POLAR2CARTESIAN: {
+ case VisualScriptBuiltinFunc::MATH_PINGPONG: {
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
- double r = *p_inputs[0];
- double th = *p_inputs[1];
- *r_return = Vector2(r * Math::cos(th), r * Math::sin(th));
- } break;
- case VisualScriptBuiltinFunc::MATH_CARTESIAN2POLAR: {
- VALIDATE_ARG_NUM(0);
- VALIDATE_ARG_NUM(1);
- double x = *p_inputs[0];
- double y = *p_inputs[1];
- *r_return = Vector2(Math::sqrt(x * x + y * y), Math::atan2(y, x));
+ *r_return = Math::pingpong((double)*p_inputs[0], (double)*p_inputs[1]);
} break;
case VisualScriptBuiltinFunc::MATH_WRAP: {
VALIDATE_ARG_NUM(0);
@@ -983,8 +988,8 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in
return;
}
- if (p_inputs[0]->is_ref()) {
- REF r = *p_inputs[0];
+ if (p_inputs[0]->is_ref_counted()) {
+ Ref<RefCounted> r = *p_inputs[0];
if (!r.is_valid()) {
return;
}
@@ -1076,6 +1081,10 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in
OS::get_singleton()->print("%s", str.utf8().get_data());
} break;
+ case VisualScriptBuiltinFunc::TEXT_PRINT_VERBOSE: {
+ String str = *p_inputs[0];
+ print_verbose(str);
+ } break;
case VisualScriptBuiltinFunc::VAR_TO_STR: {
String vars;
VariantWriter::write_to_string(*p_inputs[0], vars);
@@ -1171,22 +1180,22 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in
class VisualScriptNodeInstanceBuiltinFunc : public VisualScriptNodeInstance {
public:
- VisualScriptBuiltinFunc *node;
- VisualScriptInstance *instance;
+ VisualScriptBuiltinFunc *node = nullptr;
+ VisualScriptInstance *instance = nullptr;
VisualScriptBuiltinFunc::BuiltinFunc func;
- //virtual int get_working_memory_size() const { return 0; }
+ //virtual int get_working_memory_size() const override { return 0; }
//virtual bool is_output_port_unsequenced(int p_idx) const { return false; }
//virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return true; }
- virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) {
+ virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
VisualScriptBuiltinFunc::exec_func(func, p_inputs, p_outputs[0], r_error, r_error_str);
return 0;
}
};
-VisualScriptNodeInstance *VisualScriptBuiltinFunc::instance(VisualScriptInstance *p_instance) {
+VisualScriptNodeInstance *VisualScriptBuiltinFunc::instantiate(VisualScriptInstance *p_instance) {
VisualScriptNodeInstanceBuiltinFunc *instance = memnew(VisualScriptNodeInstanceBuiltinFunc);
instance->node = this;
instance->instance = p_instance;
@@ -1235,25 +1244,25 @@ void VisualScriptBuiltinFunc::_bind_methods() {
BIND_ENUM_CONSTANT(MATH_STEP_DECIMALS);
BIND_ENUM_CONSTANT(MATH_SNAPPED);
BIND_ENUM_CONSTANT(MATH_LERP);
+ BIND_ENUM_CONSTANT(MATH_CUBIC_INTERPOLATE);
BIND_ENUM_CONSTANT(MATH_INVERSE_LERP);
BIND_ENUM_CONSTANT(MATH_RANGE_LERP);
BIND_ENUM_CONSTANT(MATH_MOVE_TOWARD);
- BIND_ENUM_CONSTANT(MATH_DECTIME);
BIND_ENUM_CONSTANT(MATH_RANDOMIZE);
BIND_ENUM_CONSTANT(MATH_RANDI);
BIND_ENUM_CONSTANT(MATH_RANDF);
- BIND_ENUM_CONSTANT(MATH_RANDF_RANGE);
BIND_ENUM_CONSTANT(MATH_RANDI_RANGE);
+ BIND_ENUM_CONSTANT(MATH_RANDF_RANGE);
+ BIND_ENUM_CONSTANT(MATH_RANDFN);
BIND_ENUM_CONSTANT(MATH_SEED);
BIND_ENUM_CONSTANT(MATH_RANDSEED);
BIND_ENUM_CONSTANT(MATH_DEG2RAD);
BIND_ENUM_CONSTANT(MATH_RAD2DEG);
BIND_ENUM_CONSTANT(MATH_LINEAR2DB);
BIND_ENUM_CONSTANT(MATH_DB2LINEAR);
- BIND_ENUM_CONSTANT(MATH_POLAR2CARTESIAN);
- BIND_ENUM_CONSTANT(MATH_CARTESIAN2POLAR);
BIND_ENUM_CONSTANT(MATH_WRAP);
BIND_ENUM_CONSTANT(MATH_WRAPF);
+ BIND_ENUM_CONSTANT(MATH_PINGPONG);
BIND_ENUM_CONSTANT(LOGIC_MAX);
BIND_ENUM_CONSTANT(LOGIC_MIN);
BIND_ENUM_CONSTANT(LOGIC_CLAMP);
@@ -1267,6 +1276,7 @@ void VisualScriptBuiltinFunc::_bind_methods() {
BIND_ENUM_CONSTANT(TEXT_PRINT);
BIND_ENUM_CONSTANT(TEXT_PRINTERR);
BIND_ENUM_CONSTANT(TEXT_PRINTRAW);
+ BIND_ENUM_CONSTANT(TEXT_PRINT_VERBOSE);
BIND_ENUM_CONSTANT(VAR_TO_STR);
BIND_ENUM_CONSTANT(STR_TO_VAR);
BIND_ENUM_CONSTANT(VAR_TO_BYTES);
@@ -1324,17 +1334,18 @@ void register_visual_script_builtin_func_node() {
VisualScriptLanguage::singleton->add_register_func("functions/built_in/step_decimals", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_STEP_DECIMALS>);
VisualScriptLanguage::singleton->add_register_func("functions/built_in/snapped", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_SNAPPED>);
VisualScriptLanguage::singleton->add_register_func("functions/built_in/lerp", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_LERP>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/cubic_interpolate", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_CUBIC_INTERPOLATE>);
VisualScriptLanguage::singleton->add_register_func("functions/built_in/lerp_angle", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_LERP_ANGLE>);
VisualScriptLanguage::singleton->add_register_func("functions/built_in/inverse_lerp", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_INVERSE_LERP>);
VisualScriptLanguage::singleton->add_register_func("functions/built_in/range_lerp", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_RANGE_LERP>);
VisualScriptLanguage::singleton->add_register_func("functions/built_in/smoothstep", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_SMOOTHSTEP>);
VisualScriptLanguage::singleton->add_register_func("functions/built_in/move_toward", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_MOVE_TOWARD>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/dectime", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_DECTIME>);
VisualScriptLanguage::singleton->add_register_func("functions/built_in/randomize", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_RANDOMIZE>);
VisualScriptLanguage::singleton->add_register_func("functions/built_in/randi", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_RANDI>);
VisualScriptLanguage::singleton->add_register_func("functions/built_in/randf", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_RANDF>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/randf_range", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_RANDF_RANGE>);
VisualScriptLanguage::singleton->add_register_func("functions/built_in/randi_range", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_RANDI_RANGE>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/randf_range", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_RANDF_RANGE>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/randfn", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_RANDFN>);
VisualScriptLanguage::singleton->add_register_func("functions/built_in/seed", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_SEED>);
VisualScriptLanguage::singleton->add_register_func("functions/built_in/randseed", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_RANDSEED>);
@@ -1342,10 +1353,9 @@ void register_visual_script_builtin_func_node() {
VisualScriptLanguage::singleton->add_register_func("functions/built_in/rad2deg", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_RAD2DEG>);
VisualScriptLanguage::singleton->add_register_func("functions/built_in/linear2db", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_LINEAR2DB>);
VisualScriptLanguage::singleton->add_register_func("functions/built_in/db2linear", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_DB2LINEAR>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/polar2cartesian", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_POLAR2CARTESIAN>);
- VisualScriptLanguage::singleton->add_register_func("functions/built_in/cartesian2polar", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_CARTESIAN2POLAR>);
VisualScriptLanguage::singleton->add_register_func("functions/built_in/wrapi", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_WRAP>);
VisualScriptLanguage::singleton->add_register_func("functions/built_in/wrapf", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_WRAPF>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/pingpong", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_PINGPONG>);
VisualScriptLanguage::singleton->add_register_func("functions/built_in/max", create_builtin_func_node<VisualScriptBuiltinFunc::LOGIC_MAX>);
VisualScriptLanguage::singleton->add_register_func("functions/built_in/min", create_builtin_func_node<VisualScriptBuiltinFunc::LOGIC_MIN>);
@@ -1362,6 +1372,7 @@ void register_visual_script_builtin_func_node() {
VisualScriptLanguage::singleton->add_register_func("functions/built_in/print", create_builtin_func_node<VisualScriptBuiltinFunc::TEXT_PRINT>);
VisualScriptLanguage::singleton->add_register_func("functions/built_in/printerr", create_builtin_func_node<VisualScriptBuiltinFunc::TEXT_PRINTERR>);
VisualScriptLanguage::singleton->add_register_func("functions/built_in/printraw", create_builtin_func_node<VisualScriptBuiltinFunc::TEXT_PRINTRAW>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/print_verbose", create_builtin_func_node<VisualScriptBuiltinFunc::TEXT_PRINT_VERBOSE>);
VisualScriptLanguage::singleton->add_register_func("functions/built_in/var2str", create_builtin_func_node<VisualScriptBuiltinFunc::VAR_TO_STR>);
VisualScriptLanguage::singleton->add_register_func("functions/built_in/str2var", create_builtin_func_node<VisualScriptBuiltinFunc::STR_TO_VAR>);
VisualScriptLanguage::singleton->add_register_func("functions/built_in/var2bytes", create_builtin_func_node<VisualScriptBuiltinFunc::VAR_TO_BYTES>);
diff --git a/modules/visual_script/visual_script_builtin_funcs.h b/modules/visual_script/visual_script_builtin_funcs.h
index 1fafaf1d98..18935b9995 100644
--- a/modules/visual_script/visual_script_builtin_funcs.h
+++ b/modules/visual_script/visual_script_builtin_funcs.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -65,25 +65,25 @@ public:
MATH_STEP_DECIMALS,
MATH_SNAPPED,
MATH_LERP,
+ MATH_CUBIC_INTERPOLATE,
MATH_INVERSE_LERP,
MATH_RANGE_LERP,
MATH_MOVE_TOWARD,
- MATH_DECTIME,
MATH_RANDOMIZE,
MATH_RANDI,
MATH_RANDF,
- MATH_RANDF_RANGE,
MATH_RANDI_RANGE,
+ MATH_RANDF_RANGE,
+ MATH_RANDFN,
MATH_SEED,
MATH_RANDSEED,
MATH_DEG2RAD,
MATH_RAD2DEG,
MATH_LINEAR2DB,
MATH_DB2LINEAR,
- MATH_POLAR2CARTESIAN,
- MATH_CARTESIAN2POLAR,
MATH_WRAP,
MATH_WRAPF,
+ MATH_PINGPONG,
LOGIC_MAX,
LOGIC_MIN,
LOGIC_CLAMP,
@@ -97,6 +97,7 @@ public:
TEXT_PRINT,
TEXT_PRINTERR,
TEXT_PRINTRAW,
+ TEXT_PRINT_VERBOSE,
VAR_TO_STR,
STR_TO_VAR,
VAR_TO_BYTES,
@@ -139,7 +140,7 @@ public:
void set_func(BuiltinFunc p_which);
BuiltinFunc get_func();
- virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override;
+ virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override;
VisualScriptBuiltinFunc(VisualScriptBuiltinFunc::BuiltinFunc func);
VisualScriptBuiltinFunc();
diff --git a/modules/visual_script/visual_script_expression.cpp b/modules/visual_script/visual_script_expression.cpp
index cb4230bea9..e0f6436094 100644
--- a/modules/visual_script/visual_script_expression.cpp
+++ b/modules/visual_script/visual_script_expression.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -136,7 +136,7 @@ void VisualScriptExpression::_get_property_list(List<PropertyInfo> *p_list) cons
argt += "," + Variant::get_type_name(Variant::Type(i));
}
- p_list->push_back(PropertyInfo(Variant::STRING, "expression", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR));
+ p_list->push_back(PropertyInfo(Variant::STRING, "expression", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR));
p_list->push_back(PropertyInfo(Variant::INT, "out_type", PROPERTY_HINT_ENUM, argt));
p_list->push_back(PropertyInfo(Variant::INT, "input_count", PROPERTY_HINT_RANGE, "0,64,1"));
p_list->push_back(PropertyInfo(Variant::BOOL, "sequenced"));
@@ -176,7 +176,7 @@ PropertyInfo VisualScriptExpression::get_output_value_port_info(int p_idx) const
}
String VisualScriptExpression::get_caption() const {
- return "Expression";
+ return RTR("Expression");
}
String VisualScriptExpression::get_text() const {
@@ -328,6 +328,7 @@ Error VisualScriptExpression::_get_token(Token &r_token) {
};
case '"': {
String str;
+ char32_t prev = 0;
while (true) {
char32_t ch = GET_CHAR();
@@ -364,9 +365,11 @@ Error VisualScriptExpression::_get_token(Token &r_token) {
case 'r':
res = 13;
break;
+ case 'U':
case 'u': {
- // hex number
- for (int j = 0; j < 4; j++) {
+ // Hexadecimal sequence.
+ int hex_len = (next == 'U') ? 6 : 4;
+ for (int j = 0; j < hex_len; j++) {
char32_t c = GET_CHAR();
if (c == 0) {
@@ -374,13 +377,13 @@ Error VisualScriptExpression::_get_token(Token &r_token) {
r_token.type = TK_ERROR;
return ERR_PARSE_ERROR;
}
- if (!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))) {
+ if (!is_hex_digit(c)) {
_set_error("Malformed hex constant in string");
r_token.type = TK_ERROR;
return ERR_PARSE_ERROR;
}
char32_t v;
- if (c >= '0' && c <= '9') {
+ if (is_digit(c)) {
v = c - '0';
} else if (c >= 'a' && c <= 'f') {
v = c - 'a';
@@ -403,12 +406,46 @@ Error VisualScriptExpression::_get_token(Token &r_token) {
} break;
}
+ // Parse UTF-16 pair.
+ if ((res & 0xfffffc00) == 0xd800) {
+ if (prev == 0) {
+ prev = res;
+ continue;
+ } else {
+ _set_error("Invalid UTF-16 sequence in string, unpaired lead surrogate");
+ r_token.type = TK_ERROR;
+ return ERR_PARSE_ERROR;
+ }
+ } else if ((res & 0xfffffc00) == 0xdc00) {
+ if (prev == 0) {
+ _set_error("Invalid UTF-16 sequence in string, unpaired trail surrogate");
+ r_token.type = TK_ERROR;
+ return ERR_PARSE_ERROR;
+ } else {
+ res = (prev << 10UL) + res - ((0xd800 << 10UL) + 0xdc00 - 0x10000);
+ prev = 0;
+ }
+ }
+ if (prev != 0) {
+ _set_error("Invalid UTF-16 sequence in string, unpaired lead surrogate");
+ r_token.type = TK_ERROR;
+ return ERR_PARSE_ERROR;
+ }
str += res;
-
} else {
+ if (prev != 0) {
+ _set_error("Invalid UTF-16 sequence in string, unpaired lead surrogate");
+ r_token.type = TK_ERROR;
+ return ERR_PARSE_ERROR;
+ }
str += ch;
}
}
+ if (prev != 0) {
+ _set_error("Invalid UTF-16 sequence in string, unpaired lead surrogate");
+ r_token.type = TK_ERROR;
+ return ERR_PARSE_ERROR;
+ }
r_token.type = TK_CONSTANT;
r_token.value = str;
@@ -420,7 +457,7 @@ Error VisualScriptExpression::_get_token(Token &r_token) {
break;
}
- if (cchar >= '0' && cchar <= '9') {
+ if (is_digit(cchar)) {
//a number
String num;
@@ -439,7 +476,7 @@ Error VisualScriptExpression::_get_token(Token &r_token) {
while (true) {
switch (reading) {
case READING_INT: {
- if (c >= '0' && c <= '9') {
+ if (is_digit(c)) {
//pass
} else if (c == '.') {
reading = READING_DEC;
@@ -452,7 +489,7 @@ Error VisualScriptExpression::_get_token(Token &r_token) {
} break;
case READING_DEC: {
- if (c >= '0' && c <= '9') {
+ if (is_digit(c)) {
} else if (c == 'e') {
reading = READING_EXP;
@@ -462,7 +499,7 @@ Error VisualScriptExpression::_get_token(Token &r_token) {
} break;
case READING_EXP: {
- if (c >= '0' && c <= '9') {
+ if (is_digit(c)) {
exp_beg = true;
} else if ((c == '-' || c == '+') && !exp_sign && !exp_beg) {
@@ -495,11 +532,11 @@ Error VisualScriptExpression::_get_token(Token &r_token) {
}
return OK;
- } else if ((cchar >= 'A' && cchar <= 'Z') || (cchar >= 'a' && cchar <= 'z') || cchar == '_') {
+ } else if (is_ascii_char(cchar) || cchar == '_') {
String id;
bool first = true;
- while ((cchar >= 'A' && cchar <= 'Z') || (cchar >= 'a' && cchar <= 'z') || cchar == '_' || (!first && cchar >= '0' && cchar <= '9')) {
+ while (is_ascii_char(cchar) || cchar == '_' || (!first && is_digit(cchar))) {
id += String::chr(cchar);
cchar = GET_CHAR();
first = false;
@@ -526,10 +563,10 @@ Error VisualScriptExpression::_get_token(Token &r_token) {
r_token.value = Math_TAU;
} else if (id == "INF") {
r_token.type = TK_CONSTANT;
- r_token.value = Math_INF;
+ r_token.value = INFINITY;
} else if (id == "NAN") {
r_token.type = TK_CONSTANT;
- r_token.value = Math_NAN;
+ r_token.value = NAN;
} else if (id == "not") {
r_token.type = TK_OP_NOT;
} else if (id == "or") {
@@ -1190,7 +1227,7 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() {
op->nodes[1] = nullptr;
expression.write[i].is_op = false;
expression.write[i].node = op;
- expression.remove(i + 1);
+ expression.remove_at(i + 1);
}
} else {
@@ -1222,8 +1259,8 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() {
//replace all 3 nodes by this operator and make it an expression
expression.write[next_op - 1].node = op;
- expression.remove(next_op);
- expression.remove(next_op);
+ expression.remove_at(next_op);
+ expression.remove_at(next_op);
}
}
@@ -1262,10 +1299,10 @@ bool VisualScriptExpression::_compile_expression() {
class VisualScriptNodeInstanceExpression : public VisualScriptNodeInstance {
public:
- VisualScriptInstance *instance;
- VisualScriptExpression *expression;
+ VisualScriptInstance *instance = nullptr;
+ VisualScriptExpression *expression = nullptr;
- //virtual int get_working_memory_size() const { return 0; }
+ //virtual int get_working_memory_size() const override { return 0; }
//execute by parsing the tree directly
virtual bool _execute(const Variant **p_inputs, VisualScriptExpression::ENode *p_node, Variant &r_ret, String &r_error_str, Callable::CallError &ce) {
switch (p_node->type) {
@@ -1463,7 +1500,7 @@ public:
argp.write[i] = &arr[i];
}
- base.call(call->method, (const Variant **)argp.ptr(), argp.size(), r_ret, ce);
+ base.callp(call->method, (const Variant **)argp.ptr(), argp.size(), r_ret, ce);
if (ce.error != Callable::CallError::CALL_OK) {
r_error_str = "On call to '" + String(call->method) + "':";
@@ -1475,7 +1512,7 @@ public:
return false;
}
- virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) {
+ virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
if (!expression->root || expression->error_set) {
r_error_str = expression->error_str;
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
@@ -1498,7 +1535,7 @@ public:
}
};
-VisualScriptNodeInstance *VisualScriptExpression::instance(VisualScriptInstance *p_instance) {
+VisualScriptNodeInstance *VisualScriptExpression::instantiate(VisualScriptInstance *p_instance) {
_compile_expression();
VisualScriptNodeInstanceExpression *instance = memnew(VisualScriptNodeInstanceExpression);
instance->instance = p_instance;
diff --git a/modules/visual_script/visual_script_expression.h b/modules/visual_script/visual_script_expression.h
index c35075ea53..c93eb0686b 100644
--- a/modules/visual_script/visual_script_expression.h
+++ b/modules/visual_script/visual_script_expression.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -273,7 +273,7 @@ public:
virtual String get_text() const override;
virtual String get_category() const override { return "operators"; }
- virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override;
+ virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override;
VisualScriptExpression();
~VisualScriptExpression();
diff --git a/modules/visual_script/visual_script_flow_control.cpp b/modules/visual_script/visual_script_flow_control.cpp
index e977f9c96b..bbbb995635 100644
--- a/modules/visual_script/visual_script_flow_control.cpp
+++ b/modules/visual_script/visual_script_flow_control.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -70,7 +70,7 @@ PropertyInfo VisualScriptReturn::get_output_value_port_info(int p_idx) const {
}
String VisualScriptReturn::get_caption() const {
- return "Return";
+ return RTR("Return");
}
String VisualScriptReturn::get_text() const {
@@ -119,15 +119,15 @@ void VisualScriptReturn::_bind_methods() {
class VisualScriptNodeInstanceReturn : public VisualScriptNodeInstance {
public:
- VisualScriptReturn *node;
- VisualScriptInstance *instance;
- bool with_value;
+ VisualScriptReturn *node = nullptr;
+ VisualScriptInstance *instance = nullptr;
+ bool with_value = false;
- virtual int get_working_memory_size() const { return 1; }
+ virtual int get_working_memory_size() const override { return 1; }
//virtual bool is_output_port_unsequenced(int p_idx) const { return false; }
//virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return true; }
- virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) {
+ virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
if (with_value) {
*p_working_mem = *p_inputs[0];
return STEP_EXIT_FUNCTION_BIT;
@@ -138,7 +138,7 @@ public:
}
};
-VisualScriptNodeInstance *VisualScriptReturn::instance(VisualScriptInstance *p_instance) {
+VisualScriptNodeInstance *VisualScriptReturn::instantiate(VisualScriptInstance *p_instance) {
VisualScriptNodeInstanceReturn *instance = memnew(VisualScriptNodeInstanceReturn);
instance->node = this;
instance->instance = p_instance;
@@ -154,7 +154,7 @@ VisualScriptReturn::VisualScriptReturn() {
template <bool with_value>
static Ref<VisualScriptNode> create_return_node(const String &p_name) {
Ref<VisualScriptReturn> node;
- node.instance();
+ node.instantiate();
node->set_enable_return_value(with_value);
return node;
}
@@ -201,11 +201,11 @@ PropertyInfo VisualScriptCondition::get_output_value_port_info(int p_idx) const
}
String VisualScriptCondition::get_caption() const {
- return "Condition";
+ return RTR("Condition");
}
String VisualScriptCondition::get_text() const {
- return "if (cond) is: ";
+ return RTR("if (cond) is:");
}
void VisualScriptCondition::_bind_methods() {
@@ -213,14 +213,14 @@ void VisualScriptCondition::_bind_methods() {
class VisualScriptNodeInstanceCondition : public VisualScriptNodeInstance {
public:
- VisualScriptCondition *node;
- VisualScriptInstance *instance;
+ VisualScriptCondition *node = nullptr;
+ VisualScriptInstance *instance = nullptr;
- //virtual int get_working_memory_size() const { return 1; }
+ //virtual int get_working_memory_size() const override { return 1; }
//virtual bool is_output_port_unsequenced(int p_idx) const { return false; }
//virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return true; }
- virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) {
+ virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
if (p_start_mode == START_MODE_CONTINUE_SEQUENCE) {
return 2;
} else if (p_inputs[0]->operator bool()) {
@@ -231,7 +231,7 @@ public:
}
};
-VisualScriptNodeInstance *VisualScriptCondition::instance(VisualScriptInstance *p_instance) {
+VisualScriptNodeInstance *VisualScriptCondition::instantiate(VisualScriptInstance *p_instance) {
VisualScriptNodeInstanceCondition *instance = memnew(VisualScriptNodeInstanceCondition);
instance->node = this;
instance->instance = p_instance;
@@ -281,11 +281,11 @@ PropertyInfo VisualScriptWhile::get_output_value_port_info(int p_idx) const {
}
String VisualScriptWhile::get_caption() const {
- return "While";
+ return RTR("While");
}
String VisualScriptWhile::get_text() const {
- return "while (cond): ";
+ return RTR("while (cond):");
}
void VisualScriptWhile::_bind_methods() {
@@ -293,14 +293,14 @@ void VisualScriptWhile::_bind_methods() {
class VisualScriptNodeInstanceWhile : public VisualScriptNodeInstance {
public:
- VisualScriptWhile *node;
- VisualScriptInstance *instance;
+ VisualScriptWhile *node = nullptr;
+ VisualScriptInstance *instance = nullptr;
- //virtual int get_working_memory_size() const { return 1; }
+ //virtual int get_working_memory_size() const override { return 1; }
//virtual bool is_output_port_unsequenced(int p_idx) const { return false; }
//virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return true; }
- virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) {
+ virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
bool keep_going = p_inputs[0]->operator bool();
if (keep_going) {
@@ -311,7 +311,7 @@ public:
}
};
-VisualScriptNodeInstance *VisualScriptWhile::instance(VisualScriptInstance *p_instance) {
+VisualScriptNodeInstance *VisualScriptWhile::instantiate(VisualScriptInstance *p_instance) {
VisualScriptNodeInstanceWhile *instance = memnew(VisualScriptNodeInstanceWhile);
instance->node = this;
instance->instance = p_instance;
@@ -364,11 +364,11 @@ PropertyInfo VisualScriptIterator::get_output_value_port_info(int p_idx) const {
}
String VisualScriptIterator::get_caption() const {
- return "Iterator";
+ return RTR("Iterator");
}
String VisualScriptIterator::get_text() const {
- return "for (elem) in (input): ";
+ return RTR("for (elem) in (input):");
}
void VisualScriptIterator::_bind_methods() {
@@ -376,14 +376,14 @@ void VisualScriptIterator::_bind_methods() {
class VisualScriptNodeInstanceIterator : public VisualScriptNodeInstance {
public:
- VisualScriptIterator *node;
- VisualScriptInstance *instance;
+ VisualScriptIterator *node = nullptr;
+ VisualScriptInstance *instance = nullptr;
- virtual int get_working_memory_size() const { return 2; }
+ virtual int get_working_memory_size() const override { return 2; }
//virtual bool is_output_port_unsequenced(int p_idx) const { return false; }
//virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return true; }
- virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) {
+ virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
if (p_start_mode == START_MODE_BEGIN_SEQUENCE) {
p_working_mem[0] = *p_inputs[0];
bool valid;
@@ -391,7 +391,7 @@ public:
if (!valid) {
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
- r_error_str = RTR("Input type not iterable: ") + Variant::get_type_name(p_inputs[0]->get_type());
+ r_error_str = RTR("Input type not iterable:") + " " + Variant::get_type_name(p_inputs[0]->get_type());
return 0;
}
@@ -414,7 +414,7 @@ public:
if (!valid) {
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
- r_error_str = RTR("Iterator became invalid: ") + Variant::get_type_name(p_inputs[0]->get_type());
+ r_error_str = RTR("Iterator became invalid:") + " " + Variant::get_type_name(p_inputs[0]->get_type());
return 0;
}
@@ -435,7 +435,7 @@ public:
}
};
-VisualScriptNodeInstance *VisualScriptIterator::instance(VisualScriptInstance *p_instance) {
+VisualScriptNodeInstance *VisualScriptIterator::instantiate(VisualScriptInstance *p_instance) {
VisualScriptNodeInstanceIterator *instance = memnew(VisualScriptNodeInstanceIterator);
instance->node = this;
instance->instance = p_instance;
@@ -478,11 +478,11 @@ PropertyInfo VisualScriptSequence::get_output_value_port_info(int p_idx) const {
}
String VisualScriptSequence::get_caption() const {
- return "Sequence";
+ return RTR("Sequence");
}
String VisualScriptSequence::get_text() const {
- return "in order: ";
+ return RTR("in order:");
}
void VisualScriptSequence::set_steps(int p_steps) {
@@ -508,15 +508,15 @@ void VisualScriptSequence::_bind_methods() {
class VisualScriptNodeInstanceSequence : public VisualScriptNodeInstance {
public:
- VisualScriptSequence *node;
- VisualScriptInstance *instance;
- int steps;
+ VisualScriptSequence *node = nullptr;
+ VisualScriptInstance *instance = nullptr;
+ int steps = 0;
- virtual int get_working_memory_size() const { return 1; }
+ virtual int get_working_memory_size() const override { return 1; }
//virtual bool is_output_port_unsequenced(int p_idx) const { return false; }
//virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return true; }
- virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) {
+ virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
if (p_start_mode == START_MODE_BEGIN_SEQUENCE) {
p_working_mem[0] = 0;
}
@@ -534,7 +534,7 @@ public:
}
};
-VisualScriptNodeInstance *VisualScriptSequence::instance(VisualScriptInstance *p_instance) {
+VisualScriptNodeInstance *VisualScriptSequence::instantiate(VisualScriptInstance *p_instance) {
VisualScriptNodeInstanceSequence *instance = memnew(VisualScriptNodeInstanceSequence);
instance->node = this;
instance->instance = p_instance;
@@ -587,23 +587,23 @@ PropertyInfo VisualScriptSwitch::get_output_value_port_info(int p_idx) const {
}
String VisualScriptSwitch::get_caption() const {
- return "Switch";
+ return RTR("Switch");
}
String VisualScriptSwitch::get_text() const {
- return "'input' is:";
+ return RTR("'input' is:");
}
class VisualScriptNodeInstanceSwitch : public VisualScriptNodeInstance {
public:
- VisualScriptInstance *instance;
- int case_count;
+ VisualScriptInstance *instance = nullptr;
+ int case_count = 0;
- //virtual int get_working_memory_size() const { return 0; }
+ //virtual int get_working_memory_size() const override { return 0; }
//virtual bool is_output_port_unsequenced(int p_idx) const { return false; }
//virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return false; }
- virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) {
+ virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
if (p_start_mode == START_MODE_CONTINUE_SEQUENCE) {
return case_count; //exit
}
@@ -618,7 +618,7 @@ public:
}
};
-VisualScriptNodeInstance *VisualScriptSwitch::instance(VisualScriptInstance *p_instance) {
+VisualScriptNodeInstance *VisualScriptSwitch::instantiate(VisualScriptInstance *p_instance) {
VisualScriptNodeInstanceSwitch *instance = memnew(VisualScriptNodeInstanceSwitch);
instance->instance = p_instance;
instance->case_count = case_values.size();
@@ -720,14 +720,14 @@ PropertyInfo VisualScriptTypeCast::get_output_value_port_info(int p_idx) const {
}
String VisualScriptTypeCast::get_caption() const {
- return "Type Cast";
+ return RTR("Type Cast");
}
String VisualScriptTypeCast::get_text() const {
- if (script != String()) {
- return "Is " + script.get_file() + "?";
+ if (!script.is_empty()) {
+ return vformat(RTR("Is %s?"), script.get_file());
} else {
- return "Is " + base_type + "?";
+ return vformat(RTR("Is %s?"), base_type);
}
}
@@ -762,7 +762,7 @@ String VisualScriptTypeCast::get_base_script() const {
VisualScriptTypeCast::TypeGuess VisualScriptTypeCast::guess_output_type(TypeGuess *p_inputs, int p_output) const {
TypeGuess tg;
tg.type = Variant::OBJECT;
- if (script != String()) {
+ if (!script.is_empty()) {
tg.script = ResourceLoader::load(script);
}
//if (!tg.script.is_valid()) {
@@ -774,15 +774,15 @@ VisualScriptTypeCast::TypeGuess VisualScriptTypeCast::guess_output_type(TypeGues
class VisualScriptNodeInstanceTypeCast : public VisualScriptNodeInstance {
public:
- VisualScriptInstance *instance;
+ VisualScriptInstance *instance = nullptr;
StringName base_type;
String script;
- //virtual int get_working_memory_size() const { return 0; }
+ //virtual int get_working_memory_size() const override { return 0; }
//virtual bool is_output_port_unsequenced(int p_idx) const { return false; }
//virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return false; }
- virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) {
+ virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
Object *obj = *p_inputs[0];
*p_outputs[0] = Variant();
@@ -793,7 +793,7 @@ public:
return 0;
}
- if (script != String()) {
+ if (!script.is_empty()) {
Ref<Script> obj_script = obj->get_script();
if (!obj_script.is_valid()) {
return 1; //well, definitely not the script because object we got has no script.
@@ -831,7 +831,7 @@ public:
}
};
-VisualScriptNodeInstance *VisualScriptTypeCast::instance(VisualScriptInstance *p_instance) {
+VisualScriptNodeInstance *VisualScriptTypeCast::instantiate(VisualScriptInstance *p_instance) {
VisualScriptNodeInstanceTypeCast *instance = memnew(VisualScriptNodeInstanceTypeCast);
instance->instance = p_instance;
instance->base_type = base_type;
@@ -852,11 +852,11 @@ void VisualScriptTypeCast::_bind_methods() {
}
String script_ext_hint;
- for (List<String>::Element *E = script_extensions.front(); E; E = E->next()) {
- if (script_ext_hint != String()) {
+ for (const String &E : script_extensions) {
+ if (!script_ext_hint.is_empty()) {
script_ext_hint += ",";
}
- script_ext_hint += "*." + E->get();
+ script_ext_hint += "*." + E;
}
ADD_PROPERTY(PropertyInfo(Variant::STRING, "base_type", PROPERTY_HINT_TYPE_STRING, "Object"), "set_base_type", "get_base_type");
diff --git a/modules/visual_script/visual_script_flow_control.h b/modules/visual_script/visual_script_flow_control.h
index d9c4dedafd..7ffdf3df65 100644
--- a/modules/visual_script/visual_script_flow_control.h
+++ b/modules/visual_script/visual_script_flow_control.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -64,7 +64,7 @@ public:
void set_enable_return_value(bool p_enable);
bool is_return_value_enabled() const;
- virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override;
+ virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override;
VisualScriptReturn();
};
@@ -91,7 +91,7 @@ public:
virtual String get_text() const override;
virtual String get_category() const override { return "flow_control"; }
- virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override;
+ virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override;
VisualScriptCondition();
};
@@ -118,7 +118,7 @@ public:
virtual String get_text() const override;
virtual String get_category() const override { return "flow_control"; }
- virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override;
+ virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override;
VisualScriptWhile();
};
@@ -145,7 +145,7 @@ public:
virtual String get_text() const override;
virtual String get_category() const override { return "flow_control"; }
- virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override;
+ virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override;
VisualScriptIterator();
};
@@ -177,7 +177,7 @@ public:
void set_steps(int p_steps);
int get_steps() const;
- virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override;
+ virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override;
VisualScriptSequence();
};
@@ -220,7 +220,7 @@ public:
virtual String get_text() const override;
virtual String get_category() const override { return "flow_control"; }
- virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override;
+ virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override;
VisualScriptSwitch();
};
@@ -258,7 +258,7 @@ public:
virtual TypeGuess guess_output_type(TypeGuess *p_inputs, int p_output) const override;
- virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override;
+ virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override;
VisualScriptTypeCast();
};
diff --git a/modules/visual_script/visual_script_func_nodes.cpp b/modules/visual_script/visual_script_func_nodes.cpp
index 9310b86627..483fc8b6c3 100644
--- a/modules/visual_script/visual_script_func_nodes.cpp
+++ b/modules/visual_script/visual_script_func_nodes.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -33,6 +33,7 @@
#include "core/config/engine.h"
#include "core/io/resource_loader.h"
#include "core/os/os.h"
+#include "core/templates/local_vector.h"
#include "scene/main/node.h"
#include "scene/main/scene_tree.h"
#include "visual_script_nodes.h"
@@ -254,25 +255,32 @@ PropertyInfo VisualScriptFunctionCall::get_output_value_port_info(int p_idx) con
}
String VisualScriptFunctionCall::get_caption() const {
- if (call_mode == CALL_MODE_SELF) {
- return " " + String(function) + "()";
- }
- if (call_mode == CALL_MODE_SINGLETON) {
- return String(singleton) + ":" + String(function) + "()";
- } else if (call_mode == CALL_MODE_BASIC_TYPE) {
- return Variant::get_type_name(basic_type) + "." + String(function) + "()";
- } else if (call_mode == CALL_MODE_NODE_PATH) {
- return " [" + String(base_path.simplified()) + "]." + String(function) + "()";
- } else {
- return " " + base_type + "." + String(function) + "()";
- }
+ return " " + String(function) + "()";
}
String VisualScriptFunctionCall::get_text() const {
+ String text;
+
+ if (call_mode == CALL_MODE_BASIC_TYPE) {
+ text = vformat(RTR("On %s"), Variant::get_type_name(basic_type));
+ } else if (call_mode == CALL_MODE_INSTANCE) {
+ text = vformat(RTR("On %s"), base_type);
+ } else if (call_mode == CALL_MODE_NODE_PATH) {
+ text = "[" + String(base_path.simplified()) + "]";
+ } else if (call_mode == CALL_MODE_SELF) {
+ text = RTR("On Self");
+ } else if (call_mode == CALL_MODE_SINGLETON) {
+ text = String(singleton) + ":" + String(function) + "()";
+ }
+
if (rpc_call_mode) {
- return "RPC";
+ text += " RPC";
+ if (rpc_call_mode == RPC_UNRELIABLE || rpc_call_mode == RPC_UNRELIABLE_TO_ID) {
+ text += " UNREL";
+ }
}
- return "";
+
+ return text;
}
void VisualScriptFunctionCall::set_basic_type(Variant::Type p_type) {
@@ -363,7 +371,7 @@ void VisualScriptFunctionCall::_update_method_cache() {
} else if (call_mode == CALL_MODE_INSTANCE) {
type = base_type;
- if (base_script != String()) {
+ if (!base_script.is_empty()) {
if (!ResourceCache::has(base_script) && ScriptServer::edit_request_func) {
ScriptServer::edit_request_func(base_script); //make sure it's loaded
}
@@ -507,35 +515,35 @@ Dictionary VisualScriptFunctionCall::_get_argument_cache() const {
void VisualScriptFunctionCall::_validate_property(PropertyInfo &property) const {
if (property.name == "base_type") {
if (call_mode != CALL_MODE_INSTANCE) {
- property.usage = PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL;
+ property.usage = PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL;
}
}
if (property.name == "base_script") {
if (call_mode != CALL_MODE_INSTANCE) {
- property.usage = 0;
+ property.usage = PROPERTY_USAGE_NONE;
}
}
if (property.name == "basic_type") {
if (call_mode != CALL_MODE_BASIC_TYPE) {
- property.usage = 0;
+ property.usage = PROPERTY_USAGE_NONE;
}
}
if (property.name == "singleton") {
if (call_mode != CALL_MODE_SINGLETON) {
- property.usage = 0;
+ property.usage = PROPERTY_USAGE_NONE;
} else {
List<Engine::Singleton> names;
Engine::get_singleton()->get_singletons(&names);
property.hint = PROPERTY_HINT_ENUM;
String sl;
- for (List<Engine::Singleton>::Element *E = names.front(); E; E = E->next()) {
- if (sl != String()) {
+ for (const Engine::Singleton &E : names) {
+ if (!sl.is_empty()) {
sl += ",";
}
- sl += E->get().name;
+ sl += E.name;
}
property.hint_string = sl;
}
@@ -543,7 +551,7 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo &property) const
if (property.name == "node_path") {
if (call_mode != CALL_MODE_NODE_PATH) {
- property.usage = 0;
+ property.usage = PROPERTY_USAGE_NONE;
} else {
Node *bnode = _get_base_node();
if (bnode) {
@@ -573,7 +581,7 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo &property) const
property.hint = PROPERTY_HINT_METHOD_OF_BASE_TYPE;
property.hint_string = base_type;
- if (base_script != String()) {
+ if (!base_script.is_empty()) {
if (!ResourceCache::has(base_script) && ScriptServer::edit_request_func) {
ScriptServer::edit_request_func(base_script); //make sure it's loaded
}
@@ -614,7 +622,7 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo &property) const
}
if (mc == 0) {
- property.usage = 0; //do not show
+ property.usage = PROPERTY_USAGE_NONE; //do not show
} else {
property.hint_string = "0," + itos(mc) + ",1";
}
@@ -622,7 +630,7 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo &property) const
if (property.name == "rpc_call_mode") {
if (call_mode == CALL_MODE_BASIC_TYPE) {
- property.usage = 0;
+ property.usage = PROPERTY_USAGE_NONE;
}
}
}
@@ -676,11 +684,11 @@ void VisualScriptFunctionCall::_bind_methods() {
}
String script_ext_hint;
- for (List<String>::Element *E = script_extensions.front(); E; E = E->next()) {
- if (script_ext_hint != String()) {
+ for (const String &E : script_extensions) {
+ if (!script_ext_hint.is_empty()) {
script_ext_hint += ",";
}
- script_ext_hint += "*." + E->get();
+ script_ext_hint += "*." + E;
}
ADD_PROPERTY(PropertyInfo(Variant::INT, "call_mode", PROPERTY_HINT_ENUM, "Self,Node Path,Instance,Basic Type,Singleton"), "set_call_mode", "get_call_mode");
@@ -689,7 +697,7 @@ void VisualScriptFunctionCall::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::STRING, "singleton"), "set_singleton", "get_singleton");
ADD_PROPERTY(PropertyInfo(Variant::INT, "basic_type", PROPERTY_HINT_ENUM, bt), "set_basic_type", "get_basic_type");
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "node_path", PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE), "set_base_path", "get_base_path");
- ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "argument_cache", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_argument_cache", "_get_argument_cache");
+ ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "argument_cache", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "_set_argument_cache", "_get_argument_cache");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "function"), "set_function", "get_function"); //when set, if loaded properly, will override argument count.
ADD_PROPERTY(PropertyInfo(Variant::INT, "use_default_args"), "set_use_default_args", "get_use_default_args");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "validate"), "set_validate", "get_validate");
@@ -712,17 +720,17 @@ class VisualScriptNodeInstanceFunctionCall : public VisualScriptNodeInstance {
public:
VisualScriptFunctionCall::CallMode call_mode;
NodePath node_path;
- int input_args;
- bool validate;
- int returns;
+ int input_args = 0;
+ bool validate = false;
+ int returns = 0;
VisualScriptFunctionCall::RPCCallMode rpc_mode;
StringName function;
StringName singleton;
- VisualScriptFunctionCall *node;
- VisualScriptInstance *instance;
+ VisualScriptFunctionCall *node = nullptr;
+ VisualScriptInstance *instance = nullptr;
- //virtual int get_working_memory_size() const { return 0; }
+ //virtual int get_working_memory_size() const override { return 0; }
//virtual bool is_output_port_unsequenced(int p_idx) const { return false; }
//virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return true; }
@@ -737,25 +745,27 @@ public:
}
int to_id = 0;
- bool reliable = true;
+ //bool reliable = true;
if (rpc_mode >= VisualScriptFunctionCall::RPC_RELIABLE_TO_ID) {
to_id = *p_args[0];
p_args += 1;
p_argcount -= 1;
- if (rpc_mode == VisualScriptFunctionCall::RPC_UNRELIABLE_TO_ID) {
- reliable = false;
- }
- } else if (rpc_mode == VisualScriptFunctionCall::RPC_UNRELIABLE) {
- reliable = false;
+ //if (rpc_mode == VisualScriptFunctionCall::RPC_UNRELIABLE_TO_ID) {
+ //reliable = false;
+ //}
}
+ //else if (rpc_mode == VisualScriptFunctionCall::RPC_UNRELIABLE) {
+ //reliable = false;
+ //}
- node->rpcp(to_id, !reliable, function, p_args, p_argcount);
+ // TODO reliable?
+ node->rpcp(to_id, function, p_args, p_argcount);
return true;
}
- virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) {
+ virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
switch (call_mode) {
case VisualScriptFunctionCall::CALL_MODE_SELF: {
Object *object = instance->get_owner_ptr();
@@ -763,9 +773,9 @@ public:
if (rpc_mode) {
call_rpc(object, p_inputs, input_args);
} else if (returns) {
- *p_outputs[0] = object->call(function, p_inputs, input_args, r_error);
+ *p_outputs[0] = object->callp(function, p_inputs, input_args, r_error);
} else {
- object->call(function, p_inputs, input_args, r_error);
+ object->callp(function, p_inputs, input_args, r_error);
}
} break;
case VisualScriptFunctionCall::CALL_MODE_NODE_PATH: {
@@ -786,9 +796,9 @@ public:
if (rpc_mode) {
call_rpc(node, p_inputs, input_args);
} else if (returns) {
- *p_outputs[0] = another->call(function, p_inputs, input_args, r_error);
+ *p_outputs[0] = another->callp(function, p_inputs, input_args, r_error);
} else {
- another->call(function, p_inputs, input_args, r_error);
+ another->callp(function, p_inputs, input_args, r_error);
}
} break;
@@ -804,21 +814,21 @@ public:
} else if (returns) {
if (call_mode == VisualScriptFunctionCall::CALL_MODE_INSTANCE) {
if (returns >= 2) {
- v.call(function, p_inputs + 1, input_args, *p_outputs[1], r_error);
+ v.callp(function, p_inputs + 1, input_args, *p_outputs[1], r_error);
} else if (returns == 1) {
Variant ret;
- v.call(function, p_inputs + 1, input_args, ret, r_error);
+ v.callp(function, p_inputs + 1, input_args, ret, r_error);
} else {
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
r_error_str = "Invalid returns count for call_mode == CALL_MODE_INSTANCE";
return 0;
}
} else {
- v.call(function, p_inputs + 1, input_args, *p_outputs[0], r_error);
+ v.callp(function, p_inputs + 1, input_args, *p_outputs[0], r_error);
}
} else {
Variant ret;
- v.call(function, p_inputs + 1, input_args, ret, r_error);
+ v.callp(function, p_inputs + 1, input_args, ret, r_error);
}
if (call_mode == VisualScriptFunctionCall::CALL_MODE_INSTANCE) {
@@ -837,9 +847,9 @@ public:
if (rpc_mode) {
call_rpc(object, p_inputs, input_args);
} else if (returns) {
- *p_outputs[0] = object->call(function, p_inputs, input_args, r_error);
+ *p_outputs[0] = object->callp(function, p_inputs, input_args, r_error);
} else {
- object->call(function, p_inputs, input_args, r_error);
+ object->callp(function, p_inputs, input_args, r_error);
}
} break;
}
@@ -854,7 +864,7 @@ public:
}
};
-VisualScriptNodeInstance *VisualScriptFunctionCall::instance(VisualScriptInstance *p_instance) {
+VisualScriptNodeInstance *VisualScriptFunctionCall::instantiate(VisualScriptInstance *p_instance) {
VisualScriptNodeInstanceFunctionCall *instance = memnew(VisualScriptNodeInstanceFunctionCall);
instance->node = this;
instance->instance = p_instance;
@@ -889,7 +899,7 @@ VisualScriptFunctionCall::VisualScriptFunctionCall() {
template <VisualScriptFunctionCall::CallMode cmode>
static Ref<VisualScriptNode> create_function_call_node(const String &p_name) {
Ref<VisualScriptFunctionCall> node;
- node.instance();
+ node.instantiate();
node->set_call_mode(cmode);
return node;
}
@@ -899,11 +909,11 @@ static Ref<VisualScriptNode> create_function_call_node(const String &p_name) {
//////////////////////////////////////////
int VisualScriptPropertySet::get_output_sequence_port_count() const {
- return call_mode != CALL_MODE_BASIC_TYPE ? 1 : 0;
+ return 1;
}
bool VisualScriptPropertySet::has_input_sequence_port() const {
- return call_mode != CALL_MODE_BASIC_TYPE;
+ return true;
}
Node *VisualScriptPropertySet::_get_base_node() const {
@@ -988,31 +998,33 @@ PropertyInfo VisualScriptPropertySet::get_input_value_port_info(int p_idx) const
if (p_idx == 0) {
PropertyInfo pi;
pi.type = (call_mode == CALL_MODE_INSTANCE ? Variant::OBJECT : basic_type);
- pi.name = (call_mode == CALL_MODE_INSTANCE ? String("instance") : Variant::get_type_name(basic_type).to_lower());
- _adjust_input_index(pi);
+ pi.name = "instance";
return pi;
}
}
List<PropertyInfo> props;
ClassDB::get_property_list(_get_base_type(), &props, false);
- for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
- if (E->get().name == property) {
- PropertyInfo pinfo = PropertyInfo(E->get().type, "value", PROPERTY_HINT_TYPE_STRING, E->get().hint_string);
+ for (const PropertyInfo &E : props) {
+ if (E.name == property) {
+ String detail_prop_name = property;
+ if (index != StringName()) {
+ detail_prop_name += "." + String(index);
+ }
+ PropertyInfo pinfo = PropertyInfo(E.type, detail_prop_name, E.hint, E.hint_string);
_adjust_input_index(pinfo);
return pinfo;
}
}
PropertyInfo pinfo = type_cache;
- pinfo.name = "value";
_adjust_input_index(pinfo);
return pinfo;
}
PropertyInfo VisualScriptPropertySet::get_output_value_port_info(int p_idx) const {
if (call_mode == CALL_MODE_BASIC_TYPE) {
- return PropertyInfo(basic_type, "out");
+ return PropertyInfo(basic_type, "pass");
} else if (call_mode == CALL_MODE_INSTANCE) {
return PropertyInfo(Variant::OBJECT, "pass", PROPERTY_HINT_TYPE_STRING, get_base_type());
} else {
@@ -1021,30 +1033,41 @@ PropertyInfo VisualScriptPropertySet::get_output_value_port_info(int p_idx) cons
}
String VisualScriptPropertySet::get_caption() const {
- static const char *opname[ASSIGN_OP_MAX] = {
- "Set", "Add", "Subtract", "Multiply", "Divide", "Mod", "ShiftLeft", "ShiftRight", "BitAnd", "BitOr", "BitXor"
+ static const LocalVector<String> opname = {
+ RTR("Set %s"),
+ RTR("Add %s"),
+ RTR("Subtract %s"),
+ RTR("Multiply %s"),
+ RTR("Divide %s"),
+ RTR("Mod %s"),
+ RTR("ShiftLeft %s"),
+ RTR("ShiftRight %s"),
+ RTR("BitAnd %s"),
+ RTR("BitOr %s"),
+ RTR("BitXor %s"),
};
- String prop = String(opname[assign_op]) + " " + property;
+ String prop = property;
if (index != StringName()) {
prop += "." + String(index);
}
- return prop;
+ return vformat(opname[assign_op], prop);
}
String VisualScriptPropertySet::get_text() const {
+ if (!has_input_sequence_port()) {
+ return "";
+ }
if (call_mode == CALL_MODE_BASIC_TYPE) {
- return String("On ") + Variant::get_type_name(basic_type);
+ return vformat(RTR("On %s"), Variant::get_type_name(basic_type));
+ } else if (call_mode == CALL_MODE_INSTANCE) {
+ return vformat(RTR("On %s"), base_type);
+ } else if (call_mode == CALL_MODE_NODE_PATH) {
+ return " [" + String(base_path.simplified()) + "]";
+ } else {
+ return RTR("On Self");
}
-
- static const char *cname[3] = {
- "Self",
- "Scene Node",
- "Instance"
- };
-
- return String("On ") + cname[call_mode];
}
void VisualScriptPropertySet::_update_base_type() {
@@ -1123,9 +1146,9 @@ void VisualScriptPropertySet::_update_cache() {
List<PropertyInfo> pinfo;
v.get_property_list(&pinfo);
- for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
- if (E->get().name == property) {
- type_cache = E->get();
+ for (const PropertyInfo &E : pinfo) {
+ if (E.name == property) {
+ type_cache = E;
}
}
@@ -1149,7 +1172,7 @@ void VisualScriptPropertySet::_update_cache() {
}
} else if (call_mode == CALL_MODE_INSTANCE) {
type = base_type;
- if (base_script != String()) {
+ if (!base_script.is_empty()) {
if (!ResourceCache::has(base_script) && ScriptServer::edit_request_func) {
ScriptServer::edit_request_func(base_script); //make sure it's loaded
}
@@ -1174,9 +1197,9 @@ void VisualScriptPropertySet::_update_cache() {
script->get_script_property_list(&pinfo);
}
- for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
- if (E->get().name == property) {
- type_cache = E->get();
+ for (const PropertyInfo &E : pinfo) {
+ if (E.name == property) {
+ type_cache = E;
return;
}
}
@@ -1270,25 +1293,25 @@ VisualScriptPropertySet::AssignOp VisualScriptPropertySet::get_assign_op() const
void VisualScriptPropertySet::_validate_property(PropertyInfo &property) const {
if (property.name == "base_type") {
if (call_mode != CALL_MODE_INSTANCE) {
- property.usage = PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL;
+ property.usage = PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL;
}
}
if (property.name == "base_script") {
if (call_mode != CALL_MODE_INSTANCE) {
- property.usage = 0;
+ property.usage = PROPERTY_USAGE_NONE;
}
}
if (property.name == "basic_type") {
if (call_mode != CALL_MODE_BASIC_TYPE) {
- property.usage = 0;
+ property.usage = PROPERTY_USAGE_NONE;
}
}
if (property.name == "node_path") {
if (call_mode != CALL_MODE_NODE_PATH) {
- property.usage = 0;
+ property.usage = PROPERTY_USAGE_NONE;
} else {
Node *bnode = _get_base_node();
if (bnode) {
@@ -1309,7 +1332,7 @@ void VisualScriptPropertySet::_validate_property(PropertyInfo &property) const {
property.hint = PROPERTY_HINT_PROPERTY_OF_BASE_TYPE;
property.hint_string = base_type;
- if (base_script != String()) {
+ if (!base_script.is_empty()) {
if (!ResourceCache::has(base_script) && ScriptServer::edit_request_func) {
ScriptServer::edit_request_func(base_script); //make sure it's loaded
}
@@ -1342,15 +1365,15 @@ void VisualScriptPropertySet::_validate_property(PropertyInfo &property) const {
List<PropertyInfo> plist;
v.get_property_list(&plist);
String options = "";
- for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {
- options += "," + E->get().name;
+ for (const PropertyInfo &E : plist) {
+ options += "," + E.name;
}
property.hint = PROPERTY_HINT_ENUM;
property.hint_string = options;
property.type = Variant::STRING;
- if (options == "") {
- property.usage = 0; //hide if type has no usable index
+ if (options.is_empty()) {
+ property.usage = PROPERTY_USAGE_NONE; //hide if type has no usable index
}
}
}
@@ -1398,17 +1421,17 @@ void VisualScriptPropertySet::_bind_methods() {
}
String script_ext_hint;
- for (List<String>::Element *E = script_extensions.front(); E; E = E->next()) {
- if (script_ext_hint != String()) {
+ for (const String &E : script_extensions) {
+ if (!script_ext_hint.is_empty()) {
script_ext_hint += ",";
}
- script_ext_hint += "*." + E->get();
+ script_ext_hint += "*." + E;
}
ADD_PROPERTY(PropertyInfo(Variant::INT, "set_mode", PROPERTY_HINT_ENUM, "Self,Node Path,Instance,Basic Type"), "set_call_mode", "get_call_mode");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "base_type", PROPERTY_HINT_TYPE_STRING, "Object"), "set_base_type", "get_base_type");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "base_script", PROPERTY_HINT_FILE, script_ext_hint), "set_base_script", "get_base_script");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "type_cache", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_type_cache", "_get_type_cache");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "type_cache", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "_set_type_cache", "_get_type_cache");
ADD_PROPERTY(PropertyInfo(Variant::INT, "basic_type", PROPERTY_HINT_ENUM, bt), "set_basic_type", "get_basic_type");
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "node_path", PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE), "set_base_path", "get_base_path");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "property"), "set_property", "get_property");
@@ -1439,13 +1462,13 @@ public:
NodePath node_path;
StringName property;
- VisualScriptPropertySet *node;
- VisualScriptInstance *instance;
+ VisualScriptPropertySet *node = nullptr;
+ VisualScriptInstance *instance = nullptr;
VisualScriptPropertySet::AssignOp assign_op;
StringName index;
- bool needs_get;
+ bool needs_get = false;
- //virtual int get_working_memory_size() const { return 0; }
+ //virtual int get_working_memory_size() const override { return 0; }
//virtual bool is_output_port_unsequenced(int p_idx) const { return false; }
//virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return true; }
@@ -1506,7 +1529,7 @@ public:
}
}
- virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) {
+ virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
switch (call_mode) {
case VisualScriptPropertySet::CALL_MODE_SELF: {
Object *object = instance->get_owner_ptr();
@@ -1585,7 +1608,7 @@ public:
}
};
-VisualScriptNodeInstance *VisualScriptPropertySet::instance(VisualScriptInstance *p_instance) {
+VisualScriptNodeInstance *VisualScriptPropertySet::instantiate(VisualScriptInstance *p_instance) {
VisualScriptNodeInstancePropertySet *instance = memnew(VisualScriptNodeInstancePropertySet);
instance->node = this;
instance->instance = p_instance;
@@ -1616,7 +1639,7 @@ VisualScriptPropertySet::VisualScriptPropertySet() {
template <VisualScriptPropertySet::CallMode cmode>
static Ref<VisualScriptNode> create_property_set_node(const String &p_name) {
Ref<VisualScriptPropertySet> node;
- node.instance();
+ node.instantiate();
node->set_call_mode(cmode);
return node;
}
@@ -1705,7 +1728,9 @@ int VisualScriptPropertyGet::get_input_value_port_count() const {
}
int VisualScriptPropertyGet::get_output_value_port_count() const {
- return 1;
+ int pc = (call_mode == CALL_MODE_BASIC_TYPE || call_mode == CALL_MODE_INSTANCE) ? 2 : 1;
+
+ return pc;
}
String VisualScriptPropertyGet::get_output_sequence_port_text(int p_port) const {
@@ -1725,33 +1750,46 @@ PropertyInfo VisualScriptPropertyGet::get_input_value_port_info(int p_idx) const
}
PropertyInfo VisualScriptPropertyGet::get_output_value_port_info(int p_idx) const {
- List<PropertyInfo> props;
- ClassDB::get_property_list(_get_base_type(), &props, false);
- for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
- if (E->get().name == property) {
- return PropertyInfo(E->get().type, "value." + String(index));
+ if (call_mode == CALL_MODE_BASIC_TYPE && p_idx == 0) {
+ return PropertyInfo(basic_type, "pass");
+ } else if (call_mode == CALL_MODE_INSTANCE && p_idx == 0) {
+ return PropertyInfo(Variant::OBJECT, "pass", PROPERTY_HINT_TYPE_STRING, get_base_type());
+ } else {
+ List<PropertyInfo> props;
+ ClassDB::get_property_list(_get_base_type(), &props, false);
+ for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
+ if (E->get().name == property) {
+ PropertyInfo pinfo = PropertyInfo(E->get().type, String(property) + "." + String(index), E->get().hint, E->get().hint_string);
+ _adjust_input_index(pinfo);
+ return pinfo;
+ }
}
}
- return PropertyInfo(type_cache, "value");
+ PropertyInfo pinfo = PropertyInfo(type_cache, "value");
+ _adjust_input_index(pinfo);
+ return pinfo;
}
String VisualScriptPropertyGet::get_caption() const {
- return String("Get ") + property;
+ String prop = property;
+ if (index != StringName()) {
+ prop += "." + String(index);
+ }
+
+ return vformat(RTR("Get %s"), prop);
}
String VisualScriptPropertyGet::get_text() const {
if (call_mode == CALL_MODE_BASIC_TYPE) {
- return String("On ") + Variant::get_type_name(basic_type);
+ return vformat(RTR("On %s"), Variant::get_type_name(basic_type));
+ } else if (call_mode == CALL_MODE_INSTANCE) {
+ return vformat(RTR("On %s"), base_type);
+ } else if (call_mode == CALL_MODE_NODE_PATH) {
+ return " [" + String(base_path.simplified()) + "]";
+ } else {
+ return RTR("On Self");
}
-
- static const char *cname[3] = {
- "Self",
- "Scene Node",
- "Instance"
- };
-
- return String("On ") + cname[call_mode];
}
void VisualScriptPropertyGet::set_base_type(const StringName &p_type) {
@@ -1793,9 +1831,9 @@ void VisualScriptPropertyGet::_update_cache() {
List<PropertyInfo> pinfo;
v.get_property_list(&pinfo);
- for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
- if (E->get().name == property) {
- type_cache = E->get().type;
+ for (const PropertyInfo &E : pinfo) {
+ if (E.name == property) {
+ type_cache = E.type;
return;
}
}
@@ -1820,7 +1858,7 @@ void VisualScriptPropertyGet::_update_cache() {
}
} else if (call_mode == CALL_MODE_INSTANCE) {
type = base_type;
- if (base_script != String()) {
+ if (!base_script.is_empty()) {
if (!ResourceCache::has(base_script) && ScriptServer::edit_request_func) {
ScriptServer::edit_request_func(base_script); //make sure it's loaded
}
@@ -1931,6 +1969,19 @@ Variant::Type VisualScriptPropertyGet::_get_type_cache() const {
return type_cache;
}
+void VisualScriptPropertyGet::_adjust_input_index(PropertyInfo &pinfo) const {
+ if (index != StringName()) {
+ Variant v;
+ Callable::CallError ce;
+ Variant::construct(pinfo.type, v, nullptr, 0, ce);
+ Variant i = v.get(index);
+ pinfo.type = i.get_type();
+ pinfo.name = String(property) + "." + index;
+ } else {
+ pinfo.name = String(property);
+ }
+}
+
void VisualScriptPropertyGet::set_index(const StringName &p_type) {
if (index == p_type) {
return;
@@ -1948,25 +1999,25 @@ StringName VisualScriptPropertyGet::get_index() const {
void VisualScriptPropertyGet::_validate_property(PropertyInfo &property) const {
if (property.name == "base_type") {
if (call_mode != CALL_MODE_INSTANCE) {
- property.usage = PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL;
+ property.usage = PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL;
}
}
if (property.name == "base_script") {
if (call_mode != CALL_MODE_INSTANCE) {
- property.usage = 0;
+ property.usage = PROPERTY_USAGE_NONE;
}
}
if (property.name == "basic_type") {
if (call_mode != CALL_MODE_BASIC_TYPE) {
- property.usage = 0;
+ property.usage = PROPERTY_USAGE_NONE;
}
}
if (property.name == "node_path") {
if (call_mode != CALL_MODE_NODE_PATH) {
- property.usage = 0;
+ property.usage = PROPERTY_USAGE_NONE;
} else {
Node *bnode = _get_base_node();
if (bnode) {
@@ -1987,7 +2038,7 @@ void VisualScriptPropertyGet::_validate_property(PropertyInfo &property) const {
property.hint = PROPERTY_HINT_PROPERTY_OF_BASE_TYPE;
property.hint_string = base_type;
- if (base_script != String()) {
+ if (!base_script.is_empty()) {
if (!ResourceCache::has(base_script) && ScriptServer::edit_request_func) {
ScriptServer::edit_request_func(base_script); //make sure it's loaded
}
@@ -2019,15 +2070,15 @@ void VisualScriptPropertyGet::_validate_property(PropertyInfo &property) const {
List<PropertyInfo> plist;
v.get_property_list(&plist);
String options = "";
- for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {
- options += "," + E->get().name;
+ for (const PropertyInfo &E : plist) {
+ options += "," + E.name;
}
property.hint = PROPERTY_HINT_ENUM;
property.hint_string = options;
property.type = Variant::STRING;
- if (options == "") {
- property.usage = 0; //hide if type has no usable index
+ if (options.is_empty()) {
+ property.usage = PROPERTY_USAGE_NONE; //hide if type has no usable index
}
}
}
@@ -2072,17 +2123,17 @@ void VisualScriptPropertyGet::_bind_methods() {
}
String script_ext_hint;
- for (List<String>::Element *E = script_extensions.front(); E; E = E->next()) {
- if (script_ext_hint != String()) {
+ for (const String &E : script_extensions) {
+ if (!script_ext_hint.is_empty()) {
script_ext_hint += ",";
}
- script_ext_hint += "." + E->get();
+ script_ext_hint += "." + E;
}
ADD_PROPERTY(PropertyInfo(Variant::INT, "set_mode", PROPERTY_HINT_ENUM, "Self,Node Path,Instance,Basic Type"), "set_call_mode", "get_call_mode");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "base_type", PROPERTY_HINT_TYPE_STRING, "Object"), "set_base_type", "get_base_type");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "base_script", PROPERTY_HINT_FILE, script_ext_hint), "set_base_script", "get_base_script");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "type_cache", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_type_cache", "_get_type_cache");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "type_cache", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "_set_type_cache", "_get_type_cache");
ADD_PROPERTY(PropertyInfo(Variant::INT, "basic_type", PROPERTY_HINT_ENUM, bt), "set_basic_type", "get_basic_type");
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "node_path", PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE), "set_base_path", "get_base_path");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "property"), "set_property", "get_property");
@@ -2101,10 +2152,10 @@ public:
StringName property;
StringName index;
- VisualScriptPropertyGet *node;
- VisualScriptInstance *instance;
+ VisualScriptPropertyGet *node = nullptr;
+ VisualScriptInstance *instance = nullptr;
- virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) {
+ virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
switch (call_mode) {
case VisualScriptPropertyGet::CALL_MODE_SELF: {
Object *object = instance->get_owner_ptr();
@@ -2157,15 +2208,17 @@ public:
bool valid;
Variant v = *p_inputs[0];
- *p_outputs[0] = v.get(property, &valid);
+ *p_outputs[1] = v.get(property, &valid);
if (index != StringName()) {
- *p_outputs[0] = p_outputs[0]->get_named(index, valid);
+ *p_outputs[1] = p_outputs[1]->get_named(index, valid);
}
if (!valid) {
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
r_error_str = RTR("Invalid index property name.");
}
+
+ *p_outputs[0] = v;
};
}
@@ -2173,7 +2226,7 @@ public:
}
};
-VisualScriptNodeInstance *VisualScriptPropertyGet::instance(VisualScriptInstance *p_instance) {
+VisualScriptNodeInstance *VisualScriptPropertyGet::instantiate(VisualScriptInstance *p_instance) {
VisualScriptNodeInstancePropertyGet *instance = memnew(VisualScriptNodeInstancePropertyGet);
instance->node = this;
instance->instance = p_instance;
@@ -2195,7 +2248,7 @@ VisualScriptPropertyGet::VisualScriptPropertyGet() {
template <VisualScriptPropertyGet::CallMode cmode>
static Ref<VisualScriptNode> create_property_get_node(const String &p_name) {
Ref<VisualScriptPropertyGet> node;
- node.instance();
+ node.instantiate();
node->set_call_mode(cmode);
return node;
}
@@ -2251,7 +2304,7 @@ PropertyInfo VisualScriptEmitSignal::get_output_value_port_info(int p_idx) const
}
String VisualScriptEmitSignal::get_caption() const {
- return "Emit " + String(name);
+ return vformat(RTR("Emit %s"), name);
}
void VisualScriptEmitSignal::set_signal(const StringName &p_type) {
@@ -2274,18 +2327,26 @@ void VisualScriptEmitSignal::_validate_property(PropertyInfo &property) const {
property.hint = PROPERTY_HINT_ENUM;
List<StringName> sigs;
+ List<MethodInfo> base_sigs;
Ref<VisualScript> vs = get_visual_script();
if (vs.is_valid()) {
vs->get_custom_signal_list(&sigs);
+ ClassDB::get_signal_list(vs->get_instance_base_type(), &base_sigs);
}
String ml;
- for (List<StringName>::Element *E = sigs.front(); E; E = E->next()) {
- if (ml != String()) {
+ for (const StringName &E : sigs) {
+ if (!ml.is_empty()) {
+ ml += ",";
+ }
+ ml += E;
+ }
+ for (const MethodInfo &E : base_sigs) {
+ if (!ml.is_empty()) {
ml += ",";
}
- ml += E->get();
+ ml += E.name;
}
property.hint_string = ml;
@@ -2301,25 +2362,25 @@ void VisualScriptEmitSignal::_bind_methods() {
class VisualScriptNodeInstanceEmitSignal : public VisualScriptNodeInstance {
public:
- VisualScriptEmitSignal *node;
- VisualScriptInstance *instance;
- int argcount;
+ VisualScriptEmitSignal *node = nullptr;
+ VisualScriptInstance *instance = nullptr;
+ int argcount = 0;
StringName name;
- //virtual int get_working_memory_size() const { return 0; }
+ //virtual int get_working_memory_size() const override { return 0; }
//virtual bool is_output_port_unsequenced(int p_idx) const { return false; }
//virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return true; }
- virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) {
+ virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
Object *obj = instance->get_owner_ptr();
- obj->emit_signal(name, p_inputs, argcount);
+ obj->emit_signalp(name, p_inputs, argcount);
return 0;
}
};
-VisualScriptNodeInstance *VisualScriptEmitSignal::instance(VisualScriptInstance *p_instance) {
+VisualScriptNodeInstance *VisualScriptEmitSignal::instantiate(VisualScriptInstance *p_instance) {
VisualScriptNodeInstanceEmitSignal *instance = memnew(VisualScriptNodeInstanceEmitSignal);
instance->node = this;
instance->instance = p_instance;
@@ -2338,7 +2399,7 @@ static Ref<VisualScriptNode> create_basic_type_call_node(const String &p_name) {
String method = path[3];
Ref<VisualScriptFunctionCall> node;
- node.instance();
+ node.instantiate();
Variant::Type type = Variant::VARIANT_MAX;
@@ -2376,8 +2437,8 @@ void register_visual_script_func_nodes() {
List<MethodInfo> ml;
vt.get_method_list(&ml);
- for (List<MethodInfo>::Element *E = ml.front(); E; E = E->next()) {
- VisualScriptLanguage::singleton->add_register_func("functions/by_type/" + type_name + "/" + E->get().name, create_basic_type_call_node);
+ for (const MethodInfo &E : ml) {
+ VisualScriptLanguage::singleton->add_register_func("functions/by_type/" + type_name + "/" + E.name, create_basic_type_call_node);
}
}
}
diff --git a/modules/visual_script/visual_script_func_nodes.h b/modules/visual_script/visual_script_func_nodes.h
index 2ff9b7a981..886ed7bc81 100644
--- a/modules/visual_script/visual_script_func_nodes.h
+++ b/modules/visual_script/visual_script_func_nodes.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -125,7 +125,7 @@ public:
void set_rpc_call_mode(RPCCallMode p_mode);
RPCCallMode get_rpc_call_mode() const;
- virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override;
+ virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override;
virtual TypeGuess guess_output_type(TypeGuess *p_inputs, int p_output) const override;
@@ -231,7 +231,7 @@ public:
void set_assign_op(AssignOp p_op);
AssignOp get_assign_op() const;
- virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override;
+ virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override;
virtual TypeGuess guess_output_type(TypeGuess *p_inputs, int p_output) const override;
VisualScriptPropertySet();
@@ -272,6 +272,8 @@ private:
void _set_type_cache(Variant::Type p_type);
Variant::Type _get_type_cache() const;
+ void _adjust_input_index(PropertyInfo &pinfo) const;
+
protected:
virtual void _validate_property(PropertyInfo &property) const override;
@@ -314,7 +316,7 @@ public:
void set_index(const StringName &p_type);
StringName get_index() const;
- virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override;
+ virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override;
VisualScriptPropertyGet();
};
@@ -351,7 +353,7 @@ public:
void set_signal(const StringName &p_type);
StringName get_signal() const;
- virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override;
+ virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override;
VisualScriptEmitSignal();
};
diff --git a/modules/visual_script/visual_script_nodes.cpp b/modules/visual_script/visual_script_nodes.cpp
index fed6637acb..2dfc6da181 100644
--- a/modules/visual_script/visual_script_nodes.cpp
+++ b/modules/visual_script/visual_script_nodes.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -90,7 +90,7 @@ bool VisualScriptFunction::_set(const StringName &p_name, const Variant &p_value
}
if (p_name == "rpc/mode") {
- rpc_mode = MultiplayerAPI::RPCMode(int(p_value));
+ rpc_mode = Multiplayer::RPCMode(int(p_value));
return true;
}
@@ -163,7 +163,7 @@ void VisualScriptFunction::_get_property_list(List<PropertyInfo> *p_list) const
p_list->push_back(PropertyInfo(Variant::INT, "stack/size", PROPERTY_HINT_RANGE, "1,100000"));
}
p_list->push_back(PropertyInfo(Variant::BOOL, "stack/stackless"));
- p_list->push_back(PropertyInfo(Variant::INT, "rpc/mode", PROPERTY_HINT_ENUM, "Disabled,Remote,Master,Puppet,Remote Sync,Master Sync,Puppet Sync"));
+ p_list->push_back(PropertyInfo(Variant::INT, "rpc/mode", PROPERTY_HINT_ENUM, "Disabled,Any,Authority"));
}
int VisualScriptFunction::get_output_sequence_port_count() const {
@@ -191,7 +191,10 @@ PropertyInfo VisualScriptFunction::get_input_value_port_info(int p_idx) const {
}
PropertyInfo VisualScriptFunction::get_output_value_port_info(int p_idx) const {
- ERR_FAIL_INDEX_V(p_idx, arguments.size(), PropertyInfo());
+ // Need to check it without ERR_FAIL_COND, to prevent warnings from appearing on node creation via dragging.
+ if (p_idx < 0 || p_idx >= arguments.size()) {
+ return PropertyInfo();
+ }
PropertyInfo out;
out.type = arguments[p_idx].type;
out.name = arguments[p_idx].name;
@@ -201,7 +204,7 @@ PropertyInfo VisualScriptFunction::get_output_value_port_info(int p_idx) const {
}
String VisualScriptFunction::get_caption() const {
- return "Function";
+ return RTR("Function");
}
String VisualScriptFunction::get_text() const {
@@ -250,7 +253,7 @@ String VisualScriptFunction::get_argument_name(int p_argidx) const {
void VisualScriptFunction::remove_argument(int p_argidx) {
ERR_FAIL_INDEX(p_argidx, arguments.size());
- arguments.remove(p_argidx);
+ arguments.remove_at(p_argidx);
ports_changed_notify();
}
@@ -258,22 +261,22 @@ int VisualScriptFunction::get_argument_count() const {
return arguments.size();
}
-void VisualScriptFunction::set_rpc_mode(MultiplayerAPI::RPCMode p_mode) {
+void VisualScriptFunction::set_rpc_mode(Multiplayer::RPCMode p_mode) {
rpc_mode = p_mode;
}
-MultiplayerAPI::RPCMode VisualScriptFunction::get_rpc_mode() const {
+Multiplayer::RPCMode VisualScriptFunction::get_rpc_mode() const {
return rpc_mode;
}
class VisualScriptNodeInstanceFunction : public VisualScriptNodeInstance {
public:
- VisualScriptFunction *node;
- VisualScriptInstance *instance;
+ VisualScriptFunction *node = nullptr;
+ VisualScriptInstance *instance = nullptr;
- //virtual int get_working_memory_size() const { return 0; }
+ //virtual int get_working_memory_size() const override { return 0; }
- virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) {
+ virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
int ac = node->get_argument_count();
for (int i = 0; i < ac; i++) {
@@ -296,7 +299,7 @@ public:
}
};
-VisualScriptNodeInstance *VisualScriptFunction::instance(VisualScriptInstance *p_instance) {
+VisualScriptNodeInstance *VisualScriptFunction::instantiate(VisualScriptInstance *p_instance) {
VisualScriptNodeInstanceFunction *instance = memnew(VisualScriptNodeInstanceFunction);
instance->node = this;
instance->instance = p_instance;
@@ -308,14 +311,14 @@ void VisualScriptFunction::reset_state() {
stack_size = 256;
stack_less = false;
sequenced = true;
- rpc_mode = MultiplayerAPI::RPC_MODE_DISABLED;
+ rpc_mode = Multiplayer::RPC_MODE_DISABLED;
}
VisualScriptFunction::VisualScriptFunction() {
stack_size = 256;
stack_less = false;
sequenced = true;
- rpc_mode = MultiplayerAPI::RPC_MODE_DISABLED;
+ rpc_mode = Multiplayer::RPC_MODE_DISABLED;
}
void VisualScriptFunction::set_stack_less(bool p_enable) {
@@ -620,7 +623,7 @@ void VisualScriptLists::remove_input_data_port(int p_argidx) {
ERR_FAIL_INDEX(p_argidx, inputports.size());
- inputports.remove(p_argidx);
+ inputports.remove_at(p_argidx);
ports_changed_notify();
notify_property_list_changed();
@@ -676,7 +679,7 @@ void VisualScriptLists::remove_output_data_port(int p_argidx) {
ERR_FAIL_INDEX(p_argidx, outputports.size());
- outputports.remove(p_argidx);
+ outputports.remove_at(p_argidx);
ports_changed_notify();
notify_property_list_changed();
@@ -764,7 +767,7 @@ PropertyInfo VisualScriptComposeArray::get_output_value_port_info(int p_idx) con
}
String VisualScriptComposeArray::get_caption() const {
- return "Compose Array";
+ return RTR("Compose Array");
}
String VisualScriptComposeArray::get_text() const {
@@ -774,9 +777,9 @@ String VisualScriptComposeArray::get_text() const {
class VisualScriptComposeArrayNode : public VisualScriptNodeInstance {
public:
int input_count = 0;
- virtual int get_working_memory_size() const { return 0; }
+ virtual int get_working_memory_size() const override { return 0; }
- virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) {
+ virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
if (input_count > 0) {
Array arr;
for (int i = 0; i < input_count; i++) {
@@ -791,7 +794,7 @@ public:
}
};
-VisualScriptNodeInstance *VisualScriptComposeArray::instance(VisualScriptInstance *p_instance) {
+VisualScriptNodeInstance *VisualScriptComposeArray::instantiate(VisualScriptInstance *p_instance) {
VisualScriptComposeArrayNode *instance = memnew(VisualScriptComposeArrayNode);
instance->input_count = inputports.size();
return instance;
@@ -912,73 +915,135 @@ PropertyInfo VisualScriptOperator::get_output_value_port_info(int p_idx) const {
return pinfo;
}
-static const char *op_names[] = {
- //comparison
- "Are Equal", //OP_EQUAL,
- "Are Not Equal", //OP_NOT_EQUAL,
- "Less Than", //OP_LESS,
- "Less Than or Equal", //OP_LESS_EQUAL,
- "Greater Than", //OP_GREATER,
- "Greater Than or Equal", //OP_GREATER_EQUAL,
- //mathematic
- "Add", //OP_ADD,
- "Subtract", //OP_SUBTRACT,
- "Multiply", //OP_MULTIPLY,
- "Divide", //OP_DIVIDE,
- "Negate", //OP_NEGATE,
- "Positive", //OP_POSITIVE,
- "Remainder", //OP_MODULE,
- "Concatenate", //OP_STRING_CONCAT,
- //bitwise
- "Bit Shift Left", //OP_SHIFT_LEFT,
- "Bit Shift Right", //OP_SHIFT_RIGHT,
- "Bit And", //OP_BIT_AND,
- "Bit Or", //OP_BIT_OR,
- "Bit Xor", //OP_BIT_XOR,
- "Bit Negate", //OP_BIT_NEGATE,
- //logic
- "And", //OP_AND,
- "Or", //OP_OR,
- "Xor", //OP_XOR,
- "Not", //OP_NOT,
- //containment
- "In", //OP_IN,
-};
-
String VisualScriptOperator::get_caption() const {
- static const char32_t *op_names[] = {
- //comparison
- U"A = B", //OP_EQUAL,
- U"A \u2260 B", //OP_NOT_EQUAL,
- U"A < B", //OP_LESS,
- U"A \u2264 B", //OP_LESS_EQUAL,
- U"A > B", //OP_GREATER,
- U"A \u2265 B", //OP_GREATER_EQUAL,
- //mathematic
- U"A + B", //OP_ADD,
- U"A - B", //OP_SUBTRACT,
- U"A \u00D7 B", //OP_MULTIPLY,
- U"A \u00F7 B", //OP_DIVIDE,
- U"\u00AC A", //OP_NEGATE,
- U"+ A", //OP_POSITIVE,
- U"A mod B", //OP_MODULE,
- U"A .. B", //OP_STRING_CONCAT,
- //bitwise
- U"A << B", //OP_SHIFT_LEFT,
- U"A >> B", //OP_SHIFT_RIGHT,
- U"A & B", //OP_BIT_AND,
- U"A | B", //OP_BIT_OR,
- U"A ^ B", //OP_BIT_XOR,
- U"~A", //OP_BIT_NEGATE,
- //logic
- U"A and B", //OP_AND,
- U"A or B", //OP_OR,
- U"A xor B", //OP_XOR,
- U"not A", //OP_NOT,
- U"A in B", //OP_IN,
-
- };
- return op_names[op];
+ switch (op) {
+ // comparison
+ case Variant::OP_EQUAL:
+ return U"A = B";
+ case Variant::OP_NOT_EQUAL:
+ return U"A \u2260 B";
+ case Variant::OP_LESS:
+ return U"A < B";
+ case Variant::OP_LESS_EQUAL:
+ return U"A \u2264 B";
+ case Variant::OP_GREATER:
+ return U"A > B";
+ case Variant::OP_GREATER_EQUAL:
+ return U"A \u2265 B";
+
+ // mathematic
+ case Variant::OP_ADD:
+ return U"A + B";
+ case Variant::OP_SUBTRACT:
+ return U"A - B";
+ case Variant::OP_MULTIPLY:
+ return U"A \u00D7 B";
+ case Variant::OP_DIVIDE:
+ return U"A \u00F7 B";
+ case Variant::OP_NEGATE:
+ return U"\u00AC A";
+ case Variant::OP_POSITIVE:
+ return U"+ A";
+ case Variant::OP_MODULE:
+ return U"A mod B";
+
+ // bitwise
+ case Variant::OP_SHIFT_LEFT:
+ return U"A << B";
+ case Variant::OP_SHIFT_RIGHT:
+ return U"A >> B";
+ case Variant::OP_BIT_AND:
+ return U"A & B";
+ case Variant::OP_BIT_OR:
+ return U"A | B";
+ case Variant::OP_BIT_XOR:
+ return U"A ^ B";
+ case Variant::OP_BIT_NEGATE:
+ return U"~A";
+
+ // logic
+ case Variant::OP_AND:
+ return U"A and B";
+ case Variant::OP_OR:
+ return U"A or B";
+ case Variant::OP_XOR:
+ return U"A xor B";
+ case Variant::OP_NOT:
+ return U"not A";
+ case Variant::OP_IN:
+ return U"A in B";
+
+ default: {
+ ERR_FAIL_V_MSG(
+ U"Unknown node",
+ U"Unknown node type encountered, caption not available.");
+ }
+ }
+}
+
+String VisualScriptOperator::get_operator_name(Variant::Operator p_op) {
+ switch (p_op) {
+ // comparison
+ case Variant::OP_EQUAL:
+ return "Are Equal";
+ case Variant::OP_NOT_EQUAL:
+ return "Are Not Equal";
+ case Variant::OP_LESS:
+ return "Less Than";
+ case Variant::OP_LESS_EQUAL:
+ return "Less Than or Equal";
+ case Variant::OP_GREATER:
+ return "Greater Than";
+ case Variant::OP_GREATER_EQUAL:
+ return "Greater Than or Equal";
+
+ // mathematic
+ case Variant::OP_ADD:
+ return "Add";
+ case Variant::OP_SUBTRACT:
+ return "Subtract";
+ case Variant::OP_MULTIPLY:
+ return "Multiply";
+ case Variant::OP_DIVIDE:
+ return "Divide";
+ case Variant::OP_NEGATE:
+ return "Negate";
+ case Variant::OP_POSITIVE:
+ return "Positive";
+ case Variant::OP_MODULE:
+ return "Remainder";
+
+ // bitwise
+ case Variant::OP_SHIFT_LEFT:
+ return "Bit Shift Left";
+ case Variant::OP_SHIFT_RIGHT:
+ return "Bit Shift Right";
+ case Variant::OP_BIT_AND:
+ return "Bit And";
+ case Variant::OP_BIT_OR:
+ return "Bit Or";
+ case Variant::OP_BIT_XOR:
+ return "Bit Xor";
+ case Variant::OP_BIT_NEGATE:
+ return "Bit Negate";
+
+ // logic
+ case Variant::OP_AND:
+ return "And";
+ case Variant::OP_OR:
+ return "Or";
+ case Variant::OP_XOR:
+ return "Xor";
+ case Variant::OP_NOT:
+ return "Not";
+ case Variant::OP_IN:
+ return "In";
+
+ default: {
+ ERR_FAIL_INDEX_V(p_op, Variant::OP_MAX, "");
+ return "Unknown Operator";
+ }
+ }
}
void VisualScriptOperator::set_operator(Variant::Operator p_op) {
@@ -1018,7 +1083,7 @@ void VisualScriptOperator::_bind_methods() {
if (i > 0) {
types += ",";
}
- types += op_names[i];
+ types += get_operator_name(static_cast<Variant::Operator>(i));
}
String argt = "Any";
@@ -1032,12 +1097,12 @@ void VisualScriptOperator::_bind_methods() {
class VisualScriptNodeInstanceOperator : public VisualScriptNodeInstance {
public:
- bool unary;
+ bool unary = false;
Variant::Operator op;
- //virtual int get_working_memory_size() const { return 0; }
+ //virtual int get_working_memory_size() const override { return 0; }
- virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) {
+ virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
bool valid;
if (unary) {
Variant::evaluate(op, *p_inputs[0], Variant(), *p_outputs[0], valid);
@@ -1051,9 +1116,9 @@ public:
r_error_str = *p_outputs[0];
} else {
if (unary) {
- r_error_str = String(op_names[op]) + RTR(": Invalid argument of type: ") + Variant::get_type_name(p_inputs[0]->get_type());
+ r_error_str = String(Variant::get_operator_name(op)) + ": " + RTR("Invalid argument of type:") + " " + Variant::get_type_name(p_inputs[0]->get_type());
} else {
- r_error_str = String(op_names[op]) + RTR(": Invalid arguments: ") + "A: " + Variant::get_type_name(p_inputs[0]->get_type()) + " B: " + Variant::get_type_name(p_inputs[1]->get_type());
+ r_error_str = String(Variant::get_operator_name(op)) + ": " + RTR("Invalid arguments:") + " A: " + Variant::get_type_name(p_inputs[0]->get_type()) + ", B: " + Variant::get_type_name(p_inputs[1]->get_type());
}
}
}
@@ -1062,7 +1127,7 @@ public:
}
};
-VisualScriptNodeInstance *VisualScriptOperator::instance(VisualScriptInstance *p_instance) {
+VisualScriptNodeInstance *VisualScriptOperator::instantiate(VisualScriptInstance *p_instance) {
VisualScriptNodeInstanceOperator *instance = memnew(VisualScriptNodeInstanceOperator);
instance->unary = get_input_value_port_count() == 1;
instance->op = op;
@@ -1077,7 +1142,7 @@ VisualScriptOperator::VisualScriptOperator() {
template <Variant::Operator OP>
static Ref<VisualScriptNode> create_op_node(const String &p_name) {
Ref<VisualScriptOperator> node;
- node.instance();
+ node.instantiate();
node->set_operator(OP);
return node;
}
@@ -1121,11 +1186,11 @@ PropertyInfo VisualScriptSelect::get_output_value_port_info(int p_idx) const {
}
String VisualScriptSelect::get_caption() const {
- return "Select";
+ return RTR("Select");
}
String VisualScriptSelect::get_text() const {
- return "a if cond, else b";
+ return RTR("a if cond, else b");
}
void VisualScriptSelect::set_typed(Variant::Type p_op) {
@@ -1155,9 +1220,9 @@ void VisualScriptSelect::_bind_methods() {
class VisualScriptNodeInstanceSelect : public VisualScriptNodeInstance {
public:
- //virtual int get_working_memory_size() const { return 0; }
+ //virtual int get_working_memory_size() const override { return 0; }
- virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) {
+ virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
bool cond = *p_inputs[0];
if (cond) {
*p_outputs[0] = *p_inputs[1];
@@ -1169,7 +1234,7 @@ public:
}
};
-VisualScriptNodeInstance *VisualScriptSelect::instance(VisualScriptInstance *p_instance) {
+VisualScriptNodeInstance *VisualScriptSelect::instantiate(VisualScriptInstance *p_instance) {
VisualScriptNodeInstanceSelect *instance = memnew(VisualScriptNodeInstanceSelect);
return instance;
}
@@ -1219,7 +1284,7 @@ PropertyInfo VisualScriptVariableGet::get_output_value_port_info(int p_idx) cons
}
String VisualScriptVariableGet::get_caption() const {
- return "Get " + variable;
+ return vformat(RTR("Get %s"), variable);
}
void VisualScriptVariableGet::set_variable(StringName p_variable) {
@@ -1241,12 +1306,12 @@ void VisualScriptVariableGet::_validate_property(PropertyInfo &property) const {
vs->get_variable_list(&vars);
String vhint;
- for (List<StringName>::Element *E = vars.front(); E; E = E->next()) {
- if (vhint != String()) {
+ for (const StringName &E : vars) {
+ if (!vhint.is_empty()) {
vhint += ",";
}
- vhint += E->get().operator String();
+ vhint += E.operator String();
}
property.hint = PROPERTY_HINT_ENUM;
@@ -1263,21 +1328,21 @@ void VisualScriptVariableGet::_bind_methods() {
class VisualScriptNodeInstanceVariableGet : public VisualScriptNodeInstance {
public:
- VisualScriptVariableGet *node;
- VisualScriptInstance *instance;
+ VisualScriptVariableGet *node = nullptr;
+ VisualScriptInstance *instance = nullptr;
StringName variable;
- virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) {
+ virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
if (!instance->get_variable(variable, p_outputs[0])) {
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
- r_error_str = RTR("VariableGet not found in script: ") + "'" + String(variable) + "'";
+ r_error_str = RTR("VariableGet not found in script:") + " '" + String(variable) + "'";
return 0;
}
return 0;
}
};
-VisualScriptNodeInstance *VisualScriptVariableGet::instance(VisualScriptInstance *p_instance) {
+VisualScriptNodeInstance *VisualScriptVariableGet::instantiate(VisualScriptInstance *p_instance) {
VisualScriptNodeInstanceVariableGet *instance = memnew(VisualScriptNodeInstanceVariableGet);
instance->node = this;
instance->instance = p_instance;
@@ -1329,7 +1394,7 @@ PropertyInfo VisualScriptVariableSet::get_output_value_port_info(int p_idx) cons
}
String VisualScriptVariableSet::get_caption() const {
- return "Set " + variable;
+ return vformat(RTR("Set %s"), variable);
}
void VisualScriptVariableSet::set_variable(StringName p_variable) {
@@ -1351,12 +1416,12 @@ void VisualScriptVariableSet::_validate_property(PropertyInfo &property) const {
vs->get_variable_list(&vars);
String vhint;
- for (List<StringName>::Element *E = vars.front(); E; E = E->next()) {
- if (vhint != String()) {
+ for (const StringName &E : vars) {
+ if (!vhint.is_empty()) {
vhint += ",";
}
- vhint += E->get().operator String();
+ vhint += E.operator String();
}
property.hint = PROPERTY_HINT_ENUM;
@@ -1373,23 +1438,23 @@ void VisualScriptVariableSet::_bind_methods() {
class VisualScriptNodeInstanceVariableSet : public VisualScriptNodeInstance {
public:
- VisualScriptVariableSet *node;
- VisualScriptInstance *instance;
+ VisualScriptVariableSet *node = nullptr;
+ VisualScriptInstance *instance = nullptr;
StringName variable;
- //virtual int get_working_memory_size() const { return 0; }
+ //virtual int get_working_memory_size() const override { return 0; }
- virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) {
+ virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
if (!instance->set_variable(variable, *p_inputs[0])) {
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
- r_error_str = RTR("VariableSet not found in script: ") + "'" + String(variable) + "'";
+ r_error_str = RTR("VariableSet not found in script:") + " '" + String(variable) + "'";
}
return 0;
}
};
-VisualScriptNodeInstance *VisualScriptVariableSet::instance(VisualScriptInstance *p_instance) {
+VisualScriptNodeInstance *VisualScriptVariableSet::instantiate(VisualScriptInstance *p_instance) {
VisualScriptNodeInstanceVariableSet *instance = memnew(VisualScriptNodeInstanceVariableSet);
instance->node = this;
instance->instance = p_instance;
@@ -1436,7 +1501,7 @@ PropertyInfo VisualScriptConstant::get_output_value_port_info(int p_idx) const {
}
String VisualScriptConstant::get_caption() const {
- return "Constant";
+ return RTR("Constant");
}
void VisualScriptConstant::set_constant_type(Variant::Type p_type) {
@@ -1472,7 +1537,7 @@ void VisualScriptConstant::_validate_property(PropertyInfo &property) const {
if (property.name == "value") {
property.type = type;
if (type == Variant::NIL) {
- property.usage = 0; //do not save if nil
+ property.usage = PROPERTY_USAGE_NONE; //do not save if nil
}
}
}
@@ -1496,15 +1561,15 @@ void VisualScriptConstant::_bind_methods() {
class VisualScriptNodeInstanceConstant : public VisualScriptNodeInstance {
public:
Variant constant;
- //virtual int get_working_memory_size() const { return 0; }
+ //virtual int get_working_memory_size() const override { return 0; }
- virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) {
+ virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
*p_outputs[0] = constant;
return 0;
}
};
-VisualScriptNodeInstance *VisualScriptConstant::instance(VisualScriptInstance *p_instance) {
+VisualScriptNodeInstance *VisualScriptConstant::instantiate(VisualScriptInstance *p_instance) {
VisualScriptNodeInstanceConstant *instance = memnew(VisualScriptNodeInstanceConstant);
instance->constant = value;
return instance;
@@ -1550,7 +1615,7 @@ PropertyInfo VisualScriptPreload::get_output_value_port_info(int p_idx) const {
pinfo.hint_string = preload->get_class();
if (preload->get_path().is_resource_file()) {
pinfo.name = preload->get_path();
- } else if (preload->get_name() != String()) {
+ } else if (!preload->get_name().is_empty()) {
pinfo.name = preload->get_name();
} else {
pinfo.name = preload->get_class();
@@ -1563,7 +1628,7 @@ PropertyInfo VisualScriptPreload::get_output_value_port_info(int p_idx) const {
}
String VisualScriptPreload::get_caption() const {
- return "Preload";
+ return RTR("Preload");
}
void VisualScriptPreload::set_preload(const Ref<Resource> &p_preload) {
@@ -1589,15 +1654,15 @@ void VisualScriptPreload::_bind_methods() {
class VisualScriptNodeInstancePreload : public VisualScriptNodeInstance {
public:
Ref<Resource> preload;
- //virtual int get_working_memory_size() const { return 0; }
+ //virtual int get_working_memory_size() const override { return 0; }
- virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) {
+ virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
*p_outputs[0] = preload;
return 0;
}
};
-VisualScriptNodeInstance *VisualScriptPreload::instance(VisualScriptInstance *p_instance) {
+VisualScriptNodeInstance *VisualScriptPreload::instantiate(VisualScriptInstance *p_instance) {
VisualScriptNodeInstancePreload *instance = memnew(VisualScriptNodeInstancePreload);
instance->preload = preload;
return instance;
@@ -1643,14 +1708,14 @@ PropertyInfo VisualScriptIndexGet::get_output_value_port_info(int p_idx) const {
}
String VisualScriptIndexGet::get_caption() const {
- return "Get Index";
+ return RTR("Get Index");
}
class VisualScriptNodeInstanceIndexGet : public VisualScriptNodeInstance {
public:
- //virtual int get_working_memory_size() const { return 0; }
+ //virtual int get_working_memory_size() const override { return 0; }
- virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) {
+ virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
bool valid;
*p_outputs[0] = p_inputs[0]->get(*p_inputs[1], &valid);
@@ -1662,7 +1727,7 @@ public:
}
};
-VisualScriptNodeInstance *VisualScriptIndexGet::instance(VisualScriptInstance *p_instance) {
+VisualScriptNodeInstance *VisualScriptIndexGet::instantiate(VisualScriptInstance *p_instance) {
VisualScriptNodeInstanceIndexGet *instance = memnew(VisualScriptNodeInstanceIndexGet);
return instance;
}
@@ -1710,19 +1775,16 @@ PropertyInfo VisualScriptIndexSet::get_output_value_port_info(int p_idx) const {
}
String VisualScriptIndexSet::get_caption() const {
- return "Set Index";
+ return RTR("Set Index");
}
class VisualScriptNodeInstanceIndexSet : public VisualScriptNodeInstance {
public:
- //virtual int get_working_memory_size() const { return 0; }
+ //virtual int get_working_memory_size() const override { return 0; }
- virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) {
+ virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
bool valid;
- // *p_output[0] points to the same place as *p_inputs[2] so we need a temp to store the value before the change in the next line
- Variant temp = *p_inputs[2];
- *p_outputs[0] = *p_inputs[0];
- p_outputs[0]->set(*p_inputs[1], temp, &valid);
+ ((Variant *)p_inputs[0])->set(*p_inputs[1], *p_inputs[2], &valid);
if (!valid) {
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
@@ -1732,7 +1794,7 @@ public:
}
};
-VisualScriptNodeInstance *VisualScriptIndexSet::instance(VisualScriptInstance *p_instance) {
+VisualScriptNodeInstance *VisualScriptIndexSet::instantiate(VisualScriptInstance *p_instance) {
VisualScriptNodeInstanceIndexSet *instance = memnew(VisualScriptNodeInstanceIndexSet);
return instance;
}
@@ -1774,7 +1836,7 @@ PropertyInfo VisualScriptGlobalConstant::get_output_value_port_info(int p_idx) c
}
String VisualScriptGlobalConstant::get_caption() const {
- return "Global Constant";
+ return RTR("Global Constant");
}
void VisualScriptGlobalConstant::set_global_constant(int p_which) {
@@ -1789,16 +1851,15 @@ int VisualScriptGlobalConstant::get_global_constant() {
class VisualScriptNodeInstanceGlobalConstant : public VisualScriptNodeInstance {
public:
- int index;
- //virtual int get_working_memory_size() const { return 0; }
+ int index = 0;
- virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) {
+ virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
*p_outputs[0] = CoreConstants::get_global_constant_value(index);
return 0;
}
};
-VisualScriptNodeInstance *VisualScriptGlobalConstant::instance(VisualScriptInstance *p_instance) {
+VisualScriptNodeInstance *VisualScriptGlobalConstant::instantiate(VisualScriptInstance *p_instance) {
VisualScriptNodeInstanceGlobalConstant *instance = memnew(VisualScriptNodeInstanceGlobalConstant);
instance->index = index;
return instance;
@@ -1860,7 +1921,7 @@ PropertyInfo VisualScriptClassConstant::get_output_value_port_info(int p_idx) co
}
String VisualScriptClassConstant::get_caption() const {
- return "Class Constant";
+ return RTR("Class Constant");
}
void VisualScriptClassConstant::set_class_constant(const StringName &p_which) {
@@ -1879,8 +1940,8 @@ void VisualScriptClassConstant::set_base_type(const StringName &p_which) {
ClassDB::get_integer_constant_list(base_type, &constants, true);
if (constants.size() > 0) {
bool found_name = false;
- for (List<String>::Element *E = constants.front(); E; E = E->next()) {
- if (E->get() == name) {
+ for (const String &E : constants) {
+ if (E == name) {
found_name = true;
break;
}
@@ -1901,11 +1962,10 @@ StringName VisualScriptClassConstant::get_base_type() {
class VisualScriptNodeInstanceClassConstant : public VisualScriptNodeInstance {
public:
- int value;
- bool valid;
- //virtual int get_working_memory_size() const { return 0; }
+ int value = 0;
+ bool valid = false;
- virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) {
+ virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
if (!valid) {
r_error_str = "Invalid constant name, pick a valid class constant.";
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
@@ -1916,7 +1976,7 @@ public:
}
};
-VisualScriptNodeInstance *VisualScriptClassConstant::instance(VisualScriptInstance *p_instance) {
+VisualScriptNodeInstance *VisualScriptClassConstant::instantiate(VisualScriptInstance *p_instance) {
VisualScriptNodeInstanceClassConstant *instance = memnew(VisualScriptNodeInstanceClassConstant);
instance->value = ClassDB::get_integer_constant(base_type, name, &instance->valid);
return instance;
@@ -1928,11 +1988,11 @@ void VisualScriptClassConstant::_validate_property(PropertyInfo &property) const
ClassDB::get_integer_constant_list(base_type, &constants, true);
property.hint_string = "";
- for (List<String>::Element *E = constants.front(); E; E = E->next()) {
- if (property.hint_string != String()) {
+ for (const String &E : constants) {
+ if (!property.hint_string.is_empty()) {
property.hint_string += ",";
}
- property.hint_string += E->get();
+ property.hint_string += E;
}
}
}
@@ -1985,7 +2045,7 @@ PropertyInfo VisualScriptBasicTypeConstant::get_output_value_port_info(int p_idx
}
String VisualScriptBasicTypeConstant::get_caption() const {
- return "Basic Constant";
+ return RTR("Basic Constant");
}
String VisualScriptBasicTypeConstant::get_text() const {
@@ -2013,8 +2073,8 @@ void VisualScriptBasicTypeConstant::set_basic_type(Variant::Type p_which) {
Variant::get_constants_for_type(type, &constants);
if (constants.size() > 0) {
bool found_name = false;
- for (List<StringName>::Element *E = constants.front(); E; E = E->next()) {
- if (E->get() == name) {
+ for (const StringName &E : constants) {
+ if (E == name) {
found_name = true;
break;
}
@@ -2036,10 +2096,9 @@ Variant::Type VisualScriptBasicTypeConstant::get_basic_type() const {
class VisualScriptNodeInstanceBasicTypeConstant : public VisualScriptNodeInstance {
public:
Variant value;
- bool valid;
- //virtual int get_working_memory_size() const { return 0; }
+ bool valid = false;
- virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) {
+ virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
if (!valid) {
r_error_str = "Invalid constant name, pick a valid basic type constant.";
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
@@ -2050,7 +2109,7 @@ public:
}
};
-VisualScriptNodeInstance *VisualScriptBasicTypeConstant::instance(VisualScriptInstance *p_instance) {
+VisualScriptNodeInstance *VisualScriptBasicTypeConstant::instantiate(VisualScriptInstance *p_instance) {
VisualScriptNodeInstanceBasicTypeConstant *instance = memnew(VisualScriptNodeInstanceBasicTypeConstant);
instance->value = Variant::get_constant_value(type, name, &instance->valid);
return instance;
@@ -2062,15 +2121,15 @@ void VisualScriptBasicTypeConstant::_validate_property(PropertyInfo &property) c
Variant::get_constants_for_type(type, &constants);
if (constants.size() == 0) {
- property.usage = 0;
+ property.usage = PROPERTY_USAGE_NONE;
return;
}
property.hint_string = "";
- for (List<StringName>::Element *E = constants.front(); E; E = E->next()) {
- if (property.hint_string != String()) {
+ for (const StringName &E : constants) {
+ if (!property.hint_string.is_empty()) {
property.hint_string += ",";
}
- property.hint_string += String(E->get());
+ property.hint_string += String(E);
}
}
}
@@ -2117,8 +2176,8 @@ double VisualScriptMathConstant::const_value[MATH_CONSTANT_MAX] = {
Math_TAU,
2.71828182845904523536,
Math::sqrt(2.0),
- Math_INF,
- Math_NAN
+ INFINITY,
+ NAN
};
int VisualScriptMathConstant::get_output_sequence_port_count() const {
@@ -2150,7 +2209,7 @@ PropertyInfo VisualScriptMathConstant::get_output_value_port_info(int p_idx) con
}
String VisualScriptMathConstant::get_caption() const {
- return "Math Constant";
+ return RTR("Math Constant");
}
void VisualScriptMathConstant::set_math_constant(MathConstant p_which) {
@@ -2165,16 +2224,15 @@ VisualScriptMathConstant::MathConstant VisualScriptMathConstant::get_math_consta
class VisualScriptNodeInstanceMathConstant : public VisualScriptNodeInstance {
public:
- float value;
- //virtual int get_working_memory_size() const { return 0; }
+ float value = 0.0f;
- virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) {
+ virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
*p_outputs[0] = value;
return 0;
}
};
-VisualScriptNodeInstance *VisualScriptMathConstant::instance(VisualScriptInstance *p_instance) {
+VisualScriptNodeInstance *VisualScriptMathConstant::instantiate(VisualScriptInstance *p_instance) {
VisualScriptNodeInstanceMathConstant *instance = memnew(VisualScriptNodeInstanceMathConstant);
instance->value = const_value[constant];
return instance;
@@ -2242,7 +2300,7 @@ PropertyInfo VisualScriptEngineSingleton::get_output_value_port_info(int p_idx)
}
String VisualScriptEngineSingleton::get_caption() const {
- return "Get Engine Singleton";
+ return RTR("Get Engine Singleton");
}
void VisualScriptEngineSingleton::set_singleton(const String &p_string) {
@@ -2258,17 +2316,17 @@ String VisualScriptEngineSingleton::get_singleton() {
class VisualScriptNodeInstanceEngineSingleton : public VisualScriptNodeInstance {
public:
- Object *singleton;
+ Object *singleton = nullptr;
- //virtual int get_working_memory_size() const { return 0; }
+ //virtual int get_working_memory_size() const override { return 0; }
- virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) {
+ virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
*p_outputs[0] = singleton;
return 0;
}
};
-VisualScriptNodeInstance *VisualScriptEngineSingleton::instance(VisualScriptInstance *p_instance) {
+VisualScriptNodeInstance *VisualScriptEngineSingleton::instantiate(VisualScriptInstance *p_instance) {
VisualScriptNodeInstanceEngineSingleton *instance = memnew(VisualScriptNodeInstanceEngineSingleton);
instance->singleton = Engine::get_singleton()->get_singleton_object(singleton);
return instance;
@@ -2293,15 +2351,15 @@ void VisualScriptEngineSingleton::_validate_property(PropertyInfo &property) con
Engine::get_singleton()->get_singletons(&singletons);
- for (List<Engine::Singleton>::Element *E = singletons.front(); E; E = E->next()) {
- if (E->get().name == "VS" || E->get().name == "PS" || E->get().name == "PS2D" || E->get().name == "AS" || E->get().name == "TS" || E->get().name == "SS" || E->get().name == "SS2D") {
+ for (const Engine::Singleton &E : singletons) {
+ if (E.name == "VS" || E.name == "PS" || E.name == "PS2D" || E.name == "AS" || E.name == "TS" || E.name == "SS" || E.name == "SS2D") {
continue; //skip these, too simple named
}
- if (cc != String()) {
+ if (!cc.is_empty()) {
cc += ",";
}
- cc += E->get().name;
+ cc += E.name;
}
property.hint = PROPERTY_HINT_ENUM;
@@ -2352,7 +2410,7 @@ PropertyInfo VisualScriptSceneNode::get_output_value_port_info(int p_idx) const
}
String VisualScriptSceneNode::get_caption() const {
- return "Get Scene Node";
+ return RTR("Get Scene Node");
}
void VisualScriptSceneNode::set_node_path(const NodePath &p_path) {
@@ -2367,13 +2425,13 @@ NodePath VisualScriptSceneNode::get_node_path() {
class VisualScriptNodeInstanceSceneNode : public VisualScriptNodeInstance {
public:
- VisualScriptSceneNode *node;
- VisualScriptInstance *instance;
+ VisualScriptSceneNode *node = nullptr;
+ VisualScriptInstance *instance = nullptr;
NodePath path;
- //virtual int get_working_memory_size() const { return 0; }
+ //virtual int get_working_memory_size() const override { return 0; }
- virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) {
+ virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
Node *node = Object::cast_to<Node>(instance->get_owner_ptr());
if (!node) {
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
@@ -2394,7 +2452,7 @@ public:
}
};
-VisualScriptNodeInstance *VisualScriptSceneNode::instance(VisualScriptInstance *p_instance) {
+VisualScriptNodeInstance *VisualScriptSceneNode::instantiate(VisualScriptInstance *p_instance) {
VisualScriptNodeInstanceSceneNode *instance = memnew(VisualScriptNodeInstanceSceneNode);
instance->node = this;
instance->instance = p_instance;
@@ -2430,7 +2488,7 @@ static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const
VisualScriptSceneNode::TypeGuess VisualScriptSceneNode::guess_output_type(TypeGuess *p_inputs, int p_output) const {
VisualScriptSceneNode::TypeGuess tg;
tg.type = Variant::OBJECT;
- tg.gdclass = "Node";
+ tg.gdclass = SNAME("Node");
#ifdef TOOLS_ENABLED
Ref<Script> script = get_visual_script();
@@ -2543,17 +2601,17 @@ PropertyInfo VisualScriptSceneTree::get_output_value_port_info(int p_idx) const
}
String VisualScriptSceneTree::get_caption() const {
- return "Get Scene Tree";
+ return RTR("Get Scene Tree");
}
class VisualScriptNodeInstanceSceneTree : public VisualScriptNodeInstance {
public:
- VisualScriptSceneTree *node;
- VisualScriptInstance *instance;
+ VisualScriptSceneTree *node = nullptr;
+ VisualScriptInstance *instance = nullptr;
- //virtual int get_working_memory_size() const { return 0; }
+ //virtual int get_working_memory_size() const override { return 0; }
- virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) {
+ virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
Node *node = Object::cast_to<Node>(instance->get_owner_ptr());
if (!node) {
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
@@ -2574,7 +2632,7 @@ public:
}
};
-VisualScriptNodeInstance *VisualScriptSceneTree::instance(VisualScriptInstance *p_instance) {
+VisualScriptNodeInstance *VisualScriptSceneTree::instantiate(VisualScriptInstance *p_instance) {
VisualScriptNodeInstanceSceneTree *instance = memnew(VisualScriptNodeInstanceSceneTree);
instance->node = this;
instance->instance = p_instance;
@@ -2584,7 +2642,7 @@ VisualScriptNodeInstance *VisualScriptSceneTree::instance(VisualScriptInstance *
VisualScriptSceneTree::TypeGuess VisualScriptSceneTree::guess_output_type(TypeGuess *p_inputs, int p_output) const {
TypeGuess tg;
tg.type = Variant::OBJECT;
- tg.gdclass = "SceneTree";
+ tg.gdclass = SNAME("SceneTree");
return tg;
}
@@ -2630,7 +2688,7 @@ PropertyInfo VisualScriptResourcePath::get_output_value_port_info(int p_idx) con
}
String VisualScriptResourcePath::get_caption() const {
- return "Resource Path";
+ return RTR("Resource Path");
}
void VisualScriptResourcePath::set_resource_path(const String &p_path) {
@@ -2647,15 +2705,15 @@ class VisualScriptNodeInstanceResourcePath : public VisualScriptNodeInstance {
public:
String path;
- //virtual int get_working_memory_size() const { return 0; }
+ //virtual int get_working_memory_size() const override { return 0; }
- virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) {
+ virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
*p_outputs[0] = path;
return 0;
}
};
-VisualScriptNodeInstance *VisualScriptResourcePath::instance(VisualScriptInstance *p_instance) {
+VisualScriptNodeInstance *VisualScriptResourcePath::instantiate(VisualScriptInstance *p_instance) {
VisualScriptNodeInstanceResourcePath *instance = memnew(VisualScriptNodeInstanceResourcePath);
instance->path = path;
return instance;
@@ -2701,33 +2759,33 @@ PropertyInfo VisualScriptSelf::get_input_value_port_info(int p_idx) const {
}
PropertyInfo VisualScriptSelf::get_output_value_port_info(int p_idx) const {
- String type_name;
+ StringName type_name;
if (get_visual_script().is_valid()) {
type_name = get_visual_script()->get_instance_base_type();
} else {
- type_name = "instance";
+ type_name = SNAME("instance");
}
return PropertyInfo(Variant::OBJECT, type_name);
}
String VisualScriptSelf::get_caption() const {
- return "Get Self";
+ return RTR("Get Self");
}
class VisualScriptNodeInstanceSelf : public VisualScriptNodeInstance {
public:
- VisualScriptInstance *instance;
+ VisualScriptInstance *instance = nullptr;
- //virtual int get_working_memory_size() const { return 0; }
+ //virtual int get_working_memory_size() const override { return 0; }
- virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) {
+ virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
*p_outputs[0] = instance->get_owner_ptr();
return 0;
}
};
-VisualScriptNodeInstance *VisualScriptSelf::instance(VisualScriptInstance *p_instance) {
+VisualScriptNodeInstance *VisualScriptSelf::instantiate(VisualScriptInstance *p_instance) {
VisualScriptNodeInstanceSelf *instance = memnew(VisualScriptNodeInstanceSelf);
instance->instance = p_instance;
return instance;
@@ -2736,7 +2794,7 @@ VisualScriptNodeInstance *VisualScriptSelf::instance(VisualScriptInstance *p_ins
VisualScriptSelf::TypeGuess VisualScriptSelf::guess_output_type(TypeGuess *p_inputs, int p_output) const {
VisualScriptSceneNode::TypeGuess tg;
tg.type = Variant::OBJECT;
- tg.gdclass = "Object";
+ tg.gdclass = SNAME("Object");
Ref<Script> script = get_visual_script();
if (!script.is_valid()) {
@@ -2760,36 +2818,41 @@ VisualScriptSelf::VisualScriptSelf() {
//////////////////////////////////////////
int VisualScriptCustomNode::get_output_sequence_port_count() const {
- if (get_script_instance() && get_script_instance()->has_method("_get_output_sequence_port_count")) {
- return get_script_instance()->call("_get_output_sequence_port_count");
+ int ret;
+ if (GDVIRTUAL_CALL(_get_output_sequence_port_count, ret)) {
+ return ret;
}
return 0;
}
bool VisualScriptCustomNode::has_input_sequence_port() const {
- if (get_script_instance() && get_script_instance()->has_method("_has_input_sequence_port")) {
- return get_script_instance()->call("_has_input_sequence_port");
+ bool ret;
+ if (GDVIRTUAL_CALL(_has_input_sequence_port, ret)) {
+ return ret;
}
return false;
}
int VisualScriptCustomNode::get_input_value_port_count() const {
- if (get_script_instance() && get_script_instance()->has_method("_get_input_value_port_count")) {
- return get_script_instance()->call("_get_input_value_port_count");
+ int ret;
+ if (GDVIRTUAL_CALL(_get_input_value_port_count, ret)) {
+ return ret;
}
return 0;
}
int VisualScriptCustomNode::get_output_value_port_count() const {
- if (get_script_instance() && get_script_instance()->has_method("_get_output_value_port_count")) {
- return get_script_instance()->call("_get_output_value_port_count");
+ int ret;
+ if (GDVIRTUAL_CALL(_get_output_value_port_count, ret)) {
+ return ret;
}
return 0;
}
String VisualScriptCustomNode::get_output_sequence_port_text(int p_port) const {
- if (get_script_instance() && get_script_instance()->has_method("_get_output_sequence_port_text")) {
- return get_script_instance()->call("_get_output_sequence_port_text", p_port);
+ String ret;
+ if (GDVIRTUAL_CALL(_get_output_sequence_port_text, p_port, ret)) {
+ return ret;
}
return String();
@@ -2797,65 +2860,116 @@ String VisualScriptCustomNode::get_output_sequence_port_text(int p_port) const {
PropertyInfo VisualScriptCustomNode::get_input_value_port_info(int p_idx) const {
PropertyInfo info;
- if (get_script_instance() && get_script_instance()->has_method("_get_input_value_port_type")) {
- info.type = Variant::Type(int(get_script_instance()->call("_get_input_value_port_type", p_idx)));
+ {
+ int type;
+ if (GDVIRTUAL_CALL(_get_input_value_port_type, p_idx, type)) {
+ info.type = Variant::Type(type);
+ }
+ }
+ {
+ String name;
+ if (GDVIRTUAL_CALL(_get_input_value_port_name, p_idx, name)) {
+ info.name = name;
+ }
+ }
+ {
+ int hint;
+ if (GDVIRTUAL_CALL(_get_input_value_port_hint, p_idx, hint)) {
+ info.hint = PropertyHint(hint);
+ }
}
- if (get_script_instance() && get_script_instance()->has_method("_get_input_value_port_name")) {
- info.name = get_script_instance()->call("_get_input_value_port_name", p_idx);
+
+ {
+ String hint_string;
+ if (GDVIRTUAL_CALL(_get_input_value_port_hint_string, p_idx, hint_string)) {
+ info.hint_string = hint_string;
+ }
}
+
return info;
}
PropertyInfo VisualScriptCustomNode::get_output_value_port_info(int p_idx) const {
PropertyInfo info;
- if (get_script_instance() && get_script_instance()->has_method("_get_output_value_port_type")) {
- info.type = Variant::Type(int(get_script_instance()->call("_get_output_value_port_type", p_idx)));
+ {
+ int type;
+ if (GDVIRTUAL_CALL(_get_output_value_port_type, p_idx, type)) {
+ info.type = Variant::Type(type);
+ }
}
- if (get_script_instance() && get_script_instance()->has_method("_get_output_value_port_name")) {
- info.name = get_script_instance()->call("_get_output_value_port_name", p_idx);
+ {
+ String name;
+ if (GDVIRTUAL_CALL(_get_output_value_port_name, p_idx, name)) {
+ info.name = name;
+ }
+ }
+ {
+ int hint;
+ if (GDVIRTUAL_CALL(_get_output_value_port_hint, p_idx, hint)) {
+ info.hint = PropertyHint(hint);
+ }
+ }
+
+ {
+ String hint_string;
+ if (GDVIRTUAL_CALL(_get_output_value_port_hint_string, p_idx, hint_string)) {
+ info.hint_string = hint_string;
+ }
}
return info;
}
+VisualScriptCustomNode::TypeGuess VisualScriptCustomNode::guess_output_type(TypeGuess *p_inputs, int p_output) const {
+ TypeGuess tg;
+ PropertyInfo pi = VisualScriptCustomNode::get_output_value_port_info(p_output);
+ tg.type = pi.type;
+ if (pi.type == Variant::OBJECT) {
+ if (pi.hint == PROPERTY_HINT_RESOURCE_TYPE) {
+ if (pi.hint_string.is_resource_file()) {
+ tg.script = ResourceLoader::load(pi.hint_string);
+ } else if (ClassDB::class_exists(pi.hint_string)) {
+ tg.gdclass = pi.hint_string;
+ }
+ }
+ }
+ return tg;
+}
+
String VisualScriptCustomNode::get_caption() const {
- if (get_script_instance() && get_script_instance()->has_method("_get_caption")) {
- return get_script_instance()->call("_get_caption");
+ String ret;
+ if (GDVIRTUAL_CALL(_get_caption, ret)) {
+ return ret;
}
- return "CustomNode";
+ return RTR("CustomNode");
}
String VisualScriptCustomNode::get_text() const {
- if (get_script_instance() && get_script_instance()->has_method("_get_text")) {
- return get_script_instance()->call("_get_text");
+ String ret;
+ if (GDVIRTUAL_CALL(_get_text, ret)) {
+ return ret;
}
return "";
}
String VisualScriptCustomNode::get_category() const {
- if (get_script_instance() && get_script_instance()->has_method("_get_category")) {
- return get_script_instance()->call("_get_category");
+ String ret;
+ if (GDVIRTUAL_CALL(_get_category, ret)) {
+ return ret;
}
return "Custom";
}
class VisualScriptNodeInstanceCustomNode : public VisualScriptNodeInstance {
public:
- VisualScriptInstance *instance;
- VisualScriptCustomNode *node;
- int in_count;
- int out_count;
- int work_mem_size;
-
- virtual int get_working_memory_size() const { return work_mem_size; }
- virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) {
- if (node->get_script_instance()) {
-#ifdef DEBUG_ENABLED
- if (!node->get_script_instance()->has_method(VisualScriptLanguage::singleton->_step)) {
- r_error_str = RTR("Custom node has no _step() method, can't process graph.");
- r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
- return 0;
- }
-#endif
+ VisualScriptInstance *instance = nullptr;
+ VisualScriptCustomNode *node = nullptr;
+ int in_count = 0;
+ int out_count = 0;
+ int work_mem_size = 0;
+
+ virtual int get_working_memory_size() const override { return work_mem_size; }
+ virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
+ if (GDVIRTUAL_IS_OVERRIDDEN_PTR(node, _step)) {
Array in_values;
Array out_values;
Array work_mem;
@@ -2876,7 +2990,8 @@ public:
int ret_out;
- Variant ret = node->get_script_instance()->call(VisualScriptLanguage::singleton->_step, in_values, out_values, p_start_mode, work_mem);
+ Variant ret;
+ GDVIRTUAL_CALL_PTR(node, _step, in_values, out_values, p_start_mode, work_mem, ret);
if (ret.get_type() == Variant::STRING) {
r_error_str = ret;
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
@@ -2902,55 +3017,56 @@ public:
}
return ret_out;
+ } else {
+ r_error_str = RTR("Custom node has no _step() method, can't process graph.");
+ r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
}
return 0;
}
};
-VisualScriptNodeInstance *VisualScriptCustomNode::instance(VisualScriptInstance *p_instance) {
+VisualScriptNodeInstance *VisualScriptCustomNode::instantiate(VisualScriptInstance *p_instance) {
VisualScriptNodeInstanceCustomNode *instance = memnew(VisualScriptNodeInstanceCustomNode);
instance->instance = p_instance;
instance->node = this;
instance->in_count = get_input_value_port_count();
instance->out_count = get_output_value_port_count();
- if (get_script_instance() && get_script_instance()->has_method("_get_working_memory_size")) {
- instance->work_mem_size = get_script_instance()->call("_get_working_memory_size");
- } else {
- instance->work_mem_size = 0;
- }
+ instance->work_mem_size = 0;
+ GDVIRTUAL_CALL(_get_working_memory_size, instance->work_mem_size);
return instance;
}
void VisualScriptCustomNode::_script_changed() {
- call_deferred("ports_changed_notify");
+ call_deferred(SNAME("ports_changed_notify"));
}
void VisualScriptCustomNode::_bind_methods() {
- BIND_VMETHOD(MethodInfo(Variant::INT, "_get_output_sequence_port_count"));
- BIND_VMETHOD(MethodInfo(Variant::BOOL, "_has_input_sequence_port"));
+ GDVIRTUAL_BIND(_get_output_sequence_port_count);
+ GDVIRTUAL_BIND(_has_input_sequence_port);
+ GDVIRTUAL_BIND(_get_output_sequence_port_text, "seq_idx");
- BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_output_sequence_port_text", PropertyInfo(Variant::INT, "idx")));
- BIND_VMETHOD(MethodInfo(Variant::INT, "_get_input_value_port_count"));
- BIND_VMETHOD(MethodInfo(Variant::INT, "_get_output_value_port_count"));
+ GDVIRTUAL_BIND(_get_input_value_port_count);
+ GDVIRTUAL_BIND(_get_input_value_port_type, "input_idx");
+ GDVIRTUAL_BIND(_get_input_value_port_name, "input_idx");
+ GDVIRTUAL_BIND(_get_input_value_port_hint, "input_idx");
+ GDVIRTUAL_BIND(_get_input_value_port_hint_string, "input_idx");
- BIND_VMETHOD(MethodInfo(Variant::INT, "_get_input_value_port_type", PropertyInfo(Variant::INT, "idx")));
- BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_input_value_port_name", PropertyInfo(Variant::INT, "idx")));
+ GDVIRTUAL_BIND(_get_output_value_port_count);
+ GDVIRTUAL_BIND(_get_output_value_port_type, "output_idx");
+ GDVIRTUAL_BIND(_get_output_value_port_name, "output_idx");
+ GDVIRTUAL_BIND(_get_output_value_port_hint, "output_idx");
+ GDVIRTUAL_BIND(_get_output_value_port_hint_string, "output_idx");
- BIND_VMETHOD(MethodInfo(Variant::INT, "_get_output_value_port_type", PropertyInfo(Variant::INT, "idx")));
- BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_output_value_port_name", PropertyInfo(Variant::INT, "idx")));
+ GDVIRTUAL_BIND(_get_caption);
+ GDVIRTUAL_BIND(_get_text);
+ GDVIRTUAL_BIND(_get_category);
- BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_caption"));
- BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_text"));
- BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_category"));
+ GDVIRTUAL_BIND(_get_working_memory_size);
- BIND_VMETHOD(MethodInfo(Variant::INT, "_get_working_memory_size"));
-
- MethodInfo stepmi(Variant::NIL, "_step", PropertyInfo(Variant::ARRAY, "inputs"), PropertyInfo(Variant::ARRAY, "outputs"), PropertyInfo(Variant::INT, "start_mode"), PropertyInfo(Variant::ARRAY, "working_mem"));
- stepmi.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT;
- BIND_VMETHOD(stepmi);
+ GDVIRTUAL_BIND(_step, "inputs", "outputs", "start_mode", "working_mem");
BIND_ENUM_CONSTANT(START_MODE_BEGIN_SEQUENCE);
BIND_ENUM_CONSTANT(START_MODE_CONTINUE_SEQUENCE);
@@ -3018,13 +3134,13 @@ PropertyInfo VisualScriptSubCall::get_output_value_port_info(int p_idx) const {
}
String VisualScriptSubCall::get_caption() const {
- return "SubCall";
+ return RTR("SubCall");
}
String VisualScriptSubCall::get_text() const {
Ref<Script> script = get_script();
if (script.is_valid()) {
- if (script->get_name() != String()) {
+ if (!script->get_name().is_empty()) {
return script->get_name();
}
if (script->get_path().is_resource_file()) {
@@ -3041,25 +3157,25 @@ String VisualScriptSubCall::get_category() const {
class VisualScriptNodeInstanceSubCall : public VisualScriptNodeInstance {
public:
- VisualScriptInstance *instance;
- VisualScriptSubCall *subcall;
- int input_args;
- bool valid;
+ VisualScriptInstance *instance = nullptr;
+ VisualScriptSubCall *subcall = nullptr;
+ int input_args = 0;
+ bool valid = false;
- //virtual int get_working_memory_size() const { return 0; }
+ //virtual int get_working_memory_size() const override { return 0; }
- virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) {
+ virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
if (!valid) {
r_error_str = "Node requires a script with a _subcall(<args>) method to work.";
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
return 0;
}
- *p_outputs[0] = subcall->call(VisualScriptLanguage::singleton->_subcall, p_inputs, input_args, r_error);
+ *p_outputs[0] = subcall->callp(VisualScriptLanguage::singleton->_subcall, p_inputs, input_args, r_error);
return 0;
}
};
-VisualScriptNodeInstance *VisualScriptSubCall::instance(VisualScriptInstance *p_instance) {
+VisualScriptNodeInstance *VisualScriptSubCall::instantiate(VisualScriptInstance *p_instance) {
VisualScriptNodeInstanceSubCall *instance = memnew(VisualScriptNodeInstanceSubCall);
instance->instance = p_instance;
Ref<Script> script = get_script();
@@ -3073,9 +3189,7 @@ VisualScriptNodeInstance *VisualScriptSubCall::instance(VisualScriptInstance *p_
}
void VisualScriptSubCall::_bind_methods() {
- MethodInfo scmi(Variant::NIL, "_subcall", PropertyInfo(Variant::NIL, "arguments"));
- scmi.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT;
- BIND_VMETHOD(scmi);
+ // Since this is script only, registering virtual function is no longer valid. Will have to go in docs.
}
VisualScriptSubCall::VisualScriptSubCall() {
@@ -3163,16 +3277,16 @@ String VisualScriptComment::get_category() const {
class VisualScriptNodeInstanceComment : public VisualScriptNodeInstance {
public:
- VisualScriptInstance *instance;
+ VisualScriptInstance *instance = nullptr;
- //virtual int get_working_memory_size() const { return 0; }
+ //virtual int get_working_memory_size() const override { return 0; }
- virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) {
+ virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
return 0;
}
};
-VisualScriptNodeInstance *VisualScriptComment::instance(VisualScriptInstance *p_instance) {
+VisualScriptNodeInstance *VisualScriptComment::instantiate(VisualScriptInstance *p_instance) {
VisualScriptNodeInstanceComment *instance = memnew(VisualScriptNodeInstanceComment);
instance->instance = p_instance;
return instance;
@@ -3231,7 +3345,7 @@ PropertyInfo VisualScriptConstructor::get_output_value_port_info(int p_idx) cons
}
String VisualScriptConstructor::get_caption() const {
- return "Construct " + Variant::get_type_name(type);
+ return vformat(RTR("Construct %s"), Variant::get_type_name(type));
}
String VisualScriptConstructor::get_category() const {
@@ -3262,13 +3376,13 @@ Dictionary VisualScriptConstructor::get_constructor() const {
class VisualScriptNodeInstanceConstructor : public VisualScriptNodeInstance {
public:
- VisualScriptInstance *instance;
+ VisualScriptInstance *instance = nullptr;
Variant::Type type;
- int argcount;
+ int argcount = 0;
- //virtual int get_working_memory_size() const { return 0; }
+ //virtual int get_working_memory_size() const override { return 0; }
- virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) {
+ virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
Callable::CallError ce;
Variant::construct(type, *p_outputs[0], p_inputs, argcount, ce);
if (ce.error != Callable::CallError::CALL_OK) {
@@ -3279,7 +3393,7 @@ public:
}
};
-VisualScriptNodeInstance *VisualScriptConstructor::instance(VisualScriptInstance *p_instance) {
+VisualScriptNodeInstance *VisualScriptConstructor::instantiate(VisualScriptInstance *p_instance) {
VisualScriptNodeInstanceConstructor *instance = memnew(VisualScriptNodeInstanceConstructor);
instance->instance = p_instance;
instance->type = type;
@@ -3294,21 +3408,21 @@ void VisualScriptConstructor::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_constructor", "constructor"), &VisualScriptConstructor::set_constructor);
ClassDB::bind_method(D_METHOD("get_constructor"), &VisualScriptConstructor::get_constructor);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "type", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "set_constructor_type", "get_constructor_type");
- ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "constructor", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "set_constructor", "get_constructor");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "type", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "set_constructor_type", "get_constructor_type");
+ ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "constructor", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "set_constructor", "get_constructor");
}
VisualScriptConstructor::VisualScriptConstructor() {
type = Variant::NIL;
}
-static Map<String, Pair<Variant::Type, MethodInfo>> constructor_map;
+static HashMap<String, Pair<Variant::Type, MethodInfo>> constructor_map;
static Ref<VisualScriptNode> create_constructor_node(const String &p_name) {
ERR_FAIL_COND_V(!constructor_map.has(p_name), Ref<VisualScriptNode>());
Ref<VisualScriptConstructor> vsc;
- vsc.instance();
+ vsc.instantiate();
vsc->set_constructor_type(constructor_map[p_name].first);
vsc->set_constructor(constructor_map[p_name].second);
@@ -3348,7 +3462,7 @@ PropertyInfo VisualScriptLocalVar::get_output_value_port_info(int p_idx) const {
}
String VisualScriptLocalVar::get_caption() const {
- return "Get Local Var";
+ return RTR("Get Local Var");
}
String VisualScriptLocalVar::get_category() const {
@@ -3379,17 +3493,17 @@ Variant::Type VisualScriptLocalVar::get_var_type() const {
class VisualScriptNodeInstanceLocalVar : public VisualScriptNodeInstance {
public:
- VisualScriptInstance *instance;
+ VisualScriptInstance *instance = nullptr;
StringName name;
- virtual int get_working_memory_size() const { return 1; }
- virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) {
+ virtual int get_working_memory_size() const override { return 1; }
+ virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
*p_outputs[0] = *p_working_mem;
return 0;
}
};
-VisualScriptNodeInstance *VisualScriptLocalVar::instance(VisualScriptInstance *p_instance) {
+VisualScriptNodeInstance *VisualScriptLocalVar::instantiate(VisualScriptInstance *p_instance) {
VisualScriptNodeInstanceLocalVar *instance = memnew(VisualScriptNodeInstanceLocalVar);
instance->instance = p_instance;
instance->name = name;
@@ -3451,7 +3565,7 @@ PropertyInfo VisualScriptLocalVarSet::get_output_value_port_info(int p_idx) cons
}
String VisualScriptLocalVarSet::get_caption() const {
- return "Set Local Var";
+ return RTR("Set Local Var");
}
String VisualScriptLocalVarSet::get_text() const {
@@ -3486,18 +3600,18 @@ Variant::Type VisualScriptLocalVarSet::get_var_type() const {
class VisualScriptNodeInstanceLocalVarSet : public VisualScriptNodeInstance {
public:
- VisualScriptInstance *instance;
+ VisualScriptInstance *instance = nullptr;
StringName name;
- virtual int get_working_memory_size() const { return 1; }
- virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) {
+ virtual int get_working_memory_size() const override { return 1; }
+ virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
*p_working_mem = *p_inputs[0];
*p_outputs[0] = *p_working_mem;
return 0;
}
};
-VisualScriptNodeInstance *VisualScriptLocalVarSet::instance(VisualScriptInstance *p_instance) {
+VisualScriptNodeInstance *VisualScriptLocalVarSet::instantiate(VisualScriptInstance *p_instance) {
VisualScriptNodeInstanceLocalVarSet *instance = memnew(VisualScriptNodeInstanceLocalVarSet);
instance->instance = p_instance;
instance->name = name;
@@ -3575,7 +3689,7 @@ PropertyInfo VisualScriptInputAction::get_output_value_port_info(int p_idx) cons
}
String VisualScriptInputAction::get_caption() const {
- return "Action " + name;
+ return vformat(RTR("Action %s"), name);
}
String VisualScriptInputAction::get_category() const {
@@ -3610,11 +3724,11 @@ VisualScriptInputAction::Mode VisualScriptInputAction::get_action_mode() const {
class VisualScriptNodeInstanceInputAction : public VisualScriptNodeInstance {
public:
- VisualScriptInstance *instance;
+ VisualScriptInstance *instance = nullptr;
StringName action;
VisualScriptInputAction::Mode mode;
- virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) {
+ virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
switch (mode) {
case VisualScriptInputAction::MODE_PRESSED: {
*p_outputs[0] = Input::get_singleton()->is_action_pressed(action);
@@ -3634,7 +3748,7 @@ public:
}
};
-VisualScriptNodeInstance *VisualScriptInputAction::instance(VisualScriptInstance *p_instance) {
+VisualScriptNodeInstance *VisualScriptInputAction::instantiate(VisualScriptInstance *p_instance) {
VisualScriptNodeInstanceInputAction *instance = memnew(VisualScriptNodeInstanceInputAction);
instance->instance = p_instance;
instance->action = name;
@@ -3652,9 +3766,7 @@ void VisualScriptInputAction::_validate_property(PropertyInfo &property) const {
ProjectSettings::get_singleton()->get_property_list(&pinfo);
Vector<String> al;
- for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
- const PropertyInfo &pi = E->get();
-
+ for (const PropertyInfo &pi : pinfo) {
if (!pi.name.begins_with("input/")) {
continue;
}
@@ -3667,7 +3779,7 @@ void VisualScriptInputAction::_validate_property(PropertyInfo &property) const {
al.sort();
for (int i = 0; i < al.size(); i++) {
- if (actions != String()) {
+ if (!actions.is_empty()) {
actions += ",";
}
actions += al[i];
@@ -3731,7 +3843,7 @@ PropertyInfo VisualScriptDeconstruct::get_output_value_port_info(int p_idx) cons
}
String VisualScriptDeconstruct::get_caption() const {
- return "Deconstruct " + Variant::get_type_name(type);
+ return vformat(RTR("Deconstruct %s"), Variant::get_type_name(type));
}
String VisualScriptDeconstruct::get_category() const {
@@ -3747,10 +3859,10 @@ void VisualScriptDeconstruct::_update_elements() {
List<PropertyInfo> pinfo;
v.get_property_list(&pinfo);
- for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
+ for (const PropertyInfo &E : pinfo) {
Element e;
- e.name = E->get().name;
- e.type = E->get().type;
+ e.name = E.name;
+ e.type = E.type;
elements.push_back(e);
}
}
@@ -3790,12 +3902,12 @@ Array VisualScriptDeconstruct::_get_elem_cache() const {
class VisualScriptNodeInstanceDeconstruct : public VisualScriptNodeInstance {
public:
- VisualScriptInstance *instance;
+ VisualScriptInstance *instance = nullptr;
Vector<StringName> outputs;
- //virtual int get_working_memory_size() const { return 0; }
+ //virtual int get_working_memory_size() const override { return 0; }
- virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) {
+ virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
Variant in = *p_inputs[0];
for (int i = 0; i < outputs.size(); i++) {
@@ -3812,7 +3924,7 @@ public:
}
};
-VisualScriptNodeInstance *VisualScriptDeconstruct::instance(VisualScriptInstance *p_instance) {
+VisualScriptNodeInstance *VisualScriptDeconstruct::instantiate(VisualScriptInstance *p_instance) {
VisualScriptNodeInstanceDeconstruct *instance = memnew(VisualScriptNodeInstanceDeconstruct);
instance->instance = p_instance;
instance->outputs.resize(elements.size());
@@ -3839,7 +3951,7 @@ void VisualScriptDeconstruct::_bind_methods() {
}
ADD_PROPERTY(PropertyInfo(Variant::INT, "type", PROPERTY_HINT_ENUM, argt), "set_deconstruct_type", "get_deconstruct_type");
- ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "elem_cache", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_elem_cache", "_get_elem_cache");
+ ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "elem_cache", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "_set_elem_cache", "_get_elem_cache");
}
VisualScriptDeconstruct::VisualScriptDeconstruct() {
@@ -3849,7 +3961,7 @@ VisualScriptDeconstruct::VisualScriptDeconstruct() {
template <Variant::Type T>
static Ref<VisualScriptNode> create_node_deconst_typed(const String &p_name) {
Ref<VisualScriptDeconstruct> node;
- node.instance();
+ node.instantiate();
node->set_deconstruct_type(T);
return node;
}
@@ -3918,34 +4030,34 @@ void register_visual_script_nodes() {
VisualScriptLanguage::singleton->add_register_func("functions/deconstruct/" + Variant::get_type_name(Variant::Type::RECT2I), create_node_deconst_typed<Variant::Type::RECT2I>);
VisualScriptLanguage::singleton->add_register_func("functions/deconstruct/" + Variant::get_type_name(Variant::Type::TRANSFORM2D), create_node_deconst_typed<Variant::Type::TRANSFORM2D>);
VisualScriptLanguage::singleton->add_register_func("functions/deconstruct/" + Variant::get_type_name(Variant::Type::PLANE), create_node_deconst_typed<Variant::Type::PLANE>);
- VisualScriptLanguage::singleton->add_register_func("functions/deconstruct/" + Variant::get_type_name(Variant::Type::QUAT), create_node_deconst_typed<Variant::Type::QUAT>);
+ VisualScriptLanguage::singleton->add_register_func("functions/deconstruct/" + Variant::get_type_name(Variant::Type::QUATERNION), create_node_deconst_typed<Variant::Type::QUATERNION>);
VisualScriptLanguage::singleton->add_register_func("functions/deconstruct/" + Variant::get_type_name(Variant::Type::AABB), create_node_deconst_typed<Variant::Type::AABB>);
VisualScriptLanguage::singleton->add_register_func("functions/deconstruct/" + Variant::get_type_name(Variant::Type::BASIS), create_node_deconst_typed<Variant::Type::BASIS>);
- VisualScriptLanguage::singleton->add_register_func("functions/deconstruct/" + Variant::get_type_name(Variant::Type::TRANSFORM), create_node_deconst_typed<Variant::Type::TRANSFORM>);
+ VisualScriptLanguage::singleton->add_register_func("functions/deconstruct/" + Variant::get_type_name(Variant::Type::TRANSFORM3D), create_node_deconst_typed<Variant::Type::TRANSFORM3D>);
VisualScriptLanguage::singleton->add_register_func("functions/compose_array", create_node_generic<VisualScriptComposeArray>);
for (int i = 1; i < Variant::VARIANT_MAX; i++) {
List<MethodInfo> constructors;
Variant::get_constructor_list(Variant::Type(i), &constructors);
- for (List<MethodInfo>::Element *E = constructors.front(); E; E = E->next()) {
- if (E->get().arguments.size() > 0) {
+ for (const MethodInfo &E : constructors) {
+ if (E.arguments.size() > 0) {
String name = "functions/constructors/" + Variant::get_type_name(Variant::Type(i)) + "(";
- for (int j = 0; j < E->get().arguments.size(); j++) {
+ for (int j = 0; j < E.arguments.size(); j++) {
if (j > 0) {
name += ", ";
}
- if (E->get().arguments.size() == 1) {
- name += Variant::get_type_name(E->get().arguments[j].type);
+ if (E.arguments.size() == 1) {
+ name += Variant::get_type_name(E.arguments[j].type);
} else {
- name += E->get().arguments[j].name;
+ name += E.arguments[j].name;
}
}
name += ")";
VisualScriptLanguage::singleton->add_register_func(name, create_constructor_node);
Pair<Variant::Type, MethodInfo> pair;
pair.first = Variant::Type(i);
- pair.second = E->get();
+ pair.second = E;
constructor_map[name] = pair;
}
}
diff --git a/modules/visual_script/visual_script_nodes.h b/modules/visual_script/visual_script_nodes.h
index 7392443e4e..18573f8682 100644
--- a/modules/visual_script/visual_script_nodes.h
+++ b/modules/visual_script/visual_script_nodes.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -31,6 +31,8 @@
#ifndef VISUAL_SCRIPT_NODES_H
#define VISUAL_SCRIPT_NODES_H
+#include "core/object/gdvirtual.gen.inc"
+#include "core/object/script_language.h"
#include "visual_script.h"
class VisualScriptFunction : public VisualScriptNode {
@@ -47,7 +49,7 @@ class VisualScriptFunction : public VisualScriptNode {
bool stack_less;
int stack_size;
- MultiplayerAPI::RPCMode rpc_mode;
+ Multiplayer::RPCMode rpc_mode;
bool sequenced;
protected:
@@ -88,16 +90,10 @@ public:
void set_stack_size(int p_size);
int get_stack_size() const;
- void set_return_type_enabled(bool p_returns);
- bool is_return_type_enabled() const;
+ void set_rpc_mode(Multiplayer::RPCMode p_mode);
+ Multiplayer::RPCMode get_rpc_mode() const;
- void set_return_type(Variant::Type p_type);
- Variant::Type get_return_type() const;
-
- void set_rpc_mode(MultiplayerAPI::RPCMode p_mode);
- MultiplayerAPI::RPCMode get_rpc_mode() const;
-
- virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override;
+ virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override;
virtual void reset_state() override;
@@ -192,7 +188,7 @@ public:
virtual String get_text() const override;
virtual String get_category() const override { return "functions"; }
- virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override;
+ virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override;
VisualScriptComposeArray();
};
@@ -227,7 +223,9 @@ public:
void set_typed(Variant::Type p_op);
Variant::Type get_typed() const;
- virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override;
+ static String get_operator_name(Variant::Operator p_op);
+
+ virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override;
VisualScriptOperator();
};
@@ -259,7 +257,7 @@ public:
void set_typed(Variant::Type p_op);
Variant::Type get_typed() const;
- virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override;
+ virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override;
VisualScriptSelect();
};
@@ -291,7 +289,7 @@ public:
void set_variable(StringName p_variable);
StringName get_variable() const;
- virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override;
+ virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override;
VisualScriptVariableGet();
};
@@ -323,7 +321,7 @@ public:
void set_variable(StringName p_variable);
StringName get_variable() const;
- virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override;
+ virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override;
VisualScriptVariableSet();
};
@@ -359,7 +357,7 @@ public:
void set_constant_value(Variant p_value);
Variant get_constant_value() const;
- virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override;
+ virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override;
VisualScriptConstant();
};
@@ -390,7 +388,7 @@ public:
void set_preload(const Ref<Resource> &p_preload);
Ref<Resource> get_preload() const;
- virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override;
+ virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override;
VisualScriptPreload();
};
@@ -413,7 +411,7 @@ public:
virtual String get_caption() const override;
virtual String get_category() const override { return "operators"; }
- virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override;
+ virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override;
VisualScriptIndexGet();
};
@@ -436,7 +434,7 @@ public:
virtual String get_caption() const override;
virtual String get_category() const override { return "operators"; }
- virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override;
+ virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override;
VisualScriptIndexSet();
};
@@ -466,7 +464,7 @@ public:
void set_global_constant(int p_which);
int get_global_constant();
- virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override;
+ virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override;
VisualScriptGlobalConstant();
};
@@ -502,7 +500,7 @@ public:
void set_base_type(const StringName &p_which);
StringName get_base_type();
- virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override;
+ virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override;
VisualScriptClassConstant();
};
@@ -539,7 +537,7 @@ public:
void set_basic_type(Variant::Type p_which);
Variant::Type get_basic_type() const;
- virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override;
+ virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override;
VisualScriptBasicTypeConstant();
};
@@ -586,7 +584,7 @@ public:
void set_math_constant(MathConstant p_which);
MathConstant get_math_constant();
- virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override;
+ virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override;
VisualScriptMathConstant();
};
@@ -621,7 +619,7 @@ public:
void set_singleton(const String &p_string);
String get_singleton();
- virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override;
+ virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override;
virtual TypeGuess guess_output_type(TypeGuess *p_inputs, int p_output) const override;
@@ -655,7 +653,7 @@ public:
void set_node_path(const NodePath &p_path);
NodePath get_node_path();
- virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override;
+ virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override;
virtual TypeGuess guess_output_type(TypeGuess *p_inputs, int p_output) const override;
@@ -684,7 +682,7 @@ public:
virtual String get_caption() const override;
virtual String get_category() const override { return "data"; }
- virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override;
+ virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override;
virtual TypeGuess guess_output_type(TypeGuess *p_inputs, int p_output) const override;
@@ -717,7 +715,7 @@ public:
void set_resource_path(const String &p_path);
String get_resource_path();
- virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override;
+ virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override;
VisualScriptResourcePath();
};
@@ -743,7 +741,7 @@ public:
virtual String get_caption() const override;
virtual String get_category() const override { return "data"; }
- virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override;
+ virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override;
virtual TypeGuess guess_output_type(TypeGuess *p_inputs, int p_output) const override;
@@ -755,6 +753,30 @@ class VisualScriptCustomNode : public VisualScriptNode {
protected:
static void _bind_methods();
+ friend class VisualScriptNodeInstanceCustomNode;
+ GDVIRTUAL0RC(int, _get_output_sequence_port_count)
+ GDVIRTUAL0RC(bool, _has_input_sequence_port)
+ GDVIRTUAL1RC(String, _get_output_sequence_port_text, int)
+
+ GDVIRTUAL0RC(int, _get_input_value_port_count)
+ GDVIRTUAL1RC(int, _get_input_value_port_type, int)
+ GDVIRTUAL1RC(String, _get_input_value_port_name, int)
+ GDVIRTUAL1RC(int, _get_input_value_port_hint, int)
+ GDVIRTUAL1RC(String, _get_input_value_port_hint_string, int)
+
+ GDVIRTUAL0RC(int, _get_output_value_port_count)
+ GDVIRTUAL1RC(int, _get_output_value_port_type, int)
+ GDVIRTUAL1RC(String, _get_output_value_port_name, int)
+ GDVIRTUAL1RC(int, _get_output_value_port_hint, int)
+ GDVIRTUAL1RC(String, _get_output_value_port_hint_string, int)
+
+ GDVIRTUAL0RC(String, _get_caption)
+ GDVIRTUAL0RC(String, _get_text)
+ GDVIRTUAL0RC(String, _get_category)
+
+ GDVIRTUAL0RC(int, _get_working_memory_size)
+
+ GDVIRTUAL4RC(Variant, _step, Array, Array, int, Array)
public:
enum StartMode { //replicated for step
@@ -788,7 +810,9 @@ public:
virtual String get_text() const override;
virtual String get_category() const override;
- virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override;
+ virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override;
+
+ virtual TypeGuess guess_output_type(TypeGuess *p_inputs, int p_output) const override;
void _script_changed();
@@ -819,7 +843,7 @@ public:
virtual String get_text() const override;
virtual String get_category() const override;
- virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override;
+ virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override;
VisualScriptSubCall();
};
@@ -859,7 +883,7 @@ public:
void set_size(const Size2 &p_size);
Size2 get_size() const;
- virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override;
+ virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override;
VisualScriptComment();
};
@@ -894,7 +918,7 @@ public:
void set_constructor(const Dictionary &p_info);
Dictionary get_constructor() const;
- virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override;
+ virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override;
VisualScriptConstructor();
};
@@ -929,7 +953,7 @@ public:
void set_var_type(Variant::Type p_type);
Variant::Type get_var_type() const;
- virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override;
+ virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override;
VisualScriptLocalVar();
};
@@ -965,7 +989,7 @@ public:
void set_var_type(Variant::Type p_type);
Variant::Type get_var_type() const;
- virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override;
+ virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override;
VisualScriptLocalVarSet();
};
@@ -1010,7 +1034,7 @@ public:
void set_action_mode(Mode p_mode);
Mode get_action_mode() const;
- virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override;
+ virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override;
VisualScriptInputAction();
};
@@ -1056,7 +1080,7 @@ public:
void set_deconstruct_type(Variant::Type p_type);
Variant::Type get_deconstruct_type() const;
- virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override;
+ virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override;
VisualScriptDeconstruct();
};
diff --git a/modules/visual_script/visual_script_property_selector.cpp b/modules/visual_script/visual_script_property_selector.cpp
deleted file mode 100644
index 862cac5c67..0000000000
--- a/modules/visual_script/visual_script_property_selector.cpp
+++ /dev/null
@@ -1,724 +0,0 @@
-/*************************************************************************/
-/* visual_script_property_selector.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 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_property_selector.h"
-
-#include "core/os/keyboard.h"
-#include "editor/doc_tools.h"
-#include "editor/editor_node.h"
-#include "editor/editor_scale.h"
-#include "modules/visual_script/visual_script.h"
-#include "modules/visual_script/visual_script_builtin_funcs.h"
-#include "modules/visual_script/visual_script_flow_control.h"
-#include "modules/visual_script/visual_script_func_nodes.h"
-#include "modules/visual_script/visual_script_nodes.h"
-#include "scene/main/node.h"
-#include "scene/main/window.h"
-
-void VisualScriptPropertySelector::_text_changed(const String &p_newtext) {
- _update_search();
-}
-
-void VisualScriptPropertySelector::_sbox_input(const Ref<InputEvent> &p_ie) {
- Ref<InputEventKey> k = p_ie;
-
- if (k.is_valid()) {
- switch (k->get_keycode()) {
- case KEY_UP:
- case KEY_DOWN:
- case KEY_PAGEUP:
- case KEY_PAGEDOWN: {
- search_options->call("_gui_input", k);
- search_box->accept_event();
-
- TreeItem *root = search_options->get_root();
- if (!root->get_children()) {
- break;
- }
-
- TreeItem *current = search_options->get_selected();
-
- TreeItem *item = search_options->get_next_selected(root);
- while (item) {
- item->deselect(0);
- item = search_options->get_next_selected(item);
- }
-
- current->select(0);
-
- } break;
- }
- }
-}
-
-void VisualScriptPropertySelector::_update_search() {
- set_title(TTR("Search VisualScript"));
-
- search_options->clear();
- help_bit->set_text("");
-
- TreeItem *root = search_options->create_item();
- bool found = false;
- StringName base = base_type;
- List<StringName> base_list;
- while (base) {
- base_list.push_back(base);
- base = ClassDB::get_parent_class_nocheck(base);
- }
-
- for (List<StringName>::Element *E = base_list.front(); E; E = E->next()) {
- List<MethodInfo> methods;
- List<PropertyInfo> props;
- TreeItem *category = nullptr;
- Ref<Texture2D> type_icons[Variant::VARIANT_MAX] = {
- vbc->get_theme_icon("Variant", "EditorIcons"),
- vbc->get_theme_icon("bool", "EditorIcons"),
- vbc->get_theme_icon("int", "EditorIcons"),
- vbc->get_theme_icon("float", "EditorIcons"),
- vbc->get_theme_icon("String", "EditorIcons"),
- vbc->get_theme_icon("Vector2", "EditorIcons"),
- vbc->get_theme_icon("Rect2", "EditorIcons"),
- vbc->get_theme_icon("Vector3", "EditorIcons"),
- vbc->get_theme_icon("Transform2D", "EditorIcons"),
- vbc->get_theme_icon("Plane", "EditorIcons"),
- vbc->get_theme_icon("Quat", "EditorIcons"),
- vbc->get_theme_icon("AABB", "EditorIcons"),
- vbc->get_theme_icon("Basis", "EditorIcons"),
- vbc->get_theme_icon("Transform", "EditorIcons"),
- vbc->get_theme_icon("Color", "EditorIcons"),
- vbc->get_theme_icon("Path", "EditorIcons"),
- vbc->get_theme_icon("RID", "EditorIcons"),
- vbc->get_theme_icon("Object", "EditorIcons"),
- vbc->get_theme_icon("Dictionary", "EditorIcons"),
- vbc->get_theme_icon("Array", "EditorIcons"),
- vbc->get_theme_icon("PackedByteArray", "EditorIcons"),
- vbc->get_theme_icon("PackedInt32Array", "EditorIcons"),
- vbc->get_theme_icon("PackedFloat32Array", "EditorIcons"),
- vbc->get_theme_icon("PackedInt64Array", "EditorIcons"),
- vbc->get_theme_icon("PackedFloat64Array", "EditorIcons"),
- vbc->get_theme_icon("PackedStringArray", "EditorIcons"),
- vbc->get_theme_icon("PackedVector2Array", "EditorIcons"),
- vbc->get_theme_icon("PackedVector3Array", "EditorIcons"),
- vbc->get_theme_icon("PackedColorArray", "EditorIcons")
- };
- {
- String b = String(E->get());
- category = search_options->create_item(root);
- if (category) {
- category->set_text(0, b.replace_first("*", ""));
- category->set_selectable(0, false);
- Ref<Texture2D> icon;
- String rep = b.replace("*", "");
- icon = EditorNode::get_singleton()->get_class_icon(rep);
- category->set_icon(0, icon);
- }
- }
- if (properties || seq_connect) {
- if (instance) {
- instance->get_property_list(&props, true);
- } else {
- Object *obj = ObjectDB::get_instance(script);
- if (Object::cast_to<Script>(obj)) {
- Object::cast_to<Script>(obj)->get_script_property_list(&props);
- } else {
- ClassDB::get_property_list(E->get(), &props, true);
- }
- }
- for (List<PropertyInfo>::Element *F = props.front(); F; F = F->next()) {
- if (!(F->get().usage & PROPERTY_USAGE_EDITOR) && !(F->get().usage & PROPERTY_USAGE_SCRIPT_VARIABLE)) {
- continue;
- }
-
- if (type_filter.size() && type_filter.find(F->get().type) == -1) {
- continue;
- }
-
- // capitalize() also converts underscore to space, we'll match again both possible styles
- String get_text_raw = String(vformat(TTR("Get %s"), F->get().name));
- String get_text = get_text_raw.capitalize();
- String set_text_raw = String(vformat(TTR("Set %s"), F->get().name));
- String set_text = set_text_raw.capitalize();
- String input = search_box->get_text().capitalize();
-
- if (input == String() || get_text_raw.findn(input) != -1 || get_text.findn(input) != -1) {
- TreeItem *item = search_options->create_item(category ? category : root);
- item->set_text(0, get_text);
- item->set_metadata(0, F->get().name);
- item->set_icon(0, type_icons[F->get().type]);
- item->set_metadata(1, "get");
- item->set_collapsed(true);
- item->set_selectable(0, true);
- item->set_selectable(1, false);
- item->set_selectable(2, false);
- item->set_metadata(2, connecting);
- }
-
- if (input == String() || set_text_raw.findn(input) != -1 || set_text.findn(input) != -1) {
- TreeItem *item = search_options->create_item(category ? category : root);
- item->set_text(0, set_text);
- item->set_metadata(0, F->get().name);
- item->set_icon(0, type_icons[F->get().type]);
- item->set_metadata(1, "set");
- item->set_selectable(0, true);
- item->set_selectable(1, false);
- item->set_selectable(2, false);
- item->set_metadata(2, connecting);
- }
- }
- }
- {
- if (type != Variant::NIL) {
- Variant v;
- Callable::CallError ce;
- Variant::construct(type, v, nullptr, 0, ce);
- v.get_method_list(&methods);
- } else {
- Object *obj = ObjectDB::get_instance(script);
- if (Object::cast_to<Script>(obj)) {
- Object::cast_to<Script>(obj)->get_script_method_list(&methods);
- }
-
- ClassDB::get_method_list(E->get(), &methods, true, true);
- }
- }
- for (List<MethodInfo>::Element *M = methods.front(); M; M = M->next()) {
- String name = M->get().name.get_slice(":", 0);
- if (name.begins_with("_") && !(M->get().flags & METHOD_FLAG_VIRTUAL)) {
- continue;
- }
-
- if (virtuals_only && !(M->get().flags & METHOD_FLAG_VIRTUAL)) {
- continue;
- }
-
- if (!virtuals_only && (M->get().flags & METHOD_FLAG_VIRTUAL)) {
- continue;
- }
-
- MethodInfo mi = M->get();
- String desc_arguments;
- if (mi.arguments.size() > 0) {
- desc_arguments = "(";
- for (int i = 0; i < mi.arguments.size(); i++) {
- if (i > 0) {
- desc_arguments += ", ";
- }
- if (mi.arguments[i].type == Variant::NIL) {
- desc_arguments += "var";
- } else if (mi.arguments[i].name.find(":") != -1) {
- desc_arguments += mi.arguments[i].name.get_slice(":", 1);
- mi.arguments[i].name = mi.arguments[i].name.get_slice(":", 0);
- } else {
- desc_arguments += Variant::get_type_name(mi.arguments[i].type);
- }
- }
- desc_arguments += ")";
- }
- String desc_raw = mi.name + desc_arguments;
- String desc = desc_raw.capitalize().replace("( ", "(");
-
- if (search_box->get_text() != String() &&
- name.findn(search_box->get_text()) == -1 &&
- desc.findn(search_box->get_text()) == -1 &&
- desc_raw.findn(search_box->get_text()) == -1) {
- continue;
- }
-
- TreeItem *item = search_options->create_item(category ? category : root);
- item->set_text(0, desc);
- item->set_icon(0, vbc->get_theme_icon("MemberMethod", "EditorIcons"));
- item->set_metadata(0, name);
- item->set_selectable(0, true);
-
- item->set_metadata(1, "method");
- item->set_collapsed(true);
- item->set_selectable(1, false);
-
- item->set_selectable(2, false);
- item->set_metadata(2, connecting);
- }
-
- if (category && category->get_children() == nullptr) {
- memdelete(category); //old category was unused
- }
- }
- if (properties) {
- if (!seq_connect && !visual_script_generic) {
- get_visual_node_names("flow_control/type_cast", Set<String>(), found, root, search_box);
- get_visual_node_names("functions/built_in/print", Set<String>(), found, root, search_box);
- get_visual_node_names("functions/by_type/" + Variant::get_type_name(type), Set<String>(), found, root, search_box);
- get_visual_node_names("functions/deconstruct/" + Variant::get_type_name(type), Set<String>(), found, root, search_box);
- get_visual_node_names("operators/compare/", Set<String>(), found, root, search_box);
- if (type == Variant::INT) {
- get_visual_node_names("operators/bitwise/", Set<String>(), found, root, search_box);
- }
- if (type == Variant::BOOL) {
- get_visual_node_names("operators/logic/", Set<String>(), found, root, search_box);
- }
- if (type == Variant::BOOL || type == Variant::INT || type == Variant::FLOAT || type == Variant::VECTOR2 || type == Variant::VECTOR3) {
- get_visual_node_names("operators/math/", Set<String>(), found, root, search_box);
- }
- }
- }
-
- if (seq_connect && !visual_script_generic) {
- String text = search_box->get_text();
- create_visualscript_item(String("VisualScriptCondition"), root, text, String("Condition"));
- create_visualscript_item(String("VisualScriptSwitch"), root, text, String("Switch"));
- create_visualscript_item(String("VisualScriptSequence"), root, text, String("Sequence"));
- create_visualscript_item(String("VisualScriptIterator"), root, text, String("Iterator"));
- create_visualscript_item(String("VisualScriptWhile"), root, text, String("While"));
- create_visualscript_item(String("VisualScriptReturn"), root, text, String("Return"));
- get_visual_node_names("flow_control/type_cast", Set<String>(), found, root, search_box);
- get_visual_node_names("functions/built_in/print", Set<String>(), found, root, search_box);
- }
-
- if ((properties || seq_connect) && visual_script_generic) {
- get_visual_node_names("", Set<String>(), found, root, search_box);
- }
-
- TreeItem *selected_item = search_options->search_item_text(search_box->get_text());
- if (!found && selected_item != nullptr) {
- selected_item->select(0);
- found = true;
- }
-
- get_ok_button()->set_disabled(root->get_children() == nullptr);
-}
-
-void VisualScriptPropertySelector::create_visualscript_item(const String &name, TreeItem *const root, const String &search_input, const String &text) {
- if (search_input == String() || text.findn(search_input) != -1) {
- TreeItem *item = search_options->create_item(root);
- item->set_text(0, text);
- item->set_icon(0, vbc->get_theme_icon("VisualScript", "EditorIcons"));
- item->set_metadata(0, name);
- item->set_metadata(1, "action");
- item->set_selectable(0, true);
- item->set_collapsed(true);
- item->set_selectable(1, false);
- item->set_selectable(2, false);
- item->set_metadata(2, connecting);
- }
-}
-
-void VisualScriptPropertySelector::get_visual_node_names(const String &root_filter, const Set<String> &p_modifiers, bool &found, TreeItem *const root, LineEdit *const search_box) {
- Map<String, TreeItem *> path_cache;
-
- List<String> fnodes;
- VisualScriptLanguage::singleton->get_registered_node_names(&fnodes);
-
- for (List<String>::Element *E = fnodes.front(); E; E = E->next()) {
- if (!E->get().begins_with(root_filter)) {
- continue;
- }
- Vector<String> path = E->get().split("/");
-
- // check if the name has the filter
- bool in_filter = false;
- Vector<String> tx_filters = search_box->get_text().split(" ");
- for (int i = 0; i < tx_filters.size(); i++) {
- if (tx_filters[i] == "") {
- in_filter = true;
- } else {
- in_filter = false;
- }
- if (E->get().findn(tx_filters[i]) != -1) {
- in_filter = true;
- break;
- }
- }
- if (!in_filter) {
- continue;
- }
-
- bool in_modifier = p_modifiers.is_empty();
- for (Set<String>::Element *F = p_modifiers.front(); F && in_modifier; F = F->next()) {
- if (E->get().findn(F->get()) != -1) {
- in_modifier = true;
- }
- }
- if (!in_modifier) {
- continue;
- }
-
- TreeItem *item = search_options->create_item(root);
- Ref<VisualScriptNode> vnode = VisualScriptLanguage::singleton->create_node_from_name(E->get());
- Ref<VisualScriptOperator> vnode_operator = vnode;
- String type_name;
- if (vnode_operator.is_valid()) {
- String type;
- if (path.size() >= 2) {
- type = path[1];
- }
- type_name = type.capitalize() + " ";
- }
- Ref<VisualScriptFunctionCall> vnode_function_call = vnode;
- if (vnode_function_call.is_valid()) {
- String basic_type = Variant::get_type_name(vnode_function_call->get_basic_type());
- type_name = basic_type.capitalize() + " ";
- }
- Ref<VisualScriptConstructor> vnode_constructor = vnode;
- if (vnode_constructor.is_valid()) {
- type_name = "Construct ";
- }
- Ref<VisualScriptDeconstruct> vnode_deconstruct = vnode;
- if (vnode_deconstruct.is_valid()) {
- type_name = "Deconstruct ";
- }
- Vector<String> desc = path[path.size() - 1].replace("(", " ").replace(")", " ").replace(",", " ").split(" ");
- for (int i = 0; i < desc.size(); i++) {
- desc.write[i] = desc[i].capitalize();
- if (desc[i].ends_with(",")) {
- desc.write[i] = desc[i].replace(",", ", ");
- }
- }
-
- item->set_text(0, type_name + String("").join(desc));
- item->set_icon(0, vbc->get_theme_icon("VisualScript", "EditorIcons"));
- item->set_selectable(0, true);
- item->set_metadata(0, E->get());
- item->set_selectable(0, true);
- item->set_metadata(1, "visualscript");
- item->set_selectable(1, false);
- item->set_selectable(2, false);
- item->set_metadata(2, connecting);
- }
-}
-
-void VisualScriptPropertySelector::_confirmed() {
- TreeItem *ti = search_options->get_selected();
- if (!ti) {
- return;
- }
- emit_signal("selected", ti->get_metadata(0), ti->get_metadata(1), ti->get_metadata(2));
- set_visible(false);
-}
-
-void VisualScriptPropertySelector::_item_selected() {
- help_bit->set_text("");
-
- TreeItem *item = search_options->get_selected();
- if (!item) {
- return;
- }
- String name = item->get_metadata(0);
-
- String class_type;
- if (type != Variant::NIL) {
- class_type = Variant::get_type_name(type);
-
- } else {
- class_type = base_type;
- }
-
- DocTools *dd = EditorHelp::get_doc_data();
- String text;
-
- String at_class = class_type;
-
- while (at_class != String()) {
- Map<String, DocData::ClassDoc>::Element *E = dd->class_list.find(at_class);
- if (E) {
- for (int i = 0; i < E->get().properties.size(); i++) {
- if (E->get().properties[i].name == name) {
- text = DTR(E->get().properties[i].description);
- }
- }
- }
-
- at_class = ClassDB::get_parent_class_nocheck(at_class);
- }
- at_class = class_type;
-
- while (at_class != String()) {
- Map<String, DocData::ClassDoc>::Element *C = dd->class_list.find(at_class);
- if (C) {
- for (int i = 0; i < C->get().methods.size(); i++) {
- if (C->get().methods[i].name == name) {
- text = DTR(C->get().methods[i].description);
- }
- }
- }
-
- at_class = ClassDB::get_parent_class_nocheck(at_class);
- }
- Map<String, DocData::ClassDoc>::Element *T = dd->class_list.find(class_type);
- if (T) {
- for (int i = 0; i < T->get().methods.size(); i++) {
- Vector<String> functions = name.rsplit("/", false, 1);
- if (T->get().methods[i].name == functions[functions.size() - 1]) {
- text = DTR(T->get().methods[i].description);
- }
- }
- }
-
- List<String> *names = memnew(List<String>);
- VisualScriptLanguage::singleton->get_registered_node_names(names);
- if (names->find(name) != nullptr) {
- Ref<VisualScriptOperator> operator_node = VisualScriptLanguage::singleton->create_node_from_name(name);
- if (operator_node.is_valid()) {
- Map<String, DocData::ClassDoc>::Element *F = dd->class_list.find(operator_node->get_class_name());
- if (F) {
- text = Variant::get_operator_name(operator_node->get_operator());
- }
- }
- Ref<VisualScriptTypeCast> typecast_node = VisualScriptLanguage::singleton->create_node_from_name(name);
- if (typecast_node.is_valid()) {
- Map<String, DocData::ClassDoc>::Element *F = dd->class_list.find(typecast_node->get_class_name());
- if (F) {
- text = DTR(F->get().description);
- }
- }
-
- Ref<VisualScriptBuiltinFunc> builtin_node = VisualScriptLanguage::singleton->create_node_from_name(name);
- if (builtin_node.is_valid()) {
- Map<String, DocData::ClassDoc>::Element *F = dd->class_list.find(builtin_node->get_class_name());
- if (F) {
- for (int i = 0; i < F->get().constants.size(); i++) {
- if (F->get().constants[i].value.to_int() == int(builtin_node->get_func())) {
- text = DTR(F->get().constants[i].description);
- }
- }
- }
- }
- }
-
- memdelete(names);
-
- if (text == String()) {
- return;
- }
-
- help_bit->set_text(text);
-}
-
-void VisualScriptPropertySelector::_hide_requested() {
- _cancel_pressed(); // From AcceptDialog.
-}
-
-void VisualScriptPropertySelector::_notification(int p_what) {
- if (p_what == NOTIFICATION_ENTER_TREE) {
- connect("confirmed", callable_mp(this, &VisualScriptPropertySelector::_confirmed));
- }
-}
-
-void VisualScriptPropertySelector::select_method_from_base_type(const String &p_base, const String &p_current, const bool p_virtuals_only, const bool p_connecting, bool clear_text) {
- base_type = p_base;
- selected = p_current;
- type = Variant::NIL;
- properties = false;
- instance = nullptr;
- virtuals_only = p_virtuals_only;
-
- show_window(.5f);
- if (clear_text) {
- search_box->set_text("");
- } else {
- search_box->select_all();
- }
- search_box->grab_focus();
- connecting = p_connecting;
-
- _update_search();
-}
-
-void VisualScriptPropertySelector::set_type_filter(const Vector<Variant::Type> &p_type_filter) {
- type_filter = p_type_filter;
-}
-
-void VisualScriptPropertySelector::select_from_base_type(const String &p_base, const String &p_current, bool p_virtuals_only, bool p_seq_connect, const bool p_connecting, bool clear_text) {
- base_type = p_base;
- selected = p_current;
- type = Variant::NIL;
- properties = true;
- visual_script_generic = false;
- instance = nullptr;
- virtuals_only = p_virtuals_only;
-
- show_window(.5f);
- if (clear_text) {
- search_box->set_text("");
- } else {
- search_box->select_all();
- }
- search_box->grab_focus();
- seq_connect = p_seq_connect;
- connecting = p_connecting;
-
- _update_search();
-}
-
-void VisualScriptPropertySelector::select_from_script(const Ref<Script> &p_script, const String &p_current, const bool p_connecting, bool clear_text) {
- ERR_FAIL_COND(p_script.is_null());
-
- base_type = p_script->get_instance_base_type();
- selected = p_current;
- type = Variant::NIL;
- script = p_script->get_instance_id();
- properties = true;
- visual_script_generic = false;
- instance = nullptr;
- virtuals_only = false;
-
- show_window(.5f);
- if (clear_text) {
- search_box->set_text("");
- } else {
- search_box->select_all();
- }
- search_box->grab_focus();
- seq_connect = false;
- connecting = p_connecting;
-
- _update_search();
-}
-
-void VisualScriptPropertySelector::select_from_basic_type(Variant::Type p_type, const String &p_current, const bool p_connecting, bool clear_text) {
- ERR_FAIL_COND(p_type == Variant::NIL);
- base_type = "";
- selected = p_current;
- type = p_type;
- properties = true;
- visual_script_generic = false;
- instance = nullptr;
- virtuals_only = false;
-
- show_window(.5f);
- if (clear_text) {
- search_box->set_text("");
- } else {
- search_box->select_all();
- }
- search_box->grab_focus();
- seq_connect = false;
- connecting = p_connecting;
-
- _update_search();
-}
-
-void VisualScriptPropertySelector::select_from_action(const String &p_type, const String &p_current, const bool p_connecting, bool clear_text) {
- base_type = p_type;
- selected = p_current;
- type = Variant::NIL;
- properties = false;
- visual_script_generic = false;
- instance = nullptr;
- virtuals_only = false;
-
- show_window(.5f);
- if (clear_text) {
- search_box->set_text("");
- } else {
- search_box->select_all();
- }
- search_box->grab_focus();
- seq_connect = true;
- connecting = p_connecting;
-
- _update_search();
-}
-
-void VisualScriptPropertySelector::select_from_instance(Object *p_instance, const String &p_current, const bool p_connecting, const String &p_basetype, bool clear_text) {
- base_type = p_basetype;
- selected = p_current;
- type = Variant::NIL;
- properties = true;
- visual_script_generic = false;
- instance = p_instance;
- virtuals_only = false;
-
- show_window(.5f);
- if (clear_text) {
- search_box->set_text("");
- } else {
- search_box->select_all();
- }
- search_box->grab_focus();
- seq_connect = false;
- connecting = p_connecting;
-
- _update_search();
-}
-
-void VisualScriptPropertySelector::select_from_visual_script(const String &p_base, const bool p_connecting, bool clear_text) {
- base_type = p_base;
- selected = "";
- type = Variant::NIL;
- properties = true;
- visual_script_generic = true;
- instance = nullptr;
- virtuals_only = false;
- show_window(.5f);
- if (clear_text) {
- search_box->set_text("");
- } else {
- search_box->select_all();
- }
- search_box->grab_focus();
- connecting = p_connecting;
-
- _update_search();
-}
-
-void VisualScriptPropertySelector::show_window(float p_screen_ratio) {
- popup_centered_ratio(p_screen_ratio);
-}
-
-void VisualScriptPropertySelector::_bind_methods() {
- ADD_SIGNAL(MethodInfo("selected", PropertyInfo(Variant::STRING, "name"), PropertyInfo(Variant::STRING, "category"), PropertyInfo(Variant::BOOL, "connecting")));
-}
-
-VisualScriptPropertySelector::VisualScriptPropertySelector() {
- vbc = memnew(VBoxContainer);
- add_child(vbc);
- //set_child_rect(vbc);
- search_box = memnew(LineEdit);
- vbc->add_margin_child(TTR("Search:"), search_box);
- search_box->connect("text_changed", callable_mp(this, &VisualScriptPropertySelector::_text_changed));
- search_box->connect("gui_input", callable_mp(this, &VisualScriptPropertySelector::_sbox_input));
- search_options = memnew(Tree);
- vbc->add_margin_child(TTR("Matches:"), search_options, true);
- get_ok_button()->set_text(TTR("Open"));
- get_ok_button()->set_disabled(true);
- register_text_enter(search_box);
- set_hide_on_ok(false);
- search_options->connect("item_activated", callable_mp(this, &VisualScriptPropertySelector::_confirmed));
- search_options->connect("cell_selected", callable_mp(this, &VisualScriptPropertySelector::_item_selected));
- search_options->set_hide_root(true);
- search_options->set_hide_folding(true);
- virtuals_only = false;
- seq_connect = false;
- help_bit = memnew(EditorHelpBit);
- vbc->add_margin_child(TTR("Description:"), help_bit);
- help_bit->connect("request_hide", callable_mp(this, &VisualScriptPropertySelector::_hide_requested));
- search_options->set_columns(3);
- search_options->set_column_expand(1, false);
- search_options->set_column_expand(2, false);
-}
diff --git a/modules/visual_script/visual_script_property_selector.h b/modules/visual_script/visual_script_property_selector.h
deleted file mode 100644
index 7a87f3d3ee..0000000000
--- a/modules/visual_script/visual_script_property_selector.h
+++ /dev/null
@@ -1,91 +0,0 @@
-/*************************************************************************/
-/* visual_script_property_selector.h */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 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. */
-/*************************************************************************/
-
-#ifndef VISUALSCRIPT_PROPERTYSELECTOR_H
-#define VISUALSCRIPT_PROPERTYSELECTOR_H
-
-#include "editor/editor_help.h"
-#include "editor/property_editor.h"
-#include "scene/gui/rich_text_label.h"
-
-class VisualScriptPropertySelector : public ConfirmationDialog {
- GDCLASS(VisualScriptPropertySelector, ConfirmationDialog);
-
- LineEdit *search_box;
- Tree *search_options;
-
- void _text_changed(const String &p_newtext);
- void _sbox_input(const Ref<InputEvent> &p_ie);
- void _update_search();
-
- void create_visualscript_item(const String &name, TreeItem *const root, const String &search_input, const String &text);
- void get_visual_node_names(const String &root_filter, const Set<String> &p_modifiers, bool &found, TreeItem *const root, LineEdit *const search_box);
-
- void _confirmed();
- void _item_selected();
- void _hide_requested();
-
- EditorHelpBit *help_bit;
-
- bool properties;
- bool visual_script_generic;
- bool connecting;
- String selected;
- Variant::Type type;
- String base_type;
- ObjectID script;
- Object *instance;
- bool virtuals_only;
- bool seq_connect;
- VBoxContainer *vbc;
-
- Vector<Variant::Type> type_filter;
-
-protected:
- void _notification(int p_what);
- static void _bind_methods();
-
-public:
- void select_method_from_base_type(const String &p_base, const String &p_current = "", const bool p_virtuals_only = false, const bool p_connecting = true, bool clear_text = true);
- void select_from_base_type(const String &p_base, const String &p_current = "", bool p_virtuals_only = false, bool p_seq_connect = false, const bool p_connecting = true, bool clear_text = true);
- void select_from_script(const Ref<Script> &p_script, const String &p_current = "", const bool p_connecting = true, bool clear_text = true);
- void select_from_basic_type(Variant::Type p_type, const String &p_current = "", const bool p_connecting = true, bool clear_text = true);
- void select_from_action(const String &p_type, const String &p_current = "", const bool p_connecting = true, bool clear_text = true);
- void select_from_instance(Object *p_instance, const String &p_current = "", const bool p_connecting = true, const String &p_basetype = "", bool clear_text = true);
- void select_from_visual_script(const String &p_base, const bool p_connecting = true, bool clear_text = true);
-
- void show_window(float p_screen_ratio);
-
- void set_type_filter(const Vector<Variant::Type> &p_type_filter);
-
- VisualScriptPropertySelector();
-};
-
-#endif // VISUALSCRIPT_PROPERTYSELECTOR_H
diff --git a/modules/visual_script/visual_script_yield_nodes.cpp b/modules/visual_script/visual_script_yield_nodes.cpp
index 52fe659983..96e91a0baf 100644
--- a/modules/visual_script/visual_script_yield_nodes.cpp
+++ b/modules/visual_script/visual_script_yield_nodes.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -68,7 +68,7 @@ PropertyInfo VisualScriptYield::get_output_value_port_info(int p_idx) const {
}
String VisualScriptYield::get_caption() const {
- return yield_mode == YIELD_RETURN ? "Yield" : "Wait";
+ return yield_mode == YIELD_RETURN ? RTR("Yield") : RTR("Wait");
}
String VisualScriptYield::get_text() const {
@@ -77,13 +77,13 @@ String VisualScriptYield::get_text() const {
return "";
break;
case YIELD_FRAME:
- return "Next Frame";
+ return RTR("Next Frame");
break;
case YIELD_PHYSICS_FRAME:
- return "Next Physics Frame";
+ return RTR("Next Physics Frame");
break;
case YIELD_WAIT:
- return rtos(wait_time) + " sec(s)";
+ return vformat(RTR("%s sec(s)"), rtos(wait_time));
break;
}
@@ -93,13 +93,13 @@ String VisualScriptYield::get_text() const {
class VisualScriptNodeInstanceYield : public VisualScriptNodeInstance {
public:
VisualScriptYield::YieldMode mode;
- float wait_time;
+ double wait_time = 0.0;
- virtual int get_working_memory_size() const { return 1; } //yield needs at least 1
+ virtual int get_working_memory_size() const override { return 1; } //yield needs at least 1
//virtual bool is_output_port_unsequenced(int p_idx) const { return false; }
//virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return false; }
- virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) {
+ virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
if (p_start_mode == START_MODE_RESUME_YIELD) {
return 0; //resuming yield
} else {
@@ -113,7 +113,7 @@ public:
}
Ref<VisualScriptFunctionState> state;
- state.instance();
+ state.instantiate();
int ret = STEP_YIELD_BIT;
switch (mode) {
@@ -121,7 +121,7 @@ public:
ret = STEP_EXIT_FUNCTION_BIT;
break; //return the yield
case VisualScriptYield::YIELD_FRAME:
- state->connect_to_signal(tree, "idle_frame", Array());
+ state->connect_to_signal(tree, "process_frame", Array());
break;
case VisualScriptYield::YIELD_PHYSICS_FRAME:
state->connect_to_signal(tree, "physics_frame", Array());
@@ -138,7 +138,7 @@ public:
}
};
-VisualScriptNodeInstance *VisualScriptYield::instance(VisualScriptInstance *p_instance) {
+VisualScriptNodeInstance *VisualScriptYield::instantiate(VisualScriptInstance *p_instance) {
VisualScriptNodeInstanceYield *instance = memnew(VisualScriptNodeInstanceYield);
//instance->instance=p_instance;
instance->mode = yield_mode;
@@ -159,7 +159,7 @@ VisualScriptYield::YieldMode VisualScriptYield::get_yield_mode() {
return yield_mode;
}
-void VisualScriptYield::set_wait_time(float p_time) {
+void VisualScriptYield::set_wait_time(double p_time) {
if (wait_time == p_time) {
return;
}
@@ -167,14 +167,14 @@ void VisualScriptYield::set_wait_time(float p_time) {
ports_changed_notify();
}
-float VisualScriptYield::get_wait_time() {
+double VisualScriptYield::get_wait_time() {
return wait_time;
}
void VisualScriptYield::_validate_property(PropertyInfo &property) const {
if (property.name == "wait_time") {
if (yield_mode != YIELD_WAIT) {
- property.usage = 0;
+ property.usage = PROPERTY_USAGE_NONE;
}
}
}
@@ -186,7 +186,7 @@ void VisualScriptYield::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_wait_time", "sec"), &VisualScriptYield::set_wait_time);
ClassDB::bind_method(D_METHOD("get_wait_time"), &VisualScriptYield::get_wait_time);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Frame,Physics Frame,Time", PROPERTY_USAGE_NOEDITOR), "set_yield_mode", "get_yield_mode");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Frame,Physics Frame,Time", PROPERTY_USAGE_NO_EDITOR), "set_yield_mode", "get_yield_mode");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "wait_time"), "set_wait_time", "get_wait_time");
BIND_ENUM_CONSTANT(YIELD_FRAME);
@@ -202,7 +202,7 @@ VisualScriptYield::VisualScriptYield() {
template <VisualScriptYield::YieldMode MODE>
static Ref<VisualScriptNode> create_yield_node(const String &p_name) {
Ref<VisualScriptYield> node;
- node.instance();
+ node.instantiate();
node->set_yield_mode(MODE);
return node;
}
@@ -335,13 +335,18 @@ PropertyInfo VisualScriptYieldSignal::get_output_value_port_info(int p_idx) cons
}
String VisualScriptYieldSignal::get_caption() const {
- static const char *cname[3] = {
- "WaitSignal",
- "WaitNodeSignal",
- "WaitInstanceSigna;",
- };
-
- return cname[call_mode];
+ switch (call_mode) {
+ case CALL_MODE_SELF: {
+ return RTR("WaitSignal");
+ } break;
+ case CALL_MODE_NODE_PATH: {
+ return RTR("WaitNodeSignal");
+ } break;
+ case CALL_MODE_INSTANCE: {
+ return RTR("WaitInstanceSignal");
+ } break;
+ }
+ return String();
}
String VisualScriptYieldSignal::get_text() const {
@@ -415,13 +420,13 @@ VisualScriptYieldSignal::CallMode VisualScriptYieldSignal::get_call_mode() const
void VisualScriptYieldSignal::_validate_property(PropertyInfo &property) const {
if (property.name == "base_type") {
if (call_mode != CALL_MODE_INSTANCE) {
- property.usage = PROPERTY_USAGE_NOEDITOR;
+ property.usage = PROPERTY_USAGE_NO_EDITOR;
}
}
if (property.name == "node_path") {
if (call_mode != CALL_MODE_NODE_PATH) {
- property.usage = 0;
+ property.usage = PROPERTY_USAGE_NONE;
} else {
Node *bnode = _get_base_node();
if (bnode) {
@@ -438,21 +443,21 @@ void VisualScriptYieldSignal::_validate_property(PropertyInfo &property) const {
ClassDB::get_signal_list(_get_base_type(), &methods);
List<String> mstring;
- for (List<MethodInfo>::Element *E = methods.front(); E; E = E->next()) {
- if (E->get().name.begins_with("_")) {
+ for (const MethodInfo &E : methods) {
+ if (E.name.begins_with("_")) {
continue;
}
- mstring.push_back(E->get().name.get_slice(":", 0));
+ mstring.push_back(E.name.get_slice(":", 0));
}
mstring.sort();
String ml;
- for (List<String>::Element *E = mstring.front(); E; E = E->next()) {
- if (ml != String()) {
+ for (const String &E : mstring) {
+ if (!ml.is_empty()) {
ml += ",";
}
- ml += E->get();
+ ml += E;
}
property.hint_string = ml;
@@ -495,17 +500,17 @@ class VisualScriptNodeInstanceYieldSignal : public VisualScriptNodeInstance {
public:
VisualScriptYieldSignal::CallMode call_mode;
NodePath node_path;
- int output_args;
+ int output_args = 0;
StringName signal;
- VisualScriptYieldSignal *node;
- VisualScriptInstance *instance;
+ VisualScriptYieldSignal *node = nullptr;
+ VisualScriptInstance *instance = nullptr;
- virtual int get_working_memory_size() const { return 1; }
+ virtual int get_working_memory_size() const override { return 1; }
//virtual bool is_output_port_unsequenced(int p_idx) const { return false; }
//virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return true; }
- virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) {
+ virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
if (p_start_mode == START_MODE_RESUME_YIELD) {
return 0; //resuming yield
} else {
@@ -548,7 +553,7 @@ public:
}
Ref<VisualScriptFunctionState> state;
- state.instance();
+ state.instantiate();
state->connect_to_signal(object, signal, Array());
@@ -559,7 +564,7 @@ public:
}
};
-VisualScriptNodeInstance *VisualScriptYieldSignal::instance(VisualScriptInstance *p_instance) {
+VisualScriptNodeInstance *VisualScriptYieldSignal::instantiate(VisualScriptInstance *p_instance) {
VisualScriptNodeInstanceYieldSignal *instance = memnew(VisualScriptNodeInstanceYieldSignal);
instance->node = this;
instance->instance = p_instance;
@@ -578,7 +583,7 @@ VisualScriptYieldSignal::VisualScriptYieldSignal() {
template <VisualScriptYieldSignal::CallMode cmode>
static Ref<VisualScriptNode> create_yield_signal_node(const String &p_name) {
Ref<VisualScriptYieldSignal> node;
- node.instance();
+ node.instantiate();
node->set_call_mode(cmode);
return node;
}
diff --git a/modules/visual_script/visual_script_yield_nodes.h b/modules/visual_script/visual_script_yield_nodes.h
index cc7ce0a1c6..a7bf4e8a78 100644
--- a/modules/visual_script/visual_script_yield_nodes.h
+++ b/modules/visual_script/visual_script_yield_nodes.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* 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 */
@@ -47,7 +47,7 @@ public:
private:
YieldMode yield_mode;
- float wait_time;
+ double wait_time;
protected:
virtual void _validate_property(PropertyInfo &property) const override;
@@ -73,10 +73,10 @@ public:
void set_yield_mode(YieldMode p_mode);
YieldMode get_yield_mode();
- void set_wait_time(float p_time);
- float get_wait_time();
+ void set_wait_time(double p_time);
+ double get_wait_time();
- virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override;
+ virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override;
VisualScriptYield();
};
@@ -135,7 +135,7 @@ public:
void set_call_mode(CallMode p_mode);
CallMode get_call_mode() const;
- virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override;
+ virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override;
VisualScriptYieldSignal();
};