visual_script_editor.cpp 107 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413
  1. /*************************************************************************/
  2. /* visual_script_editor.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "visual_script_editor.h"
  31. #include "editor/editor_node.h"
  32. #include "editor/editor_resource_preview.h"
  33. #include "os/input.h"
  34. #include "os/keyboard.h"
  35. #include "visual_script_expression.h"
  36. #include "visual_script_flow_control.h"
  37. #include "visual_script_func_nodes.h"
  38. #include "visual_script_nodes.h"
  39. #ifdef TOOLS_ENABLED
  40. class VisualScriptEditorSignalEdit : public Object {
  41. GDCLASS(VisualScriptEditorSignalEdit, Object)
  42. StringName sig;
  43. public:
  44. UndoRedo *undo_redo;
  45. Ref<VisualScript> script;
  46. protected:
  47. static void _bind_methods() {
  48. ClassDB::bind_method("_sig_changed", &VisualScriptEditorSignalEdit::_sig_changed);
  49. ADD_SIGNAL(MethodInfo("changed"));
  50. }
  51. void _sig_changed() {
  52. _change_notify();
  53. emit_signal("changed");
  54. }
  55. bool _set(const StringName &p_name, const Variant &p_value) {
  56. if (sig == StringName())
  57. return false;
  58. if (p_name == "argument_count") {
  59. int new_argc = p_value;
  60. int argc = script->custom_signal_get_argument_count(sig);
  61. if (argc == new_argc)
  62. return true;
  63. undo_redo->create_action(TTR("Change Signal Arguments"));
  64. if (new_argc < argc) {
  65. for (int i = new_argc; i < argc; i++) {
  66. undo_redo->add_do_method(script.ptr(), "custom_signal_remove_argument", sig, new_argc);
  67. undo_redo->add_undo_method(script.ptr(), "custom_signal_add_argument", sig, script->custom_signal_get_argument_name(sig, i), script->custom_signal_get_argument_type(sig, i), -1);
  68. }
  69. } else if (new_argc > argc) {
  70. for (int i = argc; i < new_argc; i++) {
  71. undo_redo->add_do_method(script.ptr(), "custom_signal_add_argument", sig, Variant::NIL, "arg" + itos(i + 1), -1);
  72. undo_redo->add_undo_method(script.ptr(), "custom_signal_remove_argument", sig, argc);
  73. }
  74. }
  75. undo_redo->add_do_method(this, "_sig_changed");
  76. undo_redo->add_undo_method(this, "_sig_changed");
  77. undo_redo->commit_action();
  78. return true;
  79. }
  80. if (String(p_name).begins_with("argument/")) {
  81. int idx = String(p_name).get_slice("/", 1).to_int() - 1;
  82. ERR_FAIL_INDEX_V(idx, script->custom_signal_get_argument_count(sig), false);
  83. String what = String(p_name).get_slice("/", 2);
  84. if (what == "type") {
  85. int old_type = script->custom_signal_get_argument_type(sig, idx);
  86. int new_type = p_value;
  87. undo_redo->create_action(TTR("Change Argument Type"));
  88. undo_redo->add_do_method(script.ptr(), "custom_signal_set_argument_type", sig, idx, new_type);
  89. undo_redo->add_undo_method(script.ptr(), "custom_signal_set_argument_type", sig, idx, old_type);
  90. undo_redo->commit_action();
  91. return true;
  92. }
  93. if (what == "name") {
  94. String old_name = script->custom_signal_get_argument_name(sig, idx);
  95. String new_name = p_value;
  96. undo_redo->create_action(TTR("Change Argument name"));
  97. undo_redo->add_do_method(script.ptr(), "custom_signal_set_argument_name", sig, idx, new_name);
  98. undo_redo->add_undo_method(script.ptr(), "custom_signal_set_argument_name", sig, idx, old_name);
  99. undo_redo->commit_action();
  100. return true;
  101. }
  102. }
  103. return false;
  104. }
  105. bool _get(const StringName &p_name, Variant &r_ret) const {
  106. if (sig == StringName())
  107. return false;
  108. if (p_name == "argument_count") {
  109. r_ret = script->custom_signal_get_argument_count(sig);
  110. return true;
  111. }
  112. if (String(p_name).begins_with("argument/")) {
  113. int idx = String(p_name).get_slice("/", 1).to_int() - 1;
  114. ERR_FAIL_INDEX_V(idx, script->custom_signal_get_argument_count(sig), false);
  115. String what = String(p_name).get_slice("/", 2);
  116. if (what == "type") {
  117. r_ret = script->custom_signal_get_argument_type(sig, idx);
  118. return true;
  119. }
  120. if (what == "name") {
  121. r_ret = script->custom_signal_get_argument_name(sig, idx);
  122. return true;
  123. }
  124. }
  125. return false;
  126. }
  127. void _get_property_list(List<PropertyInfo> *p_list) const {
  128. if (sig == StringName())
  129. return;
  130. p_list->push_back(PropertyInfo(Variant::INT, "argument_count", PROPERTY_HINT_RANGE, "0,256"));
  131. String argt = "Variant";
  132. for (int i = 1; i < Variant::VARIANT_MAX; i++) {
  133. argt += "," + Variant::get_type_name(Variant::Type(i));
  134. }
  135. for (int i = 0; i < script->custom_signal_get_argument_count(sig); i++) {
  136. p_list->push_back(PropertyInfo(Variant::INT, "argument/" + itos(i + 1) + "/type", PROPERTY_HINT_ENUM, argt));
  137. p_list->push_back(PropertyInfo(Variant::STRING, "argument/" + itos(i + 1) + "/name"));
  138. }
  139. }
  140. public:
  141. void edit(const StringName &p_sig) {
  142. sig = p_sig;
  143. _change_notify();
  144. }
  145. VisualScriptEditorSignalEdit() { undo_redo = NULL; }
  146. };
  147. class VisualScriptEditorVariableEdit : public Object {
  148. GDCLASS(VisualScriptEditorVariableEdit, Object)
  149. StringName var;
  150. public:
  151. UndoRedo *undo_redo;
  152. Ref<VisualScript> script;
  153. protected:
  154. static void _bind_methods() {
  155. ClassDB::bind_method("_var_changed", &VisualScriptEditorVariableEdit::_var_changed);
  156. ClassDB::bind_method("_var_value_changed", &VisualScriptEditorVariableEdit::_var_value_changed);
  157. ADD_SIGNAL(MethodInfo("changed"));
  158. }
  159. void _var_changed() {
  160. _change_notify();
  161. emit_signal("changed");
  162. }
  163. void _var_value_changed() {
  164. _change_notify("value"); //so the whole tree is not redrawn, makes editing smoother in general
  165. emit_signal("changed");
  166. }
  167. bool _set(const StringName &p_name, const Variant &p_value) {
  168. if (var == StringName())
  169. return false;
  170. if (String(p_name) == "value") {
  171. undo_redo->create_action(TTR("Set Variable Default Value"));
  172. Variant current = script->get_variable_default_value(var);
  173. undo_redo->add_do_method(script.ptr(), "set_variable_default_value", var, p_value);
  174. undo_redo->add_undo_method(script.ptr(), "set_variable_default_value", var, current);
  175. undo_redo->add_do_method(this, "_var_value_changed");
  176. undo_redo->add_undo_method(this, "_var_value_changed");
  177. undo_redo->commit_action();
  178. return true;
  179. }
  180. Dictionary d = script->call("get_variable_info", var);
  181. if (String(p_name) == "type") {
  182. Dictionary dc = d.copy();
  183. dc["type"] = p_value;
  184. undo_redo->create_action(TTR("Set Variable Type"));
  185. undo_redo->add_do_method(script.ptr(), "set_variable_info", var, dc);
  186. undo_redo->add_undo_method(script.ptr(), "set_variable_info", var, d);
  187. undo_redo->add_do_method(this, "_var_changed");
  188. undo_redo->add_undo_method(this, "_var_changed");
  189. undo_redo->commit_action();
  190. return true;
  191. }
  192. if (String(p_name) == "hint") {
  193. Dictionary dc = d.copy();
  194. dc["hint"] = p_value;
  195. undo_redo->create_action(TTR("Set Variable Type"));
  196. undo_redo->add_do_method(script.ptr(), "set_variable_info", var, dc);
  197. undo_redo->add_undo_method(script.ptr(), "set_variable_info", var, d);
  198. undo_redo->add_do_method(this, "_var_changed");
  199. undo_redo->add_undo_method(this, "_var_changed");
  200. undo_redo->commit_action();
  201. return true;
  202. }
  203. if (String(p_name) == "hint_string") {
  204. Dictionary dc = d.copy();
  205. dc["hint_string"] = p_value;
  206. undo_redo->create_action(TTR("Set Variable Type"));
  207. undo_redo->add_do_method(script.ptr(), "set_variable_info", var, dc);
  208. undo_redo->add_undo_method(script.ptr(), "set_variable_info", var, d);
  209. undo_redo->add_do_method(this, "_var_changed");
  210. undo_redo->add_undo_method(this, "_var_changed");
  211. undo_redo->commit_action();
  212. return true;
  213. }
  214. if (String(p_name) == "export") {
  215. script->set_variable_export(var, p_value);
  216. EditorNode::get_singleton()->get_property_editor()->update_tree();
  217. return true;
  218. }
  219. return false;
  220. }
  221. bool _get(const StringName &p_name, Variant &r_ret) const {
  222. if (var == StringName())
  223. return false;
  224. if (String(p_name) == "value") {
  225. r_ret = script->get_variable_default_value(var);
  226. return true;
  227. }
  228. PropertyInfo pinfo = script->get_variable_info(var);
  229. if (String(p_name) == "type") {
  230. r_ret = pinfo.type;
  231. return true;
  232. }
  233. if (String(p_name) == "hint") {
  234. r_ret = pinfo.hint;
  235. return true;
  236. }
  237. if (String(p_name) == "hint_string") {
  238. r_ret = pinfo.hint_string;
  239. return true;
  240. }
  241. if (String(p_name) == "export") {
  242. r_ret = script->get_variable_export(var);
  243. return true;
  244. }
  245. return false;
  246. }
  247. void _get_property_list(List<PropertyInfo> *p_list) const {
  248. if (var == StringName())
  249. return;
  250. String argt = "Variant";
  251. for (int i = 1; i < Variant::VARIANT_MAX; i++) {
  252. argt += "," + Variant::get_type_name(Variant::Type(i));
  253. }
  254. p_list->push_back(PropertyInfo(Variant::INT, "type", PROPERTY_HINT_ENUM, argt));
  255. p_list->push_back(PropertyInfo(script->get_variable_info(var).type, "value", script->get_variable_info(var).hint, script->get_variable_info(var).hint_string, PROPERTY_USAGE_DEFAULT));
  256. p_list->push_back(PropertyInfo(Variant::INT, "hint", PROPERTY_HINT_ENUM, "None,Range,ExpRange,Enum,ExpEasing,Length,SpriteFrame,KeyAccel,BitFlags,AllFlags,File,Dir,GlobalFile,GlobalDir,ResourceType,MultilineText"));
  257. p_list->push_back(PropertyInfo(Variant::STRING, "hint_string"));
  258. p_list->push_back(PropertyInfo(Variant::BOOL, "export"));
  259. }
  260. public:
  261. void edit(const StringName &p_var) {
  262. var = p_var;
  263. _change_notify();
  264. }
  265. VisualScriptEditorVariableEdit() { undo_redo = NULL; }
  266. };
  267. static Color _color_from_type(Variant::Type p_type) {
  268. Color color;
  269. switch (p_type) {
  270. case Variant::NIL: color = Color::html("69ecbd"); break;
  271. case Variant::BOOL: color = Color::html("8da6f0"); break;
  272. case Variant::INT: color = Color::html("7dc6ef"); break;
  273. case Variant::REAL: color = Color::html("61daf4"); break;
  274. case Variant::STRING: color = Color::html("6ba7ec"); break;
  275. case Variant::VECTOR2: color = Color::html("bd91f1"); break;
  276. case Variant::RECT2: color = Color::html("f191a5"); break;
  277. case Variant::VECTOR3: color = Color::html("d67dee"); break;
  278. case Variant::TRANSFORM2D: color = Color::html("c4ec69"); break;
  279. case Variant::PLANE: color = Color::html("f77070"); break;
  280. case Variant::QUAT: color = Color::html("ec69a3"); break;
  281. case Variant::RECT3: color = Color::html("ee7991"); break;
  282. case Variant::BASIS: color = Color::html("e3ec69"); break;
  283. case Variant::TRANSFORM: color = Color::html("f6a86e"); break;
  284. case Variant::COLOR: color = Color::html("9dff70"); break;
  285. case Variant::NODE_PATH: color = Color::html("6993ec"); break;
  286. case Variant::_RID: color = Color::html("69ec9a"); break;
  287. case Variant::OBJECT: color = Color::html("79f3e8"); break;
  288. case Variant::DICTIONARY: color = Color::html("77edb1"); break;
  289. case Variant::ARRAY: color = Color::html("e0e0e0"); break;
  290. case Variant::POOL_BYTE_ARRAY: color = Color::html("aaf4c8"); break;
  291. case Variant::POOL_INT_ARRAY: color = Color::html("afdcf5"); break;
  292. case Variant::POOL_REAL_ARRAY: color = Color::html("97e7f8"); break;
  293. case Variant::POOL_STRING_ARRAY: color = Color::html("9dc4f2"); break;
  294. case Variant::POOL_VECTOR2_ARRAY: color = Color::html("d1b3f5"); break;
  295. case Variant::POOL_VECTOR3_ARRAY: color = Color::html("df9bf2"); break;
  296. case Variant::POOL_COLOR_ARRAY: color = Color::html("e9ff97"); break;
  297. default:
  298. color.set_hsv(p_type / float(Variant::VARIANT_MAX), 0.7, 0.7);
  299. }
  300. return color;
  301. }
  302. void VisualScriptEditor::_update_graph_connections() {
  303. graph->clear_connections();
  304. List<VisualScript::SequenceConnection> sequence_conns;
  305. script->get_sequence_connection_list(edited_func, &sequence_conns);
  306. for (List<VisualScript::SequenceConnection>::Element *E = sequence_conns.front(); E; E = E->next()) {
  307. graph->connect_node(itos(E->get().from_node), E->get().from_output, itos(E->get().to_node), 0);
  308. }
  309. List<VisualScript::DataConnection> data_conns;
  310. script->get_data_connection_list(edited_func, &data_conns);
  311. for (List<VisualScript::DataConnection>::Element *E = data_conns.front(); E; E = E->next()) {
  312. VisualScript::DataConnection dc = E->get();
  313. Ref<VisualScriptNode> from_node = script->get_node(edited_func, E->get().from_node);
  314. Ref<VisualScriptNode> to_node = script->get_node(edited_func, E->get().to_node);
  315. if (to_node->has_input_sequence_port()) {
  316. dc.to_port++;
  317. }
  318. dc.from_port += from_node->get_output_sequence_port_count();
  319. graph->connect_node(itos(E->get().from_node), dc.from_port, itos(E->get().to_node), dc.to_port);
  320. }
  321. }
  322. void VisualScriptEditor::_update_graph(int p_only_id) {
  323. if (updating_graph)
  324. return;
  325. updating_graph = true;
  326. //byebye all nodes
  327. if (p_only_id >= 0) {
  328. if (graph->has_node(itos(p_only_id))) {
  329. Node *gid = graph->get_node(itos(p_only_id));
  330. if (gid)
  331. memdelete(gid);
  332. }
  333. } else {
  334. for (int i = 0; i < graph->get_child_count(); i++) {
  335. if (Object::cast_to<GraphNode>(graph->get_child(i))) {
  336. memdelete(graph->get_child(i));
  337. i--;
  338. }
  339. }
  340. }
  341. if (!script->has_function(edited_func)) {
  342. graph->hide();
  343. select_func_text->show();
  344. updating_graph = false;
  345. return;
  346. }
  347. graph->show();
  348. select_func_text->hide();
  349. Ref<Texture> type_icons[Variant::VARIANT_MAX] = {
  350. Control::get_icon("MiniVariant", "EditorIcons"),
  351. Control::get_icon("MiniBoolean", "EditorIcons"),
  352. Control::get_icon("MiniInteger", "EditorIcons"),
  353. Control::get_icon("MiniFloat", "EditorIcons"),
  354. Control::get_icon("MiniString", "EditorIcons"),
  355. Control::get_icon("MiniVector2", "EditorIcons"),
  356. Control::get_icon("MiniRect2", "EditorIcons"),
  357. Control::get_icon("MiniVector3", "EditorIcons"),
  358. Control::get_icon("MiniTransform2D", "EditorIcons"),
  359. Control::get_icon("MiniPlane", "EditorIcons"),
  360. Control::get_icon("MiniQuat", "EditorIcons"),
  361. Control::get_icon("MiniAabb", "EditorIcons"),
  362. Control::get_icon("MiniBasis", "EditorIcons"),
  363. Control::get_icon("MiniTransform", "EditorIcons"),
  364. Control::get_icon("MiniColor", "EditorIcons"),
  365. Control::get_icon("MiniPath", "EditorIcons"),
  366. Control::get_icon("MiniRid", "EditorIcons"),
  367. Control::get_icon("MiniObject", "EditorIcons"),
  368. Control::get_icon("MiniDictionary", "EditorIcons"),
  369. Control::get_icon("MiniArray", "EditorIcons"),
  370. Control::get_icon("MiniRawArray", "EditorIcons"),
  371. Control::get_icon("MiniIntArray", "EditorIcons"),
  372. Control::get_icon("MiniFloatArray", "EditorIcons"),
  373. Control::get_icon("MiniStringArray", "EditorIcons"),
  374. Control::get_icon("MiniVector2Array", "EditorIcons"),
  375. Control::get_icon("MiniVector3Array", "EditorIcons"),
  376. Control::get_icon("MiniColorArray", "EditorIcons")
  377. };
  378. Ref<Texture> seq_port = Control::get_icon("VisualShaderPort", "EditorIcons");
  379. List<int> ids;
  380. script->get_node_list(edited_func, &ids);
  381. StringName editor_icons = "EditorIcons";
  382. for (List<int>::Element *E = ids.front(); E; E = E->next()) {
  383. if (p_only_id >= 0 && p_only_id != E->get())
  384. continue;
  385. Ref<VisualScriptNode> node = script->get_node(edited_func, E->get());
  386. Vector2 pos = script->get_node_pos(edited_func, E->get());
  387. GraphNode *gnode = memnew(GraphNode);
  388. gnode->set_title(node->get_caption());
  389. if (error_line == E->get()) {
  390. gnode->set_overlay(GraphNode::OVERLAY_POSITION);
  391. } else if (node->is_breakpoint()) {
  392. gnode->set_overlay(GraphNode::OVERLAY_BREAKPOINT);
  393. }
  394. if (node_styles.has(node->get_category())) {
  395. gnode->add_style_override("frame", node_styles[node->get_category()]);
  396. }
  397. gnode->set_meta("__vnode", node);
  398. gnode->set_name(itos(E->get()));
  399. gnode->connect("dragged", this, "_node_moved", varray(E->get()));
  400. gnode->connect("close_request", this, "_remove_node", varray(E->get()), CONNECT_DEFERRED);
  401. if (E->get() != script->get_function_node_id(edited_func)) {
  402. //function can't be erased
  403. gnode->set_show_close_button(true);
  404. }
  405. if (Object::cast_to<VisualScriptExpression>(node.ptr())) {
  406. LineEdit *line_edit = memnew(LineEdit);
  407. line_edit->set_text(node->get_text());
  408. line_edit->set_expand_to_text_length(true);
  409. line_edit->add_font_override("font", get_font("source", "EditorFonts"));
  410. gnode->add_child(line_edit);
  411. line_edit->connect("text_changed", this, "_expression_text_changed", varray(E->get()));
  412. } else {
  413. Label *text = memnew(Label);
  414. text->set_text(node->get_text());
  415. gnode->add_child(text);
  416. }
  417. if (Object::cast_to<VisualScriptComment>(node.ptr())) {
  418. Ref<VisualScriptComment> vsc = node;
  419. gnode->set_comment(true);
  420. gnode->set_resizable(true);
  421. gnode->set_custom_minimum_size(vsc->get_size() * EDSCALE);
  422. gnode->connect("resize_request", this, "_comment_node_resized", varray(E->get()));
  423. }
  424. int slot_idx = 0;
  425. bool single_seq_output = node->get_output_sequence_port_count() == 1 && node->get_output_sequence_port_text(0) == String();
  426. gnode->set_slot(0, node->has_input_sequence_port(), TYPE_SEQUENCE, Color(1, 1, 1, 1), single_seq_output, TYPE_SEQUENCE, Color(1, 1, 1, 1), seq_port, seq_port);
  427. gnode->set_offset(pos * EDSCALE);
  428. slot_idx++;
  429. int mixed_seq_ports = 0;
  430. if (!single_seq_output) {
  431. if (node->has_mixed_input_and_sequence_ports()) {
  432. mixed_seq_ports = node->get_output_sequence_port_count();
  433. } else {
  434. for (int i = 0; i < node->get_output_sequence_port_count(); i++) {
  435. Label *text2 = memnew(Label);
  436. text2->set_text(node->get_output_sequence_port_text(i));
  437. text2->set_align(Label::ALIGN_RIGHT);
  438. gnode->add_child(text2);
  439. gnode->set_slot(slot_idx, false, 0, Color(), true, TYPE_SEQUENCE, Color(1, 1, 1, 1), seq_port, seq_port);
  440. slot_idx++;
  441. }
  442. }
  443. }
  444. for (int i = 0; i < MAX(node->get_output_value_port_count(), MAX(mixed_seq_ports, node->get_input_value_port_count())); i++) {
  445. bool left_ok = false;
  446. Variant::Type left_type = Variant::NIL;
  447. String left_name;
  448. if (i < node->get_input_value_port_count()) {
  449. PropertyInfo pi = node->get_input_value_port_info(i);
  450. left_ok = true;
  451. left_type = pi.type;
  452. left_name = pi.name;
  453. }
  454. bool right_ok = false;
  455. Variant::Type right_type = Variant::NIL;
  456. String right_name;
  457. if (i >= mixed_seq_ports && i < node->get_output_value_port_count() + mixed_seq_ports) {
  458. PropertyInfo pi = node->get_output_value_port_info(i - mixed_seq_ports);
  459. right_ok = true;
  460. right_type = pi.type;
  461. right_name = pi.name;
  462. }
  463. HBoxContainer *hbc = memnew(HBoxContainer);
  464. if (left_ok) {
  465. Ref<Texture> t;
  466. if (left_type >= 0 && left_type < Variant::VARIANT_MAX) {
  467. t = type_icons[left_type];
  468. }
  469. if (t.is_valid()) {
  470. TextureRect *tf = memnew(TextureRect);
  471. tf->set_texture(t);
  472. tf->set_stretch_mode(TextureRect::STRETCH_KEEP_CENTERED);
  473. hbc->add_child(tf);
  474. }
  475. hbc->add_child(memnew(Label(left_name)));
  476. if (left_type != Variant::NIL && !script->is_input_value_port_connected(edited_func, E->get(), i)) {
  477. PropertyInfo pi = node->get_input_value_port_info(i);
  478. Button *button = memnew(Button);
  479. Variant value = node->get_default_input_value(i);
  480. if (value.get_type() != left_type) {
  481. //different type? for now convert
  482. //not the same, reconvert
  483. Variant::CallError ce;
  484. const Variant *existingp = &value;
  485. value = Variant::construct(left_type, &existingp, 1, ce, false);
  486. }
  487. if (left_type == Variant::COLOR) {
  488. button->set_custom_minimum_size(Size2(30, 0) * EDSCALE);
  489. button->connect("draw", this, "_draw_color_over_button", varray(button, value));
  490. } else if (left_type == Variant::OBJECT && Ref<Resource>(value).is_valid()) {
  491. Ref<Resource> res = value;
  492. Array arr;
  493. arr.push_back(button->get_instance_id());
  494. arr.push_back(String(value));
  495. EditorResourcePreview::get_singleton()->queue_edited_resource_preview(res, this, "_button_resource_previewed", arr);
  496. } else if (pi.type == Variant::INT && pi.hint == PROPERTY_HINT_ENUM) {
  497. button->set_text(pi.hint_string.get_slice(",", value));
  498. } else {
  499. button->set_text(value);
  500. }
  501. button->connect("pressed", this, "_default_value_edited", varray(button, E->get(), i));
  502. hbc->add_child(button);
  503. }
  504. } else {
  505. Control *c = memnew(Control);
  506. c->set_custom_minimum_size(Size2(10, 0) * EDSCALE);
  507. hbc->add_child(c);
  508. }
  509. hbc->add_spacer();
  510. if (i < mixed_seq_ports) {
  511. Label *text2 = memnew(Label);
  512. text2->set_text(node->get_output_sequence_port_text(i));
  513. text2->set_align(Label::ALIGN_RIGHT);
  514. hbc->add_child(text2);
  515. }
  516. if (right_ok) {
  517. hbc->add_child(memnew(Label(right_name)));
  518. Ref<Texture> t;
  519. if (right_type >= 0 && right_type < Variant::VARIANT_MAX) {
  520. t = type_icons[right_type];
  521. }
  522. if (t.is_valid()) {
  523. TextureRect *tf = memnew(TextureRect);
  524. tf->set_texture(t);
  525. tf->set_stretch_mode(TextureRect::STRETCH_KEEP_CENTERED);
  526. hbc->add_child(tf);
  527. }
  528. }
  529. gnode->add_child(hbc);
  530. if (i < mixed_seq_ports) {
  531. gnode->set_slot(slot_idx, left_ok, left_type, _color_from_type(left_type), true, TYPE_SEQUENCE, Color(1, 1, 1, 1), Ref<Texture>(), seq_port);
  532. } else {
  533. gnode->set_slot(slot_idx, left_ok, left_type, _color_from_type(left_type), right_ok, right_type, _color_from_type(right_type));
  534. }
  535. slot_idx++;
  536. }
  537. graph->add_child(gnode);
  538. if (gnode->is_comment()) {
  539. graph->move_child(gnode, 0);
  540. }
  541. }
  542. _update_graph_connections();
  543. graph->call_deferred("set_scroll_ofs", script->get_function_scroll(edited_func) * EDSCALE); //may need to adapt a bit, let it do so
  544. updating_graph = false;
  545. }
  546. void VisualScriptEditor::_update_members() {
  547. updating_members = true;
  548. members->clear();
  549. TreeItem *root = members->create_item();
  550. TreeItem *functions = members->create_item(root);
  551. functions->set_selectable(0, false);
  552. functions->set_text(0, TTR("Functions:"));
  553. functions->add_button(0, Control::get_icon("Override", "EditorIcons"), 1);
  554. functions->add_button(0, Control::get_icon("Add", "EditorIcons"), 0);
  555. functions->set_custom_bg_color(0, Control::get_color("prop_section", "Editor"));
  556. List<StringName> func_names;
  557. script->get_function_list(&func_names);
  558. for (List<StringName>::Element *E = func_names.front(); E; E = E->next()) {
  559. TreeItem *ti = members->create_item(functions);
  560. ti->set_text(0, E->get());
  561. ti->set_selectable(0, true);
  562. ti->set_editable(0, true);
  563. //ti->add_button(0,Control::get_icon("Edit","EditorIcons"),0); function arguments are in the node now
  564. //ti->add_button(0, Control::get_icon("Del", "EditorIcons"), 1);
  565. ti->set_metadata(0, E->get());
  566. if (E->get() == edited_func) {
  567. ti->set_custom_bg_color(0, get_color("prop_category", "Editor"));
  568. ti->set_custom_color(0, Color(1, 1, 1, 1));
  569. }
  570. if (selected == E->get())
  571. ti->select(0);
  572. }
  573. TreeItem *variables = members->create_item(root);
  574. variables->set_selectable(0, false);
  575. variables->set_text(0, TTR("Variables:"));
  576. variables->add_button(0, Control::get_icon("Add", "EditorIcons"));
  577. variables->set_custom_bg_color(0, Control::get_color("prop_section", "Editor"));
  578. Ref<Texture> type_icons[Variant::VARIANT_MAX] = {
  579. Control::get_icon("MiniVariant", "EditorIcons"),
  580. Control::get_icon("MiniBoolean", "EditorIcons"),
  581. Control::get_icon("MiniInteger", "EditorIcons"),
  582. Control::get_icon("MiniFloat", "EditorIcons"),
  583. Control::get_icon("MiniString", "EditorIcons"),
  584. Control::get_icon("MiniVector2", "EditorIcons"),
  585. Control::get_icon("MiniRect2", "EditorIcons"),
  586. Control::get_icon("MiniVector3", "EditorIcons"),
  587. Control::get_icon("MiniMatrix32", "EditorIcons"),
  588. Control::get_icon("MiniPlane", "EditorIcons"),
  589. Control::get_icon("MiniQuat", "EditorIcons"),
  590. Control::get_icon("MiniAabb", "EditorIcons"),
  591. Control::get_icon("MiniMatrix3", "EditorIcons"),
  592. Control::get_icon("MiniTransform", "EditorIcons"),
  593. Control::get_icon("MiniColor", "EditorIcons"),
  594. Control::get_icon("MiniPath", "EditorIcons"),
  595. Control::get_icon("MiniRid", "EditorIcons"),
  596. Control::get_icon("MiniObject", "EditorIcons"),
  597. Control::get_icon("MiniDictionary", "EditorIcons"),
  598. Control::get_icon("MiniArray", "EditorIcons"),
  599. Control::get_icon("MiniRawArray", "EditorIcons"),
  600. Control::get_icon("MiniIntArray", "EditorIcons"),
  601. Control::get_icon("MiniFloatArray", "EditorIcons"),
  602. Control::get_icon("MiniStringArray", "EditorIcons"),
  603. Control::get_icon("MiniVector2Array", "EditorIcons"),
  604. Control::get_icon("MiniVector3Array", "EditorIcons"),
  605. Control::get_icon("MiniColorArray", "EditorIcons")
  606. };
  607. List<StringName> var_names;
  608. script->get_variable_list(&var_names);
  609. for (List<StringName>::Element *E = var_names.front(); E; E = E->next()) {
  610. TreeItem *ti = members->create_item(variables);
  611. ti->set_text(0, E->get());
  612. Variant var = script->get_variable_default_value(E->get());
  613. ti->set_suffix(0, "=" + String(var));
  614. ti->set_icon(0, type_icons[script->get_variable_info(E->get()).type]);
  615. ti->set_selectable(0, true);
  616. ti->set_editable(0, true);
  617. //ti->add_button(0, Control::get_icon("Edit", "EditorIcons"), 0);
  618. //ti->add_button(0, Control::get_icon("Del", "EditorIcons"), 1);
  619. ti->set_metadata(0, E->get());
  620. if (selected == E->get())
  621. ti->select(0);
  622. }
  623. TreeItem *_signals = members->create_item(root);
  624. _signals->set_selectable(0, false);
  625. _signals->set_text(0, TTR("Signals:"));
  626. _signals->add_button(0, Control::get_icon("Add", "EditorIcons"));
  627. _signals->set_custom_bg_color(0, Control::get_color("prop_section", "Editor"));
  628. List<StringName> signal_names;
  629. script->get_custom_signal_list(&signal_names);
  630. for (List<StringName>::Element *E = signal_names.front(); E; E = E->next()) {
  631. TreeItem *ti = members->create_item(_signals);
  632. ti->set_text(0, E->get());
  633. ti->set_selectable(0, true);
  634. ti->set_editable(0, true);
  635. //ti->add_button(0, Control::get_icon("Edit", "EditorIcons"), 0);
  636. //ti->add_button(0, Control::get_icon("Del", "EditorIcons"), 1);
  637. ti->set_metadata(0, E->get());
  638. if (selected == E->get())
  639. ti->select(0);
  640. }
  641. String base_type = script->get_instance_base_type();
  642. String icon_type = base_type;
  643. if (!Control::has_icon(base_type, "EditorIcons")) {
  644. icon_type = "Object";
  645. }
  646. base_type_select->set_text(base_type);
  647. base_type_select->set_icon(Control::get_icon(icon_type, "EditorIcons"));
  648. updating_members = false;
  649. }
  650. void VisualScriptEditor::_member_selected() {
  651. if (updating_members)
  652. return;
  653. TreeItem *ti = members->get_selected();
  654. ERR_FAIL_COND(!ti);
  655. selected = ti->get_metadata(0);
  656. //print_line("selected: "+String(selected));
  657. if (ti->get_parent() == members->get_root()->get_children()) {
  658. if (edited_func != selected) {
  659. revert_on_drag = edited_func;
  660. edited_func = selected;
  661. _update_members();
  662. _update_graph();
  663. }
  664. return; //or crash because it will become invalid
  665. }
  666. }
  667. void VisualScriptEditor::_member_edited() {
  668. if (updating_members)
  669. return;
  670. TreeItem *ti = members->get_edited();
  671. ERR_FAIL_COND(!ti);
  672. String name = ti->get_metadata(0);
  673. String new_name = ti->get_text(0);
  674. if (name == new_name)
  675. return;
  676. if (!new_name.is_valid_identifier()) {
  677. EditorNode::get_singleton()->show_warning(TTR("Name is not a valid identifier:") + " " + new_name);
  678. updating_members = true;
  679. ti->set_text(0, name);
  680. updating_members = false;
  681. return;
  682. }
  683. if (script->has_function(new_name) || script->has_variable(new_name) || script->has_custom_signal(new_name)) {
  684. EditorNode::get_singleton()->show_warning(TTR("Name already in use by another func/var/signal:") + " " + new_name);
  685. updating_members = true;
  686. ti->set_text(0, name);
  687. updating_members = false;
  688. return;
  689. }
  690. TreeItem *root = members->get_root();
  691. if (ti->get_parent() == root->get_children()) {
  692. if (edited_func == selected) {
  693. edited_func = new_name;
  694. }
  695. selected = new_name;
  696. int node_id = script->get_function_node_id(name);
  697. Ref<VisualScriptFunction> func;
  698. if (script->has_node(name, node_id)) {
  699. func = script->get_node(name, node_id);
  700. }
  701. undo_redo->create_action(TTR("Rename Function"));
  702. undo_redo->add_do_method(script.ptr(), "rename_function", name, new_name);
  703. undo_redo->add_undo_method(script.ptr(), "rename_function", new_name, name);
  704. if (func.is_valid()) {
  705. undo_redo->add_do_method(func.ptr(), "set_name", new_name);
  706. undo_redo->add_undo_method(func.ptr(), "set_name", name);
  707. }
  708. undo_redo->add_do_method(this, "_update_members");
  709. undo_redo->add_undo_method(this, "_update_members");
  710. undo_redo->add_do_method(this, "_update_graph");
  711. undo_redo->add_undo_method(this, "_update_graph");
  712. undo_redo->add_do_method(this, "emit_signal", "edited_script_changed");
  713. undo_redo->add_undo_method(this, "emit_signal", "edited_script_changed");
  714. undo_redo->commit_action();
  715. // _update_graph();
  716. return; //or crash because it will become invalid
  717. }
  718. if (ti->get_parent() == root->get_children()->get_next()) {
  719. selected = new_name;
  720. undo_redo->create_action(TTR("Rename Variable"));
  721. undo_redo->add_do_method(script.ptr(), "rename_variable", name, new_name);
  722. undo_redo->add_undo_method(script.ptr(), "rename_variable", new_name, name);
  723. undo_redo->add_do_method(this, "_update_members");
  724. undo_redo->add_undo_method(this, "_update_members");
  725. undo_redo->add_do_method(this, "emit_signal", "edited_script_changed");
  726. undo_redo->add_undo_method(this, "emit_signal", "edited_script_changed");
  727. undo_redo->commit_action();
  728. return; //or crash because it will become invalid
  729. }
  730. if (ti->get_parent() == root->get_children()->get_next()->get_next()) {
  731. selected = new_name;
  732. undo_redo->create_action(TTR("Rename Signal"));
  733. undo_redo->add_do_method(script.ptr(), "rename_custom_signal", name, new_name);
  734. undo_redo->add_undo_method(script.ptr(), "rename_custom_signal", new_name, name);
  735. undo_redo->add_do_method(this, "_update_members");
  736. undo_redo->add_undo_method(this, "_update_members");
  737. undo_redo->add_do_method(this, "emit_signal", "edited_script_changed");
  738. undo_redo->add_undo_method(this, "emit_signal", "edited_script_changed");
  739. undo_redo->commit_action();
  740. return; //or crash because it will become invalid
  741. }
  742. }
  743. void VisualScriptEditor::_member_button(Object *p_item, int p_column, int p_button) {
  744. TreeItem *ti = Object::cast_to<TreeItem>(p_item);
  745. TreeItem *root = members->get_root();
  746. if (ti->get_parent() == root) {
  747. //main buttons
  748. if (ti == root->get_children()) {
  749. //add function, this one uses menu
  750. if (p_button == 1) {
  751. new_virtual_method_select->select_method_from_base_type(script->get_instance_base_type(), String(), true);
  752. return;
  753. } else if (p_button == 0) {
  754. String name = _validate_name("new_function");
  755. selected = name;
  756. edited_func = selected;
  757. Ref<VisualScriptFunction> func_node;
  758. func_node.instance();
  759. func_node->set_name(name);
  760. undo_redo->create_action(TTR("Add Function"));
  761. undo_redo->add_do_method(script.ptr(), "add_function", name);
  762. undo_redo->add_do_method(script.ptr(), "add_node", name, script->get_available_id(), func_node);
  763. undo_redo->add_undo_method(script.ptr(), "remove_function", name);
  764. undo_redo->add_do_method(this, "_update_members");
  765. undo_redo->add_undo_method(this, "_update_members");
  766. undo_redo->add_do_method(this, "_update_graph");
  767. undo_redo->add_undo_method(this, "_update_graph");
  768. undo_redo->add_do_method(this, "emit_signal", "edited_script_changed");
  769. undo_redo->add_undo_method(this, "emit_signal", "edited_script_changed");
  770. undo_redo->commit_action();
  771. _update_graph();
  772. }
  773. return; //or crash because it will become invalid
  774. }
  775. if (ti == root->get_children()->get_next()) {
  776. //add variable
  777. String name = _validate_name("new_variable");
  778. selected = name;
  779. undo_redo->create_action(TTR("Add Variable"));
  780. undo_redo->add_do_method(script.ptr(), "add_variable", name);
  781. undo_redo->add_undo_method(script.ptr(), "remove_variable", name);
  782. undo_redo->add_do_method(this, "_update_members");
  783. undo_redo->add_undo_method(this, "_update_members");
  784. undo_redo->add_do_method(this, "emit_signal", "edited_script_changed");
  785. undo_redo->add_undo_method(this, "emit_signal", "edited_script_changed");
  786. undo_redo->commit_action();
  787. return; //or crash because it will become invalid
  788. }
  789. if (ti == root->get_children()->get_next()->get_next()) {
  790. //add variable
  791. String name = _validate_name("new_signal");
  792. selected = name;
  793. undo_redo->create_action(TTR("Add Signal"));
  794. undo_redo->add_do_method(script.ptr(), "add_custom_signal", name);
  795. undo_redo->add_undo_method(script.ptr(), "remove_custom_signal", name);
  796. undo_redo->add_do_method(this, "_update_members");
  797. undo_redo->add_undo_method(this, "_update_members");
  798. undo_redo->add_do_method(this, "emit_signal", "edited_script_changed");
  799. undo_redo->add_undo_method(this, "emit_signal", "edited_script_changed");
  800. undo_redo->commit_action();
  801. return; //or crash because it will become invalid
  802. }
  803. }
  804. }
  805. void VisualScriptEditor::_expression_text_changed(const String &p_text, int p_id) {
  806. Ref<VisualScriptExpression> vse = script->get_node(edited_func, p_id);
  807. if (!vse.is_valid())
  808. return;
  809. updating_graph = true;
  810. undo_redo->create_action(TTR("Change Expression"), UndoRedo::MERGE_ENDS);
  811. undo_redo->add_do_property(vse.ptr(), "expression", p_text);
  812. undo_redo->add_undo_property(vse.ptr(), "expression", vse->get("expression"));
  813. undo_redo->add_do_method(this, "_update_graph", p_id);
  814. undo_redo->add_undo_method(this, "_update_graph", p_id);
  815. undo_redo->commit_action();
  816. Node *node = graph->get_node(itos(p_id));
  817. if (Object::cast_to<Control>(node))
  818. Object::cast_to<Control>(node)->set_size(Vector2(1, 1)); //shrink if text is smaller
  819. updating_graph = false;
  820. }
  821. void VisualScriptEditor::_available_node_doubleclicked() {
  822. TreeItem *item = nodes->get_selected();
  823. if (!item)
  824. return;
  825. String which = item->get_metadata(0);
  826. if (which == String())
  827. return;
  828. Vector2 ofs = graph->get_scroll_ofs() + graph->get_size() * 0.5;
  829. if (graph->is_using_snap()) {
  830. int snap = graph->get_snap();
  831. ofs = ofs.snapped(Vector2(snap, snap));
  832. }
  833. ofs /= EDSCALE;
  834. while (true) {
  835. bool exists = false;
  836. List<int> existing;
  837. script->get_node_list(edited_func, &existing);
  838. for (List<int>::Element *E = existing.front(); E; E = E->next()) {
  839. Point2 pos = script->get_node_pos(edited_func, E->get());
  840. if (pos.distance_to(ofs) < 15) {
  841. ofs += Vector2(graph->get_snap(), graph->get_snap());
  842. exists = true;
  843. break;
  844. }
  845. }
  846. if (exists)
  847. continue;
  848. break;
  849. }
  850. Ref<VisualScriptNode> vnode = VisualScriptLanguage::singleton->create_node_from_name(which);
  851. int new_id = script->get_available_id();
  852. undo_redo->create_action(TTR("Add Node"));
  853. undo_redo->add_do_method(script.ptr(), "add_node", edited_func, new_id, vnode, ofs);
  854. undo_redo->add_undo_method(script.ptr(), "remove_node", edited_func, new_id);
  855. undo_redo->add_do_method(this, "_update_graph");
  856. undo_redo->add_undo_method(this, "_update_graph");
  857. undo_redo->commit_action();
  858. Node *node = graph->get_node(itos(new_id));
  859. if (node) {
  860. graph->set_selected(node);
  861. _node_selected(node);
  862. }
  863. }
  864. void VisualScriptEditor::_update_available_nodes() {
  865. nodes->clear();
  866. TreeItem *root = nodes->create_item();
  867. Map<String, TreeItem *> path_cache;
  868. String filter = node_filter->get_text();
  869. List<String> fnodes;
  870. VisualScriptLanguage::singleton->get_registered_node_names(&fnodes);
  871. for (List<String>::Element *E = fnodes.front(); E; E = E->next()) {
  872. Vector<String> path = E->get().split("/");
  873. if (filter != String() && path.size() && path[path.size() - 1].findn(filter) == -1)
  874. continue;
  875. String sp;
  876. TreeItem *parent = root;
  877. for (int i = 0; i < path.size() - 1; i++) {
  878. if (i > 0)
  879. sp += ",";
  880. sp += path[i];
  881. if (!path_cache.has(sp)) {
  882. TreeItem *pathn = nodes->create_item(parent);
  883. pathn->set_selectable(0, false);
  884. pathn->set_text(0, path[i].capitalize());
  885. path_cache[sp] = pathn;
  886. parent = pathn;
  887. if (filter == String()) {
  888. pathn->set_collapsed(true); //should remember state
  889. }
  890. } else {
  891. parent = path_cache[sp];
  892. }
  893. }
  894. TreeItem *item = nodes->create_item(parent);
  895. item->set_text(0, path[path.size() - 1].capitalize());
  896. item->set_selectable(0, true);
  897. item->set_metadata(0, E->get());
  898. }
  899. }
  900. String VisualScriptEditor::_validate_name(const String &p_name) const {
  901. String valid = p_name;
  902. int counter = 1;
  903. while (true) {
  904. bool exists = script->has_function(valid) || script->has_variable(valid) || script->has_custom_signal(valid);
  905. if (exists) {
  906. counter++;
  907. valid = p_name + "_" + itos(counter);
  908. continue;
  909. }
  910. break;
  911. }
  912. return valid;
  913. }
  914. void VisualScriptEditor::_on_nodes_delete() {
  915. List<int> to_erase;
  916. for (int i = 0; i < graph->get_child_count(); i++) {
  917. GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i));
  918. if (gn) {
  919. if (gn->is_selected() && gn->is_close_button_visible()) {
  920. to_erase.push_back(gn->get_name().operator String().to_int());
  921. }
  922. }
  923. }
  924. if (to_erase.empty())
  925. return;
  926. undo_redo->create_action(TTR("Remove VisualScript Nodes"));
  927. for (List<int>::Element *F = to_erase.front(); F; F = F->next()) {
  928. undo_redo->add_do_method(script.ptr(), "remove_node", edited_func, F->get());
  929. undo_redo->add_undo_method(script.ptr(), "add_node", edited_func, F->get(), script->get_node(edited_func, F->get()), script->get_node_pos(edited_func, F->get()));
  930. List<VisualScript::SequenceConnection> sequence_conns;
  931. script->get_sequence_connection_list(edited_func, &sequence_conns);
  932. for (List<VisualScript::SequenceConnection>::Element *E = sequence_conns.front(); E; E = E->next()) {
  933. if (E->get().from_node == F->get() || E->get().to_node == F->get()) {
  934. undo_redo->add_undo_method(script.ptr(), "sequence_connect", edited_func, E->get().from_node, E->get().from_output, E->get().to_node);
  935. }
  936. }
  937. List<VisualScript::DataConnection> data_conns;
  938. script->get_data_connection_list(edited_func, &data_conns);
  939. for (List<VisualScript::DataConnection>::Element *E = data_conns.front(); E; E = E->next()) {
  940. if (E->get().from_node == F->get() || E->get().to_node == F->get()) {
  941. undo_redo->add_undo_method(script.ptr(), "data_connect", edited_func, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port);
  942. }
  943. }
  944. }
  945. undo_redo->add_do_method(this, "_update_graph");
  946. undo_redo->add_undo_method(this, "_update_graph");
  947. undo_redo->commit_action();
  948. }
  949. void VisualScriptEditor::_on_nodes_duplicate() {
  950. List<int> to_duplicate;
  951. for (int i = 0; i < graph->get_child_count(); i++) {
  952. GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i));
  953. if (gn) {
  954. if (gn->is_selected() && gn->is_close_button_visible()) {
  955. to_duplicate.push_back(gn->get_name().operator String().to_int());
  956. }
  957. }
  958. }
  959. if (to_duplicate.empty())
  960. return;
  961. undo_redo->create_action(TTR("Duplicate VisualScript Nodes"));
  962. int idc = script->get_available_id() + 1;
  963. Set<int> to_select;
  964. for (List<int>::Element *F = to_duplicate.front(); F; F = F->next()) {
  965. Ref<VisualScriptNode> node = script->get_node(edited_func, F->get());
  966. Ref<VisualScriptNode> dupe = node->duplicate();
  967. int new_id = idc++;
  968. to_select.insert(new_id);
  969. undo_redo->add_do_method(script.ptr(), "add_node", edited_func, new_id, dupe, script->get_node_pos(edited_func, F->get()) + Vector2(20, 20));
  970. undo_redo->add_undo_method(script.ptr(), "remove_node", edited_func, new_id);
  971. }
  972. undo_redo->add_do_method(this, "_update_graph");
  973. undo_redo->add_undo_method(this, "_update_graph");
  974. undo_redo->commit_action();
  975. for (int i = 0; i < graph->get_child_count(); i++) {
  976. GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i));
  977. if (gn) {
  978. int id = gn->get_name().operator String().to_int();
  979. gn->set_selected(to_select.has(id));
  980. }
  981. }
  982. if (to_select.size()) {
  983. EditorNode::get_singleton()->push_item(script->get_node(edited_func, to_select.front()->get()).ptr());
  984. }
  985. }
  986. void VisualScriptEditor::_input(const Ref<InputEvent> &p_event) {
  987. Ref<InputEventMouseButton> mb = p_event;
  988. if (mb.is_valid() && !mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
  989. revert_on_drag = String(); //so we can still drag functions
  990. }
  991. }
  992. Variant VisualScriptEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
  993. if (p_from == nodes) {
  994. TreeItem *it = nodes->get_item_at_pos(p_point);
  995. if (!it)
  996. return Variant();
  997. String type = it->get_metadata(0);
  998. if (type == String())
  999. return Variant();
  1000. Dictionary dd;
  1001. dd["type"] = "visual_script_node_drag";
  1002. dd["node_type"] = type;
  1003. Label *label = memnew(Label);
  1004. label->set_text(it->get_text(0));
  1005. set_drag_preview(label);
  1006. return dd;
  1007. }
  1008. if (p_from == members) {
  1009. TreeItem *it = members->get_item_at_pos(p_point);
  1010. if (!it)
  1011. return Variant();
  1012. String type = it->get_metadata(0);
  1013. if (type == String())
  1014. return Variant();
  1015. Dictionary dd;
  1016. TreeItem *root = members->get_root();
  1017. if (it->get_parent() == root->get_children()) {
  1018. dd["type"] = "visual_script_function_drag";
  1019. dd["function"] = type;
  1020. if (revert_on_drag != String()) {
  1021. edited_func = revert_on_drag; //revert so function does not change
  1022. revert_on_drag = String();
  1023. _update_graph();
  1024. }
  1025. } else if (it->get_parent() == root->get_children()->get_next()) {
  1026. dd["type"] = "visual_script_variable_drag";
  1027. dd["variable"] = type;
  1028. } else if (it->get_parent() == root->get_children()->get_next()->get_next()) {
  1029. dd["type"] = "visual_script_signal_drag";
  1030. dd["signal"] = type;
  1031. } else {
  1032. return Variant();
  1033. }
  1034. Label *label = memnew(Label);
  1035. label->set_text(it->get_text(0));
  1036. set_drag_preview(label);
  1037. return dd;
  1038. }
  1039. return Variant();
  1040. }
  1041. bool VisualScriptEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
  1042. if (p_from == graph) {
  1043. Dictionary d = p_data;
  1044. if (d.has("type") &&
  1045. (String(d["type"]) == "visual_script_node_drag" ||
  1046. String(d["type"]) == "visual_script_function_drag" ||
  1047. String(d["type"]) == "visual_script_variable_drag" ||
  1048. String(d["type"]) == "visual_script_signal_drag" ||
  1049. String(d["type"]) == "obj_property" ||
  1050. String(d["type"]) == "resource" ||
  1051. String(d["type"]) == "files" ||
  1052. String(d["type"]) == "nodes")) {
  1053. if (String(d["type"]) == "obj_property") {
  1054. #ifdef OSX_ENABLED
  1055. const_cast<VisualScriptEditor *>(this)->_show_hint(TTR("Hold Meta to drop a Getter. Hold Shift to drop a generic signature."));
  1056. #else
  1057. const_cast<VisualScriptEditor *>(this)->_show_hint(TTR("Hold Ctrl to drop a Getter. Hold Shift to drop a generic signature."));
  1058. #endif
  1059. }
  1060. if (String(d["type"]) == "nodes") {
  1061. #ifdef OSX_ENABLED
  1062. const_cast<VisualScriptEditor *>(this)->_show_hint(TTR("Hold Meta to drop a simple reference to the node."));
  1063. #else
  1064. const_cast<VisualScriptEditor *>(this)->_show_hint(TTR("Hold Ctrl to drop a simple reference to the node."));
  1065. #endif
  1066. }
  1067. if (String(d["type"]) == "visual_script_variable_drag") {
  1068. #ifdef OSX_ENABLED
  1069. const_cast<VisualScriptEditor *>(this)->_show_hint(TTR("Hold Meta to drop a Variable Setter."));
  1070. #else
  1071. const_cast<VisualScriptEditor *>(this)->_show_hint(TTR("Hold Ctrl to drop a Variable Setter."));
  1072. #endif
  1073. }
  1074. return true;
  1075. }
  1076. }
  1077. return false;
  1078. }
  1079. #ifdef TOOLS_ENABLED
  1080. static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const Ref<Script> &script) {
  1081. if (p_edited_scene != p_current_node && p_current_node->get_owner() != p_edited_scene)
  1082. return NULL;
  1083. Ref<Script> scr = p_current_node->get_script();
  1084. if (scr.is_valid() && scr == script)
  1085. return p_current_node;
  1086. for (int i = 0; i < p_current_node->get_child_count(); i++) {
  1087. Node *n = _find_script_node(p_edited_scene, p_current_node->get_child(i), script);
  1088. if (n)
  1089. return n;
  1090. }
  1091. return NULL;
  1092. }
  1093. #endif
  1094. void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
  1095. if (p_from != graph) {
  1096. return;
  1097. }
  1098. Dictionary d = p_data;
  1099. if (!d.has("type")) {
  1100. return;
  1101. }
  1102. if (String(d["type"]) == "visual_script_node_drag") {
  1103. if (!d.has("node_type") || String(d["node_type"]) == "Null") {
  1104. return;
  1105. }
  1106. Vector2 ofs = graph->get_scroll_ofs() + p_point;
  1107. if (graph->is_using_snap()) {
  1108. int snap = graph->get_snap();
  1109. ofs = ofs.snapped(Vector2(snap, snap));
  1110. }
  1111. ofs /= EDSCALE;
  1112. Ref<VisualScriptNode> vnode = VisualScriptLanguage::singleton->create_node_from_name(d["node_type"]);
  1113. int new_id = script->get_available_id();
  1114. undo_redo->create_action(TTR("Add Node"));
  1115. undo_redo->add_do_method(script.ptr(), "add_node", edited_func, new_id, vnode, ofs);
  1116. undo_redo->add_undo_method(script.ptr(), "remove_node", edited_func, new_id);
  1117. undo_redo->add_do_method(this, "_update_graph");
  1118. undo_redo->add_undo_method(this, "_update_graph");
  1119. undo_redo->commit_action();
  1120. Node *node = graph->get_node(itos(new_id));
  1121. if (node) {
  1122. graph->set_selected(node);
  1123. _node_selected(node);
  1124. }
  1125. }
  1126. if (String(d["type"]) == "visual_script_variable_drag") {
  1127. #ifdef OSX_ENABLED
  1128. bool use_set = Input::get_singleton()->is_key_pressed(KEY_META);
  1129. #else
  1130. bool use_set = Input::get_singleton()->is_key_pressed(KEY_CONTROL);
  1131. #endif
  1132. Vector2 ofs = graph->get_scroll_ofs() + p_point;
  1133. if (graph->is_using_snap()) {
  1134. int snap = graph->get_snap();
  1135. ofs = ofs.snapped(Vector2(snap, snap));
  1136. }
  1137. ofs /= EDSCALE;
  1138. Ref<VisualScriptNode> vnode;
  1139. if (use_set) {
  1140. Ref<VisualScriptVariableSet> vnodes;
  1141. vnodes.instance();
  1142. vnodes->set_variable(d["variable"]);
  1143. vnode = vnodes;
  1144. } else {
  1145. Ref<VisualScriptVariableGet> vnodeg;
  1146. vnodeg.instance();
  1147. vnodeg->set_variable(d["variable"]);
  1148. vnode = vnodeg;
  1149. }
  1150. int new_id = script->get_available_id();
  1151. undo_redo->create_action(TTR("Add Node"));
  1152. undo_redo->add_do_method(script.ptr(), "add_node", edited_func, new_id, vnode, ofs);
  1153. undo_redo->add_undo_method(script.ptr(), "remove_node", edited_func, new_id);
  1154. undo_redo->add_do_method(this, "_update_graph");
  1155. undo_redo->add_undo_method(this, "_update_graph");
  1156. undo_redo->commit_action();
  1157. Node *node = graph->get_node(itos(new_id));
  1158. if (node) {
  1159. graph->set_selected(node);
  1160. _node_selected(node);
  1161. }
  1162. }
  1163. if (String(d["type"]) == "visual_script_function_drag") {
  1164. Vector2 ofs = graph->get_scroll_ofs() + p_point;
  1165. if (graph->is_using_snap()) {
  1166. int snap = graph->get_snap();
  1167. ofs = ofs.snapped(Vector2(snap, snap));
  1168. }
  1169. ofs /= EDSCALE;
  1170. Ref<VisualScriptFunctionCall> vnode;
  1171. vnode.instance();
  1172. vnode->set_call_mode(VisualScriptFunctionCall::CALL_MODE_SELF);
  1173. int new_id = script->get_available_id();
  1174. undo_redo->create_action(TTR("Add Node"));
  1175. undo_redo->add_do_method(script.ptr(), "add_node", edited_func, new_id, vnode, ofs);
  1176. undo_redo->add_do_method(vnode.ptr(), "set_base_type", script->get_instance_base_type());
  1177. undo_redo->add_do_method(vnode.ptr(), "set_function", d["function"]);
  1178. undo_redo->add_undo_method(script.ptr(), "remove_node", edited_func, new_id);
  1179. undo_redo->add_do_method(this, "_update_graph");
  1180. undo_redo->add_undo_method(this, "_update_graph");
  1181. undo_redo->commit_action();
  1182. Node *node = graph->get_node(itos(new_id));
  1183. if (node) {
  1184. graph->set_selected(node);
  1185. _node_selected(node);
  1186. }
  1187. }
  1188. if (String(d["type"]) == "visual_script_signal_drag") {
  1189. Vector2 ofs = graph->get_scroll_ofs() + p_point;
  1190. if (graph->is_using_snap()) {
  1191. int snap = graph->get_snap();
  1192. ofs = ofs.snapped(Vector2(snap, snap));
  1193. }
  1194. ofs /= EDSCALE;
  1195. Ref<VisualScriptEmitSignal> vnode;
  1196. vnode.instance();
  1197. vnode->set_signal(d["signal"]);
  1198. int new_id = script->get_available_id();
  1199. undo_redo->create_action(TTR("Add Node"));
  1200. undo_redo->add_do_method(script.ptr(), "add_node", edited_func, new_id, vnode, ofs);
  1201. undo_redo->add_undo_method(script.ptr(), "remove_node", edited_func, new_id);
  1202. undo_redo->add_do_method(this, "_update_graph");
  1203. undo_redo->add_undo_method(this, "_update_graph");
  1204. undo_redo->commit_action();
  1205. Node *node = graph->get_node(itos(new_id));
  1206. if (node) {
  1207. graph->set_selected(node);
  1208. _node_selected(node);
  1209. }
  1210. }
  1211. if (String(d["type"]) == "resource") {
  1212. Vector2 ofs = graph->get_scroll_ofs() + p_point;
  1213. if (graph->is_using_snap()) {
  1214. int snap = graph->get_snap();
  1215. ofs = ofs.snapped(Vector2(snap, snap));
  1216. }
  1217. ofs /= EDSCALE;
  1218. Ref<VisualScriptPreload> prnode;
  1219. prnode.instance();
  1220. prnode->set_preload(d["resource"]);
  1221. int new_id = script->get_available_id();
  1222. undo_redo->create_action(TTR("Add Preload Node"));
  1223. undo_redo->add_do_method(script.ptr(), "add_node", edited_func, new_id, prnode, ofs);
  1224. undo_redo->add_undo_method(script.ptr(), "remove_node", edited_func, new_id);
  1225. undo_redo->add_do_method(this, "_update_graph");
  1226. undo_redo->add_undo_method(this, "_update_graph");
  1227. undo_redo->commit_action();
  1228. Node *node = graph->get_node(itos(new_id));
  1229. if (node) {
  1230. graph->set_selected(node);
  1231. _node_selected(node);
  1232. }
  1233. }
  1234. if (String(d["type"]) == "files") {
  1235. Vector2 ofs = graph->get_scroll_ofs() + p_point;
  1236. if (graph->is_using_snap()) {
  1237. int snap = graph->get_snap();
  1238. ofs = ofs.snapped(Vector2(snap, snap));
  1239. }
  1240. ofs /= EDSCALE;
  1241. Array files = d["files"];
  1242. List<int> new_ids;
  1243. int new_id = script->get_available_id();
  1244. if (files.size()) {
  1245. undo_redo->create_action(TTR("Add Preload Node"));
  1246. for (int i = 0; i < files.size(); i++) {
  1247. Ref<Resource> res = ResourceLoader::load(files[i]);
  1248. if (!res.is_valid())
  1249. continue;
  1250. Ref<VisualScriptPreload> prnode;
  1251. prnode.instance();
  1252. prnode->set_preload(res);
  1253. undo_redo->add_do_method(script.ptr(), "add_node", edited_func, new_id, prnode, ofs);
  1254. undo_redo->add_undo_method(script.ptr(), "remove_node", edited_func, new_id);
  1255. new_ids.push_back(new_id);
  1256. new_id++;
  1257. ofs += Vector2(20, 20) * EDSCALE;
  1258. }
  1259. undo_redo->add_do_method(this, "_update_graph");
  1260. undo_redo->add_undo_method(this, "_update_graph");
  1261. undo_redo->commit_action();
  1262. }
  1263. for (List<int>::Element *E = new_ids.front(); E; E = E->next()) {
  1264. Node *node = graph->get_node(itos(E->get()));
  1265. if (node) {
  1266. graph->set_selected(node);
  1267. _node_selected(node);
  1268. }
  1269. }
  1270. }
  1271. if (String(d["type"]) == "nodes") {
  1272. Node *sn = _find_script_node(get_tree()->get_edited_scene_root(), get_tree()->get_edited_scene_root(), script);
  1273. if (!sn) {
  1274. EditorNode::get_singleton()->show_warning("Can't drop nodes because script '" + get_name() + "' is not used in this scene.");
  1275. return;
  1276. }
  1277. #ifdef OSX_ENABLED
  1278. bool use_node = Input::get_singleton()->is_key_pressed(KEY_META);
  1279. #else
  1280. bool use_node = Input::get_singleton()->is_key_pressed(KEY_CONTROL);
  1281. #endif
  1282. Array nodes = d["nodes"];
  1283. Vector2 ofs = graph->get_scroll_ofs() + p_point;
  1284. if (graph->is_using_snap()) {
  1285. int snap = graph->get_snap();
  1286. ofs = ofs.snapped(Vector2(snap, snap));
  1287. }
  1288. ofs /= EDSCALE;
  1289. undo_redo->create_action(TTR("Add Node(s) From Tree"));
  1290. int base_id = script->get_available_id();
  1291. if (nodes.size() > 1) {
  1292. use_node = true;
  1293. }
  1294. for (int i = 0; i < nodes.size(); i++) {
  1295. NodePath np = nodes[i];
  1296. Node *node = get_node(np);
  1297. if (!node) {
  1298. continue;
  1299. }
  1300. Ref<VisualScriptNode> n;
  1301. if (use_node) {
  1302. Ref<VisualScriptSceneNode> scene_node;
  1303. scene_node.instance();
  1304. scene_node->set_node_path(sn->get_path_to(node));
  1305. n = scene_node;
  1306. } else {
  1307. Ref<VisualScriptFunctionCall> call;
  1308. call.instance();
  1309. call->set_call_mode(VisualScriptFunctionCall::CALL_MODE_NODE_PATH);
  1310. call->set_base_path(sn->get_path_to(node));
  1311. call->set_base_type(node->get_class());
  1312. n = call;
  1313. method_select->select_method_from_instance(node);
  1314. selecting_method_id = base_id;
  1315. }
  1316. undo_redo->add_do_method(script.ptr(), "add_node", edited_func, base_id, n, ofs);
  1317. undo_redo->add_undo_method(script.ptr(), "remove_node", edited_func, base_id);
  1318. base_id++;
  1319. ofs += Vector2(25, 25);
  1320. }
  1321. undo_redo->add_do_method(this, "_update_graph");
  1322. undo_redo->add_undo_method(this, "_update_graph");
  1323. undo_redo->commit_action();
  1324. }
  1325. if (String(d["type"]) == "obj_property") {
  1326. Node *sn = _find_script_node(get_tree()->get_edited_scene_root(), get_tree()->get_edited_scene_root(), script);
  1327. if (!sn && !Input::get_singleton()->is_key_pressed(KEY_SHIFT)) {
  1328. EditorNode::get_singleton()->show_warning("Can't drop properties because script '" + get_name() + "' is not used in this scene.\nDrop holding 'Shift' to just copy the signature.");
  1329. return;
  1330. }
  1331. Object *obj = d["object"];
  1332. if (!obj)
  1333. return;
  1334. Node *node = Object::cast_to<Node>(obj);
  1335. Vector2 ofs = graph->get_scroll_ofs() + p_point;
  1336. if (graph->is_using_snap()) {
  1337. int snap = graph->get_snap();
  1338. ofs = ofs.snapped(Vector2(snap, snap));
  1339. }
  1340. ofs /= EDSCALE;
  1341. #ifdef OSX_ENABLED
  1342. bool use_get = Input::get_singleton()->is_key_pressed(KEY_META);
  1343. #else
  1344. bool use_get = Input::get_singleton()->is_key_pressed(KEY_CONTROL);
  1345. #endif
  1346. if (!node || Input::get_singleton()->is_key_pressed(KEY_SHIFT)) {
  1347. if (use_get)
  1348. undo_redo->create_action(TTR("Add Getter Property"));
  1349. else
  1350. undo_redo->create_action(TTR("Add Setter Property"));
  1351. int base_id = script->get_available_id();
  1352. Ref<VisualScriptNode> vnode;
  1353. if (!use_get) {
  1354. Ref<VisualScriptPropertySet> pset;
  1355. pset.instance();
  1356. pset->set_call_mode(VisualScriptPropertySet::CALL_MODE_INSTANCE);
  1357. pset->set_base_type(obj->get_class());
  1358. /*if (use_value) {
  1359. pset->set_use_builtin_value(true);
  1360. pset->set_builtin_value(d["value"]);
  1361. }*/
  1362. vnode = pset;
  1363. } else {
  1364. Ref<VisualScriptPropertyGet> pget;
  1365. pget.instance();
  1366. pget->set_call_mode(VisualScriptPropertyGet::CALL_MODE_INSTANCE);
  1367. pget->set_base_type(obj->get_class());
  1368. vnode = pget;
  1369. }
  1370. undo_redo->add_do_method(script.ptr(), "add_node", edited_func, base_id, vnode, ofs);
  1371. undo_redo->add_do_method(vnode.ptr(), "set_property", d["property"]);
  1372. if (!use_get) {
  1373. undo_redo->add_do_method(vnode.ptr(), "set_default_input_value", 0, d["value"]);
  1374. }
  1375. undo_redo->add_undo_method(script.ptr(), "remove_node", edited_func, base_id);
  1376. undo_redo->add_do_method(this, "_update_graph");
  1377. undo_redo->add_undo_method(this, "_update_graph");
  1378. undo_redo->commit_action();
  1379. } else {
  1380. if (use_get)
  1381. undo_redo->create_action(TTR("Add Getter Property"));
  1382. else
  1383. undo_redo->create_action(TTR("Add Setter Property"));
  1384. int base_id = script->get_available_id();
  1385. Ref<VisualScriptNode> vnode;
  1386. if (!use_get) {
  1387. Ref<VisualScriptPropertySet> pset;
  1388. pset.instance();
  1389. if (sn == node) {
  1390. pset->set_call_mode(VisualScriptPropertySet::CALL_MODE_SELF);
  1391. } else {
  1392. pset->set_call_mode(VisualScriptPropertySet::CALL_MODE_NODE_PATH);
  1393. pset->set_base_path(sn->get_path_to(node));
  1394. }
  1395. vnode = pset;
  1396. } else {
  1397. Ref<VisualScriptPropertyGet> pget;
  1398. pget.instance();
  1399. if (sn == node) {
  1400. pget->set_call_mode(VisualScriptPropertyGet::CALL_MODE_SELF);
  1401. } else {
  1402. pget->set_call_mode(VisualScriptPropertyGet::CALL_MODE_NODE_PATH);
  1403. pget->set_base_path(sn->get_path_to(node));
  1404. }
  1405. vnode = pget;
  1406. }
  1407. undo_redo->add_do_method(script.ptr(), "add_node", edited_func, base_id, vnode, ofs);
  1408. undo_redo->add_do_method(vnode.ptr(), "set_property", d["property"]);
  1409. if (!use_get) {
  1410. undo_redo->add_do_method(vnode.ptr(), "set_default_input_value", 0, d["value"]);
  1411. }
  1412. undo_redo->add_undo_method(script.ptr(), "remove_node", edited_func, base_id);
  1413. undo_redo->add_do_method(this, "_update_graph");
  1414. undo_redo->add_undo_method(this, "_update_graph");
  1415. undo_redo->commit_action();
  1416. }
  1417. }
  1418. }
  1419. void VisualScriptEditor::_selected_method(const String &p_method) {
  1420. Ref<VisualScriptFunctionCall> vsfc = script->get_node(edited_func, selecting_method_id);
  1421. if (!vsfc.is_valid())
  1422. return;
  1423. vsfc->set_function(p_method);
  1424. }
  1425. void VisualScriptEditor::_draw_color_over_button(Object *obj, Color p_color) {
  1426. Button *button = Object::cast_to<Button>(obj);
  1427. if (!button)
  1428. return;
  1429. Ref<StyleBox> normal = get_stylebox("normal", "Button");
  1430. button->draw_rect(Rect2(normal->get_offset(), button->get_size() - normal->get_minimum_size()), p_color);
  1431. }
  1432. void VisualScriptEditor::_button_resource_previewed(const String &p_path, const Ref<Texture> &p_preview, Variant p_ud) {
  1433. Array ud = p_ud;
  1434. ERR_FAIL_COND(ud.size() != 2);
  1435. ObjectID id = ud[0];
  1436. Object *obj = ObjectDB::get_instance(id);
  1437. if (!obj)
  1438. return;
  1439. Button *b = Object::cast_to<Button>(obj);
  1440. ERR_FAIL_COND(!b);
  1441. if (p_preview.is_null()) {
  1442. b->set_text(ud[1]);
  1443. } else {
  1444. b->set_icon(p_preview);
  1445. }
  1446. }
  1447. /////////////////////////
  1448. void VisualScriptEditor::apply_code() {
  1449. }
  1450. Ref<Script> VisualScriptEditor::get_edited_script() const {
  1451. return script;
  1452. }
  1453. Vector<String> VisualScriptEditor::get_functions() {
  1454. return Vector<String>();
  1455. }
  1456. void VisualScriptEditor::set_edited_script(const Ref<Script> &p_script) {
  1457. script = p_script;
  1458. signal_editor->script = p_script;
  1459. signal_editor->undo_redo = undo_redo;
  1460. variable_editor->script = p_script;
  1461. variable_editor->undo_redo = undo_redo;
  1462. script->connect("node_ports_changed", this, "_node_ports_changed");
  1463. _update_members();
  1464. _update_available_nodes();
  1465. }
  1466. void VisualScriptEditor::reload_text() {
  1467. }
  1468. String VisualScriptEditor::get_name() {
  1469. String name;
  1470. if (script->get_path().find("local://") == -1 && script->get_path().find("::") == -1) {
  1471. name = script->get_path().get_file();
  1472. if (is_unsaved()) {
  1473. name += "(*)";
  1474. }
  1475. } else if (script->get_name() != "")
  1476. name = script->get_name();
  1477. else
  1478. name = script->get_class() + "(" + itos(script->get_instance_id()) + ")";
  1479. return name;
  1480. }
  1481. Ref<Texture> VisualScriptEditor::get_icon() {
  1482. return Control::get_icon("VisualScript", "EditorIcons");
  1483. }
  1484. bool VisualScriptEditor::is_unsaved() {
  1485. #ifdef TOOLS_ENABLED
  1486. return script->is_edited() || script->are_subnodes_edited();
  1487. #else
  1488. return false;
  1489. #endif
  1490. }
  1491. Variant VisualScriptEditor::get_edit_state() {
  1492. Dictionary d;
  1493. d["function"] = edited_func;
  1494. d["scroll"] = graph->get_scroll_ofs();
  1495. d["zoom"] = graph->get_zoom();
  1496. d["using_snap"] = graph->is_using_snap();
  1497. d["snap"] = graph->get_snap();
  1498. return d;
  1499. }
  1500. void VisualScriptEditor::set_edit_state(const Variant &p_state) {
  1501. Dictionary d = p_state;
  1502. if (d.has("function")) {
  1503. edited_func = p_state;
  1504. selected = edited_func;
  1505. }
  1506. _update_graph();
  1507. _update_members();
  1508. if (d.has("scroll")) {
  1509. graph->set_scroll_ofs(d["scroll"]);
  1510. }
  1511. if (d.has("zoom")) {
  1512. graph->set_zoom(d["zoom"]);
  1513. }
  1514. if (d.has("snap")) {
  1515. graph->set_snap(d["snap"]);
  1516. }
  1517. if (d.has("snap_enabled")) {
  1518. graph->set_use_snap(d["snap_enabled"]);
  1519. }
  1520. }
  1521. void VisualScriptEditor::_center_on_node(int p_id) {
  1522. Node *n = graph->get_node(itos(p_id));
  1523. GraphNode *gn = Object::cast_to<GraphNode>(n);
  1524. if (gn) {
  1525. gn->set_selected(true);
  1526. Vector2 new_scroll = gn->get_offset() - graph->get_size() * 0.5 + gn->get_size() * 0.5;
  1527. graph->set_scroll_ofs(new_scroll);
  1528. script->set_function_scroll(edited_func, new_scroll / EDSCALE);
  1529. script->set_edited(true); //so it's saved
  1530. }
  1531. }
  1532. void VisualScriptEditor::goto_line(int p_line, bool p_with_error) {
  1533. p_line += 1; //add one because script lines begin from 0.
  1534. if (p_with_error)
  1535. error_line = p_line;
  1536. List<StringName> functions;
  1537. script->get_function_list(&functions);
  1538. for (List<StringName>::Element *E = functions.front(); E; E = E->next()) {
  1539. if (script->has_node(E->get(), p_line)) {
  1540. edited_func = E->get();
  1541. selected = edited_func;
  1542. _update_graph();
  1543. _update_members();
  1544. call_deferred("call_deferred", "_center_on_node", p_line); //editor might be just created and size might not exist yet
  1545. return;
  1546. }
  1547. }
  1548. }
  1549. void VisualScriptEditor::trim_trailing_whitespace() {
  1550. }
  1551. void VisualScriptEditor::convert_indent_to_spaces() {
  1552. }
  1553. void VisualScriptEditor::convert_indent_to_tabs() {
  1554. }
  1555. void VisualScriptEditor::ensure_focus() {
  1556. graph->grab_focus();
  1557. }
  1558. void VisualScriptEditor::tag_saved_version() {
  1559. }
  1560. void VisualScriptEditor::reload(bool p_soft) {
  1561. }
  1562. void VisualScriptEditor::get_breakpoints(List<int> *p_breakpoints) {
  1563. List<StringName> functions;
  1564. script->get_function_list(&functions);
  1565. for (List<StringName>::Element *E = functions.front(); E; E = E->next()) {
  1566. List<int> nodes;
  1567. script->get_node_list(E->get(), &nodes);
  1568. for (List<int>::Element *F = nodes.front(); F; F = F->next()) {
  1569. Ref<VisualScriptNode> vsn = script->get_node(E->get(), F->get());
  1570. if (vsn->is_breakpoint()) {
  1571. p_breakpoints->push_back(F->get() - 1); //subtract 1 because breakpoints in text start from zero
  1572. }
  1573. }
  1574. }
  1575. }
  1576. void VisualScriptEditor::add_callback(const String &p_function, PoolStringArray p_args) {
  1577. if (script->has_function(p_function)) {
  1578. edited_func = p_function;
  1579. selected = edited_func;
  1580. _update_members();
  1581. _update_graph();
  1582. return;
  1583. }
  1584. Ref<VisualScriptFunction> func;
  1585. func.instance();
  1586. for (int i = 0; i < p_args.size(); i++) {
  1587. String name = p_args[i];
  1588. Variant::Type type = Variant::NIL;
  1589. if (name.find(":") != -1) {
  1590. String tt = name.get_slice(":", 1);
  1591. name = name.get_slice(":", 0);
  1592. for (int j = 0; j < Variant::VARIANT_MAX; j++) {
  1593. String tname = Variant::get_type_name(Variant::Type(j));
  1594. if (tname == tt) {
  1595. type = Variant::Type(j);
  1596. break;
  1597. }
  1598. }
  1599. }
  1600. func->add_argument(type, name);
  1601. }
  1602. func->set_name(p_function);
  1603. script->add_function(p_function);
  1604. script->add_node(p_function, script->get_available_id(), func);
  1605. edited_func = p_function;
  1606. selected = edited_func;
  1607. _update_members();
  1608. _update_graph();
  1609. graph->call_deferred("set_scroll_ofs", script->get_function_scroll(edited_func)); //for first time it might need to be later
  1610. //undo_redo->clear_history();
  1611. }
  1612. bool VisualScriptEditor::show_members_overview() {
  1613. return false;
  1614. }
  1615. void VisualScriptEditor::update_settings() {
  1616. _update_graph();
  1617. }
  1618. void VisualScriptEditor::set_debugger_active(bool p_active) {
  1619. if (!p_active) {
  1620. error_line = -1;
  1621. _update_graph(); //clear line break
  1622. }
  1623. }
  1624. void VisualScriptEditor::set_tooltip_request_func(String p_method, Object *p_obj) {
  1625. }
  1626. Control *VisualScriptEditor::get_edit_menu() {
  1627. return edit_menu;
  1628. }
  1629. void VisualScriptEditor::_change_base_type() {
  1630. select_base_type->popup_create(true);
  1631. }
  1632. void VisualScriptEditor::clear_edit_menu() {
  1633. memdelete(edit_menu);
  1634. memdelete(left_vsplit);
  1635. }
  1636. void VisualScriptEditor::_change_base_type_callback() {
  1637. String bt = select_base_type->get_selected_type();
  1638. ERR_FAIL_COND(bt == String());
  1639. undo_redo->create_action(TTR("Change Base Type"));
  1640. undo_redo->add_do_method(script.ptr(), "set_instance_base_type", bt);
  1641. undo_redo->add_undo_method(script.ptr(), "set_instance_base_type", script->get_instance_base_type());
  1642. undo_redo->add_do_method(this, "_update_members");
  1643. undo_redo->add_undo_method(this, "_update_members");
  1644. undo_redo->commit_action();
  1645. }
  1646. void VisualScriptEditor::_node_selected(Node *p_node) {
  1647. Ref<VisualScriptNode> vnode = p_node->get_meta("__vnode");
  1648. if (vnode.is_null())
  1649. return;
  1650. EditorNode::get_singleton()->push_item(vnode.ptr()); //edit node in inspector
  1651. }
  1652. static bool _get_out_slot(const Ref<VisualScriptNode> &p_node, int p_slot, int &r_real_slot, bool &r_sequence) {
  1653. if (p_slot < p_node->get_output_sequence_port_count()) {
  1654. r_sequence = true;
  1655. r_real_slot = p_slot;
  1656. return true;
  1657. }
  1658. r_real_slot = p_slot - p_node->get_output_sequence_port_count();
  1659. r_sequence = false;
  1660. return (r_real_slot < p_node->get_output_value_port_count());
  1661. }
  1662. static bool _get_in_slot(const Ref<VisualScriptNode> &p_node, int p_slot, int &r_real_slot, bool &r_sequence) {
  1663. if (p_slot == 0 && p_node->has_input_sequence_port()) {
  1664. r_sequence = true;
  1665. r_real_slot = 0;
  1666. return true;
  1667. }
  1668. r_real_slot = p_slot - (p_node->has_input_sequence_port() ? 1 : 0);
  1669. r_sequence = false;
  1670. return r_real_slot < p_node->get_input_value_port_count();
  1671. }
  1672. void VisualScriptEditor::_begin_node_move() {
  1673. undo_redo->create_action(TTR("Move Node(s)"));
  1674. }
  1675. void VisualScriptEditor::_end_node_move() {
  1676. undo_redo->commit_action();
  1677. }
  1678. void VisualScriptEditor::_move_node(String func, int p_id, const Vector2 &p_to) {
  1679. if (func == String(edited_func)) {
  1680. Node *node = graph->get_node(itos(p_id));
  1681. if (Object::cast_to<GraphNode>(node))
  1682. Object::cast_to<GraphNode>(node)->set_offset(p_to);
  1683. }
  1684. script->set_node_pos(edited_func, p_id, p_to / EDSCALE);
  1685. }
  1686. void VisualScriptEditor::_node_moved(Vector2 p_from, Vector2 p_to, int p_id) {
  1687. undo_redo->add_do_method(this, "_move_node", String(edited_func), p_id, p_to);
  1688. undo_redo->add_undo_method(this, "_move_node", String(edited_func), p_id, p_from);
  1689. }
  1690. void VisualScriptEditor::_remove_node(int p_id) {
  1691. undo_redo->create_action(TTR("Remove VisualScript Node"));
  1692. undo_redo->add_do_method(script.ptr(), "remove_node", edited_func, p_id);
  1693. undo_redo->add_undo_method(script.ptr(), "add_node", edited_func, p_id, script->get_node(edited_func, p_id), script->get_node_pos(edited_func, p_id));
  1694. List<VisualScript::SequenceConnection> sequence_conns;
  1695. script->get_sequence_connection_list(edited_func, &sequence_conns);
  1696. for (List<VisualScript::SequenceConnection>::Element *E = sequence_conns.front(); E; E = E->next()) {
  1697. if (E->get().from_node == p_id || E->get().to_node == p_id) {
  1698. undo_redo->add_undo_method(script.ptr(), "sequence_connect", edited_func, E->get().from_node, E->get().from_output, E->get().to_node);
  1699. }
  1700. }
  1701. List<VisualScript::DataConnection> data_conns;
  1702. script->get_data_connection_list(edited_func, &data_conns);
  1703. for (List<VisualScript::DataConnection>::Element *E = data_conns.front(); E; E = E->next()) {
  1704. if (E->get().from_node == p_id || E->get().to_node == p_id) {
  1705. undo_redo->add_undo_method(script.ptr(), "data_connect", edited_func, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port);
  1706. }
  1707. }
  1708. undo_redo->add_do_method(this, "_update_graph");
  1709. undo_redo->add_undo_method(this, "_update_graph");
  1710. undo_redo->commit_action();
  1711. }
  1712. void VisualScriptEditor::_node_ports_changed(const String &p_func, int p_id) {
  1713. if (p_func != String(edited_func))
  1714. return;
  1715. _update_graph(p_id);
  1716. }
  1717. void VisualScriptEditor::_graph_connected(const String &p_from, int p_from_slot, const String &p_to, int p_to_slot) {
  1718. Ref<VisualScriptNode> from_node = script->get_node(edited_func, p_from.to_int());
  1719. ERR_FAIL_COND(!from_node.is_valid());
  1720. bool from_seq;
  1721. int from_port;
  1722. if (!_get_out_slot(from_node, p_from_slot, from_port, from_seq))
  1723. return; //can't connect this, it' s invalid
  1724. Ref<VisualScriptNode> to_node = script->get_node(edited_func, p_to.to_int());
  1725. ERR_FAIL_COND(!to_node.is_valid());
  1726. bool to_seq;
  1727. int to_port;
  1728. if (!_get_in_slot(to_node, p_to_slot, to_port, to_seq))
  1729. return; //can't connect this, it' s invalid
  1730. ERR_FAIL_COND(from_seq != to_seq);
  1731. undo_redo->create_action(TTR("Connect Nodes"));
  1732. if (from_seq) {
  1733. undo_redo->add_do_method(script.ptr(), "sequence_connect", edited_func, p_from.to_int(), from_port, p_to.to_int());
  1734. undo_redo->add_undo_method(script.ptr(), "sequence_disconnect", edited_func, p_from.to_int(), from_port, p_to.to_int());
  1735. } else {
  1736. // disconect current, and connect the new one
  1737. if (script->is_input_value_port_connected(edited_func, p_to.to_int(), to_port)) {
  1738. int conn_from;
  1739. int conn_port;
  1740. script->get_input_value_port_connection_source(edited_func, p_to.to_int(), to_port, &conn_from, &conn_port);
  1741. undo_redo->add_do_method(script.ptr(), "data_disconnect", edited_func, conn_from, conn_port, p_to.to_int(), to_port);
  1742. undo_redo->add_undo_method(script.ptr(), "data_connect", edited_func, conn_from, conn_port, p_to.to_int(), to_port);
  1743. }
  1744. undo_redo->add_do_method(script.ptr(), "data_connect", edited_func, p_from.to_int(), from_port, p_to.to_int(), to_port);
  1745. undo_redo->add_undo_method(script.ptr(), "data_disconnect", edited_func, p_from.to_int(), from_port, p_to.to_int(), to_port);
  1746. //update nodes in sgraph
  1747. undo_redo->add_do_method(this, "_update_graph", p_from.to_int());
  1748. undo_redo->add_do_method(this, "_update_graph", p_to.to_int());
  1749. undo_redo->add_undo_method(this, "_update_graph", p_from.to_int());
  1750. undo_redo->add_undo_method(this, "_update_graph", p_to.to_int());
  1751. }
  1752. undo_redo->add_do_method(this, "_update_graph_connections");
  1753. undo_redo->add_undo_method(this, "_update_graph_connections");
  1754. undo_redo->commit_action();
  1755. }
  1756. void VisualScriptEditor::_graph_disconnected(const String &p_from, int p_from_slot, const String &p_to, int p_to_slot) {
  1757. Ref<VisualScriptNode> from_node = script->get_node(edited_func, p_from.to_int());
  1758. ERR_FAIL_COND(!from_node.is_valid());
  1759. bool from_seq;
  1760. int from_port;
  1761. if (!_get_out_slot(from_node, p_from_slot, from_port, from_seq))
  1762. return; //can't connect this, it' s invalid
  1763. Ref<VisualScriptNode> to_node = script->get_node(edited_func, p_to.to_int());
  1764. ERR_FAIL_COND(!to_node.is_valid());
  1765. bool to_seq;
  1766. int to_port;
  1767. if (!_get_in_slot(to_node, p_to_slot, to_port, to_seq))
  1768. return; //can't connect this, it' s invalid
  1769. ERR_FAIL_COND(from_seq != to_seq);
  1770. undo_redo->create_action(TTR("Connect Nodes"));
  1771. if (from_seq) {
  1772. undo_redo->add_do_method(script.ptr(), "sequence_disconnect", edited_func, p_from.to_int(), from_port, p_to.to_int());
  1773. undo_redo->add_undo_method(script.ptr(), "sequence_connect", edited_func, p_from.to_int(), from_port, p_to.to_int());
  1774. } else {
  1775. undo_redo->add_do_method(script.ptr(), "data_disconnect", edited_func, p_from.to_int(), from_port, p_to.to_int(), to_port);
  1776. undo_redo->add_undo_method(script.ptr(), "data_connect", edited_func, p_from.to_int(), from_port, p_to.to_int(), to_port);
  1777. //update nodes in sgraph
  1778. undo_redo->add_do_method(this, "_update_graph", p_from.to_int());
  1779. undo_redo->add_do_method(this, "_update_graph", p_to.to_int());
  1780. undo_redo->add_undo_method(this, "_update_graph", p_from.to_int());
  1781. undo_redo->add_undo_method(this, "_update_graph", p_to.to_int());
  1782. }
  1783. undo_redo->add_do_method(this, "_update_graph_connections");
  1784. undo_redo->add_undo_method(this, "_update_graph_connections");
  1785. undo_redo->commit_action();
  1786. }
  1787. void VisualScriptEditor::_graph_connect_to_empty(const String &p_from, int p_from_slot, const Vector2 &p_release_pos) {
  1788. Node *node = graph->get_node(p_from);
  1789. GraphNode *gn = Object::cast_to<GraphNode>(node);
  1790. if (!gn)
  1791. return;
  1792. Ref<VisualScriptNode> vsn = script->get_node(edited_func, p_from.to_int());
  1793. if (!vsn.is_valid())
  1794. return;
  1795. if (p_from_slot < vsn->get_output_sequence_port_count()) {
  1796. port_action_popup->clear();
  1797. port_action_popup->add_item(TTR("Condition"), CREATE_COND);
  1798. port_action_popup->add_item(TTR("Sequence"), CREATE_SEQUENCE);
  1799. port_action_popup->add_item(TTR("Switch"), CREATE_SWITCH);
  1800. port_action_popup->add_item(TTR("Iterator"), CREATE_ITERATOR);
  1801. port_action_popup->add_item(TTR("While"), CREATE_WHILE);
  1802. port_action_popup->add_item(TTR("Return"), CREATE_RETURN);
  1803. port_action_node = p_from.to_int();
  1804. port_action_output = p_from_slot;
  1805. } else {
  1806. port_action_popup->clear();
  1807. port_action_popup->add_item(TTR("Call"), CREATE_CALL);
  1808. port_action_popup->add_item(TTR("Get"), CREATE_GET);
  1809. port_action_popup->add_item(TTR("Set"), CREATE_SET);
  1810. port_action_output = p_from_slot - vsn->get_output_sequence_port_count();
  1811. port_action_node = p_from.to_int();
  1812. }
  1813. port_action_pos = p_release_pos;
  1814. port_action_popup->set_size(Size2(1, 1));
  1815. port_action_popup->set_position(graph->get_global_position() + p_release_pos);
  1816. port_action_popup->popup();
  1817. }
  1818. VisualScriptNode::TypeGuess VisualScriptEditor::_guess_output_type(int p_port_action_node, int p_port_action_output, Set<int> &visited_nodes) {
  1819. VisualScriptNode::TypeGuess tg;
  1820. tg.type = Variant::NIL;
  1821. if (visited_nodes.has(p_port_action_node))
  1822. return tg; //no loop
  1823. visited_nodes.insert(p_port_action_node);
  1824. Ref<VisualScriptNode> node = script->get_node(edited_func, p_port_action_node);
  1825. if (!node.is_valid()) {
  1826. return tg;
  1827. }
  1828. Vector<VisualScriptNode::TypeGuess> in_guesses;
  1829. for (int i = 0; i < node->get_input_value_port_count(); i++) {
  1830. PropertyInfo pi = node->get_input_value_port_info(i);
  1831. VisualScriptNode::TypeGuess g;
  1832. g.type = pi.type;
  1833. if (g.type == Variant::NIL || g.type == Variant::OBJECT) {
  1834. //any or object input, must further guess what this is
  1835. int from_node;
  1836. int from_port;
  1837. if (script->get_input_value_port_connection_source(edited_func, p_port_action_node, i, &from_node, &from_port)) {
  1838. g = _guess_output_type(from_node, from_port, visited_nodes);
  1839. } else {
  1840. Variant defval = node->get_default_input_value(i);
  1841. if (defval.get_type() == Variant::OBJECT) {
  1842. Object *obj = defval;
  1843. if (obj) {
  1844. g.type = Variant::OBJECT;
  1845. g.gdclass = obj->get_class();
  1846. g.script = obj->get_script();
  1847. }
  1848. }
  1849. }
  1850. }
  1851. in_guesses.push_back(g);
  1852. }
  1853. return node->guess_output_type(in_guesses.ptr(), p_port_action_output);
  1854. }
  1855. void VisualScriptEditor::_port_action_menu(int p_option) {
  1856. Vector2 ofs = graph->get_scroll_ofs() + port_action_pos;
  1857. if (graph->is_using_snap()) {
  1858. int snap = graph->get_snap();
  1859. ofs = ofs.snapped(Vector2(snap, snap));
  1860. }
  1861. ofs /= EDSCALE;
  1862. bool seq_connect = false;
  1863. Ref<VisualScriptNode> vnode;
  1864. Set<int> vn;
  1865. switch (p_option) {
  1866. case CREATE_CALL: {
  1867. Ref<VisualScriptFunctionCall> n;
  1868. n.instance();
  1869. vnode = n;
  1870. VisualScriptNode::TypeGuess tg = _guess_output_type(port_action_node, port_action_output, vn);
  1871. if (tg.type == Variant::OBJECT) {
  1872. n->set_call_mode(VisualScriptFunctionCall::CALL_MODE_INSTANCE);
  1873. if (tg.gdclass != StringName()) {
  1874. n->set_base_type(tg.gdclass);
  1875. } else {
  1876. n->set_base_type("Object");
  1877. }
  1878. if (tg.script.is_valid()) {
  1879. n->set_base_script(tg.script->get_path());
  1880. new_connect_node_select->select_method_from_script(tg.script);
  1881. } else {
  1882. new_connect_node_select->select_method_from_base_type(n->get_base_type());
  1883. }
  1884. } else {
  1885. n->set_call_mode(VisualScriptFunctionCall::CALL_MODE_BASIC_TYPE);
  1886. n->set_basic_type(tg.type);
  1887. new_connect_node_select->select_method_from_basic_type(tg.type);
  1888. }
  1889. } break;
  1890. case CREATE_SET: {
  1891. Ref<VisualScriptPropertySet> n;
  1892. n.instance();
  1893. vnode = n;
  1894. VisualScriptNode::TypeGuess tg = _guess_output_type(port_action_node, port_action_output, vn);
  1895. if (tg.type == Variant::OBJECT) {
  1896. n->set_call_mode(VisualScriptPropertySet::CALL_MODE_INSTANCE);
  1897. if (tg.gdclass != StringName()) {
  1898. n->set_base_type(tg.gdclass);
  1899. } else {
  1900. n->set_base_type("Object");
  1901. }
  1902. if (tg.script.is_valid()) {
  1903. n->set_base_script(tg.script->get_path());
  1904. new_connect_node_select->select_property_from_script(tg.script);
  1905. } else {
  1906. new_connect_node_select->select_property_from_base_type(n->get_base_type());
  1907. }
  1908. } else {
  1909. n->set_call_mode(VisualScriptPropertySet::CALL_MODE_BASIC_TYPE);
  1910. n->set_basic_type(tg.type);
  1911. new_connect_node_select->select_property_from_basic_type(tg.type);
  1912. }
  1913. } break;
  1914. case CREATE_GET: {
  1915. Ref<VisualScriptPropertyGet> n;
  1916. n.instance();
  1917. vnode = n;
  1918. VisualScriptNode::TypeGuess tg = _guess_output_type(port_action_node, port_action_output, vn);
  1919. if (tg.type == Variant::OBJECT) {
  1920. n->set_call_mode(VisualScriptPropertyGet::CALL_MODE_INSTANCE);
  1921. if (tg.gdclass != StringName()) {
  1922. n->set_base_type(tg.gdclass);
  1923. } else {
  1924. n->set_base_type("Object");
  1925. }
  1926. if (tg.script.is_valid()) {
  1927. n->set_base_script(tg.script->get_path());
  1928. new_connect_node_select->select_property_from_script(tg.script);
  1929. } else {
  1930. new_connect_node_select->select_property_from_base_type(n->get_base_type());
  1931. }
  1932. } else {
  1933. n->set_call_mode(VisualScriptPropertyGet::CALL_MODE_BASIC_TYPE);
  1934. n->set_basic_type(tg.type);
  1935. new_connect_node_select->select_property_from_basic_type(tg.type);
  1936. }
  1937. } break;
  1938. case CREATE_COND: {
  1939. Ref<VisualScriptCondition> n;
  1940. n.instance();
  1941. vnode = n;
  1942. seq_connect = true;
  1943. } break;
  1944. case CREATE_SEQUENCE: {
  1945. Ref<VisualScriptSequence> n;
  1946. n.instance();
  1947. vnode = n;
  1948. seq_connect = true;
  1949. } break;
  1950. case CREATE_SWITCH: {
  1951. Ref<VisualScriptSwitch> n;
  1952. n.instance();
  1953. vnode = n;
  1954. seq_connect = true;
  1955. } break;
  1956. case CREATE_ITERATOR: {
  1957. Ref<VisualScriptIterator> n;
  1958. n.instance();
  1959. vnode = n;
  1960. seq_connect = true;
  1961. } break;
  1962. case CREATE_WHILE: {
  1963. Ref<VisualScriptWhile> n;
  1964. n.instance();
  1965. vnode = n;
  1966. seq_connect = true;
  1967. } break;
  1968. case CREATE_RETURN: {
  1969. Ref<VisualScriptReturn> n;
  1970. n.instance();
  1971. vnode = n;
  1972. seq_connect = true;
  1973. } break;
  1974. }
  1975. int new_id = script->get_available_id();
  1976. undo_redo->create_action(TTR("Add Node"));
  1977. undo_redo->add_do_method(script.ptr(), "add_node", edited_func, new_id, vnode, ofs);
  1978. if (seq_connect) {
  1979. undo_redo->add_do_method(script.ptr(), "sequence_connect", edited_func, port_action_node, port_action_output, new_id);
  1980. }
  1981. undo_redo->add_undo_method(script.ptr(), "remove_node", edited_func, new_id);
  1982. undo_redo->add_do_method(this, "_update_graph", new_id);
  1983. undo_redo->add_undo_method(this, "_update_graph", new_id);
  1984. undo_redo->commit_action();
  1985. port_action_new_node = new_id;
  1986. }
  1987. void VisualScriptEditor::_selected_connect_node_method_or_setget(const String &p_text) {
  1988. Ref<VisualScriptNode> vsn = script->get_node(edited_func, port_action_new_node);
  1989. if (Object::cast_to<VisualScriptFunctionCall>(vsn.ptr())) {
  1990. Ref<VisualScriptFunctionCall> vsfc = vsn;
  1991. vsfc->set_function(p_text);
  1992. script->data_connect(edited_func, port_action_node, port_action_output, port_action_new_node, 0);
  1993. }
  1994. if (Object::cast_to<VisualScriptPropertySet>(vsn.ptr())) {
  1995. Ref<VisualScriptPropertySet> vsp = vsn;
  1996. vsp->set_property(p_text);
  1997. script->data_connect(edited_func, port_action_node, port_action_output, port_action_new_node, 0);
  1998. }
  1999. if (Object::cast_to<VisualScriptPropertyGet>(vsn.ptr())) {
  2000. Ref<VisualScriptPropertyGet> vsp = vsn;
  2001. vsp->set_property(p_text);
  2002. script->data_connect(edited_func, port_action_node, port_action_output, port_action_new_node, 0);
  2003. }
  2004. _update_graph(port_action_new_node);
  2005. _update_graph_connections();
  2006. }
  2007. void VisualScriptEditor::_selected_new_virtual_method(const String &p_text) {
  2008. String name = p_text;
  2009. if (script->has_function(name)) {
  2010. EditorNode::get_singleton()->show_warning(vformat(TTR("Script already has function '%s'"), name));
  2011. return;
  2012. }
  2013. MethodInfo minfo;
  2014. {
  2015. List<MethodInfo> methods;
  2016. bool found = false;
  2017. ClassDB::get_virtual_methods(script->get_instance_base_type(), &methods);
  2018. for (List<MethodInfo>::Element *E = methods.front(); E; E = E->next()) {
  2019. if (E->get().name == name) {
  2020. minfo = E->get();
  2021. found = true;
  2022. }
  2023. }
  2024. ERR_FAIL_COND(!found);
  2025. }
  2026. selected = name;
  2027. edited_func = selected;
  2028. Ref<VisualScriptFunction> func_node;
  2029. func_node.instance();
  2030. func_node->set_name(name);
  2031. undo_redo->create_action(TTR("Add Function"));
  2032. undo_redo->add_do_method(script.ptr(), "add_function", name);
  2033. for (int i = 0; i < minfo.arguments.size(); i++) {
  2034. func_node->add_argument(minfo.arguments[i].type, minfo.arguments[i].name);
  2035. }
  2036. undo_redo->add_do_method(script.ptr(), "add_node", name, script->get_available_id(), func_node);
  2037. if (minfo.return_val.type != Variant::NIL || minfo.return_val.usage & PROPERTY_USAGE_NIL_IS_VARIANT) {
  2038. Ref<VisualScriptReturn> ret_node;
  2039. ret_node.instance();
  2040. ret_node->set_return_type(minfo.return_val.type);
  2041. ret_node->set_enable_return_value(true);
  2042. ret_node->set_name(name);
  2043. undo_redo->add_do_method(script.ptr(), "add_node", name, script->get_available_id() + 1, ret_node, Vector2(500, 0));
  2044. }
  2045. undo_redo->add_undo_method(script.ptr(), "remove_function", name);
  2046. undo_redo->add_do_method(this, "_update_members");
  2047. undo_redo->add_undo_method(this, "_update_members");
  2048. undo_redo->add_do_method(this, "_update_graph");
  2049. undo_redo->add_undo_method(this, "_update_graph");
  2050. undo_redo->commit_action();
  2051. _update_graph();
  2052. }
  2053. void VisualScriptEditor::_cancel_connect_node_method_or_setget() {
  2054. script->remove_node(edited_func, port_action_new_node);
  2055. _update_graph();
  2056. }
  2057. void VisualScriptEditor::_default_value_changed() {
  2058. Ref<VisualScriptNode> vsn = script->get_node(edited_func, editing_id);
  2059. if (vsn.is_null())
  2060. return;
  2061. undo_redo->create_action(TTR("Change Input Value"));
  2062. undo_redo->add_do_method(vsn.ptr(), "set_default_input_value", editing_input, default_value_edit->get_variant());
  2063. undo_redo->add_undo_method(vsn.ptr(), "set_default_input_value", editing_input, vsn->get_default_input_value(editing_input));
  2064. undo_redo->add_do_method(this, "_update_graph", editing_id);
  2065. undo_redo->add_undo_method(this, "_update_graph", editing_id);
  2066. undo_redo->commit_action();
  2067. }
  2068. void VisualScriptEditor::_default_value_edited(Node *p_button, int p_id, int p_input_port) {
  2069. Ref<VisualScriptNode> vsn = script->get_node(edited_func, p_id);
  2070. if (vsn.is_null())
  2071. return;
  2072. PropertyInfo pinfo = vsn->get_input_value_port_info(p_input_port);
  2073. Variant existing = vsn->get_default_input_value(p_input_port);
  2074. if (pinfo.type != Variant::NIL && existing.get_type() != pinfo.type) {
  2075. Variant::CallError ce;
  2076. const Variant *existingp = &existing;
  2077. existing = Variant::construct(pinfo.type, &existingp, 1, ce, false);
  2078. }
  2079. default_value_edit->set_position(Object::cast_to<Control>(p_button)->get_global_position() + Vector2(0, Object::cast_to<Control>(p_button)->get_size().y));
  2080. default_value_edit->set_size(Size2(1, 1));
  2081. if (default_value_edit->edit(NULL, pinfo.name, pinfo.type, existing, pinfo.hint, pinfo.hint_string)) {
  2082. if (pinfo.hint == PROPERTY_HINT_MULTILINE_TEXT)
  2083. default_value_edit->popup_centered_ratio();
  2084. else
  2085. default_value_edit->popup();
  2086. }
  2087. editing_id = p_id;
  2088. editing_input = p_input_port;
  2089. }
  2090. void VisualScriptEditor::_show_hint(const String &p_hint) {
  2091. hint_text->set_text(p_hint);
  2092. hint_text->show();
  2093. hint_text_timer->start();
  2094. }
  2095. void VisualScriptEditor::_hide_timer() {
  2096. hint_text->hide();
  2097. }
  2098. void VisualScriptEditor::_node_filter_changed(const String &p_text) {
  2099. _update_available_nodes();
  2100. }
  2101. void VisualScriptEditor::_notification(int p_what) {
  2102. if (p_what == NOTIFICATION_READY) {
  2103. node_filter->add_icon_override("right_icon", Control::get_icon("Search", "EditorIcons"));
  2104. variable_editor->connect("changed", this, "_update_members");
  2105. signal_editor->connect("changed", this, "_update_members");
  2106. List<Pair<String, Color> > colors;
  2107. colors.push_back(Pair<String, Color>("functions", Color(1, 0.9, 0.9)));
  2108. colors.push_back(Pair<String, Color>("data", Color(0.9, 1.0, 0.9)));
  2109. colors.push_back(Pair<String, Color>("operators", Color(0.9, 0.9, 1.0)));
  2110. colors.push_back(Pair<String, Color>("flow_control", Color(1.0, 1.0, 1.0)));
  2111. colors.push_back(Pair<String, Color>("custom", Color(0.8, 1.0, 1.0)));
  2112. colors.push_back(Pair<String, Color>("constants", Color(1.0, 0.8, 1.0)));
  2113. for (List<Pair<String, Color> >::Element *E = colors.front(); E; E = E->next()) {
  2114. print_line(E->get().first);
  2115. Ref<StyleBoxFlat> sb = EditorNode::get_singleton()->get_theme_base()->get_theme()->get_stylebox("frame", "GraphNode");
  2116. if (sb != NULL) {
  2117. Ref<StyleBoxFlat> frame_style = sb->duplicate();
  2118. Color c = sb->get_border_color(MARGIN_TOP);
  2119. Color cn = E->get().second;
  2120. cn.a = c.a;
  2121. frame_style->set_border_color_all(cn);
  2122. node_styles[E->get().first] = frame_style;
  2123. }
  2124. }
  2125. }
  2126. if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
  2127. left_vsplit->set_visible(is_visible_in_tree());
  2128. }
  2129. }
  2130. void VisualScriptEditor::_graph_ofs_changed(const Vector2 &p_ofs) {
  2131. if (updating_graph || !script.is_valid())
  2132. return;
  2133. updating_graph = true;
  2134. if (script->has_function(edited_func)) {
  2135. script->set_function_scroll(edited_func, graph->get_scroll_ofs() / EDSCALE);
  2136. script->set_edited(true);
  2137. }
  2138. updating_graph = false;
  2139. }
  2140. void VisualScriptEditor::_comment_node_resized(const Vector2 &p_new_size, int p_node) {
  2141. if (updating_graph)
  2142. return;
  2143. Ref<VisualScriptComment> vsc = script->get_node(edited_func, p_node);
  2144. if (vsc.is_null())
  2145. return;
  2146. Node *node = graph->get_node(itos(p_node));
  2147. GraphNode *gn = Object::cast_to<GraphNode>(node);
  2148. if (!gn)
  2149. return;
  2150. updating_graph = true;
  2151. graph->set_block_minimum_size_adjust(true); //faster resize
  2152. undo_redo->create_action("Resize Comment", UndoRedo::MERGE_ENDS);
  2153. undo_redo->add_do_method(vsc.ptr(), "set_size", p_new_size / EDSCALE);
  2154. undo_redo->add_undo_method(vsc.ptr(), "set_size", vsc->get_size());
  2155. undo_redo->commit_action();
  2156. gn->set_custom_minimum_size(p_new_size); //for this time since graph update is blocked
  2157. gn->set_size(Size2(1, 1));
  2158. graph->set_block_minimum_size_adjust(false);
  2159. updating_graph = false;
  2160. }
  2161. void VisualScriptEditor::_menu_option(int p_what) {
  2162. switch (p_what) {
  2163. case EDIT_DELETE_NODES: {
  2164. _on_nodes_delete();
  2165. } break;
  2166. case EDIT_TOGGLE_BREAKPOINT: {
  2167. List<String> reselect;
  2168. for (int i = 0; i < graph->get_child_count(); i++) {
  2169. GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i));
  2170. if (gn) {
  2171. if (gn->is_selected()) {
  2172. int id = String(gn->get_name()).to_int();
  2173. Ref<VisualScriptNode> vsn = script->get_node(edited_func, id);
  2174. if (vsn.is_valid()) {
  2175. vsn->set_breakpoint(!vsn->is_breakpoint());
  2176. reselect.push_back(gn->get_name());
  2177. }
  2178. }
  2179. }
  2180. }
  2181. _update_graph();
  2182. for (List<String>::Element *E = reselect.front(); E; E = E->next()) {
  2183. GraphNode *gn = Object::cast_to<GraphNode>(graph->get_node(E->get()));
  2184. gn->set_selected(true);
  2185. }
  2186. } break;
  2187. case EDIT_FIND_NODE_TYPE: {
  2188. //popup disappearing grabs focus to owner, so use call deferred
  2189. node_filter->call_deferred("grab_focus");
  2190. node_filter->call_deferred("select_all");
  2191. } break;
  2192. case EDIT_COPY_NODES:
  2193. case EDIT_CUT_NODES: {
  2194. if (!script->has_function(edited_func))
  2195. break;
  2196. clipboard->nodes.clear();
  2197. clipboard->data_connections.clear();
  2198. clipboard->sequence_connections.clear();
  2199. for (int i = 0; i < graph->get_child_count(); i++) {
  2200. GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i));
  2201. if (gn) {
  2202. if (gn->is_selected()) {
  2203. int id = String(gn->get_name()).to_int();
  2204. Ref<VisualScriptNode> node = script->get_node(edited_func, id);
  2205. if (Object::cast_to<VisualScriptFunction>(*node)) {
  2206. EditorNode::get_singleton()->show_warning(TTR("Can't copy the function node."));
  2207. return;
  2208. }
  2209. if (node.is_valid()) {
  2210. clipboard->nodes[id] = node->duplicate();
  2211. clipboard->nodes_positions[id] = script->get_node_pos(edited_func, id);
  2212. }
  2213. }
  2214. }
  2215. }
  2216. if (clipboard->nodes.empty())
  2217. break;
  2218. List<VisualScript::SequenceConnection> sequence_connections;
  2219. script->get_sequence_connection_list(edited_func, &sequence_connections);
  2220. for (List<VisualScript::SequenceConnection>::Element *E = sequence_connections.front(); E; E = E->next()) {
  2221. if (clipboard->nodes.has(E->get().from_node) && clipboard->nodes.has(E->get().to_node)) {
  2222. clipboard->sequence_connections.insert(E->get());
  2223. }
  2224. }
  2225. List<VisualScript::DataConnection> data_connections;
  2226. script->get_data_connection_list(edited_func, &data_connections);
  2227. for (List<VisualScript::DataConnection>::Element *E = data_connections.front(); E; E = E->next()) {
  2228. if (clipboard->nodes.has(E->get().from_node) && clipboard->nodes.has(E->get().to_node)) {
  2229. clipboard->data_connections.insert(E->get());
  2230. }
  2231. }
  2232. if (p_what == EDIT_CUT_NODES) {
  2233. _on_nodes_delete(); // oh yeah, also delete on cut
  2234. }
  2235. } break;
  2236. case EDIT_PASTE_NODES: {
  2237. if (!script->has_function(edited_func))
  2238. break;
  2239. if (clipboard->nodes.empty()) {
  2240. EditorNode::get_singleton()->show_warning(TTR("Clipboard is empty!"));
  2241. break;
  2242. }
  2243. Map<int, int> remap;
  2244. undo_redo->create_action(TTR("Paste VisualScript Nodes"));
  2245. int idc = script->get_available_id() + 1;
  2246. Set<int> to_select;
  2247. Set<Vector2> existing_positions;
  2248. {
  2249. List<int> nodes;
  2250. script->get_node_list(edited_func, &nodes);
  2251. for (List<int>::Element *E = nodes.front(); E; E = E->next()) {
  2252. Vector2 pos = script->get_node_pos(edited_func, E->get()).snapped(Vector2(2, 2));
  2253. existing_positions.insert(pos);
  2254. }
  2255. }
  2256. for (Map<int, Ref<VisualScriptNode> >::Element *E = clipboard->nodes.front(); E; E = E->next()) {
  2257. Ref<VisualScriptNode> node = E->get()->duplicate();
  2258. int new_id = idc++;
  2259. to_select.insert(new_id);
  2260. remap[E->key()] = new_id;
  2261. Vector2 paste_pos = clipboard->nodes_positions[E->key()];
  2262. while (existing_positions.has(paste_pos.snapped(Vector2(2, 2)))) {
  2263. paste_pos += Vector2(20, 20) * EDSCALE;
  2264. }
  2265. undo_redo->add_do_method(script.ptr(), "add_node", edited_func, new_id, node, paste_pos);
  2266. undo_redo->add_undo_method(script.ptr(), "remove_node", edited_func, new_id);
  2267. }
  2268. for (Set<VisualScript::SequenceConnection>::Element *E = clipboard->sequence_connections.front(); E; E = E->next()) {
  2269. undo_redo->add_do_method(script.ptr(), "sequence_connect", edited_func, remap[E->get().from_node], E->get().from_output, remap[E->get().to_node]);
  2270. undo_redo->add_undo_method(script.ptr(), "sequence_disconnect", edited_func, remap[E->get().from_node], E->get().from_output, remap[E->get().to_node]);
  2271. }
  2272. for (Set<VisualScript::DataConnection>::Element *E = clipboard->data_connections.front(); E; E = E->next()) {
  2273. undo_redo->add_do_method(script.ptr(), "data_connect", edited_func, remap[E->get().from_node], E->get().from_port, remap[E->get().to_node], E->get().to_port);
  2274. undo_redo->add_undo_method(script.ptr(), "data_disconnect", edited_func, remap[E->get().from_node], E->get().from_port, remap[E->get().to_node], E->get().to_port);
  2275. }
  2276. undo_redo->add_do_method(this, "_update_graph");
  2277. undo_redo->add_undo_method(this, "_update_graph");
  2278. undo_redo->commit_action();
  2279. for (int i = 0; i < graph->get_child_count(); i++) {
  2280. GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i));
  2281. if (gn) {
  2282. int id = gn->get_name().operator String().to_int();
  2283. gn->set_selected(to_select.has(id));
  2284. }
  2285. }
  2286. } break;
  2287. }
  2288. }
  2289. void VisualScriptEditor::_member_rmb_selected(const Vector2 &p_pos) {
  2290. TreeItem *ti = members->get_selected();
  2291. ERR_FAIL_COND(!ti);
  2292. member_popup->clear();
  2293. member_popup->set_position(members->get_global_position() + p_pos);
  2294. member_popup->set_size(Vector2());
  2295. TreeItem *root = members->get_root();
  2296. Ref<Texture> del_icon = Control::get_icon("Remove", "EditorIcons");
  2297. Ref<Texture> edit_icon = Control::get_icon("Edit", "EditorIcons");
  2298. if (ti->get_parent() == root->get_children()) {
  2299. member_type = MEMBER_FUNCTION;
  2300. member_name = ti->get_text(0);
  2301. member_popup->add_icon_item(del_icon, TTR("Remove Function"), MEMBER_REMOVE);
  2302. member_popup->popup();
  2303. return;
  2304. }
  2305. if (ti->get_parent() == root->get_children()->get_next()) {
  2306. member_type = MEMBER_VARIABLE;
  2307. member_name = ti->get_text(0);
  2308. member_popup->add_icon_item(edit_icon, TTR("Edit Variable"), MEMBER_EDIT);
  2309. member_popup->add_separator();
  2310. member_popup->add_icon_item(del_icon, TTR("Remove Variable"), MEMBER_REMOVE);
  2311. member_popup->popup();
  2312. return;
  2313. }
  2314. if (ti->get_parent() == root->get_children()->get_next()->get_next()) {
  2315. member_type = MEMBER_SIGNAL;
  2316. member_name = ti->get_text(0);
  2317. member_popup->add_icon_item(edit_icon, TTR("Edit Signal"), MEMBER_EDIT);
  2318. member_popup->add_separator();
  2319. member_popup->add_icon_item(del_icon, TTR("Remove Signal"), MEMBER_REMOVE);
  2320. member_popup->popup();
  2321. return;
  2322. }
  2323. }
  2324. void VisualScriptEditor::_member_option(int p_option) {
  2325. switch (member_type) {
  2326. case MEMBER_FUNCTION: {
  2327. if (p_option == MEMBER_REMOVE) {
  2328. //delete the function
  2329. String name = member_name;
  2330. undo_redo->create_action(TTR("Remove Function"));
  2331. undo_redo->add_do_method(script.ptr(), "remove_function", name);
  2332. undo_redo->add_undo_method(script.ptr(), "add_function", name);
  2333. List<int> nodes;
  2334. script->get_node_list(name, &nodes);
  2335. for (List<int>::Element *E = nodes.front(); E; E = E->next()) {
  2336. undo_redo->add_undo_method(script.ptr(), "add_node", name, E->get(), script->get_node(name, E->get()), script->get_node_pos(name, E->get()));
  2337. }
  2338. List<VisualScript::SequenceConnection> seq_connections;
  2339. script->get_sequence_connection_list(name, &seq_connections);
  2340. for (List<VisualScript::SequenceConnection>::Element *E = seq_connections.front(); E; E = E->next()) {
  2341. undo_redo->add_undo_method(script.ptr(), "sequence_connect", name, E->get().from_node, E->get().from_output, E->get().to_node);
  2342. }
  2343. List<VisualScript::DataConnection> data_connections;
  2344. script->get_data_connection_list(name, &data_connections);
  2345. for (List<VisualScript::DataConnection>::Element *E = data_connections.front(); E; E = E->next()) {
  2346. undo_redo->add_undo_method(script.ptr(), "data_connect", name, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port);
  2347. }
  2348. /*
  2349. for(int i=0;i<script->function_get_argument_count(name);i++) {
  2350. undo_redo->add_undo_method(script.ptr(),"function_add_argument",name,script->function_get_argument_name(name,i),script->function_get_argument_type(name,i));
  2351. }
  2352. */
  2353. undo_redo->add_do_method(this, "_update_members");
  2354. undo_redo->add_undo_method(this, "_update_members");
  2355. undo_redo->add_do_method(this, "_update_graph");
  2356. undo_redo->add_undo_method(this, "_update_graph");
  2357. undo_redo->commit_action();
  2358. }
  2359. } break;
  2360. case MEMBER_VARIABLE: {
  2361. String name = member_name;
  2362. if (p_option == MEMBER_REMOVE) {
  2363. undo_redo->create_action(TTR("Remove Variable"));
  2364. undo_redo->add_do_method(script.ptr(), "remove_variable", name);
  2365. undo_redo->add_undo_method(script.ptr(), "add_variable", name, script->get_variable_default_value(name));
  2366. undo_redo->add_undo_method(script.ptr(), "set_variable_info", name, script->call("get_variable_info", name)); //return as dict
  2367. undo_redo->add_do_method(this, "_update_members");
  2368. undo_redo->add_undo_method(this, "_update_members");
  2369. undo_redo->commit_action();
  2370. } else if (p_option == MEMBER_EDIT) {
  2371. variable_editor->edit(name);
  2372. edit_variable_dialog->set_title(TTR("Editing Variable:") + " " + name);
  2373. edit_variable_dialog->popup_centered_minsize(Size2(400, 200) * EDSCALE);
  2374. }
  2375. } break;
  2376. case MEMBER_SIGNAL: {
  2377. String name = member_name;
  2378. if (p_option == MEMBER_REMOVE) {
  2379. undo_redo->create_action(TTR("Remove Signal"));
  2380. undo_redo->add_do_method(script.ptr(), "remove_custom_signal", name);
  2381. undo_redo->add_undo_method(script.ptr(), "add_custom_signal", name);
  2382. for (int i = 0; i < script->custom_signal_get_argument_count(name); i++) {
  2383. undo_redo->add_undo_method(script.ptr(), "custom_signal_add_argument", name, script->custom_signal_get_argument_name(name, i), script->custom_signal_get_argument_type(name, i));
  2384. }
  2385. undo_redo->add_do_method(this, "_update_members");
  2386. undo_redo->add_undo_method(this, "_update_members");
  2387. undo_redo->commit_action();
  2388. } else if (p_option == MEMBER_EDIT) {
  2389. signal_editor->edit(name);
  2390. edit_signal_dialog->set_title(TTR("Editing Signal:") + " " + name);
  2391. edit_signal_dialog->popup_centered_minsize(Size2(400, 300) * EDSCALE);
  2392. }
  2393. } break;
  2394. }
  2395. }
  2396. void VisualScriptEditor::_bind_methods() {
  2397. ClassDB::bind_method("_member_button", &VisualScriptEditor::_member_button);
  2398. ClassDB::bind_method("_member_edited", &VisualScriptEditor::_member_edited);
  2399. ClassDB::bind_method("_member_selected", &VisualScriptEditor::_member_selected);
  2400. ClassDB::bind_method("_update_members", &VisualScriptEditor::_update_members);
  2401. ClassDB::bind_method("_change_base_type", &VisualScriptEditor::_change_base_type);
  2402. ClassDB::bind_method("_change_base_type_callback", &VisualScriptEditor::_change_base_type_callback);
  2403. ClassDB::bind_method("_node_selected", &VisualScriptEditor::_node_selected);
  2404. ClassDB::bind_method("_node_moved", &VisualScriptEditor::_node_moved);
  2405. ClassDB::bind_method("_move_node", &VisualScriptEditor::_move_node);
  2406. ClassDB::bind_method("_begin_node_move", &VisualScriptEditor::_begin_node_move);
  2407. ClassDB::bind_method("_end_node_move", &VisualScriptEditor::_end_node_move);
  2408. ClassDB::bind_method("_remove_node", &VisualScriptEditor::_remove_node);
  2409. ClassDB::bind_method("_update_graph", &VisualScriptEditor::_update_graph, DEFVAL(-1));
  2410. ClassDB::bind_method("_node_ports_changed", &VisualScriptEditor::_node_ports_changed);
  2411. ClassDB::bind_method("_available_node_doubleclicked", &VisualScriptEditor::_available_node_doubleclicked);
  2412. ClassDB::bind_method("_default_value_edited", &VisualScriptEditor::_default_value_edited);
  2413. ClassDB::bind_method("_default_value_changed", &VisualScriptEditor::_default_value_changed);
  2414. ClassDB::bind_method("_menu_option", &VisualScriptEditor::_menu_option);
  2415. ClassDB::bind_method("_graph_ofs_changed", &VisualScriptEditor::_graph_ofs_changed);
  2416. ClassDB::bind_method("_center_on_node", &VisualScriptEditor::_center_on_node);
  2417. ClassDB::bind_method("_comment_node_resized", &VisualScriptEditor::_comment_node_resized);
  2418. ClassDB::bind_method("_button_resource_previewed", &VisualScriptEditor::_button_resource_previewed);
  2419. ClassDB::bind_method("_port_action_menu", &VisualScriptEditor::_port_action_menu);
  2420. ClassDB::bind_method("_selected_connect_node_method_or_setget", &VisualScriptEditor::_selected_connect_node_method_or_setget);
  2421. ClassDB::bind_method("_selected_new_virtual_method", &VisualScriptEditor::_selected_new_virtual_method);
  2422. ClassDB::bind_method("_cancel_connect_node_method_or_setget", &VisualScriptEditor::_cancel_connect_node_method_or_setget);
  2423. ClassDB::bind_method("_expression_text_changed", &VisualScriptEditor::_expression_text_changed);
  2424. ClassDB::bind_method("get_drag_data_fw", &VisualScriptEditor::get_drag_data_fw);
  2425. ClassDB::bind_method("can_drop_data_fw", &VisualScriptEditor::can_drop_data_fw);
  2426. ClassDB::bind_method("drop_data_fw", &VisualScriptEditor::drop_data_fw);
  2427. ClassDB::bind_method("_input", &VisualScriptEditor::_input);
  2428. ClassDB::bind_method("_on_nodes_delete", &VisualScriptEditor::_on_nodes_delete);
  2429. ClassDB::bind_method("_on_nodes_duplicate", &VisualScriptEditor::_on_nodes_duplicate);
  2430. ClassDB::bind_method("_hide_timer", &VisualScriptEditor::_hide_timer);
  2431. ClassDB::bind_method("_graph_connected", &VisualScriptEditor::_graph_connected);
  2432. ClassDB::bind_method("_graph_disconnected", &VisualScriptEditor::_graph_disconnected);
  2433. ClassDB::bind_method("_graph_connect_to_empty", &VisualScriptEditor::_graph_connect_to_empty);
  2434. ClassDB::bind_method("_update_graph_connections", &VisualScriptEditor::_update_graph_connections);
  2435. ClassDB::bind_method("_node_filter_changed", &VisualScriptEditor::_node_filter_changed);
  2436. ClassDB::bind_method("_selected_method", &VisualScriptEditor::_selected_method);
  2437. ClassDB::bind_method("_draw_color_over_button", &VisualScriptEditor::_draw_color_over_button);
  2438. ClassDB::bind_method("_member_rmb_selected", &VisualScriptEditor::_member_rmb_selected);
  2439. ClassDB::bind_method("_member_option", &VisualScriptEditor::_member_option);
  2440. }
  2441. VisualScriptEditor::VisualScriptEditor() {
  2442. if (!clipboard) {
  2443. clipboard = memnew(Clipboard);
  2444. }
  2445. updating_graph = false;
  2446. edit_menu = memnew(MenuButton);
  2447. edit_menu->set_text(TTR("Edit"));
  2448. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("visual_script_editor/delete_selected"), EDIT_DELETE_NODES);
  2449. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("visual_script_editor/toggle_breakpoint"), EDIT_TOGGLE_BREAKPOINT);
  2450. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("visual_script_editor/find_node_type"), EDIT_FIND_NODE_TYPE);
  2451. edit_menu->get_popup()->add_separator();
  2452. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("visual_script_editor/copy_nodes"), EDIT_COPY_NODES);
  2453. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("visual_script_editor/cut_nodes"), EDIT_CUT_NODES);
  2454. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("visual_script_editor/paste_nodes"), EDIT_PASTE_NODES);
  2455. edit_menu->get_popup()->connect("id_pressed", this, "_menu_option");
  2456. left_vsplit = memnew(VSplitContainer);
  2457. ScriptEditor::get_singleton()->get_left_list_split()->call_deferred("add_child", left_vsplit); //add but wait until done settig up this
  2458. left_vsplit->set_v_size_flags(SIZE_EXPAND_FILL);
  2459. left_vsplit->set_stretch_ratio(2);
  2460. left_vsplit->hide();
  2461. VBoxContainer *left_vb = memnew(VBoxContainer);
  2462. left_vsplit->add_child(left_vb);
  2463. left_vb->set_v_size_flags(SIZE_EXPAND_FILL);
  2464. //left_vb->set_custom_minimum_size(Size2(230, 1) * EDSCALE);
  2465. base_type_select = memnew(Button);
  2466. left_vb->add_margin_child(TTR("Base Type:"), base_type_select);
  2467. base_type_select->connect("pressed", this, "_change_base_type");
  2468. members = memnew(Tree);
  2469. left_vb->add_margin_child(TTR("Members:"), members, true);
  2470. members->set_hide_root(true);
  2471. members->connect("button_pressed", this, "_member_button");
  2472. members->connect("item_edited", this, "_member_edited");
  2473. members->connect("cell_selected", this, "_member_selected", varray(), CONNECT_DEFERRED);
  2474. members->set_allow_reselect(true);
  2475. members->set_hide_folding(true);
  2476. members->set_drag_forwarding(this);
  2477. VBoxContainer *left_vb2 = memnew(VBoxContainer);
  2478. left_vsplit->add_child(left_vb2);
  2479. left_vb2->set_v_size_flags(SIZE_EXPAND_FILL);
  2480. VBoxContainer *vbc_nodes = memnew(VBoxContainer);
  2481. HBoxContainer *hbc_nodes = memnew(HBoxContainer);
  2482. node_filter = memnew(LineEdit);
  2483. node_filter->connect("text_changed", this, "_node_filter_changed");
  2484. hbc_nodes->add_child(node_filter);
  2485. node_filter->set_h_size_flags(SIZE_EXPAND_FILL);
  2486. vbc_nodes->add_child(hbc_nodes);
  2487. nodes = memnew(Tree);
  2488. vbc_nodes->add_child(nodes);
  2489. nodes->set_v_size_flags(SIZE_EXPAND_FILL);
  2490. left_vb2->add_margin_child(TTR("Available Nodes:"), vbc_nodes, true);
  2491. nodes->set_hide_root(true);
  2492. nodes->connect("item_activated", this, "_available_node_doubleclicked");
  2493. nodes->set_drag_forwarding(this);
  2494. graph = memnew(GraphEdit);
  2495. add_child(graph);
  2496. graph->set_area_as_parent_rect();
  2497. graph->set_h_size_flags(SIZE_EXPAND_FILL);
  2498. graph->connect("node_selected", this, "_node_selected");
  2499. graph->connect("_begin_node_move", this, "_begin_node_move");
  2500. graph->connect("_end_node_move", this, "_end_node_move");
  2501. graph->connect("delete_nodes_request", this, "_on_nodes_delete");
  2502. graph->connect("duplicate_nodes_request", this, "_on_nodes_duplicate");
  2503. graph->set_drag_forwarding(this);
  2504. graph->hide();
  2505. graph->connect("scroll_offset_changed", this, "_graph_ofs_changed");
  2506. select_func_text = memnew(Label);
  2507. select_func_text->set_text(TTR("Select or create a function to edit graph"));
  2508. select_func_text->set_align(Label::ALIGN_CENTER);
  2509. select_func_text->set_valign(Label::VALIGN_CENTER);
  2510. select_func_text->set_h_size_flags(SIZE_EXPAND_FILL);
  2511. add_child(select_func_text);
  2512. hint_text = memnew(Label);
  2513. hint_text->set_anchor_and_margin(MARGIN_TOP, ANCHOR_END, -100);
  2514. hint_text->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, 0);
  2515. hint_text->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, 0);
  2516. hint_text->set_align(Label::ALIGN_CENTER);
  2517. hint_text->set_valign(Label::VALIGN_CENTER);
  2518. graph->add_child(hint_text);
  2519. hint_text_timer = memnew(Timer);
  2520. hint_text_timer->set_wait_time(4);
  2521. hint_text_timer->connect("timeout", this, "_hide_timer");
  2522. add_child(hint_text_timer);
  2523. //allowed casts (connections)
  2524. for (int i = 0; i < Variant::VARIANT_MAX; i++) {
  2525. graph->add_valid_connection_type(Variant::NIL, i);
  2526. graph->add_valid_connection_type(i, Variant::NIL);
  2527. for (int j = 0; j < Variant::VARIANT_MAX; j++) {
  2528. if (Variant::can_convert(Variant::Type(i), Variant::Type(j))) {
  2529. graph->add_valid_connection_type(i, j);
  2530. }
  2531. }
  2532. graph->add_valid_right_disconnect_type(i);
  2533. }
  2534. graph->add_valid_left_disconnect_type(TYPE_SEQUENCE);
  2535. graph->connect("connection_request", this, "_graph_connected");
  2536. graph->connect("disconnection_request", this, "_graph_disconnected");
  2537. graph->connect("connection_to_empty", this, "_graph_connect_to_empty");
  2538. edit_signal_dialog = memnew(AcceptDialog);
  2539. edit_signal_dialog->get_ok()->set_text(TTR("Close"));
  2540. add_child(edit_signal_dialog);
  2541. edit_signal_dialog->set_title(TTR("Edit Signal Arguments:"));
  2542. signal_editor = memnew(VisualScriptEditorSignalEdit);
  2543. edit_signal_edit = memnew(PropertyEditor);
  2544. edit_signal_edit->hide_top_label();
  2545. edit_signal_dialog->add_child(edit_signal_edit);
  2546. edit_signal_edit->edit(signal_editor);
  2547. edit_variable_dialog = memnew(AcceptDialog);
  2548. edit_variable_dialog->get_ok()->set_text(TTR("Close"));
  2549. add_child(edit_variable_dialog);
  2550. edit_variable_dialog->set_title(TTR("Edit Variable:"));
  2551. variable_editor = memnew(VisualScriptEditorVariableEdit);
  2552. edit_variable_edit = memnew(PropertyEditor);
  2553. edit_variable_edit->hide_top_label();
  2554. edit_variable_dialog->add_child(edit_variable_edit);
  2555. edit_variable_edit->edit(variable_editor);
  2556. select_base_type = memnew(CreateDialog);
  2557. select_base_type->set_base_type("Object"); //anything goes
  2558. select_base_type->connect("create", this, "_change_base_type_callback");
  2559. select_base_type->get_ok()->set_text(TTR("Change"));
  2560. add_child(select_base_type);
  2561. undo_redo = EditorNode::get_singleton()->get_undo_redo();
  2562. updating_members = false;
  2563. set_process_input(true); //for revert on drag
  2564. set_process_unhandled_input(true); //for revert on drag
  2565. default_value_edit = memnew(CustomPropertyEditor);
  2566. add_child(default_value_edit);
  2567. default_value_edit->connect("variant_changed", this, "_default_value_changed");
  2568. method_select = memnew(PropertySelector);
  2569. add_child(method_select);
  2570. method_select->connect("selected", this, "_selected_method");
  2571. error_line = -1;
  2572. new_connect_node_select = memnew(PropertySelector);
  2573. add_child(new_connect_node_select);
  2574. new_connect_node_select->connect("selected", this, "_selected_connect_node_method_or_setget");
  2575. new_connect_node_select->get_cancel()->connect("pressed", this, "_cancel_connect_node_method_or_setget");
  2576. new_virtual_method_select = memnew(PropertySelector);
  2577. add_child(new_virtual_method_select);
  2578. new_virtual_method_select->connect("selected", this, "_selected_new_virtual_method");
  2579. new_virtual_method_select->get_cancel()->connect("pressed", this, "_selected_new_virtual_method");
  2580. port_action_popup = memnew(PopupMenu);
  2581. add_child(port_action_popup);
  2582. port_action_popup->connect("id_pressed", this, "_port_action_menu");
  2583. member_popup = memnew(PopupMenu);
  2584. add_child(member_popup);
  2585. members->connect("item_rmb_selected", this, "_member_rmb_selected");
  2586. members->set_allow_rmb_select(true);
  2587. member_popup->connect("id_pressed", this, "_member_option");
  2588. }
  2589. VisualScriptEditor::~VisualScriptEditor() {
  2590. undo_redo->clear_history(); //avoid crashes
  2591. memdelete(signal_editor);
  2592. memdelete(variable_editor);
  2593. }
  2594. static ScriptEditorBase *create_editor(const Ref<Script> &p_script) {
  2595. if (Object::cast_to<VisualScript>(*p_script)) {
  2596. return memnew(VisualScriptEditor);
  2597. }
  2598. return NULL;
  2599. }
  2600. VisualScriptEditor::Clipboard *VisualScriptEditor::clipboard = NULL;
  2601. void VisualScriptEditor::free_clipboard() {
  2602. if (clipboard)
  2603. memdelete(clipboard);
  2604. }
  2605. static void register_editor_callback() {
  2606. ScriptEditor::register_create_script_editor_function(create_editor);
  2607. ED_SHORTCUT("visual_script_editor/delete_selected", TTR("Delete Selected"));
  2608. ED_SHORTCUT("visual_script_editor/toggle_breakpoint", TTR("Toggle Breakpoint"), KEY_F9);
  2609. ED_SHORTCUT("visual_script_editor/find_node_type", TTR("Find Node Type"), KEY_MASK_CMD + KEY_F);
  2610. ED_SHORTCUT("visual_script_editor/copy_nodes", TTR("Copy Nodes"), KEY_MASK_CMD + KEY_C);
  2611. ED_SHORTCUT("visual_script_editor/cut_nodes", TTR("Cut Nodes"), KEY_MASK_CMD + KEY_X);
  2612. ED_SHORTCUT("visual_script_editor/paste_nodes", TTR("Paste Nodes"), KEY_MASK_CMD + KEY_V);
  2613. }
  2614. void VisualScriptEditor::register_editor() {
  2615. //too early to register stuff here, request a callback
  2616. EditorNode::add_plugin_init_callback(register_editor_callback);
  2617. }
  2618. #endif