visual_script_func_nodes.cpp 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847
  1. #include "visual_script_func_nodes.h"
  2. #include "scene/main/scene_main_loop.h"
  3. #include "os/os.h"
  4. #include "scene/main/node.h"
  5. #include "visual_script_nodes.h"
  6. //////////////////////////////////////////
  7. ////////////////CALL//////////////////////
  8. //////////////////////////////////////////
  9. int VisualScriptFunctionCall::get_output_sequence_port_count() const {
  10. return 1;
  11. }
  12. bool VisualScriptFunctionCall::has_input_sequence_port() const{
  13. return true;
  14. }
  15. #ifdef TOOLS_ENABLED
  16. static Node* _find_script_node(Node* p_edited_scene,Node* p_current_node,const Ref<Script> &script) {
  17. if (p_edited_scene!=p_current_node && p_current_node->get_owner()!=p_edited_scene)
  18. return NULL;
  19. Ref<Script> scr = p_current_node->get_script();
  20. if (scr.is_valid() && scr==script)
  21. return p_current_node;
  22. for(int i=0;i<p_current_node->get_child_count();i++) {
  23. Node *n = _find_script_node(p_edited_scene,p_current_node->get_child(i),script);
  24. if (n)
  25. return n;
  26. }
  27. return NULL;
  28. }
  29. #endif
  30. Node *VisualScriptFunctionCall::_get_base_node() const {
  31. #ifdef TOOLS_ENABLED
  32. Ref<Script> script = get_visual_script();
  33. if (!script.is_valid())
  34. return NULL;
  35. MainLoop * main_loop = OS::get_singleton()->get_main_loop();
  36. if (!main_loop)
  37. return NULL;
  38. SceneTree *scene_tree = main_loop->cast_to<SceneTree>();
  39. if (!scene_tree)
  40. return NULL;
  41. Node *edited_scene = scene_tree->get_edited_scene_root();
  42. if (!edited_scene)
  43. return NULL;
  44. Node* script_node = _find_script_node(edited_scene,edited_scene,script);
  45. if (!script_node)
  46. return NULL;
  47. if (!script_node->has_node(base_path))
  48. return NULL;
  49. Node *path_to = script_node->get_node(base_path);
  50. return path_to;
  51. #else
  52. return NULL;
  53. #endif
  54. }
  55. StringName VisualScriptFunctionCall::_get_base_type() const {
  56. if (call_mode==CALL_MODE_SELF && get_visual_script().is_valid())
  57. return get_visual_script()->get_instance_base_type();
  58. else if (call_mode==CALL_MODE_NODE_PATH && get_visual_script().is_valid()) {
  59. Node *path = _get_base_node();
  60. if (path)
  61. return path->get_type();
  62. }
  63. return base_type;
  64. }
  65. int VisualScriptFunctionCall::get_input_value_port_count() const{
  66. if (call_mode==CALL_MODE_BASIC_TYPE) {
  67. Vector<StringName> names = Variant::get_method_argument_names(basic_type,function);
  68. return names.size()+1;
  69. } else {
  70. MethodBind *mb = ObjectTypeDB::get_method(_get_base_type(),function);
  71. if (!mb)
  72. return 0;
  73. return mb->get_argument_count() + (call_mode==CALL_MODE_INSTANCE?1:0) - use_default_args;
  74. }
  75. }
  76. int VisualScriptFunctionCall::get_output_value_port_count() const{
  77. if (call_mode==CALL_MODE_BASIC_TYPE) {
  78. bool returns=false;
  79. Variant::get_method_return_type(basic_type,function,&returns);
  80. return returns?1:0;
  81. } else {
  82. MethodBind *mb = ObjectTypeDB::get_method(_get_base_type(),function);
  83. if (!mb)
  84. return 0;
  85. return mb->has_return() ? 1 : 0;
  86. }
  87. }
  88. String VisualScriptFunctionCall::get_output_sequence_port_text(int p_port) const {
  89. return String();
  90. }
  91. PropertyInfo VisualScriptFunctionCall::get_input_value_port_info(int p_idx) const{
  92. if (call_mode==CALL_MODE_INSTANCE || call_mode==CALL_MODE_BASIC_TYPE) {
  93. if (p_idx==0) {
  94. PropertyInfo pi;
  95. pi.type=(call_mode==CALL_MODE_INSTANCE?Variant::OBJECT:basic_type);
  96. pi.name=(call_mode==CALL_MODE_INSTANCE?String("instance"):Variant::get_type_name(basic_type).to_lower());
  97. return pi;
  98. } else {
  99. p_idx--;
  100. }
  101. }
  102. #ifdef DEBUG_METHODS_ENABLED
  103. if (call_mode==CALL_MODE_BASIC_TYPE) {
  104. Vector<StringName> names = Variant::get_method_argument_names(basic_type,function);
  105. Vector<Variant::Type> types = Variant::get_method_argument_types(basic_type,function);
  106. return PropertyInfo(types[p_idx],names[p_idx]);
  107. } else {
  108. MethodBind *mb = ObjectTypeDB::get_method(_get_base_type(),function);
  109. if (!mb)
  110. return PropertyInfo();
  111. return mb->get_argument_info(p_idx);
  112. }
  113. #else
  114. return PropertyInfo();
  115. #endif
  116. }
  117. PropertyInfo VisualScriptFunctionCall::get_output_value_port_info(int p_idx) const{
  118. #ifdef DEBUG_METHODS_ENABLED
  119. if (call_mode==CALL_MODE_BASIC_TYPE) {
  120. return PropertyInfo(Variant::get_method_return_type(basic_type,function),"");
  121. } else {
  122. MethodBind *mb = ObjectTypeDB::get_method(_get_base_type(),function);
  123. if (!mb)
  124. return PropertyInfo();
  125. PropertyInfo pi = mb->get_argument_info(-1);
  126. pi.name="";
  127. return pi;
  128. }
  129. #else
  130. return PropertyInfo();
  131. #endif
  132. }
  133. String VisualScriptFunctionCall::get_caption() const {
  134. static const char*cname[4]= {
  135. "CallSelf",
  136. "CallNode",
  137. "CallInstance",
  138. "CallBasic"
  139. };
  140. return cname[call_mode];
  141. }
  142. String VisualScriptFunctionCall::get_text() const {
  143. if (call_mode==CALL_MODE_SELF)
  144. return " "+String(function)+"()";
  145. else if (call_mode==CALL_MODE_BASIC_TYPE)
  146. return Variant::get_type_name(basic_type)+"."+String(function)+"()";
  147. else
  148. return " "+base_type+"."+String(function)+"()";
  149. }
  150. void VisualScriptFunctionCall::_update_defargs() {
  151. if (call_mode==CALL_MODE_BASIC_TYPE) {
  152. use_default_args = Variant::get_method_default_arguments(basic_type,function).size();
  153. } else {
  154. if (!get_visual_script().is_valid())
  155. return; //do not change if not valid yet
  156. MethodBind *mb = ObjectTypeDB::get_method(_get_base_type(),function);
  157. if (!mb)
  158. return;
  159. use_default_args=mb->get_default_argument_count();
  160. }
  161. }
  162. void VisualScriptFunctionCall::set_basic_type(Variant::Type p_type) {
  163. if (basic_type==p_type)
  164. return;
  165. basic_type=p_type;
  166. _update_defargs();
  167. _change_notify();
  168. emit_signal("ports_changed");
  169. }
  170. Variant::Type VisualScriptFunctionCall::get_basic_type() const{
  171. return basic_type;
  172. }
  173. void VisualScriptFunctionCall::set_base_type(const StringName& p_type) {
  174. if (base_type==p_type)
  175. return;
  176. base_type=p_type;
  177. _update_defargs();
  178. _change_notify();
  179. emit_signal("ports_changed");
  180. }
  181. StringName VisualScriptFunctionCall::get_base_type() const{
  182. return base_type;
  183. }
  184. void VisualScriptFunctionCall::set_function(const StringName& p_type){
  185. if (function==p_type)
  186. return;
  187. function=p_type;
  188. _update_defargs();
  189. _change_notify();
  190. emit_signal("ports_changed");
  191. }
  192. StringName VisualScriptFunctionCall::get_function() const {
  193. return function;
  194. }
  195. void VisualScriptFunctionCall::set_base_path(const NodePath& p_type) {
  196. if (base_path==p_type)
  197. return;
  198. base_path=p_type;
  199. _update_defargs();
  200. _change_notify();
  201. emit_signal("ports_changed");
  202. }
  203. NodePath VisualScriptFunctionCall::get_base_path() const {
  204. return base_path;
  205. }
  206. void VisualScriptFunctionCall::set_call_mode(CallMode p_mode) {
  207. if (call_mode==p_mode)
  208. return;
  209. call_mode=p_mode;
  210. _update_defargs();
  211. _change_notify();
  212. emit_signal("ports_changed");
  213. }
  214. VisualScriptFunctionCall::CallMode VisualScriptFunctionCall::get_call_mode() const {
  215. return call_mode;
  216. }
  217. void VisualScriptFunctionCall::set_use_default_args(int p_amount) {
  218. if (use_default_args==p_amount)
  219. return;
  220. use_default_args=p_amount;
  221. emit_signal("ports_changed");
  222. }
  223. int VisualScriptFunctionCall::get_use_default_args() const{
  224. return use_default_args;
  225. }
  226. void VisualScriptFunctionCall::_validate_property(PropertyInfo& property) const {
  227. if (property.name=="function/base_type") {
  228. if (call_mode!=CALL_MODE_INSTANCE) {
  229. property.usage=0;
  230. }
  231. }
  232. if (property.name=="function/basic_type") {
  233. if (call_mode!=CALL_MODE_BASIC_TYPE) {
  234. property.usage=0;
  235. }
  236. }
  237. if (property.name=="function/node_path") {
  238. if (call_mode!=CALL_MODE_NODE_PATH) {
  239. property.usage=0;
  240. } else {
  241. Node *bnode = _get_base_node();
  242. if (bnode) {
  243. property.hint_string=bnode->get_path(); //convert to loong string
  244. } else {
  245. }
  246. }
  247. }
  248. if (property.name=="function/function") {
  249. property.hint=PROPERTY_HINT_ENUM;
  250. List<MethodInfo> methods;
  251. if (call_mode==CALL_MODE_BASIC_TYPE) {
  252. if (basic_type==Variant::NIL) {
  253. property.usage=0;
  254. return; //nothing for nil
  255. }
  256. Variant::CallError ce;
  257. Variant v = Variant::construct(basic_type,NULL,0,ce);
  258. v.get_method_list(&methods);
  259. } else {
  260. StringName base = _get_base_type();
  261. ObjectTypeDB::get_method_list(base,&methods);
  262. }
  263. List<String> mstring;
  264. for (List<MethodInfo>::Element *E=methods.front();E;E=E->next()) {
  265. if (E->get().name.begins_with("_"))
  266. continue;
  267. mstring.push_back(E->get().name.get_slice(":",0));
  268. }
  269. mstring.sort();
  270. String ml;
  271. for (List<String>::Element *E=mstring.front();E;E=E->next()) {
  272. if (ml!=String())
  273. ml+=",";
  274. ml+=E->get();
  275. }
  276. property.hint_string=ml;
  277. }
  278. if (property.name=="function/use_default_args") {
  279. property.hint=PROPERTY_HINT_RANGE;
  280. int mc=0;
  281. if (call_mode==CALL_MODE_BASIC_TYPE) {
  282. mc = Variant::get_method_default_arguments(basic_type,function).size();
  283. } else {
  284. MethodBind *mb = ObjectTypeDB::get_method(_get_base_type(),function);
  285. if (mb) {
  286. mc=mb->get_default_argument_count();
  287. }
  288. }
  289. if (mc==0) {
  290. property.usage=0; //do not show
  291. } else {
  292. property.hint_string="0,"+itos(mc)+",1";
  293. }
  294. }
  295. }
  296. void VisualScriptFunctionCall::_bind_methods() {
  297. ObjectTypeDB::bind_method(_MD("set_base_type","base_type"),&VisualScriptFunctionCall::set_base_type);
  298. ObjectTypeDB::bind_method(_MD("get_base_type"),&VisualScriptFunctionCall::get_base_type);
  299. ObjectTypeDB::bind_method(_MD("set_basic_type","basic_type"),&VisualScriptFunctionCall::set_basic_type);
  300. ObjectTypeDB::bind_method(_MD("get_basic_type"),&VisualScriptFunctionCall::get_basic_type);
  301. ObjectTypeDB::bind_method(_MD("set_function","function"),&VisualScriptFunctionCall::set_function);
  302. ObjectTypeDB::bind_method(_MD("get_function"),&VisualScriptFunctionCall::get_function);
  303. ObjectTypeDB::bind_method(_MD("set_call_mode","mode"),&VisualScriptFunctionCall::set_call_mode);
  304. ObjectTypeDB::bind_method(_MD("get_call_mode"),&VisualScriptFunctionCall::get_call_mode);
  305. ObjectTypeDB::bind_method(_MD("set_base_path","base_path"),&VisualScriptFunctionCall::set_base_path);
  306. ObjectTypeDB::bind_method(_MD("get_base_path"),&VisualScriptFunctionCall::get_base_path);
  307. ObjectTypeDB::bind_method(_MD("set_use_default_args","amount"),&VisualScriptFunctionCall::set_use_default_args);
  308. ObjectTypeDB::bind_method(_MD("get_use_default_args"),&VisualScriptFunctionCall::get_use_default_args);
  309. String bt;
  310. for(int i=0;i<Variant::VARIANT_MAX;i++) {
  311. if (i>0)
  312. bt+=",";
  313. bt+=Variant::get_type_name(Variant::Type(i));
  314. }
  315. 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"));
  316. ADD_PROPERTY(PropertyInfo(Variant::STRING,"function/base_type",PROPERTY_HINT_TYPE_STRING,"Object"),_SCS("set_base_type"),_SCS("get_base_type"));
  317. ADD_PROPERTY(PropertyInfo(Variant::INT,"function/basic_type",PROPERTY_HINT_ENUM,bt),_SCS("set_basic_type"),_SCS("get_basic_type"));
  318. ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH,"function/node_path",PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE),_SCS("set_base_path"),_SCS("get_base_path"));
  319. ADD_PROPERTY(PropertyInfo(Variant::STRING,"function/function"),_SCS("set_function"),_SCS("get_function"));
  320. ADD_PROPERTY(PropertyInfo(Variant::INT,"function/use_default_args"),_SCS("set_use_default_args"),_SCS("get_use_default_args"));
  321. BIND_CONSTANT( CALL_MODE_SELF );
  322. BIND_CONSTANT( CALL_MODE_NODE_PATH);
  323. BIND_CONSTANT( CALL_MODE_INSTANCE);
  324. BIND_CONSTANT( CALL_MODE_BASIC_TYPE );
  325. }
  326. VisualScriptNodeInstance* VisualScriptFunctionCall::instance(VScriptInstance* p_instance) {
  327. return NULL;
  328. }
  329. VisualScriptFunctionCall::VisualScriptFunctionCall() {
  330. call_mode=CALL_MODE_INSTANCE;
  331. basic_type=Variant::NIL;
  332. use_default_args=0;
  333. base_type="Object";
  334. }
  335. template<VisualScriptFunctionCall::CallMode cmode>
  336. static Ref<VisualScriptNode> create_function_call_node(const String& p_name) {
  337. Ref<VisualScriptFunctionCall> node;
  338. node.instance();
  339. node->set_call_mode(cmode);
  340. return node;
  341. }
  342. //////////////////////////////////////////
  343. ////////////////SET//////////////////////
  344. //////////////////////////////////////////
  345. int VisualScriptPropertySet::get_output_sequence_port_count() const {
  346. return 1;
  347. }
  348. bool VisualScriptPropertySet::has_input_sequence_port() const{
  349. return true;
  350. }
  351. Node *VisualScriptPropertySet::_get_base_node() const {
  352. #ifdef TOOLS_ENABLED
  353. Ref<Script> script = get_visual_script();
  354. if (!script.is_valid())
  355. return NULL;
  356. MainLoop * main_loop = OS::get_singleton()->get_main_loop();
  357. if (!main_loop)
  358. return NULL;
  359. SceneTree *scene_tree = main_loop->cast_to<SceneTree>();
  360. if (!scene_tree)
  361. return NULL;
  362. Node *edited_scene = scene_tree->get_edited_scene_root();
  363. if (!edited_scene)
  364. return NULL;
  365. Node* script_node = _find_script_node(edited_scene,edited_scene,script);
  366. if (!script_node)
  367. return NULL;
  368. if (!script_node->has_node(base_path))
  369. return NULL;
  370. Node *path_to = script_node->get_node(base_path);
  371. return path_to;
  372. #else
  373. return NULL;
  374. #endif
  375. }
  376. StringName VisualScriptPropertySet::_get_base_type() const {
  377. if (call_mode==CALL_MODE_SELF && get_visual_script().is_valid())
  378. return get_visual_script()->get_instance_base_type();
  379. else if (call_mode==CALL_MODE_NODE_PATH && get_visual_script().is_valid()) {
  380. Node *path = _get_base_node();
  381. if (path)
  382. return path->get_type();
  383. }
  384. return base_type;
  385. }
  386. int VisualScriptPropertySet::get_input_value_port_count() const{
  387. int pc = (call_mode==CALL_MODE_BASIC_TYPE || call_mode==CALL_MODE_INSTANCE)?1:0;
  388. if (!use_builtin_value)
  389. pc++;
  390. return pc;
  391. }
  392. int VisualScriptPropertySet::get_output_value_port_count() const{
  393. return 0;
  394. }
  395. String VisualScriptPropertySet::get_output_sequence_port_text(int p_port) const {
  396. return String();
  397. }
  398. PropertyInfo VisualScriptPropertySet::get_input_value_port_info(int p_idx) const{
  399. if (call_mode==CALL_MODE_INSTANCE || call_mode==CALL_MODE_BASIC_TYPE) {
  400. if (p_idx==0) {
  401. PropertyInfo pi;
  402. pi.type=(call_mode==CALL_MODE_INSTANCE?Variant::OBJECT:basic_type);
  403. pi.name=(call_mode==CALL_MODE_INSTANCE?String("instance"):Variant::get_type_name(basic_type).to_lower());
  404. return pi;
  405. } else {
  406. p_idx--;
  407. }
  408. }
  409. #ifdef DEBUG_METHODS_ENABLED
  410. //not very efficient but..
  411. List<PropertyInfo> pinfo;
  412. if (call_mode==CALL_MODE_BASIC_TYPE) {
  413. Variant::CallError ce;
  414. Variant v = Variant::construct(basic_type,NULL,0,ce);
  415. v.get_property_list(&pinfo);
  416. } else if (call_mode==CALL_MODE_NODE_PATH) {
  417. Node *n = _get_base_node();
  418. if (n) {
  419. n->get_property_list(&pinfo);
  420. } else {
  421. ObjectTypeDB::get_property_list(_get_base_type(),&pinfo);
  422. }
  423. } else {
  424. ObjectTypeDB::get_property_list(_get_base_type(),&pinfo);
  425. }
  426. for (List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) {
  427. if (E->get().name==property) {
  428. PropertyInfo info=E->get();
  429. info.name="value";
  430. return info;
  431. }
  432. }
  433. #endif
  434. return PropertyInfo(Variant::NIL,"value");
  435. }
  436. PropertyInfo VisualScriptPropertySet::get_output_value_port_info(int p_idx) const{
  437. return PropertyInfo();
  438. }
  439. String VisualScriptPropertySet::get_caption() const {
  440. static const char*cname[4]= {
  441. "SelfSet",
  442. "NodeSet",
  443. "InstanceSet",
  444. "BasicSet"
  445. };
  446. return cname[call_mode];
  447. }
  448. String VisualScriptPropertySet::get_text() const {
  449. String prop;
  450. if (call_mode==CALL_MODE_BASIC_TYPE)
  451. prop=Variant::get_type_name(basic_type)+"."+property;
  452. else
  453. prop=property;
  454. if (use_builtin_value) {
  455. String bit = builtin_value.get_construct_string();
  456. if (bit.length()>40) {
  457. bit=bit.substr(0,40);
  458. bit+="...";
  459. }
  460. prop+="\n "+bit;
  461. }
  462. return prop;
  463. }
  464. void VisualScriptPropertySet::set_basic_type(Variant::Type p_type) {
  465. if (basic_type==p_type)
  466. return;
  467. basic_type=p_type;
  468. _change_notify();
  469. emit_signal("ports_changed");
  470. }
  471. Variant::Type VisualScriptPropertySet::get_basic_type() const{
  472. return basic_type;
  473. }
  474. void VisualScriptPropertySet::set_base_type(const StringName& p_type) {
  475. if (base_type==p_type)
  476. return;
  477. base_type=p_type;
  478. _change_notify();
  479. emit_signal("ports_changed");
  480. }
  481. StringName VisualScriptPropertySet::get_base_type() const{
  482. return base_type;
  483. }
  484. void VisualScriptPropertySet::set_property(const StringName& p_type){
  485. if (property==p_type)
  486. return;
  487. property=p_type;
  488. _change_notify();
  489. emit_signal("ports_changed");
  490. }
  491. StringName VisualScriptPropertySet::get_property() const {
  492. return property;
  493. }
  494. void VisualScriptPropertySet::set_base_path(const NodePath& p_type) {
  495. if (base_path==p_type)
  496. return;
  497. base_path=p_type;
  498. _change_notify();
  499. emit_signal("ports_changed");
  500. }
  501. NodePath VisualScriptPropertySet::get_base_path() const {
  502. return base_path;
  503. }
  504. void VisualScriptPropertySet::set_call_mode(CallMode p_mode) {
  505. if (call_mode==p_mode)
  506. return;
  507. call_mode=p_mode;
  508. _change_notify();
  509. emit_signal("ports_changed");
  510. }
  511. VisualScriptPropertySet::CallMode VisualScriptPropertySet::get_call_mode() const {
  512. return call_mode;
  513. }
  514. void VisualScriptPropertySet::set_use_builtin_value(bool p_use) {
  515. if (use_builtin_value==p_use)
  516. return;
  517. use_builtin_value=p_use;
  518. _change_notify();
  519. emit_signal("ports_changed");
  520. }
  521. bool VisualScriptPropertySet::is_using_builtin_value() const{
  522. return use_builtin_value;
  523. }
  524. void VisualScriptPropertySet::set_builtin_value(const Variant& p_value){
  525. if (builtin_value==p_value)
  526. return;
  527. builtin_value=p_value;
  528. }
  529. Variant VisualScriptPropertySet::get_builtin_value() const{
  530. return builtin_value;
  531. }
  532. void VisualScriptPropertySet::_validate_property(PropertyInfo& property) const {
  533. if (property.name=="property/base_type") {
  534. if (call_mode!=CALL_MODE_INSTANCE) {
  535. property.usage=0;
  536. }
  537. }
  538. if (property.name=="property/basic_type") {
  539. if (call_mode!=CALL_MODE_BASIC_TYPE) {
  540. property.usage=0;
  541. }
  542. }
  543. if (property.name=="property/node_path") {
  544. if (call_mode!=CALL_MODE_NODE_PATH) {
  545. property.usage=0;
  546. } else {
  547. Node *bnode = _get_base_node();
  548. if (bnode) {
  549. property.hint_string=bnode->get_path(); //convert to loong string
  550. } else {
  551. }
  552. }
  553. }
  554. if (property.name=="property/property") {
  555. property.hint=PROPERTY_HINT_ENUM;
  556. List<PropertyInfo> pinfo;
  557. if (call_mode==CALL_MODE_BASIC_TYPE) {
  558. Variant::CallError ce;
  559. Variant v = Variant::construct(basic_type,NULL,0,ce);
  560. v.get_property_list(&pinfo);
  561. } else if (call_mode==CALL_MODE_NODE_PATH) {
  562. Node *n = _get_base_node();
  563. if (n) {
  564. n->get_property_list(&pinfo);
  565. } else {
  566. ObjectTypeDB::get_property_list(_get_base_type(),&pinfo);
  567. }
  568. } else {
  569. ObjectTypeDB::get_property_list(_get_base_type(),&pinfo);
  570. }
  571. List<String> mstring;
  572. for (List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) {
  573. if (E->get().usage&PROPERTY_USAGE_EDITOR) {
  574. mstring.push_back(E->get().name);
  575. }
  576. }
  577. String ml;
  578. for (List<String>::Element *E=mstring.front();E;E=E->next()) {
  579. if (ml!=String())
  580. ml+=",";
  581. ml+=E->get();
  582. }
  583. if (ml==String()) {
  584. property.usage=PROPERTY_USAGE_NOEDITOR; //do not show for editing if empty
  585. } else {
  586. property.hint_string=ml;
  587. }
  588. }
  589. if (property.name=="value/builtin") {
  590. if (!use_builtin_value) {
  591. property.usage=0;
  592. } else {
  593. List<PropertyInfo> pinfo;
  594. if (call_mode==CALL_MODE_BASIC_TYPE) {
  595. Variant::CallError ce;
  596. Variant v = Variant::construct(basic_type,NULL,0,ce);
  597. v.get_property_list(&pinfo);
  598. } else if (call_mode==CALL_MODE_NODE_PATH) {
  599. Node *n = _get_base_node();
  600. if (n) {
  601. n->get_property_list(&pinfo);
  602. } else {
  603. ObjectTypeDB::get_property_list(_get_base_type(),&pinfo);
  604. }
  605. } else {
  606. ObjectTypeDB::get_property_list(_get_base_type(),&pinfo);
  607. }
  608. for (List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) {
  609. if (E->get().name==this->property) {
  610. property.hint=E->get().hint;
  611. property.type=E->get().type;
  612. property.hint_string=E->get().hint_string;
  613. }
  614. }
  615. }
  616. }
  617. }
  618. void VisualScriptPropertySet::_bind_methods() {
  619. ObjectTypeDB::bind_method(_MD("set_base_type","base_type"),&VisualScriptPropertySet::set_base_type);
  620. ObjectTypeDB::bind_method(_MD("get_base_type"),&VisualScriptPropertySet::get_base_type);
  621. ObjectTypeDB::bind_method(_MD("set_basic_type","basic_type"),&VisualScriptPropertySet::set_basic_type);
  622. ObjectTypeDB::bind_method(_MD("get_basic_type"),&VisualScriptPropertySet::get_basic_type);
  623. ObjectTypeDB::bind_method(_MD("set_property","property"),&VisualScriptPropertySet::set_property);
  624. ObjectTypeDB::bind_method(_MD("get_property"),&VisualScriptPropertySet::get_property);
  625. ObjectTypeDB::bind_method(_MD("set_call_mode","mode"),&VisualScriptPropertySet::set_call_mode);
  626. ObjectTypeDB::bind_method(_MD("get_call_mode"),&VisualScriptPropertySet::get_call_mode);
  627. ObjectTypeDB::bind_method(_MD("set_base_path","base_path"),&VisualScriptPropertySet::set_base_path);
  628. ObjectTypeDB::bind_method(_MD("get_base_path"),&VisualScriptPropertySet::get_base_path);
  629. ObjectTypeDB::bind_method(_MD("set_builtin_value","value"),&VisualScriptPropertySet::set_builtin_value);
  630. ObjectTypeDB::bind_method(_MD("get_builtin_value"),&VisualScriptPropertySet::get_builtin_value);
  631. ObjectTypeDB::bind_method(_MD("set_use_builtin_value","enable"),&VisualScriptPropertySet::set_use_builtin_value);
  632. ObjectTypeDB::bind_method(_MD("is_using_builtin_value"),&VisualScriptPropertySet::is_using_builtin_value);
  633. String bt;
  634. for(int i=0;i<Variant::VARIANT_MAX;i++) {
  635. if (i>0)
  636. bt+=",";
  637. bt+=Variant::get_type_name(Variant::Type(i));
  638. }
  639. 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"));
  640. ADD_PROPERTY(PropertyInfo(Variant::STRING,"property/base_type",PROPERTY_HINT_TYPE_STRING,"Object"),_SCS("set_base_type"),_SCS("get_base_type"));
  641. ADD_PROPERTY(PropertyInfo(Variant::INT,"property/basic_type",PROPERTY_HINT_ENUM,bt),_SCS("set_basic_type"),_SCS("get_basic_type"));
  642. ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH,"property/node_path",PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE),_SCS("set_base_path"),_SCS("get_base_path"));
  643. ADD_PROPERTY(PropertyInfo(Variant::STRING,"property/property"),_SCS("set_property"),_SCS("get_property"));
  644. ADD_PROPERTY(PropertyInfo(Variant::BOOL,"value/use_builtin"),_SCS("set_use_builtin_value"),_SCS("is_using_builtin_value"));
  645. ADD_PROPERTY(PropertyInfo(Variant::NIL,"value/builtin"),_SCS("set_builtin_value"),_SCS("get_builtin_value"));
  646. BIND_CONSTANT( CALL_MODE_SELF );
  647. BIND_CONSTANT( CALL_MODE_NODE_PATH);
  648. BIND_CONSTANT( CALL_MODE_INSTANCE);
  649. }
  650. VisualScriptNodeInstance* VisualScriptPropertySet::instance(VScriptInstance* p_instance) {
  651. return NULL;
  652. }
  653. VisualScriptPropertySet::VisualScriptPropertySet() {
  654. call_mode=CALL_MODE_INSTANCE;
  655. base_type="Object";
  656. basic_type=Variant::NIL;
  657. }
  658. template<VisualScriptPropertySet::CallMode cmode>
  659. static Ref<VisualScriptNode> create_property_set_node(const String& p_name) {
  660. Ref<VisualScriptPropertySet> node;
  661. node.instance();
  662. node->set_call_mode(cmode);
  663. return node;
  664. }
  665. //////////////////////////////////////////
  666. ////////////////GET//////////////////////
  667. //////////////////////////////////////////
  668. int VisualScriptPropertyGet::get_output_sequence_port_count() const {
  669. return 1;
  670. }
  671. bool VisualScriptPropertyGet::has_input_sequence_port() const{
  672. return true;
  673. }
  674. Node *VisualScriptPropertyGet::_get_base_node() const {
  675. #ifdef TOOLS_ENABLED
  676. Ref<Script> script = get_visual_script();
  677. if (!script.is_valid())
  678. return NULL;
  679. MainLoop * main_loop = OS::get_singleton()->get_main_loop();
  680. if (!main_loop)
  681. return NULL;
  682. SceneTree *scene_tree = main_loop->cast_to<SceneTree>();
  683. if (!scene_tree)
  684. return NULL;
  685. Node *edited_scene = scene_tree->get_edited_scene_root();
  686. if (!edited_scene)
  687. return NULL;
  688. Node* script_node = _find_script_node(edited_scene,edited_scene,script);
  689. if (!script_node)
  690. return NULL;
  691. if (!script_node->has_node(base_path))
  692. return NULL;
  693. Node *path_to = script_node->get_node(base_path);
  694. return path_to;
  695. #else
  696. return NULL;
  697. #endif
  698. }
  699. StringName VisualScriptPropertyGet::_get_base_type() const {
  700. if (call_mode==CALL_MODE_SELF && get_visual_script().is_valid())
  701. return get_visual_script()->get_instance_base_type();
  702. else if (call_mode==CALL_MODE_NODE_PATH && get_visual_script().is_valid()) {
  703. Node *path = _get_base_node();
  704. if (path)
  705. return path->get_type();
  706. }
  707. return base_type;
  708. }
  709. int VisualScriptPropertyGet::get_input_value_port_count() const{
  710. return (call_mode==CALL_MODE_BASIC_TYPE || call_mode==CALL_MODE_INSTANCE)?1:0;
  711. }
  712. int VisualScriptPropertyGet::get_output_value_port_count() const{
  713. return 1;
  714. }
  715. String VisualScriptPropertyGet::get_output_sequence_port_text(int p_port) const {
  716. return String();
  717. }
  718. PropertyInfo VisualScriptPropertyGet::get_input_value_port_info(int p_idx) const{
  719. if (call_mode==CALL_MODE_INSTANCE || call_mode==CALL_MODE_BASIC_TYPE) {
  720. if (p_idx==0) {
  721. PropertyInfo pi;
  722. pi.type=(call_mode==CALL_MODE_INSTANCE?Variant::OBJECT:basic_type);
  723. pi.name=(call_mode==CALL_MODE_INSTANCE?String("instance"):Variant::get_type_name(basic_type).to_lower());
  724. return pi;
  725. } else {
  726. p_idx--;
  727. }
  728. }
  729. return PropertyInfo();
  730. }
  731. PropertyInfo VisualScriptPropertyGet::get_output_value_port_info(int p_idx) const{
  732. #ifdef DEBUG_METHODS_ENABLED
  733. //not very efficient but..
  734. List<PropertyInfo> pinfo;
  735. if (call_mode==CALL_MODE_BASIC_TYPE) {
  736. Variant::CallError ce;
  737. Variant v = Variant::construct(basic_type,NULL,0,ce);
  738. v.get_property_list(&pinfo);
  739. } else if (call_mode==CALL_MODE_NODE_PATH) {
  740. Node *n = _get_base_node();
  741. if (n) {
  742. n->get_property_list(&pinfo);
  743. } else {
  744. ObjectTypeDB::get_property_list(_get_base_type(),&pinfo);
  745. }
  746. } else {
  747. ObjectTypeDB::get_property_list(_get_base_type(),&pinfo);
  748. }
  749. for (List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) {
  750. if (E->get().name==property) {
  751. PropertyInfo info=E->get();
  752. info.name="";
  753. return info;
  754. }
  755. }
  756. #endif
  757. return PropertyInfo(Variant::NIL,"");
  758. }
  759. String VisualScriptPropertyGet::get_caption() const {
  760. static const char*cname[4]= {
  761. "SelfGet",
  762. "NodeGet",
  763. "InstanceGet",
  764. "BasicGet"
  765. };
  766. return cname[call_mode];
  767. }
  768. String VisualScriptPropertyGet::get_text() const {
  769. if (call_mode==CALL_MODE_BASIC_TYPE)
  770. return Variant::get_type_name(basic_type)+"."+property;
  771. else
  772. return property;
  773. }
  774. void VisualScriptPropertyGet::set_base_type(const StringName& p_type) {
  775. if (base_type==p_type)
  776. return;
  777. base_type=p_type;
  778. _change_notify();
  779. emit_signal("ports_changed");
  780. }
  781. StringName VisualScriptPropertyGet::get_base_type() const{
  782. return base_type;
  783. }
  784. void VisualScriptPropertyGet::set_property(const StringName& p_type){
  785. if (property==p_type)
  786. return;
  787. property=p_type;
  788. _change_notify();
  789. emit_signal("ports_changed");
  790. }
  791. StringName VisualScriptPropertyGet::get_property() const {
  792. return property;
  793. }
  794. void VisualScriptPropertyGet::set_base_path(const NodePath& p_type) {
  795. if (base_path==p_type)
  796. return;
  797. base_path=p_type;
  798. _change_notify();
  799. emit_signal("ports_changed");
  800. }
  801. NodePath VisualScriptPropertyGet::get_base_path() const {
  802. return base_path;
  803. }
  804. void VisualScriptPropertyGet::set_call_mode(CallMode p_mode) {
  805. if (call_mode==p_mode)
  806. return;
  807. call_mode=p_mode;
  808. _change_notify();
  809. emit_signal("ports_changed");
  810. }
  811. VisualScriptPropertyGet::CallMode VisualScriptPropertyGet::get_call_mode() const {
  812. return call_mode;
  813. }
  814. void VisualScriptPropertyGet::set_basic_type(Variant::Type p_type) {
  815. if (basic_type==p_type)
  816. return;
  817. basic_type=p_type;
  818. _change_notify();
  819. emit_signal("ports_changed");
  820. }
  821. Variant::Type VisualScriptPropertyGet::get_basic_type() const{
  822. return basic_type;
  823. }
  824. void VisualScriptPropertyGet::_validate_property(PropertyInfo& property) const {
  825. if (property.name=="property/base_type") {
  826. if (call_mode!=CALL_MODE_INSTANCE) {
  827. property.usage=0;
  828. }
  829. }
  830. if (property.name=="property/basic_type") {
  831. if (call_mode!=CALL_MODE_BASIC_TYPE) {
  832. property.usage=0;
  833. }
  834. }
  835. if (property.name=="property/node_path") {
  836. if (call_mode!=CALL_MODE_NODE_PATH) {
  837. property.usage=0;
  838. } else {
  839. Node *bnode = _get_base_node();
  840. if (bnode) {
  841. property.hint_string=bnode->get_path(); //convert to loong string
  842. } else {
  843. }
  844. }
  845. }
  846. if (property.name=="property/property") {
  847. property.hint=PROPERTY_HINT_ENUM;
  848. List<PropertyInfo> pinfo;
  849. if (call_mode==CALL_MODE_BASIC_TYPE) {
  850. Variant::CallError ce;
  851. Variant v = Variant::construct(basic_type,NULL,0,ce);
  852. v.get_property_list(&pinfo);
  853. } else if (call_mode==CALL_MODE_NODE_PATH) {
  854. Node *n = _get_base_node();
  855. if (n) {
  856. n->get_property_list(&pinfo);
  857. } else {
  858. ObjectTypeDB::get_property_list(_get_base_type(),&pinfo);
  859. }
  860. } else {
  861. ObjectTypeDB::get_property_list(_get_base_type(),&pinfo);
  862. }
  863. List<String> mstring;
  864. for (List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) {
  865. if (E->get().usage&PROPERTY_USAGE_EDITOR)
  866. mstring.push_back(E->get().name);
  867. }
  868. String ml;
  869. for (List<String>::Element *E=mstring.front();E;E=E->next()) {
  870. if (ml!=String())
  871. ml+=",";
  872. ml+=E->get();
  873. }
  874. if (ml==String()) {
  875. property.usage=PROPERTY_USAGE_NOEDITOR; //do not show for editing if empty
  876. } else {
  877. property.hint_string=ml;
  878. }
  879. }
  880. }
  881. void VisualScriptPropertyGet::_bind_methods() {
  882. ObjectTypeDB::bind_method(_MD("set_base_type","base_type"),&VisualScriptPropertyGet::set_base_type);
  883. ObjectTypeDB::bind_method(_MD("get_base_type"),&VisualScriptPropertyGet::get_base_type);
  884. ObjectTypeDB::bind_method(_MD("set_basic_type","basic_type"),&VisualScriptPropertyGet::set_basic_type);
  885. ObjectTypeDB::bind_method(_MD("get_basic_type"),&VisualScriptPropertyGet::get_basic_type);
  886. ObjectTypeDB::bind_method(_MD("set_property","property"),&VisualScriptPropertyGet::set_property);
  887. ObjectTypeDB::bind_method(_MD("get_property"),&VisualScriptPropertyGet::get_property);
  888. ObjectTypeDB::bind_method(_MD("set_call_mode","mode"),&VisualScriptPropertyGet::set_call_mode);
  889. ObjectTypeDB::bind_method(_MD("get_call_mode"),&VisualScriptPropertyGet::get_call_mode);
  890. ObjectTypeDB::bind_method(_MD("set_base_path","base_path"),&VisualScriptPropertyGet::set_base_path);
  891. ObjectTypeDB::bind_method(_MD("get_base_path"),&VisualScriptPropertyGet::get_base_path);
  892. String bt;
  893. for(int i=0;i<Variant::VARIANT_MAX;i++) {
  894. if (i>0)
  895. bt+=",";
  896. bt+=Variant::get_type_name(Variant::Type(i));
  897. }
  898. 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"));
  899. ADD_PROPERTY(PropertyInfo(Variant::STRING,"property/base_type",PROPERTY_HINT_TYPE_STRING,"Object"),_SCS("set_base_type"),_SCS("get_base_type"));
  900. ADD_PROPERTY(PropertyInfo(Variant::INT,"property/basic_type",PROPERTY_HINT_ENUM,bt),_SCS("set_basic_type"),_SCS("get_basic_type"));
  901. ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH,"property/node_path",PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE),_SCS("set_base_path"),_SCS("get_base_path"));
  902. ADD_PROPERTY(PropertyInfo(Variant::STRING,"property/property"),_SCS("set_property"),_SCS("get_property"));
  903. BIND_CONSTANT( CALL_MODE_SELF );
  904. BIND_CONSTANT( CALL_MODE_NODE_PATH);
  905. BIND_CONSTANT( CALL_MODE_INSTANCE);
  906. }
  907. VisualScriptNodeInstance* VisualScriptPropertyGet::instance(VScriptInstance* p_instance) {
  908. return NULL;
  909. }
  910. VisualScriptPropertyGet::VisualScriptPropertyGet() {
  911. call_mode=CALL_MODE_INSTANCE;
  912. base_type="Object";
  913. basic_type=Variant::NIL;
  914. }
  915. template<VisualScriptPropertyGet::CallMode cmode>
  916. static Ref<VisualScriptNode> create_property_get_node(const String& p_name) {
  917. Ref<VisualScriptPropertyGet> node;
  918. node.instance();
  919. node->set_call_mode(cmode);
  920. return node;
  921. }
  922. //////////////////////////////////////////
  923. ////////////////SCRIPT CALL//////////////////////
  924. //////////////////////////////////////////
  925. int VisualScriptScriptCall::get_output_sequence_port_count() const {
  926. return 1;
  927. }
  928. bool VisualScriptScriptCall::has_input_sequence_port() const{
  929. return true;
  930. }
  931. Node *VisualScriptScriptCall::_get_base_node() const {
  932. #ifdef TOOLS_ENABLED
  933. Ref<Script> script = get_visual_script();
  934. if (!script.is_valid())
  935. return NULL;
  936. MainLoop * main_loop = OS::get_singleton()->get_main_loop();
  937. if (!main_loop)
  938. return NULL;
  939. SceneTree *scene_tree = main_loop->cast_to<SceneTree>();
  940. if (!scene_tree)
  941. return NULL;
  942. Node *edited_scene = scene_tree->get_edited_scene_root();
  943. if (!edited_scene)
  944. return NULL;
  945. Node* script_node = _find_script_node(edited_scene,edited_scene,script);
  946. if (!script_node)
  947. return NULL;
  948. if (!script_node->has_node(base_path))
  949. return NULL;
  950. Node *path_to = script_node->get_node(base_path);
  951. return path_to;
  952. #else
  953. return NULL;
  954. #endif
  955. }
  956. int VisualScriptScriptCall::get_input_value_port_count() const{
  957. if (call_mode==CALL_MODE_SELF) {
  958. Ref<VisualScript> vs = get_visual_script();
  959. if (vs.is_valid()) {
  960. if (!vs->has_function(function))
  961. return 0;
  962. int id = vs->get_function_node_id(function);
  963. if (id<0)
  964. return 0;
  965. Ref<VisualScriptFunction> func = vs->get_node(function,id);
  966. return func->get_argument_count();
  967. }
  968. } else {
  969. Node*base = _get_base_node();
  970. if (!base)
  971. return 0;
  972. Ref<Script> script = base->get_script();
  973. if (!script.is_valid())
  974. return 0;
  975. List<MethodInfo> functions;
  976. script->get_method_list(&functions);
  977. for (List<MethodInfo>::Element *E=functions.front();E;E=E->next()) {
  978. if (E->get().name==function) {
  979. return E->get().arguments.size();
  980. }
  981. }
  982. }
  983. return 0;
  984. }
  985. int VisualScriptScriptCall::get_output_value_port_count() const{
  986. return 1;
  987. }
  988. String VisualScriptScriptCall::get_output_sequence_port_text(int p_port) const {
  989. return String();
  990. }
  991. PropertyInfo VisualScriptScriptCall::get_input_value_port_info(int p_idx) const{
  992. if (call_mode==CALL_MODE_SELF) {
  993. Ref<VisualScript> vs = get_visual_script();
  994. if (vs.is_valid()) {
  995. if (!vs->has_function(function))
  996. return PropertyInfo();
  997. int id = vs->get_function_node_id(function);
  998. if (id<0)
  999. return PropertyInfo();
  1000. Ref<VisualScriptFunction> func = vs->get_node(function,id);
  1001. if (p_idx>=func->get_argument_count())
  1002. return PropertyInfo();
  1003. return PropertyInfo(func->get_argument_type(p_idx),func->get_argument_name(p_idx));
  1004. }
  1005. } else {
  1006. Node*base = _get_base_node();
  1007. if (!base)
  1008. return PropertyInfo();
  1009. Ref<Script> script = base->get_script();
  1010. if (!script.is_valid())
  1011. return PropertyInfo();
  1012. List<MethodInfo> functions;
  1013. script->get_method_list(&functions);
  1014. for (List<MethodInfo>::Element *E=functions.front();E;E=E->next()) {
  1015. if (E->get().name==function) {
  1016. if (p_idx<0 || p_idx>=E->get().arguments.size())
  1017. return PropertyInfo();
  1018. return E->get().arguments[p_idx];
  1019. }
  1020. }
  1021. }
  1022. return PropertyInfo();
  1023. }
  1024. PropertyInfo VisualScriptScriptCall::get_output_value_port_info(int p_idx) const{
  1025. return PropertyInfo();
  1026. }
  1027. String VisualScriptScriptCall::get_caption() const {
  1028. return "ScriptCall";
  1029. }
  1030. String VisualScriptScriptCall::get_text() const {
  1031. return " "+String(function)+"()";
  1032. }
  1033. void VisualScriptScriptCall::set_function(const StringName& p_type){
  1034. if (function==p_type)
  1035. return;
  1036. function=p_type;
  1037. _change_notify();
  1038. emit_signal("ports_changed");
  1039. }
  1040. StringName VisualScriptScriptCall::get_function() const {
  1041. return function;
  1042. }
  1043. void VisualScriptScriptCall::set_base_path(const NodePath& p_type) {
  1044. if (base_path==p_type)
  1045. return;
  1046. base_path=p_type;
  1047. _change_notify();
  1048. emit_signal("ports_changed");
  1049. }
  1050. NodePath VisualScriptScriptCall::get_base_path() const {
  1051. return base_path;
  1052. }
  1053. void VisualScriptScriptCall::set_call_mode(CallMode p_mode) {
  1054. if (call_mode==p_mode)
  1055. return;
  1056. call_mode=p_mode;
  1057. _change_notify();
  1058. emit_signal("ports_changed");
  1059. }
  1060. VisualScriptScriptCall::CallMode VisualScriptScriptCall::get_call_mode() const {
  1061. return call_mode;
  1062. }
  1063. void VisualScriptScriptCall::_validate_property(PropertyInfo& property) const {
  1064. if (property.name=="function/node_path") {
  1065. if (call_mode!=CALL_MODE_NODE_PATH) {
  1066. property.usage=0;
  1067. } else {
  1068. Node *bnode = _get_base_node();
  1069. if (bnode) {
  1070. property.hint_string=bnode->get_path(); //convert to loong string
  1071. } else {
  1072. }
  1073. }
  1074. }
  1075. if (property.name=="function/function") {
  1076. property.hint=PROPERTY_HINT_ENUM;
  1077. List<MethodInfo> methods;
  1078. if (call_mode==CALL_MODE_SELF) {
  1079. Ref<VisualScript> vs = get_visual_script();
  1080. if (vs.is_valid()) {
  1081. vs->get_method_list(&methods);
  1082. }
  1083. } else {
  1084. Node*base = _get_base_node();
  1085. if (!base)
  1086. return;
  1087. Ref<Script> script = base->get_script();
  1088. if (!script.is_valid())
  1089. return;
  1090. script->get_method_list(&methods);
  1091. }
  1092. List<String> mstring;
  1093. for (List<MethodInfo>::Element *E=methods.front();E;E=E->next()) {
  1094. if (E->get().name.begins_with("_"))
  1095. continue;
  1096. mstring.push_back(E->get().name.get_slice(":",0));
  1097. }
  1098. mstring.sort();
  1099. String ml;
  1100. for (List<String>::Element *E=mstring.front();E;E=E->next()) {
  1101. if (ml!=String())
  1102. ml+=",";
  1103. ml+=E->get();
  1104. }
  1105. property.hint_string=ml;
  1106. }
  1107. }
  1108. void VisualScriptScriptCall::_bind_methods() {
  1109. ObjectTypeDB::bind_method(_MD("set_function","function"),&VisualScriptScriptCall::set_function);
  1110. ObjectTypeDB::bind_method(_MD("get_function"),&VisualScriptScriptCall::get_function);
  1111. ObjectTypeDB::bind_method(_MD("set_call_mode","mode"),&VisualScriptScriptCall::set_call_mode);
  1112. ObjectTypeDB::bind_method(_MD("get_call_mode"),&VisualScriptScriptCall::get_call_mode);
  1113. ObjectTypeDB::bind_method(_MD("set_base_path","base_path"),&VisualScriptScriptCall::set_base_path);
  1114. ObjectTypeDB::bind_method(_MD("get_base_path"),&VisualScriptScriptCall::get_base_path);
  1115. ADD_PROPERTY(PropertyInfo(Variant::INT,"function/call_mode",PROPERTY_HINT_ENUM,"Self,Node Path"),_SCS("set_call_mode"),_SCS("get_call_mode"));
  1116. ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH,"function/node_path",PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE),_SCS("set_base_path"),_SCS("get_base_path"));
  1117. ADD_PROPERTY(PropertyInfo(Variant::STRING,"function/function"),_SCS("set_function"),_SCS("get_function"));
  1118. BIND_CONSTANT( CALL_MODE_SELF );
  1119. BIND_CONSTANT( CALL_MODE_NODE_PATH);
  1120. }
  1121. VisualScriptNodeInstance* VisualScriptScriptCall::instance(VScriptInstance* p_instance) {
  1122. return NULL;
  1123. }
  1124. VisualScriptScriptCall::VisualScriptScriptCall() {
  1125. call_mode=CALL_MODE_SELF;
  1126. }
  1127. template<VisualScriptScriptCall::CallMode cmode>
  1128. static Ref<VisualScriptNode> create_script_call_node(const String& p_name) {
  1129. Ref<VisualScriptScriptCall> node;
  1130. node.instance();
  1131. node->set_call_mode(cmode);
  1132. return node;
  1133. }
  1134. //////////////////////////////////////////
  1135. ////////////////SCRIPT CALL//////////////////////
  1136. //////////////////////////////////////////
  1137. int VisualScriptEmitSignal::get_output_sequence_port_count() const {
  1138. return 1;
  1139. }
  1140. bool VisualScriptEmitSignal::has_input_sequence_port() const{
  1141. return true;
  1142. }
  1143. int VisualScriptEmitSignal::get_input_value_port_count() const{
  1144. Ref<VisualScript> vs = get_visual_script();
  1145. if (vs.is_valid()) {
  1146. if (!vs->has_custom_signal(name))
  1147. return 0;
  1148. return vs->custom_signal_get_argument_count(name);
  1149. }
  1150. return 0;
  1151. }
  1152. int VisualScriptEmitSignal::get_output_value_port_count() const{
  1153. return 0;
  1154. }
  1155. String VisualScriptEmitSignal::get_output_sequence_port_text(int p_port) const {
  1156. return String();
  1157. }
  1158. PropertyInfo VisualScriptEmitSignal::get_input_value_port_info(int p_idx) const{
  1159. Ref<VisualScript> vs = get_visual_script();
  1160. if (vs.is_valid()) {
  1161. if (!vs->has_custom_signal(name))
  1162. return PropertyInfo();
  1163. return PropertyInfo(vs->custom_signal_get_argument_type(name,p_idx),vs->custom_signal_get_argument_name(name,p_idx));
  1164. }
  1165. return PropertyInfo();
  1166. }
  1167. PropertyInfo VisualScriptEmitSignal::get_output_value_port_info(int p_idx) const{
  1168. return PropertyInfo();
  1169. }
  1170. String VisualScriptEmitSignal::get_caption() const {
  1171. return "EmitSignal";
  1172. }
  1173. String VisualScriptEmitSignal::get_text() const {
  1174. return "emit "+String(name);
  1175. }
  1176. void VisualScriptEmitSignal::set_signal(const StringName& p_type){
  1177. if (name==p_type)
  1178. return;
  1179. name=p_type;
  1180. _change_notify();
  1181. emit_signal("ports_changed");
  1182. }
  1183. StringName VisualScriptEmitSignal::get_signal() const {
  1184. return name;
  1185. }
  1186. void VisualScriptEmitSignal::_validate_property(PropertyInfo& property) const {
  1187. if (property.name=="signal/signal") {
  1188. property.hint=PROPERTY_HINT_ENUM;
  1189. List<StringName> sigs;
  1190. Ref<VisualScript> vs = get_visual_script();
  1191. if (vs.is_valid()) {
  1192. vs->get_custom_signal_list(&sigs);
  1193. }
  1194. String ml;
  1195. for (List<StringName>::Element *E=sigs.front();E;E=E->next()) {
  1196. if (ml!=String())
  1197. ml+=",";
  1198. ml+=E->get();
  1199. }
  1200. property.hint_string=ml;
  1201. }
  1202. }
  1203. void VisualScriptEmitSignal::_bind_methods() {
  1204. ObjectTypeDB::bind_method(_MD("set_signal","name"),&VisualScriptEmitSignal::set_signal);
  1205. ObjectTypeDB::bind_method(_MD("get_signal"),&VisualScriptEmitSignal::get_signal);
  1206. ADD_PROPERTY(PropertyInfo(Variant::STRING,"signal/signal"),_SCS("set_signal"),_SCS("get_signal"));
  1207. }
  1208. VisualScriptNodeInstance* VisualScriptEmitSignal::instance(VScriptInstance* p_instance) {
  1209. return NULL;
  1210. }
  1211. VisualScriptEmitSignal::VisualScriptEmitSignal() {
  1212. }
  1213. void register_visual_script_func_nodes() {
  1214. VisualScriptLanguage::singleton->add_register_func("functions/call_method/instance_call",create_function_call_node<VisualScriptFunctionCall::CALL_MODE_INSTANCE>);
  1215. VisualScriptLanguage::singleton->add_register_func("functions/call_method/basic_type_call",create_function_call_node<VisualScriptFunctionCall::CALL_MODE_BASIC_TYPE>);
  1216. VisualScriptLanguage::singleton->add_register_func("functions/call_method/self_call",create_function_call_node<VisualScriptFunctionCall::CALL_MODE_SELF>);
  1217. VisualScriptLanguage::singleton->add_register_func("functions/call_method/node_call",create_function_call_node<VisualScriptFunctionCall::CALL_MODE_NODE_PATH>);
  1218. VisualScriptLanguage::singleton->add_register_func("functions/set_property/instace_set",create_property_set_node<VisualScriptPropertySet::CALL_MODE_INSTANCE>);
  1219. VisualScriptLanguage::singleton->add_register_func("functions/set_property/basic_type_set",create_property_set_node<VisualScriptPropertySet::CALL_MODE_BASIC_TYPE>);
  1220. VisualScriptLanguage::singleton->add_register_func("functions/set_property/self_set",create_property_set_node<VisualScriptPropertySet::CALL_MODE_SELF>);
  1221. VisualScriptLanguage::singleton->add_register_func("functions/set_property/node_set",create_property_set_node<VisualScriptPropertySet::CALL_MODE_NODE_PATH>);
  1222. VisualScriptLanguage::singleton->add_register_func("functions/get_property/instance_get",create_property_get_node<VisualScriptPropertyGet::CALL_MODE_INSTANCE>);
  1223. VisualScriptLanguage::singleton->add_register_func("functions/get_property/basic_type_get",create_property_get_node<VisualScriptPropertyGet::CALL_MODE_BASIC_TYPE>);
  1224. VisualScriptLanguage::singleton->add_register_func("functions/get_property/self_get",create_property_get_node<VisualScriptPropertyGet::CALL_MODE_SELF>);
  1225. VisualScriptLanguage::singleton->add_register_func("functions/get_property/node_get",create_property_get_node<VisualScriptPropertyGet::CALL_MODE_NODE_PATH>);
  1226. VisualScriptLanguage::singleton->add_register_func("functions/script/script_call",create_script_call_node<VisualScriptScriptCall::CALL_MODE_SELF>);
  1227. VisualScriptLanguage::singleton->add_register_func("functions/script/script_call_in_node",create_script_call_node<VisualScriptScriptCall::CALL_MODE_NODE_PATH>);
  1228. VisualScriptLanguage::singleton->add_register_func("functions/script/emit_signal",create_node_generic<VisualScriptEmitSignal>);
  1229. }