12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967 |
- #include "visual_script_func_nodes.h"
- #include "scene/main/scene_main_loop.h"
- #include "os/os.h"
- #include "scene/main/node.h"
- #include "visual_script_nodes.h"
- //////////////////////////////////////////
- ////////////////CALL//////////////////////
- //////////////////////////////////////////
- int VisualScriptFunctionCall::get_output_sequence_port_count() const {
- return 1;
- }
- bool VisualScriptFunctionCall::has_input_sequence_port() const{
- return true;
- }
- #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
- Node *VisualScriptFunctionCall::_get_base_node() const {
- #ifdef TOOLS_ENABLED
- Ref<Script> script = get_visual_script();
- if (!script.is_valid())
- return NULL;
- MainLoop * main_loop = OS::get_singleton()->get_main_loop();
- if (!main_loop)
- return NULL;
- SceneTree *scene_tree = main_loop->cast_to<SceneTree>();
- if (!scene_tree)
- return NULL;
- Node *edited_scene = scene_tree->get_edited_scene_root();
- if (!edited_scene)
- return NULL;
- Node* script_node = _find_script_node(edited_scene,edited_scene,script);
- if (!script_node)
- return NULL;
- if (!script_node->has_node(base_path))
- return NULL;
- Node *path_to = script_node->get_node(base_path);
- return path_to;
- #else
- return NULL;
- #endif
- }
- StringName VisualScriptFunctionCall::_get_base_type() const {
- if (call_mode==CALL_MODE_SELF && get_visual_script().is_valid())
- return get_visual_script()->get_instance_base_type();
- else if (call_mode==CALL_MODE_NODE_PATH && get_visual_script().is_valid()) {
- Node *path = _get_base_node();
- if (path)
- return path->get_type();
- }
- return base_type;
- }
- int VisualScriptFunctionCall::get_input_value_port_count() const{
- if (call_mode==CALL_MODE_BASIC_TYPE) {
- 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{
- 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;
- }
- }
- String VisualScriptFunctionCall::get_output_sequence_port_text(int p_port) const {
- return String();
- }
- PropertyInfo VisualScriptFunctionCall::get_input_value_port_info(int p_idx) const{
- if (call_mode==CALL_MODE_INSTANCE || call_mode==CALL_MODE_BASIC_TYPE) {
- if (p_idx==0) {
- PropertyInfo pi;
- 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--;
- }
- }
- #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();
- return mb->get_argument_info(p_idx);
- }
- #else
- return PropertyInfo();
- #endif
- }
- PropertyInfo VisualScriptFunctionCall::get_output_value_port_info(int p_idx) const{
- #ifdef DEBUG_METHODS_ENABLED
- if (call_mode==CALL_MODE_BASIC_TYPE) {
- 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
- }
- String VisualScriptFunctionCall::get_caption() const {
- 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)+"()";
- }
- void VisualScriptFunctionCall::_update_defargs() {
- //save base type if accessible
- if (call_mode==CALL_MODE_NODE_PATH) {
- Node* node=_get_base_node();
- if (node) {
- base_type=node->get_type();
- }
- } else if (call_mode==CALL_MODE_SELF) {
- if (get_visual_script().is_valid()) {
- base_type=get_visual_script()->get_instance_base_type();
- }
- }
- 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) {
- if (basic_type==p_type)
- return;
- basic_type=p_type;
- _update_defargs();
- _change_notify();
- ports_changed_notify();
- }
- Variant::Type VisualScriptFunctionCall::get_basic_type() const{
- return basic_type;
- }
- void VisualScriptFunctionCall::set_base_type(const StringName& p_type) {
- if (base_type==p_type)
- return;
- base_type=p_type;
- _update_defargs();
- _change_notify();
- ports_changed_notify();
- }
- StringName VisualScriptFunctionCall::get_base_type() const{
- return base_type;
- }
- void VisualScriptFunctionCall::set_function(const StringName& p_type){
- if (function==p_type)
- return;
- function=p_type;
- _update_defargs();
- _change_notify();
- ports_changed_notify();
- }
- StringName VisualScriptFunctionCall::get_function() const {
- return function;
- }
- void VisualScriptFunctionCall::set_base_path(const NodePath& p_type) {
- if (base_path==p_type)
- return;
- base_path=p_type;
- _update_defargs();
- _change_notify();
- ports_changed_notify();
- }
- NodePath VisualScriptFunctionCall::get_base_path() const {
- return base_path;
- }
- void VisualScriptFunctionCall::set_call_mode(CallMode p_mode) {
- if (call_mode==p_mode)
- return;
- call_mode=p_mode;
- _update_defargs();
- _change_notify();
- ports_changed_notify();
- }
- VisualScriptFunctionCall::CallMode VisualScriptFunctionCall::get_call_mode() const {
- return call_mode;
- }
- void VisualScriptFunctionCall::set_use_default_args(int p_amount) {
- if (use_default_args==p_amount)
- return;
- use_default_args=p_amount;
- ports_changed_notify();
- }
- int VisualScriptFunctionCall::get_use_default_args() const{
- return use_default_args;
- }
- void VisualScriptFunctionCall::_validate_property(PropertyInfo& property) const {
- if (property.name=="function/base_type") {
- if (call_mode!=CALL_MODE_INSTANCE) {
- property.usage=PROPERTY_USAGE_NOEDITOR;
- }
- }
- 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) {
- property.usage=0;
- } else {
- Node *bnode = _get_base_node();
- if (bnode) {
- property.hint_string=bnode->get_path(); //convert to loong string
- } else {
- }
- }
- }
- if (property.name=="function/function") {
- if (call_mode==CALL_MODE_BASIC_TYPE) {
- property.hint=PROPERTY_HINT_METHOD_OF_VARIANT_TYPE;
- property.hint_string=Variant::get_type_name(basic_type);
- } else if (call_mode==CALL_MODE_SELF && get_visual_script().is_valid()) {
- property.hint=PROPERTY_HINT_METHOD_OF_SCRIPT;
- property.hint_string=itos(get_visual_script()->get_instance_ID());
- } else if (call_mode==CALL_MODE_INSTANCE) {
- property.hint=PROPERTY_HINT_METHOD_OF_BASE_TYPE;
- property.hint_string=base_type;
- } else if (call_mode==CALL_MODE_NODE_PATH) {
- Node *node = _get_base_node();
- if (node) {
- property.hint=PROPERTY_HINT_METHOD_OF_INSTANCE;
- property.hint_string=itos(node->get_instance_ID());
- } else {
- property.hint=PROPERTY_HINT_METHOD_OF_BASE_TYPE;
- property.hint_string=get_base_type();
- }
- }
- }
- if (property.name=="function/use_default_args") {
- property.hint=PROPERTY_HINT_RANGE;
- int mc=0;
- 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();
- }
- }
- if (mc==0) {
- property.usage=0; //do not show
- } else {
- property.hint_string="0,"+itos(mc)+",1";
- }
- }
- }
- 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);
- ObjectTypeDB::bind_method(_MD("set_call_mode","mode"),&VisualScriptFunctionCall::set_call_mode);
- ObjectTypeDB::bind_method(_MD("get_call_mode"),&VisualScriptFunctionCall::get_call_mode);
- ObjectTypeDB::bind_method(_MD("set_base_path","base_path"),&VisualScriptFunctionCall::set_base_path);
- ObjectTypeDB::bind_method(_MD("get_base_path"),&VisualScriptFunctionCall::get_base_path);
- ObjectTypeDB::bind_method(_MD("set_use_default_args","amount"),&VisualScriptFunctionCall::set_use_default_args);
- ObjectTypeDB::bind_method(_MD("get_use_default_args"),&VisualScriptFunctionCall::get_use_default_args);
- 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"),_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"));
- BIND_CONSTANT( CALL_MODE_SELF );
- BIND_CONSTANT( CALL_MODE_NODE_PATH);
- BIND_CONSTANT( CALL_MODE_INSTANCE);
- BIND_CONSTANT( CALL_MODE_BASIC_TYPE );
- }
- class VisualScriptNodeInstanceFunctionCall : public VisualScriptNodeInstance {
- public:
- VisualScriptFunctionCall::CallMode call_mode;
- NodePath node_path;
- int input_args;
- bool returns;
- StringName function;
- VisualScriptFunctionCall *node;
- VisualScriptInstance *instance;
- //virtual int get_working_memory_size() const { return 0; }
- //virtual bool is_output_port_unsequenced(int p_idx) const { return false; }
- //virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return true; }
- 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) {
- switch(call_mode) {
- case VisualScriptFunctionCall::CALL_MODE_SELF: {
- Object *object=instance->get_owner_ptr();
- if (returns) {
- *p_outputs[0] = object->call(function,p_inputs,input_args,r_error);
- } else {
- object->call(function,p_inputs,input_args,r_error);
- }
- } break;
- case VisualScriptFunctionCall::CALL_MODE_NODE_PATH: {
- Node* node = instance->get_owner_ptr()->cast_to<Node>();
- if (!node) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_error_str="Base object is not a Node!";
- return 0;
- }
- Node* another = node->get_node(node_path);
- if (!node) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_error_str="Path does not lead Node!";
- return 0;
- }
- if (returns) {
- *p_outputs[0] = another->call(function,p_inputs,input_args,r_error);
- } else {
- another->call(function,p_inputs,input_args,r_error);
- }
- } break;
- case VisualScriptFunctionCall::CALL_MODE_INSTANCE:
- case VisualScriptFunctionCall::CALL_MODE_BASIC_TYPE: {
- Variant v = *p_inputs[0];
- if (returns) {
- *p_outputs[0] = v.call(function,p_inputs+1,input_args,r_error);
- } else {
- v.call(function,p_inputs+1,input_args,r_error);
- }
- } break;
- }
- return 0;
- }
- };
- VisualScriptNodeInstance* VisualScriptFunctionCall::instance(VisualScriptInstance* p_instance) {
- VisualScriptNodeInstanceFunctionCall * instance = memnew(VisualScriptNodeInstanceFunctionCall );
- instance->node=this;
- instance->instance=p_instance;
- instance->function=function;
- instance->call_mode=call_mode;
- instance->returns=get_output_value_port_count();
- 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 );
- return instance;
- }
- VisualScriptFunctionCall::VisualScriptFunctionCall() {
- call_mode=CALL_MODE_SELF;
- basic_type=Variant::NIL;
- use_default_args=0;
- base_type="Object";
- }
- template<VisualScriptFunctionCall::CallMode cmode>
- static Ref<VisualScriptNode> create_function_call_node(const String& p_name) {
- Ref<VisualScriptFunctionCall> node;
- node.instance();
- node->set_call_mode(cmode);
- return node;
- }
- //////////////////////////////////////////
- ////////////////SET//////////////////////
- //////////////////////////////////////////
- static const char* event_type_names[InputEvent::TYPE_MAX]={
- "None",
- "Key",
- "MouseMotion",
- "MouseButton",
- "JoystickMotion",
- "JoystickButton",
- "ScreenTouch",
- "ScreenDrag",
- "Action"
- };
- int VisualScriptPropertySet::get_output_sequence_port_count() const {
- return 1;
- }
- bool VisualScriptPropertySet::has_input_sequence_port() const{
- return true;
- }
- Node *VisualScriptPropertySet::_get_base_node() const {
- #ifdef TOOLS_ENABLED
- Ref<Script> script = get_visual_script();
- if (!script.is_valid())
- return NULL;
- MainLoop * main_loop = OS::get_singleton()->get_main_loop();
- if (!main_loop)
- return NULL;
- SceneTree *scene_tree = main_loop->cast_to<SceneTree>();
- if (!scene_tree)
- return NULL;
- Node *edited_scene = scene_tree->get_edited_scene_root();
- if (!edited_scene)
- return NULL;
- Node* script_node = _find_script_node(edited_scene,edited_scene,script);
- if (!script_node)
- return NULL;
- if (!script_node->has_node(base_path))
- return NULL;
- Node *path_to = script_node->get_node(base_path);
- return path_to;
- #else
- return NULL;
- #endif
- }
- StringName VisualScriptPropertySet::_get_base_type() const {
- if (call_mode==CALL_MODE_SELF && get_visual_script().is_valid())
- return get_visual_script()->get_instance_base_type();
- else if (call_mode==CALL_MODE_NODE_PATH && get_visual_script().is_valid()) {
- Node *path = _get_base_node();
- if (path)
- return path->get_type();
- }
- return base_type;
- }
- int VisualScriptPropertySet::get_input_value_port_count() const{
- 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{
- return call_mode==CALL_MODE_BASIC_TYPE? 1 : 0;
- }
- String VisualScriptPropertySet::get_output_sequence_port_text(int p_port) const {
- return String();
- }
- PropertyInfo VisualScriptPropertySet::get_input_value_port_info(int p_idx) const{
- if (call_mode==CALL_MODE_INSTANCE || call_mode==CALL_MODE_BASIC_TYPE) {
- if (p_idx==0) {
- PropertyInfo pi;
- 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--;
- }
- }
- #ifdef DEBUG_METHODS_ENABLED
- //not very efficient but..
- List<PropertyInfo> pinfo;
- if (call_mode==CALL_MODE_BASIC_TYPE) {
- Variant v;
- if (basic_type==Variant::INPUT_EVENT) {
- InputEvent ev;
- ev.type=event_type;
- v=ev;
- } else {
- Variant::CallError ce;
- 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) {
- PropertyInfo info=E->get();
- info.name="value";
- return info;
- }
- }
- #endif
- return PropertyInfo(Variant::NIL,"value");
- }
- PropertyInfo VisualScriptPropertySet::get_output_value_port_info(int p_idx) const{
- if (call_mode==CALL_MODE_BASIC_TYPE) {
- return PropertyInfo(basic_type,"out");
- } else {
- return PropertyInfo();
- }
- }
- String VisualScriptPropertySet::get_caption() const {
- static const char*cname[4]= {
- "SelfSet",
- "NodeSet",
- "InstanceSet",
- "BasicSet"
- };
- return cname[call_mode];
- }
- String VisualScriptPropertySet::get_text() const {
- 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::_update_base_type() {
- //cache it because this information may not be available on load
- if (call_mode==CALL_MODE_NODE_PATH) {
- Node* node=_get_base_node();
- if (node) {
- base_type=node->get_type();
- }
- } else if (call_mode==CALL_MODE_SELF) {
- if (get_visual_script().is_valid()) {
- base_type=get_visual_script()->get_instance_base_type();
- }
- }
- }
- void VisualScriptPropertySet::set_basic_type(Variant::Type p_type) {
- if (basic_type==p_type)
- return;
- basic_type=p_type;
- _change_notify();
- _update_base_type();
- ports_changed_notify();
- }
- Variant::Type VisualScriptPropertySet::get_basic_type() const{
- return basic_type;
- }
- void VisualScriptPropertySet::set_event_type(InputEvent::Type p_type) {
- if (event_type==p_type)
- return;
- event_type=p_type;
- _change_notify();
- _update_base_type();
- ports_changed_notify();
- }
- InputEvent::Type VisualScriptPropertySet::get_event_type() const{
- return event_type;
- }
- void VisualScriptPropertySet::set_base_type(const StringName& p_type) {
- if (base_type==p_type)
- return;
- base_type=p_type;
- _change_notify();
- ports_changed_notify();
- }
- StringName VisualScriptPropertySet::get_base_type() const{
- return base_type;
- }
- void VisualScriptPropertySet::set_property(const StringName& p_type){
- if (property==p_type)
- return;
- property=p_type;
- _change_notify();
- ports_changed_notify();
- }
- StringName VisualScriptPropertySet::get_property() const {
- return property;
- }
- void VisualScriptPropertySet::set_base_path(const NodePath& p_type) {
- if (base_path==p_type)
- return;
- base_path=p_type;
- _update_base_type();
- _change_notify();
- ports_changed_notify();
- }
- NodePath VisualScriptPropertySet::get_base_path() const {
- return base_path;
- }
- void VisualScriptPropertySet::set_call_mode(CallMode p_mode) {
- if (call_mode==p_mode)
- return;
- call_mode=p_mode;
- _update_base_type();
- _change_notify();
- ports_changed_notify();
- }
- VisualScriptPropertySet::CallMode VisualScriptPropertySet::get_call_mode() const {
- return call_mode;
- }
- void VisualScriptPropertySet::set_use_builtin_value(bool p_use) {
- if (use_builtin_value==p_use)
- return;
- use_builtin_value=p_use;
- _change_notify();
- ports_changed_notify();
- }
- bool VisualScriptPropertySet::is_using_builtin_value() const{
- return use_builtin_value;
- }
- void VisualScriptPropertySet::set_builtin_value(const Variant& p_value){
- if (builtin_value==p_value)
- return;
- builtin_value=p_value;
- }
- Variant VisualScriptPropertySet::get_builtin_value() const{
- return builtin_value;
- }
- void VisualScriptPropertySet::_validate_property(PropertyInfo& property) const {
- if (property.name=="property/base_type") {
- if (call_mode!=CALL_MODE_INSTANCE) {
- property.usage=PROPERTY_USAGE_NOEDITOR;
- }
- }
- if (property.name=="property/basic_type") {
- if (call_mode!=CALL_MODE_BASIC_TYPE) {
- property.usage=0;
- }
- }
- if (property.name=="property/event_type") {
- if (call_mode!=CALL_MODE_BASIC_TYPE || basic_type!=Variant::INPUT_EVENT) {
- property.usage=0;
- }
- }
- if (property.name=="property/node_path") {
- if (call_mode!=CALL_MODE_NODE_PATH) {
- property.usage=0;
- } else {
- Node *bnode = _get_base_node();
- if (bnode) {
- property.hint_string=bnode->get_path(); //convert to loong string
- } else {
- }
- }
- }
- if (property.name=="property/property") {
- if (call_mode==CALL_MODE_BASIC_TYPE) {
- property.hint=PROPERTY_HINT_PROPERTY_OF_VARIANT_TYPE;
- property.hint_string=Variant::get_type_name(basic_type);
- } else if (call_mode==CALL_MODE_SELF && get_visual_script().is_valid()) {
- property.hint=PROPERTY_HINT_PROPERTY_OF_SCRIPT;
- property.hint_string=itos(get_visual_script()->get_instance_ID());
- } else if (call_mode==CALL_MODE_INSTANCE) {
- property.hint=PROPERTY_HINT_PROPERTY_OF_BASE_TYPE;
- property.hint_string=base_type;
- } else if (call_mode==CALL_MODE_NODE_PATH) {
- Node *node = _get_base_node();
- if (node) {
- property.hint=PROPERTY_HINT_PROPERTY_OF_INSTANCE;
- property.hint_string=itos(node->get_instance_ID());
- } else {
- property.hint=PROPERTY_HINT_PROPERTY_OF_BASE_TYPE;
- property.hint_string=get_base_type();
- }
- }
- }
- if (property.name=="value/builtin") {
- if (!use_builtin_value) {
- property.usage=0;
- } 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);
- } 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==this->property) {
- property.hint=E->get().hint;
- property.type=E->get().type;
- property.hint_string=E->get().hint_string;
- }
- }
- }
- }
- }
- 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_event_type","event_type"),&VisualScriptPropertySet::set_event_type);
- ObjectTypeDB::bind_method(_MD("get_event_type"),&VisualScriptPropertySet::get_event_type);
- ObjectTypeDB::bind_method(_MD("set_property","property"),&VisualScriptPropertySet::set_property);
- ObjectTypeDB::bind_method(_MD("get_property"),&VisualScriptPropertySet::get_property);
- ObjectTypeDB::bind_method(_MD("set_call_mode","mode"),&VisualScriptPropertySet::set_call_mode);
- ObjectTypeDB::bind_method(_MD("get_call_mode"),&VisualScriptPropertySet::get_call_mode);
- ObjectTypeDB::bind_method(_MD("set_base_path","base_path"),&VisualScriptPropertySet::set_base_path);
- ObjectTypeDB::bind_method(_MD("get_base_path"),&VisualScriptPropertySet::get_base_path);
- ObjectTypeDB::bind_method(_MD("set_builtin_value","value"),&VisualScriptPropertySet::set_builtin_value);
- ObjectTypeDB::bind_method(_MD("get_builtin_value"),&VisualScriptPropertySet::get_builtin_value);
- 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);
- String bt;
- for(int i=0;i<Variant::VARIANT_MAX;i++) {
- if (i>0)
- bt+=",";
- bt+=Variant::get_type_name(Variant::Type(i));
- }
- String et;
- for(int i=0;i<InputEvent::TYPE_MAX;i++) {
- if (i>0)
- et+=",";
- et+=event_type_names[i];
- }
- ADD_PROPERTY(PropertyInfo(Variant::INT,"property/set_mode",PROPERTY_HINT_ENUM,"Self,Node Path,Instance,Basic Type"),_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::INT,"property/event_type",PROPERTY_HINT_ENUM,et),_SCS("set_event_type"),_SCS("get_event_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"));
- ADD_PROPERTY(PropertyInfo(Variant::NIL,"value/builtin"),_SCS("set_builtin_value"),_SCS("get_builtin_value"));
- BIND_CONSTANT( CALL_MODE_SELF );
- BIND_CONSTANT( CALL_MODE_NODE_PATH);
- BIND_CONSTANT( CALL_MODE_INSTANCE);
- }
- class VisualScriptNodeInstancePropertySet : public VisualScriptNodeInstance {
- public:
- VisualScriptPropertySet::CallMode call_mode;
- NodePath node_path;
- StringName property;
- bool use_builtin;
- Variant builtin_val;
- VisualScriptPropertySet *node;
- VisualScriptInstance *instance;
- //virtual int get_working_memory_size() const { return 0; }
- //virtual bool is_output_port_unsequenced(int p_idx) const { return false; }
- //virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return true; }
- 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) {
- switch(call_mode) {
- case VisualScriptPropertySet::CALL_MODE_SELF: {
- Object *object=instance->get_owner_ptr();
- bool valid;
- if (use_builtin) {
- object->set(property,builtin_val,&valid);
- } else {
- object->set(property,*p_inputs[0],&valid);
- }
- if (!valid) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_error_str="Invalid index property name.";
- }
- } break;
- case VisualScriptPropertySet::CALL_MODE_NODE_PATH: {
- Node* node = instance->get_owner_ptr()->cast_to<Node>();
- if (!node) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_error_str="Base object is not a Node!";
- return 0;
- }
- Node* another = node->get_node(node_path);
- if (!node) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_error_str="Path does not lead Node!";
- return 0;
- }
- bool valid;
- if (use_builtin) {
- another->set(property,builtin_val,&valid);
- } else {
- another->set(property,*p_inputs[0],&valid);
- }
- if (!valid) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_error_str="Invalid index property name.";
- }
- } break;
- case VisualScriptPropertySet::CALL_MODE_INSTANCE:
- case VisualScriptPropertySet::CALL_MODE_BASIC_TYPE: {
- Variant v = *p_inputs[0];
- bool valid;
- if (use_builtin) {
- v.set(property,builtin_val,&valid);
- } else {
- v.set(property,p_inputs[1],&valid);
- }
- if (!valid) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_error_str="Invalid index property name.";
- }
- if (call_mode==VisualScriptPropertySet::CALL_MODE_BASIC_TYPE) {
- *p_outputs[0]=v;
- }
- } break;
- }
- return 0;
- }
- };
- VisualScriptNodeInstance* VisualScriptPropertySet::instance(VisualScriptInstance* p_instance) {
- VisualScriptNodeInstancePropertySet * instance = memnew(VisualScriptNodeInstancePropertySet );
- instance->node=this;
- instance->instance=p_instance;
- instance->property=property;
- instance->call_mode=call_mode;
- instance->node_path=base_path;
- instance->use_builtin=use_builtin_value;
- instance->builtin_val=builtin_value;
- return instance;
- }
- VisualScriptPropertySet::VisualScriptPropertySet() {
- call_mode=CALL_MODE_SELF;
- base_type="Object";
- basic_type=Variant::NIL;
- event_type=InputEvent::NONE;
- }
- template<VisualScriptPropertySet::CallMode cmode>
- static Ref<VisualScriptNode> create_property_set_node(const String& p_name) {
- Ref<VisualScriptPropertySet> node;
- node.instance();
- node->set_call_mode(cmode);
- return node;
- }
- //////////////////////////////////////////
- ////////////////GET//////////////////////
- //////////////////////////////////////////
- int VisualScriptPropertyGet::get_output_sequence_port_count() const {
- return (call_mode==CALL_MODE_SELF || call_mode==CALL_MODE_NODE_PATH)?0:1;
- }
- bool VisualScriptPropertyGet::has_input_sequence_port() const{
- return (call_mode==CALL_MODE_SELF || call_mode==CALL_MODE_NODE_PATH)?false:true;
- }
- void VisualScriptPropertyGet::_update_base_type() {
- //cache it because this information may not be available on load
- if (call_mode==CALL_MODE_NODE_PATH) {
- Node* node=_get_base_node();
- if (node) {
- base_type=node->get_type();
- }
- } else if (call_mode==CALL_MODE_SELF) {
- if (get_visual_script().is_valid()) {
- base_type=get_visual_script()->get_instance_base_type();
- }
- }
- }
- Node *VisualScriptPropertyGet::_get_base_node() const {
- #ifdef TOOLS_ENABLED
- Ref<Script> script = get_visual_script();
- if (!script.is_valid())
- return NULL;
- MainLoop * main_loop = OS::get_singleton()->get_main_loop();
- if (!main_loop)
- return NULL;
- SceneTree *scene_tree = main_loop->cast_to<SceneTree>();
- if (!scene_tree)
- return NULL;
- Node *edited_scene = scene_tree->get_edited_scene_root();
- if (!edited_scene)
- return NULL;
- Node* script_node = _find_script_node(edited_scene,edited_scene,script);
- if (!script_node)
- return NULL;
- if (!script_node->has_node(base_path))
- return NULL;
- Node *path_to = script_node->get_node(base_path);
- return path_to;
- #else
- return NULL;
- #endif
- }
- StringName VisualScriptPropertyGet::_get_base_type() const {
- if (call_mode==CALL_MODE_SELF && get_visual_script().is_valid())
- return get_visual_script()->get_instance_base_type();
- else if (call_mode==CALL_MODE_NODE_PATH && get_visual_script().is_valid()) {
- Node *path = _get_base_node();
- if (path)
- return path->get_type();
- }
- return base_type;
- }
- int VisualScriptPropertyGet::get_input_value_port_count() const{
- return (call_mode==CALL_MODE_BASIC_TYPE || call_mode==CALL_MODE_INSTANCE)?1:0;
- }
- int VisualScriptPropertyGet::get_output_value_port_count() const{
- return 1;
- }
- String VisualScriptPropertyGet::get_output_sequence_port_text(int p_port) const {
- return String();
- }
- PropertyInfo VisualScriptPropertyGet::get_input_value_port_info(int p_idx) const{
- if (call_mode==CALL_MODE_INSTANCE || call_mode==CALL_MODE_BASIC_TYPE) {
- if (p_idx==0) {
- PropertyInfo pi;
- 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--;
- }
- }
- return PropertyInfo();
- }
- PropertyInfo VisualScriptPropertyGet::get_output_value_port_info(int p_idx) const{
- #ifdef DEBUG_METHODS_ENABLED
- //not very efficient but..
- List<PropertyInfo> pinfo;
- if (call_mode==CALL_MODE_BASIC_TYPE) {
- Variant v;
- if (basic_type==Variant::INPUT_EVENT) {
- InputEvent ev;
- ev.type=event_type;
- v=ev;
- } else {
- Variant::CallError ce;
- 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) {
- PropertyInfo info=E->get();
- info.name="";
- return info;
- }
- }
- #endif
- return PropertyInfo(Variant::NIL,"");
- }
- String VisualScriptPropertyGet::get_caption() const {
- static const char*cname[4]= {
- "SelfGet",
- "NodeGet",
- "InstanceGet",
- "BasicGet"
- };
- return cname[call_mode];
- }
- String VisualScriptPropertyGet::get_text() const {
- if (call_mode==CALL_MODE_BASIC_TYPE)
- return Variant::get_type_name(basic_type)+"."+property;
- else
- return property;
- }
- void VisualScriptPropertyGet::set_base_type(const StringName& p_type) {
- if (base_type==p_type)
- return;
- base_type=p_type;
- _change_notify();
- ports_changed_notify();
- }
- StringName VisualScriptPropertyGet::get_base_type() const{
- return base_type;
- }
- void VisualScriptPropertyGet::set_property(const StringName& p_type){
- if (property==p_type)
- return;
- property=p_type;
- _change_notify();
- ports_changed_notify();
- }
- StringName VisualScriptPropertyGet::get_property() const {
- return property;
- }
- void VisualScriptPropertyGet::set_base_path(const NodePath& p_type) {
- if (base_path==p_type)
- return;
- base_path=p_type;
- _change_notify();
- _update_base_type();
- ports_changed_notify();
- }
- NodePath VisualScriptPropertyGet::get_base_path() const {
- return base_path;
- }
- void VisualScriptPropertyGet::set_call_mode(CallMode p_mode) {
- if (call_mode==p_mode)
- return;
- call_mode=p_mode;
- _change_notify();
- _update_base_type();
- ports_changed_notify();
- }
- 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();
- ports_changed_notify();
- }
- Variant::Type VisualScriptPropertyGet::get_basic_type() const{
- return basic_type;
- }
- void VisualScriptPropertyGet::set_event_type(InputEvent::Type p_type) {
- if (event_type==p_type)
- return;
- event_type=p_type;
- _change_notify();
- _update_base_type();
- ports_changed_notify();
- }
- InputEvent::Type VisualScriptPropertyGet::get_event_type() const{
- return event_type;
- }
- void VisualScriptPropertyGet::_validate_property(PropertyInfo& property) const {
- if (property.name=="property/base_type") {
- if (call_mode!=CALL_MODE_INSTANCE) {
- property.usage=PROPERTY_USAGE_NOEDITOR;
- }
- }
- if (property.name=="property/basic_type") {
- if (call_mode!=CALL_MODE_BASIC_TYPE) {
- property.usage=0;
- }
- }
- if (property.name=="property/event_type") {
- if (call_mode!=CALL_MODE_BASIC_TYPE || basic_type!=Variant::INPUT_EVENT) {
- property.usage=0;
- }
- }
- if (property.name=="property/node_path") {
- if (call_mode!=CALL_MODE_NODE_PATH) {
- property.usage=0;
- } else {
- Node *bnode = _get_base_node();
- if (bnode) {
- property.hint_string=bnode->get_path(); //convert to loong string
- } else {
- }
- }
- }
- if (property.name=="property/property") {
- if (call_mode==CALL_MODE_BASIC_TYPE) {
- property.hint=PROPERTY_HINT_PROPERTY_OF_VARIANT_TYPE;
- property.hint_string=Variant::get_type_name(basic_type);
- } else if (call_mode==CALL_MODE_SELF && get_visual_script().is_valid()) {
- property.hint=PROPERTY_HINT_PROPERTY_OF_SCRIPT;
- property.hint_string=itos(get_visual_script()->get_instance_ID());
- } else if (call_mode==CALL_MODE_INSTANCE) {
- property.hint=PROPERTY_HINT_PROPERTY_OF_BASE_TYPE;
- property.hint_string=base_type;
- } else if (call_mode==CALL_MODE_NODE_PATH) {
- Node *node = _get_base_node();
- if (node) {
- property.hint=PROPERTY_HINT_PROPERTY_OF_INSTANCE;
- property.hint_string=itos(node->get_instance_ID());
- } else {
- property.hint=PROPERTY_HINT_PROPERTY_OF_BASE_TYPE;
- property.hint_string=get_base_type();
- }
- }
- }
- }
- 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_event_type","event_type"),&VisualScriptPropertyGet::set_event_type);
- ObjectTypeDB::bind_method(_MD("get_event_type"),&VisualScriptPropertyGet::get_event_type);
- ObjectTypeDB::bind_method(_MD("set_property","property"),&VisualScriptPropertyGet::set_property);
- ObjectTypeDB::bind_method(_MD("get_property"),&VisualScriptPropertyGet::get_property);
- ObjectTypeDB::bind_method(_MD("set_call_mode","mode"),&VisualScriptPropertyGet::set_call_mode);
- ObjectTypeDB::bind_method(_MD("get_call_mode"),&VisualScriptPropertyGet::get_call_mode);
- 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));
- }
- String et;
- for(int i=0;i<InputEvent::TYPE_MAX;i++) {
- if (i>0)
- et+=",";
- et+=event_type_names[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::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::INT,"property/event_type",PROPERTY_HINT_ENUM,et),_SCS("set_event_type"),_SCS("get_event_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"));
- BIND_CONSTANT( CALL_MODE_SELF );
- BIND_CONSTANT( CALL_MODE_NODE_PATH);
- BIND_CONSTANT( CALL_MODE_INSTANCE);
- }
- class VisualScriptNodeInstancePropertyGet : public VisualScriptNodeInstance {
- public:
- VisualScriptPropertyGet::CallMode call_mode;
- NodePath node_path;
- StringName property;
- VisualScriptPropertyGet *node;
- VisualScriptInstance *instance;
- //virtual int get_working_memory_size() const { return 0; }
- virtual bool is_output_port_unsequenced(int p_idx) const { return (call_mode==VisualScriptPropertyGet::CALL_MODE_SELF || call_mode==VisualScriptPropertyGet::CALL_MODE_NODE_PATH); }
- virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const {
- //these two modes can be get directly, so they use unsequenced mode
- switch(call_mode) {
- case VisualScriptPropertyGet::CALL_MODE_SELF: {
- Object *object=instance->get_owner_ptr();
- bool valid;
- *r_value = object->get(property,&valid);
- if (!valid) {
- //r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_error=RTR("Invalid index property name.");
- return false;
- }
- } break;
- case VisualScriptPropertyGet::CALL_MODE_NODE_PATH: {
- Node* node = instance->get_owner_ptr()->cast_to<Node>();
- if (!node) {
- //r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_error=RTR("Base object is not a Node!");
- return false;
- }
- Node* another = node->get_node(node_path);
- if (!node) {
- //r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_error=RTR("Path does not lead Node!");
- return false;
- }
- bool valid;
- *r_value = another->get(property,&valid);
- if (!valid) {
- //r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_error=vformat(RTR("Invalid index property name '%s' in node %s."),String(property),another->get_name());
- return false;
- }
- } break;
- default: {};
- }
- return true;
- }
- 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) {
- bool valid;
- Variant v = *p_inputs[0];
- *p_outputs[0] = v.get(property,&valid);
- if (!valid) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_error_str=RTR("Invalid index property name.");
- }
- return 0;
- }
- };
- VisualScriptNodeInstance* VisualScriptPropertyGet::instance(VisualScriptInstance* p_instance) {
- VisualScriptNodeInstancePropertyGet * instance = memnew(VisualScriptNodeInstancePropertyGet );
- instance->node=this;
- instance->instance=p_instance;
- instance->property=property;
- instance->call_mode=call_mode;
- instance->node_path=base_path;
- return instance;
- }
- VisualScriptPropertyGet::VisualScriptPropertyGet() {
- call_mode=CALL_MODE_SELF;
- base_type="Object";
- basic_type=Variant::NIL;
- event_type=InputEvent::NONE;
- }
- template<VisualScriptPropertyGet::CallMode cmode>
- static Ref<VisualScriptNode> create_property_get_node(const String& p_name) {
- Ref<VisualScriptPropertyGet> node;
- node.instance();
- node->set_call_mode(cmode);
- return node;
- }
- //////////////////////////////////////////
- ////////////////EMIT//////////////////////
- //////////////////////////////////////////
- int VisualScriptEmitSignal::get_output_sequence_port_count() const {
- return 1;
- }
- bool VisualScriptEmitSignal::has_input_sequence_port() const{
- return true;
- }
- int VisualScriptEmitSignal::get_input_value_port_count() const{
- Ref<VisualScript> vs = get_visual_script();
- if (vs.is_valid()) {
- if (!vs->has_custom_signal(name))
- return 0;
- return vs->custom_signal_get_argument_count(name);
- }
- return 0;
- }
- int VisualScriptEmitSignal::get_output_value_port_count() const{
- return 0;
- }
- String VisualScriptEmitSignal::get_output_sequence_port_text(int p_port) const {
- return String();
- }
- PropertyInfo VisualScriptEmitSignal::get_input_value_port_info(int p_idx) const{
- Ref<VisualScript> vs = get_visual_script();
- if (vs.is_valid()) {
- if (!vs->has_custom_signal(name))
- return PropertyInfo();
- return PropertyInfo(vs->custom_signal_get_argument_type(name,p_idx),vs->custom_signal_get_argument_name(name,p_idx));
- }
- return PropertyInfo();
- }
- PropertyInfo VisualScriptEmitSignal::get_output_value_port_info(int p_idx) const{
- return PropertyInfo();
- }
- String VisualScriptEmitSignal::get_caption() const {
- return "EmitSignal";
- }
- String VisualScriptEmitSignal::get_text() const {
- return "emit "+String(name);
- }
- void VisualScriptEmitSignal::set_signal(const StringName& p_type){
- if (name==p_type)
- return;
- name=p_type;
- _change_notify();
- ports_changed_notify();
- }
- StringName VisualScriptEmitSignal::get_signal() const {
- return name;
- }
- void VisualScriptEmitSignal::_validate_property(PropertyInfo& property) const {
- if (property.name=="signal/signal") {
- property.hint=PROPERTY_HINT_ENUM;
- List<StringName> sigs;
- Ref<VisualScript> vs = get_visual_script();
- if (vs.is_valid()) {
- vs->get_custom_signal_list(&sigs);
- }
- String ml;
- for (List<StringName>::Element *E=sigs.front();E;E=E->next()) {
- if (ml!=String())
- ml+=",";
- ml+=E->get();
- }
- property.hint_string=ml;
- }
- }
- void VisualScriptEmitSignal::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("set_signal","name"),&VisualScriptEmitSignal::set_signal);
- ObjectTypeDB::bind_method(_MD("get_signal"),&VisualScriptEmitSignal::get_signal);
- ADD_PROPERTY(PropertyInfo(Variant::STRING,"signal/signal"),_SCS("set_signal"),_SCS("get_signal"));
- }
- class VisualScriptNodeInstanceEmitSignal : public VisualScriptNodeInstance {
- public:
- VisualScriptEmitSignal *node;
- VisualScriptInstance *instance;
- int argcount;
- StringName name;
- //virtual int get_working_memory_size() const { return 0; }
- //virtual bool is_output_port_unsequenced(int p_idx) const { return false; }
- //virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return true; }
- 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) {
- Object *obj = instance->get_owner_ptr();
- obj->emit_signal(name,p_inputs,argcount);
- return 0;
- }
- };
- VisualScriptNodeInstance* VisualScriptEmitSignal::instance(VisualScriptInstance* p_instance) {
- VisualScriptNodeInstanceEmitSignal * instance = memnew(VisualScriptNodeInstanceEmitSignal );
- instance->node=this;
- instance->instance=p_instance;
- instance->name=name;
- instance->argcount=get_input_value_port_count();
- return instance;
- }
- VisualScriptEmitSignal::VisualScriptEmitSignal() {
- }
- static Ref<VisualScriptNode> create_basic_type_call_node(const String& p_name) {
- Vector<String> path = p_name.split("/");
- ERR_FAIL_COND_V(path.size()<4,Ref<VisualScriptNode>());
- String base_type = path[2];
- String method = path[3];
- Ref<VisualScriptFunctionCall> node;
- node.instance();
- Variant::Type type=Variant::VARIANT_MAX;
- for(int i=0;i<Variant::VARIANT_MAX;i++) {
- if (Variant::get_type_name(Variant::Type(i))==base_type) {
- type=Variant::Type(i);
- break;
- }
- }
- ERR_FAIL_COND_V(type==Variant::VARIANT_MAX,Ref<VisualScriptNode>());
- node->set_call_mode(VisualScriptFunctionCall::CALL_MODE_BASIC_TYPE);
- node->set_basic_type(type);
- node->set_function(method);
- return node;
- }
- void register_visual_script_func_nodes() {
- VisualScriptLanguage::singleton->add_register_func("functions/call",create_node_generic<VisualScriptFunctionCall>);
- VisualScriptLanguage::singleton->add_register_func("functions/set",create_node_generic<VisualScriptPropertySet>);
- VisualScriptLanguage::singleton->add_register_func("functions/get",create_node_generic<VisualScriptPropertyGet>);
- //VisualScriptLanguage::singleton->add_register_func("functions/call_script/call_self",create_script_call_node<VisualScriptScriptCall::CALL_MODE_SELF>);
- // VisualScriptLanguage::singleton->add_register_func("functions/call_script/call_node",create_script_call_node<VisualScriptScriptCall::CALL_MODE_NODE_PATH>);
- VisualScriptLanguage::singleton->add_register_func("functions/emit_signal",create_node_generic<VisualScriptEmitSignal>);
- for(int i=0;i<Variant::VARIANT_MAX;i++) {
- Variant::Type t = Variant::Type(i);
- String type_name = Variant::get_type_name(t);
- Variant::CallError ce;
- Variant vt = Variant::construct(t,NULL,0,ce);
- List<MethodInfo> ml;
- vt.get_method_list(&ml);
- for (List<MethodInfo>::Element *E=ml.front();E;E=E->next()) {
- VisualScriptLanguage::singleton->add_register_func("functions/by_type/"+type_name+"/"+E->get().name,create_basic_type_call_node);
- }
- }
- }
|