editor_node.cpp 182 KB

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