editor_node.cpp 184 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782
  1. /*************************************************************************/
  2. /* editor_node.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "editor_node.h"
  31. #include "core/bind/core_bind.h"
  32. #include "core/class_db.h"
  33. #include "core/io/config_file.h"
  34. #include "core/io/resource_loader.h"
  35. #include "core/io/resource_saver.h"
  36. #include "core/io/stream_peer_ssl.h"
  37. #include "core/io/zip_io.h"
  38. #include "core/message_queue.h"
  39. #include "core/os/file_access.h"
  40. #include "core/os/input.h"
  41. #include "core/os/keyboard.h"
  42. #include "core/os/os.h"
  43. #include "core/path_remap.h"
  44. #include "core/print_string.h"
  45. #include "core/project_settings.h"
  46. #include "core/translation.h"
  47. #include "core/version.h"
  48. #include "main/input_default.h"
  49. #include "scene/resources/packed_scene.h"
  50. #include "servers/physics_2d_server.h"
  51. #include "editor/editor_audio_buses.h"
  52. #include "editor/editor_file_system.h"
  53. #include "editor/editor_help.h"
  54. #include "editor/editor_initialize_ssl.h"
  55. #include "editor/editor_properties.h"
  56. #include "editor/editor_settings.h"
  57. #include "editor/editor_themes.h"
  58. #include "editor/import/editor_import_collada.h"
  59. #include "editor/import/editor_scene_importer_gltf.h"
  60. #include "editor/import/resource_importer_bitmask.h"
  61. #include "editor/import/resource_importer_csv_translation.h"
  62. #include "editor/import/resource_importer_obj.h"
  63. #include "editor/import/resource_importer_scene.h"
  64. #include "editor/import/resource_importer_texture.h"
  65. #include "editor/import/resource_importer_wav.h"
  66. #include "editor/plugins/animation_blend_space_1d_editor.h"
  67. #include "editor/plugins/animation_blend_space_2d_editor.h"
  68. #include "editor/plugins/animation_blend_tree_editor_plugin.h"
  69. #include "editor/plugins/animation_player_editor_plugin.h"
  70. #include "editor/plugins/animation_state_machine_editor.h"
  71. #include "editor/plugins/animation_tree_editor_plugin.h"
  72. #include "editor/plugins/asset_library_editor_plugin.h"
  73. #include "editor/plugins/audio_stream_editor_plugin.h"
  74. #include "editor/plugins/baked_lightmap_editor_plugin.h"
  75. #include "editor/plugins/camera_editor_plugin.h"
  76. #include "editor/plugins/canvas_item_editor_plugin.h"
  77. #include "editor/plugins/collision_polygon_2d_editor_plugin.h"
  78. #include "editor/plugins/collision_polygon_editor_plugin.h"
  79. #include "editor/plugins/collision_shape_2d_editor_plugin.h"
  80. #include "editor/plugins/cpu_particles_editor_plugin.h"
  81. #include "editor/plugins/cube_grid_theme_editor_plugin.h"
  82. #include "editor/plugins/curve_editor_plugin.h"
  83. #include "editor/plugins/editor_preview_plugins.h"
  84. #include "editor/plugins/gi_probe_editor_plugin.h"
  85. #include "editor/plugins/gradient_editor_plugin.h"
  86. #include "editor/plugins/item_list_editor_plugin.h"
  87. #include "editor/plugins/light_occluder_2d_editor_plugin.h"
  88. #include "editor/plugins/line_2d_editor_plugin.h"
  89. #include "editor/plugins/material_editor_plugin.h"
  90. #include "editor/plugins/mesh_editor_plugin.h"
  91. #include "editor/plugins/mesh_instance_editor_plugin.h"
  92. #include "editor/plugins/multimesh_editor_plugin.h"
  93. #include "editor/plugins/navigation_polygon_editor_plugin.h"
  94. #include "editor/plugins/particles_2d_editor_plugin.h"
  95. #include "editor/plugins/particles_editor_plugin.h"
  96. #include "editor/plugins/path_2d_editor_plugin.h"
  97. #include "editor/plugins/path_editor_plugin.h"
  98. #include "editor/plugins/physical_bone_plugin.h"
  99. #include "editor/plugins/polygon_2d_editor_plugin.h"
  100. #include "editor/plugins/resource_preloader_editor_plugin.h"
  101. #include "editor/plugins/root_motion_editor_plugin.h"
  102. #include "editor/plugins/script_editor_plugin.h"
  103. #include "editor/plugins/script_text_editor.h"
  104. #include "editor/plugins/shader_editor_plugin.h"
  105. #include "editor/plugins/shader_graph_editor_plugin.h"
  106. #include "editor/plugins/skeleton_2d_editor_plugin.h"
  107. #include "editor/plugins/skeleton_editor_plugin.h"
  108. #include "editor/plugins/spatial_editor_plugin.h"
  109. #include "editor/plugins/sprite_editor_plugin.h"
  110. #include "editor/plugins/sprite_frames_editor_plugin.h"
  111. #include "editor/plugins/style_box_editor_plugin.h"
  112. #include "editor/plugins/texture_editor_plugin.h"
  113. #include "editor/plugins/texture_region_editor_plugin.h"
  114. #include "editor/plugins/theme_editor_plugin.h"
  115. #include "editor/plugins/tile_map_editor_plugin.h"
  116. #include "editor/plugins/tile_set_editor_plugin.h"
  117. #include "editor/plugins/visual_shader_editor_plugin.h"
  118. #include "editor/pvrtc_compress.h"
  119. #include "editor/register_exporters.h"
  120. #include "editor/script_editor_debugger.h"
  121. #include <stdio.h>
  122. EditorNode *EditorNode::singleton = NULL;
  123. void EditorNode::_update_scene_tabs() {
  124. bool show_rb = EditorSettings::get_singleton()->get("interface/scene_tabs/show_script_button");
  125. scene_tabs->clear_tabs();
  126. Ref<Texture> script_icon = gui_base->get_icon("Script", "EditorIcons");
  127. for (int i = 0; i < editor_data.get_edited_scene_count(); i++) {
  128. String type = editor_data.get_scene_type(i);
  129. Ref<Texture> icon;
  130. if (type != String()) {
  131. if (!gui_base->has_icon(type, "EditorIcons")) {
  132. type = "Node";
  133. }
  134. icon = gui_base->get_icon(type, "EditorIcons");
  135. }
  136. int current = editor_data.get_edited_scene();
  137. bool unsaved = (i == current) ? saved_version != editor_data.get_undo_redo().get_version() : editor_data.get_scene_version(i) != 0;
  138. scene_tabs->add_tab(editor_data.get_scene_title(i) + (unsaved ? "(*)" : ""), icon);
  139. if (show_rb && editor_data.get_scene_root_script(i).is_valid()) {
  140. scene_tabs->set_tab_right_button(i, script_icon);
  141. }
  142. }
  143. scene_tabs->set_current_tab(editor_data.get_edited_scene());
  144. int current = editor_data.get_edited_scene();
  145. if (scene_tabs->get_offset_buttons_visible()) {
  146. // move add button to fixed position on the tabbar
  147. if (scene_tab_add->get_parent() == scene_tabs) {
  148. scene_tab_add->set_position(Point2(0, 0));
  149. scene_tabs->remove_child(scene_tab_add);
  150. tabbar_container->add_child(scene_tab_add);
  151. tabbar_container->move_child(scene_tab_add, 1);
  152. }
  153. } else {
  154. // move add button to after last tab
  155. if (scene_tab_add->get_parent() == tabbar_container) {
  156. tabbar_container->remove_child(scene_tab_add);
  157. scene_tabs->add_child(scene_tab_add);
  158. }
  159. Rect2 last_tab = Rect2();
  160. if (scene_tabs->get_tab_count() != 0)
  161. last_tab = scene_tabs->get_tab_rect(scene_tabs->get_tab_count() - 1);
  162. scene_tab_add->set_position(Point2(last_tab.get_position().x + last_tab.get_size().x + 3, last_tab.get_position().y));
  163. }
  164. }
  165. void EditorNode::_update_title() {
  166. String appname = ProjectSettings::get_singleton()->get("application/config/name");
  167. String title = appname.empty() ? String(VERSION_FULL_NAME) : String(VERSION_NAME + String(" - ") + appname);
  168. String edited = editor_data.get_edited_scene_root() ? editor_data.get_edited_scene_root()->get_filename() : String();
  169. if (!edited.empty())
  170. title += " - " + String(edited.get_file());
  171. if (unsaved_cache)
  172. title += " (*)";
  173. OS::get_singleton()->set_window_title(title);
  174. }
  175. void EditorNode::_unhandled_input(const Ref<InputEvent> &p_event) {
  176. if (Node::get_viewport()->get_modal_stack_top())
  177. return; //ignore because of modal window
  178. Ref<InputEventKey> k = p_event;
  179. if (k.is_valid() && k->is_pressed() && !k->is_echo() && !gui_base->get_viewport()->gui_has_modal_stack()) {
  180. EditorPlugin *old_editor = editor_plugin_screen;
  181. if (ED_IS_SHORTCUT("editor/next_tab", p_event)) {
  182. int next_tab = editor_data.get_edited_scene() + 1;
  183. next_tab %= editor_data.get_edited_scene_count();
  184. _scene_tab_changed(next_tab);
  185. }
  186. if (ED_IS_SHORTCUT("editor/prev_tab", p_event)) {
  187. int next_tab = editor_data.get_edited_scene() - 1;
  188. next_tab = next_tab >= 0 ? next_tab : editor_data.get_edited_scene_count() - 1;
  189. _scene_tab_changed(next_tab);
  190. }
  191. if (ED_IS_SHORTCUT("editor/filter_files", p_event)) {
  192. filesystem_dock->focus_on_filter();
  193. }
  194. if (ED_IS_SHORTCUT("editor/editor_2d", p_event)) {
  195. _editor_select(EDITOR_2D);
  196. } else if (ED_IS_SHORTCUT("editor/editor_3d", p_event)) {
  197. _editor_select(EDITOR_3D);
  198. } else if (ED_IS_SHORTCUT("editor/editor_script", p_event)) {
  199. _editor_select(EDITOR_SCRIPT);
  200. } else if (ED_IS_SHORTCUT("editor/editor_help", p_event)) {
  201. emit_signal("request_help_search", "");
  202. } else if (ED_IS_SHORTCUT("editor/editor_assetlib", p_event)) {
  203. _editor_select(EDITOR_ASSETLIB);
  204. } else if (ED_IS_SHORTCUT("editor/editor_next", p_event)) {
  205. _editor_select_next();
  206. } else if (ED_IS_SHORTCUT("editor/editor_prev", p_event)) {
  207. _editor_select_prev();
  208. }
  209. if (k->get_scancode() == KEY_ESCAPE) {
  210. for (int i = 0; i < bottom_panel_items.size(); i++) {
  211. _bottom_panel_switch(false, i);
  212. }
  213. }
  214. if (old_editor != editor_plugin_screen) {
  215. get_tree()->set_input_as_handled();
  216. }
  217. }
  218. }
  219. void EditorNode::_notification(int p_what) {
  220. if (p_what == NOTIFICATION_EXIT_TREE) {
  221. editor_data.save_editor_external_data();
  222. FileAccess::set_file_close_fail_notify_callback(NULL);
  223. log->deinit(); // do not get messages anymore
  224. }
  225. if (p_what == NOTIFICATION_PROCESS) {
  226. if (opening_prev && !confirmation->is_visible())
  227. opening_prev = false;
  228. if (unsaved_cache != (saved_version != editor_data.get_undo_redo().get_version())) {
  229. unsaved_cache = (saved_version != editor_data.get_undo_redo().get_version());
  230. _update_title();
  231. }
  232. if (last_checked_version != editor_data.get_undo_redo().get_version()) {
  233. _update_scene_tabs();
  234. last_checked_version = editor_data.get_undo_redo().get_version();
  235. }
  236. //update the circle
  237. uint64_t frame = Engine::get_singleton()->get_frames_drawn();
  238. uint32_t tick = OS::get_singleton()->get_ticks_msec();
  239. if (frame != circle_step_frame && (tick - circle_step_msec) > (1000 / 8)) {
  240. circle_step++;
  241. if (circle_step >= 8)
  242. circle_step = 0;
  243. circle_step_msec = tick;
  244. circle_step_frame = frame + 1;
  245. // update the circle itself only when its enabled
  246. if (!update_menu->get_popup()->is_item_checked(3)) {
  247. update_menu->set_icon(gui_base->get_icon("Progress" + itos(circle_step + 1), "EditorIcons"));
  248. }
  249. }
  250. editor_selection->update();
  251. scene_root->set_size_override(true, Size2(ProjectSettings::get_singleton()->get("display/window/size/width"), ProjectSettings::get_singleton()->get("display/window/size/height")));
  252. ResourceImporterTexture::get_singleton()->update_imports();
  253. }
  254. if (p_what == NOTIFICATION_ENTER_TREE) {
  255. Engine::get_singleton()->set_editor_hint(true);
  256. get_tree()->get_root()->set_usage(Viewport::USAGE_2D_NO_SAMPLING); //reduce memory usage
  257. get_tree()->get_root()->set_disable_3d(true);
  258. get_tree()->get_root()->set_as_audio_listener(false);
  259. get_tree()->get_root()->set_as_audio_listener_2d(false);
  260. get_tree()->set_auto_accept_quit(false);
  261. get_tree()->connect("files_dropped", this, "_dropped_files");
  262. }
  263. if (p_what == NOTIFICATION_EXIT_TREE) {
  264. editor_data.clear_edited_scenes();
  265. }
  266. if (p_what == NOTIFICATION_READY) {
  267. VisualServer::get_singleton()->viewport_set_hide_scenario(get_scene_root()->get_viewport_rid(), true);
  268. VisualServer::get_singleton()->viewport_set_hide_canvas(get_scene_root()->get_viewport_rid(), true);
  269. VisualServer::get_singleton()->viewport_set_disable_environment(get_viewport()->get_viewport_rid(), true);
  270. _editor_select(EDITOR_3D);
  271. _update_debug_options();
  272. _load_docks();
  273. }
  274. if (p_what == MainLoop::NOTIFICATION_WM_FOCUS_IN) {
  275. EditorFileSystem::get_singleton()->scan_changes();
  276. }
  277. if (p_what == MainLoop::NOTIFICATION_WM_QUIT_REQUEST) {
  278. _menu_option_confirm(FILE_QUIT, false);
  279. }
  280. if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) {
  281. scene_tabs->set_tab_close_display_policy((bool(EDITOR_GET("interface/scene_tabs/always_show_close_button")) ? Tabs::CLOSE_BUTTON_SHOW_ALWAYS : Tabs::CLOSE_BUTTON_SHOW_ACTIVE_ONLY));
  282. Ref<Theme> theme = create_editor_theme(theme_base->get_theme());
  283. theme_base->set_theme(theme);
  284. gui_base->set_theme(theme);
  285. gui_base->add_style_override("panel", gui_base->get_stylebox("Background", "EditorStyles"));
  286. play_button_panel->add_style_override("panel", gui_base->get_stylebox("PlayButtonPanel", "EditorStyles"));
  287. scene_root_parent->add_style_override("panel", gui_base->get_stylebox("Content", "EditorStyles"));
  288. bottom_panel->add_style_override("panel", gui_base->get_stylebox("panel", "TabContainer"));
  289. scene_tabs->add_style_override("tab_fg", gui_base->get_stylebox("SceneTabFG", "EditorStyles"));
  290. scene_tabs->add_style_override("tab_bg", gui_base->get_stylebox("SceneTabBG", "EditorStyles"));
  291. file_menu->add_style_override("hover", gui_base->get_stylebox("MenuHover", "EditorStyles"));
  292. project_menu->add_style_override("hover", gui_base->get_stylebox("MenuHover", "EditorStyles"));
  293. debug_menu->add_style_override("hover", gui_base->get_stylebox("MenuHover", "EditorStyles"));
  294. settings_menu->add_style_override("hover", gui_base->get_stylebox("MenuHover", "EditorStyles"));
  295. help_menu->add_style_override("hover", gui_base->get_stylebox("MenuHover", "EditorStyles"));
  296. if (EDITOR_GET("interface/scene_tabs/resize_if_many_tabs")) {
  297. scene_tabs->set_min_width(int(EDITOR_GET("interface/scene_tabs/minimum_width")) * EDSCALE);
  298. } else {
  299. scene_tabs->set_min_width(0);
  300. }
  301. _update_scene_tabs();
  302. recent_scenes->set_as_minsize();
  303. // debugger area
  304. if (ScriptEditor::get_singleton()->get_debugger()->is_visible())
  305. bottom_panel->add_style_override("panel", gui_base->get_stylebox("BottomPanelDebuggerOverride", "EditorStyles"));
  306. // update_icons
  307. for (int i = 0; i < singleton->main_editor_buttons.size(); i++) {
  308. ToolButton *tb = singleton->main_editor_buttons[i];
  309. EditorPlugin *p_editor = singleton->editor_table[i];
  310. Ref<Texture> icon = p_editor->get_icon();
  311. if (icon.is_valid()) {
  312. tb->set_icon(icon);
  313. } else if (singleton->gui_base->has_icon(p_editor->get_name(), "EditorIcons")) {
  314. tb->set_icon(singleton->gui_base->get_icon(p_editor->get_name(), "EditorIcons"));
  315. }
  316. }
  317. _build_icon_type_cache();
  318. play_button->set_icon(gui_base->get_icon("MainPlay", "EditorIcons"));
  319. play_scene_button->set_icon(gui_base->get_icon("PlayScene", "EditorIcons"));
  320. play_custom_scene_button->set_icon(gui_base->get_icon("PlayCustom", "EditorIcons"));
  321. pause_button->set_icon(gui_base->get_icon("Pause", "EditorIcons"));
  322. stop_button->set_icon(gui_base->get_icon("Stop", "EditorIcons"));
  323. prev_scene->set_icon(gui_base->get_icon("PrevScene", "EditorIcons"));
  324. distraction_free->set_icon(gui_base->get_icon("DistractionFree", "EditorIcons"));
  325. scene_tab_add->set_icon(gui_base->get_icon("Add", "EditorIcons"));
  326. // clear_button->set_icon(gui_base->get_icon("Close", "EditorIcons")); don't have access to that node. needs to become a class property
  327. update_menu->set_icon(gui_base->get_icon("Collapse", "EditorIcons"));
  328. dock_tab_move_left->set_icon(theme->get_icon("Back", "EditorIcons"));
  329. dock_tab_move_right->set_icon(theme->get_icon("Forward", "EditorIcons"));
  330. update_menu->set_icon(gui_base->get_icon("Progress1", "EditorIcons"));
  331. PopupMenu *p = help_menu->get_popup();
  332. p->set_item_icon(p->get_item_index(HELP_CLASSES), gui_base->get_icon("ClassList", "EditorIcons"));
  333. p->set_item_icon(p->get_item_index(HELP_SEARCH), gui_base->get_icon("HelpSearch", "EditorIcons"));
  334. p->set_item_icon(p->get_item_index(HELP_DOCS), gui_base->get_icon("Instance", "EditorIcons"));
  335. p->set_item_icon(p->get_item_index(HELP_QA), gui_base->get_icon("Instance", "EditorIcons"));
  336. p->set_item_icon(p->get_item_index(HELP_ISSUES), gui_base->get_icon("Instance", "EditorIcons"));
  337. p->set_item_icon(p->get_item_index(HELP_COMMUNITY), gui_base->get_icon("Instance", "EditorIcons"));
  338. p->set_item_icon(p->get_item_index(HELP_ABOUT), gui_base->get_icon("Godot", "EditorIcons"));
  339. }
  340. if (p_what == Control::NOTIFICATION_RESIZED) {
  341. _update_scene_tabs();
  342. }
  343. }
  344. void EditorNode::_fs_changed() {
  345. for (Set<FileDialog *>::Element *E = file_dialogs.front(); E; E = E->next()) {
  346. E->get()->invalidate();
  347. }
  348. for (Set<EditorFileDialog *>::Element *E = editor_file_dialogs.front(); E; E = E->next()) {
  349. E->get()->invalidate();
  350. }
  351. {
  352. //reload changed resources
  353. List<Ref<Resource> > changed;
  354. List<Ref<Resource> > cached;
  355. ResourceCache::get_cached_resources(&cached);
  356. // FIXME: This should be done in a thread.
  357. for (List<Ref<Resource> >::Element *E = cached.front(); E; E = E->next()) {
  358. if (!E->get()->editor_can_reload_from_file())
  359. continue;
  360. if (!E->get()->get_path().is_resource_file() && !E->get()->get_path().is_abs_path())
  361. continue;
  362. if (!FileAccess::exists(E->get()->get_path()))
  363. continue;
  364. if (E->get()->get_import_path() != String()) {
  365. //this is an imported resource, will be reloaded if reimported via the _resources_reimported() callback
  366. continue;
  367. }
  368. uint64_t mt = FileAccess::get_modified_time(E->get()->get_path());
  369. if (mt != E->get()->get_last_modified_time()) {
  370. changed.push_back(E->get());
  371. }
  372. }
  373. if (changed.size()) {
  374. for (List<Ref<Resource> >::Element *E = changed.front(); E; E = E->next()) {
  375. E->get()->reload_from_file();
  376. }
  377. }
  378. }
  379. _mark_unsaved_scenes();
  380. if (export_defer.preset != "" && !EditorFileSystem::get_singleton()->is_scanning()) {
  381. Ref<EditorExportPreset> preset;
  382. for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); ++i) {
  383. preset = EditorExport::get_singleton()->get_export_preset(i);
  384. if (preset->get_name() == export_defer.preset) {
  385. break;
  386. }
  387. preset.unref();
  388. }
  389. if (preset.is_null()) {
  390. String errstr = "Unknown export preset: " + export_defer.preset;
  391. ERR_PRINTS(errstr);
  392. } else {
  393. Ref<EditorExportPlatform> platform = preset->get_platform();
  394. if (platform.is_null()) {
  395. String errstr = "Preset \"" + export_defer.preset + "\" doesn't have a platform.";
  396. ERR_PRINTS(errstr);
  397. } else {
  398. // ensures export_project does not loop infinitely, because notifications may
  399. // come during the export
  400. export_defer.preset = "";
  401. Error err = OK;
  402. if (export_defer.path.ends_with(".pck") || export_defer.path.ends_with(".zip")) {
  403. if (export_defer.path.ends_with(".zip")) {
  404. err = platform->export_zip(preset, export_defer.debug, export_defer.path);
  405. } else if (export_defer.path.ends_with(".pck")) {
  406. err = platform->export_pack(preset, export_defer.debug, export_defer.path);
  407. }
  408. } else {
  409. err = platform->export_project(preset, export_defer.debug, export_defer.path);
  410. }
  411. if (err != OK) {
  412. ERR_PRINTS(vformat(TTR("Project export failed with error code %d."), (int)err));
  413. }
  414. }
  415. }
  416. get_tree()->quit();
  417. }
  418. }
  419. void EditorNode::_resources_reimported(const Vector<String> &p_resources) {
  420. List<String> scenes; //will load later
  421. for (int i = 0; i < p_resources.size(); i++) {
  422. String file_type = ResourceLoader::get_resource_type(p_resources[i]);
  423. if (file_type == "PackedScene") {
  424. scenes.push_back(p_resources[i]);
  425. //reload later if needed, first go with normal resources
  426. continue;
  427. }
  428. if (!ResourceCache::has(p_resources[i])) {
  429. continue; //not loaded, no need to reload
  430. }
  431. //reload normally
  432. Resource *resource = ResourceCache::get(p_resources[i]);
  433. if (resource) {
  434. resource->reload_from_file();
  435. }
  436. }
  437. for (List<String>::Element *E = scenes.front(); E; E = E->next()) {
  438. reload_scene(E->get());
  439. }
  440. }
  441. void EditorNode::_sources_changed(bool p_exist) {
  442. if (waiting_for_first_scan) {
  443. if (defer_load_scene != "") {
  444. load_scene(defer_load_scene);
  445. defer_load_scene = "";
  446. }
  447. waiting_for_first_scan = false;
  448. }
  449. }
  450. void EditorNode::_vp_resized() {
  451. }
  452. void EditorNode::_node_renamed() {
  453. if (get_inspector())
  454. get_inspector()->update_tree();
  455. }
  456. void EditorNode::_editor_select_next() {
  457. int editor = _get_current_main_editor();
  458. if (editor == editor_table.size() - 1) {
  459. editor = 0;
  460. } else {
  461. editor++;
  462. }
  463. _editor_select(editor);
  464. }
  465. void EditorNode::_editor_select_prev() {
  466. int editor = _get_current_main_editor();
  467. if (editor == 0) {
  468. editor = editor_table.size() - 1;
  469. } else {
  470. editor--;
  471. }
  472. _editor_select(editor);
  473. }
  474. Error EditorNode::load_resource(const String &p_scene) {
  475. RES res = ResourceLoader::load(p_scene);
  476. ERR_FAIL_COND_V(!res.is_valid(), ERR_CANT_OPEN);
  477. inspector_dock->edit_resource(res);
  478. return OK;
  479. }
  480. void EditorNode::edit_node(Node *p_node) {
  481. push_item(p_node);
  482. }
  483. void EditorNode::save_resource_in_path(const Ref<Resource> &p_resource, const String &p_path) {
  484. editor_data.apply_changes_in_editors();
  485. int flg = 0;
  486. if (EditorSettings::get_singleton()->get("filesystem/on_save/compress_binary_resources"))
  487. flg |= ResourceSaver::FLAG_COMPRESS;
  488. String path = ProjectSettings::get_singleton()->localize_path(p_path);
  489. Error err = ResourceSaver::save(path, p_resource, flg | ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS);
  490. if (err != OK) {
  491. show_accept(TTR("Error saving resource!"), TTR("I see..."));
  492. return;
  493. }
  494. ((Resource *)p_resource.ptr())->set_path(path);
  495. emit_signal("resource_saved", p_resource);
  496. editor_data.notify_resource_saved(p_resource);
  497. }
  498. void EditorNode::save_resource(const Ref<Resource> &p_resource) {
  499. if (p_resource->get_path().is_resource_file()) {
  500. save_resource_in_path(p_resource, p_resource->get_path());
  501. } else {
  502. save_resource_as(p_resource);
  503. }
  504. }
  505. void EditorNode::save_resource_as(const Ref<Resource> &p_resource, const String &p_at_path) {
  506. file->set_mode(EditorFileDialog::MODE_SAVE_FILE);
  507. current_option = RESOURCE_SAVE_AS;
  508. List<String> extensions;
  509. Ref<PackedScene> sd = memnew(PackedScene);
  510. ResourceSaver::get_recognized_extensions(p_resource, &extensions);
  511. file->clear_filters();
  512. List<String> preferred;
  513. for (int i = 0; i < extensions.size(); i++) {
  514. if (p_resource->is_class("Script") && (extensions[i] == "tres" || extensions[i] == "res" || extensions[i] == "xml")) {
  515. //this serves no purpose and confused people
  516. continue;
  517. }
  518. file->add_filter("*." + extensions[i] + " ; " + extensions[i].to_upper());
  519. preferred.push_back(extensions[i]);
  520. }
  521. if (p_at_path != String()) {
  522. file->set_current_dir(p_at_path);
  523. if (p_resource->get_path().is_resource_file()) {
  524. file->set_current_file(p_resource->get_path().get_file());
  525. } else {
  526. if (extensions.size()) {
  527. file->set_current_file("new_" + p_resource->get_class().to_lower() + "." + preferred.front()->get().to_lower());
  528. } else {
  529. file->set_current_file(String());
  530. }
  531. }
  532. } else if (p_resource->get_path() != "") {
  533. file->set_current_path(p_resource->get_path());
  534. if (extensions.size()) {
  535. String ext = p_resource->get_path().get_extension().to_lower();
  536. if (extensions.find(ext) == NULL) {
  537. file->set_current_path(p_resource->get_path().replacen("." + ext, "." + extensions.front()->get()));
  538. }
  539. }
  540. } else if (preferred.size()) {
  541. String existing;
  542. if (extensions.size()) {
  543. existing = "new_" + p_resource->get_class().to_lower() + "." + preferred.front()->get().to_lower();
  544. }
  545. file->set_current_path(existing);
  546. }
  547. file->popup_centered_ratio();
  548. file->set_title(TTR("Save Resource As..."));
  549. }
  550. void EditorNode::_menu_option(int p_option) {
  551. _menu_option_confirm(p_option, false);
  552. }
  553. void EditorNode::_menu_confirm_current() {
  554. _menu_option_confirm(current_option, true);
  555. }
  556. void EditorNode::_dialog_display_save_error(String p_file, Error p_error) {
  557. if (p_error) {
  558. switch (p_error) {
  559. case ERR_FILE_CANT_WRITE: {
  560. show_accept(TTR("Can't open file for writing:") + " " + p_file.get_extension(), TTR("I see..."));
  561. } break;
  562. case ERR_FILE_UNRECOGNIZED: {
  563. show_accept(TTR("Requested file format unknown:") + " " + p_file.get_extension(), TTR("I see..."));
  564. } break;
  565. default: {
  566. show_accept(TTR("Error while saving."), TTR("I see..."));
  567. } break;
  568. }
  569. }
  570. }
  571. void EditorNode::_dialog_display_load_error(String p_file, Error p_error) {
  572. if (p_error) {
  573. switch (p_error) {
  574. case ERR_CANT_OPEN: {
  575. show_accept(vformat(TTR("Can't open '%s'. The file could have been moved or deleted."), p_file.get_file()), TTR("I see..."));
  576. } break;
  577. case ERR_PARSE_ERROR: {
  578. show_accept(vformat(TTR("Error while parsing '%s'."), p_file.get_file()), TTR("I see..."));
  579. } break;
  580. case ERR_FILE_CORRUPT: {
  581. show_accept(vformat(TTR("Unexpected end of file '%s'."), p_file.get_file()), TTR("I see..."));
  582. } break;
  583. case ERR_FILE_NOT_FOUND: {
  584. show_accept(vformat(TTR("Missing '%s' or its dependencies."), p_file.get_file()), TTR("I see..."));
  585. } break;
  586. default: {
  587. show_accept(vformat(TTR("Error while loading '%s'."), p_file.get_file()), TTR("I see..."));
  588. } break;
  589. }
  590. }
  591. }
  592. void EditorNode::_get_scene_metadata(const String &p_file) {
  593. Node *scene = editor_data.get_edited_scene_root();
  594. if (!scene)
  595. return;
  596. String path = EditorSettings::get_singleton()->get_project_settings_dir().plus_file(p_file.get_file() + "-editstate-" + p_file.md5_text() + ".cfg");
  597. Ref<ConfigFile> cf;
  598. cf.instance();
  599. Error err = cf->load(path);
  600. if (err != OK || !cf->has_section("editor_states"))
  601. return; //must not exist
  602. List<String> esl;
  603. cf->get_section_keys("editor_states", &esl);
  604. Dictionary md;
  605. for (List<String>::Element *E = esl.front(); E; E = E->next()) {
  606. Variant st = cf->get_value("editor_states", E->get());
  607. if (st.get_type()) {
  608. md[E->get()] = st;
  609. }
  610. }
  611. editor_data.set_editor_states(md);
  612. }
  613. void EditorNode::_set_scene_metadata(const String &p_file, int p_idx) {
  614. Node *scene = editor_data.get_edited_scene_root(p_idx);
  615. if (!scene)
  616. return;
  617. scene->set_meta("__editor_run_settings__", Variant()); //clear it (no point in keeping it)
  618. scene->set_meta("__editor_plugin_states__", Variant());
  619. String path = EditorSettings::get_singleton()->get_project_settings_dir().plus_file(p_file.get_file() + "-editstate-" + p_file.md5_text() + ".cfg");
  620. Ref<ConfigFile> cf;
  621. cf.instance();
  622. Dictionary md;
  623. if (p_idx < 0 || editor_data.get_edited_scene() == p_idx) {
  624. md = editor_data.get_editor_states();
  625. } else {
  626. md = editor_data.get_scene_editor_states(p_idx);
  627. }
  628. List<Variant> keys;
  629. md.get_key_list(&keys);
  630. for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
  631. cf->set_value("editor_states", E->get(), md[E->get()]);
  632. }
  633. Error err = cf->save(path);
  634. ERR_FAIL_COND(err != OK);
  635. }
  636. bool EditorNode::_find_and_save_resource(RES p_res, Map<RES, bool> &processed, int32_t flags) {
  637. if (p_res.is_null())
  638. return false;
  639. if (processed.has(p_res)) {
  640. return processed[p_res];
  641. }
  642. bool changed = p_res->is_edited();
  643. p_res->set_edited(false);
  644. bool subchanged = _find_and_save_edited_subresources(p_res.ptr(), processed, flags);
  645. if (p_res->get_path().is_resource_file()) {
  646. if (changed || subchanged) {
  647. //save
  648. ResourceSaver::save(p_res->get_path(), p_res, flags);
  649. }
  650. processed[p_res] = false; //because it's a file
  651. return false;
  652. } else {
  653. processed[p_res] = changed;
  654. return changed;
  655. }
  656. }
  657. bool EditorNode::_find_and_save_edited_subresources(Object *obj, Map<RES, bool> &processed, int32_t flags) {
  658. bool ret_changed = false;
  659. List<PropertyInfo> pi;
  660. obj->get_property_list(&pi);
  661. for (List<PropertyInfo>::Element *E = pi.front(); E; E = E->next()) {
  662. if (!(E->get().usage & PROPERTY_USAGE_STORAGE))
  663. continue;
  664. switch (E->get().type) {
  665. case Variant::OBJECT: {
  666. RES res = obj->get(E->get().name);
  667. if (_find_and_save_resource(res, processed, flags))
  668. ret_changed = true;
  669. } break;
  670. case Variant::ARRAY: {
  671. Array varray = obj->get(E->get().name);
  672. int len = varray.size();
  673. for (int i = 0; i < len; i++) {
  674. Variant v = varray.get(i);
  675. RES res = v;
  676. if (_find_and_save_resource(res, processed, flags))
  677. ret_changed = true;
  678. }
  679. } break;
  680. case Variant::DICTIONARY: {
  681. Dictionary d = obj->get(E->get().name);
  682. List<Variant> keys;
  683. d.get_key_list(&keys);
  684. for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
  685. Variant v = d[E->get()];
  686. RES res = v;
  687. if (_find_and_save_resource(res, processed, flags))
  688. ret_changed = true;
  689. }
  690. } break;
  691. default: {}
  692. }
  693. }
  694. return ret_changed;
  695. }
  696. void EditorNode::_save_edited_subresources(Node *scene, Map<RES, bool> &processed, int32_t flags) {
  697. _find_and_save_edited_subresources(scene, processed, flags);
  698. for (int i = 0; i < scene->get_child_count(); i++) {
  699. Node *n = scene->get_child(i);
  700. if (n->get_owner() != editor_data.get_edited_scene_root())
  701. continue;
  702. _save_edited_subresources(n, processed, flags);
  703. }
  704. }
  705. void EditorNode::_find_node_types(Node *p_node, int &count_2d, int &count_3d) {
  706. if (p_node->is_class("Viewport") || (p_node != editor_data.get_edited_scene_root() && p_node->get_owner() != editor_data.get_edited_scene_root()))
  707. return;
  708. if (p_node->is_class("CanvasItem"))
  709. count_2d++;
  710. else if (p_node->is_class("Spatial"))
  711. count_3d++;
  712. for (int i = 0; i < p_node->get_child_count(); i++)
  713. _find_node_types(p_node->get_child(i), count_2d, count_3d);
  714. }
  715. void EditorNode::_save_scene_with_preview(String p_file, int p_idx) {
  716. EditorProgress save("save", TTR("Saving Scene"), 4);
  717. save.step(TTR("Analyzing"), 0);
  718. int c2d = 0;
  719. int c3d = 0;
  720. _find_node_types(editor_data.get_edited_scene_root(), c2d, c3d);
  721. RID viewport;
  722. bool is2d;
  723. if (c3d < c2d) {
  724. viewport = scene_root->get_viewport_rid();
  725. is2d = true;
  726. } else {
  727. viewport = SpatialEditor::get_singleton()->get_editor_viewport(0)->get_viewport_node()->get_viewport_rid();
  728. is2d = false;
  729. }
  730. save.step(TTR("Creating Thumbnail"), 1);
  731. //current view?
  732. Ref<Image> img;
  733. if (is2d) {
  734. img = scene_root->get_texture()->get_data();
  735. } else {
  736. img = SpatialEditor::get_singleton()->get_editor_viewport(0)->get_viewport_node()->get_texture()->get_data();
  737. }
  738. if (img.is_valid()) {
  739. save.step(TTR("Creating Thumbnail"), 2);
  740. save.step(TTR("Creating Thumbnail"), 3);
  741. int preview_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size");
  742. preview_size *= EDSCALE;
  743. // consider a square region
  744. int vp_size = MIN(img->get_width(), img->get_height());
  745. int x = (img->get_width() - vp_size) / 2;
  746. int y = (img->get_height() - vp_size) / 2;
  747. img->convert(Image::FORMAT_RGB8);
  748. if (vp_size < preview_size) {
  749. // just square it.
  750. img->crop_from_point(x, y, vp_size, vp_size);
  751. } else {
  752. int ratio = vp_size / preview_size;
  753. int size = preview_size * (ratio / 2);
  754. x = (img->get_width() - size) / 2;
  755. y = (img->get_height() - size) / 2;
  756. img->crop_from_point(x, y, size, size);
  757. // We could get better pictures with better filters
  758. img->resize(preview_size, preview_size, Image::INTERPOLATE_CUBIC);
  759. }
  760. img->flip_y();
  761. //save thumbnail directly, as thumbnailer may not update due to actual scene not changing md5
  762. String temp_path = EditorSettings::get_singleton()->get_cache_dir();
  763. String cache_base = ProjectSettings::get_singleton()->globalize_path(p_file).md5_text();
  764. cache_base = temp_path.plus_file("resthumb-" + cache_base);
  765. //does not have it, try to load a cached thumbnail
  766. String file = cache_base + ".png";
  767. post_process_preview(img);
  768. img->save_png(file);
  769. }
  770. save.step(TTR("Saving Scene"), 4);
  771. _save_scene(p_file, p_idx);
  772. EditorResourcePreview::get_singleton()->check_for_invalidation(p_file);
  773. }
  774. void EditorNode::_save_scene(String p_file, int idx) {
  775. Node *scene = editor_data.get_edited_scene_root(idx);
  776. if (!scene) {
  777. show_accept(TTR("This operation can't be done without a tree root."), TTR("I see..."));
  778. return;
  779. }
  780. editor_data.apply_changes_in_editors();
  781. _save_default_environment();
  782. _set_scene_metadata(p_file, idx);
  783. Ref<PackedScene> sdata;
  784. if (ResourceCache::has(p_file)) {
  785. // something may be referencing this resource and we are good with that.
  786. // we must update it, but also let the previous scene state go, as
  787. // old version still work for referencing changes in instanced or inherited scenes
  788. sdata = Ref<PackedScene>(Object::cast_to<PackedScene>(ResourceCache::get(p_file)));
  789. if (sdata.is_valid())
  790. sdata->recreate_state();
  791. else
  792. sdata.instance();
  793. } else {
  794. sdata.instance();
  795. }
  796. Error err = sdata->pack(scene);
  797. if (err != OK) {
  798. show_accept(TTR("Couldn't save scene. Likely dependencies (instances or inheritance) couldn't be satisfied."), TTR("I see..."));
  799. return;
  800. }
  801. // force creation of node path cache
  802. // (hacky but needed for the tree to update properly)
  803. Node *dummy_scene = sdata->instance(PackedScene::GEN_EDIT_STATE_INSTANCE);
  804. if (!dummy_scene) {
  805. show_accept(TTR("Couldn't save scene. Likely dependencies (instances or inheritance) couldn't be satisfied."), TTR("I see..."));
  806. return;
  807. }
  808. memdelete(dummy_scene);
  809. int flg = 0;
  810. if (EditorSettings::get_singleton()->get("filesystem/on_save/compress_binary_resources"))
  811. flg |= ResourceSaver::FLAG_COMPRESS;
  812. flg |= ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS;
  813. err = ResourceSaver::save(p_file, sdata, flg);
  814. //Map<RES, bool> processed;
  815. //this method is slow and not always works, deprecating
  816. //_save_edited_subresources(scene, processed, flg);
  817. { //instead, just find globally unsaved subresources and save them
  818. List<Ref<Resource> > cached;
  819. ResourceCache::get_cached_resources(&cached);
  820. for (List<Ref<Resource> >::Element *E = cached.front(); E; E = E->next()) {
  821. Ref<Resource> res = E->get();
  822. if (res->is_edited() && res->get_path().is_resource_file()) {
  823. ResourceSaver::save(res->get_path(), res, flg);
  824. res->set_edited(false);
  825. }
  826. }
  827. }
  828. editor_data.save_editor_external_data();
  829. if (err == OK) {
  830. scene->set_filename(ProjectSettings::get_singleton()->localize_path(p_file));
  831. if (idx < 0 || idx == editor_data.get_edited_scene())
  832. set_current_version(editor_data.get_undo_redo().get_version());
  833. else
  834. editor_data.set_edited_scene_version(0, idx);
  835. _update_title();
  836. _update_scene_tabs();
  837. } else {
  838. _dialog_display_save_error(p_file, err);
  839. }
  840. }
  841. void EditorNode::save_all_scenes_and_restart() {
  842. _menu_option_confirm(RUN_STOP, true);
  843. exiting = true;
  844. _save_all_scenes();
  845. String to_reopen;
  846. if (get_tree()->get_edited_scene_root()) {
  847. to_reopen = get_tree()->get_edited_scene_root()->get_filename();
  848. }
  849. get_tree()->quit();
  850. String exec = OS::get_singleton()->get_executable_path();
  851. List<String> args;
  852. args.push_back("--path");
  853. args.push_back(ProjectSettings::get_singleton()->get_resource_path());
  854. args.push_back("-e");
  855. if (to_reopen != String()) {
  856. args.push_back(to_reopen);
  857. }
  858. OS::get_singleton()->set_restart_on_exit(true, args);
  859. }
  860. void EditorNode::_save_all_scenes() {
  861. for (int i = 0; i < editor_data.get_edited_scene_count(); i++) {
  862. Node *scene = editor_data.get_edited_scene_root(i);
  863. if (scene && scene->get_filename() != "") {
  864. if (i != editor_data.get_edited_scene())
  865. _save_scene(scene->get_filename(), i);
  866. else
  867. _save_scene_with_preview(scene->get_filename());
  868. } // else: ignore new scenes
  869. }
  870. _save_default_environment();
  871. }
  872. void EditorNode::_mark_unsaved_scenes() {
  873. for (int i = 0; i < editor_data.get_edited_scene_count(); i++) {
  874. Node *node = editor_data.get_edited_scene_root(i);
  875. if (!node)
  876. continue;
  877. String path = node->get_filename();
  878. if (!(path == String() || FileAccess::exists(path))) {
  879. node->set_filename("");
  880. if (i == editor_data.get_edited_scene())
  881. set_current_version(-1);
  882. else
  883. editor_data.set_edited_scene_version(-1, i);
  884. }
  885. }
  886. _update_title();
  887. _update_scene_tabs();
  888. }
  889. void EditorNode::_dialog_action(String p_file) {
  890. switch (current_option) {
  891. case FILE_NEW_INHERITED_SCENE: {
  892. load_scene(p_file, false, true);
  893. } break;
  894. case FILE_OPEN_SCENE: {
  895. load_scene(p_file);
  896. } break;
  897. case SETTINGS_PICK_MAIN_SCENE: {
  898. ProjectSettings::get_singleton()->set("application/run/main_scene", p_file);
  899. ProjectSettings::get_singleton()->save();
  900. //would be nice to show the project manager opened with the highlighted field..
  901. _run(false, ""); // automatically run the project
  902. } break;
  903. case FILE_CLOSE:
  904. case FILE_CLOSE_ALL_AND_QUIT:
  905. case FILE_CLOSE_ALL_AND_RUN_PROJECT_MANAGER:
  906. case SCENE_TAB_CLOSE:
  907. case FILE_SAVE_SCENE:
  908. case FILE_SAVE_AS_SCENE: {
  909. int scene_idx = (current_option == FILE_SAVE_SCENE || current_option == FILE_SAVE_AS_SCENE) ? -1 : tab_closing;
  910. if (file->get_mode() == EditorFileDialog::MODE_SAVE_FILE) {
  911. _save_default_environment();
  912. _save_scene_with_preview(p_file, scene_idx);
  913. _add_to_recent_scenes(p_file);
  914. if (scene_idx != -1)
  915. _discard_changes();
  916. }
  917. } break;
  918. case FILE_SAVE_AND_RUN: {
  919. if (file->get_mode() == EditorFileDialog::MODE_SAVE_FILE) {
  920. _save_default_environment();
  921. _save_scene_with_preview(p_file);
  922. _run(false, p_file);
  923. }
  924. } break;
  925. case FILE_EXPORT_MESH_LIBRARY: {
  926. Ref<MeshLibrary> ml;
  927. if (file_export_lib_merge->is_pressed() && FileAccess::exists(p_file)) {
  928. ml = ResourceLoader::load(p_file, "MeshLibrary");
  929. if (ml.is_null()) {
  930. show_accept(TTR("Can't load MeshLibrary for merging!"), TTR("I see..."));
  931. return;
  932. }
  933. }
  934. if (ml.is_null()) {
  935. ml = Ref<MeshLibrary>(memnew(MeshLibrary));
  936. }
  937. MeshLibraryEditor::update_library_file(editor_data.get_edited_scene_root(), ml, true);
  938. Error err = ResourceSaver::save(p_file, ml);
  939. if (err) {
  940. show_accept(TTR("Error saving MeshLibrary!"), TTR("I see..."));
  941. return;
  942. }
  943. } break;
  944. case FILE_EXPORT_TILESET: {
  945. Ref<TileSet> tileset;
  946. if (FileAccess::exists(p_file) && file_export_lib_merge->is_pressed()) {
  947. tileset = ResourceLoader::load(p_file, "TileSet");
  948. if (tileset.is_null()) {
  949. show_accept(TTR("Can't load TileSet for merging!"), TTR("I see..."));
  950. return;
  951. }
  952. } else {
  953. tileset = Ref<TileSet>(memnew(TileSet));
  954. }
  955. TileSetEditor::update_library_file(editor_data.get_edited_scene_root(), tileset, true);
  956. Error err = ResourceSaver::save(p_file, tileset);
  957. if (err) {
  958. show_accept("Error saving TileSet!", "I see...");
  959. return;
  960. }
  961. } break;
  962. case RESOURCE_SAVE:
  963. case RESOURCE_SAVE_AS: {
  964. uint32_t current = editor_history.get_current();
  965. Object *current_obj = current > 0 ? ObjectDB::get_instance(current) : NULL;
  966. ERR_FAIL_COND(!Object::cast_to<Resource>(current_obj))
  967. RES current_res = RES(Object::cast_to<Resource>(current_obj));
  968. save_resource_in_path(current_res, p_file);
  969. } break;
  970. case SETTINGS_LAYOUT_SAVE: {
  971. if (p_file.empty())
  972. return;
  973. Ref<ConfigFile> config;
  974. config.instance();
  975. Error err = config->load(EditorSettings::get_singleton()->get_editor_layouts_config());
  976. if (err == ERR_CANT_OPEN) {
  977. config.instance(); // new config
  978. } else if (err != OK) {
  979. show_warning(TTR("Error trying to save layout!"));
  980. return;
  981. }
  982. _save_docks_to_config(config, p_file);
  983. config->save(EditorSettings::get_singleton()->get_editor_layouts_config());
  984. layout_dialog->hide();
  985. _update_layouts_menu();
  986. if (p_file == "Default") {
  987. show_warning(TTR("Default editor layout overridden."));
  988. }
  989. } break;
  990. case SETTINGS_LAYOUT_DELETE: {
  991. if (p_file.empty())
  992. return;
  993. Ref<ConfigFile> config;
  994. config.instance();
  995. Error err = config->load(EditorSettings::get_singleton()->get_editor_layouts_config());
  996. if (err != OK || !config->has_section(p_file)) {
  997. show_warning(TTR("Layout name not found!"));
  998. return;
  999. }
  1000. // erase
  1001. List<String> keys;
  1002. config->get_section_keys(p_file, &keys);
  1003. for (List<String>::Element *E = keys.front(); E; E = E->next()) {
  1004. config->set_value(p_file, E->get(), Variant());
  1005. }
  1006. config->save(EditorSettings::get_singleton()->get_editor_layouts_config());
  1007. layout_dialog->hide();
  1008. _update_layouts_menu();
  1009. if (p_file == "Default") {
  1010. show_warning(TTR("Restored default layout to base settings."));
  1011. }
  1012. } break;
  1013. default: { //save scene?
  1014. if (file->get_mode() == EditorFileDialog::MODE_SAVE_FILE) {
  1015. _save_scene_with_preview(p_file);
  1016. }
  1017. } break;
  1018. }
  1019. }
  1020. bool EditorNode::item_has_editor(Object *p_object) {
  1021. return editor_data.get_subeditors(p_object).size() > 0;
  1022. }
  1023. void EditorNode::edit_item(Object *p_object) {
  1024. Vector<EditorPlugin *> sub_plugins;
  1025. if (p_object) {
  1026. sub_plugins = editor_data.get_subeditors(p_object);
  1027. }
  1028. if (!sub_plugins.empty()) {
  1029. _display_top_editors(false);
  1030. _set_top_editors(sub_plugins);
  1031. _set_editing_top_editors(p_object);
  1032. _display_top_editors(true);
  1033. } else {
  1034. _hide_top_editors();
  1035. }
  1036. }
  1037. void EditorNode::push_item(Object *p_object, const String &p_property, bool p_inspector_only) {
  1038. if (!p_object) {
  1039. get_inspector()->edit(NULL);
  1040. node_dock->set_node(NULL);
  1041. scene_tree_dock->set_selected(NULL);
  1042. return;
  1043. }
  1044. uint32_t id = p_object->get_instance_id();
  1045. if (id != editor_history.get_current()) {
  1046. if (p_inspector_only) {
  1047. editor_history.add_object_inspector_only(id);
  1048. } else if (p_property == "")
  1049. editor_history.add_object(id);
  1050. else
  1051. editor_history.add_object(id, p_property);
  1052. }
  1053. _edit_current();
  1054. }
  1055. void EditorNode::_save_default_environment() {
  1056. Ref<Environment> fallback = get_tree()->get_root()->get_world()->get_fallback_environment();
  1057. if (fallback.is_valid() && fallback->get_path().is_resource_file()) {
  1058. Map<RES, bool> processed;
  1059. _find_and_save_edited_subresources(fallback.ptr(), processed, 0);
  1060. save_resource_in_path(fallback, fallback->get_path());
  1061. }
  1062. }
  1063. void EditorNode::_hide_top_editors() {
  1064. _display_top_editors(false);
  1065. editor_plugins_over->clear();
  1066. }
  1067. void EditorNode::_display_top_editors(bool p_display) {
  1068. editor_plugins_over->make_visible(p_display);
  1069. }
  1070. void EditorNode::_set_top_editors(Vector<EditorPlugin *> p_editor_plugins_over) {
  1071. editor_plugins_over->set_plugins_list(p_editor_plugins_over);
  1072. }
  1073. void EditorNode::_set_editing_top_editors(Object *p_current_object) {
  1074. editor_plugins_over->edit(p_current_object);
  1075. }
  1076. static bool overrides_external_editor(Object *p_object) {
  1077. Script *script = Object::cast_to<Script>(p_object);
  1078. if (!script)
  1079. return false;
  1080. return script->get_language()->overrides_external_editor();
  1081. }
  1082. void EditorNode::_edit_current() {
  1083. uint32_t current = editor_history.get_current();
  1084. Object *current_obj = current > 0 ? ObjectDB::get_instance(current) : NULL;
  1085. bool inspector_only = editor_history.is_current_inspector_only();
  1086. this->current = current_obj;
  1087. if (!current_obj) {
  1088. scene_tree_dock->set_selected(NULL);
  1089. get_inspector()->edit(NULL);
  1090. node_dock->set_node(NULL);
  1091. inspector_dock->update(NULL);
  1092. _display_top_editors(false);
  1093. return;
  1094. }
  1095. bool capitalize = bool(EDITOR_GET("interface/inspector/capitalize_properties"));
  1096. bool disable_folding = bool(EDITOR_GET("interface/inspector/disable_folding"));
  1097. bool is_resource = current_obj->is_class("Resource");
  1098. bool is_node = current_obj->is_class("Node");
  1099. String editable_warning; //none by default
  1100. if (is_resource) {
  1101. Resource *current_res = Object::cast_to<Resource>(current_obj);
  1102. ERR_FAIL_COND(!current_res);
  1103. scene_tree_dock->set_selected(NULL);
  1104. get_inspector()->edit(current_res);
  1105. node_dock->set_node(NULL);
  1106. EditorNode::get_singleton()->get_import_dock()->set_edit_path(current_res->get_path());
  1107. int subr_idx = current_res->get_path().find("::");
  1108. if (subr_idx != -1) {
  1109. String base_path = current_res->get_path().substr(0, subr_idx);
  1110. if (FileAccess::exists(base_path + ".import")) {
  1111. editable_warning = TTR("This resource belongs to a scene that was imported, so it's not editable.\nPlease read the documentation relevant to importing scenes to better understand this workflow.");
  1112. } else {
  1113. if ((!get_edited_scene() || get_edited_scene()->get_filename() != base_path) && ResourceLoader::get_resource_type(base_path) == "PackedScene") {
  1114. editable_warning = TTR("This resource belongs to a scene that was instanced or inherited.\nChanges to it will not be kept when saving the current scene.");
  1115. }
  1116. }
  1117. } else if (current_res->get_path().is_resource_file()) {
  1118. if (FileAccess::exists(current_res->get_path() + ".import")) {
  1119. editable_warning = TTR("This resource was imported, so it's not editable. Change its settings in the import panel and then re-import.");
  1120. }
  1121. }
  1122. } else if (is_node) {
  1123. Node *current_node = Object::cast_to<Node>(current_obj);
  1124. ERR_FAIL_COND(!current_node);
  1125. get_inspector()->edit(current_node);
  1126. if (current_node->is_inside_tree()) {
  1127. node_dock->set_node(current_node);
  1128. scene_tree_dock->set_selected(current_node);
  1129. } else {
  1130. node_dock->set_node(NULL);
  1131. scene_tree_dock->set_selected(NULL);
  1132. }
  1133. if (get_edited_scene() && get_edited_scene()->get_filename() != String()) {
  1134. String source_scene = get_edited_scene()->get_filename();
  1135. if (FileAccess::exists(source_scene + ".import")) {
  1136. editable_warning = TTR("This scene was imported, so changes to it will not be kept.\nInstancing it or inheriting will allow making changes to it.\nPlease read the documentation relevant to importing scenes to better understand this workflow.");
  1137. }
  1138. }
  1139. } else {
  1140. if (current_obj->is_class("ScriptEditorDebuggerInspectedObject")) {
  1141. editable_warning = TTR("This is a remote object so changes to it will not be kept.\nPlease read the documentation relevant to debugging to better understand this workflow.");
  1142. capitalize = false;
  1143. disable_folding = true;
  1144. }
  1145. get_inspector()->edit(current_obj);
  1146. node_dock->set_node(NULL);
  1147. }
  1148. inspector_dock->set_warning(editable_warning);
  1149. if (get_inspector()->is_capitalize_paths_enabled() != capitalize) {
  1150. get_inspector()->set_enable_capitalize_paths(capitalize);
  1151. }
  1152. if (get_inspector()->is_using_folding() == disable_folding) {
  1153. get_inspector()->set_use_folding(!disable_folding);
  1154. }
  1155. /* Take care of PLUGIN EDITOR */
  1156. if (!inspector_only) {
  1157. EditorPlugin *main_plugin = editor_data.get_editor(current_obj);
  1158. if (main_plugin) {
  1159. // special case if use of external editor is true
  1160. if (main_plugin->get_name() == "Script" && (bool(EditorSettings::get_singleton()->get("text_editor/external/use_external_editor")) || overrides_external_editor(current_obj))) {
  1161. if (!changing_scene)
  1162. main_plugin->edit(current_obj);
  1163. }
  1164. else if (main_plugin != editor_plugin_screen && (!ScriptEditor::get_singleton() || !ScriptEditor::get_singleton()->is_visible_in_tree() || ScriptEditor::get_singleton()->can_take_away_focus())) {
  1165. // update screen main_plugin
  1166. if (!changing_scene) {
  1167. if (editor_plugin_screen)
  1168. editor_plugin_screen->make_visible(false);
  1169. editor_plugin_screen = main_plugin;
  1170. editor_plugin_screen->edit(current_obj);
  1171. editor_plugin_screen->make_visible(true);
  1172. int plugin_count = editor_data.get_editor_plugin_count();
  1173. for (int i = 0; i < plugin_count; i++) {
  1174. editor_data.get_editor_plugin(i)->notify_main_screen_changed(editor_plugin_screen->get_name());
  1175. }
  1176. for (int i = 0; i < editor_table.size(); i++) {
  1177. main_editor_buttons[i]->set_pressed(editor_table[i] == main_plugin);
  1178. }
  1179. }
  1180. } else {
  1181. editor_plugin_screen->edit(current_obj);
  1182. }
  1183. }
  1184. Vector<EditorPlugin *> sub_plugins = editor_data.get_subeditors(current_obj);
  1185. if (!sub_plugins.empty()) {
  1186. _display_top_editors(false);
  1187. _set_top_editors(sub_plugins);
  1188. _set_editing_top_editors(current_obj);
  1189. _display_top_editors(true);
  1190. } else if (!editor_plugins_over->get_plugins_list().empty()) {
  1191. _hide_top_editors();
  1192. }
  1193. }
  1194. inspector_dock->update(current_obj);
  1195. inspector_dock->update_keying();
  1196. }
  1197. void EditorNode::_run(bool p_current, const String &p_custom) {
  1198. if (editor_run.get_status() == EditorRun::STATUS_PLAY) {
  1199. play_button->set_pressed(!_playing_edited);
  1200. play_scene_button->set_pressed(_playing_edited);
  1201. return;
  1202. }
  1203. play_button->set_pressed(false);
  1204. play_button->set_icon(gui_base->get_icon("MainPlay", "EditorIcons"));
  1205. play_scene_button->set_pressed(false);
  1206. play_scene_button->set_icon(gui_base->get_icon("PlayScene", "EditorIcons"));
  1207. play_custom_scene_button->set_pressed(false);
  1208. play_custom_scene_button->set_icon(gui_base->get_icon("PlayCustom", "EditorIcons"));
  1209. String main_scene;
  1210. String run_filename;
  1211. String args;
  1212. if (p_current || (editor_data.get_edited_scene_root() && p_custom == editor_data.get_edited_scene_root()->get_filename())) {
  1213. Node *scene = editor_data.get_edited_scene_root();
  1214. if (!scene) {
  1215. show_accept(TTR("There is no defined scene to run."), TTR("I see..."));
  1216. return;
  1217. }
  1218. if (scene->get_filename() == "") {
  1219. current_option = -1;
  1220. _menu_option_confirm(FILE_SAVE_BEFORE_RUN, false);
  1221. return;
  1222. }
  1223. run_filename = scene->get_filename();
  1224. } else if (p_custom != "") {
  1225. run_filename = p_custom;
  1226. }
  1227. if (run_filename == "") {
  1228. //evidently, run the scene
  1229. main_scene = GLOBAL_DEF("application/run/main_scene", "");
  1230. if (main_scene == "") {
  1231. current_option = -1;
  1232. pick_main_scene->set_text(TTR("No main scene has ever been defined, select one?\nYou can change it later in \"Project Settings\" under the 'application' category."));
  1233. pick_main_scene->popup_centered_minsize();
  1234. return;
  1235. }
  1236. if (!FileAccess::exists(main_scene)) {
  1237. current_option = -1;
  1238. pick_main_scene->set_text(vformat(TTR("Selected scene '%s' does not exist, select a valid one?\nYou can change it later in \"Project Settings\" under the 'application' category."), main_scene));
  1239. pick_main_scene->popup_centered_minsize();
  1240. return;
  1241. }
  1242. if (ResourceLoader::get_resource_type(main_scene) != "PackedScene") {
  1243. current_option = -1;
  1244. pick_main_scene->set_text(vformat(TTR("Selected scene '%s' is not a scene file, select a valid one?\nYou can change it later in \"Project Settings\" under the 'application' category."), main_scene));
  1245. pick_main_scene->popup_centered_minsize();
  1246. return;
  1247. }
  1248. }
  1249. if (bool(EDITOR_GET("run/auto_save/save_before_running"))) {
  1250. if (unsaved_cache) {
  1251. Node *scene = editor_data.get_edited_scene_root();
  1252. if (scene) { //only autosave if there is a scene obviously
  1253. if (scene->get_filename() == "") {
  1254. show_accept(TTR("Current scene was never saved, please save it prior to running."), TTR("I see..."));
  1255. return;
  1256. }
  1257. _save_scene_with_preview(scene->get_filename());
  1258. }
  1259. }
  1260. _menu_option(FILE_SAVE_ALL_SCENES);
  1261. editor_data.save_editor_external_data();
  1262. }
  1263. if (!call_build())
  1264. return;
  1265. if (bool(EDITOR_GET("run/output/always_clear_output_on_play"))) {
  1266. log->clear();
  1267. }
  1268. if (bool(EDITOR_GET("run/output/always_open_output_on_play"))) {
  1269. make_bottom_panel_item_visible(log);
  1270. }
  1271. List<String> breakpoints;
  1272. editor_data.get_editor_breakpoints(&breakpoints);
  1273. args = ProjectSettings::get_singleton()->get("editor/main_run_args");
  1274. Error error = editor_run.run(run_filename, args, breakpoints);
  1275. if (error != OK) {
  1276. show_accept(TTR("Could not start subprocess!"), TTR("I see..."));
  1277. return;
  1278. }
  1279. emit_signal("play_pressed");
  1280. if (p_current) {
  1281. play_scene_button->set_pressed(true);
  1282. play_scene_button->set_icon(gui_base->get_icon("Reload", "EditorIcons"));
  1283. } else if (p_custom != "") {
  1284. run_custom_filename = p_custom;
  1285. play_custom_scene_button->set_pressed(true);
  1286. play_custom_scene_button->set_icon(gui_base->get_icon("Reload", "EditorIcons"));
  1287. } else {
  1288. play_button->set_pressed(true);
  1289. play_button->set_icon(gui_base->get_icon("Reload", "EditorIcons"));
  1290. }
  1291. stop_button->set_disabled(false);
  1292. _playing_edited = p_current;
  1293. }
  1294. void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
  1295. if (!p_confirmed) //this may be a hack..
  1296. current_option = (MenuOptions)p_option;
  1297. switch (p_option) {
  1298. case FILE_NEW_SCENE: {
  1299. int idx = editor_data.add_edited_scene(-1);
  1300. _scene_tab_changed(idx);
  1301. editor_data.clear_editor_states();
  1302. _update_scene_tabs();
  1303. } break;
  1304. case FILE_NEW_INHERITED_SCENE:
  1305. case FILE_OPEN_SCENE: {
  1306. file->set_mode(EditorFileDialog::MODE_OPEN_FILE);
  1307. List<String> extensions;
  1308. ResourceLoader::get_recognized_extensions_for_type("PackedScene", &extensions);
  1309. file->clear_filters();
  1310. for (int i = 0; i < extensions.size(); i++) {
  1311. file->add_filter("*." + extensions[i] + " ; " + extensions[i].to_upper());
  1312. }
  1313. Node *scene = editor_data.get_edited_scene_root();
  1314. if (scene) {
  1315. file->set_current_path(scene->get_filename());
  1316. };
  1317. file->set_title(p_option == FILE_OPEN_SCENE ? TTR("Open Scene") : TTR("Open Base Scene"));
  1318. file->popup_centered_ratio();
  1319. } break;
  1320. case FILE_QUICK_OPEN_SCENE: {
  1321. quick_open->popup("PackedScene", true);
  1322. quick_open->set_title(TTR("Quick Open Scene..."));
  1323. } break;
  1324. case FILE_QUICK_OPEN_SCRIPT: {
  1325. quick_open->popup("Script", true);
  1326. quick_open->set_title(TTR("Quick Open Script..."));
  1327. } break;
  1328. case FILE_OPEN_PREV: {
  1329. if (previous_scenes.empty())
  1330. break;
  1331. opening_prev = true;
  1332. open_request(previous_scenes.back()->get());
  1333. } break;
  1334. case FILE_CLOSE_ALL_AND_QUIT:
  1335. case FILE_CLOSE_ALL_AND_RUN_PROJECT_MANAGER:
  1336. case FILE_CLOSE: {
  1337. if (!p_confirmed && (unsaved_cache || p_option == FILE_CLOSE_ALL_AND_QUIT || p_option == FILE_CLOSE_ALL_AND_RUN_PROJECT_MANAGER)) {
  1338. tab_closing = p_option == FILE_CLOSE ? editor_data.get_edited_scene() : _next_unsaved_scene(false);
  1339. String scene_filename = editor_data.get_edited_scene_root(tab_closing)->get_filename();
  1340. save_confirmation->get_ok()->set_text(TTR("Save & Close"));
  1341. save_confirmation->set_text(vformat(TTR("Save changes to '%s' before closing?"), scene_filename != "" ? scene_filename : "unsaved scene"));
  1342. save_confirmation->popup_centered_minsize();
  1343. break;
  1344. } else {
  1345. tab_closing = editor_data.get_edited_scene();
  1346. }
  1347. } // fallthrough
  1348. case SCENE_TAB_CLOSE:
  1349. case FILE_SAVE_SCENE: {
  1350. int scene_idx = (p_option == FILE_SAVE_SCENE) ? -1 : tab_closing;
  1351. Node *scene = editor_data.get_edited_scene_root(scene_idx);
  1352. if (scene && scene->get_filename() != "") {
  1353. if (scene_idx != editor_data.get_edited_scene())
  1354. _save_scene_with_preview(scene->get_filename(), scene_idx);
  1355. else
  1356. _save_scene_with_preview(scene->get_filename());
  1357. if (scene_idx != -1)
  1358. _discard_changes();
  1359. break;
  1360. }
  1361. // fallthrough to save_as
  1362. };
  1363. case FILE_SAVE_AS_SCENE: {
  1364. int scene_idx = (p_option == FILE_SAVE_SCENE || p_option == FILE_SAVE_AS_SCENE) ? -1 : tab_closing;
  1365. Node *scene = editor_data.get_edited_scene_root(scene_idx);
  1366. if (!scene) {
  1367. show_accept(TTR("This operation can't be done without a tree root."), TTR("I see..."));
  1368. break;
  1369. }
  1370. file->set_mode(EditorFileDialog::MODE_SAVE_FILE);
  1371. List<String> extensions;
  1372. Ref<PackedScene> sd = memnew(PackedScene);
  1373. ResourceSaver::get_recognized_extensions(sd, &extensions);
  1374. file->clear_filters();
  1375. for (int i = 0; i < extensions.size(); i++) {
  1376. file->add_filter("*." + extensions[i] + " ; " + extensions[i].to_upper());
  1377. }
  1378. if (scene->get_filename() != "") {
  1379. file->set_current_path(scene->get_filename());
  1380. if (extensions.size()) {
  1381. String ext = scene->get_filename().get_extension().to_lower();
  1382. if (extensions.find(ext) == NULL) {
  1383. file->set_current_path(scene->get_filename().replacen("." + ext, "." + extensions.front()->get()));
  1384. }
  1385. }
  1386. } else {
  1387. String existing;
  1388. if (extensions.size()) {
  1389. String root_name(scene->get_name());
  1390. existing = root_name + "." + extensions.front()->get().to_lower();
  1391. }
  1392. file->set_current_path(existing);
  1393. }
  1394. file->popup_centered_ratio();
  1395. file->set_title(TTR("Save Scene As..."));
  1396. } break;
  1397. case FILE_SAVE_ALL_SCENES: {
  1398. _save_all_scenes();
  1399. } break;
  1400. case FILE_SAVE_BEFORE_RUN: {
  1401. if (!p_confirmed) {
  1402. confirmation->get_cancel()->set_text(TTR("No"));
  1403. confirmation->get_ok()->set_text(TTR("Yes"));
  1404. confirmation->set_text(TTR("This scene has never been saved. Save before running?"));
  1405. confirmation->popup_centered_minsize();
  1406. break;
  1407. }
  1408. _menu_option(FILE_SAVE_AS_SCENE);
  1409. _menu_option_confirm(FILE_SAVE_AND_RUN, false);
  1410. } break;
  1411. case FILE_EXPORT_PROJECT: {
  1412. project_export->popup_export();
  1413. } break;
  1414. case FILE_EXPORT_MESH_LIBRARY: {
  1415. if (!editor_data.get_edited_scene_root()) {
  1416. show_accept(TTR("This operation can't be done without a scene."), TTR("I see..."));
  1417. break;
  1418. }
  1419. List<String> extensions;
  1420. Ref<MeshLibrary> ml(memnew(MeshLibrary));
  1421. ResourceSaver::get_recognized_extensions(ml, &extensions);
  1422. file_export_lib->clear_filters();
  1423. for (List<String>::Element *E = extensions.front(); E; E = E->next()) {
  1424. file_export_lib->add_filter("*." + E->get());
  1425. }
  1426. file_export_lib->popup_centered_ratio();
  1427. file_export_lib->set_title(TTR("Export Mesh Library"));
  1428. } break;
  1429. case FILE_EXPORT_TILESET: {
  1430. //Make sure that the scene has a root before trying to convert to tileset
  1431. if (!editor_data.get_edited_scene_root()) {
  1432. show_accept(TTR("This operation can't be done without a root node."), TTR("I see..."));
  1433. break;
  1434. }
  1435. List<String> extensions;
  1436. Ref<TileSet> ml(memnew(TileSet));
  1437. ResourceSaver::get_recognized_extensions(ml, &extensions);
  1438. file_export_lib->clear_filters();
  1439. for (List<String>::Element *E = extensions.front(); E; E = E->next()) {
  1440. file_export_lib->add_filter("*." + E->get());
  1441. }
  1442. file_export_lib->popup_centered_ratio();
  1443. file_export_lib->set_title(TTR("Export Tile Set"));
  1444. } break;
  1445. case FILE_IMPORT_SUBSCENE: {
  1446. if (!editor_data.get_edited_scene_root()) {
  1447. show_accept(TTR("This operation can't be done without a selected node."), TTR("I see..."));
  1448. break;
  1449. }
  1450. scene_tree_dock->import_subscene();
  1451. } break;
  1452. case FILE_EXTERNAL_OPEN_SCENE: {
  1453. if (unsaved_cache && !p_confirmed) {
  1454. confirmation->get_ok()->set_text(TTR("Open"));
  1455. confirmation->set_text(TTR("Current scene not saved. Open anyway?"));
  1456. confirmation->popup_centered_minsize();
  1457. break;
  1458. }
  1459. bool oprev = opening_prev;
  1460. Error err = load_scene(external_file);
  1461. if (err == OK && oprev) {
  1462. previous_scenes.pop_back();
  1463. opening_prev = false;
  1464. }
  1465. } break;
  1466. case EDIT_UNDO: {
  1467. if (Input::get_singleton()->get_mouse_button_mask() & 0x7) {
  1468. log->add_message("Can't UNDO while mouse buttons are pressed.");
  1469. } else {
  1470. String action = editor_data.get_undo_redo().get_current_action_name();
  1471. if (!editor_data.get_undo_redo().undo()) {
  1472. log->add_message("There is nothing to UNDO.");
  1473. } else if (action != "") {
  1474. log->add_message("UNDO: " + action);
  1475. }
  1476. }
  1477. } break;
  1478. case EDIT_REDO: {
  1479. if (Input::get_singleton()->get_mouse_button_mask() & 0x7) {
  1480. log->add_message("Can't REDO while mouse buttons are pressed.");
  1481. } else {
  1482. if (!editor_data.get_undo_redo().redo()) {
  1483. log->add_message("There is nothing to REDO.");
  1484. } else {
  1485. String action = editor_data.get_undo_redo().get_current_action_name();
  1486. log->add_message("REDO: " + action);
  1487. }
  1488. }
  1489. } break;
  1490. case EDIT_REVERT: {
  1491. Node *scene = get_edited_scene();
  1492. if (!scene)
  1493. break;
  1494. String filename = scene->get_filename();
  1495. if (filename == String()) {
  1496. show_warning(TTR("Can't reload a scene that was never saved."));
  1497. break;
  1498. }
  1499. if (unsaved_cache && !p_confirmed) {
  1500. confirmation->get_ok()->set_text(TTR("Revert"));
  1501. confirmation->set_text(TTR("This action cannot be undone. Revert anyway?"));
  1502. confirmation->popup_centered_minsize();
  1503. break;
  1504. }
  1505. int cur_idx = editor_data.get_edited_scene();
  1506. _remove_edited_scene();
  1507. Error err = load_scene(filename);
  1508. if (err != OK)
  1509. ERR_PRINT("Failed to load scene");
  1510. editor_data.move_edited_scene_to_index(cur_idx);
  1511. get_undo_redo()->clear_history();
  1512. scene_tabs->set_current_tab(cur_idx);
  1513. } break;
  1514. case RUN_PLAY: {
  1515. _menu_option_confirm(RUN_STOP, true);
  1516. _run(false);
  1517. } break;
  1518. case RUN_PLAY_CUSTOM_SCENE: {
  1519. if (run_custom_filename.empty() || editor_run.get_status() == EditorRun::STATUS_STOP) {
  1520. _menu_option_confirm(RUN_STOP, true);
  1521. quick_run->popup("PackedScene", true);
  1522. quick_run->set_title(TTR("Quick Run Scene..."));
  1523. play_custom_scene_button->set_pressed(false);
  1524. } else {
  1525. String last_custom_scene = run_custom_filename;
  1526. _menu_option_confirm(RUN_STOP, true);
  1527. _run(false, last_custom_scene);
  1528. }
  1529. } break;
  1530. case RUN_STOP: {
  1531. if (editor_run.get_status() == EditorRun::STATUS_STOP)
  1532. break;
  1533. editor_run.stop();
  1534. run_custom_filename.clear();
  1535. play_button->set_pressed(false);
  1536. play_button->set_icon(gui_base->get_icon("MainPlay", "EditorIcons"));
  1537. play_scene_button->set_pressed(false);
  1538. play_scene_button->set_icon(gui_base->get_icon("PlayScene", "EditorIcons"));
  1539. play_custom_scene_button->set_pressed(false);
  1540. play_custom_scene_button->set_icon(gui_base->get_icon("PlayCustom", "EditorIcons"));
  1541. stop_button->set_disabled(true);
  1542. if (bool(EDITOR_GET("run/output/always_close_output_on_stop"))) {
  1543. for (int i = 0; i < bottom_panel_items.size(); i++) {
  1544. if (bottom_panel_items[i].control == log) {
  1545. _bottom_panel_switch(false, i);
  1546. break;
  1547. }
  1548. }
  1549. }
  1550. emit_signal("stop_pressed");
  1551. } break;
  1552. case RUN_PLAY_SCENE: {
  1553. _save_default_environment();
  1554. _menu_option_confirm(RUN_STOP, true);
  1555. _run(true);
  1556. } break;
  1557. case RUN_PLAY_NATIVE: {
  1558. bool autosave = EDITOR_GET("run/auto_save/save_before_running");
  1559. if (autosave) {
  1560. _menu_option_confirm(FILE_SAVE_ALL_SCENES, false);
  1561. }
  1562. if (run_native->is_deploy_debug_remote_enabled()) {
  1563. _menu_option_confirm(RUN_STOP, true);
  1564. if (!call_build())
  1565. break; // build failed
  1566. emit_signal("play_pressed");
  1567. editor_run.run_native_notify();
  1568. }
  1569. } break;
  1570. case RUN_SCENE_SETTINGS: {
  1571. run_settings_dialog->popup_run_settings();
  1572. } break;
  1573. case RUN_SETTINGS: {
  1574. project_settings->popup_project_settings();
  1575. } break;
  1576. case FILE_QUIT:
  1577. case RUN_PROJECT_MANAGER: {
  1578. if (!p_confirmed) {
  1579. bool save_each = EDITOR_GET("interface/editor/save_each_scene_on_quit");
  1580. if (_next_unsaved_scene(!save_each) == -1) {
  1581. bool confirm = EDITOR_GET("interface/editor/quit_confirmation");
  1582. if (confirm) {
  1583. confirmation->get_ok()->set_text(p_option == FILE_QUIT ? TTR("Quit") : TTR("Yes"));
  1584. confirmation->set_text(p_option == FILE_QUIT ? TTR("Exit the editor?") : TTR("Open Project Manager?"));
  1585. confirmation->popup_centered_minsize();
  1586. } else {
  1587. _discard_changes();
  1588. break;
  1589. }
  1590. } else {
  1591. if (save_each) {
  1592. _menu_option_confirm(p_option == FILE_QUIT ? FILE_CLOSE_ALL_AND_QUIT : FILE_CLOSE_ALL_AND_RUN_PROJECT_MANAGER, false);
  1593. } else {
  1594. String unsaved_scenes;
  1595. int i = _next_unsaved_scene(true, 0);
  1596. while (i != -1) {
  1597. unsaved_scenes += "\n " + editor_data.get_edited_scene_root(i)->get_filename();
  1598. i = _next_unsaved_scene(true, ++i);
  1599. }
  1600. save_confirmation->get_ok()->set_text(TTR("Save & Quit"));
  1601. save_confirmation->set_text((p_option == FILE_QUIT ? TTR("Save changes to the following scene(s) before quitting?") : TTR("Save changes the following scene(s) before opening Project Manager?")) + unsaved_scenes);
  1602. save_confirmation->popup_centered_minsize();
  1603. }
  1604. }
  1605. OS::get_singleton()->request_attention();
  1606. break;
  1607. }
  1608. if (_next_unsaved_scene(true) != -1) {
  1609. _save_all_scenes();
  1610. }
  1611. _discard_changes();
  1612. } break;
  1613. case RUN_FILE_SERVER: {
  1614. bool ischecked = debug_menu->get_popup()->is_item_checked(debug_menu->get_popup()->get_item_index(RUN_FILE_SERVER));
  1615. if (ischecked) {
  1616. file_server->stop();
  1617. run_native->set_deploy_dumb(false);
  1618. } else {
  1619. file_server->start();
  1620. run_native->set_deploy_dumb(true);
  1621. }
  1622. debug_menu->get_popup()->set_item_checked(debug_menu->get_popup()->get_item_index(RUN_FILE_SERVER), !ischecked);
  1623. EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_file_server", !ischecked);
  1624. } break;
  1625. case RUN_LIVE_DEBUG: {
  1626. bool ischecked = debug_menu->get_popup()->is_item_checked(debug_menu->get_popup()->get_item_index(RUN_LIVE_DEBUG));
  1627. debug_menu->get_popup()->set_item_checked(debug_menu->get_popup()->get_item_index(RUN_LIVE_DEBUG), !ischecked);
  1628. ScriptEditor::get_singleton()->get_debugger()->set_live_debugging(!ischecked);
  1629. EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_live_debug", !ischecked);
  1630. } break;
  1631. case RUN_DEPLOY_REMOTE_DEBUG: {
  1632. bool ischecked = debug_menu->get_popup()->is_item_checked(debug_menu->get_popup()->get_item_index(RUN_DEPLOY_REMOTE_DEBUG));
  1633. debug_menu->get_popup()->set_item_checked(debug_menu->get_popup()->get_item_index(RUN_DEPLOY_REMOTE_DEBUG), !ischecked);
  1634. run_native->set_deploy_debug_remote(!ischecked);
  1635. EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_deploy_remote_debug", !ischecked);
  1636. } break;
  1637. case RUN_DEBUG_COLLISONS: {
  1638. bool ischecked = debug_menu->get_popup()->is_item_checked(debug_menu->get_popup()->get_item_index(RUN_DEBUG_COLLISONS));
  1639. debug_menu->get_popup()->set_item_checked(debug_menu->get_popup()->get_item_index(RUN_DEBUG_COLLISONS), !ischecked);
  1640. run_native->set_debug_collisions(!ischecked);
  1641. editor_run.set_debug_collisions(!ischecked);
  1642. EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_debug_collisons", !ischecked);
  1643. } break;
  1644. case RUN_DEBUG_NAVIGATION: {
  1645. bool ischecked = debug_menu->get_popup()->is_item_checked(debug_menu->get_popup()->get_item_index(RUN_DEBUG_NAVIGATION));
  1646. debug_menu->get_popup()->set_item_checked(debug_menu->get_popup()->get_item_index(RUN_DEBUG_NAVIGATION), !ischecked);
  1647. run_native->set_debug_navigation(!ischecked);
  1648. editor_run.set_debug_navigation(!ischecked);
  1649. EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_debug_navigation", !ischecked);
  1650. } break;
  1651. case RUN_RELOAD_SCRIPTS: {
  1652. bool ischecked = debug_menu->get_popup()->is_item_checked(debug_menu->get_popup()->get_item_index(RUN_RELOAD_SCRIPTS));
  1653. debug_menu->get_popup()->set_item_checked(debug_menu->get_popup()->get_item_index(RUN_RELOAD_SCRIPTS), !ischecked);
  1654. ScriptEditor::get_singleton()->set_live_auto_reload_running_scripts(!ischecked);
  1655. EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_reload_scripts", !ischecked);
  1656. } break;
  1657. case SETTINGS_UPDATE_ALWAYS: {
  1658. update_menu->get_popup()->set_item_checked(0, true);
  1659. update_menu->get_popup()->set_item_checked(1, false);
  1660. OS::get_singleton()->set_low_processor_usage_mode(false);
  1661. EditorSettings::get_singleton()->set_project_metadata("editor_options", "update_always", true);
  1662. show_accept(TTR("This option is deprecated. Situations where refresh must be forced are now considered a bug. Please report."), TTR("I see..."));
  1663. } break;
  1664. case SETTINGS_UPDATE_CHANGES: {
  1665. update_menu->get_popup()->set_item_checked(0, false);
  1666. update_menu->get_popup()->set_item_checked(1, true);
  1667. OS::get_singleton()->set_low_processor_usage_mode(true);
  1668. EditorSettings::get_singleton()->set_project_metadata("editor_options", "update_always", false);
  1669. } break;
  1670. case SETTINGS_UPDATE_SPINNER_HIDE: {
  1671. update_menu->set_icon(gui_base->get_icon("Collapse", "EditorIcons"));
  1672. update_menu->get_popup()->toggle_item_checked(3);
  1673. bool checked = update_menu->get_popup()->is_item_checked(3);
  1674. EditorSettings::get_singleton()->set_project_metadata("editor_options", "update_spinner_hide", checked);
  1675. } break;
  1676. case SETTINGS_PREFERENCES: {
  1677. settings_config_dialog->popup_edit_settings();
  1678. } break;
  1679. case SETTINGS_MANAGE_EXPORT_TEMPLATES: {
  1680. export_template_manager->popup_manager();
  1681. } break;
  1682. case SETTINGS_TOGGLE_FULLSCREEN: {
  1683. OS::get_singleton()->set_window_fullscreen(!OS::get_singleton()->is_window_fullscreen());
  1684. } break;
  1685. case SETTINGS_PICK_MAIN_SCENE: {
  1686. file->set_mode(EditorFileDialog::MODE_OPEN_FILE);
  1687. List<String> extensions;
  1688. ResourceLoader::get_recognized_extensions_for_type("PackedScene", &extensions);
  1689. file->clear_filters();
  1690. for (int i = 0; i < extensions.size(); i++) {
  1691. file->add_filter("*." + extensions[i] + " ; " + extensions[i].to_upper());
  1692. }
  1693. Node *scene = editor_data.get_edited_scene_root();
  1694. if (scene) {
  1695. file->set_current_path(scene->get_filename());
  1696. };
  1697. file->set_title(TTR("Pick a Main Scene"));
  1698. file->popup_centered_ratio();
  1699. } break;
  1700. case HELP_CLASSES: {
  1701. emit_signal("request_help_index", "");
  1702. } break;
  1703. case HELP_SEARCH: {
  1704. emit_signal("request_help_search", "");
  1705. } break;
  1706. case HELP_DOCS: {
  1707. OS::get_singleton()->shell_open("http://docs.godotengine.org/");
  1708. } break;
  1709. case HELP_QA: {
  1710. OS::get_singleton()->shell_open("https://godotengine.org/qa/");
  1711. } break;
  1712. case HELP_ISSUES: {
  1713. OS::get_singleton()->shell_open("https://github.com/godotengine/godot/issues");
  1714. } break;
  1715. case HELP_COMMUNITY: {
  1716. OS::get_singleton()->shell_open("https://godotengine.org/community");
  1717. } break;
  1718. case HELP_ABOUT: {
  1719. about->popup_centered_minsize(Size2(780, 500) * EDSCALE);
  1720. } break;
  1721. case SET_VIDEO_DRIVER_SAVE_AND_RESTART: {
  1722. ProjectSettings::get_singleton()->set("rendering/quality/driver/driver_name", video_driver_request);
  1723. ProjectSettings::get_singleton()->save();
  1724. save_all_scenes_and_restart();
  1725. } break;
  1726. default: {
  1727. if (p_option >= IMPORT_PLUGIN_BASE) {
  1728. }
  1729. }
  1730. }
  1731. }
  1732. void EditorNode::_tool_menu_option(int p_idx) {
  1733. switch (tool_menu->get_item_id(p_idx)) {
  1734. case TOOLS_ORPHAN_RESOURCES: {
  1735. orphan_resources->show();
  1736. } break;
  1737. case TOOLS_CUSTOM: {
  1738. if (tool_menu->get_item_submenu(p_idx) == "") {
  1739. Array params = tool_menu->get_item_metadata(p_idx);
  1740. Object *handler = ObjectDB::get_instance(params[0]);
  1741. String callback = params[1];
  1742. Variant *ud = &params[2];
  1743. Variant::CallError ce;
  1744. handler->call(callback, (const Variant **)&ud, 1, ce);
  1745. if (ce.error != Variant::CallError::CALL_OK) {
  1746. String err = Variant::get_call_error_text(handler, callback, (const Variant **)&ud, 1, ce);
  1747. ERR_PRINTS("Error calling function from tool menu: " + err);
  1748. }
  1749. } // else it's a submenu so don't do anything.
  1750. } break;
  1751. }
  1752. }
  1753. int EditorNode::_next_unsaved_scene(bool p_valid_filename, int p_start) {
  1754. for (int i = p_start; i < editor_data.get_edited_scene_count(); i++) {
  1755. if (!editor_data.get_edited_scene_root(i))
  1756. continue;
  1757. int current = editor_data.get_edited_scene();
  1758. bool unsaved = (i == current) ? saved_version != editor_data.get_undo_redo().get_version() : editor_data.get_scene_version(i) != 0;
  1759. if (unsaved) {
  1760. String scene_filename = editor_data.get_edited_scene_root(i)->get_filename();
  1761. if (p_valid_filename && scene_filename.length() == 0)
  1762. continue;
  1763. return i;
  1764. }
  1765. }
  1766. return -1;
  1767. }
  1768. void EditorNode::_discard_changes(const String &p_str) {
  1769. switch (current_option) {
  1770. case FILE_CLOSE_ALL_AND_QUIT:
  1771. case FILE_CLOSE_ALL_AND_RUN_PROJECT_MANAGER:
  1772. case FILE_CLOSE:
  1773. case SCENE_TAB_CLOSE: {
  1774. _remove_scene(tab_closing);
  1775. _update_scene_tabs();
  1776. if (current_option == FILE_CLOSE_ALL_AND_QUIT || current_option == FILE_CLOSE_ALL_AND_RUN_PROJECT_MANAGER) {
  1777. if (_next_unsaved_scene(false) == -1) {
  1778. current_option = current_option == FILE_CLOSE_ALL_AND_QUIT ? FILE_QUIT : RUN_PROJECT_MANAGER;
  1779. _discard_changes();
  1780. } else {
  1781. _menu_option_confirm(current_option, false);
  1782. }
  1783. } else {
  1784. current_option = -1;
  1785. save_confirmation->hide();
  1786. }
  1787. } break;
  1788. case FILE_QUIT: {
  1789. _menu_option_confirm(RUN_STOP, true);
  1790. exiting = true;
  1791. get_tree()->quit();
  1792. } break;
  1793. case RUN_PROJECT_MANAGER: {
  1794. _menu_option_confirm(RUN_STOP, true);
  1795. exiting = true;
  1796. get_tree()->quit();
  1797. String exec = OS::get_singleton()->get_executable_path();
  1798. List<String> args;
  1799. args.push_back("--path");
  1800. args.push_back(exec.get_base_dir());
  1801. args.push_back("--project-manager");
  1802. OS::ProcessID pid = 0;
  1803. Error err = OS::get_singleton()->execute(exec, args, false, &pid);
  1804. ERR_FAIL_COND(err);
  1805. } break;
  1806. }
  1807. }
  1808. void EditorNode::_update_debug_options() {
  1809. bool check_deploy_remote = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_deploy_remote_debug", false);
  1810. bool check_file_server = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_file_server", false);
  1811. bool check_debug_collisons = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_debug_collisons", false);
  1812. bool check_debug_navigation = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_debug_navigation", false);
  1813. bool check_live_debug = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_live_debug", false);
  1814. bool check_reload_scripts = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_reload_scripts", false);
  1815. if (check_deploy_remote) _menu_option_confirm(RUN_DEPLOY_REMOTE_DEBUG, true);
  1816. if (check_file_server) _menu_option_confirm(RUN_FILE_SERVER, true);
  1817. if (check_debug_collisons) _menu_option_confirm(RUN_DEBUG_COLLISONS, true);
  1818. if (check_debug_navigation) _menu_option_confirm(RUN_DEBUG_NAVIGATION, true);
  1819. if (check_live_debug) _menu_option_confirm(RUN_LIVE_DEBUG, true);
  1820. if (check_reload_scripts) _menu_option_confirm(RUN_RELOAD_SCRIPTS, true);
  1821. }
  1822. Control *EditorNode::get_viewport() {
  1823. return viewport;
  1824. }
  1825. void EditorNode::_editor_select(int p_which) {
  1826. static bool selecting = false;
  1827. if (selecting || changing_scene)
  1828. return;
  1829. selecting = true;
  1830. ERR_FAIL_INDEX(p_which, editor_table.size());
  1831. for (int i = 0; i < main_editor_buttons.size(); i++) {
  1832. main_editor_buttons[i]->set_pressed(i == p_which);
  1833. }
  1834. selecting = false;
  1835. EditorPlugin *new_editor = editor_table[p_which];
  1836. ERR_FAIL_COND(!new_editor);
  1837. if (editor_plugin_screen == new_editor)
  1838. return;
  1839. if (editor_plugin_screen) {
  1840. editor_plugin_screen->make_visible(false);
  1841. }
  1842. editor_plugin_screen = new_editor;
  1843. editor_plugin_screen->make_visible(true);
  1844. editor_plugin_screen->selected_notify();
  1845. int plugin_count = editor_data.get_editor_plugin_count();
  1846. for (int i = 0; i < plugin_count; i++) {
  1847. editor_data.get_editor_plugin(i)->notify_main_screen_changed(editor_plugin_screen->get_name());
  1848. }
  1849. if (EditorSettings::get_singleton()->get("interface/editor/separate_distraction_mode")) {
  1850. if (p_which == EDITOR_SCRIPT) {
  1851. set_distraction_free_mode(script_distraction);
  1852. } else {
  1853. set_distraction_free_mode(scene_distraction);
  1854. }
  1855. }
  1856. }
  1857. void EditorNode::add_editor_plugin(EditorPlugin *p_editor) {
  1858. if (p_editor->has_main_screen()) {
  1859. ToolButton *tb = memnew(ToolButton);
  1860. tb->set_toggle_mode(true);
  1861. tb->connect("pressed", singleton, "_editor_select", varray(singleton->main_editor_buttons.size()));
  1862. tb->set_text(p_editor->get_name());
  1863. Ref<Texture> icon = p_editor->get_icon();
  1864. if (icon.is_valid()) {
  1865. tb->set_icon(icon);
  1866. } else if (singleton->gui_base->has_icon(p_editor->get_name(), "EditorIcons")) {
  1867. tb->set_icon(singleton->gui_base->get_icon(p_editor->get_name(), "EditorIcons"));
  1868. }
  1869. tb->set_name(p_editor->get_name());
  1870. singleton->main_editor_buttons.push_back(tb);
  1871. singleton->main_editor_button_vb->add_child(tb);
  1872. singleton->editor_table.push_back(p_editor);
  1873. singleton->distraction_free->raise();
  1874. }
  1875. singleton->editor_data.add_editor_plugin(p_editor);
  1876. singleton->add_child(p_editor);
  1877. }
  1878. void EditorNode::remove_editor_plugin(EditorPlugin *p_editor) {
  1879. if (p_editor->has_main_screen()) {
  1880. for (int i = 0; i < singleton->main_editor_buttons.size(); i++) {
  1881. if (p_editor->get_name() == singleton->main_editor_buttons[i]->get_text()) {
  1882. if (singleton->main_editor_buttons[i]->is_pressed()) {
  1883. singleton->_editor_select(EDITOR_SCRIPT);
  1884. }
  1885. memdelete(singleton->main_editor_buttons[i]);
  1886. singleton->main_editor_buttons.remove(i);
  1887. break;
  1888. }
  1889. }
  1890. singleton->editor_table.erase(p_editor);
  1891. }
  1892. p_editor->make_visible(false);
  1893. p_editor->clear();
  1894. singleton->editor_plugins_over->get_plugins_list().erase(p_editor);
  1895. singleton->remove_child(p_editor);
  1896. singleton->editor_data.remove_editor_plugin(p_editor);
  1897. }
  1898. void EditorNode::_update_addon_config() {
  1899. if (_initializing_addons)
  1900. return;
  1901. Vector<String> enabled_addons;
  1902. for (Map<String, EditorPlugin *>::Element *E = plugin_addons.front(); E; E = E->next()) {
  1903. enabled_addons.push_back(E->key());
  1904. }
  1905. if (enabled_addons.size() == 0) {
  1906. ProjectSettings::get_singleton()->set("editor_plugins/enabled", Variant());
  1907. } else {
  1908. ProjectSettings::get_singleton()->set("editor_plugins/enabled", enabled_addons);
  1909. }
  1910. project_settings->queue_save();
  1911. }
  1912. void EditorNode::set_addon_plugin_enabled(const String &p_addon, bool p_enabled) {
  1913. ERR_FAIL_COND(p_enabled && plugin_addons.has(p_addon));
  1914. ERR_FAIL_COND(!p_enabled && !plugin_addons.has(p_addon));
  1915. if (!p_enabled) {
  1916. EditorPlugin *addon = plugin_addons[p_addon];
  1917. remove_editor_plugin(addon);
  1918. memdelete(addon); //bye
  1919. plugin_addons.erase(p_addon);
  1920. _update_addon_config();
  1921. return;
  1922. }
  1923. Ref<ConfigFile> cf;
  1924. cf.instance();
  1925. String addon_path = "res://addons/" + p_addon + "/plugin.cfg";
  1926. Error err = cf->load(addon_path);
  1927. if (err != OK) {
  1928. show_warning(vformat(TTR("Unable to enable addon plugin at: '%s' parsing of config failed."), addon_path));
  1929. return;
  1930. }
  1931. if (!cf->has_section_key("plugin", "script")) {
  1932. show_warning(vformat(TTR("Unable to find script field for addon plugin at: 'res://addons/%s'."), p_addon));
  1933. return;
  1934. }
  1935. String path = cf->get_value("plugin", "script");
  1936. path = "res://addons/" + p_addon + "/" + path;
  1937. Ref<Script> script = ResourceLoader::load(path);
  1938. if (script.is_null()) {
  1939. show_warning(vformat(TTR("Unable to load addon script from path: '%s'."), path));
  1940. return;
  1941. }
  1942. //could check inheritance..
  1943. if (String(script->get_instance_base_type()) != "EditorPlugin") {
  1944. show_warning(vformat(TTR("Unable to load addon script from path: '%s' Base type is not EditorPlugin."), path));
  1945. return;
  1946. }
  1947. if (!script->is_tool()) {
  1948. show_warning(vformat(TTR("Unable to load addon script from path: '%s' Script is not in tool mode."), path));
  1949. return;
  1950. }
  1951. EditorPlugin *ep = memnew(EditorPlugin);
  1952. ep->set_script(script.get_ref_ptr());
  1953. plugin_addons[p_addon] = ep;
  1954. add_editor_plugin(ep);
  1955. _update_addon_config();
  1956. }
  1957. bool EditorNode::is_addon_plugin_enabled(const String &p_addon) const {
  1958. return plugin_addons.has(p_addon);
  1959. }
  1960. void EditorNode::_remove_edited_scene() {
  1961. int new_index = editor_data.get_edited_scene();
  1962. int old_index = new_index;
  1963. if (new_index > 0) {
  1964. new_index = new_index - 1;
  1965. } else if (editor_data.get_edited_scene_count() > 1) {
  1966. new_index = 1;
  1967. } else {
  1968. editor_data.add_edited_scene(-1);
  1969. new_index = 1;
  1970. }
  1971. if (editor_data.get_scene_path(old_index) != String()) {
  1972. ScriptEditor::get_singleton()->close_builtin_scripts_from_scene(editor_data.get_scene_path(old_index));
  1973. }
  1974. _scene_tab_changed(new_index);
  1975. editor_data.remove_scene(old_index);
  1976. editor_data.get_undo_redo().clear_history();
  1977. _update_title();
  1978. _update_scene_tabs();
  1979. }
  1980. void EditorNode::_remove_scene(int index) {
  1981. if (editor_data.get_edited_scene() == index) {
  1982. //Scene to remove is current scene
  1983. _remove_edited_scene();
  1984. } else {
  1985. //Scene to remove is not active scene
  1986. editor_data.remove_scene(index);
  1987. }
  1988. }
  1989. void EditorNode::set_edited_scene(Node *p_scene) {
  1990. if (get_editor_data().get_edited_scene_root()) {
  1991. if (get_editor_data().get_edited_scene_root()->get_parent() == scene_root)
  1992. scene_root->remove_child(get_editor_data().get_edited_scene_root());
  1993. }
  1994. get_editor_data().set_edited_scene_root(p_scene);
  1995. if (Object::cast_to<Popup>(p_scene))
  1996. Object::cast_to<Popup>(p_scene)->show(); //show popups
  1997. scene_tree_dock->set_edited_scene(p_scene);
  1998. if (get_tree())
  1999. get_tree()->set_edited_scene_root(p_scene);
  2000. if (p_scene) {
  2001. if (p_scene->get_parent() != scene_root)
  2002. scene_root->add_child(p_scene);
  2003. }
  2004. }
  2005. int EditorNode::_get_current_main_editor() {
  2006. for (int i = 0; i < editor_table.size(); i++) {
  2007. if (editor_table[i] == editor_plugin_screen)
  2008. return i;
  2009. }
  2010. return 0;
  2011. }
  2012. Dictionary EditorNode::_get_main_scene_state() {
  2013. Dictionary state;
  2014. state["main_tab"] = _get_current_main_editor();
  2015. state["scene_tree_offset"] = scene_tree_dock->get_tree_editor()->get_scene_tree()->get_vscroll_bar()->get_value();
  2016. state["property_edit_offset"] = get_inspector()->get_scroll_offset();
  2017. state["saved_version"] = saved_version;
  2018. state["node_filter"] = scene_tree_dock->get_filter();
  2019. return state;
  2020. }
  2021. void EditorNode::_set_main_scene_state(Dictionary p_state, Node *p_for_scene) {
  2022. if (get_edited_scene() != p_for_scene && p_for_scene != NULL)
  2023. return; //not for this scene
  2024. changing_scene = false;
  2025. int current = -1;
  2026. for (int i = 0; i < editor_table.size(); i++) {
  2027. if (editor_plugin_screen == editor_table[i]) {
  2028. current = i;
  2029. break;
  2030. }
  2031. }
  2032. if (p_state.has("editor_index")) {
  2033. int index = p_state["editor_index"];
  2034. if (current < 2) { //if currently in spatial/2d, only switch to spatial/2d. if currently in script, stay there
  2035. if (index < 2 || !get_edited_scene()) {
  2036. _editor_select(index);
  2037. }
  2038. }
  2039. }
  2040. if (get_edited_scene()) {
  2041. if (current < 2) {
  2042. //use heuristic instead
  2043. int n2d = 0, n3d = 0;
  2044. _find_node_types(get_edited_scene(), n2d, n3d);
  2045. if (n2d > n3d) {
  2046. _editor_select(EDITOR_2D);
  2047. } else if (n3d > n2d) {
  2048. _editor_select(EDITOR_3D);
  2049. }
  2050. }
  2051. }
  2052. if (p_state.has("scene_tree_offset"))
  2053. scene_tree_dock->get_tree_editor()->get_scene_tree()->get_vscroll_bar()->set_value(p_state["scene_tree_offset"]);
  2054. if (p_state.has("property_edit_offset"))
  2055. get_inspector()->set_scroll_offset(p_state["property_edit_offset"]);
  2056. if (p_state.has("node_filter"))
  2057. scene_tree_dock->set_filter(p_state["node_filter"]);
  2058. //this should only happen at the very end
  2059. ScriptEditor::get_singleton()->get_debugger()->update_live_edit_root();
  2060. ScriptEditor::get_singleton()->set_scene_root_script(editor_data.get_scene_root_script(editor_data.get_edited_scene()));
  2061. editor_data.notify_edited_scene_changed();
  2062. }
  2063. void EditorNode::set_current_version(uint64_t p_version) {
  2064. saved_version = p_version;
  2065. editor_data.set_edited_scene_version(p_version);
  2066. }
  2067. bool EditorNode::is_changing_scene() const {
  2068. return changing_scene;
  2069. }
  2070. void EditorNode::_clear_undo_history() {
  2071. get_undo_redo()->clear_history();
  2072. }
  2073. void EditorNode::set_current_scene(int p_idx) {
  2074. if (editor_data.check_and_update_scene(p_idx)) {
  2075. call_deferred("_clear_undo_history");
  2076. }
  2077. changing_scene = true;
  2078. editor_data.save_edited_scene_state(editor_selection, &editor_history, _get_main_scene_state());
  2079. if (get_editor_data().get_edited_scene_root()) {
  2080. if (get_editor_data().get_edited_scene_root()->get_parent() == scene_root)
  2081. scene_root->remove_child(get_editor_data().get_edited_scene_root());
  2082. }
  2083. editor_selection->clear();
  2084. editor_data.set_edited_scene(p_idx);
  2085. Node *new_scene = editor_data.get_edited_scene_root();
  2086. if (Object::cast_to<Popup>(new_scene))
  2087. Object::cast_to<Popup>(new_scene)->show(); //show popups
  2088. scene_tree_dock->set_edited_scene(new_scene);
  2089. if (get_tree())
  2090. get_tree()->set_edited_scene_root(new_scene);
  2091. if (new_scene) {
  2092. if (new_scene->get_parent() != scene_root)
  2093. scene_root->add_child(new_scene);
  2094. }
  2095. Dictionary state = editor_data.restore_edited_scene_state(editor_selection, &editor_history);
  2096. _edit_current();
  2097. call_deferred("_set_main_scene_state", state, get_edited_scene()); //do after everything else is done setting up
  2098. }
  2099. bool EditorNode::is_scene_open(const String &p_path) {
  2100. for (int i = 0; i < editor_data.get_edited_scene_count(); i++) {
  2101. if (editor_data.get_scene_path(i) == p_path)
  2102. return true;
  2103. }
  2104. return false;
  2105. }
  2106. void EditorNode::fix_dependencies(const String &p_for_file) {
  2107. dependency_fixer->edit(p_for_file);
  2108. }
  2109. Error EditorNode::load_scene(const String &p_scene, bool p_ignore_broken_deps, bool p_set_inherited, bool p_clear_errors, bool p_force_open_imported) {
  2110. if (!is_inside_tree()) {
  2111. defer_load_scene = p_scene;
  2112. return OK;
  2113. }
  2114. if (!p_set_inherited) {
  2115. for (int i = 0; i < editor_data.get_edited_scene_count(); i++) {
  2116. if (editor_data.get_scene_path(i) == p_scene) {
  2117. _scene_tab_changed(i);
  2118. return OK;
  2119. }
  2120. }
  2121. if (!p_force_open_imported && FileAccess::exists(p_scene + ".import")) {
  2122. open_imported->set_text(vformat(TTR("Scene '%s' was automatically imported, so it can't be modified.\nTo make changes to it, a new inherited scene can be created."), p_scene.get_file()));
  2123. open_imported->popup_centered_minsize();
  2124. new_inherited_button->grab_focus();
  2125. open_import_request = p_scene;
  2126. return OK;
  2127. }
  2128. }
  2129. if (p_clear_errors)
  2130. load_errors->clear();
  2131. String lpath = ProjectSettings::get_singleton()->localize_path(p_scene);
  2132. if (!lpath.begins_with("res://")) {
  2133. show_accept(TTR("Error loading scene, it must be inside the project path. Use 'Import' to open the scene, then save it inside the project path."), TTR("Ugh"));
  2134. opening_prev = false;
  2135. return ERR_FILE_NOT_FOUND;
  2136. }
  2137. int prev = editor_data.get_edited_scene();
  2138. int idx = editor_data.add_edited_scene(-1);
  2139. if (!editor_data.get_edited_scene_root() && editor_data.get_edited_scene_count() == 2) {
  2140. _remove_edited_scene();
  2141. } else {
  2142. _scene_tab_changed(idx);
  2143. }
  2144. dependency_errors.clear();
  2145. Error err;
  2146. Ref<PackedScene> sdata = ResourceLoader::load(lpath, "", true, &err);
  2147. if (!sdata.is_valid()) {
  2148. _dialog_display_load_error(lpath, err);
  2149. opening_prev = false;
  2150. if (prev != -1) {
  2151. set_current_scene(prev);
  2152. editor_data.remove_scene(idx);
  2153. }
  2154. return ERR_FILE_NOT_FOUND;
  2155. }
  2156. if (!p_ignore_broken_deps && dependency_errors.has(lpath)) {
  2157. current_option = -1;
  2158. Vector<String> errors;
  2159. for (Set<String>::Element *E = dependency_errors[lpath].front(); E; E = E->next()) {
  2160. errors.push_back(E->get());
  2161. }
  2162. dependency_error->show(lpath, errors);
  2163. opening_prev = false;
  2164. if (prev != -1) {
  2165. set_current_scene(prev);
  2166. editor_data.remove_scene(idx);
  2167. }
  2168. return ERR_FILE_MISSING_DEPENDENCIES;
  2169. }
  2170. dependency_errors.erase(lpath); //at least not self path
  2171. for (Map<String, Set<String> >::Element *E = dependency_errors.front(); E; E = E->next()) {
  2172. String txt = vformat(TTR("Scene '%s' has broken dependencies:"), E->key()) + "\n";
  2173. for (Set<String>::Element *F = E->get().front(); F; F = F->next()) {
  2174. txt += "\t" + F->get() + "\n";
  2175. }
  2176. add_io_error(txt);
  2177. }
  2178. if (ResourceCache::has(lpath)) {
  2179. //used from somewhere else? no problem! update state and replace sdata
  2180. Ref<PackedScene> ps = Ref<PackedScene>(Object::cast_to<PackedScene>(ResourceCache::get(lpath)));
  2181. if (ps.is_valid()) {
  2182. ps->replace_state(sdata->get_state());
  2183. ps->set_last_modified_time(sdata->get_last_modified_time());
  2184. sdata = ps;
  2185. }
  2186. } else {
  2187. sdata->set_path(lpath, true); //take over path
  2188. }
  2189. Node *new_scene = sdata->instance(PackedScene::GEN_EDIT_STATE_MAIN);
  2190. if (!new_scene) {
  2191. sdata.unref();
  2192. _dialog_display_load_error(lpath, ERR_FILE_NOT_FOUND);
  2193. opening_prev = false;
  2194. if (prev != -1) {
  2195. set_current_scene(prev);
  2196. editor_data.remove_scene(idx);
  2197. }
  2198. return ERR_FILE_NOT_FOUND;
  2199. }
  2200. if (p_set_inherited) {
  2201. Ref<SceneState> state = sdata->get_state();
  2202. state->set_path(lpath);
  2203. new_scene->set_scene_inherited_state(state);
  2204. new_scene->set_filename(String());
  2205. }
  2206. new_scene->set_scene_instance_state(Ref<SceneState>());
  2207. set_edited_scene(new_scene);
  2208. _get_scene_metadata(p_scene);
  2209. saved_version = editor_data.get_undo_redo().get_version();
  2210. _update_title();
  2211. _update_scene_tabs();
  2212. _add_to_recent_scenes(lpath);
  2213. prev_scene->set_disabled(previous_scenes.size() == 0);
  2214. opening_prev = false;
  2215. ScriptEditor::get_singleton()->get_debugger()->update_live_edit_root();
  2216. push_item(new_scene);
  2217. if (!restoring_scenes) {
  2218. save_layout();
  2219. }
  2220. return OK;
  2221. }
  2222. void EditorNode::open_request(const String &p_path) {
  2223. load_scene(p_path); // as it will be opened in separate tab
  2224. }
  2225. void EditorNode::request_instance_scene(const String &p_path) {
  2226. scene_tree_dock->instance(p_path);
  2227. }
  2228. void EditorNode::request_instance_scenes(const Vector<String> &p_files) {
  2229. scene_tree_dock->instance_scenes(p_files);
  2230. }
  2231. ImportDock *EditorNode::get_import_dock() {
  2232. return import_dock;
  2233. }
  2234. FileSystemDock *EditorNode::get_filesystem_dock() {
  2235. return filesystem_dock;
  2236. }
  2237. SceneTreeDock *EditorNode::get_scene_tree_dock() {
  2238. return scene_tree_dock;
  2239. }
  2240. InspectorDock *EditorNode::get_inspector_dock() {
  2241. return inspector_dock;
  2242. }
  2243. void EditorNode::_instance_request(const Vector<String> &p_files) {
  2244. request_instance_scenes(p_files);
  2245. }
  2246. void EditorNode::_close_messages() {
  2247. old_split_ofs = center_split->get_split_offset();
  2248. center_split->set_split_offset(0);
  2249. }
  2250. void EditorNode::_show_messages() {
  2251. center_split->set_split_offset(old_split_ofs);
  2252. }
  2253. void EditorNode::_add_to_recent_scenes(const String &p_scene) {
  2254. Array rc = EditorSettings::get_singleton()->get_project_metadata("recent_files", "scenes", Array());
  2255. if (rc.find(p_scene) != -1)
  2256. rc.erase(p_scene);
  2257. rc.push_front(p_scene);
  2258. if (rc.size() > 10)
  2259. rc.resize(10);
  2260. EditorSettings::get_singleton()->set_project_metadata("recent_files", "scenes", rc);
  2261. _update_recent_scenes();
  2262. }
  2263. void EditorNode::_open_recent_scene(int p_idx) {
  2264. if (p_idx == recent_scenes->get_item_count() - 1) {
  2265. EditorSettings::get_singleton()->set_project_metadata("recent_files", "scenes", Array());
  2266. call_deferred("_update_recent_scenes");
  2267. } else {
  2268. Array rc = EditorSettings::get_singleton()->get_project_metadata("recent_files", "scenes", Array());
  2269. ERR_FAIL_INDEX(p_idx, rc.size());
  2270. if (load_scene(rc[p_idx]) != OK) {
  2271. rc.remove(p_idx);
  2272. EditorSettings::get_singleton()->set_project_metadata("recent_files", "scenes", rc);
  2273. _update_recent_scenes();
  2274. }
  2275. }
  2276. }
  2277. void EditorNode::_update_recent_scenes() {
  2278. Array rc = EditorSettings::get_singleton()->get_project_metadata("recent_files", "scenes", Array());
  2279. recent_scenes->clear();
  2280. String path;
  2281. for (int i = 0; i < rc.size(); i++) {
  2282. path = rc[i];
  2283. recent_scenes->add_item(path.replace("res://", ""), i);
  2284. }
  2285. recent_scenes->add_separator();
  2286. recent_scenes->add_shortcut(ED_SHORTCUT("editor/clear_recent", TTR("Clear Recent Scenes")));
  2287. recent_scenes->set_as_minsize();
  2288. }
  2289. void EditorNode::_quick_opened() {
  2290. Vector<String> files = quick_open->get_selected_files();
  2291. for (int i = 0; i < files.size(); i++) {
  2292. String res_path = files[i];
  2293. if (quick_open->get_base_type() == "PackedScene") {
  2294. open_request(res_path);
  2295. } else {
  2296. load_resource(res_path);
  2297. }
  2298. }
  2299. }
  2300. void EditorNode::_quick_run() {
  2301. _run(false, quick_run->get_selected());
  2302. }
  2303. void EditorNode::notify_child_process_exited() {
  2304. _menu_option_confirm(RUN_STOP, false);
  2305. stop_button->set_pressed(false);
  2306. editor_run.stop();
  2307. }
  2308. void EditorNode::add_io_error(const String &p_error) {
  2309. _load_error_notify(singleton, p_error);
  2310. }
  2311. void EditorNode::_load_error_notify(void *p_ud, const String &p_text) {
  2312. EditorNode *en = (EditorNode *)p_ud;
  2313. en->load_errors->add_image(en->gui_base->get_icon("Error", "EditorIcons"));
  2314. en->load_errors->add_text(p_text + "\n");
  2315. en->load_error_dialog->popup_centered_ratio(0.5);
  2316. }
  2317. bool EditorNode::_find_scene_in_use(Node *p_node, const String &p_path) const {
  2318. if (p_node->get_filename() == p_path) {
  2319. return true;
  2320. }
  2321. for (int i = 0; i < p_node->get_child_count(); i++) {
  2322. if (_find_scene_in_use(p_node->get_child(i), p_path)) {
  2323. return true;
  2324. }
  2325. }
  2326. return false;
  2327. }
  2328. bool EditorNode::is_scene_in_use(const String &p_path) {
  2329. Node *es = get_edited_scene();
  2330. if (es)
  2331. return _find_scene_in_use(es, p_path);
  2332. return false;
  2333. }
  2334. void EditorNode::register_editor_types() {
  2335. ClassDB::register_class<EditorPlugin>();
  2336. ClassDB::register_class<EditorImportPlugin>();
  2337. ClassDB::register_class<EditorScript>();
  2338. ClassDB::register_class<EditorSelection>();
  2339. ClassDB::register_class<EditorFileDialog>();
  2340. ClassDB::register_virtual_class<EditorSettings>();
  2341. ClassDB::register_class<EditorSpatialGizmo>();
  2342. ClassDB::register_virtual_class<EditorResourcePreview>();
  2343. ClassDB::register_class<EditorResourcePreviewGenerator>();
  2344. ClassDB::register_virtual_class<EditorFileSystem>();
  2345. ClassDB::register_class<EditorFileSystemDirectory>();
  2346. ClassDB::register_virtual_class<ScriptEditor>();
  2347. ClassDB::register_virtual_class<EditorInterface>();
  2348. ClassDB::register_class<EditorExportPlugin>();
  2349. ClassDB::register_class<EditorResourceConversionPlugin>();
  2350. ClassDB::register_class<EditorSceneImporter>();
  2351. ClassDB::register_class<EditorInspector>();
  2352. ClassDB::register_class<EditorInspectorPlugin>();
  2353. ClassDB::register_class<EditorProperty>();
  2354. ClassDB::register_class<AnimationTrackEditPlugin>();
  2355. ClassDB::register_class<ScriptCreateDialog>();
  2356. // FIXME: Is this stuff obsolete, or should it be ported to new APIs?
  2357. ClassDB::register_class<EditorScenePostImport>();
  2358. //ClassDB::register_type<EditorImportExport>();
  2359. }
  2360. void EditorNode::unregister_editor_types() {
  2361. _init_callbacks.clear();
  2362. }
  2363. void EditorNode::stop_child_process() {
  2364. _menu_option_confirm(RUN_STOP, false);
  2365. }
  2366. void EditorNode::progress_add_task(const String &p_task, const String &p_label, int p_steps, bool p_can_cancel) {
  2367. singleton->progress_dialog->add_task(p_task, p_label, p_steps, p_can_cancel);
  2368. }
  2369. bool EditorNode::progress_task_step(const String &p_task, const String &p_state, int p_step, bool p_force_refresh) {
  2370. return singleton->progress_dialog->task_step(p_task, p_state, p_step, p_force_refresh);
  2371. }
  2372. void EditorNode::progress_end_task(const String &p_task) {
  2373. singleton->progress_dialog->end_task(p_task);
  2374. }
  2375. void EditorNode::progress_add_task_bg(const String &p_task, const String &p_label, int p_steps) {
  2376. singleton->progress_hb->add_task(p_task, p_label, p_steps);
  2377. }
  2378. void EditorNode::progress_task_step_bg(const String &p_task, int p_step) {
  2379. singleton->progress_hb->task_step(p_task, p_step);
  2380. }
  2381. void EditorNode::progress_end_task_bg(const String &p_task) {
  2382. singleton->progress_hb->end_task(p_task);
  2383. }
  2384. Ref<Texture> EditorNode::_file_dialog_get_icon(const String &p_path) {
  2385. EditorFileSystemDirectory *efsd = EditorFileSystem::get_singleton()->get_filesystem_path(p_path.get_base_dir());
  2386. if (efsd) {
  2387. String file = p_path.get_file();
  2388. for (int i = 0; i < efsd->get_file_count(); i++) {
  2389. if (efsd->get_file(i) == file) {
  2390. String type = efsd->get_file_type(i);
  2391. if (singleton->icon_type_cache.has(type)) {
  2392. return singleton->icon_type_cache[type];
  2393. } else {
  2394. return singleton->icon_type_cache["Object"];
  2395. }
  2396. }
  2397. }
  2398. }
  2399. return singleton->icon_type_cache["Object"];
  2400. }
  2401. void EditorNode::_build_icon_type_cache() {
  2402. List<StringName> tl;
  2403. StringName ei = "EditorIcons";
  2404. theme_base->get_theme()->get_icon_list(ei, &tl);
  2405. for (List<StringName>::Element *E = tl.front(); E; E = E->next()) {
  2406. if (!ClassDB::class_exists(E->get()))
  2407. continue;
  2408. icon_type_cache[E->get()] = theme_base->get_theme()->get_icon(E->get(), ei);
  2409. }
  2410. }
  2411. void EditorNode::_file_dialog_register(FileDialog *p_dialog) {
  2412. singleton->file_dialogs.insert(p_dialog);
  2413. }
  2414. void EditorNode::_file_dialog_unregister(FileDialog *p_dialog) {
  2415. singleton->file_dialogs.erase(p_dialog);
  2416. }
  2417. void EditorNode::_editor_file_dialog_register(EditorFileDialog *p_dialog) {
  2418. singleton->editor_file_dialogs.insert(p_dialog);
  2419. }
  2420. void EditorNode::_editor_file_dialog_unregister(EditorFileDialog *p_dialog) {
  2421. singleton->editor_file_dialogs.erase(p_dialog);
  2422. }
  2423. Vector<EditorNodeInitCallback> EditorNode::_init_callbacks;
  2424. Error EditorNode::export_preset(const String &p_preset, const String &p_path, bool p_debug, const String &p_password, bool p_quit_after) {
  2425. export_defer.preset = p_preset;
  2426. export_defer.path = p_path;
  2427. export_defer.debug = p_debug;
  2428. export_defer.password = p_password;
  2429. return OK;
  2430. }
  2431. void EditorNode::show_accept(const String &p_text, const String &p_title) {
  2432. current_option = -1;
  2433. accept->get_ok()->set_text(p_title);
  2434. accept->set_text(p_text);
  2435. accept->popup_centered_minsize();
  2436. }
  2437. void EditorNode::show_warning(const String &p_text, const String &p_title) {
  2438. warning->set_text(p_text);
  2439. warning->set_title(p_title);
  2440. warning->popup_centered_minsize();
  2441. }
  2442. void EditorNode::_dock_select_input(const Ref<InputEvent> &p_input) {
  2443. Ref<InputEventMouse> me = p_input;
  2444. if (me.is_valid()) {
  2445. Vector2 point = me->get_position();
  2446. int nrect = -1;
  2447. for (int i = 0; i < DOCK_SLOT_MAX; i++) {
  2448. if (dock_select_rect[i].has_point(point)) {
  2449. nrect = i;
  2450. break;
  2451. }
  2452. }
  2453. if (nrect != dock_select_rect_over) {
  2454. dock_select->update();
  2455. dock_select_rect_over = nrect;
  2456. }
  2457. if (nrect == -1)
  2458. return;
  2459. Ref<InputEventMouseButton> mb = me;
  2460. if (mb.is_valid() && mb->get_button_index() == 1 && mb->is_pressed() && dock_popup_selected != nrect) {
  2461. Control *dock = dock_slot[dock_popup_selected]->get_current_tab_control();
  2462. if (dock) {
  2463. dock_slot[dock_popup_selected]->remove_child(dock);
  2464. }
  2465. if (dock_slot[dock_popup_selected]->get_tab_count() == 0) {
  2466. dock_slot[dock_popup_selected]->hide();
  2467. } else {
  2468. dock_slot[dock_popup_selected]->set_current_tab(0);
  2469. }
  2470. dock_slot[nrect]->add_child(dock);
  2471. dock_popup_selected = nrect;
  2472. dock_slot[nrect]->set_current_tab(dock_slot[nrect]->get_tab_count() - 1);
  2473. dock_slot[nrect]->show();
  2474. dock_select->update();
  2475. VSplitContainer *splits[DOCK_SLOT_MAX / 2] = {
  2476. left_l_vsplit,
  2477. left_r_vsplit,
  2478. right_l_vsplit,
  2479. right_r_vsplit,
  2480. };
  2481. for (int i = 0; i < 4; i++) {
  2482. bool in_use = dock_slot[i * 2 + 0]->get_tab_count() || dock_slot[i * 2 + 1]->get_tab_count();
  2483. if (in_use)
  2484. splits[i]->show();
  2485. else
  2486. splits[i]->hide();
  2487. }
  2488. if (right_l_vsplit->is_visible() || right_r_vsplit->is_visible())
  2489. right_hsplit->show();
  2490. else
  2491. right_hsplit->hide();
  2492. _edit_current();
  2493. _save_docks();
  2494. }
  2495. }
  2496. }
  2497. void EditorNode::_dock_popup_exit() {
  2498. dock_select_rect_over = -1;
  2499. dock_select->update();
  2500. }
  2501. void EditorNode::_dock_pre_popup(int p_which) {
  2502. dock_popup_selected = p_which;
  2503. }
  2504. void EditorNode::_dock_move_left() {
  2505. if (dock_popup_selected < 0 || dock_popup_selected >= DOCK_SLOT_MAX)
  2506. return;
  2507. Control *current = dock_slot[dock_popup_selected]->get_tab_control(dock_slot[dock_popup_selected]->get_current_tab());
  2508. Control *prev = dock_slot[dock_popup_selected]->get_tab_control(dock_slot[dock_popup_selected]->get_current_tab() - 1);
  2509. if (!current || !prev)
  2510. return;
  2511. dock_slot[dock_popup_selected]->move_child(current, prev->get_index());
  2512. dock_slot[dock_popup_selected]->set_current_tab(dock_slot[dock_popup_selected]->get_current_tab() - 1);
  2513. dock_select->update();
  2514. _edit_current();
  2515. _save_docks();
  2516. }
  2517. void EditorNode::_dock_move_right() {
  2518. Control *current = dock_slot[dock_popup_selected]->get_tab_control(dock_slot[dock_popup_selected]->get_current_tab());
  2519. Control *next = dock_slot[dock_popup_selected]->get_tab_control(dock_slot[dock_popup_selected]->get_current_tab() + 1);
  2520. if (!current || !next)
  2521. return;
  2522. dock_slot[dock_popup_selected]->move_child(next, current->get_index());
  2523. dock_slot[dock_popup_selected]->set_current_tab(dock_slot[dock_popup_selected]->get_current_tab() + 1);
  2524. dock_select->update();
  2525. _edit_current();
  2526. _save_docks();
  2527. }
  2528. void EditorNode::_dock_select_draw() {
  2529. Size2 s = dock_select->get_size();
  2530. s.y /= 2.0;
  2531. s.x /= 6.0;
  2532. Color used = Color(0.6, 0.6, 0.6, 0.8);
  2533. Color used_selected = Color(0.8, 0.8, 0.8, 0.8);
  2534. Color tab_selected = theme_base->get_color("mono_color", "Editor");
  2535. Color unused = used;
  2536. unused.a = 0.4;
  2537. Color unusable = unused;
  2538. unusable.a = 0.1;
  2539. Rect2 unr(s.x * 2, 0, s.x * 2, s.y * 2);
  2540. unr.position += Vector2(2, 5);
  2541. unr.size -= Vector2(4, 7);
  2542. dock_select->draw_rect(unr, unusable);
  2543. dock_tab_move_left->set_disabled(true);
  2544. dock_tab_move_right->set_disabled(true);
  2545. if (dock_popup_selected != -1 && dock_slot[dock_popup_selected]->get_tab_count()) {
  2546. dock_tab_move_left->set_disabled(dock_slot[dock_popup_selected]->get_current_tab() == 0);
  2547. dock_tab_move_right->set_disabled(dock_slot[dock_popup_selected]->get_current_tab() >= dock_slot[dock_popup_selected]->get_tab_count() - 1);
  2548. }
  2549. for (int i = 0; i < DOCK_SLOT_MAX; i++) {
  2550. Vector2 ofs;
  2551. switch (i) {
  2552. case DOCK_SLOT_LEFT_UL: {
  2553. } break;
  2554. case DOCK_SLOT_LEFT_BL: {
  2555. ofs.y += s.y;
  2556. } break;
  2557. case DOCK_SLOT_LEFT_UR: {
  2558. ofs.x += s.x;
  2559. } break;
  2560. case DOCK_SLOT_LEFT_BR: {
  2561. ofs += s;
  2562. } break;
  2563. case DOCK_SLOT_RIGHT_UL: {
  2564. ofs.x += s.x * 4;
  2565. } break;
  2566. case DOCK_SLOT_RIGHT_BL: {
  2567. ofs.x += s.x * 4;
  2568. ofs.y += s.y;
  2569. } break;
  2570. case DOCK_SLOT_RIGHT_UR: {
  2571. ofs.x += s.x * 4;
  2572. ofs.x += s.x;
  2573. } break;
  2574. case DOCK_SLOT_RIGHT_BR: {
  2575. ofs.x += s.x * 4;
  2576. ofs += s;
  2577. } break;
  2578. }
  2579. Rect2 r(ofs, s);
  2580. dock_select_rect[i] = r;
  2581. r.position += Vector2(2, 5);
  2582. r.size -= Vector2(4, 7);
  2583. if (i == dock_select_rect_over) {
  2584. dock_select->draw_rect(r, used_selected);
  2585. } else if (dock_slot[i]->get_child_count() == 0) {
  2586. dock_select->draw_rect(r, unused);
  2587. } else {
  2588. dock_select->draw_rect(r, used);
  2589. }
  2590. for (int j = 0; j < MIN(3, dock_slot[i]->get_child_count()); j++) {
  2591. int xofs = (r.size.width / 3) * j;
  2592. Color c = used;
  2593. if (i == dock_popup_selected && (dock_slot[i]->get_current_tab() > 3 || dock_slot[i]->get_current_tab() == j))
  2594. c = tab_selected;
  2595. dock_select->draw_rect(Rect2(2 + ofs.x + xofs, ofs.y, r.size.width / 3 - 1, 3), c);
  2596. }
  2597. }
  2598. }
  2599. void EditorNode::_save_docks() {
  2600. Ref<ConfigFile> config;
  2601. config.instance();
  2602. _save_docks_to_config(config, "docks");
  2603. _save_open_scenes_to_config(config, "EditorNode");
  2604. editor_data.get_plugin_window_layout(config);
  2605. config->save(EditorSettings::get_singleton()->get_project_settings_dir().plus_file("editor_layout.cfg"));
  2606. }
  2607. void EditorNode::_save_docks_to_config(Ref<ConfigFile> p_layout, const String &p_section) {
  2608. for (int i = 0; i < DOCK_SLOT_MAX; i++) {
  2609. String names;
  2610. for (int j = 0; j < dock_slot[i]->get_tab_count(); j++) {
  2611. String name = dock_slot[i]->get_tab_control(j)->get_name();
  2612. if (names != "")
  2613. names += ",";
  2614. names += name;
  2615. }
  2616. if (names != "") {
  2617. p_layout->set_value(p_section, "dock_" + itos(i + 1), names);
  2618. }
  2619. }
  2620. p_layout->set_value(p_section, "dock_filesystem_split", filesystem_dock->get_split_offset());
  2621. VSplitContainer *splits[DOCK_SLOT_MAX / 2] = {
  2622. left_l_vsplit,
  2623. left_r_vsplit,
  2624. right_l_vsplit,
  2625. right_r_vsplit,
  2626. };
  2627. for (int i = 0; i < DOCK_SLOT_MAX / 2; i++) {
  2628. if (splits[i]->is_visible_in_tree()) {
  2629. p_layout->set_value(p_section, "dock_split_" + itos(i + 1), splits[i]->get_split_offset());
  2630. }
  2631. }
  2632. HSplitContainer *h_splits[4] = {
  2633. left_l_hsplit,
  2634. left_r_hsplit,
  2635. main_hsplit,
  2636. right_hsplit,
  2637. };
  2638. for (int i = 0; i < 4; i++) {
  2639. p_layout->set_value(p_section, "dock_hsplit_" + itos(i + 1), h_splits[i]->get_split_offset());
  2640. }
  2641. }
  2642. void EditorNode::_save_open_scenes_to_config(Ref<ConfigFile> p_layout, const String &p_section) {
  2643. Array scenes;
  2644. for (int i = 0; i < editor_data.get_edited_scene_count(); i++) {
  2645. String path = editor_data.get_scene_path(i);
  2646. if (path == "") {
  2647. continue;
  2648. }
  2649. scenes.push_back(path);
  2650. }
  2651. p_layout->set_value(p_section, "open_scenes", scenes);
  2652. }
  2653. void EditorNode::save_layout() {
  2654. dock_drag_timer->start();
  2655. }
  2656. void EditorNode::_dock_split_dragged(int ofs) {
  2657. dock_drag_timer->start();
  2658. }
  2659. void EditorNode::_load_docks() {
  2660. Ref<ConfigFile> config;
  2661. config.instance();
  2662. Error err = config->load(EditorSettings::get_singleton()->get_project_settings_dir().plus_file("editor_layout.cfg"));
  2663. if (err != OK) {
  2664. //no config
  2665. if (overridden_default_layout >= 0) {
  2666. _layout_menu_option(overridden_default_layout);
  2667. }
  2668. return;
  2669. }
  2670. _load_docks_from_config(config, "docks");
  2671. _load_open_scenes_from_config(config, "EditorNode");
  2672. editor_data.set_plugin_window_layout(config);
  2673. }
  2674. void EditorNode::_update_dock_slots_visibility() {
  2675. VSplitContainer *splits[DOCK_SLOT_MAX / 2] = {
  2676. left_l_vsplit,
  2677. left_r_vsplit,
  2678. right_l_vsplit,
  2679. right_r_vsplit,
  2680. };
  2681. if (!docks_visible) {
  2682. for (int i = 0; i < DOCK_SLOT_MAX; i++) {
  2683. dock_slot[i]->hide();
  2684. }
  2685. for (int i = 0; i < DOCK_SLOT_MAX / 2; i++) {
  2686. splits[i]->hide();
  2687. }
  2688. right_hsplit->hide();
  2689. bottom_panel->hide();
  2690. } else {
  2691. for (int i = 0; i < DOCK_SLOT_MAX; i++) {
  2692. if (dock_slot[i]->get_tab_count())
  2693. dock_slot[i]->show();
  2694. else
  2695. dock_slot[i]->hide();
  2696. }
  2697. for (int i = 0; i < DOCK_SLOT_MAX / 2; i++) {
  2698. bool in_use = dock_slot[i * 2 + 0]->get_tab_count() || dock_slot[i * 2 + 1]->get_tab_count();
  2699. if (in_use)
  2700. splits[i]->show();
  2701. else
  2702. splits[i]->hide();
  2703. }
  2704. for (int i = 0; i < DOCK_SLOT_MAX; i++) {
  2705. if (dock_slot[i]->is_visible() && dock_slot[i]->get_tab_count()) {
  2706. dock_slot[i]->set_current_tab(0);
  2707. }
  2708. }
  2709. bottom_panel->show();
  2710. if (right_l_vsplit->is_visible() || right_r_vsplit->is_visible())
  2711. right_hsplit->show();
  2712. else
  2713. right_hsplit->hide();
  2714. }
  2715. }
  2716. void EditorNode::_dock_tab_changed(int p_tab) {
  2717. // update visibility but dont set current tab
  2718. VSplitContainer *splits[DOCK_SLOT_MAX / 2] = {
  2719. left_l_vsplit,
  2720. left_r_vsplit,
  2721. right_l_vsplit,
  2722. right_r_vsplit,
  2723. };
  2724. if (!docks_visible) {
  2725. for (int i = 0; i < DOCK_SLOT_MAX; i++) {
  2726. dock_slot[i]->hide();
  2727. }
  2728. for (int i = 0; i < DOCK_SLOT_MAX / 2; i++) {
  2729. splits[i]->hide();
  2730. }
  2731. right_hsplit->hide();
  2732. bottom_panel->hide();
  2733. } else {
  2734. for (int i = 0; i < DOCK_SLOT_MAX; i++) {
  2735. if (dock_slot[i]->get_tab_count())
  2736. dock_slot[i]->show();
  2737. else
  2738. dock_slot[i]->hide();
  2739. }
  2740. for (int i = 0; i < DOCK_SLOT_MAX / 2; i++) {
  2741. bool in_use = dock_slot[i * 2 + 0]->get_tab_count() || dock_slot[i * 2 + 1]->get_tab_count();
  2742. if (in_use)
  2743. splits[i]->show();
  2744. else
  2745. splits[i]->hide();
  2746. }
  2747. bottom_panel->show();
  2748. if (right_l_vsplit->is_visible() || right_r_vsplit->is_visible())
  2749. right_hsplit->show();
  2750. else
  2751. right_hsplit->hide();
  2752. }
  2753. }
  2754. void EditorNode::_load_docks_from_config(Ref<ConfigFile> p_layout, const String &p_section) {
  2755. for (int i = 0; i < DOCK_SLOT_MAX; i++) {
  2756. if (!p_layout->has_section_key(p_section, "dock_" + itos(i + 1)))
  2757. continue;
  2758. Vector<String> names = String(p_layout->get_value(p_section, "dock_" + itos(i + 1))).split(",");
  2759. for (int j = 0; j < names.size(); j++) {
  2760. String name = names[j];
  2761. //find it, in a horribly inefficient way
  2762. int atidx = -1;
  2763. Control *node = NULL;
  2764. for (int k = 0; k < DOCK_SLOT_MAX; k++) {
  2765. if (!dock_slot[k]->has_node(name))
  2766. continue;
  2767. node = Object::cast_to<Control>(dock_slot[k]->get_node(name));
  2768. if (!node)
  2769. continue;
  2770. atidx = k;
  2771. break;
  2772. }
  2773. if (atidx == -1) //well, it's not anywhere
  2774. continue;
  2775. if (atidx == i) {
  2776. node->raise();
  2777. continue;
  2778. }
  2779. dock_slot[atidx]->remove_child(node);
  2780. if (dock_slot[atidx]->get_tab_count() == 0) {
  2781. dock_slot[atidx]->hide();
  2782. }
  2783. dock_slot[i]->add_child(node);
  2784. dock_slot[i]->show();
  2785. }
  2786. }
  2787. int fs_split_ofs = 0;
  2788. if (p_layout->has_section_key(p_section, "dock_filesystem_split")) {
  2789. fs_split_ofs = p_layout->get_value(p_section, "dock_filesystem_split");
  2790. }
  2791. filesystem_dock->set_split_offset(fs_split_ofs);
  2792. VSplitContainer *splits[DOCK_SLOT_MAX / 2] = {
  2793. left_l_vsplit,
  2794. left_r_vsplit,
  2795. right_l_vsplit,
  2796. right_r_vsplit,
  2797. };
  2798. for (int i = 0; i < DOCK_SLOT_MAX / 2; i++) {
  2799. if (!p_layout->has_section_key(p_section, "dock_split_" + itos(i + 1)))
  2800. continue;
  2801. int ofs = p_layout->get_value(p_section, "dock_split_" + itos(i + 1));
  2802. splits[i]->set_split_offset(ofs);
  2803. }
  2804. HSplitContainer *h_splits[4] = {
  2805. left_l_hsplit,
  2806. left_r_hsplit,
  2807. main_hsplit,
  2808. right_hsplit,
  2809. };
  2810. for (int i = 0; i < 4; i++) {
  2811. if (!p_layout->has_section_key(p_section, "dock_hsplit_" + itos(i + 1)))
  2812. continue;
  2813. int ofs = p_layout->get_value(p_section, "dock_hsplit_" + itos(i + 1));
  2814. h_splits[i]->set_split_offset(ofs);
  2815. }
  2816. for (int i = 0; i < DOCK_SLOT_MAX / 2; i++) {
  2817. bool in_use = dock_slot[i * 2 + 0]->get_tab_count() || dock_slot[i * 2 + 1]->get_tab_count();
  2818. if (in_use)
  2819. splits[i]->show();
  2820. else
  2821. splits[i]->hide();
  2822. }
  2823. if (right_l_vsplit->is_visible() || right_r_vsplit->is_visible())
  2824. right_hsplit->show();
  2825. else
  2826. right_hsplit->hide();
  2827. for (int i = 0; i < DOCK_SLOT_MAX; i++) {
  2828. if (dock_slot[i]->is_visible() && dock_slot[i]->get_tab_count()) {
  2829. dock_slot[i]->set_current_tab(0);
  2830. }
  2831. }
  2832. }
  2833. void EditorNode::_load_open_scenes_from_config(Ref<ConfigFile> p_layout, const String &p_section) {
  2834. if (!bool(EDITOR_GET("interface/scene_tabs/restore_scenes_on_load"))) {
  2835. return;
  2836. }
  2837. if (!p_layout->has_section(p_section) || !p_layout->has_section_key(p_section, "open_scenes")) {
  2838. return;
  2839. }
  2840. restoring_scenes = true;
  2841. Array scenes = p_layout->get_value(p_section, "open_scenes");
  2842. for (int i = 0; i < scenes.size(); i++) {
  2843. load_scene(scenes[i]);
  2844. }
  2845. restoring_scenes = false;
  2846. }
  2847. void EditorNode::_update_layouts_menu() {
  2848. editor_layouts->clear();
  2849. overridden_default_layout = -1;
  2850. editor_layouts->set_size(Vector2());
  2851. editor_layouts->add_shortcut(ED_SHORTCUT("layout/save", TTR("Save Layout")), SETTINGS_LAYOUT_SAVE);
  2852. editor_layouts->add_shortcut(ED_SHORTCUT("layout/delete", TTR("Delete Layout")), SETTINGS_LAYOUT_DELETE);
  2853. editor_layouts->add_separator();
  2854. editor_layouts->add_shortcut(ED_SHORTCUT("layout/default", TTR("Default")), SETTINGS_LAYOUT_DEFAULT);
  2855. Ref<ConfigFile> config;
  2856. config.instance();
  2857. Error err = config->load(EditorSettings::get_singleton()->get_editor_layouts_config());
  2858. if (err != OK) {
  2859. return; //no config
  2860. }
  2861. List<String> layouts;
  2862. config.ptr()->get_sections(&layouts);
  2863. for (List<String>::Element *E = layouts.front(); E; E = E->next()) {
  2864. String layout = E->get();
  2865. if (layout == TTR("Default")) {
  2866. editor_layouts->remove_item(editor_layouts->get_item_index(SETTINGS_LAYOUT_DEFAULT));
  2867. overridden_default_layout = editor_layouts->get_item_count();
  2868. }
  2869. editor_layouts->add_item(layout);
  2870. }
  2871. }
  2872. void EditorNode::_layout_menu_option(int p_id) {
  2873. switch (p_id) {
  2874. case SETTINGS_LAYOUT_SAVE: {
  2875. current_option = p_id;
  2876. layout_dialog->set_title(TTR("Save Layout"));
  2877. layout_dialog->get_ok()->set_text(TTR("Save"));
  2878. layout_dialog->popup_centered();
  2879. } break;
  2880. case SETTINGS_LAYOUT_DELETE: {
  2881. current_option = p_id;
  2882. layout_dialog->set_title(TTR("Delete Layout"));
  2883. layout_dialog->get_ok()->set_text(TTR("Delete"));
  2884. layout_dialog->popup_centered();
  2885. } break;
  2886. case SETTINGS_LAYOUT_DEFAULT: {
  2887. _load_docks_from_config(default_layout, "docks");
  2888. _save_docks();
  2889. } break;
  2890. default: {
  2891. Ref<ConfigFile> config;
  2892. config.instance();
  2893. Error err = config->load(EditorSettings::get_singleton()->get_editor_layouts_config());
  2894. if (err != OK) {
  2895. return; //no config
  2896. }
  2897. _load_docks_from_config(config, editor_layouts->get_item_text(p_id));
  2898. _save_docks();
  2899. }
  2900. }
  2901. }
  2902. void EditorNode::_scene_tab_script_edited(int p_tab) {
  2903. Ref<Script> script = editor_data.get_scene_root_script(p_tab);
  2904. if (script.is_valid())
  2905. inspector_dock->edit_resource(script);
  2906. }
  2907. void EditorNode::_scene_tab_closed(int p_tab) {
  2908. current_option = SCENE_TAB_CLOSE;
  2909. tab_closing = p_tab;
  2910. Node *scene = editor_data.get_edited_scene_root(p_tab);
  2911. if (!scene) {
  2912. _discard_changes();
  2913. return;
  2914. }
  2915. bool unsaved = (p_tab == editor_data.get_edited_scene()) ?
  2916. saved_version != editor_data.get_undo_redo().get_version() :
  2917. editor_data.get_scene_version(p_tab) != 0;
  2918. if (unsaved) {
  2919. save_confirmation->get_ok()->set_text(TTR("Save & Close"));
  2920. save_confirmation->set_text(vformat(TTR("Save changes to '%s' before closing?"), scene->get_filename() != "" ? scene->get_filename() : "unsaved scene"));
  2921. save_confirmation->popup_centered_minsize();
  2922. } else {
  2923. _discard_changes();
  2924. }
  2925. save_layout();
  2926. _update_scene_tabs();
  2927. }
  2928. void EditorNode::_scene_tab_hover(int p_tab) {
  2929. if (bool(EDITOR_GET("interface/scene_tabs/show_thumbnail_on_hover")) == false) {
  2930. return;
  2931. }
  2932. int current_tab = scene_tabs->get_current_tab();
  2933. if (p_tab == current_tab || p_tab < 0) {
  2934. tab_preview_panel->hide();
  2935. } else {
  2936. String path = editor_data.get_scene_path(p_tab);
  2937. EditorResourcePreview::get_singleton()->queue_resource_preview(path, this, "_thumbnail_done", p_tab);
  2938. }
  2939. }
  2940. void EditorNode::_scene_tab_exit() {
  2941. tab_preview_panel->hide();
  2942. }
  2943. void EditorNode::_scene_tab_input(const Ref<InputEvent> &p_input) {
  2944. Ref<InputEventMouseButton> mb = p_input;
  2945. if (mb.is_valid()) {
  2946. if (scene_tabs->get_hovered_tab() >= 0) {
  2947. if (mb->get_button_index() == BUTTON_MIDDLE && mb->is_pressed()) {
  2948. _scene_tab_closed(scene_tabs->get_hovered_tab());
  2949. }
  2950. } else {
  2951. if ((mb->get_button_index() == BUTTON_LEFT && mb->is_doubleclick()) || (mb->get_button_index() == BUTTON_MIDDLE && mb->is_pressed())) {
  2952. _menu_option_confirm(FILE_NEW_SCENE, true);
  2953. }
  2954. }
  2955. }
  2956. }
  2957. void EditorNode::_reposition_active_tab(int idx_to) {
  2958. editor_data.move_edited_scene_to_index(idx_to);
  2959. _update_scene_tabs();
  2960. }
  2961. void EditorNode::_thumbnail_done(const String &p_path, const Ref<Texture> &p_preview, const Variant &p_udata) {
  2962. int p_tab = p_udata.operator signed int();
  2963. if (p_preview.is_valid()) {
  2964. Rect2 rect = scene_tabs->get_tab_rect(p_tab);
  2965. rect.position += scene_tabs->get_global_position();
  2966. tab_preview->set_texture(p_preview);
  2967. tab_preview_panel->set_position(rect.position + Vector2(0, rect.size.height));
  2968. tab_preview_panel->show();
  2969. }
  2970. }
  2971. void EditorNode::_scene_tab_changed(int p_tab) {
  2972. tab_preview_panel->hide();
  2973. bool unsaved = (saved_version != editor_data.get_undo_redo().get_version());
  2974. if (p_tab == editor_data.get_edited_scene())
  2975. return; //pointless
  2976. uint64_t next_scene_version = editor_data.get_scene_version(p_tab);
  2977. editor_data.get_undo_redo().create_action(TTR("Switch Scene Tab"));
  2978. editor_data.get_undo_redo().add_do_method(this, "set_current_version", unsaved ? saved_version : 0);
  2979. editor_data.get_undo_redo().add_do_method(this, "set_current_scene", p_tab);
  2980. editor_data.get_undo_redo().add_do_method(this, "set_current_version", next_scene_version == 0 ? editor_data.get_undo_redo().get_version() + 1 : next_scene_version);
  2981. editor_data.get_undo_redo().add_undo_method(this, "set_current_version", next_scene_version);
  2982. editor_data.get_undo_redo().add_undo_method(this, "set_current_scene", editor_data.get_edited_scene());
  2983. editor_data.get_undo_redo().add_undo_method(this, "set_current_version", saved_version);
  2984. editor_data.get_undo_redo().commit_action();
  2985. }
  2986. ToolButton *EditorNode::add_bottom_panel_item(String p_text, Control *p_item) {
  2987. ToolButton *tb = memnew(ToolButton);
  2988. tb->connect("toggled", this, "_bottom_panel_switch", varray(bottom_panel_items.size()));
  2989. tb->set_text(p_text);
  2990. tb->set_toggle_mode(true);
  2991. tb->set_focus_mode(Control::FOCUS_NONE);
  2992. bottom_panel_vb->add_child(p_item);
  2993. bottom_panel_hb->raise();
  2994. bottom_panel_hb_editors->add_child(tb);
  2995. p_item->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  2996. p_item->hide();
  2997. BottomPanelItem bpi;
  2998. bpi.button = tb;
  2999. bpi.control = p_item;
  3000. bpi.name = p_text;
  3001. bottom_panel_items.push_back(bpi);
  3002. return tb;
  3003. }
  3004. bool EditorNode::are_bottom_panels_hidden() const {
  3005. for (int i = 0; i < bottom_panel_items.size(); i++) {
  3006. if (bottom_panel_items[i].button->is_pressed())
  3007. return false;
  3008. }
  3009. return true;
  3010. }
  3011. void EditorNode::hide_bottom_panel() {
  3012. _bottom_panel_switch(false, 0);
  3013. }
  3014. void EditorNode::make_bottom_panel_item_visible(Control *p_item) {
  3015. for (int i = 0; i < bottom_panel_items.size(); i++) {
  3016. if (bottom_panel_items[i].control == p_item) {
  3017. _bottom_panel_switch(true, i);
  3018. break;
  3019. }
  3020. }
  3021. }
  3022. void EditorNode::raise_bottom_panel_item(Control *p_item) {
  3023. for (int i = 0; i < bottom_panel_items.size(); i++) {
  3024. if (bottom_panel_items[i].control == p_item) {
  3025. bottom_panel_items[i].button->raise();
  3026. SWAP(bottom_panel_items[i], bottom_panel_items[bottom_panel_items.size() - 1]);
  3027. break;
  3028. }
  3029. }
  3030. for (int i = 0; i < bottom_panel_items.size(); i++) {
  3031. bottom_panel_items[i].button->disconnect("toggled", this, "_bottom_panel_switch");
  3032. bottom_panel_items[i].button->connect("toggled", this, "_bottom_panel_switch", varray(i));
  3033. }
  3034. }
  3035. void EditorNode::remove_bottom_panel_item(Control *p_item) {
  3036. for (int i = 0; i < bottom_panel_items.size(); i++) {
  3037. if (bottom_panel_items[i].control == p_item) {
  3038. if (p_item->is_visible_in_tree()) {
  3039. _bottom_panel_switch(false, 0);
  3040. }
  3041. bottom_panel_vb->remove_child(bottom_panel_items[i].control);
  3042. bottom_panel_hb_editors->remove_child(bottom_panel_items[i].button);
  3043. memdelete(bottom_panel_items[i].button);
  3044. bottom_panel_items.remove(i);
  3045. break;
  3046. }
  3047. }
  3048. for (int i = 0; i < bottom_panel_items.size(); i++) {
  3049. bottom_panel_items[i].button->disconnect("toggled", this, "_bottom_panel_switch");
  3050. bottom_panel_items[i].button->connect("toggled", this, "_bottom_panel_switch", varray(i));
  3051. }
  3052. }
  3053. void EditorNode::_bottom_panel_switch(bool p_enable, int p_idx) {
  3054. ERR_FAIL_INDEX(p_idx, bottom_panel_items.size());
  3055. if (p_enable) {
  3056. for (int i = 0; i < bottom_panel_items.size(); i++) {
  3057. bottom_panel_items[i].button->set_pressed(i == p_idx);
  3058. bottom_panel_items[i].control->set_visible(i == p_idx);
  3059. }
  3060. if (ScriptEditor::get_singleton()->get_debugger() == bottom_panel_items[p_idx].control) { // this is the debug panel which uses tabs, so the top section should be smaller
  3061. bottom_panel->add_style_override("panel", gui_base->get_stylebox("BottomPanelDebuggerOverride", "EditorStyles"));
  3062. } else {
  3063. bottom_panel->add_style_override("panel", gui_base->get_stylebox("panel", "TabContainer"));
  3064. }
  3065. center_split->set_dragger_visibility(SplitContainer::DRAGGER_VISIBLE);
  3066. center_split->set_collapsed(false);
  3067. if (bottom_panel_raise->is_pressed()) {
  3068. top_split->hide();
  3069. }
  3070. bottom_panel_raise->show();
  3071. } else {
  3072. bottom_panel->add_style_override("panel", gui_base->get_stylebox("panel", "TabContainer"));
  3073. for (int i = 0; i < bottom_panel_items.size(); i++) {
  3074. bottom_panel_items[i].button->set_pressed(false);
  3075. bottom_panel_items[i].control->set_visible(false);
  3076. }
  3077. center_split->set_dragger_visibility(SplitContainer::DRAGGER_HIDDEN);
  3078. center_split->set_collapsed(true);
  3079. bottom_panel_raise->hide();
  3080. if (bottom_panel_raise->is_pressed()) {
  3081. top_split->show();
  3082. }
  3083. }
  3084. }
  3085. void EditorNode::set_docks_visible(bool p_show) {
  3086. docks_visible = p_show;
  3087. _update_dock_slots_visibility();
  3088. }
  3089. bool EditorNode::get_docks_visible() const {
  3090. return docks_visible;
  3091. }
  3092. void EditorNode::_toggle_distraction_free_mode() {
  3093. if (EditorSettings::get_singleton()->get("interface/editor/separate_distraction_mode")) {
  3094. int screen = -1;
  3095. for (int i = 0; i < editor_table.size(); i++) {
  3096. if (editor_plugin_screen == editor_table[i]) {
  3097. screen = i;
  3098. break;
  3099. }
  3100. }
  3101. if (screen == EDITOR_SCRIPT) {
  3102. script_distraction = !script_distraction;
  3103. set_distraction_free_mode(script_distraction);
  3104. } else {
  3105. scene_distraction = !scene_distraction;
  3106. set_distraction_free_mode(scene_distraction);
  3107. }
  3108. } else {
  3109. set_distraction_free_mode(distraction_free->is_pressed());
  3110. }
  3111. }
  3112. void EditorNode::set_distraction_free_mode(bool p_enter) {
  3113. distraction_free->set_pressed(p_enter);
  3114. if (p_enter) {
  3115. if (docks_visible) {
  3116. set_docks_visible(false);
  3117. }
  3118. } else {
  3119. set_docks_visible(true);
  3120. }
  3121. }
  3122. bool EditorNode::get_distraction_free_mode() const {
  3123. return distraction_free->is_pressed();
  3124. }
  3125. void EditorNode::add_control_to_dock(DockSlot p_slot, Control *p_control) {
  3126. ERR_FAIL_INDEX(p_slot, DOCK_SLOT_MAX);
  3127. dock_slot[p_slot]->add_child(p_control);
  3128. _update_dock_slots_visibility();
  3129. }
  3130. void EditorNode::remove_control_from_dock(Control *p_control) {
  3131. Control *dock = NULL;
  3132. for (int i = 0; i < DOCK_SLOT_MAX; i++) {
  3133. if (p_control->get_parent() == dock_slot[i]) {
  3134. dock = dock_slot[i];
  3135. break;
  3136. }
  3137. }
  3138. ERR_EXPLAIN("Control was not in dock");
  3139. ERR_FAIL_COND(!dock);
  3140. dock->remove_child(p_control);
  3141. _update_dock_slots_visibility();
  3142. }
  3143. Variant EditorNode::drag_resource(const Ref<Resource> &p_res, Control *p_from) {
  3144. Control *drag_control = memnew(Control);
  3145. TextureRect *drag_preview = memnew(TextureRect);
  3146. Label *label = memnew(Label);
  3147. Ref<Texture> preview;
  3148. {
  3149. //todo make proper previews
  3150. Ref<ImageTexture> pic = gui_base->get_icon("FileBigThumb", "EditorIcons");
  3151. Ref<Image> img = pic->get_data();
  3152. img = img->duplicate();
  3153. img->resize(48, 48); //meh
  3154. Ref<ImageTexture> resized_pic = Ref<ImageTexture>(memnew(ImageTexture));
  3155. resized_pic->create_from_image(img);
  3156. preview = resized_pic;
  3157. }
  3158. drag_preview->set_texture(preview);
  3159. drag_control->add_child(drag_preview);
  3160. if (p_res->get_path().is_resource_file()) {
  3161. label->set_text(p_res->get_path().get_file());
  3162. } else if (p_res->get_name() != "") {
  3163. label->set_text(p_res->get_name());
  3164. } else {
  3165. label->set_text(p_res->get_class());
  3166. }
  3167. drag_control->add_child(label);
  3168. p_from->set_drag_preview(drag_control); //wait until it enters scene
  3169. label->set_position(Point2((preview->get_width() - label->get_minimum_size().width) / 2, preview->get_height()));
  3170. Dictionary drag_data;
  3171. drag_data["type"] = "resource";
  3172. drag_data["resource"] = p_res;
  3173. drag_data["from"] = p_from;
  3174. return drag_data;
  3175. }
  3176. Variant EditorNode::drag_files_and_dirs(const Vector<String> &p_paths, Control *p_from) {
  3177. bool has_folder = false;
  3178. bool has_file = false;
  3179. for (int i = 0; i < p_paths.size(); i++) {
  3180. bool is_folder = p_paths[i].ends_with("/");
  3181. has_folder |= is_folder;
  3182. has_file |= !is_folder;
  3183. }
  3184. int max_rows = 6;
  3185. int num_rows = p_paths.size() > max_rows ? max_rows - 1 : p_paths.size(); //Don't waste a row to say "1 more file" - list it instead.
  3186. VBoxContainer *vbox = memnew(VBoxContainer);
  3187. for (int i = 0; i < num_rows; i++) {
  3188. HBoxContainer *hbox = memnew(HBoxContainer);
  3189. TextureRect *icon = memnew(TextureRect);
  3190. Label *label = memnew(Label);
  3191. if (p_paths[i].ends_with("/")) {
  3192. label->set_text(p_paths[i].substr(0, p_paths[i].length() - 1).get_file());
  3193. icon->set_texture(gui_base->get_icon("Folder", "EditorIcons"));
  3194. } else {
  3195. label->set_text(p_paths[i].get_file());
  3196. icon->set_texture(gui_base->get_icon("File", "EditorIcons"));
  3197. }
  3198. icon->set_size(Size2(16, 16));
  3199. hbox->add_child(icon);
  3200. hbox->add_child(label);
  3201. vbox->add_child(hbox);
  3202. }
  3203. if (p_paths.size() > num_rows) {
  3204. Label *label = memnew(Label);
  3205. if (has_file && has_folder) {
  3206. label->set_text(vformat(TTR("%d more files or folders"), p_paths.size() - num_rows));
  3207. } else if (has_folder) {
  3208. label->set_text(vformat(TTR("%d more folders"), p_paths.size() - num_rows));
  3209. } else {
  3210. label->set_text(vformat(TTR("%d more files"), p_paths.size() - num_rows));
  3211. }
  3212. vbox->add_child(label);
  3213. }
  3214. p_from->set_drag_preview(vbox); //wait until it enters scene
  3215. Dictionary drag_data;
  3216. drag_data["type"] = has_folder ? "files_and_dirs" : "files";
  3217. drag_data["files"] = p_paths;
  3218. drag_data["from"] = p_from;
  3219. return drag_data;
  3220. }
  3221. void EditorNode::add_tool_menu_item(const String &p_name, Object *p_handler, const String &p_callback, const Variant &p_ud) {
  3222. ERR_FAIL_NULL(p_handler);
  3223. int idx = tool_menu->get_item_count();
  3224. tool_menu->add_item(p_name, TOOLS_CUSTOM);
  3225. Array parameters;
  3226. parameters.push_back(p_handler->get_instance_id());
  3227. parameters.push_back(p_callback);
  3228. parameters.push_back(p_ud);
  3229. tool_menu->set_item_metadata(idx, parameters);
  3230. }
  3231. void EditorNode::add_tool_submenu_item(const String &p_name, PopupMenu *p_submenu) {
  3232. ERR_FAIL_NULL(p_submenu);
  3233. ERR_FAIL_COND(p_submenu->get_parent() != NULL);
  3234. tool_menu->add_child(p_submenu);
  3235. tool_menu->add_submenu_item(p_name, p_submenu->get_name(), TOOLS_CUSTOM);
  3236. }
  3237. void EditorNode::remove_tool_menu_item(const String &p_name) {
  3238. for (int i = 0; i < tool_menu->get_item_count(); i++) {
  3239. if (tool_menu->get_item_id(i) != TOOLS_CUSTOM)
  3240. continue;
  3241. if (tool_menu->get_item_text(i) == p_name) {
  3242. if (tool_menu->get_item_submenu(i) != "") {
  3243. Node *n = tool_menu->get_node(tool_menu->get_item_submenu(i));
  3244. tool_menu->remove_child(n);
  3245. memdelete(n);
  3246. }
  3247. tool_menu->remove_item(i);
  3248. tool_menu->set_as_minsize();
  3249. return;
  3250. }
  3251. }
  3252. }
  3253. void EditorNode::_dropped_files(const Vector<String> &p_files, int p_screen) {
  3254. String to_path = ProjectSettings::get_singleton()->globalize_path(get_filesystem_dock()->get_current_path());
  3255. DirAccessRef dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  3256. Vector<String> just_copy = String("ttf,otf").split(",");
  3257. for (int i = 0; i < p_files.size(); i++) {
  3258. String from = p_files[i];
  3259. if (!ResourceFormatImporter::get_singleton()->can_be_imported(from) && (just_copy.find(from.get_extension().to_lower()) == -1)) {
  3260. continue;
  3261. }
  3262. String to = to_path.plus_file(from.get_file());
  3263. dir->copy(from, to);
  3264. }
  3265. EditorFileSystem::get_singleton()->scan_changes();
  3266. }
  3267. void EditorNode::_file_access_close_error_notify(const String &p_str) {
  3268. add_io_error("Unable to write to file '" + p_str + "', file in use, locked or lacking permissions.");
  3269. }
  3270. void EditorNode::reload_scene(const String &p_path) {
  3271. //first of all, reload internal textures, materials, meshes, etc. as they might have changed on disk
  3272. List<Ref<Resource> > cached;
  3273. ResourceCache::get_cached_resources(&cached);
  3274. List<Ref<Resource> > to_clear; //clear internal resources from previous scene from being used
  3275. for (List<Ref<Resource> >::Element *E = cached.front(); E; E = E->next()) {
  3276. if (E->get()->get_path().begins_with(p_path + "::")) { //subresources of existing scene
  3277. to_clear.push_back(E->get());
  3278. }
  3279. }
  3280. //so reload reloads everything, clear subresources of previous scene
  3281. while (to_clear.front()) {
  3282. to_clear.front()->get()->set_path("");
  3283. to_clear.pop_front();
  3284. }
  3285. int scene_idx = -1;
  3286. for (int i = 0; i < editor_data.get_edited_scene_count(); i++) {
  3287. if (editor_data.get_scene_path(i) == p_path) {
  3288. scene_idx = i;
  3289. break;
  3290. }
  3291. }
  3292. int current_tab = editor_data.get_edited_scene();
  3293. if (scene_idx == -1) {
  3294. if (get_edited_scene()) {
  3295. //scene is not open, so at it might be instanced, just refresh, set tab to itself and it will reload
  3296. set_current_scene(current_tab);
  3297. editor_data.get_undo_redo().clear_history();
  3298. }
  3299. return;
  3300. }
  3301. if (current_tab == scene_idx) {
  3302. editor_data.apply_changes_in_editors();
  3303. _set_scene_metadata(p_path);
  3304. }
  3305. //remove scene
  3306. _remove_scene(scene_idx);
  3307. //reload scene
  3308. load_scene(p_path, true, false, true, true);
  3309. //adjust index so tab is back a the previous position
  3310. editor_data.move_edited_scene_to_index(scene_idx);
  3311. get_undo_redo()->clear_history();
  3312. //recover the tab
  3313. scene_tabs->set_current_tab(current_tab);
  3314. _scene_tab_changed(current_tab);
  3315. }
  3316. int EditorNode::plugin_init_callback_count = 0;
  3317. void EditorNode::add_plugin_init_callback(EditorPluginInitializeCallback p_callback) {
  3318. ERR_FAIL_COND(plugin_init_callback_count == MAX_INIT_CALLBACKS);
  3319. plugin_init_callbacks[plugin_init_callback_count++] = p_callback;
  3320. }
  3321. EditorPluginInitializeCallback EditorNode::plugin_init_callbacks[EditorNode::MAX_INIT_CALLBACKS];
  3322. int EditorNode::build_callback_count = 0;
  3323. void EditorNode::add_build_callback(EditorBuildCallback p_callback) {
  3324. ERR_FAIL_COND(build_callback_count == MAX_INIT_CALLBACKS);
  3325. build_callbacks[build_callback_count++] = p_callback;
  3326. }
  3327. EditorBuildCallback EditorNode::build_callbacks[EditorNode::MAX_BUILD_CALLBACKS];
  3328. bool EditorNode::call_build() {
  3329. bool builds_successful = true;
  3330. for (int i = 0; i < build_callback_count && builds_successful; i++) {
  3331. if (!build_callbacks[i]()) {
  3332. ERR_PRINT("A Godot Engine build callback failed.");
  3333. builds_successful = false;
  3334. }
  3335. }
  3336. if (builds_successful && !editor_data.call_build()) {
  3337. ERR_PRINT("An EditorPlugin build callback failed.");
  3338. builds_successful = false;
  3339. }
  3340. return builds_successful;
  3341. }
  3342. void EditorNode::_inherit_imported(const String &p_action) {
  3343. open_imported->hide();
  3344. load_scene(open_import_request, true, true);
  3345. }
  3346. void EditorNode::_open_imported() {
  3347. load_scene(open_import_request, true, false, true, true);
  3348. }
  3349. void EditorNode::dim_editor(bool p_dimming) {
  3350. static int dim_count = 0;
  3351. bool dim_ui = EditorSettings::get_singleton()->get("interface/editor/dim_editor_on_dialog_popup");
  3352. if (p_dimming) {
  3353. if (dim_ui) {
  3354. if (dim_count == 0) {
  3355. _start_dimming(true);
  3356. }
  3357. dim_count++;
  3358. }
  3359. } else {
  3360. if (dim_count == 1) {
  3361. _start_dimming(false);
  3362. dim_count = 0;
  3363. } else if (dim_ui && dim_count > 0) {
  3364. dim_count--;
  3365. }
  3366. }
  3367. }
  3368. void EditorNode::_start_dimming(bool p_dimming) {
  3369. _dimming = p_dimming;
  3370. _dim_time = 0.0f;
  3371. _dim_timer->start();
  3372. }
  3373. void EditorNode::_dim_timeout() {
  3374. _dim_time += _dim_timer->get_wait_time();
  3375. float wait_time = EditorSettings::get_singleton()->get("interface/editor/dim_transition_time");
  3376. float c = 1.0f - (float)EditorSettings::get_singleton()->get("interface/editor/dim_amount");
  3377. Color base = _dimming ? Color(1, 1, 1) : Color(c, c, c);
  3378. Color final = _dimming ? Color(c, c, c) : Color(1, 1, 1);
  3379. if (_dim_time + _dim_timer->get_wait_time() >= wait_time) {
  3380. gui_base->set_modulate(final);
  3381. _dim_timer->stop();
  3382. } else {
  3383. gui_base->set_modulate(base.linear_interpolate(final, _dim_time / wait_time));
  3384. }
  3385. }
  3386. void EditorNode::open_export_template_manager() {
  3387. export_template_manager->popup_manager();
  3388. }
  3389. void EditorNode::add_resource_conversion_plugin(const Ref<EditorResourceConversionPlugin> &p_plugin) {
  3390. resource_conversion_plugins.push_back(p_plugin);
  3391. }
  3392. void EditorNode::remove_resource_conversion_plugin(const Ref<EditorResourceConversionPlugin> &p_plugin) {
  3393. resource_conversion_plugins.erase(p_plugin);
  3394. }
  3395. Vector<Ref<EditorResourceConversionPlugin> > EditorNode::find_resource_conversion_plugin(const Ref<Resource> &p_for_resource) {
  3396. Vector<Ref<EditorResourceConversionPlugin> > ret;
  3397. for (int i = 0; i < resource_conversion_plugins.size(); i++) {
  3398. if (resource_conversion_plugins[i].is_valid() && resource_conversion_plugins[i]->handles(p_for_resource)) {
  3399. ret.push_back(resource_conversion_plugins[i]);
  3400. }
  3401. }
  3402. return ret;
  3403. }
  3404. void EditorNode::_bottom_panel_raise_toggled(bool p_pressed) {
  3405. if (p_pressed) {
  3406. top_split->hide();
  3407. bottom_panel_raise->set_icon(gui_base->get_icon("ShrinkBottomDock", "EditorIcons"));
  3408. } else {
  3409. top_split->show();
  3410. bottom_panel_raise->set_icon(gui_base->get_icon("ExpandBottomDock", "EditorIcons"));
  3411. }
  3412. }
  3413. void EditorNode::_video_driver_selected(int p_which) {
  3414. String driver = video_driver->get_item_metadata(p_which);
  3415. String current = OS::get_singleton()->get_video_driver_name(OS::get_singleton()->get_current_video_driver());
  3416. if (driver == current) {
  3417. return;
  3418. }
  3419. video_driver_request = driver;
  3420. video_restart_dialog->popup_centered_minsize();
  3421. video_driver->select(video_driver_current);
  3422. }
  3423. void EditorNode::_bind_methods() {
  3424. ClassDB::bind_method("_menu_option", &EditorNode::_menu_option);
  3425. ClassDB::bind_method("_tool_menu_option", &EditorNode::_tool_menu_option);
  3426. ClassDB::bind_method("_menu_confirm_current", &EditorNode::_menu_confirm_current);
  3427. ClassDB::bind_method("_dialog_action", &EditorNode::_dialog_action);
  3428. ClassDB::bind_method("_editor_select", &EditorNode::_editor_select);
  3429. ClassDB::bind_method("_node_renamed", &EditorNode::_node_renamed);
  3430. ClassDB::bind_method("edit_node", &EditorNode::edit_node);
  3431. ClassDB::bind_method("_unhandled_input", &EditorNode::_unhandled_input);
  3432. ClassDB::bind_method("_get_scene_metadata", &EditorNode::_get_scene_metadata);
  3433. ClassDB::bind_method("set_edited_scene", &EditorNode::set_edited_scene);
  3434. ClassDB::bind_method("open_request", &EditorNode::open_request);
  3435. ClassDB::bind_method("_instance_request", &EditorNode::_instance_request);
  3436. ClassDB::bind_method("_close_messages", &EditorNode::_close_messages);
  3437. ClassDB::bind_method("_show_messages", &EditorNode::_show_messages);
  3438. ClassDB::bind_method("_vp_resized", &EditorNode::_vp_resized);
  3439. ClassDB::bind_method("_quick_opened", &EditorNode::_quick_opened);
  3440. ClassDB::bind_method("_quick_run", &EditorNode::_quick_run);
  3441. ClassDB::bind_method("_open_recent_scene", &EditorNode::_open_recent_scene);
  3442. ClassDB::bind_method("stop_child_process", &EditorNode::stop_child_process);
  3443. ClassDB::bind_method("get_script_create_dialog", &EditorNode::get_script_create_dialog);
  3444. ClassDB::bind_method("_sources_changed", &EditorNode::_sources_changed);
  3445. ClassDB::bind_method("_fs_changed", &EditorNode::_fs_changed);
  3446. ClassDB::bind_method("_dock_select_draw", &EditorNode::_dock_select_draw);
  3447. ClassDB::bind_method("_dock_select_input", &EditorNode::_dock_select_input);
  3448. ClassDB::bind_method("_dock_pre_popup", &EditorNode::_dock_pre_popup);
  3449. ClassDB::bind_method("_dock_split_dragged", &EditorNode::_dock_split_dragged);
  3450. ClassDB::bind_method("_save_docks", &EditorNode::_save_docks);
  3451. ClassDB::bind_method("_dock_popup_exit", &EditorNode::_dock_popup_exit);
  3452. ClassDB::bind_method("_dock_move_left", &EditorNode::_dock_move_left);
  3453. ClassDB::bind_method("_dock_move_right", &EditorNode::_dock_move_right);
  3454. ClassDB::bind_method("_dock_tab_changed", &EditorNode::_dock_tab_changed);
  3455. ClassDB::bind_method("_layout_menu_option", &EditorNode::_layout_menu_option);
  3456. ClassDB::bind_method("set_current_scene", &EditorNode::set_current_scene);
  3457. ClassDB::bind_method("set_current_version", &EditorNode::set_current_version);
  3458. ClassDB::bind_method("_scene_tab_changed", &EditorNode::_scene_tab_changed);
  3459. ClassDB::bind_method("_scene_tab_closed", &EditorNode::_scene_tab_closed);
  3460. ClassDB::bind_method("_scene_tab_hover", &EditorNode::_scene_tab_hover);
  3461. ClassDB::bind_method("_scene_tab_exit", &EditorNode::_scene_tab_exit);
  3462. ClassDB::bind_method("_scene_tab_input", &EditorNode::_scene_tab_input);
  3463. ClassDB::bind_method("_reposition_active_tab", &EditorNode::_reposition_active_tab);
  3464. ClassDB::bind_method("_thumbnail_done", &EditorNode::_thumbnail_done);
  3465. ClassDB::bind_method("_scene_tab_script_edited", &EditorNode::_scene_tab_script_edited);
  3466. ClassDB::bind_method("_set_main_scene_state", &EditorNode::_set_main_scene_state);
  3467. ClassDB::bind_method("_update_scene_tabs", &EditorNode::_update_scene_tabs);
  3468. ClassDB::bind_method("_discard_changes", &EditorNode::_discard_changes);
  3469. ClassDB::bind_method("_update_recent_scenes", &EditorNode::_update_recent_scenes);
  3470. ClassDB::bind_method("_clear_undo_history", &EditorNode::_clear_undo_history);
  3471. ClassDB::bind_method("_dropped_files", &EditorNode::_dropped_files);
  3472. ClassDB::bind_method("_toggle_distraction_free_mode", &EditorNode::_toggle_distraction_free_mode);
  3473. ClassDB::bind_method(D_METHOD("get_gui_base"), &EditorNode::get_gui_base);
  3474. ClassDB::bind_method(D_METHOD("_bottom_panel_switch"), &EditorNode::_bottom_panel_switch);
  3475. ClassDB::bind_method(D_METHOD("_open_imported"), &EditorNode::_open_imported);
  3476. ClassDB::bind_method(D_METHOD("_inherit_imported"), &EditorNode::_inherit_imported);
  3477. ClassDB::bind_method(D_METHOD("_dim_timeout"), &EditorNode::_dim_timeout);
  3478. ClassDB::bind_method(D_METHOD("_resources_reimported"), &EditorNode::_resources_reimported);
  3479. ClassDB::bind_method(D_METHOD("_bottom_panel_raise_toggled"), &EditorNode::_bottom_panel_raise_toggled);
  3480. ClassDB::bind_method(D_METHOD("_video_driver_selected"), &EditorNode::_video_driver_selected);
  3481. ADD_SIGNAL(MethodInfo("play_pressed"));
  3482. ADD_SIGNAL(MethodInfo("pause_pressed"));
  3483. ADD_SIGNAL(MethodInfo("stop_pressed"));
  3484. ADD_SIGNAL(MethodInfo("request_help_search"));
  3485. ADD_SIGNAL(MethodInfo("request_help_index"));
  3486. ADD_SIGNAL(MethodInfo("script_add_function_request", PropertyInfo(Variant::OBJECT, "obj"), PropertyInfo(Variant::STRING, "function"), PropertyInfo(Variant::POOL_STRING_ARRAY, "args")));
  3487. ADD_SIGNAL(MethodInfo("resource_saved", PropertyInfo(Variant::OBJECT, "obj")));
  3488. }
  3489. static Node *_resource_get_edited_scene() {
  3490. return EditorNode::get_singleton()->get_edited_scene();
  3491. }
  3492. void EditorNode::_print_handler(void *p_this, const String &p_string, bool p_error) {
  3493. EditorNode *en = (EditorNode *)p_this;
  3494. en->log->add_message(p_string, p_error);
  3495. }
  3496. EditorNode::EditorNode() {
  3497. Resource::_get_local_scene_func = _resource_get_edited_scene;
  3498. VisualServer::get_singleton()->textures_keep_original(true);
  3499. VisualServer::get_singleton()->set_debug_generate_wireframes(true);
  3500. EditorHelp::generate_doc(); //before any editor classes are crated
  3501. SceneState::set_disable_placeholders(true);
  3502. ResourceLoader::clear_translation_remaps(); //no remaps using during editor
  3503. ResourceLoader::clear_path_remaps();
  3504. editor_initialize_certificates(); //for asset sharing
  3505. InputDefault *id = Object::cast_to<InputDefault>(Input::get_singleton());
  3506. if (id) {
  3507. if (!OS::get_singleton()->has_touchscreen_ui_hint() && Input::get_singleton()) {
  3508. //only if no touchscreen ui hint, set emulation
  3509. id->set_emulate_touch_from_mouse(false); //just disable just in case
  3510. }
  3511. id->set_custom_mouse_cursor(RES());
  3512. }
  3513. singleton = this;
  3514. exiting = false;
  3515. last_checked_version = 0;
  3516. changing_scene = false;
  3517. _initializing_addons = false;
  3518. docks_visible = true;
  3519. restoring_scenes = false;
  3520. scene_distraction = false;
  3521. script_distraction = false;
  3522. TranslationServer::get_singleton()->set_enabled(false);
  3523. // load settings
  3524. if (!EditorSettings::get_singleton())
  3525. EditorSettings::create();
  3526. FileAccess::set_backup_save(EDITOR_GET("filesystem/on_save/safe_save_on_backup_then_rename"));
  3527. {
  3528. int display_scale = EditorSettings::get_singleton()->get("interface/editor/display_scale");
  3529. float custom_display_scale = EditorSettings::get_singleton()->get("interface/editor/custom_display_scale");
  3530. switch (display_scale) {
  3531. case 0: {
  3532. // Try applying a suitable display scale automatically
  3533. const int screen = OS::get_singleton()->get_current_screen();
  3534. editor_set_scale(OS::get_singleton()->get_screen_dpi(screen) >= 192 && OS::get_singleton()->get_screen_size(screen).x > 2000 ? 2.0 : 1.0);
  3535. } break;
  3536. case 1: {
  3537. editor_set_scale(0.75);
  3538. } break;
  3539. case 2: {
  3540. editor_set_scale(1.0);
  3541. } break;
  3542. case 3: {
  3543. editor_set_scale(1.25);
  3544. } break;
  3545. case 4: {
  3546. editor_set_scale(1.5);
  3547. } break;
  3548. case 5: {
  3549. editor_set_scale(1.75);
  3550. } break;
  3551. case 6: {
  3552. editor_set_scale(2.0);
  3553. } break;
  3554. default: {
  3555. editor_set_scale(custom_display_scale);
  3556. } break;
  3557. }
  3558. }
  3559. ResourceLoader::set_abort_on_missing_resources(false);
  3560. FileDialog::set_default_show_hidden_files(EditorSettings::get_singleton()->get("filesystem/file_dialog/show_hidden_files"));
  3561. EditorFileDialog::set_default_show_hidden_files(EditorSettings::get_singleton()->get("filesystem/file_dialog/show_hidden_files"));
  3562. EditorFileDialog::set_default_display_mode((EditorFileDialog::DisplayMode)EditorSettings::get_singleton()->get("filesystem/file_dialog/display_mode").operator int());
  3563. ResourceLoader::set_error_notify_func(this, _load_error_notify);
  3564. ResourceLoader::set_dependency_error_notify_func(this, _dependency_error_report);
  3565. ResourceLoader::set_timestamp_on_load(true);
  3566. ResourceSaver::set_timestamp_on_save(true);
  3567. { //register importers at the beginning, so dialogs are created with the right extensions
  3568. Ref<ResourceImporterTexture> import_texture;
  3569. import_texture.instance();
  3570. ResourceFormatImporter::get_singleton()->add_importer(import_texture);
  3571. Ref<ResourceImporterCSVTranslation> import_csv_translation;
  3572. import_csv_translation.instance();
  3573. ResourceFormatImporter::get_singleton()->add_importer(import_csv_translation);
  3574. Ref<ResourceImporterWAV> import_wav;
  3575. import_wav.instance();
  3576. ResourceFormatImporter::get_singleton()->add_importer(import_wav);
  3577. Ref<ResourceImporterOBJ> import_obj;
  3578. import_obj.instance();
  3579. ResourceFormatImporter::get_singleton()->add_importer(import_obj);
  3580. Ref<ResourceImporterScene> import_scene;
  3581. import_scene.instance();
  3582. ResourceFormatImporter::get_singleton()->add_importer(import_scene);
  3583. {
  3584. Ref<EditorSceneImporterCollada> import_collada;
  3585. import_collada.instance();
  3586. import_scene->add_importer(import_collada);
  3587. Ref<EditorOBJImporter> import_obj;
  3588. import_obj.instance();
  3589. import_scene->add_importer(import_obj);
  3590. Ref<EditorSceneImporterGLTF> import_gltf;
  3591. import_gltf.instance();
  3592. import_scene->add_importer(import_gltf);
  3593. Ref<EditorSceneImporterESCN> import_escn;
  3594. import_escn.instance();
  3595. import_scene->add_importer(import_escn);
  3596. }
  3597. Ref<ResourceImporterBitMap> import_bitmap;
  3598. import_bitmap.instance();
  3599. ResourceFormatImporter::get_singleton()->add_importer(import_bitmap);
  3600. }
  3601. {
  3602. Ref<EditorInspectorDefaultPlugin> eidp;
  3603. eidp.instance();
  3604. EditorInspector::add_inspector_plugin(eidp);
  3605. Ref<EditorInspectorRootMotionPlugin> rmp;
  3606. rmp.instance();
  3607. EditorInspector::add_inspector_plugin(rmp);
  3608. Ref<EditorInspectorShaderModePlugin> smp;
  3609. smp.instance();
  3610. EditorInspector::add_inspector_plugin(smp);
  3611. }
  3612. _pvrtc_register_compressors();
  3613. editor_selection = memnew(EditorSelection);
  3614. EditorFileSystem *efs = memnew(EditorFileSystem);
  3615. add_child(efs);
  3616. //used for previews
  3617. FileDialog::get_icon_func = _file_dialog_get_icon;
  3618. FileDialog::register_func = _file_dialog_register;
  3619. FileDialog::unregister_func = _file_dialog_unregister;
  3620. EditorFileDialog::get_icon_func = _file_dialog_get_icon;
  3621. EditorFileDialog::register_func = _editor_file_dialog_register;
  3622. EditorFileDialog::unregister_func = _editor_file_dialog_unregister;
  3623. editor_export = memnew(EditorExport);
  3624. add_child(editor_export);
  3625. register_exporters();
  3626. GLOBAL_DEF("editor/main_run_args", "");
  3627. ClassDB::set_class_enabled("RootMotionView", true);
  3628. //defs here, use EDITOR_GET in logic
  3629. EDITOR_DEF_RST("interface/scene_tabs/always_show_close_button", false);
  3630. EDITOR_DEF_RST("interface/scene_tabs/resize_if_many_tabs", true);
  3631. EDITOR_DEF_RST("interface/scene_tabs/minimum_width", 50);
  3632. EDITOR_DEF("run/output/always_clear_output_on_play", true);
  3633. EDITOR_DEF("run/output/always_open_output_on_play", true);
  3634. EDITOR_DEF("run/output/always_close_output_on_stop", true);
  3635. EDITOR_DEF("run/auto_save/save_before_running", true);
  3636. EDITOR_DEF_RST("interface/editor/save_each_scene_on_quit", true);
  3637. EDITOR_DEF("interface/editor/quit_confirmation", true);
  3638. EDITOR_DEF_RST("interface/scene_tabs/restore_scenes_on_load", false);
  3639. EDITOR_DEF_RST("interface/scene_tabs/show_thumbnail_on_hover", true);
  3640. EDITOR_DEF_RST("interface/inspector/capitalize_properties", true);
  3641. EDITOR_DEF_RST("interface/inspector/disable_folding", false);
  3642. EDITOR_DEF("interface/inspector/open_resources_in_current_inspector", true);
  3643. EDITOR_DEF("interface/inspector/resources_types_to_open_in_new_inspector", "SpatialMaterial");
  3644. EDITOR_DEF("run/auto_save/save_before_running", true);
  3645. theme_base = memnew(Control);
  3646. add_child(theme_base);
  3647. theme_base->set_anchors_and_margins_preset(Control::PRESET_WIDE);
  3648. gui_base = memnew(Panel);
  3649. theme_base->add_child(gui_base);
  3650. gui_base->set_anchors_and_margins_preset(Control::PRESET_WIDE);
  3651. Ref<Theme> theme = create_custom_theme();
  3652. theme_base->set_theme(theme);
  3653. gui_base->set_theme(theme);
  3654. gui_base->add_style_override("panel", gui_base->get_stylebox("Background", "EditorStyles"));
  3655. resource_preview = memnew(EditorResourcePreview);
  3656. add_child(resource_preview);
  3657. progress_dialog = memnew(ProgressDialog);
  3658. gui_base->add_child(progress_dialog);
  3659. // take up all screen
  3660. gui_base->set_anchor(MARGIN_RIGHT, Control::ANCHOR_END);
  3661. gui_base->set_anchor(MARGIN_BOTTOM, Control::ANCHOR_END);
  3662. gui_base->set_end(Point2(0, 0));
  3663. main_vbox = memnew(VBoxContainer);
  3664. gui_base->add_child(main_vbox);
  3665. main_vbox->set_anchors_and_margins_preset(Control::PRESET_WIDE, Control::PRESET_MODE_MINSIZE, 8);
  3666. main_vbox->set_margin(MARGIN_TOP, 5 * EDSCALE);
  3667. menu_hb = memnew(HBoxContainer);
  3668. main_vbox->add_child(menu_hb);
  3669. left_l_hsplit = memnew(HSplitContainer);
  3670. main_vbox->add_child(left_l_hsplit);
  3671. left_l_hsplit->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  3672. left_l_vsplit = memnew(VSplitContainer);
  3673. left_l_hsplit->add_child(left_l_vsplit);
  3674. dock_slot[DOCK_SLOT_LEFT_UL] = memnew(TabContainer);
  3675. left_l_vsplit->add_child(dock_slot[DOCK_SLOT_LEFT_UL]);
  3676. dock_slot[DOCK_SLOT_LEFT_BL] = memnew(TabContainer);
  3677. left_l_vsplit->add_child(dock_slot[DOCK_SLOT_LEFT_BL]);
  3678. left_l_vsplit->hide();
  3679. dock_slot[DOCK_SLOT_LEFT_UL]->hide();
  3680. dock_slot[DOCK_SLOT_LEFT_BL]->hide();
  3681. left_r_hsplit = memnew(HSplitContainer);
  3682. left_l_hsplit->add_child(left_r_hsplit);
  3683. left_r_vsplit = memnew(VSplitContainer);
  3684. left_r_hsplit->add_child(left_r_vsplit);
  3685. dock_slot[DOCK_SLOT_LEFT_UR] = memnew(TabContainer);
  3686. left_r_vsplit->add_child(dock_slot[DOCK_SLOT_LEFT_UR]);
  3687. dock_slot[DOCK_SLOT_LEFT_BR] = memnew(TabContainer);
  3688. left_r_vsplit->add_child(dock_slot[DOCK_SLOT_LEFT_BR]);
  3689. main_hsplit = memnew(HSplitContainer);
  3690. left_r_hsplit->add_child(main_hsplit);
  3691. VBoxContainer *center_vb = memnew(VBoxContainer);
  3692. main_hsplit->add_child(center_vb);
  3693. center_vb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  3694. center_split = memnew(VSplitContainer);
  3695. center_split->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  3696. center_split->set_collapsed(false);
  3697. center_vb->add_child(center_split);
  3698. right_hsplit = memnew(HSplitContainer);
  3699. main_hsplit->add_child(right_hsplit);
  3700. right_l_vsplit = memnew(VSplitContainer);
  3701. right_hsplit->add_child(right_l_vsplit);
  3702. dock_slot[DOCK_SLOT_RIGHT_UL] = memnew(TabContainer);
  3703. right_l_vsplit->add_child(dock_slot[DOCK_SLOT_RIGHT_UL]);
  3704. dock_slot[DOCK_SLOT_RIGHT_BL] = memnew(TabContainer);
  3705. right_l_vsplit->add_child(dock_slot[DOCK_SLOT_RIGHT_BL]);
  3706. right_r_vsplit = memnew(VSplitContainer);
  3707. right_hsplit->add_child(right_r_vsplit);
  3708. dock_slot[DOCK_SLOT_RIGHT_UR] = memnew(TabContainer);
  3709. right_r_vsplit->add_child(dock_slot[DOCK_SLOT_RIGHT_UR]);
  3710. dock_slot[DOCK_SLOT_RIGHT_BR] = memnew(TabContainer);
  3711. right_r_vsplit->add_child(dock_slot[DOCK_SLOT_RIGHT_BR]);
  3712. right_r_vsplit->hide();
  3713. dock_slot[DOCK_SLOT_RIGHT_UR]->hide();
  3714. dock_slot[DOCK_SLOT_RIGHT_BR]->hide();
  3715. left_l_vsplit->connect("dragged", this, "_dock_split_dragged");
  3716. left_r_vsplit->connect("dragged", this, "_dock_split_dragged");
  3717. right_l_vsplit->connect("dragged", this, "_dock_split_dragged");
  3718. right_r_vsplit->connect("dragged", this, "_dock_split_dragged");
  3719. left_l_hsplit->connect("dragged", this, "_dock_split_dragged");
  3720. left_r_hsplit->connect("dragged", this, "_dock_split_dragged");
  3721. main_hsplit->connect("dragged", this, "_dock_split_dragged");
  3722. right_hsplit->connect("dragged", this, "_dock_split_dragged");
  3723. dock_select_popup = memnew(PopupPanel);
  3724. gui_base->add_child(dock_select_popup);
  3725. VBoxContainer *dock_vb = memnew(VBoxContainer);
  3726. dock_select_popup->add_child(dock_vb);
  3727. HBoxContainer *dock_hb = memnew(HBoxContainer);
  3728. dock_tab_move_left = memnew(ToolButton);
  3729. dock_tab_move_left->set_icon(theme->get_icon("Back", "EditorIcons"));
  3730. dock_tab_move_left->set_focus_mode(Control::FOCUS_NONE);
  3731. dock_tab_move_left->connect("pressed", this, "_dock_move_left");
  3732. dock_hb->add_child(dock_tab_move_left);
  3733. Label *dock_label = memnew(Label);
  3734. dock_label->set_text(TTR("Dock Position"));
  3735. dock_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  3736. dock_hb->add_child(dock_label);
  3737. dock_tab_move_right = memnew(ToolButton);
  3738. dock_tab_move_right->set_icon(theme->get_icon("Forward", "EditorIcons"));
  3739. dock_tab_move_right->set_focus_mode(Control::FOCUS_NONE);
  3740. dock_tab_move_right->connect("pressed", this, "_dock_move_right");
  3741. dock_hb->add_child(dock_tab_move_right);
  3742. dock_vb->add_child(dock_hb);
  3743. dock_select = memnew(Control);
  3744. dock_select->set_custom_minimum_size(Size2(128, 64) * EDSCALE);
  3745. dock_select->connect("gui_input", this, "_dock_select_input");
  3746. dock_select->connect("draw", this, "_dock_select_draw");
  3747. dock_select->connect("mouse_exited", this, "_dock_popup_exit");
  3748. dock_select->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  3749. dock_vb->add_child(dock_select);
  3750. dock_select_popup->set_as_minsize();
  3751. dock_select_rect_over = -1;
  3752. dock_popup_selected = -1;
  3753. for (int i = 0; i < DOCK_SLOT_MAX; i++) {
  3754. dock_slot[i]->set_custom_minimum_size(Size2(230, 220) * EDSCALE);
  3755. dock_slot[i]->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  3756. dock_slot[i]->set_popup(dock_select_popup);
  3757. dock_slot[i]->connect("pre_popup_pressed", this, "_dock_pre_popup", varray(i));
  3758. dock_slot[i]->set_tab_align(TabContainer::ALIGN_LEFT);
  3759. dock_slot[i]->set_drag_to_rearrange_enabled(true);
  3760. dock_slot[i]->set_tabs_rearrange_group(1);
  3761. dock_slot[i]->connect("tab_changed", this, "_dock_tab_changed");
  3762. }
  3763. dock_drag_timer = memnew(Timer);
  3764. add_child(dock_drag_timer);
  3765. dock_drag_timer->set_wait_time(0.5);
  3766. dock_drag_timer->set_one_shot(true);
  3767. dock_drag_timer->connect("timeout", this, "_save_docks");
  3768. top_split = memnew(VSplitContainer);
  3769. center_split->add_child(top_split);
  3770. top_split->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  3771. top_split->set_collapsed(true);
  3772. VBoxContainer *srt = memnew(VBoxContainer);
  3773. srt->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  3774. top_split->add_child(srt);
  3775. srt->add_constant_override("separation", 0);
  3776. tab_preview_panel = memnew(Panel);
  3777. tab_preview_panel->set_size(Size2(100, 100) * EDSCALE);
  3778. tab_preview_panel->hide();
  3779. tab_preview_panel->set_self_modulate(Color(1, 1, 1, 0.7));
  3780. gui_base->add_child(tab_preview_panel);
  3781. tab_preview = memnew(TextureRect);
  3782. tab_preview->set_stretch_mode(TextureRect::STRETCH_KEEP_ASPECT_CENTERED);
  3783. tab_preview->set_size(Size2(96, 96) * EDSCALE);
  3784. tab_preview->set_position(Point2(2, 2) * EDSCALE);
  3785. tab_preview_panel->add_child(tab_preview);
  3786. scene_tabs = memnew(Tabs);
  3787. scene_tabs->add_style_override("tab_fg", gui_base->get_stylebox("SceneTabFG", "EditorStyles"));
  3788. scene_tabs->add_style_override("tab_bg", gui_base->get_stylebox("SceneTabBG", "EditorStyles"));
  3789. scene_tabs->add_tab("unsaved");
  3790. scene_tabs->set_tab_align(Tabs::ALIGN_LEFT);
  3791. scene_tabs->set_tab_close_display_policy((bool(EDITOR_DEF("interface/scene_tabs/always_show_close_button", false)) ? Tabs::CLOSE_BUTTON_SHOW_ALWAYS : Tabs::CLOSE_BUTTON_SHOW_ACTIVE_ONLY));
  3792. scene_tabs->set_min_width(int(EDITOR_DEF("interface/scene_tabs/minimum_width", 50)) * EDSCALE);
  3793. scene_tabs->set_drag_to_rearrange_enabled(true);
  3794. scene_tabs->connect("tab_changed", this, "_scene_tab_changed");
  3795. scene_tabs->connect("right_button_pressed", this, "_scene_tab_script_edited");
  3796. scene_tabs->connect("tab_close", this, "_scene_tab_closed");
  3797. scene_tabs->connect("tab_hover", this, "_scene_tab_hover");
  3798. scene_tabs->connect("mouse_exited", this, "_scene_tab_exit");
  3799. scene_tabs->connect("gui_input", this, "_scene_tab_input");
  3800. scene_tabs->connect("reposition_active_tab_request", this, "_reposition_active_tab");
  3801. scene_tabs->connect("resized", this, "_update_scene_tabs");
  3802. tabbar_container = memnew(HBoxContainer);
  3803. scene_tabs->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  3804. srt->add_child(tabbar_container);
  3805. tabbar_container->add_child(scene_tabs);
  3806. distraction_free = memnew(ToolButton);
  3807. #ifdef OSX_ENABLED
  3808. distraction_free->set_shortcut(ED_SHORTCUT("editor/distraction_free_mode", TTR("Distraction Free Mode"), KEY_MASK_CMD | KEY_MASK_CTRL | KEY_D));
  3809. #else
  3810. distraction_free->set_shortcut(ED_SHORTCUT("editor/distraction_free_mode", TTR("Distraction Free Mode"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_F11));
  3811. #endif
  3812. distraction_free->set_tooltip(TTR("Toggle distraction-free mode."));
  3813. distraction_free->connect("pressed", this, "_toggle_distraction_free_mode");
  3814. distraction_free->set_icon(gui_base->get_icon("DistractionFree", "EditorIcons"));
  3815. distraction_free->set_toggle_mode(true);
  3816. scene_tab_add = memnew(ToolButton);
  3817. tabbar_container->add_child(scene_tab_add);
  3818. tabbar_container->add_child(distraction_free);
  3819. scene_tab_add->set_tooltip(TTR("Add a new scene."));
  3820. scene_tab_add->set_icon(gui_base->get_icon("Add", "EditorIcons"));
  3821. scene_tab_add->add_color_override("icon_color_normal", Color(0.6f, 0.6f, 0.6f, 0.8f));
  3822. scene_tab_add->connect("pressed", this, "_menu_option", make_binds(FILE_NEW_SCENE));
  3823. scene_root_parent = memnew(PanelContainer);
  3824. scene_root_parent->set_custom_minimum_size(Size2(0, 80) * EDSCALE);
  3825. scene_root_parent->add_style_override("panel", gui_base->get_stylebox("Content", "EditorStyles"));
  3826. scene_root_parent->set_draw_behind_parent(true);
  3827. srt->add_child(scene_root_parent);
  3828. scene_root_parent->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  3829. scene_root = memnew(Viewport);
  3830. //scene_root->set_usage(Viewport::USAGE_2D); canvas BG mode prevents usage of this as 2D
  3831. scene_root->set_disable_3d(true);
  3832. VisualServer::get_singleton()->viewport_set_hide_scenario(scene_root->get_viewport_rid(), true);
  3833. scene_root->set_disable_input(true);
  3834. scene_root->set_as_audio_listener_2d(true);
  3835. viewport = memnew(VBoxContainer);
  3836. viewport->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  3837. viewport->add_constant_override("separation", 0);
  3838. scene_root_parent->add_child(viewport);
  3839. PanelContainer *top_region = memnew(PanelContainer);
  3840. top_region->add_style_override("panel", gui_base->get_stylebox("MenuPanel", "EditorStyles"));
  3841. HBoxContainer *left_menu_hb = memnew(HBoxContainer);
  3842. top_region->add_child(left_menu_hb);
  3843. menu_hb->add_child(top_region);
  3844. {
  3845. Control *sp = memnew(Control);
  3846. sp->set_custom_minimum_size(Size2(30, 0) * EDSCALE);
  3847. menu_hb->add_child(sp);
  3848. }
  3849. file_menu = memnew(MenuButton);
  3850. file_menu->set_flat(false);
  3851. file_menu->set_text(TTR("Scene"));
  3852. file_menu->add_style_override("hover", gui_base->get_stylebox("MenuHover", "EditorStyles"));
  3853. left_menu_hb->add_child(file_menu);
  3854. prev_scene = memnew(ToolButton);
  3855. prev_scene->set_icon(gui_base->get_icon("PrevScene", "EditorIcons"));
  3856. prev_scene->set_tooltip(TTR("Go to previously opened scene."));
  3857. prev_scene->set_disabled(true);
  3858. prev_scene->connect("pressed", this, "_menu_option", make_binds(FILE_OPEN_PREV));
  3859. gui_base->add_child(prev_scene);
  3860. prev_scene->set_position(Point2(3, 24));
  3861. prev_scene->hide();
  3862. accept = memnew(AcceptDialog);
  3863. gui_base->add_child(accept);
  3864. accept->connect("confirmed", this, "_menu_confirm_current");
  3865. project_export = memnew(ProjectExportDialog);
  3866. gui_base->add_child(project_export);
  3867. dependency_error = memnew(DependencyErrorDialog);
  3868. gui_base->add_child(dependency_error);
  3869. dependency_fixer = memnew(DependencyEditor);
  3870. gui_base->add_child(dependency_fixer);
  3871. settings_config_dialog = memnew(EditorSettingsDialog);
  3872. gui_base->add_child(settings_config_dialog);
  3873. project_settings = memnew(ProjectSettingsEditor(&editor_data));
  3874. gui_base->add_child(project_settings);
  3875. run_settings_dialog = memnew(RunSettingsDialog);
  3876. gui_base->add_child(run_settings_dialog);
  3877. export_template_manager = memnew(ExportTemplateManager);
  3878. gui_base->add_child(export_template_manager);
  3879. about = memnew(EditorAbout);
  3880. gui_base->add_child(about);
  3881. warning = memnew(AcceptDialog);
  3882. gui_base->add_child(warning);
  3883. ED_SHORTCUT("editor/next_tab", TTR("Next tab"), KEY_MASK_CMD + KEY_TAB);
  3884. ED_SHORTCUT("editor/prev_tab", TTR("Previous tab"), KEY_MASK_CMD + KEY_MASK_SHIFT + KEY_TAB);
  3885. ED_SHORTCUT("editor/filter_files", TTR("Filter Files..."), KEY_MASK_ALT + KEY_MASK_CMD + KEY_P);
  3886. PopupMenu *p;
  3887. file_menu->set_tooltip(TTR("Operations with scene files."));
  3888. p = file_menu->get_popup();
  3889. p->add_shortcut(ED_SHORTCUT("editor/new_scene", TTR("New Scene")), FILE_NEW_SCENE);
  3890. p->add_shortcut(ED_SHORTCUT("editor/new_inherited_scene", TTR("New Inherited Scene...")), FILE_NEW_INHERITED_SCENE);
  3891. p->add_shortcut(ED_SHORTCUT("editor/open_scene", TTR("Open Scene..."), KEY_MASK_CMD + KEY_O), FILE_OPEN_SCENE);
  3892. p->add_separator();
  3893. p->add_shortcut(ED_SHORTCUT("editor/save_scene", TTR("Save Scene"), KEY_MASK_CMD + KEY_S), FILE_SAVE_SCENE);
  3894. p->add_shortcut(ED_SHORTCUT("editor/save_scene_as", TTR("Save Scene As..."), KEY_MASK_SHIFT + KEY_MASK_CMD + KEY_S), FILE_SAVE_AS_SCENE);
  3895. p->add_shortcut(ED_SHORTCUT("editor/save_all_scenes", TTR("Save all Scenes"), KEY_MASK_ALT + KEY_MASK_SHIFT + KEY_MASK_CMD + KEY_S), FILE_SAVE_ALL_SCENES);
  3896. p->add_separator();
  3897. p->add_shortcut(ED_SHORTCUT("editor/close_scene", TTR("Close Scene"), KEY_MASK_SHIFT + KEY_MASK_CMD + KEY_W), FILE_CLOSE);
  3898. p->add_separator();
  3899. p->add_submenu_item(TTR("Open Recent"), "RecentScenes", FILE_OPEN_RECENT);
  3900. p->add_separator();
  3901. p->add_shortcut(ED_SHORTCUT("editor/quick_open_scene", TTR("Quick Open Scene..."), KEY_MASK_SHIFT + KEY_MASK_CMD + KEY_O), FILE_QUICK_OPEN_SCENE);
  3902. p->add_shortcut(ED_SHORTCUT("editor/quick_open_script", TTR("Quick Open Script..."), KEY_MASK_ALT + KEY_MASK_CMD + KEY_O), FILE_QUICK_OPEN_SCRIPT);
  3903. p->add_separator();
  3904. PopupMenu *pm_export = memnew(PopupMenu);
  3905. pm_export->set_name("Export");
  3906. p->add_child(pm_export);
  3907. p->add_submenu_item(TTR("Convert To..."), "Export");
  3908. pm_export->add_shortcut(ED_SHORTCUT("editor/convert_to_MeshLibrary", TTR("MeshLibrary...")), FILE_EXPORT_MESH_LIBRARY);
  3909. pm_export->add_shortcut(ED_SHORTCUT("editor/convert_to_TileSet", TTR("TileSet...")), FILE_EXPORT_TILESET);
  3910. pm_export->connect("id_pressed", this, "_menu_option");
  3911. p->add_separator();
  3912. p->add_shortcut(ED_SHORTCUT("editor/undo", TTR("Undo"), KEY_MASK_CMD + KEY_Z), EDIT_UNDO, true);
  3913. p->add_shortcut(ED_SHORTCUT("editor/redo", TTR("Redo"), KEY_MASK_SHIFT + KEY_MASK_CMD + KEY_Z), EDIT_REDO, true);
  3914. p->add_separator();
  3915. p->add_item(TTR("Revert Scene"), EDIT_REVERT);
  3916. recent_scenes = memnew(PopupMenu);
  3917. recent_scenes->set_name("RecentScenes");
  3918. p->add_child(recent_scenes);
  3919. recent_scenes->connect("id_pressed", this, "_open_recent_scene");
  3920. p->add_separator();
  3921. p->add_item(TTR("Quit"), FILE_QUIT, KEY_MASK_CMD + KEY_Q);
  3922. project_menu = memnew(MenuButton);
  3923. project_menu->set_flat(false);
  3924. project_menu->set_tooltip(TTR("Miscellaneous project or scene-wide tools."));
  3925. project_menu->set_text(TTR("Project"));
  3926. project_menu->add_style_override("hover", gui_base->get_stylebox("MenuHover", "EditorStyles"));
  3927. left_menu_hb->add_child(project_menu);
  3928. p = project_menu->get_popup();
  3929. p->add_item(TTR("Project Settings"), RUN_SETTINGS);
  3930. p->add_separator();
  3931. p->connect("id_pressed", this, "_menu_option");
  3932. p->add_item(TTR("Export"), FILE_EXPORT_PROJECT);
  3933. tool_menu = memnew(PopupMenu);
  3934. tool_menu->set_name("Tools");
  3935. tool_menu->connect("index_pressed", this, "_tool_menu_option");
  3936. p->add_child(tool_menu);
  3937. p->add_submenu_item(TTR("Tools"), "Tools");
  3938. tool_menu->add_item(TTR("Orphan Resource Explorer"), TOOLS_ORPHAN_RESOURCES);
  3939. p->add_separator();
  3940. #ifdef OSX_ENABLED
  3941. p->add_item(TTR("Quit to Project List"), RUN_PROJECT_MANAGER, KEY_MASK_SHIFT + KEY_MASK_ALT + KEY_Q);
  3942. #else
  3943. p->add_item(TTR("Quit to Project List"), RUN_PROJECT_MANAGER, KEY_MASK_SHIFT + KEY_MASK_CMD + KEY_Q);
  3944. #endif
  3945. PanelContainer *editor_region = memnew(PanelContainer);
  3946. main_editor_button_vb = memnew(HBoxContainer);
  3947. editor_region->add_child(main_editor_button_vb);
  3948. menu_hb->add_spacer();
  3949. menu_hb->add_child(editor_region);
  3950. debug_menu = memnew(MenuButton);
  3951. debug_menu->set_flat(false);
  3952. debug_menu->set_text(TTR("Debug"));
  3953. debug_menu->add_style_override("hover", gui_base->get_stylebox("MenuHover", "EditorStyles"));
  3954. left_menu_hb->add_child(debug_menu);
  3955. p = debug_menu->get_popup();
  3956. p->set_hide_on_item_selection(false);
  3957. p->add_check_item(TTR("Deploy with Remote Debug"), RUN_DEPLOY_REMOTE_DEBUG);
  3958. p->set_item_tooltip(p->get_item_count() - 1, TTR("When exporting or deploying, the resulting executable will attempt to connect to the IP of this computer in order to be debugged."));
  3959. p->add_check_item(TTR("Small Deploy with Network FS"), RUN_FILE_SERVER);
  3960. p->set_item_tooltip(p->get_item_count() - 1, TTR("When this option is enabled, export or deploy will produce a minimal executable.\nThe filesystem will be provided from the project by the editor over the network.\nOn Android, deploy will use the USB cable for faster performance. This option speeds up testing for games with a large footprint."));
  3961. p->add_separator();
  3962. p->add_check_item(TTR("Visible Collision Shapes"), RUN_DEBUG_COLLISONS);
  3963. p->set_item_tooltip(p->get_item_count() - 1, TTR("Collision shapes and raycast nodes (for 2D and 3D) will be visible on the running game if this option is turned on."));
  3964. p->add_check_item(TTR("Visible Navigation"), RUN_DEBUG_NAVIGATION);
  3965. p->set_item_tooltip(p->get_item_count() - 1, TTR("Navigation meshes and polygons will be visible on the running game if this option is turned on."));
  3966. p->add_separator();
  3967. p->add_check_item(TTR("Sync Scene Changes"), RUN_LIVE_DEBUG);
  3968. p->set_item_tooltip(p->get_item_count() - 1, TTR("When this option is turned on, any changes made to the scene in the editor will be replicated in the running game.\nWhen used remotely on a device, this is more efficient with network filesystem."));
  3969. p->add_check_item(TTR("Sync Script Changes"), RUN_RELOAD_SCRIPTS);
  3970. p->set_item_tooltip(p->get_item_count() - 1, TTR("When this option is turned on, any script that is saved will be reloaded on the running game.\nWhen used remotely on a device, this is more efficient with network filesystem."));
  3971. p->connect("id_pressed", this, "_menu_option");
  3972. menu_hb->add_spacer();
  3973. settings_menu = memnew(MenuButton);
  3974. settings_menu->set_flat(false);
  3975. settings_menu->set_text(TTR("Editor"));
  3976. settings_menu->add_style_override("hover", gui_base->get_stylebox("MenuHover", "EditorStyles"));
  3977. left_menu_hb->add_child(settings_menu);
  3978. p = settings_menu->get_popup();
  3979. p->add_item(TTR("Editor Settings"), SETTINGS_PREFERENCES);
  3980. p->add_separator();
  3981. editor_layouts = memnew(PopupMenu);
  3982. editor_layouts->set_name("Layouts");
  3983. p->add_child(editor_layouts);
  3984. editor_layouts->connect("id_pressed", this, "_layout_menu_option");
  3985. p->add_submenu_item(TTR("Editor Layout"), "Layouts");
  3986. #ifdef OSX_ENABLED
  3987. p->add_shortcut(ED_SHORTCUT("editor/fullscreen_mode", TTR("Toggle Fullscreen"), KEY_MASK_CMD | KEY_MASK_CTRL | KEY_F), SETTINGS_TOGGLE_FULLSCREEN);
  3988. #else
  3989. p->add_shortcut(ED_SHORTCUT("editor/fullscreen_mode", TTR("Toggle Fullscreen"), KEY_MASK_SHIFT | KEY_F11), SETTINGS_TOGGLE_FULLSCREEN);
  3990. #endif
  3991. p->add_separator();
  3992. p->add_item(TTR("Manage Export Templates"), SETTINGS_MANAGE_EXPORT_TEMPLATES);
  3993. // Help Menu
  3994. help_menu = memnew(MenuButton);
  3995. help_menu->set_flat(false);
  3996. help_menu->set_text(TTR("Help"));
  3997. help_menu->add_style_override("hover", gui_base->get_stylebox("MenuHover", "EditorStyles"));
  3998. left_menu_hb->add_child(help_menu);
  3999. p = help_menu->get_popup();
  4000. p->connect("id_pressed", this, "_menu_option");
  4001. p->add_icon_item(gui_base->get_icon("ClassList", "EditorIcons"), TTR("Classes"), HELP_CLASSES);
  4002. p->add_icon_item(gui_base->get_icon("HelpSearch", "EditorIcons"), TTR("Search"), HELP_SEARCH);
  4003. p->add_separator();
  4004. p->add_icon_item(gui_base->get_icon("Instance", "EditorIcons"), TTR("Online Docs"), HELP_DOCS);
  4005. p->add_icon_item(gui_base->get_icon("Instance", "EditorIcons"), TTR("Q&A"), HELP_QA);
  4006. p->add_icon_item(gui_base->get_icon("Instance", "EditorIcons"), TTR("Issue Tracker"), HELP_ISSUES);
  4007. p->add_icon_item(gui_base->get_icon("Instance", "EditorIcons"), TTR("Community"), HELP_COMMUNITY);
  4008. p->add_separator();
  4009. p->add_icon_item(gui_base->get_icon("Godot", "EditorIcons"), TTR("About"), HELP_ABOUT);
  4010. play_cc = memnew(CenterContainer);
  4011. play_cc->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
  4012. menu_hb->add_child(play_cc);
  4013. play_button_panel = memnew(PanelContainer);
  4014. play_cc->add_child(play_button_panel);
  4015. HBoxContainer *play_hb = memnew(HBoxContainer);
  4016. play_button_panel->add_child(play_hb);
  4017. play_button = memnew(ToolButton);
  4018. play_hb->add_child(play_button);
  4019. play_button->set_toggle_mode(true);
  4020. play_button->set_icon(gui_base->get_icon("MainPlay", "EditorIcons"));
  4021. play_button->set_focus_mode(Control::FOCUS_NONE);
  4022. play_button->connect("pressed", this, "_menu_option", make_binds(RUN_PLAY));
  4023. play_button->set_tooltip(TTR("Play the project."));
  4024. #ifdef OSX_ENABLED
  4025. play_button->set_shortcut(ED_SHORTCUT("editor/play", TTR("Play"), KEY_MASK_CMD | KEY_B));
  4026. #else
  4027. play_button->set_shortcut(ED_SHORTCUT("editor/play", TTR("Play"), KEY_F5));
  4028. #endif
  4029. pause_button = memnew(ToolButton);
  4030. pause_button->set_toggle_mode(true);
  4031. pause_button->set_icon(gui_base->get_icon("Pause", "EditorIcons"));
  4032. pause_button->set_focus_mode(Control::FOCUS_NONE);
  4033. pause_button->set_tooltip(TTR("Pause the scene"));
  4034. pause_button->set_disabled(true);
  4035. play_hb->add_child(pause_button);
  4036. #ifdef OSX_ENABLED
  4037. pause_button->set_shortcut(ED_SHORTCUT("editor/pause_scene", TTR("Pause Scene"), KEY_MASK_CMD | KEY_MASK_CTRL | KEY_Y));
  4038. #else
  4039. pause_button->set_shortcut(ED_SHORTCUT("editor/pause_scene", TTR("Pause Scene"), KEY_F7));
  4040. #endif
  4041. stop_button = memnew(ToolButton);
  4042. play_hb->add_child(stop_button);
  4043. stop_button->set_focus_mode(Control::FOCUS_NONE);
  4044. stop_button->set_icon(gui_base->get_icon("Stop", "EditorIcons"));
  4045. stop_button->connect("pressed", this, "_menu_option", make_binds(RUN_STOP));
  4046. stop_button->set_tooltip(TTR("Stop the scene."));
  4047. stop_button->set_disabled(true);
  4048. #ifdef OSX_ENABLED
  4049. stop_button->set_shortcut(ED_SHORTCUT("editor/stop", TTR("Stop"), KEY_MASK_CMD | KEY_PERIOD));
  4050. #else
  4051. stop_button->set_shortcut(ED_SHORTCUT("editor/stop", TTR("Stop"), KEY_F8));
  4052. #endif
  4053. run_native = memnew(EditorRunNative);
  4054. play_hb->add_child(run_native);
  4055. native_play_button = memnew(MenuButton);
  4056. native_play_button->set_text("NTV");
  4057. menu_hb->add_child(native_play_button);
  4058. native_play_button->hide();
  4059. native_play_button->get_popup()->connect("id_pressed", this, "_run_in_device");
  4060. run_native->connect("native_run", this, "_menu_option", varray(RUN_PLAY_NATIVE));
  4061. play_scene_button = memnew(ToolButton);
  4062. play_hb->add_child(play_scene_button);
  4063. play_scene_button->set_toggle_mode(true);
  4064. play_scene_button->set_focus_mode(Control::FOCUS_NONE);
  4065. play_scene_button->set_icon(gui_base->get_icon("PlayScene", "EditorIcons"));
  4066. play_scene_button->connect("pressed", this, "_menu_option", make_binds(RUN_PLAY_SCENE));
  4067. play_scene_button->set_tooltip(TTR("Play the edited scene."));
  4068. #ifdef OSX_ENABLED
  4069. play_scene_button->set_shortcut(ED_SHORTCUT("editor/play_scene", TTR("Play Scene"), KEY_MASK_CMD | KEY_R));
  4070. #else
  4071. play_scene_button->set_shortcut(ED_SHORTCUT("editor/play_scene", TTR("Play Scene"), KEY_F6));
  4072. #endif
  4073. play_custom_scene_button = memnew(ToolButton);
  4074. play_hb->add_child(play_custom_scene_button);
  4075. play_custom_scene_button->set_toggle_mode(true);
  4076. play_custom_scene_button->set_focus_mode(Control::FOCUS_NONE);
  4077. play_custom_scene_button->set_icon(gui_base->get_icon("PlayCustom", "EditorIcons"));
  4078. play_custom_scene_button->connect("pressed", this, "_menu_option", make_binds(RUN_PLAY_CUSTOM_SCENE));
  4079. play_custom_scene_button->set_tooltip(TTR("Play custom scene"));
  4080. #ifdef OSX_ENABLED
  4081. play_custom_scene_button->set_shortcut(ED_SHORTCUT("editor/play_custom_scene", TTR("Play Custom Scene"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_R));
  4082. #else
  4083. play_custom_scene_button->set_shortcut(ED_SHORTCUT("editor/play_custom_scene", TTR("Play Custom Scene"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_F5));
  4084. #endif
  4085. video_driver = memnew(OptionButton);
  4086. video_driver->set_flat(true);
  4087. video_driver->set_focus_mode(Control::FOCUS_NONE);
  4088. video_driver->set_v_size_flags(Control::SIZE_SHRINK_CENTER);
  4089. String video_drivers = ProjectSettings::get_singleton()->get_custom_property_info()["rendering/quality/driver/driver_name"].hint_string;
  4090. String current_video_driver = OS::get_singleton()->get_video_driver_name(OS::get_singleton()->get_current_video_driver());
  4091. menu_hb->add_child(video_driver);
  4092. video_driver_current = 0;
  4093. for (int i = 0; i < video_drivers.get_slice_count(","); i++) {
  4094. String driver = video_drivers.get_slice(",", i);
  4095. if (gui_base->has_icon(driver, "EditorIcons")) {
  4096. video_driver->add_icon_item(gui_base->get_icon(driver, "EditorIcons"), "");
  4097. } else {
  4098. video_driver->add_item(driver);
  4099. }
  4100. video_driver->set_item_metadata(i, driver);
  4101. if (current_video_driver == driver) {
  4102. video_driver->select(i);
  4103. video_driver_current = i;
  4104. }
  4105. }
  4106. video_driver->connect("item_selected", this, "_video_driver_selected");
  4107. video_restart_dialog = memnew(ConfirmationDialog);
  4108. video_restart_dialog->set_text(TTR("Changing the video driver requires restarting the editor."));
  4109. video_restart_dialog->get_ok()->set_text(TTR("Save & Restart"));
  4110. video_restart_dialog->connect("confirmed", this, "_menu_option", varray(SET_VIDEO_DRIVER_SAVE_AND_RESTART));
  4111. add_child(video_restart_dialog);
  4112. progress_hb = memnew(BackgroundProgress);
  4113. HBoxContainer *right_menu_hb = memnew(HBoxContainer);
  4114. menu_hb->add_child(right_menu_hb);
  4115. layout_dialog = memnew(EditorNameDialog);
  4116. gui_base->add_child(layout_dialog);
  4117. layout_dialog->set_hide_on_ok(false);
  4118. layout_dialog->set_size(Size2(175, 70) * EDSCALE);
  4119. layout_dialog->connect("name_confirmed", this, "_dialog_action");
  4120. update_menu = memnew(MenuButton);
  4121. update_menu->set_tooltip(TTR("Spins when the editor window repaints!"));
  4122. right_menu_hb->add_child(update_menu);
  4123. update_menu->set_icon(gui_base->get_icon("Progress1", "EditorIcons"));
  4124. update_menu->get_popup()->connect("id_pressed", this, "_menu_option");
  4125. p = update_menu->get_popup();
  4126. p->add_check_item(TTR("Update Always"), SETTINGS_UPDATE_ALWAYS);
  4127. p->add_check_item(TTR("Update Changes"), SETTINGS_UPDATE_CHANGES);
  4128. p->add_separator();
  4129. p->add_check_item(TTR("Disable Update Spinner"), SETTINGS_UPDATE_SPINNER_HIDE);
  4130. int update_always = EditorSettings::get_singleton()->get_project_metadata("editor_options", "update_always", false);
  4131. int hide_spinner = EditorSettings::get_singleton()->get_project_metadata("editor_options", "update_spinner_hide", false);
  4132. _menu_option(update_always ? SETTINGS_UPDATE_ALWAYS : SETTINGS_UPDATE_CHANGES);
  4133. if (hide_spinner) {
  4134. _menu_option(SETTINGS_UPDATE_SPINNER_HIDE);
  4135. }
  4136. scene_tree_dock = memnew(SceneTreeDock(this, scene_root, editor_selection, editor_data));
  4137. dock_slot[DOCK_SLOT_RIGHT_UL]->add_child(scene_tree_dock);
  4138. dock_slot[DOCK_SLOT_RIGHT_UL]->set_tab_title(scene_tree_dock->get_index(), TTR("Scene"));
  4139. dock_slot[DOCK_SLOT_LEFT_BR]->hide();
  4140. inspector_dock = memnew(InspectorDock(this, editor_data));
  4141. dock_slot[DOCK_SLOT_RIGHT_BL]->add_child(inspector_dock);
  4142. dock_slot[DOCK_SLOT_RIGHT_BL]->set_tab_title(inspector_dock->get_index(), TTR("Inspector"));
  4143. Button *property_editable_warning;
  4144. import_dock = memnew(ImportDock);
  4145. dock_slot[DOCK_SLOT_RIGHT_UL]->add_child(import_dock);
  4146. dock_slot[DOCK_SLOT_RIGHT_UL]->set_tab_title(import_dock->get_index(), TTR("Import"));
  4147. bool use_single_dock_column = (OS::get_singleton()->get_screen_size(OS::get_singleton()->get_current_screen()).x < 1200);
  4148. node_dock = memnew(NodeDock);
  4149. if (use_single_dock_column) {
  4150. dock_slot[DOCK_SLOT_RIGHT_UL]->add_child(node_dock);
  4151. dock_slot[DOCK_SLOT_RIGHT_UL]->set_tab_title(node_dock->get_index(), TTR("Node"));
  4152. } else {
  4153. dock_slot[DOCK_SLOT_RIGHT_BL]->add_child(node_dock);
  4154. dock_slot[DOCK_SLOT_RIGHT_BL]->set_tab_title(node_dock->get_index(), TTR("Node"));
  4155. }
  4156. filesystem_dock = memnew(FileSystemDock(this));
  4157. filesystem_dock->set_display_mode(int(EditorSettings::get_singleton()->get("docks/filesystem/display_mode")));
  4158. if (use_single_dock_column) {
  4159. dock_slot[DOCK_SLOT_RIGHT_BL]->add_child(filesystem_dock);
  4160. dock_slot[DOCK_SLOT_RIGHT_BL]->set_tab_title(filesystem_dock->get_index(), TTR("FileSystem"));
  4161. left_r_vsplit->hide();
  4162. dock_slot[DOCK_SLOT_LEFT_UR]->hide();
  4163. dock_slot[DOCK_SLOT_LEFT_BR]->hide();
  4164. } else {
  4165. dock_slot[DOCK_SLOT_LEFT_UR]->add_child(filesystem_dock);
  4166. dock_slot[DOCK_SLOT_LEFT_UR]->set_tab_title(filesystem_dock->get_index(), TTR("FileSystem"));
  4167. }
  4168. filesystem_dock->connect("open", this, "open_request");
  4169. filesystem_dock->connect("instance", this, "_instance_request");
  4170. const String docks_section = "docks";
  4171. overridden_default_layout = -1;
  4172. default_layout.instance();
  4173. default_layout->set_value(docks_section, "dock_3", "FileSystem");
  4174. default_layout->set_value(docks_section, "dock_5", "Scene,Import");
  4175. default_layout->set_value(docks_section, "dock_6", "Inspector,Node");
  4176. for (int i = 0; i < DOCK_SLOT_MAX / 2; i++)
  4177. default_layout->set_value(docks_section, "dock_hsplit_" + itos(i + 1), 0);
  4178. for (int i = 0; i < DOCK_SLOT_MAX / 2; i++)
  4179. default_layout->set_value(docks_section, "dock_split_" + itos(i + 1), 0);
  4180. _update_layouts_menu();
  4181. bottom_panel = memnew(PanelContainer);
  4182. bottom_panel->add_style_override("panel", gui_base->get_stylebox("panel", "TabContainer"));
  4183. center_split->add_child(bottom_panel);
  4184. center_split->set_dragger_visibility(SplitContainer::DRAGGER_HIDDEN);
  4185. bottom_panel_vb = memnew(VBoxContainer);
  4186. bottom_panel->add_child(bottom_panel_vb);
  4187. bottom_panel_hb = memnew(HBoxContainer);
  4188. bottom_panel_vb->add_child(bottom_panel_hb);
  4189. bottom_panel_hb_editors = memnew(HBoxContainer);
  4190. bottom_panel_hb_editors->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  4191. bottom_panel_hb->add_child(bottom_panel_hb_editors);
  4192. bottom_panel_raise = memnew(ToolButton);
  4193. bottom_panel_raise->set_icon(gui_base->get_icon("ExpandBottomDock", "EditorIcons"));
  4194. bottom_panel_raise->set_shortcut(ED_SHORTCUT("editor/bottom_panel_expand", TTR("Expand Bottom Panel"), KEY_MASK_SHIFT | KEY_F12));
  4195. bottom_panel_hb->add_child(bottom_panel_raise);
  4196. bottom_panel_raise->hide();
  4197. bottom_panel_raise->set_toggle_mode(true);
  4198. bottom_panel_raise->connect("toggled", this, "_bottom_panel_raise_toggled");
  4199. log = memnew(EditorLog);
  4200. ToolButton *output_button = add_bottom_panel_item(TTR("Output"), log);
  4201. log->set_tool_button(output_button);
  4202. old_split_ofs = 0;
  4203. center_split->connect("resized", this, "_vp_resized");
  4204. orphan_resources = memnew(OrphanResourcesDialog);
  4205. gui_base->add_child(orphan_resources);
  4206. confirmation = memnew(ConfirmationDialog);
  4207. gui_base->add_child(confirmation);
  4208. confirmation->connect("confirmed", this, "_menu_confirm_current");
  4209. save_confirmation = memnew(ConfirmationDialog);
  4210. save_confirmation->add_button(TTR("Don't Save"), OS::get_singleton()->get_swap_ok_cancel(), "discard");
  4211. gui_base->add_child(save_confirmation);
  4212. save_confirmation->connect("confirmed", this, "_menu_confirm_current");
  4213. save_confirmation->connect("custom_action", this, "_discard_changes");
  4214. file_templates = memnew(EditorFileDialog);
  4215. file_templates->set_title(TTR("Import Templates From ZIP File"));
  4216. gui_base->add_child(file_templates);
  4217. file_templates->set_mode(EditorFileDialog::MODE_OPEN_FILE);
  4218. file_templates->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
  4219. file_templates->clear_filters();
  4220. file_templates->add_filter("*.tpz ; Template Package");
  4221. file = memnew(EditorFileDialog);
  4222. gui_base->add_child(file);
  4223. file->set_current_dir("res://");
  4224. file_export = memnew(EditorFileDialog);
  4225. file_export->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
  4226. gui_base->add_child(file_export);
  4227. file_export->set_title(TTR("Export Project"));
  4228. file_export->connect("file_selected", this, "_dialog_action");
  4229. file_export_lib = memnew(EditorFileDialog);
  4230. file_export_lib->set_title(TTR("Export Library"));
  4231. file_export_lib->set_mode(EditorFileDialog::MODE_SAVE_FILE);
  4232. file_export_lib->connect("file_selected", this, "_dialog_action");
  4233. file_export_lib_merge = memnew(CheckButton);
  4234. file_export_lib_merge->set_text(TTR("Merge With Existing"));
  4235. file_export_lib_merge->set_pressed(true);
  4236. file_export_lib->get_vbox()->add_child(file_export_lib_merge);
  4237. gui_base->add_child(file_export_lib);
  4238. file_export_password = memnew(LineEdit);
  4239. file_export_password->set_secret(true);
  4240. file_export_password->set_editable(false);
  4241. file_export->get_vbox()->add_margin_child(TTR("Password:"), file_export_password);
  4242. file_script = memnew(EditorFileDialog);
  4243. file_script->set_title(TTR("Open & Run a Script"));
  4244. file_script->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
  4245. file_script->set_mode(EditorFileDialog::MODE_OPEN_FILE);
  4246. List<String> sexts;
  4247. ResourceLoader::get_recognized_extensions_for_type("Script", &sexts);
  4248. for (List<String>::Element *E = sexts.front(); E; E = E->next()) {
  4249. file_script->add_filter("*." + E->get());
  4250. }
  4251. gui_base->add_child(file_script);
  4252. file_script->connect("file_selected", this, "_dialog_action");
  4253. file_menu->get_popup()->connect("id_pressed", this, "_menu_option");
  4254. settings_menu->get_popup()->connect("id_pressed", this, "_menu_option");
  4255. file->connect("file_selected", this, "_dialog_action");
  4256. file_templates->connect("file_selected", this, "_dialog_action");
  4257. preview_gen = memnew(AudioStreamPreviewGenerator);
  4258. add_child(preview_gen);
  4259. //plugin stuff
  4260. file_server = memnew(EditorFileServer);
  4261. add_editor_plugin(memnew(AnimationPlayerEditorPlugin(this)));
  4262. add_editor_plugin(memnew(CanvasItemEditorPlugin(this)));
  4263. add_editor_plugin(memnew(SpatialEditorPlugin(this)));
  4264. add_editor_plugin(memnew(ScriptEditorPlugin(this)));
  4265. EditorAudioBuses *audio_bus_editor = EditorAudioBuses::register_editor();
  4266. ScriptTextEditor::register_editor(); //register one for text scripts
  4267. if (StreamPeerSSL::is_available()) {
  4268. add_editor_plugin(memnew(AssetLibraryEditorPlugin(this)));
  4269. } else {
  4270. WARN_PRINT("Asset Library not available, as it requires SSL to work.");
  4271. }
  4272. //add interface before adding plugins
  4273. editor_interface = memnew(EditorInterface);
  4274. add_child(editor_interface);
  4275. //more visually meaningful to have this later
  4276. raise_bottom_panel_item(AnimationPlayerEditor::singleton);
  4277. add_editor_plugin(memnew(ShaderEditorPlugin(this)));
  4278. add_editor_plugin(memnew(VisualShaderEditorPlugin(this)));
  4279. add_editor_plugin(memnew(AnimationNodeBlendTreeEditorPlugin(this)));
  4280. add_editor_plugin(memnew(AnimationNodeBlendSpace1DEditorPlugin(this)));
  4281. add_editor_plugin(memnew(AnimationNodeBlendSpace2DEditorPlugin(this)));
  4282. add_editor_plugin(memnew(AnimationNodeStateMachineEditorPlugin(this)));
  4283. add_editor_plugin(memnew(CameraEditorPlugin(this)));
  4284. add_editor_plugin(memnew(ThemeEditorPlugin(this)));
  4285. add_editor_plugin(memnew(MultiMeshEditorPlugin(this)));
  4286. add_editor_plugin(memnew(MeshInstanceEditorPlugin(this)));
  4287. add_editor_plugin(memnew(AnimationTreeEditorPlugin(this)));
  4288. add_editor_plugin(memnew(MeshLibraryEditorPlugin(this)));
  4289. add_editor_plugin(memnew(StyleBoxEditorPlugin(this)));
  4290. add_editor_plugin(memnew(SpriteEditorPlugin(this)));
  4291. add_editor_plugin(memnew(Skeleton2DEditorPlugin(this)));
  4292. add_editor_plugin(memnew(ParticlesEditorPlugin(this)));
  4293. add_editor_plugin(memnew(CPUParticlesEditorPlugin(this)));
  4294. add_editor_plugin(memnew(ResourcePreloaderEditorPlugin(this)));
  4295. add_editor_plugin(memnew(ItemListEditorPlugin(this)));
  4296. add_editor_plugin(memnew(Polygon3DEditorPlugin(this)));
  4297. add_editor_plugin(memnew(CollisionPolygon2DEditorPlugin(this)));
  4298. add_editor_plugin(memnew(TileSetEditorPlugin(this)));
  4299. add_editor_plugin(memnew(TileMapEditorPlugin(this)));
  4300. add_editor_plugin(memnew(SpriteFramesEditorPlugin(this)));
  4301. add_editor_plugin(memnew(TextureRegionEditorPlugin(this)));
  4302. add_editor_plugin(memnew(Particles2DEditorPlugin(this)));
  4303. add_editor_plugin(memnew(GIProbeEditorPlugin(this)));
  4304. add_editor_plugin(memnew(BakedLightmapEditorPlugin(this)));
  4305. add_editor_plugin(memnew(Path2DEditorPlugin(this)));
  4306. add_editor_plugin(memnew(PathEditorPlugin(this)));
  4307. add_editor_plugin(memnew(Line2DEditorPlugin(this)));
  4308. add_editor_plugin(memnew(Polygon2DEditorPlugin(this)));
  4309. add_editor_plugin(memnew(LightOccluder2DEditorPlugin(this)));
  4310. add_editor_plugin(memnew(NavigationPolygonEditorPlugin(this)));
  4311. add_editor_plugin(memnew(GradientEditorPlugin(this)));
  4312. add_editor_plugin(memnew(CollisionShape2DEditorPlugin(this)));
  4313. add_editor_plugin(memnew(CurveEditorPlugin(this)));
  4314. add_editor_plugin(memnew(TextureEditorPlugin(this)));
  4315. add_editor_plugin(memnew(AudioStreamEditorPlugin(this)));
  4316. add_editor_plugin(memnew(AudioBusesEditorPlugin(audio_bus_editor)));
  4317. add_editor_plugin(memnew(AudioBusesEditorPlugin(audio_bus_editor)));
  4318. add_editor_plugin(memnew(SkeletonEditorPlugin(this)));
  4319. add_editor_plugin(memnew(PhysicalBonePlugin(this)));
  4320. // FIXME: Disabled as (according to reduz) users were complaining that it gets in the way
  4321. // Waiting for PropertyEditor rewrite (planned for 3.1) to be refactored.
  4322. //add_editor_plugin(memnew(MaterialEditorPlugin(this)));
  4323. for (int i = 0; i < EditorPlugins::get_plugin_count(); i++)
  4324. add_editor_plugin(EditorPlugins::create(i, this));
  4325. for (int i = 0; i < plugin_init_callback_count; i++) {
  4326. plugin_init_callbacks[i]();
  4327. }
  4328. resource_preview->add_preview_generator(Ref<EditorTexturePreviewPlugin>(memnew(EditorTexturePreviewPlugin)));
  4329. resource_preview->add_preview_generator(Ref<EditorPackedScenePreviewPlugin>(memnew(EditorPackedScenePreviewPlugin)));
  4330. resource_preview->add_preview_generator(Ref<EditorMaterialPreviewPlugin>(memnew(EditorMaterialPreviewPlugin)));
  4331. resource_preview->add_preview_generator(Ref<EditorScriptPreviewPlugin>(memnew(EditorScriptPreviewPlugin)));
  4332. resource_preview->add_preview_generator(Ref<EditorAudioStreamPreviewPlugin>(memnew(EditorAudioStreamPreviewPlugin)));
  4333. resource_preview->add_preview_generator(Ref<EditorMeshPreviewPlugin>(memnew(EditorMeshPreviewPlugin)));
  4334. resource_preview->add_preview_generator(Ref<EditorBitmapPreviewPlugin>(memnew(EditorBitmapPreviewPlugin)));
  4335. resource_preview->add_preview_generator(Ref<EditorFontPreviewPlugin>(memnew(EditorFontPreviewPlugin)));
  4336. {
  4337. Ref<SpatialMaterialConversionPlugin> spatial_mat_convert;
  4338. spatial_mat_convert.instance();
  4339. resource_conversion_plugins.push_back(spatial_mat_convert);
  4340. Ref<CanvasItemMaterialConversionPlugin> canvas_item_mat_convert;
  4341. canvas_item_mat_convert.instance();
  4342. resource_conversion_plugins.push_back(canvas_item_mat_convert);
  4343. Ref<ParticlesMaterialConversionPlugin> particles_mat_convert;
  4344. particles_mat_convert.instance();
  4345. resource_conversion_plugins.push_back(particles_mat_convert);
  4346. }
  4347. circle_step_msec = OS::get_singleton()->get_ticks_msec();
  4348. circle_step_frame = Engine::get_singleton()->get_frames_drawn();
  4349. circle_step = 0;
  4350. editor_plugin_screen = NULL;
  4351. editor_plugins_over = memnew(EditorPluginList);
  4352. editor_plugins_force_over = memnew(EditorPluginList);
  4353. editor_plugins_force_input_forwarding = memnew(EditorPluginList);
  4354. Ref<EditorExportTextSceneToBinaryPlugin> export_text_to_binary_plugin;
  4355. export_text_to_binary_plugin.instance();
  4356. EditorExport::get_singleton()->add_export_plugin(export_text_to_binary_plugin);
  4357. _edit_current();
  4358. current = NULL;
  4359. PhysicsServer::get_singleton()->set_active(false); // no physics by default if editor
  4360. Physics2DServer::get_singleton()->set_active(false); // no physics by default if editor
  4361. ScriptServer::set_scripting_enabled(false); // no scripting by default if editor
  4362. reference_resource_mem = true;
  4363. save_external_resources_mem = true;
  4364. set_process(true);
  4365. open_imported = memnew(ConfirmationDialog);
  4366. open_imported->get_ok()->set_text(TTR("Open Anyway"));
  4367. new_inherited_button = open_imported->add_button(TTR("New Inherited"), !OS::get_singleton()->get_swap_ok_cancel(), "inherit");
  4368. open_imported->connect("confirmed", this, "_open_imported");
  4369. open_imported->connect("custom_action", this, "_inherit_imported");
  4370. gui_base->add_child(open_imported);
  4371. saved_version = 1;
  4372. unsaved_cache = true;
  4373. _last_instanced_scene = NULL;
  4374. quick_open = memnew(EditorQuickOpen);
  4375. gui_base->add_child(quick_open);
  4376. quick_open->connect("quick_open", this, "_quick_opened");
  4377. quick_run = memnew(EditorQuickOpen);
  4378. gui_base->add_child(quick_run);
  4379. quick_run->connect("quick_open", this, "_quick_run");
  4380. _update_recent_scenes();
  4381. editor_data.restore_editor_global_states();
  4382. convert_old = false;
  4383. opening_prev = false;
  4384. set_process_unhandled_input(true);
  4385. _playing_edited = false;
  4386. load_errors = memnew(RichTextLabel);
  4387. load_error_dialog = memnew(AcceptDialog);
  4388. load_error_dialog->add_child(load_errors);
  4389. load_error_dialog->set_title(TTR("Load Errors"));
  4390. gui_base->add_child(load_error_dialog);
  4391. EditorFileSystem::get_singleton()->connect("sources_changed", this, "_sources_changed");
  4392. EditorFileSystem::get_singleton()->connect("filesystem_changed", this, "_fs_changed");
  4393. EditorFileSystem::get_singleton()->connect("resources_reimported", this, "_resources_reimported");
  4394. _build_icon_type_cache();
  4395. Node::set_human_readable_collision_renaming(true);
  4396. pick_main_scene = memnew(ConfirmationDialog);
  4397. gui_base->add_child(pick_main_scene);
  4398. pick_main_scene->get_ok()->set_text(TTR("Select"));
  4399. pick_main_scene->connect("confirmed", this, "_menu_option", varray(SETTINGS_PICK_MAIN_SCENE));
  4400. for (int i = 0; i < _init_callbacks.size(); i++)
  4401. _init_callbacks[i]();
  4402. editor_data.add_edited_scene(-1);
  4403. editor_data.set_edited_scene(0);
  4404. _update_scene_tabs();
  4405. import_dock->initialize_import_options();
  4406. {
  4407. _initializing_addons = true;
  4408. Vector<String> addons;
  4409. if (ProjectSettings::get_singleton()->has_setting("editor_plugins/enabled")) {
  4410. addons = ProjectSettings::get_singleton()->get("editor_plugins/enabled");
  4411. }
  4412. for (int i = 0; i < addons.size(); i++) {
  4413. set_addon_plugin_enabled(addons[i], true);
  4414. }
  4415. _initializing_addons = false;
  4416. }
  4417. FileAccess::set_file_close_fail_notify_callback(_file_access_close_error_notify);
  4418. waiting_for_first_scan = true;
  4419. _dimming = false;
  4420. _dim_time = 0.0f;
  4421. _dim_timer = memnew(Timer);
  4422. _dim_timer->set_wait_time(0.01666f);
  4423. _dim_timer->connect("timeout", this, "_dim_timeout");
  4424. add_child(_dim_timer);
  4425. print_handler.printfunc = _print_handler;
  4426. print_handler.userdata = this;
  4427. add_print_handler(&print_handler);
  4428. #ifdef OSX_ENABLED
  4429. ED_SHORTCUT("editor/editor_2d", TTR("Open 2D Editor"), KEY_MASK_ALT | KEY_1);
  4430. ED_SHORTCUT("editor/editor_3d", TTR("Open 3D Editor"), KEY_MASK_ALT | KEY_2);
  4431. ED_SHORTCUT("editor/editor_script", TTR("Open Script Editor"), KEY_MASK_ALT | KEY_3);
  4432. ED_SHORTCUT("editor/editor_help", TTR("Search Help"), KEY_MASK_ALT | KEY_SPACE);
  4433. #else
  4434. ED_SHORTCUT("editor/editor_2d", TTR("Open 2D Editor"), KEY_F1);
  4435. ED_SHORTCUT("editor/editor_3d", TTR("Open 3D Editor"), KEY_F2);
  4436. ED_SHORTCUT("editor/editor_script", TTR("Open Script Editor"), KEY_F3); //hack neded for script editor F3 search to work :) Assign like this or don't use F3
  4437. ED_SHORTCUT("editor/editor_help", TTR("Search Help"), KEY_F4);
  4438. #endif
  4439. ED_SHORTCUT("editor/editor_assetlib", TTR("Open Asset Library"));
  4440. ED_SHORTCUT("editor/editor_next", TTR("Open the next Editor"));
  4441. ED_SHORTCUT("editor/editor_prev", TTR("Open the previous Editor"));
  4442. }
  4443. EditorNode::~EditorNode() {
  4444. EditorInspector::cleanup_plugins();
  4445. remove_print_handler(&print_handler);
  4446. memdelete(EditorHelp::get_doc_data());
  4447. memdelete(editor_selection);
  4448. memdelete(editor_plugins_over);
  4449. memdelete(editor_plugins_force_over);
  4450. memdelete(editor_plugins_force_input_forwarding);
  4451. memdelete(file_server);
  4452. memdelete(progress_hb);
  4453. EditorSettings::destroy();
  4454. }
  4455. /*
  4456. * EDITOR PLUGIN LIST
  4457. */
  4458. void EditorPluginList::make_visible(bool p_visible) {
  4459. for (int i = 0; i < plugins_list.size(); i++) {
  4460. plugins_list[i]->make_visible(p_visible);
  4461. }
  4462. }
  4463. void EditorPluginList::edit(Object *p_object) {
  4464. for (int i = 0; i < plugins_list.size(); i++) {
  4465. plugins_list[i]->edit(p_object);
  4466. }
  4467. }
  4468. bool EditorPluginList::forward_gui_input(const Ref<InputEvent> &p_event) {
  4469. bool discard = false;
  4470. for (int i = 0; i < plugins_list.size(); i++) {
  4471. if (plugins_list[i]->forward_canvas_gui_input(p_event)) {
  4472. discard = true;
  4473. }
  4474. }
  4475. return discard;
  4476. }
  4477. bool EditorPluginList::forward_spatial_gui_input(Camera *p_camera, const Ref<InputEvent> &p_event, bool serve_when_force_input_enabled) {
  4478. bool discard = false;
  4479. for (int i = 0; i < plugins_list.size(); i++) {
  4480. if ((!serve_when_force_input_enabled) && plugins_list[i]->is_input_event_forwarding_always_enabled()) {
  4481. continue;
  4482. }
  4483. if (plugins_list[i]->forward_spatial_gui_input(p_camera, p_event)) {
  4484. discard = true;
  4485. }
  4486. }
  4487. return discard;
  4488. }
  4489. void EditorPluginList::forward_draw_over_viewport(Control *p_overlay) {
  4490. for (int i = 0; i < plugins_list.size(); i++) {
  4491. plugins_list[i]->forward_draw_over_viewport(p_overlay);
  4492. }
  4493. }
  4494. void EditorPluginList::forward_force_draw_over_viewport(Control *p_overlay) {
  4495. for (int i = 0; i < plugins_list.size(); i++) {
  4496. plugins_list[i]->forward_force_draw_over_viewport(p_overlay);
  4497. }
  4498. }
  4499. void EditorPluginList::add_plugin(EditorPlugin *p_plugin) {
  4500. plugins_list.push_back(p_plugin);
  4501. }
  4502. bool EditorPluginList::empty() {
  4503. return plugins_list.empty();
  4504. }
  4505. void EditorPluginList::clear() {
  4506. plugins_list.clear();
  4507. }
  4508. EditorPluginList::EditorPluginList() {
  4509. }
  4510. EditorPluginList::~EditorPluginList() {
  4511. }