editor_node.cpp 112 KB

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