editor_node.cpp 188 KB

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