From 9865650b43c2a924f5e3ed4ffdaac56c87328756 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Mon, 8 Aug 2016 01:21:22 -0300 Subject: [PATCH] Added a simpler way to do sub-functions in both visual and gdscript with the subcall node. With this, visual script is almost done (missing registering custom nodes from addon). All this is probably pretty broken, too and needs a lot of testing. --- core/script_language.h | 3 + modules/gdscript/gd_script.cpp | 31 ++++- modules/gdscript/gd_script.h | 2 + modules/visual_script/register_types.cpp | 1 + modules/visual_script/visual_script.cpp | 32 ++++- modules/visual_script/visual_script.h | 5 + .../visual_script/visual_script_editor.cpp | 1 + modules/visual_script/visual_script_nodes.cpp | 129 ++++++++++++++++++ modules/visual_script/visual_script_nodes.h | 35 +++++ tools/editor/property_editor.cpp | 4 + 10 files changed, 241 insertions(+), 2 deletions(-) diff --git a/core/script_language.h b/core/script_language.h index d1f82eff062..0e3f2987903 100644 --- a/core/script_language.h +++ b/core/script_language.h @@ -98,6 +98,9 @@ public: virtual void set_source_code(const String& p_code)=0; virtual Error reload(bool p_keep_state=false)=0; + virtual bool has_method(const StringName& p_method) const=0; + virtual MethodInfo get_method_info(const StringName& p_method) const=0; + virtual bool is_tool() const=0; virtual String get_node_type() const=0; diff --git a/modules/gdscript/gd_script.cpp b/modules/gdscript/gd_script.cpp index cc46d91a2d7..2f5c7956d1e 100644 --- a/modules/gdscript/gd_script.cpp +++ b/modules/gdscript/gd_script.cpp @@ -262,10 +262,37 @@ void GDScript::get_method_list(List *p_list) const { mi.arguments.push_back(arg); } - mi.return_val.name="var"; + mi.return_val.name="Variant"; p_list->push_back(mi); } } + +bool GDScript::has_method(const StringName& p_method) const { + + return member_functions.has(p_method); +} + +MethodInfo GDScript::get_method_info(const StringName& p_method) const { + + const Map::Element *E=member_functions.find(p_method); + if (!E) + return MethodInfo(); + + MethodInfo mi; + mi.name=E->key(); + for(int i=0;iget()->get_argument_count();i++) { + PropertyInfo arg; + arg.type=Variant::NIL; //variant + arg.name=E->get()->get_argument_name(i); + mi.arguments.push_back(arg); + } + + mi.return_val.name="Variant"; + return mi; + +} + + bool GDScript::get_property_default_value(const StringName& p_property, Variant &r_value) const { #ifdef TOOLS_ENABLED @@ -1239,6 +1266,8 @@ void GDInstance::call_multilevel_reversed(const StringName& p_method,const Varia } } + + void GDInstance::notification(int p_notification) { //notification is not virutal, it gets called at ALL levels just like in C. diff --git a/modules/gdscript/gd_script.h b/modules/gdscript/gd_script.h index 3634eb796eb..28a0df1efd4 100644 --- a/modules/gdscript/gd_script.h +++ b/modules/gdscript/gd_script.h @@ -182,6 +182,8 @@ public: bool get_property_default_value(const StringName& p_property,Variant& r_value) const; virtual void get_method_list(List *p_list) const; + virtual bool has_method(const StringName& p_method) const; + virtual MethodInfo get_method_info(const StringName& p_method) const; virtual ScriptLanguage *get_language() const; diff --git a/modules/visual_script/register_types.cpp b/modules/visual_script/register_types.cpp index 6b1362cdf72..1360e546f32 100644 --- a/modules/visual_script/register_types.cpp +++ b/modules/visual_script/register_types.cpp @@ -61,6 +61,7 @@ void register_visual_script_types() { ObjectTypeDB::register_type(); ObjectTypeDB::register_type(); ObjectTypeDB::register_type(); + ObjectTypeDB::register_type(); ObjectTypeDB::register_type(); ObjectTypeDB::register_type(); diff --git a/modules/visual_script/visual_script.cpp b/modules/visual_script/visual_script.cpp index e6880755967..425436d907b 100644 --- a/modules/visual_script/visual_script.cpp +++ b/modules/visual_script/visual_script.cpp @@ -1015,6 +1015,36 @@ void VisualScript::get_method_list(List *p_list) const { } } +bool VisualScript::has_method(const StringName& p_method) const { + + return functions.has(p_method); +} +MethodInfo VisualScript::get_method_info(const StringName& p_method) const{ + + const Map::Element *E=functions.find(p_method); + if (!E) + return MethodInfo(); + + MethodInfo mi; + mi.name=E->key(); + if (E->get().function_id>=0) { + + Ref func=E->get().nodes[E->get().function_id].node; + if (func.is_valid()) { + + for(int i=0;iget_argument_count();i++) { + PropertyInfo arg; + arg.name=func->get_argument_name(i); + arg.type=func->get_argument_type(i); + mi.arguments.push_back(arg); + } + } + } + + return mi; +} + + void VisualScript::_set_data(const Dictionary& p_data) { Dictionary d = p_data; @@ -2550,7 +2580,7 @@ VisualScriptLanguage::VisualScriptLanguage() { notification="_notification"; _get_output_port_unsequenced="_get_output_port_unsequenced"; _step="_step"; - + _subcall="_subcall"; singleton=this; #ifndef NO_THREADS lock = Mutex::create(); diff --git a/modules/visual_script/visual_script.h b/modules/visual_script/visual_script.h index 88e9ea01d07..786b9b873e5 100644 --- a/modules/visual_script/visual_script.h +++ b/modules/visual_script/visual_script.h @@ -322,6 +322,10 @@ public: virtual bool get_property_default_value(const StringName& p_property,Variant& r_value) const; virtual void get_method_list(List *p_list) const; + virtual bool has_method(const StringName& p_method) const; + virtual MethodInfo get_method_info(const StringName& p_method) const; + + VisualScript(); ~VisualScript(); @@ -470,6 +474,7 @@ public: StringName notification; StringName _get_output_port_unsequenced; StringName _step; + StringName _subcall; static VisualScriptLanguage* singleton; diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index 0407a37a7bd..d01cafb90c4 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -2596,6 +2596,7 @@ static void register_editor_callback() { EditorSettings::get_singleton()->set("visual_script_editor/color_data",Color(0.9,1.0,0.9)); EditorSettings::get_singleton()->set("visual_script_editor/color_operators",Color(0.9,0.9,1.0)); EditorSettings::get_singleton()->set("visual_script_editor/color_flow_control",Color(1.0,1.0,0.8)); + EditorSettings::get_singleton()->set("visual_script_editor/color_custom",Color(0.8,1.0,1.0)); ED_SHORTCUT("visual_script_editor/delete_selected", TTR("Delete Selected")); diff --git a/modules/visual_script/visual_script_nodes.cpp b/modules/visual_script/visual_script_nodes.cpp index 009d13a2f20..2326bdc4a48 100644 --- a/modules/visual_script/visual_script_nodes.cpp +++ b/modules/visual_script/visual_script_nodes.cpp @@ -2296,6 +2296,133 @@ VisualScriptCustomNode::VisualScriptCustomNode() { } +////////////////////////////////////////// +////////////////SUBCALL/////////// +////////////////////////////////////////// + +int VisualScriptSubCall::get_output_sequence_port_count() const { + + return 1; +} + +bool VisualScriptSubCall::has_input_sequence_port() const{ + + return true; +} + +int VisualScriptSubCall::get_input_value_port_count() const{ + + Ref