diff options
author | Juan Linietsky <reduzio@gmail.com> | 2016-08-31 17:58:51 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2016-08-31 17:58:51 -0300 |
commit | fc70824f7c6ab1944d54194f54b816e55671e177 (patch) | |
tree | bfb5645fa22c724d9f2f8724c809f6319ca51579 /modules | |
parent | 5567350e1bf28ca9468b8321378f19e67ee03909 (diff) |
More improvements to visual script..
fixed a bug of not saving when sub-nodes changed.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/visual_script/register_types.cpp | 3 | ||||
-rw-r--r-- | modules/visual_script/visual_script.cpp | 20 | ||||
-rw-r--r-- | modules/visual_script/visual_script.h | 1 | ||||
-rw-r--r-- | modules/visual_script/visual_script_editor.cpp | 44 | ||||
-rw-r--r-- | modules/visual_script/visual_script_editor.h | 7 | ||||
-rw-r--r-- | modules/visual_script/visual_script_flow_control.cpp | 15 | ||||
-rw-r--r-- | modules/visual_script/visual_script_func_nodes.cpp | 25 | ||||
-rw-r--r-- | modules/visual_script/visual_script_func_nodes.h | 4 | ||||
-rw-r--r-- | modules/visual_script/visual_script_nodes.cpp | 1 |
9 files changed, 96 insertions, 24 deletions
diff --git a/modules/visual_script/register_types.cpp b/modules/visual_script/register_types.cpp index b55ebf2ffc..58afeef3e3 100644 --- a/modules/visual_script/register_types.cpp +++ b/modules/visual_script/register_types.cpp @@ -117,6 +117,9 @@ void unregister_visual_script_types() { ScriptServer::unregister_language(visual_script_language); +#ifdef TOOLS_ENABLED + VisualScriptEditor::free_clipboard(); +#endif if (visual_script_language) memdelete( visual_script_language ); diff --git a/modules/visual_script/visual_script.cpp b/modules/visual_script/visual_script.cpp index 312abdf39b..aa09e7f005 100644 --- a/modules/visual_script/visual_script.cpp +++ b/modules/visual_script/visual_script.cpp @@ -907,6 +907,9 @@ void VisualScript::_update_placeholders() { for (Map<StringName,Variable>::Element *E=variables.front();E;E=E->next()) { + if (!E->get()._export) + continue; + PropertyInfo p = E->get().info; p.name=SCRIPT_VARIABLES_PREFIX+String(E->key()); pinfo.push_back(p); @@ -940,6 +943,9 @@ ScriptInstance* VisualScript::instance_create(Object *p_this) { for (Map<StringName,Variable>::Element *E=variables.front();E;E=E->next()) { + if (!E->get()._export) + continue; + PropertyInfo p = E->get().info; p.name=SCRIPT_VARIABLES_PREFIX+String(E->key()); pinfo.push_back(p); @@ -1110,6 +1116,20 @@ void VisualScript::get_script_property_list(List<PropertyInfo> *p_list) const { } } +bool VisualScript::are_subnodes_edited() const { + + for(const Map<StringName,Function>::Element *E=functions.front();E;E=E->next()) { + + for (const Map<int,Function::NodeData>::Element *F=E->get().nodes.front();F;F=F->next()) { + if (F->get().node->is_edited()) { + return true; + } + } + } + + return false; +} + void VisualScript::_set_data(const Dictionary& p_data) { diff --git a/modules/visual_script/visual_script.h b/modules/visual_script/visual_script.h index 8f541a367b..9e96967c6f 100644 --- a/modules/visual_script/visual_script.h +++ b/modules/visual_script/visual_script.h @@ -342,6 +342,7 @@ public: virtual void get_script_property_list(List<PropertyInfo> *p_list) const; + virtual bool are_subnodes_edited() const; VisualScript(); ~VisualScript(); diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index 01e26a6628..7f09a265fb 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -2127,7 +2127,8 @@ Ref<Texture> VisualScriptEditor::get_icon(){ bool VisualScriptEditor::is_unsaved(){ #ifdef TOOLS_ENABLED - return script->is_edited(); + + return script->is_edited() || script->are_subnodes_edited(); #else return false; #endif @@ -2722,9 +2723,9 @@ void VisualScriptEditor::_menu_option(int p_what) { if (!script->has_function(edited_func)) break; - clipboard.nodes.clear(); - clipboard.data_connections.clear(); - clipboard.sequence_connections.clear(); + clipboard->nodes.clear(); + clipboard->data_connections.clear(); + clipboard->sequence_connections.clear(); for(int i=0;i<graph->get_child_count();i++) { GraphNode *gn = graph->get_child(i)->cast_to<GraphNode>(); @@ -2738,15 +2739,15 @@ void VisualScriptEditor::_menu_option(int p_what) { return; } if (node.is_valid()) { - clipboard.nodes[id]=node->duplicate(); - clipboard.nodes_positions[id]=script->get_node_pos(edited_func,id); + clipboard->nodes[id]=node->duplicate(); + clipboard->nodes_positions[id]=script->get_node_pos(edited_func,id); } } } } - if (clipboard.nodes.empty()) + if (clipboard->nodes.empty()) break; List<VisualScript::SequenceConnection> sequence_connections; @@ -2755,9 +2756,9 @@ void VisualScriptEditor::_menu_option(int p_what) { 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)) { + if (clipboard->nodes.has(E->get().from_node) && clipboard->nodes.has(E->get().to_node)) { - clipboard.sequence_connections.insert(E->get()); + clipboard->sequence_connections.insert(E->get()); } } @@ -2767,9 +2768,9 @@ void VisualScriptEditor::_menu_option(int p_what) { 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)) { + if (clipboard->nodes.has(E->get().from_node) && clipboard->nodes.has(E->get().to_node)) { - clipboard.data_connections.insert(E->get()); + clipboard->data_connections.insert(E->get()); } } @@ -2783,7 +2784,7 @@ void VisualScriptEditor::_menu_option(int p_what) { if (!script->has_function(edited_func)) break; - if (clipboard.nodes.empty()) { + if (clipboard->nodes.empty()) { EditorNode::get_singleton()->show_warning("Clipboard is empty!"); break; } @@ -2806,7 +2807,7 @@ void VisualScriptEditor::_menu_option(int p_what) { } } - for (Map<int,Ref<VisualScriptNode> >::Element *E=clipboard.nodes.front();E;E=E->next()) { + for (Map<int,Ref<VisualScriptNode> >::Element *E=clipboard->nodes.front();E;E=E->next()) { Ref<VisualScriptNode> node = E->get()->duplicate(); @@ -2816,7 +2817,7 @@ void VisualScriptEditor::_menu_option(int p_what) { remap[E->key()]=new_id; - Vector2 paste_pos = clipboard.nodes_positions[E->key()]; + Vector2 paste_pos = clipboard->nodes_positions[E->key()]; while(existing_positions.has(paste_pos.snapped(Vector2(2,2)))) { paste_pos+=Vector2(20,20)*EDSCALE; @@ -2828,7 +2829,7 @@ void VisualScriptEditor::_menu_option(int p_what) { } - for (Set<VisualScript::SequenceConnection>::Element *E=clipboard.sequence_connections.front();E;E=E->next()) { + for (Set<VisualScript::SequenceConnection>::Element *E=clipboard->sequence_connections.front();E;E=E->next()) { undo_redo->add_do_method(script.ptr(),"sequence_connect",edited_func,remap[E->get().from_node],E->get().from_output,remap[E->get().to_node]); @@ -2836,7 +2837,7 @@ void VisualScriptEditor::_menu_option(int p_what) { } - for (Set<VisualScript::DataConnection>::Element *E=clipboard.data_connections.front();E;E=E->next()) { + for (Set<VisualScript::DataConnection>::Element *E=clipboard->data_connections.front();E;E=E->next()) { undo_redo->add_do_method(script.ptr(),"data_connect",edited_func,remap[E->get().from_node],E->get().from_port,remap[E->get().to_node],E->get().to_port); @@ -2921,6 +2922,9 @@ void VisualScriptEditor::_bind_methods() { VisualScriptEditor::VisualScriptEditor() { + if (!clipboard) { + clipboard = memnew( Clipboard ); + } updating_graph=false; edit_menu = memnew( MenuButton ); @@ -3107,6 +3111,14 @@ static ScriptEditorBase * create_editor(const Ref<Script>& p_script) { return NULL; } + +VisualScriptEditor::Clipboard *VisualScriptEditor::clipboard=NULL; + +void VisualScriptEditor::free_clipboard() { + if (clipboard) + memdelete(clipboard); +} + static void register_editor_callback() { ScriptEditor::register_create_script_editor_function(create_editor); diff --git a/modules/visual_script/visual_script_editor.h b/modules/visual_script/visual_script_editor.h index 735eaae446..5a40822bfe 100644 --- a/modules/visual_script/visual_script_editor.h +++ b/modules/visual_script/visual_script_editor.h @@ -13,6 +13,7 @@ class VisualScriptEditorVariableEdit; #ifdef TOOLS_ENABLED + class VisualScriptEditor : public ScriptEditorBase { OBJ_TYPE(VisualScriptEditor,ScriptEditorBase) @@ -109,7 +110,9 @@ class VisualScriptEditor : public ScriptEditorBase { Set<VisualScript::SequenceConnection> sequence_connections; Set<VisualScript::DataConnection> data_connections; - } clipboard; + }; + + static Clipboard *clipboard; int error_line; @@ -203,6 +206,8 @@ public: static void register_editor(); + static void free_clipboard(); + VisualScriptEditor(); ~VisualScriptEditor(); }; diff --git a/modules/visual_script/visual_script_flow_control.cpp b/modules/visual_script/visual_script_flow_control.cpp index 42cf4aab49..5066a4214d 100644 --- a/modules/visual_script/visual_script_flow_control.cpp +++ b/modules/visual_script/visual_script_flow_control.cpp @@ -605,7 +605,7 @@ VisualScriptSequence::VisualScriptSequence() { int VisualScriptSwitch::get_output_sequence_port_count() const { - return case_values.size(); + return case_values.size()+1; } bool VisualScriptSwitch::has_input_sequence_port() const{ @@ -625,6 +625,9 @@ int VisualScriptSwitch::get_output_value_port_count() const{ String VisualScriptSwitch::get_output_sequence_port_text(int p_port) const { + if (p_port==case_values.size()) + return "done"; + if (case_values[p_port].value.get_type()==Variant::NIL) return "null"; return case_values[p_port].value; @@ -664,20 +667,18 @@ public: virtual int step(const Variant** p_inputs,Variant** p_outputs,StartMode p_start_mode,Variant* p_working_mem,Variant::CallError& r_error,String& r_error_str) { - if (p_inputs[0]->get_type()!=Variant::INPUT_EVENT) { - r_error_str="Input value not of type event"; - r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD; - return 0; + if (p_start_mode==START_MODE_CONTINUE_SEQUENCE) { + return case_values.size(); //exit } for(int i=0;i<case_values.size();i++) { if (*p_inputs[0]==case_values[i]) { - return i; + return i|STEP_FLAG_PUSH_STACK_BIT; } } - return STEP_NO_ADVANCE_BIT; + return case_values.size(); } diff --git a/modules/visual_script/visual_script_func_nodes.cpp b/modules/visual_script/visual_script_func_nodes.cpp index a81f323729..79910aa2bd 100644 --- a/modules/visual_script/visual_script_func_nodes.cpp +++ b/modules/visual_script/visual_script_func_nodes.cpp @@ -513,6 +513,15 @@ int VisualScriptFunctionCall::get_use_default_args() const{ } +void VisualScriptFunctionCall::set_validate(bool p_amount) { + + validate=p_amount; +} + +bool VisualScriptFunctionCall::get_validate() const { + + return validate; +} void VisualScriptFunctionCall::_set_argument_cache(const Dictionary& p_cache) { @@ -700,6 +709,9 @@ void VisualScriptFunctionCall::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_rpc_call_mode","mode"),&VisualScriptFunctionCall::set_rpc_call_mode); ObjectTypeDB::bind_method(_MD("get_rpc_call_mode"),&VisualScriptFunctionCall::get_rpc_call_mode); + ObjectTypeDB::bind_method(_MD("set_validate","enable"),&VisualScriptFunctionCall::set_validate); + ObjectTypeDB::bind_method(_MD("get_validate"),&VisualScriptFunctionCall::get_validate); + String bt; for(int i=0;i<Variant::VARIANT_MAX;i++) { if (i>0) @@ -732,6 +744,7 @@ void VisualScriptFunctionCall::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY,"function/argument_cache",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("_set_argument_cache"),_SCS("_get_argument_cache")); ADD_PROPERTY(PropertyInfo(Variant::STRING,"function/function"),_SCS("set_function"),_SCS("get_function")); //when set, if loaded properly, will override argument count. ADD_PROPERTY(PropertyInfo(Variant::INT,"function/use_default_args"),_SCS("set_use_default_args"),_SCS("get_use_default_args")); + ADD_PROPERTY(PropertyInfo(Variant::BOOL,"function/validate"),_SCS("set_validate"),_SCS("get_validate")); ADD_PROPERTY(PropertyInfo(Variant::INT,"rpc/call_mode",PROPERTY_HINT_ENUM,"Disabled,Reliable,Unreliable,ReliableToID,UnreliableToID"),_SCS("set_rpc_call_mode"),_SCS("get_rpc_call_mode")); //when set, if loaded properly, will override argument count. BIND_CONSTANT( CALL_MODE_SELF ); @@ -747,6 +760,7 @@ public: VisualScriptFunctionCall::CallMode call_mode; NodePath node_path; int input_args; + bool validate; bool returns; VisualScriptFunctionCall::RPCCallMode rpc_mode; StringName function; @@ -874,7 +888,16 @@ public: object->call(function,p_inputs,input_args,r_error); } } break; + } + + if (!validate) { + + //ignore call errors if validation is disabled + r_error.error=Variant::CallError::CALL_OK; + r_error_str=String(); + } + return 0; } @@ -894,10 +917,12 @@ VisualScriptNodeInstance* VisualScriptFunctionCall::instance(VisualScriptInstanc instance->node_path=base_path; instance->input_args = get_input_value_port_count() - ( (call_mode==CALL_MODE_BASIC_TYPE || call_mode==CALL_MODE_INSTANCE) ? 1: 0 ); instance->rpc_mode=rpc_call_mode; + instance->validate=validate; return instance; } VisualScriptFunctionCall::VisualScriptFunctionCall() { + validate=true; call_mode=CALL_MODE_SELF; basic_type=Variant::NIL; use_default_args=0; diff --git a/modules/visual_script/visual_script_func_nodes.h b/modules/visual_script/visual_script_func_nodes.h index fa6ab99b9b..5367deed7f 100644 --- a/modules/visual_script/visual_script_func_nodes.h +++ b/modules/visual_script/visual_script_func_nodes.h @@ -35,6 +35,7 @@ private: int use_default_args; RPCCallMode rpc_call_mode; StringName singleton; + bool validate; Node *_get_base_node() const; @@ -96,6 +97,9 @@ public: void set_use_default_args(int p_amount); int get_use_default_args() const; + void set_validate(bool p_amount); + bool get_validate() const; + void set_rpc_call_mode(RPCCallMode p_mode); RPCCallMode get_rpc_call_mode() const; diff --git a/modules/visual_script/visual_script_nodes.cpp b/modules/visual_script/visual_script_nodes.cpp index 0ed2353884..f5c5159af7 100644 --- a/modules/visual_script/visual_script_nodes.cpp +++ b/modules/visual_script/visual_script_nodes.cpp @@ -2858,6 +2858,7 @@ Variant::Type VisualScriptConstructor::get_constructor_type() const { void VisualScriptConstructor::set_constructor(const Dictionary& p_info) { constructor=MethodInfo::from_dict(p_info); + ports_changed_notify(); } Dictionary VisualScriptConstructor::get_constructor() const { |