editor_node.cpp 197 KB

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