editor_node.cpp 192 KB

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