editor_node.cpp 181 KB

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