diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/visual_script/register_types.cpp | 4 | ||||
-rw-r--r-- | modules/visual_script/visual_script_editor.cpp | 262 | ||||
-rw-r--r-- | modules/visual_script/visual_script_editor.h | 8 | ||||
-rw-r--r-- | modules/visual_script/visual_script_func_nodes.cpp | 413 | ||||
-rw-r--r-- | modules/visual_script/visual_script_func_nodes.h | 18 | ||||
-rw-r--r-- | modules/visual_script/visual_script_nodes.cpp | 192 | ||||
-rw-r--r-- | modules/visual_script/visual_script_nodes.h | 77 |
7 files changed, 871 insertions, 103 deletions
diff --git a/modules/visual_script/register_types.cpp b/modules/visual_script/register_types.cpp index 2cd84203e8..da767c8447 100644 --- a/modules/visual_script/register_types.cpp +++ b/modules/visual_script/register_types.cpp @@ -52,8 +52,10 @@ void register_visual_script_types() { ObjectTypeDB::register_type<VisualScriptIndexSet>(); ObjectTypeDB::register_type<VisualScriptGlobalConstant>(); ObjectTypeDB::register_type<VisualScriptMathConstant>(); - ObjectTypeDB::register_type<VisualScriptSingleton>(); + ObjectTypeDB::register_type<VisualScriptEngineSingleton>(); ObjectTypeDB::register_type<VisualScriptSceneNode>(); + ObjectTypeDB::register_type<VisualScriptSceneTree>(); + ObjectTypeDB::register_type<VisualScriptResourcePath>(); ObjectTypeDB::register_type<VisualScriptFunctionCall>(); ObjectTypeDB::register_type<VisualScriptPropertySet>(); diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index f25bd0b998..677960a03d 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -3,6 +3,8 @@ #include "visual_script_nodes.h" #include "visual_script_flow_control.h" #include "visual_script_func_nodes.h" +#include "os/input.h" +#include "os/keyboard.h" class VisualScriptEditorSignalEdit : public Object { @@ -363,8 +365,14 @@ void VisualScriptEditor::_update_graph(int p_only_id) { } } - if (!script->has_function(edited_func)) + if (!script->has_function(edited_func)) { + graph->hide(); + select_func_text->show(); return; + } + + graph->show(); + select_func_text->hide(); Ref<Texture> type_icons[Variant::VARIANT_MAX]={ Control::get_icon("MiniVariant","EditorIcons"), @@ -762,6 +770,9 @@ void VisualScriptEditor::_override_pressed(int p_id) { undo_redo->add_undo_method(script.ptr(),"remove_function",name); undo_redo->add_do_method(this,"_update_members"); undo_redo->add_undo_method(this,"_update_members"); + undo_redo->add_do_method(this,"_update_graph"); + undo_redo->add_undo_method(this,"_update_graph"); + undo_redo->commit_action(); @@ -858,6 +869,9 @@ void VisualScriptEditor::_member_button(Object *p_item, int p_column, int p_butt undo_redo->add_undo_method(script.ptr(),"remove_function",name); undo_redo->add_do_method(this,"_update_members"); undo_redo->add_undo_method(this,"_update_members"); + undo_redo->add_do_method(this,"_update_graph"); + undo_redo->add_undo_method(this,"_update_graph"); + undo_redo->commit_action(); _update_graph(); @@ -935,6 +949,8 @@ void VisualScriptEditor::_member_button(Object *p_item, int p_column, int p_butt //} undo_redo->add_do_method(this,"_update_members"); undo_redo->add_undo_method(this,"_update_members"); + undo_redo->add_do_method(this,"_update_graph"); + undo_redo->add_undo_method(this,"_update_graph"); undo_redo->commit_action(); } else if (p_button==0) { @@ -1309,20 +1325,62 @@ bool VisualScriptEditor::can_drop_data_fw(const Point2& p_point,const Variant& p if (p_from==graph) { + Dictionary d = p_data; if (d.has("type") && ( String(d["type"])=="visual_script_node_drag" || String(d["type"])=="visual_script_function_drag" || String(d["type"])=="visual_script_variable_drag" || - String(d["type"])=="visual_script_signal_drag" - ) ) + String(d["type"])=="visual_script_signal_drag" || + String(d["type"])=="obj_property" || + String(d["type"])=="nodes" + ) ) { + + + if (String(d["type"])=="obj_property") { + +#ifdef OSX_ENABLED + const_cast<VisualScriptEditor*>(this)->_show_hint("Hold Meta to drop a Setter, Shift+Meta to drop a Setter and copy the value."); +#else + const_cast<VisualScriptEditor*>(this)->_show_hint("Hold Ctrl to drop a Setter, Shift+Ctrl to drop a Setter and copy the value."); +#endif + } return true; + + } + + + } return false; } + +#ifdef TOOLS_ENABLED + +static Node* _find_script_node(Node* p_edited_scene,Node* p_current_node,const Ref<Script> &script) { + + if (p_edited_scene!=p_current_node && p_current_node->get_owner()!=p_edited_scene) + return NULL; + + Ref<Script> scr = p_current_node->get_script(); + + if (scr.is_valid() && scr==script) + return p_current_node; + + for(int i=0;i<p_current_node->get_child_count();i++) { + Node *n = _find_script_node(p_edited_scene,p_current_node->get_child(i),script); + if (n) + return n; + } + + return NULL; +} + +#endif + void VisualScriptEditor::drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from){ if (p_from==graph) { @@ -1430,6 +1488,165 @@ void VisualScriptEditor::drop_data_fw(const Point2& p_point,const Variant& p_dat _node_selected(node); } } + if (d.has("type") && String(d["type"])=="nodes") { + + Node* sn = _find_script_node(get_tree()->get_edited_scene_root(),get_tree()->get_edited_scene_root(),script); + + + if (!sn) { + EditorNode::get_singleton()->show_warning("Can't drop nodes because script '"+get_name()+"' is not used in this scene."); + return; + } + + Array nodes = d["nodes"]; + + Vector2 ofs = graph->get_scroll_ofs() + p_point; + + ofs/=EDSCALE; + + undo_redo->create_action(TTR("Add Node(s) From Tree")); + int base_id = script->get_available_id(); + + for(int i=0;i<nodes.size();i++) { + + NodePath np = nodes[i]; + Node *node = get_node(np); + if (!node) { + continue; + } + + Ref<VisualScriptSceneNode> scene_node; + scene_node.instance(); + scene_node->set_node_path(sn->get_path_to(node)); + undo_redo->add_do_method(script.ptr(),"add_node",edited_func,base_id,scene_node,ofs); + undo_redo->add_undo_method(script.ptr(),"remove_node",edited_func,base_id); + + base_id++; + ofs+=Vector2(25,25); + } + undo_redo->add_do_method(this,"_update_graph"); + undo_redo->add_undo_method(this,"_update_graph"); + undo_redo->commit_action(); + + + } + + if (d.has("type") && 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) { + //EditorNode::get_singleton()->show_warning("Can't drop properties because script '"+get_name()+"' is not used in this scene."); + //return; + } + + Object *obj=d["object"]; + + if (!obj) + return; + + Node *node = obj->cast_to<Node>(); + Vector2 ofs = graph->get_scroll_ofs() + p_point; + ofs/=EDSCALE; +#ifdef OSX_ENABLED + bool use_set = Input::get_singleton()->is_key_pressed(KEY_META); +#else + bool use_set = Input::get_singleton()->is_key_pressed(KEY_CONTROL); +#endif + + bool use_value = Input::get_singleton()->is_key_pressed(KEY_SHIFT); + + if (!node) { + + + if (use_set) + undo_redo->create_action(TTR("Add Setter Property")); + else + undo_redo->create_action(TTR("Add Getter Property")); + + int base_id = script->get_available_id(); + + Ref<VisualScriptNode> vnode; + + if (use_set) { + + Ref<VisualScriptPropertySet> pset; + pset.instance(); + pset->set_call_mode(VisualScriptPropertySet::CALL_MODE_INSTANCE); + pset->set_base_type(obj->get_type()); + pset->set_property(d["property"]); + if (use_value) { + pset->set_use_builtin_value(true); + pset->set_builtin_value(d["value"]); + } + vnode=pset; + } else { + + Ref<VisualScriptPropertyGet> pget; + pget.instance(); + pget->set_call_mode(VisualScriptPropertyGet::CALL_MODE_INSTANCE); + pget->set_base_type(obj->get_type()); + pget->set_property(d["property"]); + vnode=pget; + + } + + undo_redo->add_do_method(script.ptr(),"add_node",edited_func,base_id,vnode,ofs); + undo_redo->add_undo_method(script.ptr(),"remove_node",edited_func,base_id); + + undo_redo->add_do_method(this,"_update_graph"); + undo_redo->add_undo_method(this,"_update_graph"); + undo_redo->commit_action(); + + } else { + + + + if (use_set) + undo_redo->create_action(TTR("Add Setter Property")); + else + undo_redo->create_action(TTR("Add Getter Property")); + + int base_id = script->get_available_id(); + + Ref<VisualScriptNode> vnode; + + if (use_set) { + + Ref<VisualScriptPropertySet> pset; + pset.instance(); + pset->set_call_mode(VisualScriptPropertySet::CALL_MODE_NODE_PATH); + pset->set_base_path(sn->get_path_to(sn)); + pset->set_property(d["property"]); + if (use_value) { + pset->set_use_builtin_value(true); + pset->set_builtin_value(d["value"]); + } + + vnode=pset; + } else { + + Ref<VisualScriptPropertyGet> pget; + pget.instance(); + pget->set_call_mode(VisualScriptPropertyGet::CALL_MODE_NODE_PATH); + pget->set_base_path(sn->get_path_to(sn)); + pget->set_property(d["property"]); + vnode=pget; + + } + undo_redo->add_do_method(script.ptr(),"add_node",edited_func,base_id,vnode,ofs); + undo_redo->add_undo_method(script.ptr(),"remove_node",edited_func,base_id); + + undo_redo->add_do_method(this,"_update_graph"); + undo_redo->add_undo_method(this,"_update_graph"); + undo_redo->commit_action(); + } + + + } + + } @@ -1785,6 +2002,20 @@ void VisualScriptEditor::_graph_disconnected(const String& p_from,int p_from_slo } +void VisualScriptEditor::_show_hint(const String& p_hint) { + + hint_text->set_text(p_hint); + hint_text->show(); + hint_text_timer->start(); +} + +void VisualScriptEditor::_hide_timer() { + + hint_text->hide(); +} + + + void VisualScriptEditor::_bind_methods() { ObjectTypeDB::bind_method("_member_button",&VisualScriptEditor::_member_button); @@ -1812,6 +2043,7 @@ void VisualScriptEditor::_bind_methods() { ObjectTypeDB::bind_method("_on_nodes_delete",&VisualScriptEditor::_on_nodes_delete); ObjectTypeDB::bind_method("_on_nodes_duplicate",&VisualScriptEditor::_on_nodes_duplicate); + ObjectTypeDB::bind_method("_hide_timer",&VisualScriptEditor::_hide_timer); ObjectTypeDB::bind_method("_graph_connected",&VisualScriptEditor::_graph_connected); ObjectTypeDB::bind_method("_graph_disconnected",&VisualScriptEditor::_graph_disconnected); @@ -1870,8 +2102,28 @@ VisualScriptEditor::VisualScriptEditor() { graph->connect("delete_nodes_request",this,"_on_nodes_delete"); graph->connect("duplicate_nodes_request",this,"_on_nodes_duplicate"); graph->set_drag_forwarding(this); - - + graph->hide(); + + select_func_text = memnew( Label ); + select_func_text->set_text(TTR("Select or create a function to edit graph")); + select_func_text->set_align(Label::ALIGN_CENTER); + select_func_text->set_valign(Label::VALIGN_CENTER); + select_func_text->set_h_size_flags(SIZE_EXPAND_FILL); + main_hsplit->add_child(select_func_text); + + + hint_text = memnew( Label ); + hint_text->set_anchor_and_margin(MARGIN_TOP,ANCHOR_END,100); + hint_text->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_END,0); + hint_text->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,0); + hint_text->set_align(Label::ALIGN_CENTER); + hint_text->set_valign(Label::VALIGN_CENTER); + graph->add_child(hint_text); + + hint_text_timer = memnew( Timer ); + hint_text_timer->set_wait_time(4); + hint_text_timer->connect("timeout",this,"_hide_timer"); + add_child(hint_text_timer); //allowed casts (connections) for(int i=0;i<Variant::VARIANT_MAX;i++) { diff --git a/modules/visual_script/visual_script_editor.h b/modules/visual_script/visual_script_editor.h index fcb31e50cc..6194058564 100644 --- a/modules/visual_script/visual_script_editor.h +++ b/modules/visual_script/visual_script_editor.h @@ -47,6 +47,14 @@ class VisualScriptEditor : public ScriptEditorBase { Tree *members; Tree *nodes; + Label *hint_text; + Timer *hint_text_timer; + + Label *select_func_text; + + void _show_hint(const String& p_hint); + void _hide_timer(); + CreateDialog *select_base_type; struct VirtualInMenu { diff --git a/modules/visual_script/visual_script_func_nodes.cpp b/modules/visual_script/visual_script_func_nodes.cpp index 6fb2b19585..6494df7667 100644 --- a/modules/visual_script/visual_script_func_nodes.cpp +++ b/modules/visual_script/visual_script_func_nodes.cpp @@ -93,20 +93,36 @@ StringName VisualScriptFunctionCall::_get_base_type() const { int VisualScriptFunctionCall::get_input_value_port_count() const{ - MethodBind *mb = ObjectTypeDB::get_method(_get_base_type(),function); - if (!mb) - return 0; + if (call_mode==CALL_MODE_BASIC_TYPE) { - return mb->get_argument_count() + (call_mode==CALL_MODE_INSTANCE?1:0) - use_default_args; + + Vector<StringName> names = Variant::get_method_argument_names(basic_type,function); + return names.size()+1; + + } else { + MethodBind *mb = ObjectTypeDB::get_method(_get_base_type(),function); + if (!mb) + return 0; + + return mb->get_argument_count() + (call_mode==CALL_MODE_INSTANCE?1:0) - use_default_args; + } } int VisualScriptFunctionCall::get_output_value_port_count() const{ - MethodBind *mb = ObjectTypeDB::get_method(_get_base_type(),function); - if (!mb) - return 0; + if (call_mode==CALL_MODE_BASIC_TYPE) { + + bool returns=false; + Variant::get_method_return_type(basic_type,function,&returns); + return returns?1:0; + + } else { + MethodBind *mb = ObjectTypeDB::get_method(_get_base_type(),function); + if (!mb) + return 0; - return mb->has_return() ? 1 : 0; + return mb->has_return() ? 1 : 0; + } } String VisualScriptFunctionCall::get_output_sequence_port_text(int p_port) const { @@ -116,11 +132,11 @@ String VisualScriptFunctionCall::get_output_sequence_port_text(int p_port) const PropertyInfo VisualScriptFunctionCall::get_input_value_port_info(int p_idx) const{ - if (call_mode==CALL_MODE_INSTANCE) { + if (call_mode==CALL_MODE_INSTANCE || call_mode==CALL_MODE_BASIC_TYPE) { if (p_idx==0) { PropertyInfo pi; - pi.type=Variant::OBJECT; - pi.name="instance"; + 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()); return pi; } else { p_idx--; @@ -129,13 +145,21 @@ PropertyInfo VisualScriptFunctionCall::get_input_value_port_info(int p_idx) cons #ifdef DEBUG_METHODS_ENABLED + if (call_mode==CALL_MODE_BASIC_TYPE) { + + + Vector<StringName> names = Variant::get_method_argument_names(basic_type,function); + Vector<Variant::Type> types = Variant::get_method_argument_types(basic_type,function); + return PropertyInfo(types[p_idx],names[p_idx]); + } else { - MethodBind *mb = ObjectTypeDB::get_method(_get_base_type(),function); - if (!mb) - return PropertyInfo(); + MethodBind *mb = ObjectTypeDB::get_method(_get_base_type(),function); + if (!mb) + return PropertyInfo(); - return mb->get_argument_info(p_idx); + return mb->get_argument_info(p_idx); + } #else return PropertyInfo(); #endif @@ -147,13 +171,20 @@ PropertyInfo VisualScriptFunctionCall::get_output_value_port_info(int p_idx) con #ifdef DEBUG_METHODS_ENABLED - MethodBind *mb = ObjectTypeDB::get_method(_get_base_type(),function); - if (!mb) - return PropertyInfo(); + if (call_mode==CALL_MODE_BASIC_TYPE) { + - PropertyInfo pi = mb->get_argument_info(-1); - pi.name=""; - return pi; + return PropertyInfo(Variant::get_method_return_type(basic_type,function),""); + } else { + + MethodBind *mb = ObjectTypeDB::get_method(_get_base_type(),function); + if (!mb) + return PropertyInfo(); + + PropertyInfo pi = mb->get_argument_info(-1); + pi.name=""; + return pi; + } #else return PropertyInfo(); #endif @@ -162,13 +193,22 @@ PropertyInfo VisualScriptFunctionCall::get_output_value_port_info(int p_idx) con String VisualScriptFunctionCall::get_caption() const { - return "Call"; + static const char*cname[4]= { + "CallSelf", + "CallNode", + "CallInstance", + "CallBasic" + }; + + return cname[call_mode]; } String VisualScriptFunctionCall::get_text() const { if (call_mode==CALL_MODE_SELF) return " "+String(function)+"()"; + else if (call_mode==CALL_MODE_BASIC_TYPE) + return Variant::get_type_name(basic_type)+"."+String(function)+"()"; else return " "+base_type+"."+String(function)+"()"; @@ -176,15 +216,35 @@ String VisualScriptFunctionCall::get_text() const { void VisualScriptFunctionCall::_update_defargs() { - if (!get_visual_script().is_valid()) - return; //do not change if not valid yet + if (call_mode==CALL_MODE_BASIC_TYPE) { + use_default_args = Variant::get_method_default_arguments(basic_type,function).size(); + } else { + if (!get_visual_script().is_valid()) + return; //do not change if not valid yet + + MethodBind *mb = ObjectTypeDB::get_method(_get_base_type(),function); + if (!mb) + return; + + use_default_args=mb->get_default_argument_count(); + } + +} + +void VisualScriptFunctionCall::set_basic_type(Variant::Type p_type) { - MethodBind *mb = ObjectTypeDB::get_method(_get_base_type(),function); - if (!mb) + if (basic_type==p_type) return; + basic_type=p_type; + + _update_defargs(); + _change_notify(); + emit_signal("ports_changed"); +} - use_default_args=mb->get_default_argument_count(); +Variant::Type VisualScriptFunctionCall::get_basic_type() const{ + return basic_type; } void VisualScriptFunctionCall::set_base_type(const StringName& p_type) { @@ -275,6 +335,11 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo& property) const } } + if (property.name=="function/basic_type") { + if (call_mode!=CALL_MODE_BASIC_TYPE) { + property.usage=0; + } + } if (property.name=="function/node_path") { if (call_mode!=CALL_MODE_NODE_PATH) { @@ -296,9 +361,24 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo& property) const List<MethodInfo> methods; - StringName base = _get_base_type(); - ObjectTypeDB::get_method_list(base,&methods); + if (call_mode==CALL_MODE_BASIC_TYPE) { + + if (basic_type==Variant::NIL) { + property.usage=0; + return; //nothing for nil + } + Variant::CallError ce; + Variant v = Variant::construct(basic_type,NULL,0,ce); + v.get_method_list(&methods); + + + } else { + + StringName base = _get_base_type(); + ObjectTypeDB::get_method_list(base,&methods); + + } List<String> mstring; for (List<MethodInfo>::Element *E=methods.front();E;E=E->next()) { @@ -321,17 +401,28 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo& property) const } if (property.name=="function/use_default_args") { + property.hint=PROPERTY_HINT_RANGE; int mc=0; - MethodBind *mb = ObjectTypeDB::get_method(_get_base_type(),function); - if (mb) { + if (call_mode==CALL_MODE_BASIC_TYPE) { + + mc = Variant::get_method_default_arguments(basic_type,function).size(); + } else { + MethodBind *mb = ObjectTypeDB::get_method(_get_base_type(),function); + if (mb) { - mc=mb->get_default_argument_count(); + mc=mb->get_default_argument_count(); + } } - property.hint_string="0,"+itos(mc)+",1"; + if (mc==0) { + property.usage=0; //do not show + } else { + + property.hint_string="0,"+itos(mc)+",1"; + } } } @@ -341,6 +432,9 @@ void VisualScriptFunctionCall::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_base_type","base_type"),&VisualScriptFunctionCall::set_base_type); ObjectTypeDB::bind_method(_MD("get_base_type"),&VisualScriptFunctionCall::get_base_type); + ObjectTypeDB::bind_method(_MD("set_basic_type","basic_type"),&VisualScriptFunctionCall::set_basic_type); + ObjectTypeDB::bind_method(_MD("get_basic_type"),&VisualScriptFunctionCall::get_basic_type); + ObjectTypeDB::bind_method(_MD("set_function","function"),&VisualScriptFunctionCall::set_function); ObjectTypeDB::bind_method(_MD("get_function"),&VisualScriptFunctionCall::get_function); @@ -354,8 +448,17 @@ void VisualScriptFunctionCall::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_use_default_args"),&VisualScriptFunctionCall::get_use_default_args); - ADD_PROPERTY(PropertyInfo(Variant::INT,"function/call_mode",PROPERTY_HINT_ENUM,"Self,Node Path,Instance"),_SCS("set_call_mode"),_SCS("get_call_mode")); + String bt; + for(int i=0;i<Variant::VARIANT_MAX;i++) { + if (i>0) + bt+=","; + + bt+=Variant::get_type_name(Variant::Type(i)); + } + + ADD_PROPERTY(PropertyInfo(Variant::INT,"function/call_mode",PROPERTY_HINT_ENUM,"Self,Node Path,Instance,Basic Type",PROPERTY_USAGE_NOEDITOR),_SCS("set_call_mode"),_SCS("get_call_mode")); ADD_PROPERTY(PropertyInfo(Variant::STRING,"function/base_type",PROPERTY_HINT_TYPE_STRING,"Object"),_SCS("set_base_type"),_SCS("get_base_type")); + ADD_PROPERTY(PropertyInfo(Variant::INT,"function/basic_type",PROPERTY_HINT_ENUM,bt),_SCS("set_basic_type"),_SCS("get_basic_type")); ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH,"function/node_path",PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE),_SCS("set_base_path"),_SCS("get_base_path")); ADD_PROPERTY(PropertyInfo(Variant::STRING,"function/function"),_SCS("set_function"),_SCS("get_function")); ADD_PROPERTY(PropertyInfo(Variant::INT,"function/use_default_args"),_SCS("set_use_default_args"),_SCS("get_use_default_args")); @@ -363,6 +466,7 @@ void VisualScriptFunctionCall::_bind_methods() { BIND_CONSTANT( CALL_MODE_SELF ); BIND_CONSTANT( CALL_MODE_NODE_PATH); BIND_CONSTANT( CALL_MODE_INSTANCE); + BIND_CONSTANT( CALL_MODE_BASIC_TYPE ); } VisualScriptNodeInstance* VisualScriptFunctionCall::instance(VScriptInstance* p_instance) { @@ -373,6 +477,7 @@ VisualScriptNodeInstance* VisualScriptFunctionCall::instance(VScriptInstance* p_ VisualScriptFunctionCall::VisualScriptFunctionCall() { call_mode=CALL_MODE_INSTANCE; + basic_type=Variant::NIL; use_default_args=0; base_type="Object"; @@ -456,12 +561,12 @@ StringName VisualScriptPropertySet::_get_base_type() const { int VisualScriptPropertySet::get_input_value_port_count() const{ - if (use_builtin_value) - return 0; - else - return 1; + int pc = (call_mode==CALL_MODE_BASIC_TYPE || call_mode==CALL_MODE_INSTANCE)?1:0; + if (!use_builtin_value) + pc++; + return pc; } int VisualScriptPropertySet::get_output_value_port_count() const{ @@ -475,11 +580,11 @@ String VisualScriptPropertySet::get_output_sequence_port_text(int p_port) const PropertyInfo VisualScriptPropertySet::get_input_value_port_info(int p_idx) const{ - if (call_mode==CALL_MODE_INSTANCE) { + if (call_mode==CALL_MODE_INSTANCE || call_mode==CALL_MODE_BASIC_TYPE) { if (p_idx==0) { PropertyInfo pi; - pi.type=Variant::OBJECT; - pi.name="instance"; + 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()); return pi; } else { p_idx--; @@ -493,18 +598,25 @@ PropertyInfo VisualScriptPropertySet::get_input_value_port_info(int p_idx) const List<PropertyInfo> pinfo; - if (call_mode==CALL_MODE_NODE_PATH) { + if (call_mode==CALL_MODE_BASIC_TYPE) { - Node *n = _get_base_node(); - if (n) { - n->get_property_list(&pinfo); - } else { - ObjectTypeDB::get_property_list(_get_base_type(),&pinfo); - } + + Variant::CallError ce; + Variant v = Variant::construct(basic_type,NULL,0,ce); + v.get_property_list(&pinfo); + } else if (call_mode==CALL_MODE_NODE_PATH) { + + Node *n = _get_base_node(); + if (n) { + n->get_property_list(&pinfo); + } else { + ObjectTypeDB::get_property_list(_get_base_type(),&pinfo); + } } else { ObjectTypeDB::get_property_list(_get_base_type(),&pinfo); } + for (List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) { if (E->get().name==property) { @@ -531,15 +643,57 @@ PropertyInfo VisualScriptPropertySet::get_output_value_port_info(int p_idx) cons String VisualScriptPropertySet::get_caption() const { - return "Set"; + static const char*cname[4]= { + "SelfSet", + "NodeSet", + "InstanceSet", + "BasicSet" + }; + + return cname[call_mode]; } String VisualScriptPropertySet::get_text() const { - return property; + String prop; + + if (call_mode==CALL_MODE_BASIC_TYPE) + prop=Variant::get_type_name(basic_type)+"."+property; + else + prop=property; + + if (use_builtin_value) { + String bit = builtin_value.get_construct_string(); + if (bit.length()>40) { + bit=bit.substr(0,40); + bit+="..."; + } + + prop+="\n "+bit; + } + + return prop; + +} + + +void VisualScriptPropertySet::set_basic_type(Variant::Type p_type) { + + if (basic_type==p_type) + return; + basic_type=p_type; + + + _change_notify(); + emit_signal("ports_changed"); +} +Variant::Type VisualScriptPropertySet::get_basic_type() const{ + + return basic_type; } + void VisualScriptPropertySet::set_base_type(const StringName& p_type) { if (base_type==p_type) @@ -639,6 +793,12 @@ void VisualScriptPropertySet::_validate_property(PropertyInfo& property) const { } + if (property.name=="property/basic_type") { + if (call_mode!=CALL_MODE_BASIC_TYPE) { + property.usage=0; + } + } + if (property.name=="property/node_path") { if (call_mode!=CALL_MODE_NODE_PATH) { property.usage=0; @@ -659,7 +819,13 @@ void VisualScriptPropertySet::_validate_property(PropertyInfo& property) const { List<PropertyInfo> pinfo; - if (call_mode==CALL_MODE_NODE_PATH) { + + if (call_mode==CALL_MODE_BASIC_TYPE) { + Variant::CallError ce; + Variant v = Variant::construct(basic_type,NULL,0,ce); + v.get_property_list(&pinfo); + + } else if (call_mode==CALL_MODE_NODE_PATH) { Node *n = _get_base_node(); if (n) { @@ -668,15 +834,19 @@ void VisualScriptPropertySet::_validate_property(PropertyInfo& property) const { ObjectTypeDB::get_property_list(_get_base_type(),&pinfo); } } else { + + ObjectTypeDB::get_property_list(_get_base_type(),&pinfo); + } List<String> mstring; for (List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) { - if (E->get().usage&PROPERTY_USAGE_EDITOR) + if (E->get().usage&PROPERTY_USAGE_EDITOR) { mstring.push_back(E->get().name); + } } String ml; @@ -687,7 +857,11 @@ void VisualScriptPropertySet::_validate_property(PropertyInfo& property) const { ml+=E->get(); } - property.hint_string=ml; + if (ml==String()) { + property.usage=PROPERTY_USAGE_NOEDITOR; //do not show for editing if empty + } else { + property.hint_string=ml; + } } if (property.name=="value/builtin") { @@ -697,8 +871,12 @@ void VisualScriptPropertySet::_validate_property(PropertyInfo& property) const { } else { List<PropertyInfo> pinfo; + if (call_mode==CALL_MODE_BASIC_TYPE) { + Variant::CallError ce; + Variant v = Variant::construct(basic_type,NULL,0,ce); + v.get_property_list(&pinfo); - if (call_mode==CALL_MODE_NODE_PATH) { + } else if (call_mode==CALL_MODE_NODE_PATH) { Node *n = _get_base_node(); if (n) { @@ -729,6 +907,11 @@ void VisualScriptPropertySet::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_base_type","base_type"),&VisualScriptPropertySet::set_base_type); ObjectTypeDB::bind_method(_MD("get_base_type"),&VisualScriptPropertySet::get_base_type); + + ObjectTypeDB::bind_method(_MD("set_basic_type","basic_type"),&VisualScriptPropertySet::set_basic_type); + ObjectTypeDB::bind_method(_MD("get_basic_type"),&VisualScriptPropertySet::get_basic_type); + + ObjectTypeDB::bind_method(_MD("set_property","property"),&VisualScriptPropertySet::set_property); ObjectTypeDB::bind_method(_MD("get_property"),&VisualScriptPropertySet::get_property); @@ -744,8 +927,17 @@ void VisualScriptPropertySet::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_use_builtin_value","enable"),&VisualScriptPropertySet::set_use_builtin_value); ObjectTypeDB::bind_method(_MD("is_using_builtin_value"),&VisualScriptPropertySet::is_using_builtin_value); - ADD_PROPERTY(PropertyInfo(Variant::INT,"property/set_mode",PROPERTY_HINT_ENUM,"Self,Node Path,Instance"),_SCS("set_call_mode"),_SCS("get_call_mode")); + String bt; + for(int i=0;i<Variant::VARIANT_MAX;i++) { + if (i>0) + bt+=","; + + bt+=Variant::get_type_name(Variant::Type(i)); + } + + ADD_PROPERTY(PropertyInfo(Variant::INT,"property/set_mode",PROPERTY_HINT_ENUM,"Self,Node Path,Instance,Basic Type",PROPERTY_USAGE_NOEDITOR),_SCS("set_call_mode"),_SCS("get_call_mode")); ADD_PROPERTY(PropertyInfo(Variant::STRING,"property/base_type",PROPERTY_HINT_TYPE_STRING,"Object"),_SCS("set_base_type"),_SCS("get_base_type")); + ADD_PROPERTY(PropertyInfo(Variant::INT,"property/basic_type",PROPERTY_HINT_ENUM,bt),_SCS("set_basic_type"),_SCS("get_basic_type")); ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH,"property/node_path",PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE),_SCS("set_base_path"),_SCS("get_base_path")); ADD_PROPERTY(PropertyInfo(Variant::STRING,"property/property"),_SCS("set_property"),_SCS("get_property")); ADD_PROPERTY(PropertyInfo(Variant::BOOL,"value/use_builtin"),_SCS("set_use_builtin_value"),_SCS("is_using_builtin_value")); @@ -754,6 +946,7 @@ void VisualScriptPropertySet::_bind_methods() { BIND_CONSTANT( CALL_MODE_SELF ); BIND_CONSTANT( CALL_MODE_NODE_PATH); BIND_CONSTANT( CALL_MODE_INSTANCE); + } VisualScriptNodeInstance* VisualScriptPropertySet::instance(VScriptInstance* p_instance) { @@ -765,6 +958,7 @@ VisualScriptPropertySet::VisualScriptPropertySet() { call_mode=CALL_MODE_INSTANCE; base_type="Object"; + basic_type=Variant::NIL; } @@ -779,7 +973,7 @@ static Ref<VisualScriptNode> create_property_set_node(const String& p_name) { ////////////////////////////////////////// -////////////////SET////////////////////// +////////////////GET////////////////////// ////////////////////////////////////////// int VisualScriptPropertyGet::get_output_sequence_port_count() const { @@ -846,7 +1040,7 @@ StringName VisualScriptPropertyGet::_get_base_type() const { int VisualScriptPropertyGet::get_input_value_port_count() const{ - return 0; + return (call_mode==CALL_MODE_BASIC_TYPE || call_mode==CALL_MODE_INSTANCE)?1:0; } int VisualScriptPropertyGet::get_output_value_port_count() const{ @@ -861,11 +1055,11 @@ String VisualScriptPropertyGet::get_output_sequence_port_text(int p_port) const PropertyInfo VisualScriptPropertyGet::get_input_value_port_info(int p_idx) const{ - if (call_mode==CALL_MODE_INSTANCE) { + if (call_mode==CALL_MODE_INSTANCE || call_mode==CALL_MODE_BASIC_TYPE) { if (p_idx==0) { PropertyInfo pi; - pi.type=Variant::OBJECT; - pi.name="instance"; + 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()); return pi; } else { p_idx--; @@ -886,7 +1080,13 @@ PropertyInfo VisualScriptPropertyGet::get_output_value_port_info(int p_idx) cons List<PropertyInfo> pinfo; - if (call_mode==CALL_MODE_NODE_PATH) { + if (call_mode==CALL_MODE_BASIC_TYPE) { + + + Variant::CallError ce; + Variant v = Variant::construct(basic_type,NULL,0,ce); + v.get_property_list(&pinfo); + } else if (call_mode==CALL_MODE_NODE_PATH) { Node *n = _get_base_node(); if (n) { @@ -917,12 +1117,23 @@ PropertyInfo VisualScriptPropertyGet::get_output_value_port_info(int p_idx) cons String VisualScriptPropertyGet::get_caption() const { - return "Get"; + static const char*cname[4]= { + "SelfGet", + "NodeGet", + "InstanceGet", + "BasicGet" + }; + + return cname[call_mode]; } String VisualScriptPropertyGet::get_text() const { - return property; + + if (call_mode==CALL_MODE_BASIC_TYPE) + return Variant::get_type_name(basic_type)+"."+property; + else + return property; } @@ -987,6 +1198,25 @@ VisualScriptPropertyGet::CallMode VisualScriptPropertyGet::get_call_mode() const return call_mode; } + + +void VisualScriptPropertyGet::set_basic_type(Variant::Type p_type) { + + if (basic_type==p_type) + return; + basic_type=p_type; + + + _change_notify(); + emit_signal("ports_changed"); +} + +Variant::Type VisualScriptPropertyGet::get_basic_type() const{ + + return basic_type; +} + + void VisualScriptPropertyGet::_validate_property(PropertyInfo& property) const { if (property.name=="property/base_type") { @@ -996,6 +1226,12 @@ void VisualScriptPropertyGet::_validate_property(PropertyInfo& property) const { } + if (property.name=="property/basic_type") { + if (call_mode!=CALL_MODE_BASIC_TYPE) { + property.usage=0; + } + } + if (property.name=="property/node_path") { if (call_mode!=CALL_MODE_NODE_PATH) { property.usage=0; @@ -1016,7 +1252,12 @@ void VisualScriptPropertyGet::_validate_property(PropertyInfo& property) const { List<PropertyInfo> pinfo; - if (call_mode==CALL_MODE_NODE_PATH) { + if (call_mode==CALL_MODE_BASIC_TYPE) { + Variant::CallError ce; + Variant v = Variant::construct(basic_type,NULL,0,ce); + v.get_property_list(&pinfo); + + } else if (call_mode==CALL_MODE_NODE_PATH) { Node *n = _get_base_node(); if (n) { @@ -1044,7 +1285,12 @@ void VisualScriptPropertyGet::_validate_property(PropertyInfo& property) const { ml+=E->get(); } - property.hint_string=ml; + if (ml==String()) { + property.usage=PROPERTY_USAGE_NOEDITOR; //do not show for editing if empty + } else { + property.hint_string=ml; + } + } } @@ -1054,6 +1300,11 @@ void VisualScriptPropertyGet::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_base_type","base_type"),&VisualScriptPropertyGet::set_base_type); ObjectTypeDB::bind_method(_MD("get_base_type"),&VisualScriptPropertyGet::get_base_type); + + ObjectTypeDB::bind_method(_MD("set_basic_type","basic_type"),&VisualScriptPropertyGet::set_basic_type); + ObjectTypeDB::bind_method(_MD("get_basic_type"),&VisualScriptPropertyGet::get_basic_type); + + ObjectTypeDB::bind_method(_MD("set_property","property"),&VisualScriptPropertyGet::set_property); ObjectTypeDB::bind_method(_MD("get_property"),&VisualScriptPropertyGet::get_property); @@ -1063,10 +1314,18 @@ void VisualScriptPropertyGet::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_base_path","base_path"),&VisualScriptPropertyGet::set_base_path); ObjectTypeDB::bind_method(_MD("get_base_path"),&VisualScriptPropertyGet::get_base_path); + String bt; + for(int i=0;i<Variant::VARIANT_MAX;i++) { + if (i>0) + bt+=","; + + bt+=Variant::get_type_name(Variant::Type(i)); + } - ADD_PROPERTY(PropertyInfo(Variant::INT,"property/set_mode",PROPERTY_HINT_ENUM,"Self,Node Path,Instance"),_SCS("set_call_mode"),_SCS("get_call_mode")); + ADD_PROPERTY(PropertyInfo(Variant::INT,"property/set_mode",PROPERTY_HINT_ENUM,"Self,Node Path,Instance",PROPERTY_USAGE_NOEDITOR),_SCS("set_call_mode"),_SCS("get_call_mode")); ADD_PROPERTY(PropertyInfo(Variant::STRING,"property/base_type",PROPERTY_HINT_TYPE_STRING,"Object"),_SCS("set_base_type"),_SCS("get_base_type")); + ADD_PROPERTY(PropertyInfo(Variant::INT,"property/basic_type",PROPERTY_HINT_ENUM,bt),_SCS("set_basic_type"),_SCS("get_basic_type")); ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH,"property/node_path",PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE),_SCS("set_base_path"),_SCS("get_base_path")); ADD_PROPERTY(PropertyInfo(Variant::STRING,"property/property"),_SCS("set_property"),_SCS("get_property")); @@ -1084,6 +1343,7 @@ VisualScriptPropertyGet::VisualScriptPropertyGet() { call_mode=CALL_MODE_INSTANCE; base_type="Object"; + basic_type=Variant::NIL; } @@ -1564,17 +1824,20 @@ VisualScriptEmitSignal::VisualScriptEmitSignal() { void register_visual_script_func_nodes() { - VisualScriptLanguage::singleton->add_register_func("functions/call_method/call",create_function_call_node<VisualScriptFunctionCall::CALL_MODE_INSTANCE>); - VisualScriptLanguage::singleton->add_register_func("functions/call_method/call_in_self",create_function_call_node<VisualScriptFunctionCall::CALL_MODE_SELF>); - VisualScriptLanguage::singleton->add_register_func("functions/call_method/call_in_node",create_function_call_node<VisualScriptFunctionCall::CALL_MODE_NODE_PATH>); + VisualScriptLanguage::singleton->add_register_func("functions/call_method/instance_call",create_function_call_node<VisualScriptFunctionCall::CALL_MODE_INSTANCE>); + VisualScriptLanguage::singleton->add_register_func("functions/call_method/basic_type_call",create_function_call_node<VisualScriptFunctionCall::CALL_MODE_BASIC_TYPE>); + VisualScriptLanguage::singleton->add_register_func("functions/call_method/self_call",create_function_call_node<VisualScriptFunctionCall::CALL_MODE_SELF>); + VisualScriptLanguage::singleton->add_register_func("functions/call_method/node_call",create_function_call_node<VisualScriptFunctionCall::CALL_MODE_NODE_PATH>); - VisualScriptLanguage::singleton->add_register_func("functions/set_property/set",create_property_set_node<VisualScriptPropertySet::CALL_MODE_INSTANCE>); - VisualScriptLanguage::singleton->add_register_func("functions/set_property/set_in_self",create_property_set_node<VisualScriptPropertySet::CALL_MODE_SELF>); - VisualScriptLanguage::singleton->add_register_func("functions/set_property/set_in_node",create_property_set_node<VisualScriptPropertySet::CALL_MODE_NODE_PATH>); + VisualScriptLanguage::singleton->add_register_func("functions/set_property/instace_set",create_property_set_node<VisualScriptPropertySet::CALL_MODE_INSTANCE>); + VisualScriptLanguage::singleton->add_register_func("functions/set_property/basic_type_set",create_property_set_node<VisualScriptPropertySet::CALL_MODE_BASIC_TYPE>); + VisualScriptLanguage::singleton->add_register_func("functions/set_property/self_set",create_property_set_node<VisualScriptPropertySet::CALL_MODE_SELF>); + VisualScriptLanguage::singleton->add_register_func("functions/set_property/node_set",create_property_set_node<VisualScriptPropertySet::CALL_MODE_NODE_PATH>); - VisualScriptLanguage::singleton->add_register_func("functions/get_property/get",create_property_get_node<VisualScriptPropertyGet::CALL_MODE_INSTANCE>); - VisualScriptLanguage::singleton->add_register_func("functions/get_property/get_from_self",create_property_get_node<VisualScriptPropertyGet::CALL_MODE_SELF>); - VisualScriptLanguage::singleton->add_register_func("functions/get_property/get_from_node",create_property_get_node<VisualScriptPropertyGet::CALL_MODE_NODE_PATH>); + VisualScriptLanguage::singleton->add_register_func("functions/get_property/instance_get",create_property_get_node<VisualScriptPropertyGet::CALL_MODE_INSTANCE>); + VisualScriptLanguage::singleton->add_register_func("functions/get_property/basic_type_get",create_property_get_node<VisualScriptPropertyGet::CALL_MODE_BASIC_TYPE>); + VisualScriptLanguage::singleton->add_register_func("functions/get_property/self_get",create_property_get_node<VisualScriptPropertyGet::CALL_MODE_SELF>); + VisualScriptLanguage::singleton->add_register_func("functions/get_property/node_get",create_property_get_node<VisualScriptPropertyGet::CALL_MODE_NODE_PATH>); VisualScriptLanguage::singleton->add_register_func("functions/script/script_call",create_script_call_node<VisualScriptScriptCall::CALL_MODE_SELF>); VisualScriptLanguage::singleton->add_register_func("functions/script/script_call_in_node",create_script_call_node<VisualScriptScriptCall::CALL_MODE_NODE_PATH>); diff --git a/modules/visual_script/visual_script_func_nodes.h b/modules/visual_script/visual_script_func_nodes.h index d1201541b3..3d8f953a27 100644 --- a/modules/visual_script/visual_script_func_nodes.h +++ b/modules/visual_script/visual_script_func_nodes.h @@ -12,11 +12,13 @@ public: CALL_MODE_SELF, CALL_MODE_NODE_PATH, CALL_MODE_INSTANCE, + CALL_MODE_BASIC_TYPE, }; private: CallMode call_mode; StringName base_type; + Variant::Type basic_type; NodePath base_path; StringName function; int use_default_args; @@ -49,6 +51,9 @@ public: virtual String get_caption() const; virtual String get_text() const; + void set_basic_type(Variant::Type p_type); + Variant::Type get_basic_type() const; + void set_base_type(const StringName& p_type); StringName get_base_type() const; @@ -80,10 +85,14 @@ public: CALL_MODE_SELF, CALL_MODE_NODE_PATH, CALL_MODE_INSTANCE, + CALL_MODE_BASIC_TYPE, + + }; private: CallMode call_mode; + Variant::Type basic_type; StringName base_type; NodePath base_path; StringName property; @@ -121,6 +130,9 @@ public: void set_base_type(const StringName& p_type); StringName get_base_type() const; + void set_basic_type(Variant::Type p_type); + Variant::Type get_basic_type() const; + void set_property(const StringName& p_type); StringName get_property() const; @@ -152,10 +164,13 @@ public: CALL_MODE_SELF, CALL_MODE_NODE_PATH, CALL_MODE_INSTANCE, + CALL_MODE_BASIC_TYPE + }; private: CallMode call_mode; + Variant::Type basic_type; StringName base_type; NodePath base_path; StringName property; @@ -192,6 +207,9 @@ public: void set_base_type(const StringName& p_type); StringName get_base_type() const; + void set_basic_type(Variant::Type p_type); + Variant::Type get_basic_type() const; + void set_property(const StringName& p_type); StringName get_property() const; diff --git a/modules/visual_script/visual_script_nodes.cpp b/modules/visual_script/visual_script_nodes.cpp index f8d883c491..f29b6e34a7 100644 --- a/modules/visual_script/visual_script_nodes.cpp +++ b/modules/visual_script/visual_script_nodes.cpp @@ -863,7 +863,7 @@ PropertyInfo VisualScriptGlobalConstant::get_input_value_port_info(int p_idx) co PropertyInfo VisualScriptGlobalConstant::get_output_value_port_info(int p_idx) const{ - return PropertyInfo(Variant::INT,"value"); + return PropertyInfo(Variant::REAL,"value"); } @@ -1021,52 +1021,52 @@ VisualScriptMathConstant::VisualScriptMathConstant() { ////////////////GLOBALSINGLETON/////////// ////////////////////////////////////////// -int VisualScriptSingleton::get_output_sequence_port_count() const { +int VisualScriptEngineSingleton::get_output_sequence_port_count() const { return 0; } -bool VisualScriptSingleton::has_input_sequence_port() const{ +bool VisualScriptEngineSingleton::has_input_sequence_port() const{ return false; } -int VisualScriptSingleton::get_input_value_port_count() const{ +int VisualScriptEngineSingleton::get_input_value_port_count() const{ return 0; } -int VisualScriptSingleton::get_output_value_port_count() const{ +int VisualScriptEngineSingleton::get_output_value_port_count() const{ return 1; } -String VisualScriptSingleton::get_output_sequence_port_text(int p_port) const { +String VisualScriptEngineSingleton::get_output_sequence_port_text(int p_port) const { return String(); } -PropertyInfo VisualScriptSingleton::get_input_value_port_info(int p_idx) const{ +PropertyInfo VisualScriptEngineSingleton::get_input_value_port_info(int p_idx) const{ return PropertyInfo(); } -PropertyInfo VisualScriptSingleton::get_output_value_port_info(int p_idx) const{ +PropertyInfo VisualScriptEngineSingleton::get_output_value_port_info(int p_idx) const{ return PropertyInfo(Variant::OBJECT,"instance"); } -String VisualScriptSingleton::get_caption() const { +String VisualScriptEngineSingleton::get_caption() const { - return "Singleton"; + return "EngineSingleton"; } -String VisualScriptSingleton::get_text() const { +String VisualScriptEngineSingleton::get_text() const { return singleton; } -void VisualScriptSingleton::set_singleton(const String& p_string) { +void VisualScriptEngineSingleton::set_singleton(const String& p_string) { singleton=p_string; @@ -1074,21 +1074,21 @@ void VisualScriptSingleton::set_singleton(const String& p_string) { emit_signal("ports_changed"); } -String VisualScriptSingleton::get_singleton() { +String VisualScriptEngineSingleton::get_singleton() { return singleton; } -VisualScriptNodeInstance* VisualScriptSingleton::instance(VScriptInstance* p_instance) { +VisualScriptNodeInstance* VisualScriptEngineSingleton::instance(VScriptInstance* p_instance) { return NULL; } -void VisualScriptSingleton::_bind_methods() { +void VisualScriptEngineSingleton::_bind_methods() { - ObjectTypeDB::bind_method(_MD("set_singleton","name"),&VisualScriptSingleton::set_singleton); - ObjectTypeDB::bind_method(_MD("get_singleton"),&VisualScriptSingleton::get_singleton); + ObjectTypeDB::bind_method(_MD("set_singleton","name"),&VisualScriptEngineSingleton::set_singleton); + ObjectTypeDB::bind_method(_MD("get_singleton"),&VisualScriptEngineSingleton::get_singleton); String cc; @@ -1108,7 +1108,7 @@ void VisualScriptSingleton::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::STRING,"constant",PROPERTY_HINT_ENUM,cc),_SCS("set_singleton"),_SCS("get_singleton")); } -VisualScriptSingleton::VisualScriptSingleton() { +VisualScriptEngineSingleton::VisualScriptEngineSingleton() { singleton=String(); } @@ -1252,14 +1252,168 @@ VisualScriptSceneNode::VisualScriptSceneNode() { } +////////////////////////////////////////// +////////////////SceneTree/////////// +////////////////////////////////////////// + +int VisualScriptSceneTree::get_output_sequence_port_count() const { + + return 0; +} + +bool VisualScriptSceneTree::has_input_sequence_port() const{ + + return false; +} + +int VisualScriptSceneTree::get_input_value_port_count() const{ + + return 0; +} +int VisualScriptSceneTree::get_output_value_port_count() const{ + + return 1; +} + +String VisualScriptSceneTree::get_output_sequence_port_text(int p_port) const { + + return String(); +} + +PropertyInfo VisualScriptSceneTree::get_input_value_port_info(int p_idx) const{ + + return PropertyInfo(); +} + +PropertyInfo VisualScriptSceneTree::get_output_value_port_info(int p_idx) const{ + + return PropertyInfo(Variant::OBJECT,"instance"); +} + + +String VisualScriptSceneTree::get_caption() const { + + return "SceneTree"; +} + +String VisualScriptSceneTree::get_text() const { + + return ""; +} + + + +VisualScriptNodeInstance* VisualScriptSceneTree::instance(VScriptInstance* p_instance) { + + return NULL; +} + +void VisualScriptSceneTree::_validate_property(PropertyInfo& property) const { + +} + +void VisualScriptSceneTree::_bind_methods() { + +} + +VisualScriptSceneTree::VisualScriptSceneTree() { + +} + + +////////////////////////////////////////// +////////////////RESPATH/////////// +////////////////////////////////////////// + +int VisualScriptResourcePath::get_output_sequence_port_count() const { + + return 0; +} + +bool VisualScriptResourcePath::has_input_sequence_port() const{ + + return false; +} + +int VisualScriptResourcePath::get_input_value_port_count() const{ + + return 0; +} +int VisualScriptResourcePath::get_output_value_port_count() const{ + + return 1; +} + +String VisualScriptResourcePath::get_output_sequence_port_text(int p_port) const { + + return String(); +} + +PropertyInfo VisualScriptResourcePath::get_input_value_port_info(int p_idx) const{ + + return PropertyInfo(); +} + +PropertyInfo VisualScriptResourcePath::get_output_value_port_info(int p_idx) const{ + + return PropertyInfo(Variant::STRING,"path"); +} + + +String VisualScriptResourcePath::get_caption() const { + + return "ResourcePath"; +} + +String VisualScriptResourcePath::get_text() const { + + return path; +} + +void VisualScriptResourcePath::set_resource_path(const String& p_path) { + + path=p_path; + _change_notify(); + emit_signal("ports_changed"); +} + +String VisualScriptResourcePath::get_resource_path() { + return path; +} + + + +VisualScriptNodeInstance* VisualScriptResourcePath::instance(VScriptInstance* p_instance) { + + return NULL; +} + + + +void VisualScriptResourcePath::_bind_methods() { + + ObjectTypeDB::bind_method(_MD("set_resource_path","path"),&VisualScriptResourcePath::set_resource_path); + ObjectTypeDB::bind_method(_MD("get_resource_path"),&VisualScriptResourcePath::get_resource_path); + + ADD_PROPERTY(PropertyInfo(Variant::STRING,"path",PROPERTY_HINT_FILE),_SCS("set_resource_path"),_SCS("get_resource_path")); +} + +VisualScriptResourcePath::VisualScriptResourcePath() { + + path=""; +} + + void register_visual_script_nodes() { VisualScriptLanguage::singleton->add_register_func("data/variable",create_node_generic<VisualScriptVariable>); VisualScriptLanguage::singleton->add_register_func("data/constant",create_node_generic<VisualScriptConstant>); VisualScriptLanguage::singleton->add_register_func("data/global_constant",create_node_generic<VisualScriptGlobalConstant>); VisualScriptLanguage::singleton->add_register_func("data/math_constant",create_node_generic<VisualScriptMathConstant>); - VisualScriptLanguage::singleton->add_register_func("data/singleton",create_node_generic<VisualScriptSingleton>); + VisualScriptLanguage::singleton->add_register_func("data/engine_singleton",create_node_generic<VisualScriptEngineSingleton>); VisualScriptLanguage::singleton->add_register_func("data/scene_node",create_node_generic<VisualScriptSceneNode>); + VisualScriptLanguage::singleton->add_register_func("data/scene_tree",create_node_generic<VisualScriptSceneTree>); + VisualScriptLanguage::singleton->add_register_func("data/resource_path",create_node_generic<VisualScriptResourcePath>); VisualScriptLanguage::singleton->add_register_func("index/get",create_node_generic<VisualScriptIndexGet>); diff --git a/modules/visual_script/visual_script_nodes.h b/modules/visual_script/visual_script_nodes.h index e10f9a7331..6080050d78 100644 --- a/modules/visual_script/visual_script_nodes.h +++ b/modules/visual_script/visual_script_nodes.h @@ -315,9 +315,9 @@ public: VARIANT_ENUM_CAST( VisualScriptMathConstant::MathConstant ) -class VisualScriptSingleton : public VisualScriptNode { +class VisualScriptEngineSingleton : public VisualScriptNode { - OBJ_TYPE(VisualScriptSingleton,VisualScriptNode) + OBJ_TYPE(VisualScriptEngineSingleton,VisualScriptNode) String singleton; @@ -346,7 +346,7 @@ public: virtual VisualScriptNodeInstance* instance(VScriptInstance* p_instance); - VisualScriptSingleton(); + VisualScriptEngineSingleton(); }; @@ -389,6 +389,77 @@ public: + +class VisualScriptSceneTree : public VisualScriptNode { + + OBJ_TYPE(VisualScriptSceneTree,VisualScriptNode) + + +protected: + virtual void _validate_property(PropertyInfo& property) const; + static void _bind_methods(); +public: + + virtual int get_output_sequence_port_count() const; + virtual bool has_input_sequence_port() const; + + + virtual String get_output_sequence_port_text(int p_port) const; + + + virtual int get_input_value_port_count() const; + virtual int get_output_value_port_count() const; + + + virtual PropertyInfo get_input_value_port_info(int p_idx) const; + virtual PropertyInfo get_output_value_port_info(int p_idx) const; + + virtual String get_caption() const; + virtual String get_text() const; + + virtual VisualScriptNodeInstance* instance(VScriptInstance* p_instance); + + VisualScriptSceneTree(); +}; + + + +class VisualScriptResourcePath : public VisualScriptNode { + + OBJ_TYPE(VisualScriptResourcePath,VisualScriptNode) + + String path; +protected: + + static void _bind_methods(); +public: + + virtual int get_output_sequence_port_count() const; + virtual bool has_input_sequence_port() const; + + + virtual String get_output_sequence_port_text(int p_port) const; + + + virtual int get_input_value_port_count() const; + virtual int get_output_value_port_count() const; + + + virtual PropertyInfo get_input_value_port_info(int p_idx) const; + virtual PropertyInfo get_output_value_port_info(int p_idx) const; + + virtual String get_caption() const; + virtual String get_text() const; + + void set_resource_path(const String &p_path); + String get_resource_path(); + + virtual VisualScriptNodeInstance* instance(VScriptInstance* p_instance); + + VisualScriptResourcePath(); +}; + + void register_visual_script_nodes(); #endif // VISUAL_SCRIPT_NODES_H |