editor_node.cpp 172 KB

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