editor_node.cpp 114 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226
  1. /*************************************************************************/
  2. /* editor_node.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #include "version.h"
  30. #include "editor_node.h"
  31. #include "print_string.h"
  32. #include "editor_icons.h"
  33. #include "editor_fonts.h"
  34. #include "editor_help.h"
  35. #include "scene/io/scene_saver.h"
  36. #include "scene/io/scene_loader.h"
  37. #include "core/io/resource_saver.h"
  38. #include "core/io/resource_loader.h"
  39. #include "servers/physics_2d_server.h"
  40. #include "scene/resources/packed_scene.h"
  41. #include "editor_settings.h"
  42. #include "io_plugins/editor_import_collada.h"
  43. #include "io_plugins/editor_scene_importer_fbxconv.h"
  44. #include "globals.h"
  45. #include <stdio.h>
  46. #include "object_type_db.h"
  47. #include "os/keyboard.h"
  48. #include "os/os.h"
  49. #include "os/file_access.h"
  50. #include "message_queue.h"
  51. #include "path_remap.h"
  52. #include "translation.h"
  53. #include "pvrtc_compress.h"
  54. #include "editor_file_system.h"
  55. #include "register_exporters.h"
  56. #include "bind/core_bind.h"
  57. #include "io/zip_io.h"
  58. // plugins
  59. #include "plugins/sprite_frames_editor_plugin.h"
  60. #include "plugins/canvas_item_editor_plugin.h"
  61. #include "plugins/spatial_editor_plugin.h"
  62. #include "plugins/sample_editor_plugin.h"
  63. #include "plugins/sample_library_editor_plugin.h"
  64. #include "plugins/sample_player_editor_plugin.h"
  65. #include "plugins/camera_editor_plugin.h"
  66. #include "plugins/style_box_editor_plugin.h"
  67. #include "plugins/resource_preloader_editor_plugin.h"
  68. #include "plugins/item_list_editor_plugin.h"
  69. #include "plugins/stream_editor_plugin.h"
  70. #include "plugins/multimesh_editor_plugin.h"
  71. #include "plugins/theme_editor_plugin.h"
  72. #include "plugins/tile_map_editor_plugin.h"
  73. #include "plugins/cube_grid_theme_editor_plugin.h"
  74. #include "plugins/shader_editor_plugin.h"
  75. #include "plugins/path_editor_plugin.h"
  76. #include "plugins/rich_text_editor_plugin.h"
  77. #include "plugins/collision_polygon_editor_plugin.h"
  78. #include "plugins/script_editor_plugin.h"
  79. #include "plugins/path_2d_editor_plugin.h"
  80. #include "plugins/particles_editor_plugin.h"
  81. #include "plugins/particles_2d_editor_plugin.h"
  82. #include "plugins/animation_tree_editor_plugin.h"
  83. #include "plugins/tile_set_editor_plugin.h"
  84. #include "plugins/animation_player_editor_plugin.h"
  85. #include "plugins/baked_light_editor_plugin.h"
  86. #include "plugins/polygon_2d_editor_plugin.h"
  87. // end
  88. #include "tools/editor/io_plugins/editor_texture_import_plugin.h"
  89. #include "tools/editor/io_plugins/editor_scene_import_plugin.h"
  90. #include "tools/editor/io_plugins/editor_font_import_plugin.h"
  91. #include "tools/editor/io_plugins/editor_sample_import_plugin.h"
  92. #include "tools/editor/io_plugins/editor_translation_import_plugin.h"
  93. #include "tools/editor/io_plugins/editor_mesh_import_plugin.h"
  94. EditorNode *EditorNode::singleton=NULL;
  95. void EditorNode::_update_title() {
  96. String appname = Globals::get_singleton()->get("application/name");
  97. String title = appname.empty()?String(VERSION_FULL_NAME):String(_MKSTR(VERSION_NAME) + String(" - ") + appname);
  98. String edited = edited_scene?edited_scene->get_filename():String();
  99. if (!edited.empty())
  100. title+=" - " + String(edited.get_file());
  101. if (unsaved_cache)
  102. title+=" (*)";
  103. OS::get_singleton()->set_window_title(title);
  104. }
  105. void EditorNode::_unhandled_input(const InputEvent& p_event) {
  106. if (p_event.type==InputEvent::KEY && p_event.key.pressed && !p_event.key.echo) {
  107. switch(p_event.key.scancode) {
  108. case KEY_F1:
  109. if (!p_event.key.mod.shift && !p_event.key.mod.command)
  110. _editor_select(3);
  111. break;
  112. case KEY_F2: _editor_select(0); break;
  113. case KEY_F3: _editor_select(1); break;
  114. case KEY_F4: _editor_select(2); break;
  115. case KEY_F5: _menu_option_confirm((p_event.key.mod.control&&p_event.key.mod.shift)?RUN_PLAY_CUSTOM_SCENE:RUN_PLAY,true); break;
  116. case KEY_F6: _menu_option_confirm(RUN_PLAY_SCENE,true); break;
  117. case KEY_F7: _menu_option_confirm(RUN_PAUSE,true); break;
  118. case KEY_F8: _menu_option_confirm(RUN_STOP,true); break;
  119. }
  120. }
  121. }
  122. void EditorNode::_notification(int p_what) {
  123. if (p_what==NOTIFICATION_EXIT_SCENE) {
  124. editor_data.save_editor_external_data();
  125. log->deinit(); // do not get messages anymore
  126. }
  127. if (p_what==NOTIFICATION_PROCESS) {
  128. //force the whole tree viewport
  129. #if 0
  130. {
  131. Rect2 grect = scene_root_base->get_global_rect();
  132. Rect2 grectsrp = scene_root_parent->get_global_rect();
  133. if (grect!=grectsrp) {
  134. scene_root_parent->set_pos(grect.pos);
  135. scene_root_parent->set_size(grect.size);
  136. }
  137. }
  138. #endif
  139. if (opening_prev && confirmation->is_hidden())
  140. opening_prev=false;
  141. if (unsaved_cache != (saved_version!=editor_data.get_undo_redo().get_version())) {
  142. unsaved_cache = (saved_version!=editor_data.get_undo_redo().get_version());
  143. _update_title();
  144. }
  145. //get_root_node()->set_rect(viewport->get_global_rect());
  146. //update the circle
  147. uint64_t frame = OS::get_singleton()->get_frames_drawn();
  148. uint32_t tick = OS::get_singleton()->get_ticks_msec();
  149. if (frame!=circle_step_frame && (tick-circle_step_msec)>(1000/8)) {
  150. circle_step++;
  151. if (circle_step>=8)
  152. circle_step=0;
  153. circle_step_msec=tick;
  154. circle_step_frame=frame+1;
  155. update_menu->set_icon(gui_base->get_icon("Progress"+itos(circle_step+1),"EditorIcons"));
  156. }
  157. scene_root->set_size_override(true,Size2(Globals::get_singleton()->get("display/width"),Globals::get_singleton()->get("display/height")));
  158. editor_selection->update();
  159. {
  160. uint32_t p32 = AudioServer::get_singleton()->read_output_peak()>>8;
  161. float peak = p32==0? -80 : Math::linear2db(p32 / 65535.0);
  162. if (peak<-80)
  163. peak=-80;
  164. float vu = audio_vu->get_val();
  165. if (peak > vu) {
  166. audio_vu->set_val(peak);
  167. } else {
  168. float new_vu = vu - get_process_delta_time()*70.0;
  169. if (new_vu<-80)
  170. new_vu=-80;
  171. if (new_vu !=-80 && vu !=-80)
  172. audio_vu->set_val(new_vu);
  173. }
  174. }
  175. }
  176. if (p_what==NOTIFICATION_ENTER_SCENE) {
  177. //MessageQueue::get_singleton()->push_call(this,"_get_scene_metadata");
  178. get_scene()->set_editor_hint(true);
  179. get_scene()->get_root()->set_as_audio_listener(false);
  180. get_scene()->get_root()->set_as_audio_listener_2d(false);
  181. get_scene()->set_auto_accept_quit(false);
  182. //VisualServer::get_singleton()->viewport_set_hide_canvas(editor->get_scene_root()->get_viewport(),false);
  183. //import_monitor->scan_changes();
  184. }
  185. if (p_what==NOTIFICATION_READY) {
  186. VisualServer::get_singleton()->viewport_set_hide_scenario(get_scene_root()->get_viewport(),true);
  187. VisualServer::get_singleton()->viewport_set_hide_canvas(get_scene_root()->get_viewport(),true);
  188. _editor_select(1);
  189. if (defer_load_scene!="") {
  190. #ifdef OLD_SCENE_FORMAT_ENABLED
  191. if (convert_old) {
  192. get_scene()->quit();
  193. Node *scn = SceneLoader::load(defer_load_scene,true);
  194. ERR_EXPLAIN("Couldn't load scene: "+defer_load_scene);
  195. ERR_FAIL_COND(!scn);
  196. Ref<PackedScene> sdata = memnew( PackedScene );
  197. Error err = sdata->pack(scn);
  198. ERR_EXPLAIN("Couldn't repack scene: "+defer_load_scene);
  199. ERR_FAIL_COND(err!=OK);
  200. err = ResourceSaver::save(defer_load_scene,sdata);
  201. ERR_EXPLAIN("Couldn't resave scene: "+defer_load_scene);
  202. ERR_FAIL_COND(err!=OK);
  203. return;
  204. }
  205. #endif
  206. load_scene(defer_load_scene);
  207. defer_load_scene="";
  208. }
  209. if (defer_translatable!="") {
  210. Error ok = save_translatable_strings(defer_translatable);
  211. if (ok!=OK)
  212. OS::get_singleton()->set_exit_code(255);
  213. defer_translatable="";
  214. get_scene()->quit();
  215. }
  216. /*
  217. if (defer_optimize!="") {
  218. Error ok = save_optimized_copy(defer_optimize,defer_optimize_preset);
  219. defer_optimize_preset="";
  220. if (ok!=OK)
  221. OS::get_singleton()->set_exit_code(255);
  222. get_scene()->quit();
  223. }
  224. */
  225. if (export_defer.platform!="") {
  226. project_export_settings->export_platform(export_defer.platform,export_defer.path,export_defer.debug,export_defer.password,true);
  227. export_defer.platform="";
  228. }
  229. }
  230. if (p_what == MainLoop::NOTIFICATION_WM_FOCUS_IN) {
  231. /*
  232. List<Ref<Resource> > cached;
  233. ResourceCache::get_cached_resources(&cached);
  234. bool changes=false;
  235. for(List<Ref<Resource> >::Element *E=cached.front();E;E=E->next()) {
  236. if (!E->get()->can_reload_from_file())
  237. continue;
  238. if (E->get()->get_path().find("::")!=-1)
  239. continue;
  240. uint64_t mt = FileAccess::get_modified_time(E->get()->get_path());
  241. if (mt!=E->get()->get_last_modified_time()) {
  242. changes=true;
  243. break;
  244. }
  245. }
  246. sources_button->get_popup()->set_item_disabled(sources_button->get_popup()->get_item_index(DEPENDENCY_UPDATE_LOCAL),!changes);
  247. if (changes && sources_button->get_popup()->is_item_disabled(sources_button->get_popup()->get_item_index(DEPENDENCY_UPDATE_IMPORTED))) {
  248. sources_button->set_icon(gui_base->get_icon("DependencyLocalChanged","EditorIcons"));
  249. }
  250. */
  251. if (bool(EDITOR_DEF("resources/auto_reload_modified_images",true))) {
  252. _menu_option_confirm(DEPENDENCY_LOAD_CHANGED_IMAGES,true);
  253. }
  254. EditorFileSystem::get_singleton()->scan_sources();
  255. }
  256. if (p_what == MainLoop::NOTIFICATION_WM_QUIT_REQUEST) {
  257. _menu_option_confirm(FILE_QUIT, false);
  258. };
  259. }
  260. void EditorNode::_fs_changed() {
  261. for(Set<FileDialog*>::Element *E=file_dialogs.front();E;E=E->next()) {
  262. E->get()->invalidate();
  263. }
  264. }
  265. void EditorNode::_sources_changed(bool p_exist) {
  266. if (p_exist) {
  267. sources_button->set_icon(gui_base->get_icon("DependencyChanged","EditorIcons"));
  268. sources_button->set_disabled(false);
  269. } else {
  270. sources_button->set_icon(gui_base->get_icon("DependencyOk","EditorIcons"));
  271. sources_button->set_disabled(true);
  272. }
  273. }
  274. void EditorNode::_vp_resized() {
  275. }
  276. void EditorNode::_node_renamed() {
  277. if (property_editor)
  278. property_editor->update_tree();
  279. }
  280. Error EditorNode::load_resource(const String& p_scene) {
  281. RES res = ResourceLoader::load(p_scene);
  282. ERR_FAIL_COND_V(!res.is_valid(),ERR_CANT_OPEN);
  283. edit_resource(res);
  284. return OK;
  285. }
  286. void EditorNode::edit_resource(const Ref<Resource>& p_resource) {
  287. _resource_selected(p_resource,"");
  288. }
  289. void EditorNode::edit_node(Node *p_node) {
  290. push_item(p_node);
  291. }
  292. void EditorNode::open_resource(const String& p_type) {
  293. file->set_mode(FileDialog::MODE_OPEN_FILE);
  294. List<String> extensions;
  295. ResourceLoader::get_recognized_extensions_for_type(p_type,&extensions);
  296. file->clear_filters();
  297. for(int i=0;i<extensions.size();i++) {
  298. file->add_filter("*."+extensions[i]+" ; "+extensions[i].to_upper());
  299. }
  300. //file->set_current_path(current_path);
  301. file->popup_centered_ratio();
  302. current_option=RESOURCE_LOAD;
  303. }
  304. void EditorNode::save_resource(const Ref<Resource>& p_resource) {
  305. ERR_FAIL_COND(p_resource.is_null() || p_resource->get_path()=="" || p_resource->get_path().find("::")!=-1);
  306. resources_dock->save_resource(p_resource->get_path(),p_resource);
  307. }
  308. void EditorNode::save_resource_as(const Ref<Resource>& p_resource) {
  309. resources_dock->save_resource_as(p_resource);
  310. }
  311. void EditorNode::_menu_option(int p_option) {
  312. _menu_option_confirm(p_option,false);
  313. }
  314. void EditorNode::_menu_confirm_current() {
  315. _menu_option_confirm(current_option,true);
  316. }
  317. void EditorNode::_dialog_display_file_error(String p_file,Error p_error) {
  318. if (p_error) {
  319. current_option=-1;
  320. //accept->"()->hide();
  321. accept->get_ok()->set_text("I see..");
  322. switch(p_error) {
  323. case ERR_FILE_CANT_WRITE: {
  324. accept->set_text("Can't open file for writing: "+p_file.extension());
  325. } break;
  326. case ERR_FILE_UNRECOGNIZED: {
  327. accept->set_text("File format requested unknown: "+p_file.extension());
  328. } break;
  329. default: {
  330. accept->set_text("Error Saving.");
  331. }break;
  332. }
  333. accept->popup_centered(Size2(300,70));;
  334. }
  335. }
  336. void EditorNode::_get_scene_metadata() {
  337. Node *scene = edited_scene;
  338. if (!scene)
  339. return;
  340. if (scene->has_meta("__editor_plugin_states__")) {
  341. Dictionary md = scene->get_meta("__editor_plugin_states__");
  342. editor_data.set_editor_states(md);
  343. }
  344. if (scene->has_meta("__editor_run_settings__")) {
  345. Dictionary md = scene->get_meta("__editor_run_settings__");
  346. if (md.has("run_mode"))
  347. run_settings_dialog->set_run_mode(md["run_mode"]);
  348. if (md.has("custom_args"))
  349. run_settings_dialog->set_custom_arguments(md["custom_args"]);
  350. }
  351. }
  352. void EditorNode::_set_scene_metadata() {
  353. Node *scene = edited_scene;
  354. if (!scene)
  355. return;
  356. { /* Editor States */
  357. Dictionary md = editor_data.get_editor_states();
  358. if (!md.empty()) {
  359. scene->set_meta("__editor_plugin_states__",md);
  360. }
  361. }
  362. { /* Run Settings */
  363. Dictionary md;
  364. md["run_mode"]=run_settings_dialog->get_run_mode();
  365. md["custom_args"]=run_settings_dialog->get_custom_arguments();
  366. scene->set_meta("__editor_run_settings__",md);
  367. }
  368. }
  369. static Error _fix_object_paths(Object* obj, Node* root, String save_path) {
  370. Globals* g = Globals::get_singleton();
  371. String import_dir = root->get_meta("__editor_import_file__");
  372. import_dir = import_dir.get_base_dir();
  373. import_dir = DirAccess::normalize_path(import_dir);
  374. if (import_dir[import_dir.length()-1] != '/') {
  375. import_dir = import_dir + "/";
  376. };
  377. String resource_dir = DirAccess::normalize_path(g->get_resource_path());
  378. if (resource_dir[resource_dir.length()-1] != '/') {
  379. resource_dir = resource_dir + "/";
  380. };
  381. List<PropertyInfo> list;
  382. obj->get_property_list(&list, false);
  383. List<PropertyInfo>::Element *E = list.front();
  384. while (E) {
  385. Variant v = obj->get(E->get().name);
  386. if (v.get_type() == Variant::OBJECT) {
  387. Ref<Resource> res = (RefPtr)v;
  388. if (res.is_null()) {
  389. E = E->next();
  390. continue;
  391. }
  392. if (res->get_path() != "") {
  393. String res_path = res->get_path();
  394. res_path = Globals::get_singleton()->globalize_path(res_path);
  395. res_path = DirAccess::normalize_path(res_path);
  396. if (res_path.find(resource_dir) != 0) {
  397. // path of resource is not inside engine's resource path
  398. String new_path;
  399. if (res_path.find(import_dir) == 0) {
  400. // path of resource is relative to path of import file
  401. new_path = save_path + "/" + res_path.substr(import_dir.length(), res_path.length() - import_dir.length());
  402. } else {
  403. // path of resource is not relative to import file
  404. new_path = save_path + "/" + res_path.get_file();
  405. };
  406. res->set_path(g->localize_path(new_path));
  407. DirAccess* d = DirAccess::create(DirAccess::ACCESS_RESOURCES);
  408. d->make_dir_recursive(new_path.get_base_dir());
  409. printf("copying from %ls to %ls\n", res_path.c_str(), new_path.c_str());
  410. Error err = d->copy(res_path, new_path);
  411. memdelete(d);
  412. ERR_FAIL_COND_V(err != OK, err);
  413. }
  414. } else {
  415. _fix_object_paths(res.operator->(), root, save_path);
  416. };
  417. };
  418. E = E->next();
  419. };
  420. return OK;
  421. };
  422. static Error _fix_imported_scene_paths(Node* node, Node* root, String save_path) {
  423. if (node == root || node->get_owner() == root) {
  424. Error e = _fix_object_paths(node, root, save_path);
  425. ERR_FAIL_COND_V(e != OK, e);
  426. };
  427. for (int i=0; i<node->get_child_count(); i++) {
  428. Error e = _fix_imported_scene_paths(node->get_child(i), root, save_path);
  429. ERR_FAIL_COND_V(e != OK, e);
  430. };
  431. return OK;
  432. };
  433. bool EditorNode::_find_and_save_edited_subresources(Object *obj,Set<RES>& processed,int32_t flags) {
  434. bool ret_changed=false;
  435. List<PropertyInfo> pi;
  436. obj->get_property_list(&pi);
  437. for (List<PropertyInfo>::Element *E=pi.front();E;E=E->next()) {
  438. if (!(E->get().usage&PROPERTY_USAGE_STORAGE))
  439. continue;
  440. switch(E->get().type) {
  441. case Variant::OBJECT: {
  442. RES res = obj->get(E->get().name);
  443. if (res.is_null() || processed.has(res))
  444. break;
  445. processed.insert(res);
  446. bool changed = res->is_edited();
  447. res->set_edited(false);
  448. bool subchanged = _find_and_save_edited_subresources(res.ptr(),processed,flags);
  449. if (res->get_path().is_resource_file()) {
  450. if (changed || subchanged) {
  451. //save
  452. print_line("Also saving modified external resource: "+res->get_path());
  453. Error err = ResourceSaver::save(res->get_path(),res,flags);
  454. }
  455. } else {
  456. ret_changed=true;
  457. }
  458. } break;
  459. case Variant::ARRAY: {
  460. /*Array varray=p_variant;
  461. int len=varray.size();
  462. for(int i=0;i<len;i++) {
  463. Variant v=varray.get(i);
  464. _find_resources(v);
  465. }*/
  466. } break;
  467. case Variant::DICTIONARY: {
  468. /*
  469. Dictionary d=p_variant;
  470. List<Variant> keys;
  471. d.get_key_list(&keys);
  472. for(List<Variant>::Element *E=keys.front();E;E=E->next()) {
  473. Variant v = d[E->get()];
  474. _find_resources(v);
  475. } */
  476. } break;
  477. default: {}
  478. }
  479. }
  480. return ret_changed;
  481. }
  482. void EditorNode::_save_edited_subresources(Node* scene,Set<RES>& processed,int32_t flags) {
  483. _find_and_save_edited_subresources(scene,processed,flags);
  484. for(int i=0;i<scene->get_child_count();i++) {
  485. Node *n = scene->get_child(i);
  486. if (n->get_owner()!=edited_scene)
  487. continue;
  488. _save_edited_subresources(n,processed,flags);
  489. }
  490. }
  491. void EditorNode::_save_scene(String p_file) {
  492. Node *scene = edited_scene;
  493. if (!scene) {
  494. current_option=-1;
  495. //accept->get_cancel()->hide();
  496. accept->get_ok()->set_text("I see..");
  497. accept->set_text("This operation can't be done without a tree root.");
  498. accept->popup_centered(Size2(300,70));;
  499. return;
  500. }
  501. editor_data.apply_changes_in_editors();
  502. if (editor_plugin_screen) {
  503. scene->set_meta("__editor_plugin_screen__",editor_plugin_screen->get_name());
  504. }
  505. _set_scene_metadata();
  506. Ref<PackedScene> sdata = memnew( PackedScene );
  507. Error err = sdata->pack(scene);
  508. if (err!=OK) {
  509. current_option=-1;
  510. //accept->get_cancel()->hide();
  511. accept->get_ok()->set_text("I see..");
  512. accept->set_text("Couldn't save scene. Likely dependencies (instances) couldn't be satisfied.");
  513. accept->popup_centered(Size2(300,70));;
  514. return;
  515. }
  516. sdata->set_import_metadata(scene_import_metadata);
  517. int flg=0;
  518. if (EditorSettings::get_singleton()->get("on_save/compress_binary_resources"))
  519. flg|=ResourceSaver::FLAG_COMPRESS;
  520. if (EditorSettings::get_singleton()->get("on_save/save_paths_as_relative"))
  521. flg|=ResourceSaver::FLAG_RELATIVE_PATHS;
  522. flg|=ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS;
  523. err = ResourceSaver::save(p_file,sdata,flg);
  524. Set<RES> processed;
  525. _save_edited_subresources(scene,processed,flg);
  526. editor_data.save_editor_external_data();
  527. if (err==OK) {
  528. scene->set_filename( Globals::get_singleton()->localize_path(p_file) );
  529. //EditorFileSystem::get_singleton()->update_file(p_file,sdata->get_type());
  530. saved_version=editor_data.get_undo_redo().get_version();
  531. _update_title();
  532. } else {
  533. _dialog_display_file_error(p_file,err);
  534. }
  535. };
  536. void EditorNode::_import_action(const String& p_action) {
  537. #if 0
  538. import_confirmation->hide();
  539. if (p_action=="re-import") {
  540. _import(_tmp_import_path);
  541. }
  542. if (p_action=="update") {
  543. Node *src = EditorImport::import_scene(_tmp_import_path);
  544. if (!src) {
  545. current_option=-1;
  546. //accept->get_cancel()->hide();
  547. accept->get_ok()->set_text("Ugh");
  548. accept->set_text("Error importing scene.");
  549. accept->popup_centered(Size2(300,70));;
  550. return;
  551. }
  552. //as soon as the scene is imported, version hashes must be generated for comparison against saved scene
  553. EditorImport::generate_version_hashes(src);
  554. Node *dst = SceneLoader::load(editor_data.get_imported_scene(Globals::get_singleton()->localize_path(_tmp_import_path)));
  555. if (!dst) {
  556. memdelete(src);
  557. //accept->get_cancel()->hide();
  558. accept->get_ok()->set_text("Ugh");
  559. accept->set_text("Error load scene to update.");
  560. accept->popup_centered(Size2(300,70));;
  561. return;
  562. }
  563. List<EditorImport::Conflict> conflicts;
  564. EditorImport::check_conflicts(src,dst,&conflicts);
  565. bool conflicted=false;
  566. for (List<EditorImport::Conflict>::Element *E=conflicts.front();E;E=E->next()) {
  567. if (E->get().status==EditorImport::Conflict::STATUS_CONFLICT) {
  568. conflicted=true;
  569. break;
  570. }
  571. }
  572. if (conflicted) {
  573. import_conflicts_dialog->popup(src,dst,conflicts);
  574. return;
  575. }
  576. _import_with_conflicts(src,dst,conflicts);
  577. //not conflicted, just reimport!
  578. }
  579. #endif
  580. }
  581. void EditorNode::_import(const String &p_file) {
  582. #if 0
  583. Node *new_scene = EditorImport::import_scene(p_file);
  584. if (!new_scene) {
  585. current_option=-1;
  586. //accept->get_cancel()->hide();
  587. accept->get_ok()->set_text("Ugh");
  588. accept->set_text("Error importing scene.");
  589. accept->popup_centered(Size2(300,70));;
  590. return;
  591. }
  592. //as soon as the scene is imported, version hashes must be generated for comparison against saved scene
  593. EditorImport::generate_version_hashes(new_scene);
  594. Node *old_scene = edited_scene;
  595. _hide_top_editors();
  596. set_edited_scene(NULL);
  597. editor_data.clear_editor_states();
  598. if (old_scene) {
  599. memdelete(old_scene);
  600. }
  601. set_edited_scene(new_scene);
  602. scene_tree_dock->set_selected(new_scene);
  603. //_get_scene_metadata();
  604. editor_data.get_undo_redo().clear_history();
  605. saved_version=editor_data.get_undo_redo().get_version();
  606. _update_title();
  607. #endif
  608. }
  609. void EditorNode::_dialog_action(String p_file) {
  610. switch(current_option) {
  611. case RESOURCE_LOAD: {
  612. RES res = ResourceLoader::load(p_file);
  613. if (res.is_null()) {
  614. current_option=-1;
  615. //accept->get_cancel()->hide();
  616. accept->get_ok()->set_text("ok :(");
  617. accept->set_text("Failed to load resource.");
  618. return;
  619. };
  620. push_item(res.operator->() );
  621. } break;
  622. case FILE_OPEN_SCENE: {
  623. load_scene(p_file);
  624. } break;
  625. #ifdef OLD_SCENE_FORMAT_ENABLED
  626. case FILE_OPEN_OLD_SCENE: {
  627. String lpath = Globals::get_singleton()->localize_path(p_file);
  628. if (!lpath.begins_with("res://")) {
  629. current_option=-1;
  630. //accept->get_cancel()->hide();
  631. accept->get_ok()->set_text("Ugh");
  632. accept->set_text("Error loading scene, it must be inside the project path. Use 'Import' to open the scene, then save it inside the project path.");
  633. accept->popup_centered(Size2(300,120));
  634. return ;
  635. }
  636. Node*new_scene=SceneLoader::load(lpath,true);
  637. if (!new_scene) {
  638. current_option=-1;
  639. //accept->get_cancel()->hide();
  640. accept->get_ok()->set_text("Ugh");
  641. accept->set_text("Error loading scene.");
  642. accept->popup_centered(Size2(300,70));;
  643. return ;
  644. }
  645. Node *old_scene = edited_scene;
  646. _hide_top_editors();
  647. set_edited_scene(NULL);
  648. editor_data.clear_editor_states();
  649. if (old_scene) {
  650. memdelete(old_scene);
  651. }
  652. set_edited_scene(new_scene);
  653. scene_tree_dock->set_selected(new_scene);
  654. _get_scene_metadata();
  655. editor_data.get_undo_redo().clear_history();
  656. saved_version=editor_data.get_undo_redo().get_version();
  657. _update_title();
  658. _add_to_recent_scenes(lpath);
  659. if (new_scene->has_meta("__editor_plugin_screen__")) {
  660. String editor = new_scene->get_meta("__editor_plugin_screen__");
  661. for(int i=0;i<editor_table.size();i++) {
  662. if (editor_table[i]->get_name()==editor) {
  663. _editor_select(i);
  664. break;
  665. }
  666. }
  667. }
  668. } break;
  669. #endif
  670. case FILE_SAVE_OPTIMIZED: {
  671. } break;
  672. case FILE_RUN_SCRIPT: {
  673. print_line("RUN: "+p_file);
  674. Ref<Script> scr = ResourceLoader::load(p_file,"Script",true);
  675. if (scr.is_null()) {
  676. add_io_error("Script Failed to Load:\n"+p_file);
  677. return;
  678. }
  679. if (!scr->is_tool()) {
  680. add_io_error("Script is not tool, will not be able to run:\n"+p_file);
  681. return;
  682. }
  683. Ref<EditorScript> es = memnew( EditorScript );
  684. es->set_script(scr.get_ref_ptr());
  685. es->set_editor(this);
  686. es->_run();
  687. get_undo_redo()->clear_history();
  688. } break;
  689. case FILE_DUMP_STRINGS: {
  690. save_translatable_strings(p_file);
  691. } break;
  692. case FILE_SAVE_SUBSCENE: {
  693. List<Node*> selection = editor_selection->get_selected_node_list();
  694. if (selection.size()!=1) {
  695. current_option=-1;
  696. //confirmation->get_cancel()->hide();
  697. accept->get_ok()->set_text("I see..");
  698. accept->set_text("This operation requieres a single selected node.");
  699. accept->popup_centered(Size2(300,70));;
  700. break;
  701. }
  702. Node *base = selection.front()->get();
  703. Map<Node*,Node*> reown;
  704. reown[get_edited_scene()]=base;
  705. Node *copy = base->duplicate_and_reown(reown);
  706. if (copy) {
  707. Ref<PackedScene> sdata = memnew( PackedScene );
  708. Error err = sdata->pack(copy);
  709. memdelete(copy);
  710. if (err!=OK) {
  711. current_option=-1;
  712. //accept->get_cancel()->hide();
  713. accept->get_ok()->set_text("I see..");
  714. accept->set_text("Couldn't save subscene. Likely dependencies (instances) couldn't be satisfied.");
  715. accept->popup_centered(Size2(300,70));;
  716. return;
  717. }
  718. int flg=0;
  719. if (EditorSettings::get_singleton()->get("on_save/compress_binary_resources"))
  720. flg|=ResourceSaver::FLAG_COMPRESS;
  721. if (EditorSettings::get_singleton()->get("on_save/save_paths_as_relative"))
  722. flg|=ResourceSaver::FLAG_RELATIVE_PATHS;
  723. err = ResourceSaver::save(p_file,sdata,flg);
  724. if (err!=OK) {
  725. current_option=-1;
  726. //confirmation->get_cancel()->hide();
  727. accept->get_ok()->set_text("I see..");
  728. accept->set_text("Error saving scene.");
  729. accept->popup_centered(Size2(300,70));;
  730. break;
  731. }
  732. //EditorFileSystem::get_singleton()->update_file(p_file,sdata->get_type());
  733. } else {
  734. current_option=-1;
  735. //confirmation->get_cancel()->hide();
  736. accept->get_ok()->set_text("I see..");
  737. accept->set_text("Error duplicating scene to save it.");
  738. accept->popup_centered(Size2(300,70));;
  739. break;
  740. }
  741. } break;
  742. case FILE_SAVE_SCENE:
  743. case FILE_SAVE_AS_SCENE: {
  744. if (file->get_mode()==FileDialog::MODE_SAVE_FILE) {
  745. _save_scene(p_file);
  746. }
  747. } break;
  748. case FILE_EXPORT_MESH_LIBRARY: {
  749. Ref<MeshLibrary> ml;
  750. if (file_export_lib_merge->is_pressed() && FileAccess::exists(p_file)) {
  751. ml=ResourceLoader::load(p_file,"MeshLibrary");
  752. if (ml.is_null()) {
  753. current_option=-1;
  754. //accept->get_cancel()->hide();
  755. accept->get_ok()->set_text("I see..");
  756. accept->set_text("Can't load MeshLibrary for merging!.");
  757. accept->popup_centered(Size2(300,70));;
  758. return;
  759. }
  760. }
  761. if (ml.is_null()) {
  762. ml = Ref<MeshLibrary>( memnew( MeshLibrary ));
  763. }
  764. MeshLibraryEditor::update_library_file(edited_scene,ml,true);
  765. Error err = ResourceSaver::save(p_file,ml);
  766. if (err) {
  767. accept->get_ok()->set_text("I see..");
  768. accept->set_text("Error saving MeshLibrary!.");
  769. accept->popup_centered(Size2(300,70));;
  770. return;
  771. }
  772. } break;
  773. case FILE_EXPORT_TILESET: {
  774. Ref<TileSet> ml;
  775. if (file_export_lib_merge->is_pressed() && FileAccess::exists(p_file)) {
  776. ml=ResourceLoader::load(p_file,"TileSet");
  777. if (ml.is_null()) {
  778. current_option=-1;
  779. //accept->get_cancel()->hide();
  780. accept->get_ok()->set_text("I see..");
  781. accept->set_text("Can't load TileSet for merging!.");
  782. accept->popup_centered(Size2(300,70));;
  783. return;
  784. }
  785. }
  786. if (ml.is_null()) {
  787. ml = Ref<TileSet>( memnew( TileSet ));
  788. }
  789. TileSetEditor::update_library_file(edited_scene,ml,true);
  790. Error err = ResourceSaver::save(p_file,ml);
  791. if (err) {
  792. accept->get_ok()->set_text("I see..");
  793. accept->set_text("Error saving TileSet!.");
  794. accept->popup_centered(Size2(300,70));;
  795. return;
  796. }
  797. } break;
  798. case SETTINGS_LOAD_EXPORT_TEMPLATES: {
  799. FileAccess *fa=NULL;
  800. zlib_filefunc_def io = zipio_create_io_from_file(&fa);
  801. unzFile pkg = unzOpen2(p_file.utf8().get_data(), &io);
  802. if (!pkg) {
  803. current_option=-1;
  804. //confirmation->get_cancel()->hide();
  805. accept->get_ok()->set_text("I see..");
  806. accept->set_text("Can't open export templates zip.");
  807. accept->popup_centered(Size2(300,70));;
  808. return;
  809. }
  810. int ret = unzGoToFirstFile(pkg);
  811. int fc=0; //coun them
  812. while(ret==UNZ_OK) {
  813. fc++;
  814. ret = unzGoToNextFile(pkg);
  815. }
  816. ret = unzGoToFirstFile(pkg);
  817. EditorProgress p("ltask","Loading Export Templates",fc);
  818. print_line("BEGIN IMPORT");
  819. fc=0;
  820. while(ret==UNZ_OK) {
  821. //get filename
  822. unz_file_info info;
  823. char fname[16384];
  824. ret = unzGetCurrentFileInfo(pkg,&info,fname,16384,NULL,0,NULL,0);
  825. String file=fname;
  826. Vector<uint8_t> data;
  827. data.resize(info.uncompressed_size);
  828. //read
  829. ret = unzOpenCurrentFile(pkg);
  830. ret = unzReadCurrentFile(pkg,data.ptr(),data.size());
  831. unzCloseCurrentFile(pkg);
  832. print_line(fname);
  833. //for(int i=0;i<512;i++) {
  834. // print_line(itos(data[i]));
  835. //}
  836. file=file.get_file();
  837. p.step("Importing: "+file,fc);
  838. print_line("IMPORT "+file);
  839. FileAccess *f = FileAccess::open(EditorSettings::get_singleton()->get_settings_path()+"/templates/"+file,FileAccess::WRITE);
  840. ERR_CONTINUE(!f);
  841. f->store_buffer(data.ptr(),data.size());
  842. memdelete(f);
  843. ret = unzGoToNextFile(pkg);
  844. fc++;
  845. }
  846. unzClose(pkg);
  847. } break;
  848. default: { //save scene?
  849. if (file->get_mode()==FileDialog::MODE_SAVE_FILE) {
  850. _save_scene(p_file);
  851. }
  852. } break;
  853. }
  854. }
  855. void EditorNode::push_item(Object *p_object,const String& p_property) {
  856. if (!p_object) {
  857. property_editor->edit(NULL);
  858. scene_tree_dock->set_selected(NULL);
  859. return;
  860. }
  861. uint32_t id = p_object->get_instance_ID();
  862. if (id!=editor_history.get_current()) {
  863. if (p_property=="")
  864. editor_history.add_object(id);
  865. else
  866. editor_history.add_object(id,p_property);
  867. }
  868. _edit_current();
  869. }
  870. void EditorNode::_property_editor_forward() {
  871. if (editor_history.next())
  872. _edit_current();
  873. }
  874. void EditorNode::_property_editor_back() {
  875. if (editor_history.previous())
  876. _edit_current();
  877. }
  878. void EditorNode::_imported(Node *p_node) {
  879. Node *scene = edited_scene;
  880. set_edited_scene(p_node);
  881. if (scene) {
  882. String path = scene->get_filename();
  883. p_node->set_filename(path);
  884. memdelete(scene);
  885. }
  886. }
  887. void EditorNode::_hide_top_editors() {
  888. if (editor_plugin_over)
  889. editor_plugin_over->make_visible(false);
  890. editor_plugin_over=NULL;
  891. }
  892. void EditorNode::_edit_current() {
  893. uint32_t current = editor_history.get_current();
  894. Object *current_obj = current>0 ? ObjectDB::get_instance(current) : NULL;
  895. this->current=current_obj;
  896. editor_path->update_path();
  897. if (!current_obj) {
  898. scene_tree_dock->set_selected(NULL);
  899. property_editor->edit( NULL );
  900. object_menu->set_disabled(true);
  901. return;
  902. }
  903. object_menu->set_disabled(true);
  904. if (current_obj->is_type("Resource")) {
  905. Resource *current_res = current_obj->cast_to<Resource>();
  906. ERR_FAIL_COND(!current_res);
  907. scene_tree_dock->set_selected(NULL);
  908. property_editor->edit( current_res );
  909. object_menu->set_disabled(false);
  910. resources_dock->add_resource(Ref<Resource>(current_res));
  911. top_pallete->set_current_tab(1);
  912. }
  913. if (current_obj->is_type("Node")) {
  914. Node * current_node = current_obj->cast_to<Node>();
  915. ERR_FAIL_COND(!current_node);
  916. ERR_FAIL_COND(!current_node->is_inside_scene());
  917. property_editor->edit( current_node );
  918. scene_tree_dock->set_selected(current_node);
  919. object_menu->get_popup()->clear();
  920. top_pallete->set_current_tab(0);
  921. }
  922. /* Take care of PLUGIN EDITOR */
  923. EditorPlugin *main_plugin = editor_data.get_editor(current_obj);
  924. if (main_plugin) {
  925. if (main_plugin!=editor_plugin_screen) {
  926. // update screen main_plugin
  927. if (editor_plugin_screen)
  928. editor_plugin_screen->make_visible(false);
  929. editor_plugin_screen=main_plugin;
  930. editor_plugin_screen->edit(current_obj);
  931. editor_plugin_screen->make_visible(true);
  932. for(int i=0;i<editor_table.size();i++) {
  933. if (editor_table[i]==main_plugin) {
  934. main_editor_tabs->set_current_tab(i);
  935. break;
  936. }
  937. }
  938. } else {
  939. editor_plugin_screen->edit(current_obj);
  940. }
  941. }
  942. EditorPlugin *sub_plugin = editor_data.get_subeditor(current_obj);
  943. if (sub_plugin) {
  944. if (editor_plugin_over)
  945. editor_plugin_over->make_visible(false);
  946. editor_plugin_over=sub_plugin;
  947. editor_plugin_over->edit(current_obj);
  948. editor_plugin_over->make_visible(true);
  949. } else if (editor_plugin_over) {
  950. editor_plugin_over->make_visible(false);
  951. editor_plugin_over=NULL;
  952. }
  953. /*
  954. if (!plugin || plugin->has_main_screen()) {
  955. // remove the OVER plugin if exists
  956. if (editor_plugin_over)
  957. editor_plugin_over->make_visible(false);
  958. editor_plugin_over=NULL;
  959. }
  960. */
  961. /* Take care of OBJECT MENU */
  962. object_menu->set_disabled(false);
  963. PopupMenu *p=object_menu->get_popup();
  964. p->clear();
  965. p->add_item("Copy Params",OBJECT_COPY_PARAMS);
  966. p->add_item("Set Params",OBJECT_PASTE_PARAMS);
  967. p->add_separator();
  968. p->add_icon_item(gui_base->get_icon("Help","EditorIcons"),"Class Reference",OBJECT_REQUEST_HELP);
  969. List<MethodInfo> methods;
  970. current_obj->get_method_list(&methods);
  971. if (!methods.empty()) {
  972. bool found=false;
  973. List<MethodInfo>::Element *I=methods.front();
  974. int i=0;
  975. while(I) {
  976. if (I->get().flags&METHOD_FLAG_EDITOR) {
  977. if (!found) {
  978. p->add_separator();
  979. found=true;
  980. }
  981. p->add_item(I->get().name.capitalize(),OBJECT_METHOD_BASE+i);
  982. }
  983. i++;
  984. I=I->next();
  985. }
  986. }
  987. //p->add_separator();
  988. //p->add_item("All Methods",OBJECT_CALL_METHOD);
  989. _update_keying();
  990. }
  991. void EditorNode::_resource_selected(const RES& p_res,const String& p_property) {
  992. if (p_res.is_null())
  993. return;
  994. RES r=p_res;
  995. push_item(r.operator->(),p_property);
  996. }
  997. void EditorNode::_run(bool p_current,const String& p_custom) {
  998. if (editor_run.get_status()==EditorRun::STATUS_PLAY) {
  999. play_button->set_pressed(!_playing_edited);
  1000. play_scene_button->set_pressed(_playing_edited);
  1001. return;
  1002. }
  1003. play_button->set_pressed(false);
  1004. pause_button->set_pressed(false);
  1005. play_scene_button->set_pressed(false);
  1006. String current_filename;
  1007. String run_filename;
  1008. String args;
  1009. if (p_current || (edited_scene && p_custom==edited_scene->get_filename())) {
  1010. Node *scene = edited_scene;
  1011. if (!scene) {
  1012. current_option=-1;
  1013. //accept->get_cancel()->hide();
  1014. accept->get_ok()->set_text("I see..");
  1015. accept->set_text("No scene to run exists.");
  1016. accept->popup_centered(Size2(300,70));;
  1017. return;
  1018. }
  1019. if (scene->get_filename()=="") {
  1020. current_option=-1;
  1021. //accept->get_cancel()->hide();
  1022. accept->get_ok()->set_text("I see..");
  1023. accept->set_text("Scene has never been saved. Save before running!");
  1024. accept->popup_centered(Size2(300,70));;
  1025. return;
  1026. }
  1027. bool autosave = EDITOR_DEF("run/auto_save_before_running",true);
  1028. if (autosave) {
  1029. _menu_option(FILE_SAVE_SCENE);
  1030. }
  1031. if (run_settings_dialog->get_run_mode()==RunSettingsDialog::RUN_LOCAL_SCENE) {
  1032. run_filename=scene->get_filename();
  1033. } else {
  1034. args=run_settings_dialog->get_custom_arguments();
  1035. current_filename=scene->get_filename();
  1036. }
  1037. } else if (p_custom!="") {
  1038. run_filename=p_custom;
  1039. }
  1040. if (run_filename=="") {
  1041. //evidently, run the scene
  1042. run_filename=GLOBAL_DEF("application/main_scene","");
  1043. if (run_filename=="") {
  1044. current_option=-1;
  1045. //accept->get_cancel()->hide();
  1046. accept->get_ok()->set_text("I see..");
  1047. accept->set_text("No main scene has ever been defined.\nSelect one from \"Project Settings\" under the 'application' category.");
  1048. accept->popup_centered(Size2(300,100));;
  1049. return;
  1050. }
  1051. }
  1052. if (bool(EDITOR_DEF("run/auto_save_before_running",true))) {
  1053. if (unsaved_cache) {
  1054. Node *scene = edited_scene;
  1055. if (scene) { //only autosave if there is a scene obviously
  1056. if (scene->get_filename()=="") {
  1057. current_option=-1;
  1058. //accept->get_cancel()->hide();
  1059. accept->get_ok()->set_text("I see..");
  1060. accept->set_text("Current scene was never saved, please save scene before running.");
  1061. accept->popup_centered(Size2(300,70));;
  1062. return;
  1063. }
  1064. _save_scene(scene->get_filename());
  1065. }
  1066. }
  1067. editor_data.save_editor_external_data();
  1068. }
  1069. List<String> breakpoints;
  1070. editor_data.get_editor_breakpoints(&breakpoints);
  1071. Error error = editor_run.run(run_filename,args,breakpoints,current_filename);
  1072. if (error!=OK) {
  1073. current_option=-1;
  1074. //confirmation->get_cancel()->hide();
  1075. accept->get_ok()->set_text("I see..");
  1076. accept->set_text("Could not start subprocess!");
  1077. accept->popup_centered(Size2(300,70));;
  1078. return;
  1079. }
  1080. emit_signal("play_pressed");
  1081. if (p_current) {
  1082. play_scene_button->set_pressed(true);
  1083. } else {
  1084. play_button->set_pressed(true);
  1085. }
  1086. _playing_edited=p_current;
  1087. }
  1088. void EditorNode::_cleanup_scene() {
  1089. Node *scene = edited_scene;
  1090. editor_selection->clear();
  1091. editor_data.clear_editor_states();
  1092. editor_history.clear();
  1093. _hide_top_editors();
  1094. animation_editor->cleanup();
  1095. property_editor->edit(NULL);
  1096. resources_dock->cleanup();
  1097. scene_import_metadata.unref();
  1098. set_edited_scene(NULL);
  1099. if (scene) {
  1100. if (scene->get_filename()!="") {
  1101. previous_scenes.push_back(scene->get_filename());
  1102. }
  1103. memdelete(scene);
  1104. }
  1105. editor_data.get_undo_redo().clear_history();
  1106. saved_version=editor_data.get_undo_redo().get_version();
  1107. run_settings_dialog->set_run_mode(0);
  1108. run_settings_dialog->set_custom_arguments("-l $scene");
  1109. List<Ref<Resource> > cached;
  1110. ResourceCache::get_cached_resources(&cached);
  1111. for(List<Ref<Resource> >::Element *E=cached.front();E;E=E->next()) {
  1112. String path = E->get()->get_path();
  1113. if (path.is_resource_file()) {
  1114. ERR_PRINT(("Stray resource not cleaned:"+path).utf8().get_data());
  1115. }
  1116. }
  1117. _update_title();
  1118. }
  1119. void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) {
  1120. current_option=(MenuOptions)p_option;
  1121. switch( p_option ) {
  1122. case FILE_NEW_SCENE: {
  1123. if (!p_confirmed) {
  1124. confirmation->get_ok()->set_text("Yes");
  1125. //confirmation->get_cancel()->show();
  1126. confirmation->set_text("Start a New Scene? (Current will be lost)");
  1127. confirmation->popup_centered(Size2(300,70));
  1128. break;
  1129. }
  1130. _cleanup_scene();
  1131. } break;
  1132. case FILE_OPEN_SCENE: {
  1133. //print_tree();
  1134. file->set_mode(FileDialog::MODE_OPEN_FILE);
  1135. //not for now?
  1136. List<String> extensions;
  1137. ResourceLoader::get_recognized_extensions_for_type("PackedScene",&extensions);
  1138. file->clear_filters();
  1139. for(int i=0;i<extensions.size();i++) {
  1140. file->add_filter("*."+extensions[i]+" ; "+extensions[i].to_upper());
  1141. }
  1142. //file->set_current_path(current_path);
  1143. Node *scene = edited_scene;
  1144. if (scene) {
  1145. file->set_current_path(scene->get_filename());
  1146. };
  1147. file->set_title("Open Scene");
  1148. file->popup_centered_ratio();
  1149. } break;
  1150. case FILE_QUICK_OPEN_SCENE: {
  1151. quick_open->popup("PackedScene");
  1152. quick_open->set_title("Quick Open Scene..");
  1153. } break;
  1154. case FILE_QUICK_OPEN_SCRIPT: {
  1155. quick_open->popup("Script");
  1156. quick_open->set_title("Quick Open Script..");
  1157. } break;
  1158. case FILE_RUN_SCRIPT: {
  1159. file_script->popup_centered_ratio();
  1160. } break;
  1161. case FILE_OPEN_PREV: {
  1162. if (previous_scenes.empty())
  1163. break;
  1164. opening_prev=true;
  1165. open_request(previous_scenes.back()->get());
  1166. } break;
  1167. #ifdef OLD_SCENE_FORMAT_ENABLED
  1168. case FILE_OPEN_OLD_SCENE: {
  1169. //print_tree();
  1170. file->set_mode(FileDialog::MODE_OPEN_FILE);
  1171. //not for now?
  1172. file->clear_filters();
  1173. file->add_filter("*.xml");
  1174. //file->set_current_path(current_path);
  1175. Node *scene = edited_scene;
  1176. if (scene) {
  1177. file->set_current_path(scene->get_filename());
  1178. };
  1179. file->set_title("Open Scene");
  1180. file->popup_centered_ratio();
  1181. } break;
  1182. #endif
  1183. case FILE_SAVE_SCENE: {
  1184. Node *scene = edited_scene;
  1185. if (scene && scene->get_filename()!="") {
  1186. _save_scene(scene->get_filename());
  1187. return;
  1188. };
  1189. // fallthrough to save_as
  1190. };
  1191. case FILE_SAVE_AS_SCENE: {
  1192. Node *scene = edited_scene;
  1193. if (!scene) {
  1194. current_option=-1;
  1195. //confirmation->get_cancel()->hide();
  1196. accept->get_ok()->set_text("I see..");
  1197. accept->set_text("This operation can't be done without a tree root.");
  1198. accept->popup_centered(Size2(300,70));;
  1199. break;
  1200. }
  1201. file->set_mode(FileDialog::MODE_SAVE_FILE);
  1202. bool relpaths = (scene->has_meta("__editor_relpaths__") && scene->get_meta("__editor_relpaths__").operator bool());
  1203. List<String> extensions;
  1204. Ref<PackedScene> sd = memnew( PackedScene );
  1205. ResourceSaver::get_recognized_extensions(sd,&extensions);
  1206. file->clear_filters();
  1207. for(int i=0;i<extensions.size();i++) {
  1208. file->add_filter("*."+extensions[i]+" ; "+extensions[i].to_upper());
  1209. }
  1210. //file->set_current_path(current_path);
  1211. if (scene->get_filename()!="") {
  1212. file->set_current_path(scene->get_filename());
  1213. if (extensions.size()) {
  1214. String ext=scene->get_filename().extension().to_lower();
  1215. if (extensions.find(ext)==NULL) {
  1216. file->set_current_path(scene->get_filename().replacen("."+ext,"."+extensions.front()->get()));
  1217. }
  1218. }
  1219. } else {
  1220. String existing;
  1221. if (extensions.size()) {
  1222. existing="new_scene."+extensions.front()->get().to_lower();
  1223. }
  1224. file->set_current_path(existing);
  1225. }
  1226. file->popup_centered_ratio();
  1227. file->set_title("Save Scene As..");
  1228. } break;
  1229. case FILE_DUMP_STRINGS: {
  1230. Node *scene = edited_scene;
  1231. if (!scene) {
  1232. current_option=-1;
  1233. //confirmation->get_cancel()->hide();
  1234. accept->get_ok()->set_text("I see..");
  1235. accept->set_text("This operation can't be done without a tree root.");
  1236. accept->popup_centered(Size2(300,70));;
  1237. break;
  1238. }
  1239. String cpath;
  1240. if (scene->get_filename()!="") {
  1241. cpath = scene->get_filename();
  1242. String fn = cpath.substr(0,cpath.length() - cpath.extension().size());
  1243. String ext=cpath.extension();
  1244. cpath=fn+".pot";
  1245. } else {
  1246. current_option=-1;
  1247. //confirmation->get_cancel()->hide();
  1248. accept->get_ok()->set_text("I see..");
  1249. accept->set_text("Please save the scene first.");
  1250. accept->popup_centered(Size2(300,70));;
  1251. break;
  1252. }
  1253. bool relpaths = (scene->has_meta("__editor_relpaths__") && scene->get_meta("__editor_relpaths__").operator bool());
  1254. file->set_current_path(cpath);
  1255. file->set_title("Save Translatable Strings");
  1256. file->popup_centered_ratio();
  1257. } break;
  1258. case FILE_SAVE_SUBSCENE: {
  1259. Node *scene = edited_scene;
  1260. if (!scene) {
  1261. current_option=-1;
  1262. //confirmation->get_cancel()->hide();
  1263. accept->get_ok()->set_text("I see..");
  1264. accept->set_text("This operation can't be done without a scene.");
  1265. accept->popup_centered(Size2(300,70));;
  1266. break;
  1267. }
  1268. List<Node*> selection = editor_selection->get_selected_node_list();
  1269. if (selection.size()!=1) {
  1270. current_option=-1;
  1271. //confirmation->get_cancel()->hide();
  1272. accept->get_ok()->set_text("I see..");
  1273. accept->set_text("This operation requieres a single selected node.");
  1274. accept->popup_centered(Size2(300,70));;
  1275. break;
  1276. }
  1277. Node *tocopy = selection.front()->get();
  1278. if (tocopy!=edited_scene && tocopy->get_filename()!="") {
  1279. current_option=-1;
  1280. //confirmation->get_cancel()->hide();
  1281. accept->get_ok()->set_text("I see..");
  1282. accept->set_text("This operation can't be done on instanced scenes.");
  1283. accept->popup_centered(Size2(300,70));;
  1284. break;
  1285. }
  1286. file->set_mode(FileDialog::MODE_SAVE_FILE);
  1287. List<String> extensions;
  1288. Ref<PackedScene> sd = memnew( PackedScene );
  1289. ResourceSaver::get_recognized_extensions(sd,&extensions);
  1290. file->clear_filters();
  1291. for(int i=0;i<extensions.size();i++) {
  1292. file->add_filter("*."+extensions[i]+" ; "+extensions[i].to_upper());
  1293. }
  1294. String existing;
  1295. if (extensions.size()) {
  1296. existing="new_scene."+extensions.front()->get().to_lower();
  1297. }
  1298. file->set_current_path(existing);
  1299. file->popup_centered_ratio();
  1300. file->set_title("Save Sub-Scene As..");
  1301. } break;
  1302. case FILE_SAVE_OPTIMIZED: {
  1303. Node *scene = edited_scene;
  1304. #if 0
  1305. if (!scene) {
  1306. current_option=-1;
  1307. //confirmation->get_cancel()->hide();
  1308. accept->get_ok()->set_text("I see..");
  1309. accept->set_text("This operation can't be done without a tree root.");
  1310. accept->popup_centered(Size2(300,70));;
  1311. break;
  1312. }
  1313. //file->set_current_path(current_path);
  1314. String cpath;
  1315. if (scene->get_filename()!="") {
  1316. cpath = scene->get_filename();
  1317. String fn = cpath.substr(0,cpath.length() - cpath.extension().size());
  1318. String ext=cpath.extension();
  1319. cpath=fn+".optimized.scn";
  1320. optimized_save->set_optimized_scene(cpath);
  1321. optimized_save->popup_centered(Size2(500,143));
  1322. } else {
  1323. current_option=-1;
  1324. //confirmation->get_cancel()->hide();
  1325. accept->get_ok()->set_text("I see..");
  1326. accept->set_text("Please save the scene first.");
  1327. accept->popup_centered(Size2(300,70));;
  1328. break;
  1329. }
  1330. #endif
  1331. } break;
  1332. case FILE_EXPORT_PROJECT: {
  1333. project_export_settings->popup_centered_ratio();
  1334. /*
  1335. String target = export_db->get_current_platform();
  1336. Ref<EditorExporter> exporter = export_db->get_exporter(target);
  1337. if (exporter.is_null()) {
  1338. accept->set_text("No exporter for platform '"+target+"' yet.");
  1339. accept->popup_centered(Size2(300,70));;
  1340. return;
  1341. }
  1342. String extension = exporter->get_binary_extension();
  1343. print_line("for target: "+target+" extension: "+extension);
  1344. file_export_password->set_editable( exporter->requieres_password(file_export_check->is_pressed()));
  1345. file_export->clear_filters();
  1346. if (extension!="") {
  1347. file_export->add_filter("*."+extension);
  1348. }
  1349. file_export->popup_centered_ratio();*/
  1350. } break;
  1351. case FILE_EXPORT_MESH_LIBRARY: {
  1352. if (!edited_scene) {
  1353. current_option=-1;
  1354. //confirmation->get_cancel()->hide();
  1355. accept->get_ok()->set_text("I see..");
  1356. accept->set_text("This operation can't be done without a scene.");
  1357. accept->popup_centered(Size2(300,70));;
  1358. break;
  1359. }
  1360. List<String> extensions;
  1361. Ref<MeshLibrary> ml( memnew( MeshLibrary) );
  1362. ResourceSaver::get_recognized_extensions(ml,&extensions);
  1363. file_export_lib->clear_filters();
  1364. for(List<String>::Element *E=extensions.front();E;E=E->next()) {
  1365. file_export_lib->add_filter("*."+E->get());
  1366. }
  1367. file_export_lib->popup_centered_ratio();
  1368. file_export_lib->set_title("Export Mesh Library");
  1369. } break;
  1370. case FILE_EXPORT_TILESET: {
  1371. List<String> extensions;
  1372. Ref<TileSet> ml( memnew( TileSet) );
  1373. ResourceSaver::get_recognized_extensions(ml,&extensions);
  1374. file_export_lib->clear_filters();
  1375. for(List<String>::Element *E=extensions.front();E;E=E->next()) {
  1376. file_export_lib->add_filter("*."+E->get());
  1377. }
  1378. file_export_lib->popup_centered_ratio();
  1379. file_export_lib->set_title("Export Tile Set");
  1380. } break;
  1381. case SETTINGS_EXPORT_PREFERENCES: {
  1382. //project_export_settings->popup_centered_ratio();
  1383. } break;
  1384. case FILE_IMPORT_SUBSCENE: {
  1385. //import_subscene->popup_centered_ratio();
  1386. if (!edited_scene) {
  1387. current_option=-1;
  1388. //accept->get_cancel()->hide();
  1389. accept->get_ok()->set_text("I see..");
  1390. accept->set_text("This operation can't be done without a selected node.");
  1391. accept->popup_centered(Size2(300,70));;
  1392. break;
  1393. }
  1394. scene_tree_dock->import_subscene();
  1395. } break;
  1396. case FILE_QUIT: {
  1397. if (!p_confirmed) {
  1398. confirmation->get_ok()->set_text("Quit");
  1399. //confirmation->get_cancel()->show();
  1400. confirmation->set_text("Exit the Editor?");
  1401. confirmation->popup_centered(Size2(300,70));
  1402. break;
  1403. }
  1404. _menu_option_confirm(RUN_STOP,true);
  1405. get_scene()->quit();
  1406. } break;
  1407. case FILE_EXTERNAL_OPEN_SCENE: {
  1408. if (unsaved_cache && !p_confirmed) {
  1409. confirmation->get_ok()->set_text("Open");
  1410. //confirmation->get_cancel()->show();
  1411. confirmation->set_text("Current scene not saved. Open anyway?");
  1412. confirmation->popup_centered(Size2(300,70));
  1413. break;
  1414. }
  1415. bool oprev=opening_prev;
  1416. Error err = load_scene(external_file);
  1417. if (err == OK && oprev) {
  1418. previous_scenes.pop_back();
  1419. opening_prev=false;
  1420. }
  1421. } break;
  1422. case EDIT_UNDO: {
  1423. if (OS::get_singleton()->get_mouse_button_state())
  1424. break; // can't undo while mouse buttons are pressed
  1425. String action = editor_data.get_undo_redo().get_current_action_name();
  1426. if (action!="")
  1427. log->add_message("UNDO: "+action);
  1428. editor_data.get_undo_redo().undo();
  1429. } break;
  1430. case EDIT_REDO: {
  1431. if (OS::get_singleton()->get_mouse_button_state())
  1432. break; // can't redo while mouse buttons are pressed
  1433. editor_data.get_undo_redo().redo();
  1434. String action = editor_data.get_undo_redo().get_current_action_name();
  1435. if (action!="")
  1436. log->add_message("REDO: "+action);
  1437. } break;
  1438. #if 0
  1439. case NODE_EXTERNAL_INSTANCE: {
  1440. if (!edited_scene) {
  1441. current_option=-1;
  1442. //accept->get_cancel()->hide();
  1443. accept->get_ok()->set_text("I see..");
  1444. accept->set_text("This operation can't be done without a selected node.");
  1445. accept->popup_centered(Size2(300,70));;
  1446. break;
  1447. }
  1448. Node *parent = scene_tree_editor->get_selected();
  1449. if (!parent) {
  1450. current_option=-1;
  1451. //confirmation->get_cancel()->hide();
  1452. accept->get_ok()->set_text("I see..");
  1453. accept->set_text("This operation can't be done without a selected node.");
  1454. accept->popup_centered(Size2(300,70));;
  1455. break;
  1456. }
  1457. Node*instanced_scene=SceneLoader::load(external_file,true);
  1458. if (!instanced_scene) {
  1459. current_option=-1;
  1460. //accept->get_cancel()->hide();
  1461. accept->get_ok()->set_text("Ugh");
  1462. accept->set_text(String("Error loading scene from ")+external_file);
  1463. accept->popup_centered(Size2(300,70));;
  1464. return;
  1465. }
  1466. instanced_scene->generate_instance_state();
  1467. instanced_scene->set_filename( Globals::get_singleton()->localize_path(external_file) );
  1468. editor_data.get_undo_redo().create_action("Instance Scene");
  1469. editor_data.get_undo_redo().add_do_method(parent,"add_child",instanced_scene);
  1470. editor_data.get_undo_redo().add_do_method(instanced_scene,"set_owner",edited_scene);
  1471. editor_data.get_undo_redo().add_do_reference(instanced_scene);
  1472. editor_data.get_undo_redo().add_undo_method(parent,"remove_child",instanced_scene);
  1473. editor_data.get_undo_redo().commit_action();
  1474. // parent->add_child(instanced_scene);
  1475. // instanced_scene->set_owner(edited_scene);
  1476. _last_instanced_scene=instanced_scene;
  1477. } break;
  1478. #endif
  1479. case OBJECT_REQUEST_HELP: {
  1480. if (current) {
  1481. _editor_select(3);
  1482. emit_signal("request_help",current->get_type());
  1483. }
  1484. } break;
  1485. case OBJECT_COPY_PARAMS: {
  1486. editor_data.apply_changes_in_editors();;
  1487. if (current)
  1488. editor_data.copy_object_params(current);
  1489. } break;
  1490. case OBJECT_PASTE_PARAMS: {
  1491. editor_data.apply_changes_in_editors();;
  1492. if (current)
  1493. editor_data.paste_object_params(current);
  1494. editor_data.get_undo_redo().clear_history();
  1495. } break;
  1496. case OBJECT_CALL_METHOD: {
  1497. editor_data.apply_changes_in_editors();;
  1498. call_dialog->set_object(current);
  1499. call_dialog->popup_centered_ratio();
  1500. } break;
  1501. case RUN_PLAY: {
  1502. _run(false);
  1503. } break;
  1504. case RUN_PLAY_CUSTOM_SCENE: {
  1505. quick_run->popup("PackedScene",true);
  1506. quick_run->set_title("Quick Run Scene..");
  1507. } break;
  1508. case RUN_PAUSE: {
  1509. emit_signal("pause_pressed");
  1510. } break;
  1511. case RUN_STOP: {
  1512. if (editor_run.get_status()==EditorRun::STATUS_STOP)
  1513. break;
  1514. editor_run.stop();
  1515. play_button->set_pressed(false);
  1516. play_scene_button->set_pressed(false);
  1517. pause_button->set_pressed(false);
  1518. emit_signal("stop_pressed");
  1519. } break;
  1520. case RUN_PLAY_SCENE: {
  1521. _run(true);
  1522. } break;
  1523. case RUN_SCENE_SETTINGS: {
  1524. run_settings_dialog->popup_run_settings();
  1525. } break;
  1526. case RUN_SETTINGS: {
  1527. project_settings->popup_project_settings();
  1528. } break;
  1529. case RUN_PROJECT_MANAGER: {
  1530. if (!p_confirmed) {
  1531. confirmation->get_ok()->set_text("Yes");
  1532. confirmation->set_text("Open Project Manager? \n(Unsaved changes will be lost)");
  1533. confirmation->popup_centered(Size2(300,70));
  1534. break;
  1535. }
  1536. get_scene()->quit();
  1537. String exec = OS::get_singleton()->get_executable_path();
  1538. List<String> args;
  1539. args.push_back ( "-path" );
  1540. args.push_back (exec.get_base_dir() );
  1541. OS::ProcessID pid=0;
  1542. Error err = OS::get_singleton()->execute(exec,args,false,&pid);
  1543. ERR_FAIL_COND(err);
  1544. } break;
  1545. case RUN_FILE_SERVER: {
  1546. //file_server
  1547. bool ischecked = fileserver_menu->get_popup()->is_item_checked( fileserver_menu->get_popup()->get_item_index(RUN_FILE_SERVER));
  1548. if (ischecked) {
  1549. file_server->stop();
  1550. fileserver_menu->set_icon(gui_base->get_icon("FileServer","EditorIcons"));
  1551. fileserver_menu->get_popup()->set_item_text( fileserver_menu->get_popup()->get_item_index(RUN_FILE_SERVER),"Enable File Server");
  1552. } else {
  1553. file_server->start();
  1554. fileserver_menu->set_icon(gui_base->get_icon("FileServerActive","EditorIcons"));
  1555. fileserver_menu->get_popup()->set_item_text( fileserver_menu->get_popup()->get_item_index(RUN_FILE_SERVER),"Disable File Server");
  1556. }
  1557. fileserver_menu->get_popup()->set_item_checked( fileserver_menu->get_popup()->get_item_index(RUN_FILE_SERVER),!ischecked);
  1558. } break;
  1559. case RUN_DEPLOY_DUMB_CLIENTS: {
  1560. bool ischecked = fileserver_menu->get_popup()->is_item_checked( fileserver_menu->get_popup()->get_item_index(RUN_DEPLOY_DUMB_CLIENTS));
  1561. fileserver_menu->get_popup()->set_item_checked( fileserver_menu->get_popup()->get_item_index(RUN_DEPLOY_DUMB_CLIENTS),!ischecked);
  1562. run_native->set_deploy_dumb(!ischecked);
  1563. } break;
  1564. case SETTINGS_UPDATE_ALWAYS: {
  1565. update_menu->get_popup()->set_item_checked(0,true);
  1566. update_menu->get_popup()->set_item_checked(1,false);
  1567. OS::get_singleton()->set_low_processor_usage_mode(false);
  1568. } break;
  1569. case SETTINGS_UPDATE_CHANGES: {
  1570. update_menu->get_popup()->set_item_checked(0,false);
  1571. update_menu->get_popup()->set_item_checked(1,true);
  1572. OS::get_singleton()->set_low_processor_usage_mode(true);
  1573. } break;
  1574. case SETTINGS_PREFERENCES: {
  1575. settings_config_dialog->popup_edit_settings();
  1576. } break;
  1577. case SETTINGS_IMPORT: {
  1578. import_settings->popup_import_settings();
  1579. } break;
  1580. case SETTINGS_OPTIMIZED_PRESETS: {
  1581. //optimized_presets->popup_centered_ratio();
  1582. } break;
  1583. case SETTINGS_SHOW_ANIMATION: {
  1584. animation_panel_make_visible( ! animation_panel->is_visible() );
  1585. } break;
  1586. case SETTINGS_LOAD_EXPORT_TEMPLATES: {
  1587. file_templates->popup_centered_ratio();
  1588. } break;
  1589. case SETTINGS_ABOUT: {
  1590. about->popup_centered(Size2(500,130));
  1591. } break;
  1592. case SOURCES_REIMPORT: {
  1593. reimport_dialog->popup_reimport();
  1594. } break;
  1595. case DEPENDENCY_LOAD_CHANGED_IMAGES: {
  1596. List<Ref<Resource> > cached;
  1597. ResourceCache::get_cached_resources(&cached);
  1598. for(List<Ref<Resource> >::Element *E=cached.front();E;E=E->next()) {
  1599. if (!E->get()->can_reload_from_file())
  1600. continue;
  1601. if (!FileAccess::exists(E->get()->get_path()))
  1602. continue;
  1603. uint64_t mt = FileAccess::get_modified_time(E->get()->get_path());
  1604. if (mt!=E->get()->get_last_modified_time()) {
  1605. E->get()->reload_from_file();
  1606. }
  1607. }
  1608. } break;
  1609. case DEPENDENCY_UPDATE_IMPORTED: {
  1610. /*
  1611. bool editing_changed = _find_editing_changed_scene(get_edited_scene());
  1612. import_reload_fn="";
  1613. if (editing_changed) {
  1614. if (unsaved_cache && !bool(EDITOR_DEF("import/ask_save_before_reimport",false))) {
  1615. if (!p_confirmed) {
  1616. confirmation->get_ok()->set_text("Open");
  1617. //confirmation->get_cancel()->show();
  1618. confirmation->set_text("Current scene changed, save and re-import ?");
  1619. confirmation->popup_centered(Size2(300,70));
  1620. break;
  1621. }
  1622. }
  1623. Node *scene = get_edited_scene();
  1624. if (scene->get_filename()=="") {
  1625. current_option=-1;
  1626. //accept->get_cancel()->hide();
  1627. accept->get_ok()->set_text("I see..");
  1628. accept->set_text("Can't import if edited scene was not saved."); //i dont think this code will ever run
  1629. accept->popup_centered(Size2(300,70));;
  1630. break;
  1631. }
  1632. import_reload_fn = scene->get_filename();
  1633. _save_scene(import_reload_fn);
  1634. _cleanup_scene();
  1635. }
  1636. */
  1637. } break;
  1638. default: {
  1639. if (p_option>=OBJECT_METHOD_BASE) {
  1640. ERR_FAIL_COND(!current);
  1641. int idx=p_option-OBJECT_METHOD_BASE;
  1642. List<MethodInfo> methods;
  1643. current->get_method_list(&methods);
  1644. ERR_FAIL_INDEX( idx, methods.size() );
  1645. String name=methods[idx].name;
  1646. if (current)
  1647. current->call(name);
  1648. } else if (p_option>=IMPORT_PLUGIN_BASE) {
  1649. Ref<EditorImportPlugin> p = editor_import_export->get_import_plugin(p_option-IMPORT_PLUGIN_BASE);
  1650. if (p.is_valid()) {
  1651. p->import_dialog();
  1652. }
  1653. }
  1654. }
  1655. }
  1656. }
  1657. Control* EditorNode::get_viewport() {
  1658. return viewport;
  1659. }
  1660. void EditorNode::_editor_select(int p_which) {
  1661. static bool selecting=false;
  1662. if (selecting)
  1663. return;
  1664. selecting=true;
  1665. ERR_FAIL_INDEX(p_which,editor_table.size());
  1666. main_editor_tabs->set_current_tab(p_which);
  1667. selecting=false;
  1668. EditorPlugin *new_editor = editor_table[p_which];
  1669. ERR_FAIL_COND(!new_editor);
  1670. if (editor_plugin_screen==new_editor)
  1671. return;
  1672. if (editor_plugin_screen) {
  1673. editor_plugin_screen->make_visible(false);
  1674. }
  1675. editor_plugin_screen=new_editor;
  1676. editor_plugin_screen->make_visible(true);
  1677. editor_plugin_screen->selected_notify();
  1678. }
  1679. void EditorNode::add_editor_plugin(EditorPlugin *p_editor) {
  1680. if (p_editor->has_main_screen()) {
  1681. singleton->main_editor_tabs->add_tab(p_editor->get_name());
  1682. singleton->editor_table.push_back(p_editor);
  1683. }
  1684. singleton->editor_data.add_editor_plugin( p_editor );
  1685. singleton->add_child(p_editor);
  1686. }
  1687. void EditorNode::remove_editor_plugin(EditorPlugin *p_editor) {
  1688. if (p_editor->has_main_screen()) {
  1689. for(int i=0;i<singleton->main_editor_tabs->get_tab_count();i++) {
  1690. if (p_editor->get_name()==singleton->main_editor_tabs->get_tab_title(i)) {
  1691. singleton->main_editor_tabs->remove_tab(i);
  1692. break;
  1693. }
  1694. }
  1695. singleton->main_editor_tabs->add_tab(p_editor->get_name());
  1696. singleton->editor_table.erase(p_editor);
  1697. }
  1698. singleton->remove_child(p_editor);
  1699. singleton->editor_data.remove_editor_plugin( p_editor );
  1700. }
  1701. void EditorNode::set_edited_scene(Node *p_scene) {
  1702. if (edited_scene) {
  1703. if (edited_scene->get_parent()==scene_root)
  1704. scene_root->remove_child(edited_scene);
  1705. animation_editor->set_root(NULL);
  1706. }
  1707. edited_scene=p_scene;
  1708. if (edited_scene && edited_scene->cast_to<Popup>())
  1709. edited_scene->cast_to<Popup>()->show(); //show popups
  1710. scene_tree_dock->set_edited_scene(edited_scene);
  1711. if (edited_scene) {
  1712. if (p_scene->get_parent()!=scene_root)
  1713. scene_root->add_child(p_scene);
  1714. animation_editor->set_root(p_scene);
  1715. }
  1716. }
  1717. void EditorNode::_fetch_translatable_strings(const Object *p_object,Set<StringName>& strings) {
  1718. List<String> tstrings;
  1719. p_object->get_translatable_strings(&tstrings);
  1720. for(List<String>::Element *E=tstrings.front();E;E=E->next())
  1721. strings.insert(E->get());
  1722. const Node * node = p_object->cast_to<Node>();
  1723. if (!node)
  1724. return;
  1725. Ref<Script> script = node->get_script();
  1726. if (script.is_valid())
  1727. _fetch_translatable_strings(script.ptr(),strings);
  1728. for(int i=0;i<node->get_child_count();i++) {
  1729. Node *c=node->get_child(i);
  1730. if (c->get_owner()!=get_edited_scene())
  1731. continue;
  1732. _fetch_translatable_strings(c,strings);
  1733. }
  1734. }
  1735. Error EditorNode::save_translatable_strings(const String& p_to_file) {
  1736. if (!is_inside_scene()) {
  1737. defer_translatable=p_to_file;
  1738. return OK;
  1739. }
  1740. ERR_FAIL_COND_V(!get_edited_scene(),ERR_INVALID_DATA);
  1741. Set<StringName> strings;
  1742. _fetch_translatable_strings(get_edited_scene(),strings);
  1743. Error err;
  1744. FileAccess *f = FileAccess::open(p_to_file,FileAccess::WRITE,&err);
  1745. ERR_FAIL_COND_V(err,err);
  1746. OS::Date date = OS::get_singleton()->get_date();
  1747. OS::Time time = OS::get_singleton()->get_time();
  1748. f->store_line("# Translation Strings Dump.");
  1749. f->store_line("# Created By.");
  1750. f->store_line("# \t"VERSION_FULL_NAME" (c) 2008-2014 Juan Linietsky, Ariel Manzur.");
  1751. f->store_line("# From Scene: ");
  1752. f->store_line("# \t"+get_edited_scene()->get_filename());
  1753. f->store_line("");
  1754. f->store_line("msgid \"\"");
  1755. f->store_line("msgstr \"\"");
  1756. f->store_line("\"Report-Msgid-Bugs-To: <define>\\n\"");
  1757. f->store_line("\"POT-Creation-Date: "+itos(date.year)+"-"+itos(date.month)+"-"+itos(date.day)+" "+itos(time.hour)+":"+itos(time.min)+"0000\\n\"");
  1758. // f->store_line("\"PO-Revision-Date: 2006-08-30 13:56-0700\\n\"");
  1759. // f->store_line("\"Last-Translator: Rubén C. Díaz Alonso <[email protected]>\\n\"");
  1760. f->store_line("\"Language-Team: <define>\\n\"");
  1761. f->store_line("\"MIME-Version: 1.0\\n\"");
  1762. f->store_line("\"Content-Type: text/plain; charset=UTF-8\\n\"");
  1763. f->store_line("\"Content-Transfer-Encoding: 8bit\\n\"");
  1764. f->store_line("");
  1765. for(Set<StringName>::Element *E=strings.front();E;E=E->next()) {
  1766. String s = E->get();
  1767. if (s=="" || s.strip_edges()=="")
  1768. continue;
  1769. Vector<String> substr = s.split("\n");
  1770. ERR_CONTINUE(substr.size()==0);
  1771. f->store_line("");
  1772. if (substr.size()==1) {
  1773. f->store_line("msgid \""+substr[0].c_escape()+"\"");
  1774. } else {
  1775. f->store_line("msgid \"\"");
  1776. for(int i=0;i<substr.size();i++) {
  1777. String s = substr[i];
  1778. if (i!=substr.size()-1)
  1779. s+="\n";
  1780. f->store_line("\""+s.c_escape()+"\"");
  1781. }
  1782. }
  1783. f->store_line("msgstr \"\"");
  1784. }
  1785. f->close();
  1786. memdelete(f);
  1787. return OK;
  1788. }
  1789. Error EditorNode::save_optimized_copy(const String& p_scene,const String& p_preset) {
  1790. #if 0
  1791. if (!is_inside_scene()) {
  1792. defer_optimize=p_scene;
  1793. defer_optimize_preset=p_preset;
  1794. return OK;
  1795. }
  1796. if (!get_edited_scene()) {
  1797. get_scene()->quit();
  1798. ERR_EXPLAIN("No scene to optimize (loading failed?");
  1799. ERR_FAIL_V(ERR_FILE_NOT_FOUND);
  1800. }
  1801. String src_scene=Globals::get_singleton()->localize_path(get_edited_scene()->get_filename());
  1802. String path=p_scene;
  1803. print_line("p_path: "+p_scene);
  1804. print_line("src_scene: "+p_scene);
  1805. if (path.is_rel_path()) {
  1806. print_line("rel path!?");
  1807. path=src_scene.get_base_dir()+"/"+path;
  1808. }
  1809. path = Globals::get_singleton()->localize_path(path);
  1810. print_line("path: "+path);
  1811. String preset = "optimizer_presets/"+p_preset;
  1812. if (!Globals::get_singleton()->has(preset)) {
  1813. //accept->"()->hide();
  1814. accept->get_ok()->set_text("I see..");
  1815. accept->set_text("Optimizer preset not found: "+p_preset);
  1816. accept->popup_centered(Size2(300,70));;
  1817. ERR_EXPLAIN("Optimizer preset not found: "+p_preset);
  1818. ERR_FAIL_V(ERR_INVALID_PARAMETER);
  1819. }
  1820. Dictionary d = Globals::get_singleton()->get(preset);
  1821. ERR_FAIL_COND_V(!d.has("__type__"),ERR_INVALID_DATA);
  1822. String type=d["__type__"];
  1823. Ref<EditorOptimizedSaver> saver;
  1824. for(int i=0;i<editor_data.get_optimized_saver_count();i++) {
  1825. print_line(type+" vs "+editor_data.get_optimized_saver(i)->get_target_name());
  1826. if (editor_data.get_optimized_saver(i)->get_target_name()==type) {
  1827. saver=editor_data.get_optimized_saver(i);
  1828. }
  1829. }
  1830. ERR_EXPLAIN("Preset '"+p_preset+"' references unexisting saver: "+type);
  1831. ERR_FAIL_COND_V(saver.is_null(),ERR_INVALID_DATA);
  1832. List<Variant> keys;
  1833. d.get_key_list(&keys);
  1834. saver->clear();
  1835. for(List<Variant>::Element *E=keys.front();E;E=E->next()) {
  1836. saver->set(E->get(),d[E->get()]);
  1837. }
  1838. uint32_t flags=0;
  1839. // if (saver->is_bundle_scenes_enabled())
  1840. // flags|=ResourceSaver::FLAG_BUNDLE_INSTANCED_SCENES;
  1841. if (saver->is_bundle_resources_enabled())
  1842. flags|=ResourceSaver::FLAG_BUNDLE_RESOURCES;
  1843. if (saver->is_remove_editor_data_enabled())
  1844. flags|=ResourceSaver::FLAG_OMIT_EDITOR_PROPERTIES;
  1845. if (saver->is_big_endian_data_enabled())
  1846. flags|=ResourceSaver::FLAG_SAVE_BIG_ENDIAN;
  1847. String platform=saver->get_target_platform();
  1848. if (platform=="")
  1849. platform="all";
  1850. Ref<PackedScene> sdata = memnew( PackedScene );
  1851. Error err = sdata->pack(get_edited_scene());
  1852. if (err) {
  1853. current_option=-1;
  1854. //accept->get_cancel()->hide();
  1855. accept->get_ok()->set_text("I see..");
  1856. accept->set_text("Couldn't save scene. Likely dependencies (instances) couldn't be satisfied.");
  1857. accept->popup_centered(Size2(300,70));;
  1858. return ERR_INVALID_DATA;
  1859. }
  1860. err = ResourceSaver::save(path,sdata,flags); //todo, saverSceneSaver::save(path,get_edited_scene(),flags,saver);
  1861. if (err) {
  1862. //accept->"()->hide();
  1863. accept->get_ok()->set_text("I see..");
  1864. accept->set_text("Error saving optimized scene: "+path);
  1865. accept->popup_centered(Size2(300,70));;
  1866. ERR_FAIL_COND_V(err,err);
  1867. }
  1868. project_settings->add_remapped_path(src_scene,path,platform);
  1869. #endif
  1870. return OK;
  1871. }
  1872. Error EditorNode::load_scene(const String& p_scene) {
  1873. if (!is_inside_scene()) {
  1874. defer_load_scene = p_scene;
  1875. return OK;
  1876. }
  1877. load_errors->clear();
  1878. String lpath = Globals::get_singleton()->localize_path(p_scene);
  1879. if (!lpath.begins_with("res://")) {
  1880. current_option=-1;
  1881. //accept->get_cancel()->hide();
  1882. accept->get_ok()->set_text("Ugh");
  1883. accept->set_text("Error loading scene, it must be inside the project path. Use 'Import' to open the scene, then save it inside the project path.");
  1884. accept->popup_centered(Size2(300,120));
  1885. opening_prev=false;
  1886. return ERR_FILE_NOT_FOUND;
  1887. }
  1888. _cleanup_scene(); // i'm sorry but this MUST happen to avoid modified resources to not be reloaded.
  1889. Ref<PackedScene> sdata = ResourceLoader::load(lpath);
  1890. if (!sdata.is_valid()) {
  1891. current_option=-1;
  1892. //accept->get_cancel()->hide();
  1893. accept->get_ok()->set_text("Ugh");
  1894. accept->set_text("Error loading scene.");
  1895. accept->popup_centered(Size2(300,70));;
  1896. opening_prev=false;
  1897. return ERR_FILE_NOT_FOUND;
  1898. }
  1899. Node*new_scene=sdata->instance(true);
  1900. if (!new_scene) {
  1901. current_option=-1;
  1902. //accept->get_cancel()->hide();
  1903. accept->get_ok()->set_text("Ugh");
  1904. accept->set_text("Error loading scene.");
  1905. accept->popup_centered(Size2(300,70));;
  1906. opening_prev=false;
  1907. return ERR_FILE_NOT_FOUND;
  1908. }
  1909. /*
  1910. Node *old_scene = edited_scene;
  1911. _hide_top_editors();
  1912. set_edited_scene(NULL);
  1913. editor_data.clear_editor_states();
  1914. if (old_scene) {
  1915. if (!opening_prev && old_scene->get_filename()!="") {
  1916. previous_scenes.push_back(old_scene->get_filename());
  1917. }
  1918. memdelete(old_scene);
  1919. }
  1920. */
  1921. set_edited_scene(new_scene);
  1922. _get_scene_metadata();
  1923. scene_tree_dock->set_selected(new_scene, true);
  1924. property_editor->edit(new_scene);
  1925. scene_import_metadata = sdata->get_import_metadata();
  1926. editor_data.get_undo_redo().clear_history();
  1927. saved_version=editor_data.get_undo_redo().get_version();
  1928. _update_title();
  1929. _add_to_recent_scenes(lpath);
  1930. if (new_scene->has_meta("__editor_plugin_screen__")) {
  1931. String editor = new_scene->get_meta("__editor_plugin_screen__");
  1932. for(int i=0;i<editor_table.size();i++) {
  1933. if (editor_table[i]->get_name()==editor) {
  1934. _editor_select(i);
  1935. break;
  1936. }
  1937. }
  1938. }
  1939. prev_scene->set_disabled(previous_scenes.size()==0);
  1940. opening_prev=false;
  1941. top_pallete->set_current_tab(0); //always go to scene
  1942. push_item(new_scene);
  1943. return OK;
  1944. }
  1945. void EditorNode::open_request(const String& p_path) {
  1946. external_file=p_path;
  1947. _menu_option_confirm(FILE_EXTERNAL_OPEN_SCENE,false);
  1948. }
  1949. Node* EditorNode::request_instance_scene(const String &p_path) {
  1950. return scene_tree_dock->instance(p_path);
  1951. }
  1952. ScenesDock *EditorNode::get_scenes_dock() {
  1953. return scenes_dock;
  1954. }
  1955. void EditorNode::_instance_request(const String& p_path){
  1956. request_instance_scene(p_path);
  1957. }
  1958. void EditorNode::_property_keyed(const String& p_keyed,const Variant& p_value) {
  1959. animation_editor->insert_value_key(p_keyed,p_value);
  1960. }
  1961. void EditorNode::_transform_keyed(Object *sp,const String& p_sub,const Transform& p_key) {
  1962. Spatial *s=sp->cast_to<Spatial>();
  1963. if (!s)
  1964. return;
  1965. animation_editor->insert_transform_key(s,p_sub,p_key);
  1966. }
  1967. void EditorNode::_update_keying() {
  1968. //print_line("KR: "+itos(p_enabled));
  1969. bool valid=false;
  1970. if (animation_editor->has_keying()) {
  1971. if (editor_history.get_path_size()>=1) {
  1972. Object *obj = ObjectDB::get_instance(editor_history.get_path_object(0));
  1973. if (obj && obj->cast_to<Node>()) {
  1974. valid=true;
  1975. }
  1976. }
  1977. }
  1978. property_editor->set_keying(valid);
  1979. }
  1980. void EditorNode::_close_messages() {
  1981. // left_split->set_dragger_visible(false);
  1982. old_split_ofs = left_split->get_split_offset();
  1983. left_split->set_split_offset(0);
  1984. // scene_root_parent->set_anchor_and_margin(MARGIN_BOTTOM,Control::ANCHOR_END,0);
  1985. }
  1986. void EditorNode::_show_messages() {
  1987. // left_split->set_dragger_visible(true);
  1988. left_split->set_split_offset(old_split_ofs);
  1989. // scene_root_parent->set_anchor_and_margin(MARGIN_BOTTOM,Control::ANCHOR_END,log->get_margin(MARGIN_TOP));
  1990. }
  1991. void EditorNode::animation_panel_make_visible(bool p_visible) {
  1992. if (!p_visible) {
  1993. animation_panel->hide();
  1994. } else {
  1995. animation_panel->show();
  1996. }
  1997. int idx = settings_menu->get_popup()->get_item_index(SETTINGS_SHOW_ANIMATION);
  1998. settings_menu->get_popup()->set_item_checked(idx,p_visible);
  1999. }
  2000. void EditorNode::animation_editor_make_visible(bool p_visible) {
  2001. if (p_visible) {
  2002. animation_editor->show();
  2003. animation_vb->get_parent_control()->minimum_size_changed();
  2004. //pd_anim->show();
  2005. top_split->set_collapsed(false);
  2006. //scene_root_parent->set_margin(MARGIN_TOP,animation_editor->get_margin(MARGIN_BOTTOM));
  2007. } else {
  2008. //pd_anim->hide();
  2009. animation_editor->hide();
  2010. // scene_root_parent->set_margin(MARGIN_TOP,0);
  2011. animation_vb->get_parent_control()->minimum_size_changed();
  2012. top_split->set_collapsed(true);
  2013. }
  2014. animation_editor->set_keying(p_visible);
  2015. _update_keying();
  2016. }
  2017. void EditorNode::_add_to_recent_scenes(const String& p_scene) {
  2018. String base="_"+Globals::get_singleton()->get_resource_path().replace("\\","::").replace("/","::");
  2019. Vector<String> rc = EDITOR_DEF(base+"/_recent_scenes",Array());
  2020. String name = p_scene;
  2021. name=name.replace("res://","");
  2022. if (rc.find(name)!=-1)
  2023. rc.erase(name);
  2024. rc.insert(0,name);
  2025. if (rc.size()>10)
  2026. rc.resize(10);
  2027. EditorSettings::get_singleton()->set(base+"/_recent_scenes",rc);
  2028. EditorSettings::get_singleton()->save();
  2029. _update_recent_scenes();
  2030. }
  2031. void EditorNode::_open_recent_scene(int p_idx) {
  2032. String base="_"+Globals::get_singleton()->get_resource_path().replace("\\","::").replace("/","::");
  2033. Vector<String> rc = EDITOR_DEF(base+"/_recent_scenes",Array());
  2034. ERR_FAIL_INDEX(p_idx,rc.size());
  2035. String path = "res://"+rc[p_idx];
  2036. if (unsaved_cache) {
  2037. _recent_scene=rc[p_idx];
  2038. open_recent_confirmation->set_text("Discard current scene and open:\n'"+rc[p_idx]+"'");
  2039. open_recent_confirmation->get_label()->set_align(Label::ALIGN_CENTER);
  2040. open_recent_confirmation->popup_centered(Size2(400,100));
  2041. return;
  2042. }
  2043. load_scene(rc[p_idx]);
  2044. }
  2045. void EditorNode::_save_optimized() {
  2046. // save_optimized_copy(optimized_save->get_optimized_scene(),optimized_save->get_preset());
  2047. #if 0
  2048. String path = optimized_save->get_optimized_scene();
  2049. uint32_t flags=0;
  2050. String platform="all";
  2051. Ref<EditorOptimizedSaver> saver=editor_data.get_optimized_saver(optimized_save->get_preset());
  2052. if (saver->is_bundle_scenes_enabled())
  2053. flags|=SceneSaver::FLAG_BUNDLE_INSTANCED_SCENES;
  2054. if (saver->is_bundle_resources_enabled())
  2055. flags|=SceneSaver::FLAG_BUNDLE_RESOURCES;
  2056. if (saver->is_remove_editor_data_enabled())
  2057. flags|=SceneSaver::FLAG_OMIT_EDITOR_PROPERTIES;
  2058. if (saver->is_big_endian_data_enabled())
  2059. flags|=SceneSaver::FLAG_SAVE_BIG_ENDIAN;
  2060. platform=saver->get_target_platform();
  2061. Error err = SceneSaver::save(path,get_edited_scene(),flags,saver);
  2062. if (err) {
  2063. //accept->"()->hide();
  2064. accept->get_ok()->set_text("I see..");
  2065. accept->set_text("Error saving optimized scene: "+path);
  2066. accept->popup_centered(Size2(300,70));;
  2067. return;
  2068. }
  2069. project_settings->add_remapped_path(Globals::get_singleton()->localize_path(get_edited_scene()->get_filename()),Globals::get_singleton()->localize_path(path),platform);
  2070. #endif
  2071. }
  2072. void EditorNode::_open_recent_scene_confirm() {
  2073. load_scene(_recent_scene);
  2074. }
  2075. void EditorNode::_update_recent_scenes() {
  2076. String base="_"+Globals::get_singleton()->get_resource_path().replace("\\","::").replace("/","::");
  2077. Vector<String> rc = EDITOR_DEF(base+"/_recent_scenes",Array());
  2078. recent_scenes->clear();
  2079. for(int i=0;i<rc.size();i++) {
  2080. recent_scenes->add_item(rc[i],i);
  2081. }
  2082. }
  2083. void EditorNode::hide_animation_player_editors() {
  2084. emit_signal("hide_animation_player_editors");
  2085. }
  2086. void EditorNode::_quick_opened(const String& p_resource) {
  2087. print_line("quick_opened");
  2088. if (quick_open->get_base_type()=="PackedScene") {
  2089. open_request(p_resource);
  2090. } else {
  2091. load_resource(p_resource);
  2092. }
  2093. }
  2094. void EditorNode::_quick_run(const String& p_resource) {
  2095. _run(false,p_resource);
  2096. }
  2097. void EditorNode::notify_child_process_exited() {
  2098. play_button->set_pressed(false);
  2099. play_scene_button->set_pressed(false);
  2100. pause_button->set_pressed(false);
  2101. stop_button->set_pressed(false);
  2102. editor_run.stop();
  2103. }
  2104. bool EditorNode::_find_editing_changed_scene(Node *p_from) {
  2105. /*
  2106. if (!p_from)
  2107. return false;
  2108. if (p_from->get_filename()!="") {
  2109. StringName fn = p_from->get_filename();
  2110. for(int i=0;i<import_monitor->get_changes().size();i++) {
  2111. if (fn==import_monitor->get_changes()[i])
  2112. return true;
  2113. }
  2114. }
  2115. for(int i=0;i<p_from->get_child_count();i++) {
  2116. if (_find_editing_changed_scene(p_from->get_child(i)))
  2117. return true;
  2118. }
  2119. */
  2120. return false;
  2121. }
  2122. void EditorNode::add_io_error(const String& p_error) {
  2123. _load_error_notify(singleton,p_error);
  2124. }
  2125. void EditorNode::_load_error_notify(void* p_ud,const String& p_text) {
  2126. EditorNode*en=(EditorNode*)p_ud;
  2127. en->load_errors->set_text(en->load_errors->get_text()+p_text+"\n");
  2128. en->load_error_dialog->popup_centered_ratio(0.5);
  2129. }
  2130. bool EditorNode::_find_scene_in_use(Node* p_node,const String& p_path) const {
  2131. if (p_node->get_filename()==p_path) {
  2132. return true;
  2133. }
  2134. for(int i=0;i<p_node->get_child_count();i++) {
  2135. if (_find_scene_in_use(p_node->get_child(i),p_path)) {
  2136. return true;
  2137. }
  2138. }
  2139. return false;
  2140. }
  2141. bool EditorNode::is_scene_in_use(const String& p_path) {
  2142. Node *es = get_edited_scene();
  2143. if (es)
  2144. return _find_scene_in_use(es,p_path);
  2145. return false;
  2146. }
  2147. void EditorNode::register_editor_types() {
  2148. ObjectTypeDB::register_type<EditorPlugin>();
  2149. ObjectTypeDB::register_type<EditorImportPlugin>();
  2150. ObjectTypeDB::register_type<EditorScenePostImport>();
  2151. ObjectTypeDB::register_type<EditorScript>();
  2152. //ObjectTypeDB::register_type<EditorImporter>();
  2153. // ObjectTypeDB::register_type<EditorPostImport>();
  2154. }
  2155. void EditorNode::unregister_editor_types() {
  2156. _init_callbacks.clear();
  2157. }
  2158. void EditorNode::stop_child_process() {
  2159. _menu_option_confirm(RUN_STOP,false);
  2160. }
  2161. void EditorNode::progress_add_task(const String& p_task,const String& p_label, int p_steps) {
  2162. singleton->progress_dialog->add_task(p_task,p_label,p_steps);
  2163. }
  2164. void EditorNode::progress_task_step(const String& p_task, const String& p_state, int p_step) {
  2165. singleton->progress_dialog->task_step(p_task,p_state,p_step);
  2166. }
  2167. void EditorNode::progress_end_task(const String& p_task) {
  2168. singleton->progress_dialog->end_task(p_task);
  2169. }
  2170. void EditorNode::progress_add_task_bg(const String& p_task,const String& p_label, int p_steps) {
  2171. singleton->progress_hb->add_task(p_task,p_label,p_steps);
  2172. }
  2173. void EditorNode::progress_task_step_bg(const String& p_task, int p_step) {
  2174. singleton->progress_hb->task_step(p_task,p_step);
  2175. }
  2176. void EditorNode::progress_end_task_bg(const String& p_task) {
  2177. singleton->progress_hb->end_task(p_task);
  2178. }
  2179. void EditorNode::_bind_methods() {
  2180. ObjectTypeDB::bind_method("_menu_option",&EditorNode::_menu_option);
  2181. ObjectTypeDB::bind_method("_menu_confirm_current",&EditorNode::_menu_confirm_current);
  2182. ObjectTypeDB::bind_method("_dialog_action",&EditorNode::_dialog_action);
  2183. ObjectTypeDB::bind_method("_resource_selected",&EditorNode::_resource_selected,DEFVAL(""));
  2184. ObjectTypeDB::bind_method("_property_editor_forward",&EditorNode::_property_editor_forward);
  2185. ObjectTypeDB::bind_method("_property_editor_back",&EditorNode::_property_editor_back);
  2186. ObjectTypeDB::bind_method("_editor_select",&EditorNode::_editor_select);
  2187. ObjectTypeDB::bind_method("_node_renamed",&EditorNode::_node_renamed);
  2188. ObjectTypeDB::bind_method("edit_node",&EditorNode::edit_node);
  2189. ObjectTypeDB::bind_method("_imported",&EditorNode::_imported);
  2190. ObjectTypeDB::bind_method("_unhandled_input",&EditorNode::_unhandled_input);
  2191. ObjectTypeDB::bind_method("_get_scene_metadata",&EditorNode::_get_scene_metadata);
  2192. ObjectTypeDB::bind_method("set_edited_scene",&EditorNode::set_edited_scene);
  2193. ObjectTypeDB::bind_method("open_request",&EditorNode::open_request);
  2194. ObjectTypeDB::bind_method("_instance_request",&EditorNode::_instance_request);
  2195. ObjectTypeDB::bind_method("_update_keying",&EditorNode::_update_keying);
  2196. ObjectTypeDB::bind_method("_property_keyed",&EditorNode::_property_keyed);
  2197. ObjectTypeDB::bind_method("_transform_keyed",&EditorNode::_transform_keyed);
  2198. ObjectTypeDB::bind_method("_close_messages",&EditorNode::_close_messages);
  2199. ObjectTypeDB::bind_method("_show_messages",&EditorNode::_show_messages);
  2200. ObjectTypeDB::bind_method("_vp_resized",&EditorNode::_vp_resized);
  2201. ObjectTypeDB::bind_method("_quick_opened",&EditorNode::_quick_opened);
  2202. ObjectTypeDB::bind_method("_quick_run",&EditorNode::_quick_run);
  2203. ObjectTypeDB::bind_method("_import_action",&EditorNode::_import_action);
  2204. //ObjectTypeDB::bind_method("_import",&EditorNode::_import);
  2205. // ObjectTypeDB::bind_method("_import_conflicts_solved",&EditorNode::_import_conflicts_solved);
  2206. ObjectTypeDB::bind_method("_open_recent_scene",&EditorNode::_open_recent_scene);
  2207. ObjectTypeDB::bind_method("_open_recent_scene_confirm",&EditorNode::_open_recent_scene_confirm);
  2208. ObjectTypeDB::bind_method("_save_optimized",&EditorNode::_save_optimized);
  2209. ObjectTypeDB::bind_method(_MD("animation_panel_make_visible","enable"),&EditorNode::animation_panel_make_visible);
  2210. ObjectTypeDB::bind_method("stop_child_process",&EditorNode::stop_child_process);
  2211. ObjectTypeDB::bind_method("_sources_changed",&EditorNode::_sources_changed);
  2212. ObjectTypeDB::bind_method("_fs_changed",&EditorNode::_fs_changed);
  2213. ADD_SIGNAL( MethodInfo("play_pressed") );
  2214. ADD_SIGNAL( MethodInfo("pause_pressed") );
  2215. ADD_SIGNAL( MethodInfo("stop_pressed") );
  2216. ADD_SIGNAL( MethodInfo("hide_animation_player_editors") );
  2217. ADD_SIGNAL( MethodInfo("request_help") );
  2218. ADD_SIGNAL( MethodInfo("script_add_function_request",PropertyInfo(Variant::OBJECT,"obj"),PropertyInfo(Variant::STRING,"function"),PropertyInfo(Variant::STRING_ARRAY,"args")) );
  2219. ADD_SIGNAL( MethodInfo("resource_saved",PropertyInfo(Variant::OBJECT,"obj")) );
  2220. }
  2221. Ref<Texture> EditorNode::_file_dialog_get_icon(const String& p_path) {
  2222. EditorFileSystemDirectory *efsd = EditorFileSystem::get_singleton()->get_path(p_path.get_base_dir());
  2223. if (efsd) {
  2224. String file = p_path.get_file();
  2225. for(int i=0;i<efsd->get_file_count();i++) {
  2226. if (efsd->get_file(i)==file) {
  2227. String type = efsd->get_file_type(i);
  2228. if (singleton->icon_type_cache.has(type)) {
  2229. return singleton->icon_type_cache[type];
  2230. } else {
  2231. return singleton->icon_type_cache["Object"];
  2232. }
  2233. }
  2234. }
  2235. }
  2236. return singleton->icon_type_cache["Object"];
  2237. }
  2238. void EditorNode::_file_dialog_register(FileDialog *p_dialog) {
  2239. singleton->file_dialogs.insert(p_dialog);
  2240. }
  2241. void EditorNode::_file_dialog_unregister(FileDialog *p_dialog){
  2242. singleton->file_dialogs.erase(p_dialog);
  2243. }
  2244. Vector<EditorNodeInitCallback> EditorNode::_init_callbacks;
  2245. Error EditorNode::export_platform(const String& p_platform, const String& p_path, bool p_debug,const String& p_password,bool p_quit_after) {
  2246. export_defer.platform=p_platform;
  2247. export_defer.path=p_path;
  2248. export_defer.debug=p_debug;
  2249. export_defer.password=p_password;
  2250. return OK;
  2251. }
  2252. EditorNode::EditorNode() {
  2253. EditorHelp::generate_doc(); //before any editor classes are crated
  2254. singleton=this;
  2255. FileAccess::set_backup_save(true);
  2256. PathRemap::get_singleton()->clear_remaps();; //editor uses no remaps
  2257. TranslationServer::get_singleton()->set_enabled(false);
  2258. // load settings
  2259. if (!EditorSettings::get_singleton())
  2260. EditorSettings::create();
  2261. ResourceLoader::set_abort_on_missing_resources(false);
  2262. ResourceLoader::set_error_notify_func(this,_load_error_notify);
  2263. ResourceLoader::set_timestamp_on_load(true);
  2264. ResourceSaver::set_timestamp_on_save(true);
  2265. _pvrtc_register_compressors();
  2266. editor_selection = memnew( EditorSelection );
  2267. EditorFileSystem *efs = memnew( EditorFileSystem );
  2268. add_child(efs);
  2269. //used for previews
  2270. FileDialog::get_icon_func=_file_dialog_get_icon;
  2271. FileDialog::register_func=_file_dialog_register;
  2272. FileDialog::unregister_func=_file_dialog_unregister;
  2273. editor_import_export = memnew( EditorImportExport );
  2274. register_exporters();
  2275. editor_import_export->load_config();
  2276. GLOBAL_DEF("editor/main_run_args","$exec -path $path -scene $scene $main_scene");
  2277. ObjectTypeDB::set_type_enabled("CollisionShape",true);
  2278. ObjectTypeDB::set_type_enabled("CollisionShape2D",true);
  2279. ObjectTypeDB::set_type_enabled("CollisionPolygon2D",true);
  2280. //ObjectTypeDB::set_type_enabled("BodyVolumeConvexPolygon",true);
  2281. gui_base = memnew( Panel );
  2282. add_child(gui_base);
  2283. gui_base->set_area_as_parent_rect();
  2284. Ref<Theme> theme( memnew( Theme ) );
  2285. gui_base->set_theme( theme );
  2286. editor_register_icons(theme);
  2287. editor_register_fonts(theme);
  2288. String global_font = EditorSettings::get_singleton()->get("global/font");
  2289. if (global_font!="") {
  2290. Ref<Font> fnt = ResourceLoader::load(global_font);
  2291. if (fnt.is_valid()) {
  2292. theme->set_default_theme_font(fnt);
  2293. }
  2294. }
  2295. Ref<StyleBoxTexture> focus_sbt=memnew( StyleBoxTexture );
  2296. focus_sbt->set_texture(theme->get_icon("EditorFocus","EditorIcons"));
  2297. for(int i=0;i<4;i++) {
  2298. focus_sbt->set_margin_size(Margin(i),16);
  2299. focus_sbt->set_default_margin(Margin(i),16);
  2300. }
  2301. focus_sbt->set_draw_center(false);
  2302. theme->set_stylebox("EditorFocus","EditorStyles",focus_sbt);
  2303. progress_dialog = memnew( ProgressDialog );
  2304. gui_base->add_child(progress_dialog);
  2305. // take up all screen
  2306. gui_base->set_anchor( MARGIN_RIGHT, Control::ANCHOR_END );
  2307. gui_base->set_anchor( MARGIN_BOTTOM, Control::ANCHOR_END );
  2308. gui_base->set_end( Point2(0,0) );
  2309. main_vbox = memnew( VBoxContainer );
  2310. gui_base->add_child(main_vbox);
  2311. main_vbox->set_area_as_parent_rect(8);
  2312. menu_hb = memnew( HBoxContainer );
  2313. main_vbox->add_child(menu_hb);
  2314. main_split = memnew( HSplitContainer );
  2315. main_vbox->add_child(main_split);
  2316. main_split->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  2317. left_split = memnew( VSplitContainer );
  2318. main_split->add_child(left_split);
  2319. left_split->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  2320. left_split->set_collapsed(false);
  2321. top_split = memnew( VSplitContainer );
  2322. left_split->add_child(top_split);
  2323. top_split->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  2324. top_split->set_collapsed(true);
  2325. VBoxContainer *srt = memnew( VBoxContainer );
  2326. srt->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  2327. top_split->add_child(srt);
  2328. srt->add_constant_override("separation",0);
  2329. main_editor_tabs = memnew( Tabs );
  2330. main_editor_tabs->connect("tab_changed",this,"_editor_select");
  2331. HBoxContainer *srth = memnew( HBoxContainer );
  2332. srt->add_child( srth );
  2333. EmptyControl *tec = memnew( EmptyControl );
  2334. tec->set_minsize(Size2(100,0));
  2335. tec->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  2336. srth->add_child(tec);
  2337. srth->add_child(main_editor_tabs);
  2338. tec = memnew( EmptyControl );
  2339. tec->set_minsize(Size2(100,0));
  2340. srth->add_child(tec);
  2341. tec->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  2342. scene_root_parent = memnew( Panel );
  2343. Ref<StyleBox> sp = scene_root_parent->get_stylebox("panel","TabContainer");
  2344. scene_root_parent->add_style_override("panel",sp);
  2345. /*scene_root_parent->set_anchor( MARGIN_RIGHT, Control::ANCHOR_END );
  2346. scene_root_parent->set_anchor( MARGIN_BOTTOM, Control::ANCHOR_END );
  2347. scene_root_parent->set_begin( Point2( 0, 0) );
  2348. scene_root_parent->set_end( Point2( 0,80 ) );*/
  2349. srt->add_child(scene_root_parent);
  2350. scene_root_parent->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  2351. scene_root_base = memnew( Control );
  2352. scene_root_base->set_area_as_parent_rect();
  2353. for(int i=0;i<4;i++) {
  2354. scene_root_base->set_margin(Margin(i),sp->get_margin(Margin(i)));
  2355. }
  2356. scene_root_parent->add_child(scene_root_base);
  2357. scene_root = memnew( Viewport );
  2358. //scene_root_base->add_child(scene_root);
  2359. scene_root->set_meta("_editor_disable_input",true);
  2360. VisualServer::get_singleton()->viewport_set_hide_scenario(scene_root->get_viewport(),true);
  2361. scene_root->set_as_audio_listener_2d(true);
  2362. scene_root->set_size_override(true,Size2(Globals::get_singleton()->get("display/width"),Globals::get_singleton()->get("display/height")));
  2363. // scene_root->set_world_2d( Ref<World2D>( memnew( World2D )) );
  2364. viewport = memnew( Control );
  2365. viewport->set_area_as_parent_rect(4);
  2366. for(int i=0;i<4;i++) {
  2367. viewport->set_margin(Margin(i),sp->get_margin(Margin(i)));
  2368. }
  2369. scene_root_parent->add_child(viewport);
  2370. PanelContainer *pc = memnew( PanelContainer );
  2371. top_split->add_child(pc);
  2372. animation_vb = memnew( VBoxContainer );
  2373. animation_vb->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  2374. pc->add_child(animation_vb);
  2375. animation_panel=pc;
  2376. animation_panel->hide();
  2377. HBoxContainer *animation_hb = memnew( HBoxContainer);
  2378. animation_vb->add_child(animation_hb);
  2379. Label *l= memnew( Label );
  2380. l->set_text("Animation:");
  2381. //l->set_h_size_flags(Control::SIZE_);
  2382. animation_hb->add_child(l);
  2383. animation_panel_hb = memnew( HBoxContainer );
  2384. animation_hb->add_child(animation_panel_hb);
  2385. animation_panel_hb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  2386. /*pd_anim = memnew( PaneDrag );
  2387. animation_hb->add_child(pd_anim);
  2388. pd_anim->connect("dragged",this,"_dragged");
  2389. pd_anim->set_default_cursor_shape(Control::CURSOR_MOVE);
  2390. pd_anim->hide();*/
  2391. anim_close = memnew( TextureButton );
  2392. animation_hb->add_child(anim_close);
  2393. anim_close->connect("pressed",this,"animation_panel_make_visible",make_binds(false));
  2394. anim_close->set_normal_texture( anim_close->get_icon("Close","EditorIcons"));
  2395. anim_close->set_hover_texture( anim_close->get_icon("CloseHover","EditorIcons"));
  2396. anim_close->set_pressed_texture( anim_close->get_icon("Close","EditorIcons"));
  2397. PanelContainer *top_region = memnew( PanelContainer );
  2398. top_region->add_style_override("panel",gui_base->get_stylebox("hover","Button"));
  2399. HBoxContainer *left_menu_hb = memnew( HBoxContainer );
  2400. top_region->add_child(left_menu_hb);
  2401. menu_hb->add_child(top_region);
  2402. PopupMenu *p;
  2403. file_menu = memnew( MenuButton );
  2404. file_menu->set_text("Scene");
  2405. //file_menu->set_icon(gui_base->get_icon("Save","EditorIcons"));
  2406. left_menu_hb->add_child( file_menu );
  2407. prev_scene = memnew( ToolButton );
  2408. prev_scene->set_icon(gui_base->get_icon("PrevScene","EditorIcons"));
  2409. prev_scene->set_tooltip("Go to previously opened scene.");
  2410. prev_scene->set_disabled(true);
  2411. //left_menu_hb->add_child( prev_scene );
  2412. prev_scene->connect("pressed",this,"_menu_option",make_binds(FILE_OPEN_PREV));
  2413. //gui_base->add_child(prev_scene);
  2414. prev_scene->set_pos(Point2(3,24));
  2415. Separator *vs=NULL;
  2416. file_menu->set_tooltip("Operations with scene files.");
  2417. p=file_menu->get_popup();
  2418. p->add_item("New Scene",FILE_NEW_SCENE);
  2419. p->add_item("Open Scene..",FILE_OPEN_SCENE,KEY_MASK_CMD+KEY_O);
  2420. p->add_item("Save Scene",FILE_SAVE_SCENE,KEY_MASK_CMD+KEY_S);
  2421. p->add_item("Save Scene As..",FILE_SAVE_AS_SCENE);
  2422. p->add_separator();
  2423. p->add_item("Goto Prev. Scene",FILE_OPEN_PREV,KEY_MASK_SHIFT+KEY_MASK_CMD+KEY_P);
  2424. p->add_submenu_item("Open Recent","RecentScenes",FILE_OPEN_RECENT);
  2425. p->add_separator();
  2426. p->add_item("Quick Open Scene..",FILE_QUICK_OPEN_SCENE,KEY_MASK_SHIFT+KEY_MASK_CMD+KEY_O);
  2427. p->add_item("Quick Open Script..",FILE_QUICK_OPEN_SCRIPT,KEY_MASK_ALT+KEY_MASK_CMD+KEY_O);
  2428. p->add_separator();
  2429. PopupMenu *pm_export = memnew(PopupMenu );
  2430. pm_export->set_name("Export");
  2431. p->add_child(pm_export);
  2432. p->add_submenu_item("Convert To..","Export");
  2433. pm_export->add_item("Subscene..",FILE_SAVE_SUBSCENE);
  2434. pm_export->add_item("Translatable Strings..",FILE_DUMP_STRINGS);
  2435. pm_export->add_separator();
  2436. pm_export->add_item("MeshLibrary..",FILE_EXPORT_MESH_LIBRARY);
  2437. pm_export->add_item("TileSet..",FILE_EXPORT_TILESET);
  2438. pm_export->connect("item_pressed",this,"_menu_option");
  2439. p->add_separator();
  2440. p->add_item("Undo",EDIT_UNDO,KEY_MASK_CMD+KEY_Z);
  2441. p->add_item("Redo",EDIT_REDO,KEY_MASK_CMD+KEY_MASK_SHIFT+KEY_Z);
  2442. p->add_separator();
  2443. p->add_item("Run Script",FILE_RUN_SCRIPT,KEY_MASK_SHIFT+KEY_MASK_CMD+KEY_R);
  2444. p->add_separator();
  2445. p->add_item("Project Settings",RUN_SETTINGS);
  2446. p->add_separator();
  2447. p->add_item("Quit to Project List",RUN_PROJECT_MANAGER,KEY_MASK_SHIFT+KEY_MASK_CMD+KEY_Q);
  2448. p->add_item("Quit",FILE_QUIT,KEY_MASK_CMD+KEY_Q);
  2449. recent_scenes = memnew( PopupMenu );
  2450. recent_scenes->set_name("RecentScenes");
  2451. p->add_child(recent_scenes);
  2452. recent_scenes->connect("item_pressed",this,"_open_recent_scene");
  2453. //menu_hb->add_spacer();
  2454. #if 0
  2455. node_menu = memnew( MenuButton );
  2456. node_menu->set_text("Node");
  2457. node_menu->set_pos( Point2( 50,0) );;
  2458. menu_panel->add_child( node_menu );
  2459. p=node_menu->get_popup();
  2460. p->add_item("Create",NODE_CREATE);
  2461. p->add_item("Instance",NODE_INSTANCE);
  2462. p->add_separator();
  2463. p->add_item("Reparent",NODE_REPARENT);
  2464. p->add_item("Move Up",NODE_MOVE_UP);
  2465. p->add_item("Move Down",NODE_MOVE_DOWN);
  2466. p->add_separator();
  2467. p->add_item("Duplicate",NODE_DUPLICATE);
  2468. p->add_separator();
  2469. p->add_item("Remove (Branch)",NODE_REMOVE_BRANCH);
  2470. p->add_item("Remove (Element)",NODE_REMOVE_ELEMENT);
  2471. p->add_separator();
  2472. p->add_item("Edit Subscriptions..",NODE_CONNECTIONS);
  2473. p->add_item("Edit Groups..",NODE_GROUPS);
  2474. resource_menu = memnew( MenuButton );
  2475. resource_menu->set_text("Resource");
  2476. resource_menu->set_pos( Point2( 90,0) );
  2477. menu_panel->add_child( resource_menu );
  2478. #endif
  2479. import_menu = memnew( MenuButton );
  2480. import_menu->set_tooltip("Import assets to the project.");
  2481. import_menu->set_text("Import");
  2482. //import_menu->set_icon(gui_base->get_icon("Save","EditorIcons"));
  2483. left_menu_hb->add_child( import_menu );
  2484. p=import_menu->get_popup();
  2485. p->add_item("Sub-Scene",FILE_IMPORT_SUBSCENE);
  2486. #ifdef OLD_SCENE_FORMAT_ENABLED
  2487. p->add_item("Import Old Scene",FILE_OPEN_OLD_SCENE);
  2488. #endif
  2489. p->add_separator();
  2490. p->connect("item_pressed",this,"_menu_option");
  2491. export_button = memnew( ToolButton );
  2492. export_button->set_tooltip("Export the project to many platforms.");
  2493. export_button->set_text("Export");
  2494. export_button->connect("pressed",this,"_menu_option",varray(FILE_EXPORT_PROJECT));
  2495. export_button->set_focus_mode(Control::FOCUS_NONE);
  2496. left_menu_hb->add_child(export_button);
  2497. menu_hb->add_spacer();
  2498. //Separator *s1 = memnew( VSeparator );
  2499. //menu_panel->add_child(s1);
  2500. //s1->set_pos(Point2(210,4));
  2501. //s1->set_size(Point2(10,15));
  2502. CenterContainer *play_cc = memnew( CenterContainer );
  2503. play_cc->set_ignore_mouse(true);
  2504. gui_base->add_child( play_cc );
  2505. play_cc->set_area_as_parent_rect();
  2506. play_cc->set_anchor_and_margin(MARGIN_BOTTOM,Control::ANCHOR_BEGIN,10);
  2507. play_cc->set_margin(MARGIN_TOP,5);
  2508. top_region = memnew( PanelContainer );
  2509. top_region->add_style_override("panel",gui_base->get_stylebox("hover","Button"));
  2510. play_cc->add_child(top_region);
  2511. HBoxContainer *play_hb = memnew( HBoxContainer );
  2512. top_region->add_child(play_hb);
  2513. play_button = memnew( ToolButton );
  2514. play_hb->add_child(play_button);
  2515. play_button->set_toggle_mode(true);
  2516. play_button->set_icon(gui_base->get_icon("MainPlay","EditorIcons"));
  2517. play_button->set_focus_mode(Control::FOCUS_NONE);
  2518. play_button->connect("pressed", this,"_menu_option",make_binds(RUN_PLAY));
  2519. play_button->set_tooltip("Start the scene (F5).");
  2520. pause_button = memnew( ToolButton );
  2521. //menu_panel->add_child(pause_button); - not needed for now?
  2522. pause_button->set_toggle_mode(true);
  2523. pause_button->set_icon(gui_base->get_icon("Pause","EditorIcons"));
  2524. pause_button->set_focus_mode(Control::FOCUS_NONE);
  2525. pause_button->connect("pressed", this,"_menu_option",make_binds(RUN_PAUSE));
  2526. pause_button->set_tooltip("Pause the scene (F7).");
  2527. stop_button = memnew( ToolButton );
  2528. play_hb->add_child(stop_button);
  2529. //stop_button->set_toggle_mode(true);
  2530. stop_button->set_focus_mode(Control::FOCUS_NONE);
  2531. stop_button->set_icon(gui_base->get_icon("MainStop","EditorIcons"));
  2532. stop_button->connect("pressed", this,"_menu_option",make_binds(RUN_STOP));
  2533. stop_button->set_tooltip("Stop the scene (F8).");
  2534. run_native = memnew( EditorRunNative);
  2535. play_hb->add_child(run_native);
  2536. native_play_button = memnew( MenuButton );
  2537. native_play_button->set_text("NTV");
  2538. menu_hb->add_child(native_play_button);
  2539. native_play_button->hide();
  2540. native_play_button->get_popup()->connect("item_pressed",this,"_run_in_device");
  2541. VSeparator *s1 = memnew( VSeparator );
  2542. // play_hb->add_child(s1);
  2543. play_scene_button = memnew( ToolButton );
  2544. play_hb->add_child(play_scene_button);
  2545. play_scene_button->set_toggle_mode(true);
  2546. play_scene_button->set_focus_mode(Control::FOCUS_NONE);
  2547. play_scene_button->set_icon(gui_base->get_icon("PlayScene","EditorIcons"));
  2548. play_scene_button->connect("pressed", this,"_menu_option",make_binds(RUN_PLAY_SCENE));
  2549. play_scene_button->set_tooltip("Play the edited scene (F6).");
  2550. play_custom_scene_button = memnew( ToolButton );
  2551. play_hb->add_child(play_custom_scene_button);
  2552. play_custom_scene_button->set_toggle_mode(true);
  2553. play_custom_scene_button->set_focus_mode(Control::FOCUS_NONE);
  2554. play_custom_scene_button->set_icon(gui_base->get_icon("PlayCustom","EditorIcons"));
  2555. play_custom_scene_button->connect("pressed", this,"_menu_option",make_binds(RUN_PLAY_CUSTOM_SCENE));
  2556. play_custom_scene_button->set_tooltip("Play custom scene ("+keycode_get_string(KEY_MASK_CMD|KEY_MASK_SHIFT|KEY_F5)+").");
  2557. fileserver_menu = memnew( MenuButton );
  2558. play_hb->add_child(fileserver_menu);
  2559. fileserver_menu->set_flat(true);
  2560. fileserver_menu->set_focus_mode(Control::FOCUS_NONE);
  2561. fileserver_menu->set_icon(gui_base->get_icon("FileServer","EditorIcons"));
  2562. //fileserver_menu->connect("pressed", this,"_menu_option",make_binds(RUN_PLAY_CUSTOM_SCENE));
  2563. fileserver_menu->set_tooltip("Serve the project filesystem to remote clients.");
  2564. p=fileserver_menu->get_popup();
  2565. p->add_check_item("Enable File Server",RUN_FILE_SERVER);
  2566. p->set_item_tooltip(p->get_item_index(RUN_FILE_SERVER),"Enable/Disable the File Server.");
  2567. p->add_separator();
  2568. p->add_check_item("Deploy Dumb Clients",RUN_DEPLOY_DUMB_CLIENTS);
  2569. //p->set_item_checked( p->get_item_index(RUN_DEPLOY_DUMB_CLIENTS),true );
  2570. p->set_item_tooltip(p->get_item_index(RUN_DEPLOY_DUMB_CLIENTS),"Deploy dumb clients when the File Server is active.");
  2571. p->connect("item_pressed",this,"_menu_option");
  2572. run_settings_button = memnew( ToolButton );
  2573. //menu_hb->add_child(run_settings_button);
  2574. //run_settings_button->set_toggle_mode(true);
  2575. run_settings_button->set_focus_mode(Control::FOCUS_NONE);
  2576. run_settings_button->set_icon(gui_base->get_icon("Run","EditorIcons"));
  2577. run_settings_button->connect("pressed", this,"_menu_option",make_binds(RUN_SCENE_SETTINGS));
  2578. /*
  2579. run_settings_button = memnew( ToolButton );
  2580. menu_panel->add_child(run_settings_button);
  2581. run_settings_button->set_pos(Point2(305,0));
  2582. run_settings_button->set_focus_mode(Control::FOCUS_NONE);
  2583. run_settings_button->set_icon(gui_base->get_icon("Run","EditorIcons"));
  2584. run_settings_button->connect("pressed", this,"_menu_option",make_binds(RUN_SETTINGS));
  2585. */
  2586. top_region = memnew( PanelContainer );
  2587. top_region->add_style_override("panel",gui_base->get_stylebox("hover","Button"));
  2588. HBoxContainer *right_menu_hb = memnew( HBoxContainer );
  2589. top_region->add_child(right_menu_hb);
  2590. menu_hb->add_child(top_region);
  2591. settings_menu = memnew( MenuButton );
  2592. settings_menu->set_text("Settings");
  2593. //settings_menu->set_anchor(MARGIN_RIGHT,ANCHOR_END);
  2594. right_menu_hb->add_child( settings_menu );
  2595. p=settings_menu->get_popup();
  2596. //p->add_item("Export Settings",SETTINGS_EXPORT_PREFERENCES);
  2597. p->add_item("Editor Settings",SETTINGS_PREFERENCES);
  2598. //p->add_item("Optimization Presets",SETTINGS_OPTIMIZED_PRESETS);
  2599. p->add_separator();
  2600. p->add_check_item("Show Animation",SETTINGS_SHOW_ANIMATION,KEY_MASK_CMD+KEY_N);
  2601. p->add_separator();
  2602. p->add_item("Install Export Templates",SETTINGS_LOAD_EXPORT_TEMPLATES);
  2603. p->add_separator();
  2604. p->add_item("About",SETTINGS_ABOUT);
  2605. sources_button = memnew( ToolButton );
  2606. right_menu_hb->add_child(sources_button);
  2607. sources_button->set_icon(gui_base->get_icon("DependencyOk","EditorIcons"));
  2608. sources_button->connect("pressed",this,"_menu_option",varray(SOURCES_REIMPORT));
  2609. sources_button->set_tooltip("Alerts when an external resource has changed.");
  2610. //sources_button->connect();
  2611. /*
  2612. Separator *s2 = memnew( VSeparator );
  2613. menu_panel->add_child(s2);
  2614. s2->set_pos(Point2(338,4));
  2615. s2->set_size(Point2(10,15));
  2616. */
  2617. editor_hsplit = memnew( HSplitContainer );
  2618. main_split->add_child(editor_hsplit);
  2619. editor_hsplit->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  2620. editor_vsplit = memnew( VSplitContainer );
  2621. editor_hsplit->add_child(editor_vsplit);
  2622. top_pallete = memnew( TabContainer );
  2623. scene_tree_dock = memnew( SceneTreeDock(this,scene_root,editor_selection,editor_data) );
  2624. scene_tree_dock->set_name("Scene");
  2625. top_pallete->add_child(scene_tree_dock);
  2626. resources_dock = memnew( ResourcesDock(this) );
  2627. resources_dock->set_name("Resources");
  2628. top_pallete->add_child(resources_dock);
  2629. top_pallete->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  2630. EmptyControl *editor_spacer = memnew( EmptyControl );
  2631. editor_spacer->set_minsize(Size2(260,200));
  2632. editor_spacer->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  2633. editor_vsplit->add_child( editor_spacer );
  2634. editor_spacer->add_child( top_pallete );
  2635. top_pallete->set_area_as_parent_rect();
  2636. prop_pallete = memnew( TabContainer );
  2637. prop_pallete->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  2638. editor_spacer = memnew( EmptyControl );
  2639. editor_spacer->set_minsize(Size2(260,200));
  2640. editor_spacer->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  2641. editor_vsplit->add_child( editor_spacer );
  2642. editor_spacer->add_child( prop_pallete );
  2643. prop_pallete->set_area_as_parent_rect();
  2644. VBoxContainer *prop_editor_base = memnew( VBoxContainer );
  2645. prop_editor_base->set_name("Inspector"); // Properties?
  2646. prop_pallete->add_child(prop_editor_base);
  2647. HBoxContainer *prop_editor_hb = memnew( HBoxContainer );
  2648. prop_editor_base->add_child(prop_editor_hb);
  2649. editor_path = memnew( EditorPath(&editor_history) );
  2650. editor_path->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  2651. prop_editor_hb->add_child(editor_path);
  2652. property_editor = memnew( PropertyEditor );
  2653. property_editor->set_autoclear(true);
  2654. property_editor->set_show_categories(true);
  2655. property_editor->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  2656. property_editor->hide_top_label();
  2657. prop_editor_base->add_child( property_editor );
  2658. property_editor->set_undo_redo(&editor_data.get_undo_redo());
  2659. property_back = memnew( ToolButton );
  2660. property_back->set_icon( gui_base->get_icon("Back","EditorIcons") );
  2661. property_back->set_flat(true);
  2662. property_back->set_tooltip("Go to the previous edited object in history.");
  2663. prop_editor_hb->add_child( property_back );
  2664. property_forward = memnew( ToolButton );
  2665. property_forward->set_icon( gui_base->get_icon("Forward","EditorIcons") );
  2666. property_forward->set_flat(true);
  2667. property_forward->set_tooltip("Go to the next edited object in history.");
  2668. prop_editor_hb->add_child( property_forward );
  2669. object_menu = memnew( MenuButton );
  2670. object_menu->set_icon(gui_base->get_icon("Tools","EditorIcons"));
  2671. prop_editor_hb->add_child( object_menu );
  2672. object_menu->set_tooltip("Object properties.");
  2673. scenes_dock = memnew( ScenesDock(this) );
  2674. scenes_dock->set_name("FileSystem");
  2675. prop_pallete->add_child(scenes_dock);
  2676. scenes_dock->connect("open",this,"open_request");
  2677. scenes_dock->connect("instance",this,"_instance_request");
  2678. log = memnew( EditorLog );
  2679. left_split->add_child(log);
  2680. log->connect("close_request",this,"_close_messages");
  2681. log->connect("show_request",this,"_show_messages");
  2682. //left_split->set_dragger_visible(false);
  2683. old_split_ofs=0;
  2684. animation_editor = memnew( AnimationKeyEditor(get_undo_redo(),&editor_history,editor_selection) );
  2685. animation_editor->set_anchor_and_margin(MARGIN_RIGHT,Control::ANCHOR_END,0);
  2686. animation_editor->set_margin(MARGIN_BOTTOM,200);
  2687. animation_editor->connect("keying_changed",this,"_update_keying");
  2688. animation_editor->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  2689. animation_vb->add_child(animation_editor);
  2690. left_split->connect("resized",this,"_vp_resized");
  2691. animation_editor->hide();
  2692. PanelContainer *bottom_pc = memnew( PanelContainer );
  2693. main_vbox->add_child(bottom_pc);
  2694. bottom_hb = memnew( HBoxContainer );
  2695. bottom_pc->add_child(bottom_hb);
  2696. bottom_hb->add_child( log->get_button() );
  2697. log->get_button()->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  2698. progress_hb = memnew( BackgroundProgress );
  2699. bottom_hb->add_child(progress_hb);
  2700. //progress_hb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  2701. audio_vu = memnew( TextureProgress );
  2702. CenterContainer *vu_cc = memnew( CenterContainer );
  2703. vu_cc->add_child(audio_vu);
  2704. bottom_hb->add_child(vu_cc);
  2705. audio_vu->set_under_texture(gui_base->get_icon("VuEmpty","EditorIcons"));
  2706. audio_vu->set_progress_texture(gui_base->get_icon("VuFull","EditorIcons"));
  2707. audio_vu->set_max(24);
  2708. audio_vu->set_min(-80);
  2709. audio_vu->set_step(0.01);
  2710. audio_vu->set_val(0);
  2711. update_menu = memnew( MenuButton );
  2712. update_menu->set_tooltip("Spins when the editor window repaints!");
  2713. bottom_hb->add_child(update_menu);
  2714. update_menu->set_icon(gui_base->get_icon("Progress1","EditorIcons"));
  2715. p=update_menu->get_popup();
  2716. p->add_check_item("Update Always",SETTINGS_UPDATE_ALWAYS);
  2717. p->add_check_item("Update Changes",SETTINGS_UPDATE_CHANGES);
  2718. p->set_item_checked(1,true);
  2719. /*
  2720. animation_menu = memnew( ToolButton );
  2721. animation_menu->set_pos(Point2(500,0));
  2722. animation_menu->set_size(Size2(20,20));
  2723. animation_menu->set_toggle_mode(true);
  2724. animation_menu->set_focus_mode(Control::FOCUS_NONE);
  2725. menu_panel->add_child(animation_menu);
  2726. animation_menu->set_icon(gui_base->get_icon("Animation","EditorIcons"));
  2727. animation_menu->connect("pressed",this,"_animation_visibility_toggle");;
  2728. */
  2729. call_dialog = memnew( CallDialog );
  2730. call_dialog->hide();
  2731. gui_base->add_child( call_dialog );
  2732. confirmation = memnew( ConfirmationDialog );
  2733. gui_base->add_child(confirmation);
  2734. confirmation->connect("confirmed", this,"_menu_confirm_current");
  2735. accept = memnew( AcceptDialog );
  2736. gui_base->add_child(accept);
  2737. accept->connect("confirmed", this,"_menu_confirm_current");
  2738. // optimized_save = memnew( OptimizedSaveDialog(&editor_data) );
  2739. //gui_base->add_child(optimized_save);
  2740. //optimized_save->connect("confirmed",this,"_save_optimized");
  2741. project_export = memnew( ProjectExport(&editor_data) );
  2742. gui_base->add_child(project_export);
  2743. project_export_settings = memnew( ProjectExportDialog(this) );
  2744. gui_base->add_child(project_export_settings);
  2745. //optimized_presets = memnew( OptimizedPresetsDialog(&editor_data) );
  2746. //gui_base->add_child(optimized_presets);
  2747. //optimized_presets->connect("confirmed",this,"_presets_optimized");
  2748. //import_subscene = memnew( EditorSubScene );
  2749. //gui_base->add_child(import_subscene);
  2750. settings_config_dialog = memnew( EditorSettingsDialog );
  2751. gui_base->add_child(settings_config_dialog);
  2752. project_settings = memnew( ProjectSettings(&editor_data) );
  2753. gui_base->add_child(project_settings);
  2754. import_confirmation = memnew( ConfirmationDialog );
  2755. import_confirmation->get_ok()->set_text("Re-Import");
  2756. import_confirmation->add_button("Update",!OS::get_singleton()->get_swap_ok_cancel(),"update");
  2757. import_confirmation->get_label()->set_align(Label::ALIGN_CENTER);
  2758. import_confirmation->connect("confirmed",this,"_import_action",make_binds("re-import"));
  2759. import_confirmation->connect("custom_action",this,"_import_action");
  2760. gui_base->add_child(import_confirmation);
  2761. open_recent_confirmation = memnew( ConfirmationDialog );
  2762. add_child(open_recent_confirmation);
  2763. open_recent_confirmation->connect("confirmed",this,"_open_recent_scene_confirm");
  2764. import_settings= memnew(ImportSettingsDialog(this));
  2765. gui_base->add_child(import_settings);
  2766. run_settings_dialog = memnew( RunSettingsDialog );
  2767. gui_base->add_child( run_settings_dialog );
  2768. about = memnew( AcceptDialog );
  2769. about->set_title("Thanks so Much!");
  2770. //about->get_cancel()->hide();
  2771. about->get_ok()->set_text("Thanks!");
  2772. about->set_hide_on_ok(true);
  2773. Label *about_text = memnew( Label );
  2774. about_text->set_text(VERSION_FULL_NAME"\n(c) 2008-2014 Juan Linietsky, Ariel Manzur.\n");
  2775. about_text->set_pos(Point2(gui_base->get_icon("Logo","EditorIcons")->get_size().width+30,20));
  2776. gui_base->add_child(about);
  2777. about->add_child(about_text);
  2778. TextureFrame *logo = memnew( TextureFrame );
  2779. about->add_child(logo);
  2780. logo->set_pos(Point2(20,20));
  2781. logo->set_texture(gui_base->get_icon("Logo","EditorIcons") );
  2782. file_templates = memnew( FileDialog );
  2783. file_templates->set_title("Import Templates from ZIP file");
  2784. gui_base->add_child( file_templates );
  2785. file_templates->set_mode(FileDialog::MODE_OPEN_FILE);
  2786. file_templates->set_access(FileDialog::ACCESS_FILESYSTEM);
  2787. file_templates->clear_filters();
  2788. file_templates->add_filter("*.tpz ; Template Package");
  2789. file = memnew( FileDialog );
  2790. gui_base->add_child(file);
  2791. file->set_current_dir("res://");
  2792. file_export = memnew( FileDialog );
  2793. file_export->set_access(FileDialog::ACCESS_FILESYSTEM);
  2794. gui_base->add_child(file_export);
  2795. file_export->set_title("Export Project");
  2796. file_export->connect("file_selected", this,"_dialog_action");
  2797. file_export_lib = memnew( FileDialog );
  2798. file_export_lib->set_title("Export Library");
  2799. file_export_lib->set_mode(FileDialog::MODE_SAVE_FILE);
  2800. file_export_lib->connect("file_selected", this,"_dialog_action");
  2801. file_export_lib_merge = memnew( CheckButton );
  2802. file_export_lib_merge->set_text("Merge With Existing");
  2803. file_export_lib_merge->set_pressed(true);
  2804. file_export_lib->get_vbox()->add_child(file_export_lib_merge);
  2805. gui_base->add_child(file_export_lib);
  2806. file_export_check = memnew( CheckButton );
  2807. file_export_check->set_text("Enable Debugging");
  2808. file_export_check->set_pressed(true);
  2809. file_export_check->connect("pressed",this,"_export_debug_toggled");
  2810. file_export->get_vbox()->add_margin_child("Debug:",file_export_check);
  2811. file_export_password = memnew( LineEdit );
  2812. file_export_password->set_secret(true);
  2813. file_export_password->set_editable(false);
  2814. file_export->get_vbox()->add_margin_child("Password:",file_export_password);
  2815. file_script = memnew( FileDialog );
  2816. file_script->set_title("Open & Run a Script");
  2817. file_script->set_access(FileDialog::ACCESS_FILESYSTEM);
  2818. file_script->set_mode(FileDialog::MODE_OPEN_FILE);
  2819. List<String> sexts;
  2820. ResourceLoader::get_recognized_extensions_for_type("Script",&sexts);
  2821. for (List<String>::Element*E=sexts.front();E;E=E->next()) {
  2822. file_script->add_filter("*."+E->get());
  2823. }
  2824. gui_base->add_child(file_script);
  2825. file_script->connect("file_selected",this,"_dialog_action");
  2826. reimport_dialog = memnew( EditorReImportDialog );
  2827. gui_base->add_child(reimport_dialog);
  2828. property_forward->connect("pressed", this,"_property_editor_forward");
  2829. property_back->connect("pressed", this,"_property_editor_back");
  2830. file_menu->get_popup()->connect("item_pressed", this,"_menu_option");
  2831. object_menu->get_popup()->connect("item_pressed", this,"_menu_option");
  2832. update_menu->get_popup()->connect("item_pressed", this,"_menu_option");
  2833. settings_menu->get_popup()->connect("item_pressed", this,"_menu_option");
  2834. file->connect("file_selected", this,"_dialog_action");
  2835. file_templates->connect("file_selected", this,"_dialog_action");
  2836. property_editor->connect("resource_selected", this,"_resource_selected");
  2837. property_editor->connect("property_keyed", this,"_property_keyed");
  2838. animation_editor->connect("resource_selected", this,"_resource_selected");
  2839. //plugin stuff
  2840. file_server = memnew( EditorFileServer );
  2841. editor_import_export->add_import_plugin( Ref<EditorTextureImportPlugin>( memnew(EditorTextureImportPlugin(this,EditorTextureImportPlugin::MODE_TEXTURE_2D) )));
  2842. editor_import_export->add_import_plugin( Ref<EditorTextureImportPlugin>( memnew(EditorTextureImportPlugin(this,EditorTextureImportPlugin::MODE_TEXTURE_3D) )));
  2843. editor_import_export->add_import_plugin( Ref<EditorTextureImportPlugin>( memnew(EditorTextureImportPlugin(this,EditorTextureImportPlugin::MODE_ATLAS) )));
  2844. Ref<EditorSceneImportPlugin> _scene_import = memnew(EditorSceneImportPlugin(this) );
  2845. Ref<EditorSceneImporterCollada> _collada_import = memnew( EditorSceneImporterCollada);
  2846. _scene_import->add_importer(_collada_import);
  2847. Ref<EditorSceneImporterFBXConv> _fbxconv_import = memnew( EditorSceneImporterFBXConv);
  2848. _scene_import->add_importer(_fbxconv_import);
  2849. editor_import_export->add_import_plugin( _scene_import);
  2850. editor_import_export->add_import_plugin( Ref<EditorSceneAnimationImportPlugin>( memnew(EditorSceneAnimationImportPlugin(this))));
  2851. editor_import_export->add_import_plugin( Ref<EditorMeshImportPlugin>( memnew(EditorMeshImportPlugin(this))));
  2852. editor_import_export->add_import_plugin( Ref<EditorFontImportPlugin>( memnew(EditorFontImportPlugin(this))));
  2853. editor_import_export->add_import_plugin( Ref<EditorSampleImportPlugin>( memnew(EditorSampleImportPlugin(this))));
  2854. editor_import_export->add_import_plugin( Ref<EditorTranslationImportPlugin>( memnew(EditorTranslationImportPlugin(this))));
  2855. for(int i=0;i<editor_import_export->get_import_plugin_count();i++) {
  2856. import_menu->get_popup()->add_item(editor_import_export->get_import_plugin(i)->get_visible_name(),IMPORT_PLUGIN_BASE+i);
  2857. }
  2858. editor_import_export->add_export_plugin( Ref<EditorTextureExportPlugin>( memnew(EditorTextureExportPlugin)));
  2859. add_editor_plugin( memnew( CanvasItemEditorPlugin(this) ) );
  2860. add_editor_plugin( memnew( SpatialEditorPlugin(this) ) );
  2861. add_editor_plugin( memnew( ScriptEditorPlugin(this) ) );
  2862. add_editor_plugin( memnew( EditorHelpPlugin(this) ) );
  2863. add_editor_plugin( memnew( AnimationPlayerEditorPlugin(this) ) );
  2864. add_editor_plugin( memnew( ShaderEditorPlugin(this) ) );
  2865. add_editor_plugin( memnew( CameraEditorPlugin(this) ) );
  2866. add_editor_plugin( memnew( SampleEditorPlugin(this) ) );
  2867. add_editor_plugin( memnew( SampleLibraryEditorPlugin(this) ) );
  2868. add_editor_plugin( memnew( ThemeEditorPlugin(this) ) );
  2869. add_editor_plugin( memnew( MultiMeshEditorPlugin(this) ) );
  2870. add_editor_plugin( memnew( AnimationTreeEditorPlugin(this) ) );
  2871. add_editor_plugin( memnew( SamplePlayerEditorPlugin(this) ) );
  2872. add_editor_plugin( memnew( MeshLibraryEditorPlugin(this) ) );
  2873. add_editor_plugin( memnew( StreamEditorPlugin(this) ) );
  2874. add_editor_plugin( memnew( StyleBoxEditorPlugin(this) ) );
  2875. add_editor_plugin( memnew( ParticlesEditorPlugin(this) ) );
  2876. add_editor_plugin( memnew( ResourcePreloaderEditorPlugin(this) ) );
  2877. add_editor_plugin( memnew( ItemListEditorPlugin(this) ) );
  2878. add_editor_plugin( memnew( RichTextEditorPlugin(this) ) );
  2879. add_editor_plugin( memnew( CollisionPolygonEditorPlugin(this) ) );
  2880. add_editor_plugin( memnew( TileSetEditorPlugin(this) ) );
  2881. add_editor_plugin( memnew( TileMapEditorPlugin(this) ) );
  2882. add_editor_plugin( memnew( SpriteFramesEditorPlugin(this) ) );
  2883. add_editor_plugin( memnew( Particles2DEditorPlugin(this) ) );
  2884. add_editor_plugin( memnew( Path2DEditorPlugin(this) ) );
  2885. add_editor_plugin( memnew( PathEditorPlugin(this) ) );
  2886. add_editor_plugin( memnew( BakedLightEditorPlugin(this) ) );
  2887. add_editor_plugin( memnew( Polygon2DEditorPlugin(this) ) );
  2888. for(int i=0;i<EditorPlugins::get_plugin_count();i++)
  2889. add_editor_plugin( EditorPlugins::create(i,this) );
  2890. circle_step_msec=OS::get_singleton()->get_ticks_msec();
  2891. circle_step_frame=OS::get_singleton()->get_frames_drawn();;
  2892. circle_step=0;
  2893. import_menu->get_popup()->add_separator();
  2894. import_menu->get_popup()->add_item("Re-Import..",SETTINGS_IMPORT);
  2895. editor_plugin_screen=NULL;
  2896. editor_plugin_over=NULL;
  2897. // force_top_viewport(true);
  2898. _edit_current();
  2899. current=NULL;
  2900. PhysicsServer::get_singleton()->set_active(false); // no physics by default if editor
  2901. Physics2DServer::get_singleton()->set_active(false); // no physics by default if editor
  2902. ScriptServer::set_scripting_enabled(false); // no scripting by default if editor
  2903. Globals::get_singleton()->set("debug/indicators_enabled",true);
  2904. Globals::get_singleton()->set("render/room_cull_enabled",false);
  2905. theme->set_color("prop_category","Editor",Color::hex(0x3f3945ff));
  2906. theme->set_color("prop_section","Editor",Color::hex(0x38323dff));
  2907. theme->set_color("prop_subsection","Editor",Color::hex(0x342e39ff));
  2908. theme->set_color("fg_selected","Editor",Color::html("ffbd8e8e"));
  2909. theme->set_color("fg_error","Editor",Color::html("ffbd8e8e"));
  2910. reference_resource_mem=true;
  2911. save_external_resources_mem=true;
  2912. set_process(true);
  2913. OS::get_singleton()->set_low_processor_usage_mode(true);
  2914. if (0) { //not sure if i want this to happen after all
  2915. //store project name in ssettings
  2916. String project_name;
  2917. //figure it out from path
  2918. project_name=Globals::get_singleton()->get_resource_path().replace("\\","/");
  2919. print_line("path: "+project_name);
  2920. if (project_name.length() && project_name[project_name.length()-1]=='/')
  2921. project_name=project_name.substr(0,project_name.length()-1);
  2922. project_name=project_name.replace("/","::");
  2923. if (project_name!="") {
  2924. EditorSettings::get_singleton()->set("projects/"+project_name,Globals::get_singleton()->get_resource_path());
  2925. EditorSettings::get_singleton()->raise_order("projects/"+project_name);
  2926. EditorSettings::get_singleton()->save();
  2927. }
  2928. }
  2929. edited_scene=NULL;
  2930. saved_version=0;
  2931. unsaved_cache=true;
  2932. _last_instanced_scene=NULL;
  2933. quick_open = memnew( EditorQuickOpen );
  2934. gui_base->add_child(quick_open);
  2935. quick_open->connect("quick_open",this,"_quick_opened");
  2936. quick_run = memnew( EditorQuickOpen );
  2937. gui_base->add_child(quick_run);
  2938. quick_run->connect("quick_open",this,"_quick_run");
  2939. _update_recent_scenes();
  2940. editor_data.restore_editor_global_states();
  2941. convert_old=false;
  2942. opening_prev=false;
  2943. set_process_unhandled_input(true);
  2944. _playing_edited=false;
  2945. load_errors = memnew( TextEdit );
  2946. load_errors->set_readonly(true);
  2947. load_error_dialog = memnew( AcceptDialog );
  2948. load_error_dialog->add_child(load_errors);
  2949. load_error_dialog->set_title("Load Errors");
  2950. load_error_dialog->set_child_rect(load_errors);
  2951. add_child(load_error_dialog);
  2952. //EditorImport::add_importer( Ref<EditorImporterCollada>( memnew(EditorImporterCollada )));
  2953. EditorFileSystem::get_singleton()->connect("sources_changed",this,"_sources_changed");
  2954. EditorFileSystem::get_singleton()->connect("filesystem_changed",this,"_fs_changed");
  2955. {
  2956. List<StringName> tl;
  2957. StringName ei = "EditorIcons";
  2958. gui_base->get_theme()->get_icon_list(ei,&tl);
  2959. for(List<StringName>::Element *E=tl.front();E;E=E->next()) {
  2960. if (!ObjectTypeDB::type_exists(E->get()))
  2961. continue;
  2962. icon_type_cache[E->get()]=gui_base->get_theme()->get_icon(E->get(),ei);
  2963. }
  2964. }
  2965. EditorSettings::get_singleton()->enable_plugins();
  2966. Node::set_human_readable_collision_renaming(true);
  2967. // Ref<ImageTexture> it = gui_base->get_icon("logo","Icons");
  2968. // OS::get_singleton()->set_icon( it->get_data() );
  2969. for(int i=0;i<_init_callbacks.size();i++)
  2970. _init_callbacks[i]();
  2971. }
  2972. EditorNode::~EditorNode() {
  2973. memdelete(editor_selection);
  2974. memdelete(file_server);
  2975. EditorSettings::destroy();
  2976. }