editor_node.cpp 180 KB

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