editor_node.cpp 195 KB

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