editor_node.cpp 115 KB

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