diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2021-07-21 12:02:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-21 12:02:17 +0200 |
commit | 88bf6e1c6d3e711976304bb16ac51719e8e82f72 (patch) | |
tree | 6fdbf90145f451f81ef8f6d94c698595173b71ba /modules/visual_script | |
parent | 2273f13fbe7ba0482288e497031616ebd533308f (diff) | |
parent | 1c4c0f9960d0a42803c629dbd890d33326613dc9 (diff) |
Merge pull request #48972 from DavidCambre/Expose_VisualScriptCustomNode_TypeHints_m
Diffstat (limited to 'modules/visual_script')
-rw-r--r-- | modules/visual_script/doc_classes/VisualScriptCustomNode.xml | 40 | ||||
-rw-r--r-- | modules/visual_script/visual_script_nodes.cpp | 32 | ||||
-rw-r--r-- | modules/visual_script/visual_script_nodes.h | 2 |
3 files changed, 72 insertions, 2 deletions
diff --git a/modules/visual_script/doc_classes/VisualScriptCustomNode.xml b/modules/visual_script/doc_classes/VisualScriptCustomNode.xml index 1c23b58507..ba4eba26fd 100644 --- a/modules/visual_script/doc_classes/VisualScriptCustomNode.xml +++ b/modules/visual_script/doc_classes/VisualScriptCustomNode.xml @@ -30,6 +30,24 @@ Return the count of input value ports. </description> </method> + <method name="_get_input_value_port_hint" qualifiers="virtual"> + <return type="int"> + </return> + <argument index="0" name="idx" type="int"> + </argument> + <description> + Return the specified input port's hint. See the [enum @GlobalScope.PropertyHint] hints. + </description> + </method> + <method name="_get_input_value_port_hint_string" qualifiers="virtual"> + <return type="String"> + </return> + <argument index="0" name="idx" type="int"> + </argument> + <description> + Return the specified input port's hint string. + </description> + </method> <method name="_get_input_value_port_name" qualifiers="virtual"> <return type="String"> </return> @@ -71,13 +89,31 @@ Return the amount of output value ports. </description> </method> + <method name="_get_output_value_port_hint" qualifiers="virtual"> + <return type="int"> + </return> + <argument index="0" name="idx" type="int"> + </argument> + <description> + Return the specified output port's hint. See the [enum @GlobalScope.PropertyHint] hints. + </description> + </method> + <method name="_get_output_value_port_hint_string" qualifiers="virtual"> + <return type="String"> + </return> + <argument index="0" name="idx" type="int"> + </argument> + <description> + Return the specified output port's hint string. + </description> + </method> <method name="_get_output_value_port_name" qualifiers="virtual"> <return type="String"> </return> <argument index="0" name="idx" type="int"> </argument> <description> - Return the specified output's name. + Return the specified output port's name. </description> </method> <method name="_get_output_value_port_type" qualifiers="virtual"> @@ -86,7 +122,7 @@ <argument index="0" name="idx" type="int"> </argument> <description> - Return the specified output's type. See the [enum Variant.Type] values. + Return the specified output port's type. See the [enum Variant.Type] values. </description> </method> <method name="_get_text" qualifiers="virtual"> diff --git a/modules/visual_script/visual_script_nodes.cpp b/modules/visual_script/visual_script_nodes.cpp index 5e3451ee2b..86d8050acb 100644 --- a/modules/visual_script/visual_script_nodes.cpp +++ b/modules/visual_script/visual_script_nodes.cpp @@ -2868,6 +2868,12 @@ PropertyInfo VisualScriptCustomNode::get_input_value_port_info(int p_idx) const 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); } + if (get_script_instance() && get_script_instance()->has_method("_get_input_value_port_hint")) { + info.hint = PropertyHint(int(get_script_instance()->call("_get_input_value_port_hint", p_idx))); + } + if (get_script_instance() && get_script_instance()->has_method("_get_input_value_port_hint_string")) { + info.hint_string = get_script_instance()->call("_get_input_value_port_hint_string", p_idx); + } return info; } @@ -2879,9 +2885,31 @@ PropertyInfo VisualScriptCustomNode::get_output_value_port_info(int p_idx) const 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); } + if (get_script_instance() && get_script_instance()->has_method("_get_output_value_port_hint")) { + info.hint = PropertyHint(int(get_script_instance()->call("_get_output_value_port_hint", p_idx))); + } + if (get_script_instance() && get_script_instance()->has_method("_get_output_value_port_hint_string")) { + info.hint_string = get_script_instance()->call("_get_output_value_port_hint_string", p_idx); + } 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"); @@ -3003,9 +3031,13 @@ void VisualScriptCustomNode::_bind_methods() { 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"))); + BIND_VMETHOD(MethodInfo(Variant::INT, "_get_input_value_port_hint", PropertyInfo(Variant::INT, "idx"))); + BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_input_value_port_hint_string", PropertyInfo(Variant::INT, "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"))); + BIND_VMETHOD(MethodInfo(Variant::INT, "_get_output_value_port_hint", PropertyInfo(Variant::INT, "idx"))); + BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_output_value_port_hint_string", PropertyInfo(Variant::INT, "idx"))); BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_caption")); BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_text")); diff --git a/modules/visual_script/visual_script_nodes.h b/modules/visual_script/visual_script_nodes.h index b599b92b3a..2390e5c7bc 100644 --- a/modules/visual_script/visual_script_nodes.h +++ b/modules/visual_script/visual_script_nodes.h @@ -792,6 +792,8 @@ public: virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override; + virtual TypeGuess guess_output_type(TypeGuess *p_inputs, int p_output) const override; + void _script_changed(); VisualScriptCustomNode(); |