editor_node.cpp 187 KB

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