editor_node.cpp 201 KB

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