diff options
Diffstat (limited to 'modules/visual_script/visual_script_flow_control.cpp')
-rw-r--r-- | modules/visual_script/visual_script_flow_control.cpp | 162 |
1 files changed, 124 insertions, 38 deletions
diff --git a/modules/visual_script/visual_script_flow_control.cpp b/modules/visual_script/visual_script_flow_control.cpp index 700d5d57ff..42cf4aab49 100644 --- a/modules/visual_script/visual_script_flow_control.cpp +++ b/modules/visual_script/visual_script_flow_control.cpp @@ -603,70 +603,60 @@ VisualScriptSequence::VisualScriptSequence() { ////////////////EVENT TYPE FILTER/////////// ////////////////////////////////////////// -static const char* event_type_names[InputEvent::TYPE_MAX]={ - "None", - "Key", - "MouseMotion", - "MouseButton", - "JoystickMotion", - "JoystickButton", - "ScreenTouch", - "ScreenDrag", - "Action" -}; +int VisualScriptSwitch::get_output_sequence_port_count() const { -int VisualScriptInputSelector::get_output_sequence_port_count() const { - - return InputEvent::TYPE_MAX; + return case_values.size(); } -bool VisualScriptInputSelector::has_input_sequence_port() const{ +bool VisualScriptSwitch::has_input_sequence_port() const{ return true; } -int VisualScriptInputSelector::get_input_value_port_count() const{ +int VisualScriptSwitch::get_input_value_port_count() const{ return 1; } -int VisualScriptInputSelector::get_output_value_port_count() const{ +int VisualScriptSwitch::get_output_value_port_count() const{ - return 1; + return 0; } -String VisualScriptInputSelector::get_output_sequence_port_text(int p_port) const { +String VisualScriptSwitch::get_output_sequence_port_text(int p_port) const { - return event_type_names[p_port]; + if (case_values[p_port].value.get_type()==Variant::NIL) + return "null"; + return case_values[p_port].value; } -PropertyInfo VisualScriptInputSelector::get_input_value_port_info(int p_idx) const{ +PropertyInfo VisualScriptSwitch::get_input_value_port_info(int p_idx) const{ - return PropertyInfo(Variant::INPUT_EVENT,"event"); + return PropertyInfo(Variant::NIL,"input"); } -PropertyInfo VisualScriptInputSelector::get_output_value_port_info(int p_idx) const{ +PropertyInfo VisualScriptSwitch::get_output_value_port_info(int p_idx) const{ - return PropertyInfo(Variant::INPUT_EVENT,""); + return PropertyInfo(); } -String VisualScriptInputSelector::get_caption() const { +String VisualScriptSwitch::get_caption() const { - return "InputSelector"; + return "Switch"; } -String VisualScriptInputSelector::get_text() const { +String VisualScriptSwitch::get_text() const { - return ""; + return "'input' is:"; } -class VisualScriptNodeInstanceInputSelector : public VisualScriptNodeInstance { +class VisualScriptNodeInstanceSwitch : public VisualScriptNodeInstance { public: VisualScriptInstance* instance; - InputEvent::Type type; + Vector<Variant> case_values; //virtual int get_working_memory_size() const { return 0; } //virtual bool is_output_port_unsequenced(int p_idx) const { return false; } @@ -680,31 +670,114 @@ public: return 0; } - InputEvent event = *p_inputs[0]; + for(int i=0;i<case_values.size();i++) { - *p_outputs[0] = event; + if (*p_inputs[0]==case_values[i]) { + return i; + } + } - return event.type; + return STEP_NO_ADVANCE_BIT; } }; -VisualScriptNodeInstance* VisualScriptInputSelector::instance(VisualScriptInstance* p_instance) { +VisualScriptNodeInstance* VisualScriptSwitch::instance(VisualScriptInstance* p_instance) { - VisualScriptNodeInstanceInputSelector * instance = memnew(VisualScriptNodeInstanceInputSelector ); + VisualScriptNodeInstanceSwitch * instance = memnew(VisualScriptNodeInstanceSwitch ); instance->instance=p_instance; + instance->case_values.resize(case_values.size()); + for(int i=0;i<case_values.size();i++) { + instance->case_values[i]=case_values[i].value; + } return instance; } +bool VisualScriptSwitch::_set(const StringName& p_name, const Variant& p_value) { + + if (String(p_name)=="case_count") { + case_values.resize(p_value); + _change_notify(); + ports_changed_notify(); + return true; + } + + if (String(p_name).begins_with("case/")) { + + int idx = String(p_name).get_slice("/",1).to_int(); + ERR_FAIL_INDEX_V(idx,case_values.size(),false); + String what = String(p_name).get_slice("/",2); + + if (what=="type") { + case_values[idx].type=Variant::Type(int(p_value)); + Variant::CallError ce; + case_values[idx].value=Variant::construct(case_values[idx].type,NULL,0,ce); + _change_notify(); + ports_changed_notify(); + + return true; + } + + if (what=="value") { + case_values[idx].value=p_value; + ports_changed_notify(); + return true; + } + } + + return false; +} + +bool VisualScriptSwitch::_get(const StringName& p_name,Variant &r_ret) const { + + if (String(p_name)=="case_count") { + r_ret=case_values.size(); + return true; + } + + if (String(p_name).begins_with("case/")) { + + int idx = String(p_name).get_slice("/",1).to_int(); + ERR_FAIL_INDEX_V(idx,case_values.size(),false); + String what = String(p_name).get_slice("/",2); + + if (what=="type") { + r_ret=case_values[idx].type; + return true; + } + + if (what=="value") { + r_ret=case_values[idx].value; + return true; + } + } + + return false; + +} +void VisualScriptSwitch::_get_property_list( List<PropertyInfo> *p_list) const { + + p_list->push_back(PropertyInfo(Variant::INT,"case_count",PROPERTY_HINT_RANGE,"0,128")); + String argt="Any"; + for(int i=1;i<Variant::VARIANT_MAX;i++) { + argt+=","+Variant::get_type_name(Variant::Type(i)); + } -void VisualScriptInputSelector::_bind_methods() { + for(int i=0;i<case_values.size();i++) { + p_list->push_back(PropertyInfo(Variant::INT,"case/"+itos(i)+"/type",PROPERTY_HINT_ENUM,argt)); + p_list->push_back(PropertyInfo(case_values[i].type,"case/"+itos(i)+"/value")); + } +} + + +void VisualScriptSwitch::_bind_methods() { } -VisualScriptInputSelector::VisualScriptInputSelector() { +VisualScriptSwitch::VisualScriptSwitch() { } @@ -1359,6 +1432,19 @@ bool VisualScriptInputFilter::_get(const StringName& p_name,Variant &r_ret) cons } return false; } + +static const char* event_type_names[InputEvent::TYPE_MAX]={ + "None", + "Key", + "MouseMotion", + "MouseButton", + "JoystickMotion", + "JoystickButton", + "ScreenTouch", + "ScreenDrag", + "Action" +}; + void VisualScriptInputFilter::_get_property_list( List<PropertyInfo> *p_list) const { p_list->push_back(PropertyInfo(Variant::INT,"filter_count",PROPERTY_HINT_RANGE,"0,64")); @@ -1866,7 +1952,7 @@ void register_visual_script_flow_control_nodes() { VisualScriptLanguage::singleton->add_register_func("flow_control/while",create_node_generic<VisualScriptWhile>); VisualScriptLanguage::singleton->add_register_func("flow_control/iterator",create_node_generic<VisualScriptIterator>); VisualScriptLanguage::singleton->add_register_func("flow_control/sequence",create_node_generic<VisualScriptSequence>); - VisualScriptLanguage::singleton->add_register_func("flow_control/input_select",create_node_generic<VisualScriptInputSelector>); + VisualScriptLanguage::singleton->add_register_func("flow_control/switch",create_node_generic<VisualScriptSwitch>); VisualScriptLanguage::singleton->add_register_func("flow_control/input_filter",create_node_generic<VisualScriptInputFilter>); VisualScriptLanguage::singleton->add_register_func("flow_control/type_cast",create_node_generic<VisualScriptTypeCast>); |