editor_node.cpp 176 KB

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