editor_properties.cpp 136 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532
  1. /*************************************************************************/
  2. /* editor_properties.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 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_properties.h"
  31. #include "core/config/project_settings.h"
  32. #include "editor/editor_file_dialog.h"
  33. #include "editor/editor_node.h"
  34. #include "editor/editor_properties_array_dict.h"
  35. #include "editor/editor_resource_preview.h"
  36. #include "editor/editor_scale.h"
  37. #include "editor/filesystem_dock.h"
  38. #include "scene/2d/gpu_particles_2d.h"
  39. #include "scene/3d/fog_volume.h"
  40. #include "scene/3d/gpu_particles_3d.h"
  41. #include "scene/main/window.h"
  42. #include "scene/resources/font.h"
  43. #include "scene/resources/mesh.h"
  44. #include "scene/resources/packed_scene.h"
  45. ///////////////////// Nil /////////////////////////
  46. void EditorPropertyNil::update_property() {
  47. }
  48. EditorPropertyNil::EditorPropertyNil() {
  49. Label *label = memnew(Label);
  50. label->set_text("[null]");
  51. add_child(label);
  52. }
  53. ///////////////////// TEXT /////////////////////////
  54. void EditorPropertyText::_set_read_only(bool p_read_only) {
  55. text->set_editable(!p_read_only);
  56. };
  57. void EditorPropertyText::_text_submitted(const String &p_string) {
  58. if (updating) {
  59. return;
  60. }
  61. if (text->has_focus()) {
  62. text->release_focus();
  63. _text_changed(p_string);
  64. }
  65. }
  66. void EditorPropertyText::_text_changed(const String &p_string) {
  67. if (updating) {
  68. return;
  69. }
  70. if (string_name) {
  71. emit_changed(get_edited_property(), StringName(p_string));
  72. } else {
  73. emit_changed(get_edited_property(), p_string);
  74. }
  75. }
  76. void EditorPropertyText::update_property() {
  77. String s = get_edited_object()->get(get_edited_property());
  78. updating = true;
  79. if (text->get_text() != s) {
  80. text->set_text(s);
  81. }
  82. text->set_editable(!is_read_only());
  83. updating = false;
  84. }
  85. void EditorPropertyText::set_string_name(bool p_enabled) {
  86. string_name = p_enabled;
  87. }
  88. void EditorPropertyText::set_placeholder(const String &p_string) {
  89. text->set_placeholder(p_string);
  90. }
  91. void EditorPropertyText::_bind_methods() {
  92. }
  93. EditorPropertyText::EditorPropertyText() {
  94. text = memnew(LineEdit);
  95. add_child(text);
  96. add_focusable(text);
  97. text->connect("text_changed", callable_mp(this, &EditorPropertyText::_text_changed));
  98. text->connect("text_submitted", callable_mp(this, &EditorPropertyText::_text_submitted));
  99. }
  100. ///////////////////// MULTILINE TEXT /////////////////////////
  101. void EditorPropertyMultilineText::_set_read_only(bool p_read_only) {
  102. text->set_editable(!p_read_only);
  103. open_big_text->set_disabled(p_read_only);
  104. };
  105. void EditorPropertyMultilineText::_big_text_changed() {
  106. text->set_text(big_text->get_text());
  107. emit_changed(get_edited_property(), big_text->get_text(), "", true);
  108. }
  109. void EditorPropertyMultilineText::_text_changed() {
  110. emit_changed(get_edited_property(), text->get_text(), "", true);
  111. }
  112. void EditorPropertyMultilineText::_open_big_text() {
  113. if (!big_text_dialog) {
  114. big_text = memnew(TextEdit);
  115. if (expression) {
  116. big_text->set_syntax_highlighter(text->get_syntax_highlighter());
  117. big_text->add_theme_font_override("font", get_theme_font(SNAME("expression"), SNAME("EditorFonts")));
  118. big_text->add_theme_font_size_override("font_size", get_theme_font_size(SNAME("expression_size"), SNAME("EditorFonts")));
  119. }
  120. big_text->connect("text_changed", callable_mp(this, &EditorPropertyMultilineText::_big_text_changed));
  121. big_text->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_BOUNDARY);
  122. big_text_dialog = memnew(AcceptDialog);
  123. big_text_dialog->add_child(big_text);
  124. big_text_dialog->set_title(TTR("Edit Text:"));
  125. add_child(big_text_dialog);
  126. }
  127. big_text_dialog->popup_centered_clamped(Size2(1000, 900) * EDSCALE, 0.8);
  128. big_text->set_text(text->get_text());
  129. big_text->grab_focus();
  130. }
  131. void EditorPropertyMultilineText::update_property() {
  132. String t = get_edited_object()->get(get_edited_property());
  133. if (text->get_text() != t) {
  134. text->set_text(t);
  135. if (big_text && big_text->is_visible_in_tree()) {
  136. big_text->set_text(t);
  137. }
  138. }
  139. }
  140. void EditorPropertyMultilineText::_notification(int p_what) {
  141. switch (p_what) {
  142. case NOTIFICATION_THEME_CHANGED:
  143. case NOTIFICATION_ENTER_TREE: {
  144. Ref<Texture2D> df = get_theme_icon(SNAME("DistractionFree"), SNAME("EditorIcons"));
  145. open_big_text->set_icon(df);
  146. Ref<Font> font;
  147. int font_size;
  148. if (expression) {
  149. font = get_theme_font(SNAME("expression"), SNAME("EditorFonts"));
  150. font_size = get_theme_font_size(SNAME("expression_size"), SNAME("EditorFonts"));
  151. text->add_theme_font_override("font", font);
  152. text->add_theme_font_size_override("font_size", font_size);
  153. if (big_text) {
  154. big_text->add_theme_font_override("font", font);
  155. big_text->add_theme_font_size_override("font_size", font_size);
  156. }
  157. } else {
  158. font = get_theme_font(SNAME("font"), SNAME("TextEdit"));
  159. font_size = get_theme_font_size(SNAME("font_size"), SNAME("TextEdit"));
  160. }
  161. text->set_custom_minimum_size(Vector2(0, font->get_height(font_size) * 6));
  162. } break;
  163. }
  164. }
  165. void EditorPropertyMultilineText::_bind_methods() {
  166. }
  167. EditorPropertyMultilineText::EditorPropertyMultilineText(bool p_expression) {
  168. HBoxContainer *hb = memnew(HBoxContainer);
  169. hb->add_theme_constant_override("separation", 0);
  170. add_child(hb);
  171. set_bottom_editor(hb);
  172. text = memnew(TextEdit);
  173. text->connect("text_changed", callable_mp(this, &EditorPropertyMultilineText::_text_changed));
  174. text->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_BOUNDARY);
  175. add_focusable(text);
  176. hb->add_child(text);
  177. text->set_h_size_flags(SIZE_EXPAND_FILL);
  178. open_big_text = memnew(Button);
  179. open_big_text->set_flat(true);
  180. open_big_text->connect("pressed", callable_mp(this, &EditorPropertyMultilineText::_open_big_text));
  181. hb->add_child(open_big_text);
  182. big_text_dialog = nullptr;
  183. big_text = nullptr;
  184. if (p_expression) {
  185. expression = true;
  186. Ref<EditorStandardSyntaxHighlighter> highlighter;
  187. highlighter.instantiate();
  188. text->set_syntax_highlighter(highlighter);
  189. }
  190. }
  191. ///////////////////// TEXT ENUM /////////////////////////
  192. void EditorPropertyTextEnum::_set_read_only(bool p_read_only) {
  193. option_button->set_disabled(p_read_only);
  194. edit_button->set_disabled(p_read_only);
  195. };
  196. void EditorPropertyTextEnum::_emit_changed_value(String p_string) {
  197. if (string_name) {
  198. emit_changed(get_edited_property(), StringName(p_string));
  199. } else {
  200. emit_changed(get_edited_property(), p_string);
  201. }
  202. }
  203. void EditorPropertyTextEnum::_option_selected(int p_which) {
  204. _emit_changed_value(option_button->get_item_text(p_which));
  205. }
  206. void EditorPropertyTextEnum::_edit_custom_value() {
  207. default_layout->hide();
  208. edit_custom_layout->show();
  209. custom_value_edit->grab_focus();
  210. }
  211. void EditorPropertyTextEnum::_custom_value_submitted(String p_value) {
  212. edit_custom_layout->hide();
  213. default_layout->show();
  214. _emit_changed_value(p_value.strip_edges());
  215. }
  216. void EditorPropertyTextEnum::_custom_value_accepted() {
  217. String new_value = custom_value_edit->get_text().strip_edges();
  218. _custom_value_submitted(new_value);
  219. }
  220. void EditorPropertyTextEnum::_custom_value_cancelled() {
  221. custom_value_edit->set_text(get_edited_object()->get(get_edited_property()));
  222. edit_custom_layout->hide();
  223. default_layout->show();
  224. }
  225. void EditorPropertyTextEnum::update_property() {
  226. String current_value = get_edited_object()->get(get_edited_property());
  227. int default_option = options.find(current_value);
  228. // The list can change in the loose mode.
  229. if (loose_mode) {
  230. custom_value_edit->set_text(current_value);
  231. option_button->clear();
  232. // Manually entered value.
  233. if (default_option < 0 && !current_value.is_empty()) {
  234. option_button->add_item(current_value, options.size() + 1001);
  235. option_button->select(0);
  236. option_button->add_separator();
  237. }
  238. // Add an explicit empty value for clearing the property.
  239. option_button->add_item("", options.size() + 1000);
  240. for (int i = 0; i < options.size(); i++) {
  241. option_button->add_item(options[i], i);
  242. if (options[i] == current_value) {
  243. option_button->select(option_button->get_item_count() - 1);
  244. }
  245. }
  246. } else {
  247. option_button->select(default_option);
  248. }
  249. }
  250. void EditorPropertyTextEnum::setup(const Vector<String> &p_options, bool p_string_name, bool p_loose_mode) {
  251. string_name = p_string_name;
  252. loose_mode = p_loose_mode;
  253. options.clear();
  254. if (loose_mode) {
  255. // Add an explicit empty value for clearing the property in the loose mode.
  256. option_button->add_item("", options.size() + 1000);
  257. }
  258. for (int i = 0; i < p_options.size(); i++) {
  259. options.append(p_options[i]);
  260. option_button->add_item(p_options[i], i);
  261. }
  262. if (loose_mode) {
  263. edit_button->show();
  264. }
  265. }
  266. void EditorPropertyTextEnum::_bind_methods() {
  267. }
  268. void EditorPropertyTextEnum::_notification(int p_what) {
  269. switch (p_what) {
  270. case NOTIFICATION_ENTER_TREE:
  271. case NOTIFICATION_THEME_CHANGED: {
  272. edit_button->set_icon(get_theme_icon(SNAME("Edit"), SNAME("EditorIcons")));
  273. accept_button->set_icon(get_theme_icon(SNAME("ImportCheck"), SNAME("EditorIcons")));
  274. cancel_button->set_icon(get_theme_icon(SNAME("ImportFail"), SNAME("EditorIcons")));
  275. } break;
  276. }
  277. }
  278. EditorPropertyTextEnum::EditorPropertyTextEnum() {
  279. default_layout = memnew(HBoxContainer);
  280. add_child(default_layout);
  281. edit_custom_layout = memnew(HBoxContainer);
  282. edit_custom_layout->hide();
  283. add_child(edit_custom_layout);
  284. option_button = memnew(OptionButton);
  285. option_button->set_h_size_flags(SIZE_EXPAND_FILL);
  286. option_button->set_clip_text(true);
  287. option_button->set_flat(true);
  288. default_layout->add_child(option_button);
  289. option_button->connect("item_selected", callable_mp(this, &EditorPropertyTextEnum::_option_selected));
  290. edit_button = memnew(Button);
  291. edit_button->set_flat(true);
  292. edit_button->hide();
  293. default_layout->add_child(edit_button);
  294. edit_button->connect("pressed", callable_mp(this, &EditorPropertyTextEnum::_edit_custom_value));
  295. custom_value_edit = memnew(LineEdit);
  296. custom_value_edit->set_h_size_flags(SIZE_EXPAND_FILL);
  297. edit_custom_layout->add_child(custom_value_edit);
  298. custom_value_edit->connect("text_submitted", callable_mp(this, &EditorPropertyTextEnum::_custom_value_submitted));
  299. accept_button = memnew(Button);
  300. accept_button->set_flat(true);
  301. edit_custom_layout->add_child(accept_button);
  302. accept_button->connect("pressed", callable_mp(this, &EditorPropertyTextEnum::_custom_value_accepted));
  303. cancel_button = memnew(Button);
  304. cancel_button->set_flat(true);
  305. edit_custom_layout->add_child(cancel_button);
  306. cancel_button->connect("pressed", callable_mp(this, &EditorPropertyTextEnum::_custom_value_cancelled));
  307. add_focusable(option_button);
  308. add_focusable(edit_button);
  309. add_focusable(custom_value_edit);
  310. add_focusable(accept_button);
  311. add_focusable(cancel_button);
  312. }
  313. //////////////////// LOCALE ////////////////////////
  314. void EditorPropertyLocale::_locale_selected(const String &p_locale) {
  315. emit_changed(get_edited_property(), p_locale);
  316. update_property();
  317. }
  318. void EditorPropertyLocale::_locale_pressed() {
  319. if (!dialog) {
  320. dialog = memnew(EditorLocaleDialog);
  321. dialog->connect("locale_selected", callable_mp(this, &EditorPropertyLocale::_locale_selected));
  322. add_child(dialog);
  323. }
  324. String locale_code = get_edited_object()->get(get_edited_property());
  325. dialog->set_locale(locale_code);
  326. dialog->popup_locale_dialog();
  327. }
  328. void EditorPropertyLocale::update_property() {
  329. String locale_code = get_edited_object()->get(get_edited_property());
  330. locale->set_text(locale_code);
  331. locale->set_tooltip(locale_code);
  332. }
  333. void EditorPropertyLocale::setup(const String &p_hint_text) {
  334. }
  335. void EditorPropertyLocale::_notification(int p_what) {
  336. switch (p_what) {
  337. case NOTIFICATION_ENTER_TREE:
  338. case NOTIFICATION_THEME_CHANGED: {
  339. locale_edit->set_icon(get_theme_icon(SNAME("Translation"), SNAME("EditorIcons")));
  340. } break;
  341. }
  342. }
  343. void EditorPropertyLocale::_locale_focus_exited() {
  344. _locale_selected(locale->get_text());
  345. }
  346. void EditorPropertyLocale::_bind_methods() {
  347. }
  348. EditorPropertyLocale::EditorPropertyLocale() {
  349. HBoxContainer *locale_hb = memnew(HBoxContainer);
  350. add_child(locale_hb);
  351. locale = memnew(LineEdit);
  352. locale_hb->add_child(locale);
  353. locale->connect("text_submitted", callable_mp(this, &EditorPropertyLocale::_locale_selected));
  354. locale->connect("focus_exited", callable_mp(this, &EditorPropertyLocale::_locale_focus_exited));
  355. locale->set_h_size_flags(SIZE_EXPAND_FILL);
  356. locale_edit = memnew(Button);
  357. locale_edit->set_clip_text(true);
  358. locale_hb->add_child(locale_edit);
  359. add_focusable(locale);
  360. dialog = nullptr;
  361. locale_edit->connect("pressed", callable_mp(this, &EditorPropertyLocale::_locale_pressed));
  362. }
  363. ///////////////////// PATH /////////////////////////
  364. void EditorPropertyPath::_set_read_only(bool p_read_only) {
  365. path->set_editable(!p_read_only);
  366. path_edit->set_disabled(p_read_only);
  367. };
  368. void EditorPropertyPath::_path_selected(const String &p_path) {
  369. emit_changed(get_edited_property(), p_path);
  370. update_property();
  371. }
  372. void EditorPropertyPath::_path_pressed() {
  373. if (!dialog) {
  374. dialog = memnew(EditorFileDialog);
  375. dialog->connect("file_selected", callable_mp(this, &EditorPropertyPath::_path_selected));
  376. dialog->connect("dir_selected", callable_mp(this, &EditorPropertyPath::_path_selected));
  377. add_child(dialog);
  378. }
  379. String full_path = get_edited_object()->get(get_edited_property());
  380. dialog->clear_filters();
  381. if (global) {
  382. dialog->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
  383. } else {
  384. dialog->set_access(EditorFileDialog::ACCESS_RESOURCES);
  385. }
  386. if (folder) {
  387. dialog->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_DIR);
  388. dialog->set_current_dir(full_path);
  389. } else {
  390. dialog->set_file_mode(save_mode ? EditorFileDialog::FILE_MODE_SAVE_FILE : EditorFileDialog::FILE_MODE_OPEN_FILE);
  391. for (int i = 0; i < extensions.size(); i++) {
  392. String e = extensions[i].strip_edges();
  393. if (!e.is_empty()) {
  394. dialog->add_filter(extensions[i].strip_edges());
  395. }
  396. }
  397. dialog->set_current_path(full_path);
  398. }
  399. dialog->popup_file_dialog();
  400. }
  401. void EditorPropertyPath::update_property() {
  402. String full_path = get_edited_object()->get(get_edited_property());
  403. path->set_text(full_path);
  404. path->set_tooltip(full_path);
  405. }
  406. void EditorPropertyPath::setup(const Vector<String> &p_extensions, bool p_folder, bool p_global) {
  407. extensions = p_extensions;
  408. folder = p_folder;
  409. global = p_global;
  410. }
  411. void EditorPropertyPath::set_save_mode() {
  412. save_mode = true;
  413. }
  414. void EditorPropertyPath::_notification(int p_what) {
  415. switch (p_what) {
  416. case NOTIFICATION_ENTER_TREE:
  417. case NOTIFICATION_THEME_CHANGED: {
  418. path_edit->set_icon(get_theme_icon(SNAME("Folder"), SNAME("EditorIcons")));
  419. } break;
  420. }
  421. }
  422. void EditorPropertyPath::_path_focus_exited() {
  423. _path_selected(path->get_text());
  424. }
  425. void EditorPropertyPath::_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
  426. const Dictionary drag_data = p_data;
  427. if (!drag_data.has("type")) {
  428. return;
  429. }
  430. if (String(drag_data["type"]) != "files") {
  431. return;
  432. }
  433. const Vector<String> filesPaths = drag_data["files"];
  434. if (filesPaths.size() == 0) {
  435. return;
  436. }
  437. emit_changed(get_edited_property(), filesPaths[0]);
  438. update_property();
  439. }
  440. bool EditorPropertyPath::_can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
  441. const Dictionary drag_data = p_data;
  442. if (!drag_data.has("type")) {
  443. return false;
  444. }
  445. if (String(drag_data["type"]) != "files") {
  446. return false;
  447. }
  448. const Vector<String> filesPaths = drag_data["files"];
  449. if (filesPaths.size() == 0) {
  450. return false;
  451. }
  452. for (const String &extension : extensions) {
  453. if (filesPaths[0].ends_with(extension.substr(1, extension.size() - 1))) {
  454. return true;
  455. }
  456. }
  457. return false;
  458. }
  459. void EditorPropertyPath::_bind_methods() {
  460. ClassDB::bind_method(D_METHOD("_can_drop_data_fw", "position", "data", "from"), &EditorPropertyPath::_can_drop_data_fw);
  461. ClassDB::bind_method(D_METHOD("_drop_data_fw", "position", "data", "from"), &EditorPropertyPath::_drop_data_fw);
  462. }
  463. EditorPropertyPath::EditorPropertyPath() {
  464. HBoxContainer *path_hb = memnew(HBoxContainer);
  465. add_child(path_hb);
  466. path = memnew(LineEdit);
  467. path->set_drag_forwarding(this);
  468. path->set_structured_text_bidi_override(TextServer::STRUCTURED_TEXT_FILE);
  469. path_hb->add_child(path);
  470. path->connect("text_submitted", callable_mp(this, &EditorPropertyPath::_path_selected));
  471. path->connect("focus_exited", callable_mp(this, &EditorPropertyPath::_path_focus_exited));
  472. path->set_h_size_flags(SIZE_EXPAND_FILL);
  473. path_edit = memnew(Button);
  474. path_edit->set_clip_text(true);
  475. path_hb->add_child(path_edit);
  476. add_focusable(path);
  477. dialog = nullptr;
  478. path_edit->connect("pressed", callable_mp(this, &EditorPropertyPath::_path_pressed));
  479. }
  480. ///////////////////// CLASS NAME /////////////////////////
  481. void EditorPropertyClassName::_set_read_only(bool p_read_only) {
  482. property->set_disabled(p_read_only);
  483. };
  484. void EditorPropertyClassName::setup(const String &p_base_type, const String &p_selected_type) {
  485. base_type = p_base_type;
  486. dialog->set_base_type(base_type);
  487. selected_type = p_selected_type;
  488. property->set_text(selected_type);
  489. }
  490. void EditorPropertyClassName::update_property() {
  491. String s = get_edited_object()->get(get_edited_property());
  492. property->set_text(s);
  493. selected_type = s;
  494. }
  495. void EditorPropertyClassName::_property_selected() {
  496. dialog->popup_create(true);
  497. }
  498. void EditorPropertyClassName::_dialog_created() {
  499. selected_type = dialog->get_selected_type();
  500. emit_changed(get_edited_property(), selected_type);
  501. update_property();
  502. }
  503. void EditorPropertyClassName::_bind_methods() {
  504. }
  505. EditorPropertyClassName::EditorPropertyClassName() {
  506. property = memnew(Button);
  507. property->set_clip_text(true);
  508. add_child(property);
  509. add_focusable(property);
  510. property->set_text(selected_type);
  511. property->connect("pressed", callable_mp(this, &EditorPropertyClassName::_property_selected));
  512. dialog = memnew(CreateDialog);
  513. dialog->set_base_type(base_type);
  514. dialog->connect("create", callable_mp(this, &EditorPropertyClassName::_dialog_created));
  515. add_child(dialog);
  516. }
  517. ///////////////////// MEMBER /////////////////////////
  518. void EditorPropertyMember::_set_read_only(bool p_read_only) {
  519. property->set_disabled(p_read_only);
  520. };
  521. void EditorPropertyMember::_property_selected(const String &p_selected) {
  522. emit_changed(get_edited_property(), p_selected);
  523. update_property();
  524. }
  525. void EditorPropertyMember::_property_select() {
  526. if (!selector) {
  527. selector = memnew(PropertySelector);
  528. selector->connect("selected", callable_mp(this, &EditorPropertyMember::_property_selected));
  529. add_child(selector);
  530. }
  531. String current = get_edited_object()->get(get_edited_property());
  532. if (hint == MEMBER_METHOD_OF_VARIANT_TYPE) {
  533. Variant::Type type = Variant::NIL;
  534. for (int i = 0; i < Variant::VARIANT_MAX; i++) {
  535. if (hint_text == Variant::get_type_name(Variant::Type(i))) {
  536. type = Variant::Type(i);
  537. }
  538. }
  539. if (type != Variant::NIL) {
  540. selector->select_method_from_basic_type(type, current);
  541. }
  542. } else if (hint == MEMBER_METHOD_OF_BASE_TYPE) {
  543. selector->select_method_from_base_type(hint_text, current);
  544. } else if (hint == MEMBER_METHOD_OF_INSTANCE) {
  545. Object *instance = ObjectDB::get_instance(ObjectID(hint_text.to_int()));
  546. if (instance) {
  547. selector->select_method_from_instance(instance, current);
  548. }
  549. } else if (hint == MEMBER_METHOD_OF_SCRIPT) {
  550. Object *obj = ObjectDB::get_instance(ObjectID(hint_text.to_int()));
  551. if (Object::cast_to<Script>(obj)) {
  552. selector->select_method_from_script(Object::cast_to<Script>(obj), current);
  553. }
  554. } else if (hint == MEMBER_PROPERTY_OF_VARIANT_TYPE) {
  555. Variant::Type type = Variant::NIL;
  556. String tname = hint_text;
  557. if (tname.contains(".")) {
  558. tname = tname.get_slice(".", 0);
  559. }
  560. for (int i = 0; i < Variant::VARIANT_MAX; i++) {
  561. if (tname == Variant::get_type_name(Variant::Type(i))) {
  562. type = Variant::Type(Variant::Type(i));
  563. }
  564. }
  565. if (type != Variant::NIL) {
  566. selector->select_property_from_basic_type(type, current);
  567. }
  568. } else if (hint == MEMBER_PROPERTY_OF_BASE_TYPE) {
  569. selector->select_property_from_base_type(hint_text, current);
  570. } else if (hint == MEMBER_PROPERTY_OF_INSTANCE) {
  571. Object *instance = ObjectDB::get_instance(ObjectID(hint_text.to_int()));
  572. if (instance) {
  573. selector->select_property_from_instance(instance, current);
  574. }
  575. } else if (hint == MEMBER_PROPERTY_OF_SCRIPT) {
  576. Object *obj = ObjectDB::get_instance(ObjectID(hint_text.to_int()));
  577. if (Object::cast_to<Script>(obj)) {
  578. selector->select_property_from_script(Object::cast_to<Script>(obj), current);
  579. }
  580. }
  581. }
  582. void EditorPropertyMember::setup(Type p_hint, const String &p_hint_text) {
  583. hint = p_hint;
  584. hint_text = p_hint_text;
  585. }
  586. void EditorPropertyMember::update_property() {
  587. String full_path = get_edited_object()->get(get_edited_property());
  588. property->set_text(full_path);
  589. }
  590. void EditorPropertyMember::_bind_methods() {
  591. }
  592. EditorPropertyMember::EditorPropertyMember() {
  593. selector = nullptr;
  594. property = memnew(Button);
  595. property->set_clip_text(true);
  596. add_child(property);
  597. add_focusable(property);
  598. property->connect("pressed", callable_mp(this, &EditorPropertyMember::_property_select));
  599. }
  600. ///////////////////// CHECK /////////////////////////
  601. void EditorPropertyCheck::_set_read_only(bool p_read_only) {
  602. checkbox->set_disabled(p_read_only);
  603. };
  604. void EditorPropertyCheck::_checkbox_pressed() {
  605. emit_changed(get_edited_property(), checkbox->is_pressed());
  606. }
  607. void EditorPropertyCheck::update_property() {
  608. bool c = get_edited_object()->get(get_edited_property());
  609. checkbox->set_pressed(c);
  610. checkbox->set_disabled(is_read_only());
  611. }
  612. void EditorPropertyCheck::_bind_methods() {
  613. }
  614. EditorPropertyCheck::EditorPropertyCheck() {
  615. checkbox = memnew(CheckBox);
  616. checkbox->set_text(TTR("On"));
  617. add_child(checkbox);
  618. add_focusable(checkbox);
  619. checkbox->connect("pressed", callable_mp(this, &EditorPropertyCheck::_checkbox_pressed));
  620. }
  621. ///////////////////// ENUM /////////////////////////
  622. void EditorPropertyEnum::_set_read_only(bool p_read_only) {
  623. options->set_disabled(p_read_only);
  624. };
  625. void EditorPropertyEnum::_option_selected(int p_which) {
  626. int64_t val = options->get_item_metadata(p_which);
  627. emit_changed(get_edited_property(), val);
  628. }
  629. void EditorPropertyEnum::update_property() {
  630. int64_t which = get_edited_object()->get(get_edited_property());
  631. for (int i = 0; i < options->get_item_count(); i++) {
  632. if (which == (int64_t)options->get_item_metadata(i)) {
  633. options->select(i);
  634. return;
  635. }
  636. }
  637. }
  638. void EditorPropertyEnum::setup(const Vector<String> &p_options) {
  639. options->clear();
  640. int64_t current_val = 0;
  641. for (int i = 0; i < p_options.size(); i++) {
  642. Vector<String> text_split = p_options[i].split(":");
  643. if (text_split.size() != 1) {
  644. current_val = text_split[1].to_int();
  645. }
  646. options->add_item(text_split[0]);
  647. options->set_item_metadata(i, current_val);
  648. current_val += 1;
  649. }
  650. }
  651. void EditorPropertyEnum::set_option_button_clip(bool p_enable) {
  652. options->set_clip_text(p_enable);
  653. }
  654. void EditorPropertyEnum::_bind_methods() {
  655. }
  656. EditorPropertyEnum::EditorPropertyEnum() {
  657. options = memnew(OptionButton);
  658. options->set_clip_text(true);
  659. options->set_flat(true);
  660. add_child(options);
  661. add_focusable(options);
  662. options->connect("item_selected", callable_mp(this, &EditorPropertyEnum::_option_selected));
  663. }
  664. ///////////////////// FLAGS /////////////////////////
  665. void EditorPropertyFlags::_set_read_only(bool p_read_only) {
  666. for (CheckBox *check : flags) {
  667. check->set_disabled(p_read_only);
  668. }
  669. };
  670. void EditorPropertyFlags::_flag_toggled(int p_index) {
  671. uint32_t value = get_edited_object()->get(get_edited_property());
  672. if (flags[p_index]->is_pressed()) {
  673. value |= flag_values[p_index];
  674. } else {
  675. value &= ~flag_values[p_index];
  676. }
  677. emit_changed(get_edited_property(), value);
  678. }
  679. void EditorPropertyFlags::update_property() {
  680. uint32_t value = get_edited_object()->get(get_edited_property());
  681. for (int i = 0; i < flags.size(); i++) {
  682. flags[i]->set_pressed((value & flag_values[i]) == flag_values[i]);
  683. }
  684. }
  685. void EditorPropertyFlags::setup(const Vector<String> &p_options) {
  686. ERR_FAIL_COND(flags.size());
  687. bool first = true;
  688. uint32_t current_val;
  689. for (int i = 0; i < p_options.size(); i++) {
  690. String option = p_options[i].strip_edges();
  691. if (!option.is_empty()) {
  692. CheckBox *cb = memnew(CheckBox);
  693. cb->set_text(option);
  694. cb->set_clip_text(true);
  695. cb->connect("pressed", callable_mp(this, &EditorPropertyFlags::_flag_toggled).bind(i));
  696. add_focusable(cb);
  697. vbox->add_child(cb);
  698. flags.push_back(cb);
  699. Vector<String> text_split = p_options[i].split(":");
  700. if (text_split.size() != 1) {
  701. current_val = text_split[1].to_int();
  702. } else {
  703. current_val = 1 << i;
  704. }
  705. flag_values.push_back(current_val);
  706. if (first) {
  707. set_label_reference(cb);
  708. first = false;
  709. }
  710. }
  711. }
  712. }
  713. void EditorPropertyFlags::_bind_methods() {
  714. }
  715. EditorPropertyFlags::EditorPropertyFlags() {
  716. vbox = memnew(VBoxContainer);
  717. add_child(vbox);
  718. }
  719. ///////////////////// LAYERS /////////////////////////
  720. void EditorPropertyLayersGrid::_rename_pressed(int p_menu) {
  721. // Show rename popup for active layer.
  722. if (renamed_layer_index == -1) {
  723. return;
  724. }
  725. String name = names[renamed_layer_index];
  726. rename_dialog->set_title(vformat(TTR("Renaming layer %d:"), renamed_layer_index + 1));
  727. rename_dialog_text->set_text(name);
  728. rename_dialog_text->select(0, name.length());
  729. rename_dialog->popup_centered(Size2(300, 80) * EDSCALE);
  730. rename_dialog_text->grab_focus();
  731. }
  732. void EditorPropertyLayersGrid::_rename_operation_confirm() {
  733. String new_name = rename_dialog_text->get_text().strip_edges();
  734. if (new_name.length() == 0) {
  735. EditorNode::get_singleton()->show_warning(TTR("No name provided."));
  736. return;
  737. } else if (new_name.contains("/") || new_name.contains("\\") || new_name.contains(":")) {
  738. EditorNode::get_singleton()->show_warning(TTR("Name contains invalid characters."));
  739. return;
  740. }
  741. names.set(renamed_layer_index, new_name);
  742. tooltips.set(renamed_layer_index, new_name + "\n" + vformat(TTR("Bit %d, value %d"), renamed_layer_index, 1 << renamed_layer_index));
  743. emit_signal(SNAME("rename_confirmed"), renamed_layer_index, new_name);
  744. }
  745. EditorPropertyLayersGrid::EditorPropertyLayersGrid() {
  746. rename_dialog = memnew(ConfirmationDialog);
  747. VBoxContainer *rename_dialog_vb = memnew(VBoxContainer);
  748. rename_dialog->add_child(rename_dialog_vb);
  749. rename_dialog_text = memnew(LineEdit);
  750. rename_dialog_vb->add_margin_child(TTR("Name:"), rename_dialog_text);
  751. rename_dialog->set_ok_button_text(TTR("Rename"));
  752. add_child(rename_dialog);
  753. rename_dialog->register_text_enter(rename_dialog_text);
  754. rename_dialog->connect("confirmed", callable_mp(this, &EditorPropertyLayersGrid::_rename_operation_confirm));
  755. layer_rename = memnew(PopupMenu);
  756. layer_rename->add_item(TTR("Rename layer"), 0);
  757. add_child(layer_rename);
  758. layer_rename->connect("id_pressed", callable_mp(this, &EditorPropertyLayersGrid::_rename_pressed));
  759. }
  760. Size2 EditorPropertyLayersGrid::get_grid_size() const {
  761. Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label"));
  762. int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label"));
  763. return Vector2(0, font->get_height(font_size) * 3);
  764. }
  765. void EditorPropertyLayersGrid::set_read_only(bool p_read_only) {
  766. read_only = p_read_only;
  767. }
  768. Size2 EditorPropertyLayersGrid::get_minimum_size() const {
  769. Size2 min_size = get_grid_size();
  770. // Add extra rows when expanded.
  771. if (expanded) {
  772. const int bsize = (min_size.height * 80 / 100) / 2;
  773. for (int i = 0; i < expansion_rows; ++i) {
  774. min_size.y += 2 * (bsize + 1) + 3;
  775. }
  776. }
  777. return min_size;
  778. }
  779. String EditorPropertyLayersGrid::get_tooltip(const Point2 &p_pos) const {
  780. for (int i = 0; i < flag_rects.size(); i++) {
  781. if (i < tooltips.size() && flag_rects[i].has_point(p_pos)) {
  782. return tooltips[i];
  783. }
  784. }
  785. return String();
  786. }
  787. void EditorPropertyLayersGrid::gui_input(const Ref<InputEvent> &p_ev) {
  788. if (read_only) {
  789. return;
  790. }
  791. const Ref<InputEventMouseMotion> mm = p_ev;
  792. if (mm.is_valid()) {
  793. bool expand_was_hovered = expand_hovered;
  794. expand_hovered = expand_rect.has_point(mm->get_position());
  795. if (expand_hovered != expand_was_hovered) {
  796. update();
  797. }
  798. if (!expand_hovered) {
  799. for (int i = 0; i < flag_rects.size(); i++) {
  800. if (flag_rects[i].has_point(mm->get_position())) {
  801. // Used to highlight the hovered flag in the layers grid.
  802. hovered_index = i;
  803. update();
  804. return;
  805. }
  806. }
  807. }
  808. // Remove highlight when no square is hovered.
  809. if (hovered_index != -1) {
  810. hovered_index = -1;
  811. update();
  812. }
  813. return;
  814. }
  815. const Ref<InputEventMouseButton> mb = p_ev;
  816. if (mb.is_valid() && mb->get_button_index() == MouseButton::LEFT && mb->is_pressed()) {
  817. if (hovered_index >= 0) {
  818. // Toggle the flag.
  819. // We base our choice on the hovered flag, so that it always matches the hovered flag.
  820. if (value & (1 << hovered_index)) {
  821. value &= ~(1 << hovered_index);
  822. } else {
  823. value |= (1 << hovered_index);
  824. }
  825. emit_signal(SNAME("flag_changed"), value);
  826. update();
  827. } else if (expand_hovered) {
  828. expanded = !expanded;
  829. update_minimum_size();
  830. update();
  831. }
  832. }
  833. if (mb.is_valid() && mb->get_button_index() == MouseButton::RIGHT && mb->is_pressed()) {
  834. if (hovered_index >= 0) {
  835. renamed_layer_index = hovered_index;
  836. layer_rename->set_position(get_screen_position() + mb->get_position());
  837. layer_rename->reset_size();
  838. layer_rename->popup();
  839. }
  840. }
  841. }
  842. void EditorPropertyLayersGrid::_notification(int p_what) {
  843. switch (p_what) {
  844. case NOTIFICATION_DRAW: {
  845. Size2 grid_size = get_grid_size();
  846. grid_size.x = get_size().x;
  847. flag_rects.clear();
  848. int prev_expansion_rows = expansion_rows;
  849. expansion_rows = 0;
  850. const int bsize = (grid_size.height * 80 / 100) / 2;
  851. const int h = bsize * 2 + 1;
  852. Color color = get_theme_color(read_only ? SNAME("disabled_highlight_color") : SNAME("highlight_color"), SNAME("Editor"));
  853. Color text_color = get_theme_color(read_only ? SNAME("disabled_font_color") : SNAME("font_color"), SNAME("Editor"));
  854. text_color.a *= 0.5;
  855. Color text_color_on = get_theme_color(read_only ? SNAME("disabled_font_color") : SNAME("font_hover_color"), SNAME("Editor"));
  856. text_color_on.a *= 0.7;
  857. const int vofs = (grid_size.height - h) / 2;
  858. int layer_index = 0;
  859. int block_index = 0;
  860. Point2 arrow_pos;
  861. Point2 block_ofs(4, vofs);
  862. while (true) {
  863. Point2 ofs = block_ofs;
  864. for (int i = 0; i < 2; i++) {
  865. for (int j = 0; j < layer_group_size; j++) {
  866. const bool on = value & (1 << layer_index);
  867. Rect2 rect2 = Rect2(ofs, Size2(bsize, bsize));
  868. color.a = on ? 0.6 : 0.2;
  869. if (layer_index == hovered_index) {
  870. // Add visual feedback when hovering a flag.
  871. color.a += 0.15;
  872. }
  873. draw_rect(rect2, color);
  874. flag_rects.push_back(rect2);
  875. Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label"));
  876. int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label"));
  877. Vector2 offset;
  878. offset.y = rect2.size.y * 0.75;
  879. draw_string(font, rect2.position + offset, itos(layer_index + 1), HORIZONTAL_ALIGNMENT_CENTER, rect2.size.x, font_size, on ? text_color_on : text_color);
  880. ofs.x += bsize + 1;
  881. ++layer_index;
  882. }
  883. ofs.x = block_ofs.x;
  884. ofs.y += bsize + 1;
  885. }
  886. if (layer_index >= layer_count) {
  887. if (!flag_rects.is_empty() && (expansion_rows == 0)) {
  888. const Rect2 &last_rect = flag_rects[flag_rects.size() - 1];
  889. arrow_pos = last_rect.get_end();
  890. }
  891. break;
  892. }
  893. int block_size_x = layer_group_size * (bsize + 1);
  894. block_ofs.x += block_size_x + 3;
  895. if (block_ofs.x + block_size_x + 12 > grid_size.width) {
  896. // Keep last valid cell position for the expansion icon.
  897. if (!flag_rects.is_empty() && (expansion_rows == 0)) {
  898. const Rect2 &last_rect = flag_rects[flag_rects.size() - 1];
  899. arrow_pos = last_rect.get_end();
  900. }
  901. ++expansion_rows;
  902. if (expanded) {
  903. // Expand grid to next line.
  904. block_ofs.x = 4;
  905. block_ofs.y += 2 * (bsize + 1) + 3;
  906. } else {
  907. // Skip remaining blocks.
  908. break;
  909. }
  910. }
  911. ++block_index;
  912. }
  913. if ((expansion_rows != prev_expansion_rows) && expanded) {
  914. update_minimum_size();
  915. }
  916. if ((expansion_rows == 0) && (layer_index == layer_count)) {
  917. // Whole grid was drawn, no need for expansion icon.
  918. break;
  919. }
  920. Ref<Texture2D> arrow = get_theme_icon(SNAME("arrow"), SNAME("Tree"));
  921. ERR_FAIL_COND(arrow.is_null());
  922. Color arrow_color = get_theme_color(SNAME("highlight_color"), SNAME("Editor"));
  923. arrow_color.a = expand_hovered ? 1.0 : 0.6;
  924. arrow_pos.x += 2.0;
  925. arrow_pos.y -= arrow->get_height();
  926. Rect2 arrow_draw_rect(arrow_pos, arrow->get_size());
  927. expand_rect = arrow_draw_rect;
  928. if (expanded) {
  929. arrow_draw_rect.size.y *= -1.0; // Flip arrow vertically when expanded.
  930. }
  931. RID ci = get_canvas_item();
  932. arrow->draw_rect(ci, arrow_draw_rect, false, arrow_color);
  933. } break;
  934. case NOTIFICATION_MOUSE_EXIT: {
  935. if (expand_hovered) {
  936. expand_hovered = false;
  937. update();
  938. }
  939. if (hovered_index != -1) {
  940. hovered_index = -1;
  941. update();
  942. }
  943. } break;
  944. }
  945. }
  946. void EditorPropertyLayersGrid::set_flag(uint32_t p_flag) {
  947. value = p_flag;
  948. update();
  949. }
  950. void EditorPropertyLayersGrid::_bind_methods() {
  951. ADD_SIGNAL(MethodInfo("flag_changed", PropertyInfo(Variant::INT, "flag")));
  952. ADD_SIGNAL(MethodInfo("rename_confirmed", PropertyInfo(Variant::INT, "layer_id"), PropertyInfo(Variant::STRING, "new_name")));
  953. }
  954. void EditorPropertyLayers::_notification(int p_what) {
  955. switch (p_what) {
  956. case NOTIFICATION_ENTER_TREE:
  957. case NOTIFICATION_THEME_CHANGED: {
  958. button->set_normal_texture(get_theme_icon(SNAME("GuiTabMenuHl"), SNAME("EditorIcons")));
  959. button->set_pressed_texture(get_theme_icon(SNAME("GuiTabMenuHl"), SNAME("EditorIcons")));
  960. button->set_disabled_texture(get_theme_icon(SNAME("GuiTabMenu"), SNAME("EditorIcons")));
  961. } break;
  962. }
  963. }
  964. void EditorPropertyLayers::_set_read_only(bool p_read_only) {
  965. button->set_disabled(p_read_only);
  966. grid->set_read_only(p_read_only);
  967. };
  968. void EditorPropertyLayers::_grid_changed(uint32_t p_grid) {
  969. emit_changed(get_edited_property(), p_grid);
  970. }
  971. void EditorPropertyLayers::update_property() {
  972. uint32_t value = get_edited_object()->get(get_edited_property());
  973. grid->set_flag(value);
  974. }
  975. void EditorPropertyLayers::setup(LayerType p_layer_type) {
  976. layer_type = p_layer_type;
  977. int layer_group_size = 0;
  978. int layer_count = 0;
  979. switch (p_layer_type) {
  980. case LAYER_RENDER_2D: {
  981. basename = "layer_names/2d_render";
  982. layer_group_size = 5;
  983. layer_count = 20;
  984. } break;
  985. case LAYER_PHYSICS_2D: {
  986. basename = "layer_names/2d_physics";
  987. layer_group_size = 4;
  988. layer_count = 32;
  989. } break;
  990. case LAYER_NAVIGATION_2D: {
  991. basename = "layer_names/2d_navigation";
  992. layer_group_size = 4;
  993. layer_count = 32;
  994. } break;
  995. case LAYER_RENDER_3D: {
  996. basename = "layer_names/3d_render";
  997. layer_group_size = 5;
  998. layer_count = 20;
  999. } break;
  1000. case LAYER_PHYSICS_3D: {
  1001. basename = "layer_names/3d_physics";
  1002. layer_group_size = 4;
  1003. layer_count = 32;
  1004. } break;
  1005. case LAYER_NAVIGATION_3D: {
  1006. basename = "layer_names/3d_navigation";
  1007. layer_group_size = 4;
  1008. layer_count = 32;
  1009. } break;
  1010. }
  1011. Vector<String> names;
  1012. Vector<String> tooltips;
  1013. for (int i = 0; i < layer_count; i++) {
  1014. String name;
  1015. if (ProjectSettings::get_singleton()->has_setting(basename + vformat("/layer_%d", i + 1))) {
  1016. name = ProjectSettings::get_singleton()->get(basename + vformat("/layer_%d", i + 1));
  1017. }
  1018. if (name.is_empty()) {
  1019. name = vformat(TTR("Layer %d"), i + 1);
  1020. }
  1021. names.push_back(name);
  1022. tooltips.push_back(name + "\n" + vformat(TTR("Bit %d, value %d"), i, 1 << i));
  1023. }
  1024. grid->names = names;
  1025. grid->tooltips = tooltips;
  1026. grid->layer_group_size = layer_group_size;
  1027. grid->layer_count = layer_count;
  1028. }
  1029. void EditorPropertyLayers::set_layer_name(int p_index, const String &p_name) {
  1030. if (ProjectSettings::get_singleton()->has_setting(basename + vformat("/layer_%d", p_index + 1))) {
  1031. ProjectSettings::get_singleton()->set(basename + vformat("/layer_%d", p_index + 1), p_name);
  1032. ProjectSettings::get_singleton()->save();
  1033. }
  1034. }
  1035. void EditorPropertyLayers::_button_pressed() {
  1036. int layer_count = grid->layer_count;
  1037. int layer_group_size = grid->layer_group_size;
  1038. layers->clear();
  1039. for (int i = 0; i < layer_count; i++) {
  1040. if ((i != 0) && ((i % layer_group_size) == 0)) {
  1041. layers->add_separator();
  1042. }
  1043. layers->add_check_item(grid->names[i], i);
  1044. int idx = layers->get_item_index(i);
  1045. layers->set_item_checked(idx, grid->value & (1 << i));
  1046. }
  1047. Rect2 gp = button->get_screen_rect();
  1048. layers->reset_size();
  1049. Vector2 popup_pos = gp.position - Vector2(layers->get_contents_minimum_size().x, 0);
  1050. layers->set_position(popup_pos);
  1051. layers->popup();
  1052. }
  1053. void EditorPropertyLayers::_menu_pressed(int p_menu) {
  1054. if (grid->value & (1 << p_menu)) {
  1055. grid->value &= ~(1 << p_menu);
  1056. } else {
  1057. grid->value |= (1 << p_menu);
  1058. }
  1059. grid->update();
  1060. layers->set_item_checked(layers->get_item_index(p_menu), grid->value & (1 << p_menu));
  1061. _grid_changed(grid->value);
  1062. }
  1063. void EditorPropertyLayers::_refresh_names() {
  1064. setup(layer_type);
  1065. }
  1066. void EditorPropertyLayers::_bind_methods() {
  1067. }
  1068. EditorPropertyLayers::EditorPropertyLayers() {
  1069. HBoxContainer *hb = memnew(HBoxContainer);
  1070. hb->set_clip_contents(true);
  1071. add_child(hb);
  1072. grid = memnew(EditorPropertyLayersGrid);
  1073. grid->connect("flag_changed", callable_mp(this, &EditorPropertyLayers::_grid_changed));
  1074. grid->connect("rename_confirmed", callable_mp(this, &EditorPropertyLayers::set_layer_name));
  1075. grid->set_h_size_flags(SIZE_EXPAND_FILL);
  1076. hb->add_child(grid);
  1077. button = memnew(TextureButton);
  1078. button->set_stretch_mode(TextureButton::STRETCH_KEEP_CENTERED);
  1079. button->set_toggle_mode(true);
  1080. button->connect("pressed", callable_mp(this, &EditorPropertyLayers::_button_pressed));
  1081. hb->add_child(button);
  1082. set_bottom_editor(hb);
  1083. layers = memnew(PopupMenu);
  1084. add_child(layers);
  1085. layers->set_hide_on_checkable_item_selection(false);
  1086. layers->connect("id_pressed", callable_mp(this, &EditorPropertyLayers::_menu_pressed));
  1087. layers->connect("popup_hide", callable_mp((BaseButton *)button, &BaseButton::set_pressed).bind(false));
  1088. EditorNode::get_singleton()->connect("project_settings_changed", callable_mp(this, &EditorPropertyLayers::_refresh_names));
  1089. }
  1090. ///////////////////// INT /////////////////////////
  1091. void EditorPropertyInteger::_set_read_only(bool p_read_only) {
  1092. spin->set_read_only(p_read_only);
  1093. };
  1094. void EditorPropertyInteger::_value_changed(int64_t val) {
  1095. if (setting) {
  1096. return;
  1097. }
  1098. emit_changed(get_edited_property(), val);
  1099. }
  1100. void EditorPropertyInteger::update_property() {
  1101. int64_t val = get_edited_object()->get(get_edited_property());
  1102. setting = true;
  1103. spin->set_value(val);
  1104. setting = false;
  1105. #ifdef DEBUG_ENABLED
  1106. // If spin (currently EditorSplinSlider : Range) is changed so that it can use int64_t, then the below warning wouldn't be a problem.
  1107. if (val != (int64_t)(double)(val)) {
  1108. WARN_PRINT("Cannot reliably represent '" + itos(val) + "' in the inspector, value is too large.");
  1109. }
  1110. #endif
  1111. }
  1112. void EditorPropertyInteger::_bind_methods() {
  1113. }
  1114. void EditorPropertyInteger::setup(int64_t p_min, int64_t p_max, int64_t p_step, bool p_allow_greater, bool p_allow_lesser, const String &p_suffix) {
  1115. spin->set_min(p_min);
  1116. spin->set_max(p_max);
  1117. spin->set_step(p_step);
  1118. spin->set_allow_greater(p_allow_greater);
  1119. spin->set_allow_lesser(p_allow_lesser);
  1120. spin->set_suffix(p_suffix);
  1121. }
  1122. EditorPropertyInteger::EditorPropertyInteger() {
  1123. spin = memnew(EditorSpinSlider);
  1124. spin->set_flat(true);
  1125. add_child(spin);
  1126. add_focusable(spin);
  1127. spin->connect("value_changed", callable_mp(this, &EditorPropertyInteger::_value_changed));
  1128. }
  1129. ///////////////////// OBJECT ID /////////////////////////
  1130. void EditorPropertyObjectID::_set_read_only(bool p_read_only) {
  1131. edit->set_disabled(p_read_only);
  1132. };
  1133. void EditorPropertyObjectID::_edit_pressed() {
  1134. emit_signal(SNAME("object_id_selected"), get_edited_property(), get_edited_object()->get(get_edited_property()));
  1135. }
  1136. void EditorPropertyObjectID::update_property() {
  1137. String type = base_type;
  1138. if (type.is_empty()) {
  1139. type = "Object";
  1140. }
  1141. ObjectID id = get_edited_object()->get(get_edited_property());
  1142. if (id.is_valid()) {
  1143. edit->set_text(type + " ID: " + uitos(id));
  1144. edit->set_disabled(false);
  1145. edit->set_icon(EditorNode::get_singleton()->get_class_icon(type));
  1146. } else {
  1147. edit->set_text(TTR("[Empty]"));
  1148. edit->set_disabled(true);
  1149. edit->set_icon(Ref<Texture2D>());
  1150. }
  1151. }
  1152. void EditorPropertyObjectID::setup(const String &p_base_type) {
  1153. base_type = p_base_type;
  1154. }
  1155. void EditorPropertyObjectID::_bind_methods() {
  1156. }
  1157. EditorPropertyObjectID::EditorPropertyObjectID() {
  1158. edit = memnew(Button);
  1159. add_child(edit);
  1160. add_focusable(edit);
  1161. edit->connect("pressed", callable_mp(this, &EditorPropertyObjectID::_edit_pressed));
  1162. }
  1163. ///////////////////// SIGNAL /////////////////////////
  1164. void EditorPropertySignal::_edit_pressed() {
  1165. Signal signal = get_edited_object()->get(get_edited_property());
  1166. emit_signal(SNAME("object_id_selected"), get_edited_property(), signal.get_object_id());
  1167. }
  1168. void EditorPropertySignal::update_property() {
  1169. String type = base_type;
  1170. Signal signal = get_edited_object()->get(get_edited_property());
  1171. edit->set_text("Signal: " + signal.get_name());
  1172. edit->set_disabled(false);
  1173. edit->set_icon(get_theme_icon(SNAME("Signals"), SNAME("EditorIcons")));
  1174. }
  1175. void EditorPropertySignal::_bind_methods() {
  1176. }
  1177. EditorPropertySignal::EditorPropertySignal() {
  1178. edit = memnew(Button);
  1179. add_child(edit);
  1180. add_focusable(edit);
  1181. edit->connect("pressed", callable_mp(this, &EditorPropertySignal::_edit_pressed));
  1182. }
  1183. ///////////////////// CALLABLE /////////////////////////
  1184. void EditorPropertyCallable::update_property() {
  1185. String type = base_type;
  1186. Callable callable = get_edited_object()->get(get_edited_property());
  1187. edit->set_text("Callable");
  1188. edit->set_disabled(true);
  1189. edit->set_icon(get_theme_icon(SNAME("Callable"), SNAME("EditorIcons")));
  1190. }
  1191. void EditorPropertyCallable::_bind_methods() {
  1192. }
  1193. EditorPropertyCallable::EditorPropertyCallable() {
  1194. edit = memnew(Button);
  1195. add_child(edit);
  1196. add_focusable(edit);
  1197. }
  1198. ///////////////////// FLOAT /////////////////////////
  1199. void EditorPropertyFloat::_set_read_only(bool p_read_only) {
  1200. spin->set_read_only(p_read_only);
  1201. };
  1202. void EditorPropertyFloat::_value_changed(double val) {
  1203. if (setting) {
  1204. return;
  1205. }
  1206. if (angle_in_radians) {
  1207. val = Math::deg2rad(val);
  1208. }
  1209. emit_changed(get_edited_property(), val);
  1210. }
  1211. void EditorPropertyFloat::update_property() {
  1212. double val = get_edited_object()->get(get_edited_property());
  1213. if (angle_in_radians) {
  1214. val = Math::rad2deg(val);
  1215. }
  1216. setting = true;
  1217. spin->set_value(val);
  1218. setting = false;
  1219. }
  1220. void EditorPropertyFloat::_bind_methods() {
  1221. }
  1222. void EditorPropertyFloat::setup(double p_min, double p_max, double p_step, bool p_no_slider, bool p_exp_range, bool p_greater, bool p_lesser, const String &p_suffix, bool p_angle_in_radians) {
  1223. angle_in_radians = p_angle_in_radians;
  1224. spin->set_min(p_min);
  1225. spin->set_max(p_max);
  1226. spin->set_step(p_step);
  1227. spin->set_hide_slider(p_no_slider);
  1228. spin->set_exp_ratio(p_exp_range);
  1229. spin->set_allow_greater(p_greater);
  1230. spin->set_allow_lesser(p_lesser);
  1231. spin->set_suffix(p_suffix);
  1232. }
  1233. EditorPropertyFloat::EditorPropertyFloat() {
  1234. spin = memnew(EditorSpinSlider);
  1235. spin->set_flat(true);
  1236. add_child(spin);
  1237. add_focusable(spin);
  1238. spin->connect("value_changed", callable_mp(this, &EditorPropertyFloat::_value_changed));
  1239. }
  1240. ///////////////////// EASING /////////////////////////
  1241. void EditorPropertyEasing::_set_read_only(bool p_read_only) {
  1242. spin->set_read_only(p_read_only);
  1243. };
  1244. void EditorPropertyEasing::_drag_easing(const Ref<InputEvent> &p_ev) {
  1245. if (is_read_only()) {
  1246. return;
  1247. }
  1248. const Ref<InputEventMouseButton> mb = p_ev;
  1249. if (mb.is_valid()) {
  1250. if (mb->is_double_click() && mb->get_button_index() == MouseButton::LEFT) {
  1251. _setup_spin();
  1252. }
  1253. if (mb->is_pressed() && mb->get_button_index() == MouseButton::RIGHT) {
  1254. preset->set_position(easing_draw->get_screen_position() + mb->get_position());
  1255. preset->reset_size();
  1256. preset->popup();
  1257. // Ensure the easing doesn't appear as being dragged
  1258. dragging = false;
  1259. easing_draw->update();
  1260. }
  1261. if (mb->get_button_index() == MouseButton::LEFT) {
  1262. dragging = mb->is_pressed();
  1263. // Update to display the correct dragging color
  1264. easing_draw->update();
  1265. }
  1266. }
  1267. const Ref<InputEventMouseMotion> mm = p_ev;
  1268. if (dragging && mm.is_valid() && (mm->get_button_mask() & MouseButton::MASK_LEFT) != MouseButton::NONE) {
  1269. float rel = mm->get_relative().x;
  1270. if (rel == 0) {
  1271. return;
  1272. }
  1273. if (flip) {
  1274. rel = -rel;
  1275. }
  1276. float val = get_edited_object()->get(get_edited_property());
  1277. bool sg = val < 0;
  1278. val = Math::absf(val);
  1279. val = Math::log(val) / Math::log((float)2.0);
  1280. // Logarithmic space.
  1281. val += rel * 0.05;
  1282. val = Math::pow(2.0f, val);
  1283. if (sg) {
  1284. val = -val;
  1285. }
  1286. // 0 is a singularity, but both positive and negative values
  1287. // are otherwise allowed. Enforce 0+ as workaround.
  1288. if (Math::is_zero_approx(val)) {
  1289. val = 0.00001;
  1290. }
  1291. // Limit to a reasonable value to prevent the curve going into infinity,
  1292. // which can cause crashes and other issues.
  1293. val = CLAMP(val, -1'000'000, 1'000'000);
  1294. emit_changed(get_edited_property(), val);
  1295. easing_draw->update();
  1296. }
  1297. }
  1298. void EditorPropertyEasing::_draw_easing() {
  1299. RID ci = easing_draw->get_canvas_item();
  1300. Size2 s = easing_draw->get_size();
  1301. const int point_count = 48;
  1302. const float exp = get_edited_object()->get(get_edited_property());
  1303. const Ref<Font> f = get_theme_font(SNAME("font"), SNAME("Label"));
  1304. int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label"));
  1305. const Color font_color = get_theme_color(is_read_only() ? SNAME("font_uneditable_color") : SNAME("font_color"), SNAME("LineEdit"));
  1306. Color line_color;
  1307. if (dragging) {
  1308. line_color = get_theme_color(SNAME("accent_color"), SNAME("Editor"));
  1309. } else {
  1310. line_color = get_theme_color(is_read_only() ? SNAME("font_uneditable_color") : SNAME("font_color"), SNAME("LineEdit")) * Color(1, 1, 1, 0.9);
  1311. }
  1312. Vector<Point2> points;
  1313. for (int i = 0; i <= point_count; i++) {
  1314. float ifl = i / float(point_count);
  1315. const float h = 1.0 - Math::ease(ifl, exp);
  1316. if (flip) {
  1317. ifl = 1.0 - ifl;
  1318. }
  1319. points.push_back(Point2(ifl * s.width, h * s.height));
  1320. }
  1321. easing_draw->draw_polyline(points, line_color, 1.0, true);
  1322. // Draw more decimals for small numbers since higher precision is usually required for fine adjustments.
  1323. int decimals;
  1324. if (Math::abs(exp) < 0.1 - CMP_EPSILON) {
  1325. decimals = 4;
  1326. } else if (Math::abs(exp) < 1 - CMP_EPSILON) {
  1327. decimals = 3;
  1328. } else if (Math::abs(exp) < 10 - CMP_EPSILON) {
  1329. decimals = 2;
  1330. } else {
  1331. decimals = 1;
  1332. }
  1333. f->draw_string(ci, Point2(10, 10 + f->get_ascent(font_size)), TS->format_number(rtos(exp).pad_decimals(decimals)), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, font_color);
  1334. }
  1335. void EditorPropertyEasing::update_property() {
  1336. easing_draw->update();
  1337. }
  1338. void EditorPropertyEasing::_set_preset(int p_preset) {
  1339. static const float preset_value[EASING_MAX] = { 0.0, 1.0, 2.0, 0.5, -2.0, -0.5 };
  1340. emit_changed(get_edited_property(), preset_value[p_preset]);
  1341. easing_draw->update();
  1342. }
  1343. void EditorPropertyEasing::_setup_spin() {
  1344. setting = true;
  1345. spin->setup_and_show();
  1346. spin->get_line_edit()->set_text(TS->format_number(rtos(get_edited_object()->get(get_edited_property()))));
  1347. setting = false;
  1348. spin->show();
  1349. }
  1350. void EditorPropertyEasing::_spin_value_changed(double p_value) {
  1351. if (setting) {
  1352. return;
  1353. }
  1354. // 0 is a singularity, but both positive and negative values
  1355. // are otherwise allowed. Enforce 0+ as workaround.
  1356. if (Math::is_zero_approx(p_value)) {
  1357. p_value = 0.00001;
  1358. }
  1359. // Limit to a reasonable value to prevent the curve going into infinity,
  1360. // which can cause crashes and other issues.
  1361. p_value = CLAMP(p_value, -1'000'000, 1'000'000);
  1362. if (positive_only) {
  1363. // Force a positive or zero value if a negative value was manually entered by double-clicking.
  1364. p_value = MAX(0.0, p_value);
  1365. }
  1366. emit_changed(get_edited_property(), p_value);
  1367. _spin_focus_exited();
  1368. }
  1369. void EditorPropertyEasing::_spin_focus_exited() {
  1370. spin->hide();
  1371. // Ensure the easing doesn't appear as being dragged
  1372. dragging = false;
  1373. easing_draw->update();
  1374. }
  1375. void EditorPropertyEasing::setup(bool p_positive_only, bool p_flip) {
  1376. flip = p_flip;
  1377. positive_only = p_positive_only;
  1378. }
  1379. void EditorPropertyEasing::_notification(int p_what) {
  1380. switch (p_what) {
  1381. case NOTIFICATION_THEME_CHANGED:
  1382. case NOTIFICATION_ENTER_TREE: {
  1383. preset->clear();
  1384. preset->add_icon_item(get_theme_icon(SNAME("CurveLinear"), SNAME("EditorIcons")), "Linear", EASING_LINEAR);
  1385. preset->add_icon_item(get_theme_icon(SNAME("CurveIn"), SNAME("EditorIcons")), "Ease In", EASING_IN);
  1386. preset->add_icon_item(get_theme_icon(SNAME("CurveOut"), SNAME("EditorIcons")), "Ease Out", EASING_OUT);
  1387. preset->add_icon_item(get_theme_icon(SNAME("CurveConstant"), SNAME("EditorIcons")), "Zero", EASING_ZERO);
  1388. if (!positive_only) {
  1389. preset->add_icon_item(get_theme_icon(SNAME("CurveInOut"), SNAME("EditorIcons")), "Ease In-Out", EASING_IN_OUT);
  1390. preset->add_icon_item(get_theme_icon(SNAME("CurveOutIn"), SNAME("EditorIcons")), "Ease Out-In", EASING_OUT_IN);
  1391. }
  1392. easing_draw->set_custom_minimum_size(Size2(0, get_theme_font(SNAME("font"), SNAME("Label"))->get_height(get_theme_font_size(SNAME("font_size"), SNAME("Label"))) * 2));
  1393. } break;
  1394. }
  1395. }
  1396. void EditorPropertyEasing::_bind_methods() {
  1397. }
  1398. EditorPropertyEasing::EditorPropertyEasing() {
  1399. easing_draw = memnew(Control);
  1400. easing_draw->connect("draw", callable_mp(this, &EditorPropertyEasing::_draw_easing));
  1401. easing_draw->connect("gui_input", callable_mp(this, &EditorPropertyEasing::_drag_easing));
  1402. easing_draw->set_default_cursor_shape(Control::CURSOR_MOVE);
  1403. add_child(easing_draw);
  1404. preset = memnew(PopupMenu);
  1405. add_child(preset);
  1406. preset->connect("id_pressed", callable_mp(this, &EditorPropertyEasing::_set_preset));
  1407. spin = memnew(EditorSpinSlider);
  1408. spin->set_flat(true);
  1409. spin->set_min(-100);
  1410. spin->set_max(100);
  1411. spin->set_step(0);
  1412. spin->set_hide_slider(true);
  1413. spin->set_allow_lesser(true);
  1414. spin->set_allow_greater(true);
  1415. spin->connect("value_changed", callable_mp(this, &EditorPropertyEasing::_spin_value_changed));
  1416. spin->get_line_edit()->connect("focus_exited", callable_mp(this, &EditorPropertyEasing::_spin_focus_exited));
  1417. spin->hide();
  1418. add_child(spin);
  1419. }
  1420. ///////////////////// VECTOR2 /////////////////////////
  1421. void EditorPropertyVector2::_set_read_only(bool p_read_only) {
  1422. for (int i = 0; i < 2; i++) {
  1423. spin[i]->set_read_only(p_read_only);
  1424. }
  1425. };
  1426. void EditorPropertyVector2::_value_changed(double val, const String &p_name) {
  1427. if (setting) {
  1428. return;
  1429. }
  1430. if (linked->is_pressed()) {
  1431. setting = true;
  1432. if (p_name == "x") {
  1433. spin[1]->set_value(spin[0]->get_value() * ratio_yx);
  1434. }
  1435. if (p_name == "y") {
  1436. spin[0]->set_value(spin[1]->get_value() * ratio_xy);
  1437. }
  1438. setting = false;
  1439. }
  1440. Vector2 v2;
  1441. v2.x = spin[0]->get_value();
  1442. v2.y = spin[1]->get_value();
  1443. emit_changed(get_edited_property(), v2, p_name);
  1444. }
  1445. void EditorPropertyVector2::update_property() {
  1446. Vector2 val = get_edited_object()->get(get_edited_property());
  1447. setting = true;
  1448. spin[0]->set_value(val.x);
  1449. spin[1]->set_value(val.y);
  1450. setting = false;
  1451. _update_ratio();
  1452. }
  1453. void EditorPropertyVector2::_update_ratio() {
  1454. linked->set_modulate(Color(1, 1, 1, linked->is_pressed() ? 1.0 : 0.5));
  1455. if (spin[0]->get_value() != 0 && spin[1]->get_value() != 0) {
  1456. ratio_xy = spin[0]->get_value() / spin[1]->get_value();
  1457. ratio_yx = spin[1]->get_value() / spin[0]->get_value();
  1458. } else {
  1459. ratio_xy = 1.0;
  1460. ratio_yx = 1.0;
  1461. }
  1462. }
  1463. void EditorPropertyVector2::_notification(int p_what) {
  1464. switch (p_what) {
  1465. case NOTIFICATION_ENTER_TREE:
  1466. case NOTIFICATION_THEME_CHANGED: {
  1467. linked->set_normal_texture(get_theme_icon(SNAME("Unlinked"), SNAME("EditorIcons")));
  1468. linked->set_pressed_texture(get_theme_icon(SNAME("Instance"), SNAME("EditorIcons")));
  1469. const Color *colors = _get_property_colors();
  1470. for (int i = 0; i < 2; i++) {
  1471. spin[i]->add_theme_color_override("label_color", colors[i]);
  1472. }
  1473. } break;
  1474. }
  1475. }
  1476. void EditorPropertyVector2::setup(double p_min, double p_max, double p_step, bool p_no_slider, bool p_link, const String &p_suffix) {
  1477. for (int i = 0; i < 2; i++) {
  1478. spin[i]->set_min(p_min);
  1479. spin[i]->set_max(p_max);
  1480. spin[i]->set_step(p_step);
  1481. spin[i]->set_hide_slider(p_no_slider);
  1482. spin[i]->set_allow_greater(true);
  1483. spin[i]->set_allow_lesser(true);
  1484. spin[i]->set_suffix(p_suffix);
  1485. }
  1486. if (!p_link) {
  1487. linked->hide();
  1488. } else {
  1489. linked->set_pressed(true);
  1490. }
  1491. }
  1492. EditorPropertyVector2::EditorPropertyVector2(bool p_force_wide) {
  1493. bool horizontal = p_force_wide || bool(EDITOR_GET("interface/inspector/horizontal_vector2_editing"));
  1494. HBoxContainer *hb = memnew(HBoxContainer);
  1495. hb->set_h_size_flags(SIZE_EXPAND_FILL);
  1496. BoxContainer *bc;
  1497. if (p_force_wide) {
  1498. bc = memnew(HBoxContainer);
  1499. hb->add_child(bc);
  1500. } else if (horizontal) {
  1501. bc = memnew(HBoxContainer);
  1502. hb->add_child(bc);
  1503. set_bottom_editor(hb);
  1504. } else {
  1505. bc = memnew(VBoxContainer);
  1506. hb->add_child(bc);
  1507. }
  1508. bc->set_h_size_flags(SIZE_EXPAND_FILL);
  1509. static const char *desc[2] = { "x", "y" };
  1510. for (int i = 0; i < 2; i++) {
  1511. spin[i] = memnew(EditorSpinSlider);
  1512. spin[i]->set_flat(true);
  1513. spin[i]->set_label(desc[i]);
  1514. bc->add_child(spin[i]);
  1515. add_focusable(spin[i]);
  1516. spin[i]->connect("value_changed", callable_mp(this, &EditorPropertyVector2::_value_changed).bind(desc[i]));
  1517. if (horizontal) {
  1518. spin[i]->set_h_size_flags(SIZE_EXPAND_FILL);
  1519. }
  1520. }
  1521. linked = memnew(TextureButton);
  1522. linked->set_toggle_mode(true);
  1523. linked->set_stretch_mode(TextureButton::STRETCH_KEEP_CENTERED);
  1524. linked->connect(SNAME("pressed"), callable_mp(this, &EditorPropertyVector2::_update_ratio));
  1525. hb->add_child(linked);
  1526. add_child(hb);
  1527. if (!horizontal) {
  1528. set_label_reference(spin[0]); //show text and buttons around this
  1529. }
  1530. }
  1531. ///////////////////// RECT2 /////////////////////////
  1532. void EditorPropertyRect2::_set_read_only(bool p_read_only) {
  1533. for (int i = 0; i < 4; i++) {
  1534. spin[i]->set_read_only(p_read_only);
  1535. }
  1536. };
  1537. void EditorPropertyRect2::_value_changed(double val, const String &p_name) {
  1538. if (setting) {
  1539. return;
  1540. }
  1541. Rect2 r2;
  1542. r2.position.x = spin[0]->get_value();
  1543. r2.position.y = spin[1]->get_value();
  1544. r2.size.x = spin[2]->get_value();
  1545. r2.size.y = spin[3]->get_value();
  1546. emit_changed(get_edited_property(), r2, p_name);
  1547. }
  1548. void EditorPropertyRect2::update_property() {
  1549. Rect2 val = get_edited_object()->get(get_edited_property());
  1550. setting = true;
  1551. spin[0]->set_value(val.position.x);
  1552. spin[1]->set_value(val.position.y);
  1553. spin[2]->set_value(val.size.x);
  1554. spin[3]->set_value(val.size.y);
  1555. setting = false;
  1556. }
  1557. void EditorPropertyRect2::_notification(int p_what) {
  1558. switch (p_what) {
  1559. case NOTIFICATION_ENTER_TREE:
  1560. case NOTIFICATION_THEME_CHANGED: {
  1561. const Color *colors = _get_property_colors();
  1562. for (int i = 0; i < 4; i++) {
  1563. spin[i]->add_theme_color_override("label_color", colors[i % 2]);
  1564. }
  1565. } break;
  1566. }
  1567. }
  1568. void EditorPropertyRect2::_bind_methods() {
  1569. }
  1570. void EditorPropertyRect2::setup(double p_min, double p_max, double p_step, bool p_no_slider, const String &p_suffix) {
  1571. for (int i = 0; i < 4; i++) {
  1572. spin[i]->set_min(p_min);
  1573. spin[i]->set_max(p_max);
  1574. spin[i]->set_step(p_step);
  1575. spin[i]->set_hide_slider(p_no_slider);
  1576. spin[i]->set_allow_greater(true);
  1577. spin[i]->set_allow_lesser(true);
  1578. spin[i]->set_suffix(p_suffix);
  1579. }
  1580. }
  1581. EditorPropertyRect2::EditorPropertyRect2(bool p_force_wide) {
  1582. bool horizontal = p_force_wide || bool(EDITOR_GET("interface/inspector/horizontal_vector_types_editing"));
  1583. bool grid = false;
  1584. BoxContainer *bc;
  1585. if (p_force_wide) {
  1586. bc = memnew(HBoxContainer);
  1587. add_child(bc);
  1588. } else if (horizontal) {
  1589. bc = memnew(VBoxContainer);
  1590. add_child(bc);
  1591. set_bottom_editor(bc);
  1592. bc->add_child(memnew(HBoxContainer));
  1593. bc->add_child(memnew(HBoxContainer));
  1594. grid = true;
  1595. } else {
  1596. bc = memnew(VBoxContainer);
  1597. add_child(bc);
  1598. }
  1599. static const char *desc[4] = { "x", "y", "w", "h" };
  1600. for (int i = 0; i < 4; i++) {
  1601. spin[i] = memnew(EditorSpinSlider);
  1602. spin[i]->set_label(desc[i]);
  1603. spin[i]->set_flat(true);
  1604. if (grid) {
  1605. bc->get_child(i / 2)->add_child(spin[i]);
  1606. } else {
  1607. bc->add_child(spin[i]);
  1608. }
  1609. add_focusable(spin[i]);
  1610. spin[i]->connect("value_changed", callable_mp(this, &EditorPropertyRect2::_value_changed).bind(desc[i]));
  1611. if (horizontal) {
  1612. spin[i]->set_h_size_flags(SIZE_EXPAND_FILL);
  1613. }
  1614. }
  1615. if (!horizontal) {
  1616. set_label_reference(spin[0]); //show text and buttons around this
  1617. }
  1618. }
  1619. ///////////////////// VECTOR3 /////////////////////////
  1620. void EditorPropertyVector3::_set_read_only(bool p_read_only) {
  1621. for (int i = 0; i < 3; i++) {
  1622. spin[i]->set_read_only(p_read_only);
  1623. }
  1624. };
  1625. void EditorPropertyVector3::_value_changed(double val, const String &p_name) {
  1626. if (setting) {
  1627. return;
  1628. }
  1629. if (linked->is_pressed()) {
  1630. setting = true;
  1631. if (p_name == "x") {
  1632. spin[1]->set_value(spin[0]->get_value() * ratio_yx);
  1633. spin[2]->set_value(spin[0]->get_value() * ratio_zx);
  1634. }
  1635. if (p_name == "y") {
  1636. spin[0]->set_value(spin[1]->get_value() * ratio_xy);
  1637. spin[2]->set_value(spin[1]->get_value() * ratio_zy);
  1638. }
  1639. if (p_name == "z") {
  1640. spin[0]->set_value(spin[2]->get_value() * ratio_xz);
  1641. spin[1]->set_value(spin[2]->get_value() * ratio_yz);
  1642. }
  1643. setting = false;
  1644. }
  1645. Vector3 v3;
  1646. v3.x = spin[0]->get_value();
  1647. v3.y = spin[1]->get_value();
  1648. v3.z = spin[2]->get_value();
  1649. if (angle_in_radians) {
  1650. v3.x = Math::deg2rad(v3.x);
  1651. v3.y = Math::deg2rad(v3.y);
  1652. v3.z = Math::deg2rad(v3.z);
  1653. }
  1654. emit_changed(get_edited_property(), v3, p_name);
  1655. }
  1656. void EditorPropertyVector3::update_property() {
  1657. update_using_vector(get_edited_object()->get(get_edited_property()));
  1658. _update_ratio();
  1659. }
  1660. void EditorPropertyVector3::_update_ratio() {
  1661. linked->set_modulate(Color(1, 1, 1, linked->is_pressed() ? 1.0 : 0.5));
  1662. if (spin[0]->get_value() != 0 && spin[1]->get_value() != 0) {
  1663. ratio_yx = spin[1]->get_value() / spin[0]->get_value();
  1664. ratio_zx = spin[2]->get_value() / spin[0]->get_value();
  1665. ratio_xy = spin[0]->get_value() / spin[1]->get_value();
  1666. ratio_zy = spin[2]->get_value() / spin[1]->get_value();
  1667. ratio_xz = spin[0]->get_value() / spin[2]->get_value();
  1668. ratio_yz = spin[1]->get_value() / spin[2]->get_value();
  1669. } else {
  1670. ratio_yx = 1.0;
  1671. ratio_zx = 1.0;
  1672. ratio_xy = 1.0;
  1673. ratio_zy = 1.0;
  1674. ratio_xz = 1.0;
  1675. ratio_yz = 1.0;
  1676. }
  1677. }
  1678. void EditorPropertyVector3::update_using_vector(Vector3 p_vector) {
  1679. if (angle_in_radians) {
  1680. p_vector.x = Math::rad2deg(p_vector.x);
  1681. p_vector.y = Math::rad2deg(p_vector.y);
  1682. p_vector.z = Math::rad2deg(p_vector.z);
  1683. }
  1684. setting = true;
  1685. spin[0]->set_value(p_vector.x);
  1686. spin[1]->set_value(p_vector.y);
  1687. spin[2]->set_value(p_vector.z);
  1688. setting = false;
  1689. }
  1690. Vector3 EditorPropertyVector3::get_vector() {
  1691. Vector3 v3;
  1692. v3.x = spin[0]->get_value();
  1693. v3.y = spin[1]->get_value();
  1694. v3.z = spin[2]->get_value();
  1695. if (angle_in_radians) {
  1696. v3.x = Math::deg2rad(v3.x);
  1697. v3.y = Math::deg2rad(v3.y);
  1698. v3.z = Math::deg2rad(v3.z);
  1699. }
  1700. return v3;
  1701. }
  1702. void EditorPropertyVector3::_notification(int p_what) {
  1703. switch (p_what) {
  1704. case NOTIFICATION_ENTER_TREE:
  1705. case NOTIFICATION_THEME_CHANGED: {
  1706. linked->set_normal_texture(get_theme_icon(SNAME("Unlinked"), SNAME("EditorIcons")));
  1707. linked->set_pressed_texture(get_theme_icon(SNAME("Instance"), SNAME("EditorIcons")));
  1708. const Color *colors = _get_property_colors();
  1709. for (int i = 0; i < 3; i++) {
  1710. spin[i]->add_theme_color_override("label_color", colors[i]);
  1711. }
  1712. } break;
  1713. }
  1714. }
  1715. void EditorPropertyVector3::_bind_methods() {
  1716. }
  1717. void EditorPropertyVector3::setup(double p_min, double p_max, double p_step, bool p_no_slider, bool p_link, const String &p_suffix, bool p_angle_in_radians) {
  1718. angle_in_radians = p_angle_in_radians;
  1719. for (int i = 0; i < 3; i++) {
  1720. spin[i]->set_min(p_min);
  1721. spin[i]->set_max(p_max);
  1722. spin[i]->set_step(p_step);
  1723. spin[i]->set_hide_slider(p_no_slider);
  1724. spin[i]->set_allow_greater(true);
  1725. spin[i]->set_allow_lesser(true);
  1726. spin[i]->set_suffix(p_suffix);
  1727. }
  1728. if (!p_link) {
  1729. linked->hide();
  1730. } else {
  1731. linked->set_pressed(true);
  1732. }
  1733. }
  1734. EditorPropertyVector3::EditorPropertyVector3(bool p_force_wide) {
  1735. bool horizontal = p_force_wide || bool(EDITOR_GET("interface/inspector/horizontal_vector_types_editing"));
  1736. HBoxContainer *hb = memnew(HBoxContainer);
  1737. hb->set_h_size_flags(SIZE_EXPAND_FILL);
  1738. BoxContainer *bc;
  1739. if (p_force_wide) {
  1740. bc = memnew(HBoxContainer);
  1741. hb->add_child(bc);
  1742. } else if (horizontal) {
  1743. bc = memnew(HBoxContainer);
  1744. hb->add_child(bc);
  1745. set_bottom_editor(hb);
  1746. } else {
  1747. bc = memnew(VBoxContainer);
  1748. hb->add_child(bc);
  1749. }
  1750. bc->set_h_size_flags(SIZE_EXPAND_FILL);
  1751. static const char *desc[3] = { "x", "y", "z" };
  1752. for (int i = 0; i < 3; i++) {
  1753. spin[i] = memnew(EditorSpinSlider);
  1754. spin[i]->set_flat(true);
  1755. spin[i]->set_label(desc[i]);
  1756. bc->add_child(spin[i]);
  1757. add_focusable(spin[i]);
  1758. spin[i]->connect("value_changed", callable_mp(this, &EditorPropertyVector3::_value_changed).bind(desc[i]));
  1759. if (horizontal) {
  1760. spin[i]->set_h_size_flags(SIZE_EXPAND_FILL);
  1761. }
  1762. }
  1763. linked = memnew(TextureButton);
  1764. linked->set_toggle_mode(true);
  1765. linked->set_stretch_mode(TextureButton::STRETCH_KEEP_CENTERED);
  1766. linked->connect(SNAME("pressed"), callable_mp(this, &EditorPropertyVector3::_update_ratio));
  1767. hb->add_child(linked);
  1768. add_child(hb);
  1769. if (!horizontal) {
  1770. set_label_reference(spin[0]); //show text and buttons around this
  1771. }
  1772. }
  1773. ///////////////////// VECTOR2i /////////////////////////
  1774. void EditorPropertyVector2i::_set_read_only(bool p_read_only) {
  1775. for (int i = 0; i < 2; i++) {
  1776. spin[i]->set_read_only(p_read_only);
  1777. }
  1778. };
  1779. void EditorPropertyVector2i::_value_changed(double val, const String &p_name) {
  1780. if (setting) {
  1781. return;
  1782. }
  1783. if (linked->is_pressed()) {
  1784. setting = true;
  1785. if (p_name == "x") {
  1786. spin[1]->set_value(spin[0]->get_value() * ratio_yx);
  1787. }
  1788. if (p_name == "y") {
  1789. spin[0]->set_value(spin[1]->get_value() * ratio_xy);
  1790. }
  1791. setting = false;
  1792. }
  1793. Vector2i v2;
  1794. v2.x = spin[0]->get_value();
  1795. v2.y = spin[1]->get_value();
  1796. emit_changed(get_edited_property(), v2, p_name);
  1797. }
  1798. void EditorPropertyVector2i::update_property() {
  1799. Vector2i val = get_edited_object()->get(get_edited_property());
  1800. setting = true;
  1801. spin[0]->set_value(val.x);
  1802. spin[1]->set_value(val.y);
  1803. setting = false;
  1804. _update_ratio();
  1805. }
  1806. void EditorPropertyVector2i::_update_ratio() {
  1807. linked->set_modulate(Color(1, 1, 1, linked->is_pressed() ? 1.0 : 0.5));
  1808. if (spin[0]->get_value() != 0 && spin[1]->get_value() != 0) {
  1809. ratio_xy = spin[0]->get_value() / spin[1]->get_value();
  1810. ratio_yx = spin[1]->get_value() / spin[0]->get_value();
  1811. } else {
  1812. ratio_xy = 1.0;
  1813. ratio_yx = 1.0;
  1814. }
  1815. }
  1816. void EditorPropertyVector2i::_notification(int p_what) {
  1817. switch (p_what) {
  1818. case NOTIFICATION_ENTER_TREE:
  1819. case NOTIFICATION_THEME_CHANGED: {
  1820. linked->set_normal_texture(get_theme_icon(SNAME("Unlinked"), SNAME("EditorIcons")));
  1821. linked->set_pressed_texture(get_theme_icon(SNAME("Instance"), SNAME("EditorIcons")));
  1822. const Color *colors = _get_property_colors();
  1823. for (int i = 0; i < 2; i++) {
  1824. spin[i]->add_theme_color_override("label_color", colors[i]);
  1825. }
  1826. } break;
  1827. }
  1828. }
  1829. void EditorPropertyVector2i::setup(int p_min, int p_max, bool p_no_slider, bool p_link, const String &p_suffix) {
  1830. for (int i = 0; i < 2; i++) {
  1831. spin[i]->set_min(p_min);
  1832. spin[i]->set_max(p_max);
  1833. spin[i]->set_step(1);
  1834. spin[i]->set_hide_slider(p_no_slider);
  1835. spin[i]->set_allow_greater(true);
  1836. spin[i]->set_allow_lesser(true);
  1837. spin[i]->set_suffix(p_suffix);
  1838. }
  1839. if (!p_link) {
  1840. linked->hide();
  1841. } else {
  1842. linked->set_pressed(true);
  1843. }
  1844. }
  1845. EditorPropertyVector2i::EditorPropertyVector2i(bool p_force_wide) {
  1846. bool horizontal = p_force_wide || bool(EDITOR_GET("interface/inspector/horizontal_vector2_editing"));
  1847. HBoxContainer *hb = memnew(HBoxContainer);
  1848. hb->set_h_size_flags(SIZE_EXPAND_FILL);
  1849. BoxContainer *bc;
  1850. if (p_force_wide) {
  1851. bc = memnew(HBoxContainer);
  1852. hb->add_child(bc);
  1853. } else if (horizontal) {
  1854. bc = memnew(HBoxContainer);
  1855. hb->add_child(bc);
  1856. set_bottom_editor(hb);
  1857. } else {
  1858. bc = memnew(VBoxContainer);
  1859. hb->add_child(bc);
  1860. }
  1861. bc->set_h_size_flags(SIZE_EXPAND_FILL);
  1862. static const char *desc[2] = { "x", "y" };
  1863. for (int i = 0; i < 2; i++) {
  1864. spin[i] = memnew(EditorSpinSlider);
  1865. spin[i]->set_flat(true);
  1866. spin[i]->set_label(desc[i]);
  1867. bc->add_child(spin[i]);
  1868. add_focusable(spin[i]);
  1869. spin[i]->connect("value_changed", callable_mp(this, &EditorPropertyVector2i::_value_changed).bind(desc[i]));
  1870. if (horizontal) {
  1871. spin[i]->set_h_size_flags(SIZE_EXPAND_FILL);
  1872. }
  1873. }
  1874. linked = memnew(TextureButton);
  1875. linked->set_toggle_mode(true);
  1876. linked->set_stretch_mode(TextureButton::STRETCH_KEEP_CENTERED);
  1877. linked->connect(SNAME("pressed"), callable_mp(this, &EditorPropertyVector2i::_update_ratio));
  1878. hb->add_child(linked);
  1879. add_child(hb);
  1880. if (!horizontal) {
  1881. set_label_reference(spin[0]); //show text and buttons around this
  1882. }
  1883. }
  1884. ///////////////////// RECT2i /////////////////////////
  1885. void EditorPropertyRect2i::_set_read_only(bool p_read_only) {
  1886. for (int i = 0; i < 4; i++) {
  1887. spin[i]->set_read_only(p_read_only);
  1888. }
  1889. };
  1890. void EditorPropertyRect2i::_value_changed(double val, const String &p_name) {
  1891. if (setting) {
  1892. return;
  1893. }
  1894. Rect2i r2;
  1895. r2.position.x = spin[0]->get_value();
  1896. r2.position.y = spin[1]->get_value();
  1897. r2.size.x = spin[2]->get_value();
  1898. r2.size.y = spin[3]->get_value();
  1899. emit_changed(get_edited_property(), r2, p_name);
  1900. }
  1901. void EditorPropertyRect2i::update_property() {
  1902. Rect2i val = get_edited_object()->get(get_edited_property());
  1903. setting = true;
  1904. spin[0]->set_value(val.position.x);
  1905. spin[1]->set_value(val.position.y);
  1906. spin[2]->set_value(val.size.x);
  1907. spin[3]->set_value(val.size.y);
  1908. setting = false;
  1909. }
  1910. void EditorPropertyRect2i::_notification(int p_what) {
  1911. switch (p_what) {
  1912. case NOTIFICATION_ENTER_TREE:
  1913. case NOTIFICATION_THEME_CHANGED: {
  1914. const Color *colors = _get_property_colors();
  1915. for (int i = 0; i < 4; i++) {
  1916. spin[i]->add_theme_color_override("label_color", colors[i % 2]);
  1917. }
  1918. } break;
  1919. }
  1920. }
  1921. void EditorPropertyRect2i::_bind_methods() {
  1922. }
  1923. void EditorPropertyRect2i::setup(int p_min, int p_max, bool p_no_slider, const String &p_suffix) {
  1924. for (int i = 0; i < 4; i++) {
  1925. spin[i]->set_min(p_min);
  1926. spin[i]->set_max(p_max);
  1927. spin[i]->set_step(1);
  1928. spin[i]->set_hide_slider(p_no_slider);
  1929. spin[i]->set_allow_greater(true);
  1930. spin[i]->set_allow_lesser(true);
  1931. spin[i]->set_suffix(p_suffix);
  1932. }
  1933. }
  1934. EditorPropertyRect2i::EditorPropertyRect2i(bool p_force_wide) {
  1935. bool horizontal = p_force_wide || bool(EDITOR_GET("interface/inspector/horizontal_vector_types_editing"));
  1936. bool grid = false;
  1937. BoxContainer *bc;
  1938. if (p_force_wide) {
  1939. bc = memnew(HBoxContainer);
  1940. add_child(bc);
  1941. } else if (horizontal) {
  1942. bc = memnew(VBoxContainer);
  1943. add_child(bc);
  1944. set_bottom_editor(bc);
  1945. bc->add_child(memnew(HBoxContainer));
  1946. bc->add_child(memnew(HBoxContainer));
  1947. grid = true;
  1948. } else {
  1949. bc = memnew(VBoxContainer);
  1950. add_child(bc);
  1951. }
  1952. static const char *desc[4] = { "x", "y", "w", "h" };
  1953. for (int i = 0; i < 4; i++) {
  1954. spin[i] = memnew(EditorSpinSlider);
  1955. spin[i]->set_label(desc[i]);
  1956. spin[i]->set_flat(true);
  1957. if (grid) {
  1958. bc->get_child(i / 2)->add_child(spin[i]);
  1959. } else {
  1960. bc->add_child(spin[i]);
  1961. }
  1962. add_focusable(spin[i]);
  1963. spin[i]->connect("value_changed", callable_mp(this, &EditorPropertyRect2i::_value_changed).bind(desc[i]));
  1964. if (horizontal) {
  1965. spin[i]->set_h_size_flags(SIZE_EXPAND_FILL);
  1966. }
  1967. }
  1968. if (!horizontal) {
  1969. set_label_reference(spin[0]); //show text and buttons around this
  1970. }
  1971. }
  1972. ///////////////////// VECTOR3I /////////////////////////
  1973. void EditorPropertyVector3i::_set_read_only(bool p_read_only) {
  1974. for (int i = 0; i < 3; i++) {
  1975. spin[i]->set_read_only(p_read_only);
  1976. }
  1977. };
  1978. void EditorPropertyVector3i::_value_changed(double val, const String &p_name) {
  1979. if (setting) {
  1980. return;
  1981. }
  1982. if (linked->is_pressed()) {
  1983. setting = true;
  1984. if (p_name == "x") {
  1985. spin[1]->set_value(spin[0]->get_value() * ratio_yx);
  1986. spin[2]->set_value(spin[0]->get_value() * ratio_zx);
  1987. }
  1988. if (p_name == "y") {
  1989. spin[0]->set_value(spin[1]->get_value() * ratio_xy);
  1990. spin[2]->set_value(spin[1]->get_value() * ratio_zy);
  1991. }
  1992. if (p_name == "z") {
  1993. spin[0]->set_value(spin[2]->get_value() * ratio_xz);
  1994. spin[1]->set_value(spin[2]->get_value() * ratio_yz);
  1995. }
  1996. setting = false;
  1997. }
  1998. Vector3i v3;
  1999. v3.x = spin[0]->get_value();
  2000. v3.y = spin[1]->get_value();
  2001. v3.z = spin[2]->get_value();
  2002. emit_changed(get_edited_property(), v3, p_name);
  2003. }
  2004. void EditorPropertyVector3i::update_property() {
  2005. Vector3i val = get_edited_object()->get(get_edited_property());
  2006. setting = true;
  2007. spin[0]->set_value(val.x);
  2008. spin[1]->set_value(val.y);
  2009. spin[2]->set_value(val.z);
  2010. setting = false;
  2011. _update_ratio();
  2012. }
  2013. void EditorPropertyVector3i::_update_ratio() {
  2014. linked->set_modulate(Color(1, 1, 1, linked->is_pressed() ? 1.0 : 0.5));
  2015. if (spin[0]->get_value() != 0 && spin[1]->get_value() != 0) {
  2016. ratio_yx = spin[1]->get_value() / spin[0]->get_value();
  2017. ratio_zx = spin[2]->get_value() / spin[0]->get_value();
  2018. ratio_xy = spin[0]->get_value() / spin[1]->get_value();
  2019. ratio_zy = spin[2]->get_value() / spin[1]->get_value();
  2020. ratio_xz = spin[0]->get_value() / spin[2]->get_value();
  2021. ratio_yz = spin[1]->get_value() / spin[2]->get_value();
  2022. } else {
  2023. ratio_yx = 1.0;
  2024. ratio_zx = 1.0;
  2025. ratio_xy = 1.0;
  2026. ratio_zy = 1.0;
  2027. ratio_xz = 1.0;
  2028. ratio_yz = 1.0;
  2029. }
  2030. }
  2031. void EditorPropertyVector3i::_notification(int p_what) {
  2032. switch (p_what) {
  2033. case NOTIFICATION_ENTER_TREE:
  2034. case NOTIFICATION_THEME_CHANGED: {
  2035. linked->set_normal_texture(get_theme_icon(SNAME("Unlinked"), SNAME("EditorIcons")));
  2036. linked->set_pressed_texture(get_theme_icon(SNAME("Instance"), SNAME("EditorIcons")));
  2037. const Color *colors = _get_property_colors();
  2038. for (int i = 0; i < 3; i++) {
  2039. spin[i]->add_theme_color_override("label_color", colors[i]);
  2040. }
  2041. } break;
  2042. }
  2043. }
  2044. void EditorPropertyVector3i::_bind_methods() {
  2045. }
  2046. void EditorPropertyVector3i::setup(int p_min, int p_max, bool p_no_slider, bool p_link, const String &p_suffix) {
  2047. for (int i = 0; i < 3; i++) {
  2048. spin[i]->set_min(p_min);
  2049. spin[i]->set_max(p_max);
  2050. spin[i]->set_step(1);
  2051. spin[i]->set_hide_slider(p_no_slider);
  2052. spin[i]->set_allow_greater(true);
  2053. spin[i]->set_allow_lesser(true);
  2054. spin[i]->set_suffix(p_suffix);
  2055. }
  2056. if (!p_link) {
  2057. linked->hide();
  2058. } else {
  2059. linked->set_pressed(true);
  2060. }
  2061. }
  2062. EditorPropertyVector3i::EditorPropertyVector3i(bool p_force_wide) {
  2063. bool horizontal = p_force_wide || bool(EDITOR_GET("interface/inspector/horizontal_vector_types_editing"));
  2064. HBoxContainer *hb = memnew(HBoxContainer);
  2065. hb->set_h_size_flags(SIZE_EXPAND_FILL);
  2066. BoxContainer *bc;
  2067. if (p_force_wide) {
  2068. bc = memnew(HBoxContainer);
  2069. hb->add_child(bc);
  2070. } else if (horizontal) {
  2071. bc = memnew(HBoxContainer);
  2072. hb->add_child(bc);
  2073. set_bottom_editor(hb);
  2074. } else {
  2075. bc = memnew(VBoxContainer);
  2076. hb->add_child(bc);
  2077. }
  2078. static const char *desc[3] = { "x", "y", "z" };
  2079. for (int i = 0; i < 3; i++) {
  2080. spin[i] = memnew(EditorSpinSlider);
  2081. spin[i]->set_flat(true);
  2082. spin[i]->set_label(desc[i]);
  2083. bc->add_child(spin[i]);
  2084. add_focusable(spin[i]);
  2085. spin[i]->connect("value_changed", callable_mp(this, &EditorPropertyVector3i::_value_changed).bind(desc[i]));
  2086. if (horizontal) {
  2087. spin[i]->set_h_size_flags(SIZE_EXPAND_FILL);
  2088. }
  2089. }
  2090. bc->set_h_size_flags(SIZE_EXPAND_FILL);
  2091. linked = memnew(TextureButton);
  2092. linked->set_toggle_mode(true);
  2093. linked->set_stretch_mode(TextureButton::STRETCH_KEEP_CENTERED);
  2094. linked->connect(SNAME("pressed"), callable_mp(this, &EditorPropertyVector3i::_update_ratio));
  2095. hb->add_child(linked);
  2096. add_child(hb);
  2097. if (!horizontal) {
  2098. set_label_reference(spin[0]); //show text and buttons around this
  2099. }
  2100. }
  2101. ///////////////////// PLANE /////////////////////////
  2102. void EditorPropertyPlane::_set_read_only(bool p_read_only) {
  2103. for (int i = 0; i < 4; i++) {
  2104. spin[i]->set_read_only(p_read_only);
  2105. }
  2106. };
  2107. void EditorPropertyPlane::_value_changed(double val, const String &p_name) {
  2108. if (setting) {
  2109. return;
  2110. }
  2111. Plane p;
  2112. p.normal.x = spin[0]->get_value();
  2113. p.normal.y = spin[1]->get_value();
  2114. p.normal.z = spin[2]->get_value();
  2115. p.d = spin[3]->get_value();
  2116. emit_changed(get_edited_property(), p, p_name);
  2117. }
  2118. void EditorPropertyPlane::update_property() {
  2119. Plane val = get_edited_object()->get(get_edited_property());
  2120. setting = true;
  2121. spin[0]->set_value(val.normal.x);
  2122. spin[1]->set_value(val.normal.y);
  2123. spin[2]->set_value(val.normal.z);
  2124. spin[3]->set_value(val.d);
  2125. setting = false;
  2126. }
  2127. void EditorPropertyPlane::_notification(int p_what) {
  2128. switch (p_what) {
  2129. case NOTIFICATION_ENTER_TREE:
  2130. case NOTIFICATION_THEME_CHANGED: {
  2131. const Color *colors = _get_property_colors();
  2132. for (int i = 0; i < 4; i++) {
  2133. spin[i]->add_theme_color_override("label_color", colors[i]);
  2134. }
  2135. } break;
  2136. }
  2137. }
  2138. void EditorPropertyPlane::_bind_methods() {
  2139. }
  2140. void EditorPropertyPlane::setup(double p_min, double p_max, double p_step, bool p_no_slider, const String &p_suffix) {
  2141. for (int i = 0; i < 4; i++) {
  2142. spin[i]->set_min(p_min);
  2143. spin[i]->set_max(p_max);
  2144. spin[i]->set_step(p_step);
  2145. spin[i]->set_hide_slider(p_no_slider);
  2146. spin[i]->set_allow_greater(true);
  2147. spin[i]->set_allow_lesser(true);
  2148. }
  2149. spin[3]->set_suffix(p_suffix);
  2150. }
  2151. EditorPropertyPlane::EditorPropertyPlane(bool p_force_wide) {
  2152. bool horizontal = p_force_wide || bool(EDITOR_GET("interface/inspector/horizontal_vector_types_editing"));
  2153. BoxContainer *bc;
  2154. if (p_force_wide) {
  2155. bc = memnew(HBoxContainer);
  2156. add_child(bc);
  2157. } else if (horizontal) {
  2158. bc = memnew(HBoxContainer);
  2159. add_child(bc);
  2160. set_bottom_editor(bc);
  2161. } else {
  2162. bc = memnew(VBoxContainer);
  2163. add_child(bc);
  2164. }
  2165. static const char *desc[4] = { "x", "y", "z", "d" };
  2166. for (int i = 0; i < 4; i++) {
  2167. spin[i] = memnew(EditorSpinSlider);
  2168. spin[i]->set_flat(true);
  2169. spin[i]->set_label(desc[i]);
  2170. bc->add_child(spin[i]);
  2171. add_focusable(spin[i]);
  2172. spin[i]->connect("value_changed", callable_mp(this, &EditorPropertyPlane::_value_changed).bind(desc[i]));
  2173. if (horizontal) {
  2174. spin[i]->set_h_size_flags(SIZE_EXPAND_FILL);
  2175. }
  2176. }
  2177. if (!horizontal) {
  2178. set_label_reference(spin[0]); //show text and buttons around this
  2179. }
  2180. }
  2181. ///////////////////// QUATERNION /////////////////////////
  2182. void EditorPropertyQuaternion::_set_read_only(bool p_read_only) {
  2183. for (int i = 0; i < 4; i++) {
  2184. spin[i]->set_read_only(p_read_only);
  2185. }
  2186. };
  2187. void EditorPropertyQuaternion::_value_changed(double val, const String &p_name) {
  2188. if (setting) {
  2189. return;
  2190. }
  2191. Quaternion p;
  2192. p.x = spin[0]->get_value();
  2193. p.y = spin[1]->get_value();
  2194. p.z = spin[2]->get_value();
  2195. p.w = spin[3]->get_value();
  2196. emit_changed(get_edited_property(), p, p_name);
  2197. }
  2198. void EditorPropertyQuaternion::update_property() {
  2199. Quaternion val = get_edited_object()->get(get_edited_property());
  2200. setting = true;
  2201. spin[0]->set_value(val.x);
  2202. spin[1]->set_value(val.y);
  2203. spin[2]->set_value(val.z);
  2204. spin[3]->set_value(val.w);
  2205. setting = false;
  2206. }
  2207. void EditorPropertyQuaternion::_notification(int p_what) {
  2208. switch (p_what) {
  2209. case NOTIFICATION_ENTER_TREE:
  2210. case NOTIFICATION_THEME_CHANGED: {
  2211. const Color *colors = _get_property_colors();
  2212. for (int i = 0; i < 4; i++) {
  2213. spin[i]->add_theme_color_override("label_color", colors[i]);
  2214. }
  2215. } break;
  2216. }
  2217. }
  2218. void EditorPropertyQuaternion::_bind_methods() {
  2219. }
  2220. void EditorPropertyQuaternion::setup(double p_min, double p_max, double p_step, bool p_no_slider, const String &p_suffix) {
  2221. for (int i = 0; i < 4; i++) {
  2222. spin[i]->set_min(p_min);
  2223. spin[i]->set_max(p_max);
  2224. spin[i]->set_step(p_step);
  2225. spin[i]->set_hide_slider(p_no_slider);
  2226. spin[i]->set_allow_greater(true);
  2227. spin[i]->set_allow_lesser(true);
  2228. // Quaternion is inherently unitless, however someone may want to use it as
  2229. // a generic way to store 4 values, so we'll still respect the suffix.
  2230. spin[i]->set_suffix(p_suffix);
  2231. }
  2232. }
  2233. EditorPropertyQuaternion::EditorPropertyQuaternion() {
  2234. bool horizontal = EDITOR_GET("interface/inspector/horizontal_vector_types_editing");
  2235. BoxContainer *bc;
  2236. if (horizontal) {
  2237. bc = memnew(HBoxContainer);
  2238. add_child(bc);
  2239. set_bottom_editor(bc);
  2240. } else {
  2241. bc = memnew(VBoxContainer);
  2242. add_child(bc);
  2243. }
  2244. static const char *desc[4] = { "x", "y", "z", "w" };
  2245. for (int i = 0; i < 4; i++) {
  2246. spin[i] = memnew(EditorSpinSlider);
  2247. spin[i]->set_flat(true);
  2248. spin[i]->set_label(desc[i]);
  2249. bc->add_child(spin[i]);
  2250. add_focusable(spin[i]);
  2251. spin[i]->connect("value_changed", callable_mp(this, &EditorPropertyQuaternion::_value_changed).bind(desc[i]));
  2252. if (horizontal) {
  2253. spin[i]->set_h_size_flags(SIZE_EXPAND_FILL);
  2254. }
  2255. }
  2256. if (!horizontal) {
  2257. set_label_reference(spin[0]); //show text and buttons around this
  2258. }
  2259. }
  2260. ///////////////////// VECTOR4 /////////////////////////
  2261. void EditorPropertyVector4::_set_read_only(bool p_read_only) {
  2262. for (int i = 0; i < 4; i++) {
  2263. spin[i]->set_read_only(p_read_only);
  2264. }
  2265. };
  2266. void EditorPropertyVector4::_value_changed(double val, const String &p_name) {
  2267. if (setting) {
  2268. return;
  2269. }
  2270. Vector4 p;
  2271. p.x = spin[0]->get_value();
  2272. p.y = spin[1]->get_value();
  2273. p.z = spin[2]->get_value();
  2274. p.w = spin[3]->get_value();
  2275. emit_changed(get_edited_property(), p, p_name);
  2276. }
  2277. void EditorPropertyVector4::update_property() {
  2278. Vector4 val = get_edited_object()->get(get_edited_property());
  2279. setting = true;
  2280. spin[0]->set_value(val.x);
  2281. spin[1]->set_value(val.y);
  2282. spin[2]->set_value(val.z);
  2283. spin[3]->set_value(val.w);
  2284. setting = false;
  2285. }
  2286. void EditorPropertyVector4::_notification(int p_what) {
  2287. switch (p_what) {
  2288. case NOTIFICATION_ENTER_TREE:
  2289. case NOTIFICATION_THEME_CHANGED: {
  2290. const Color *colors = _get_property_colors();
  2291. for (int i = 0; i < 4; i++) {
  2292. spin[i]->add_theme_color_override("label_color", colors[i]);
  2293. }
  2294. } break;
  2295. }
  2296. }
  2297. void EditorPropertyVector4::_bind_methods() {
  2298. }
  2299. void EditorPropertyVector4::setup(double p_min, double p_max, double p_step, bool p_no_slider, const String &p_suffix) {
  2300. for (int i = 0; i < 4; i++) {
  2301. spin[i]->set_min(p_min);
  2302. spin[i]->set_max(p_max);
  2303. spin[i]->set_step(p_step);
  2304. spin[i]->set_hide_slider(p_no_slider);
  2305. spin[i]->set_allow_greater(true);
  2306. spin[i]->set_allow_lesser(true);
  2307. // Vector4 is inherently unitless, however someone may want to use it as
  2308. // a generic way to store 4 values, so we'll still respect the suffix.
  2309. spin[i]->set_suffix(p_suffix);
  2310. }
  2311. }
  2312. EditorPropertyVector4::EditorPropertyVector4() {
  2313. bool horizontal = EDITOR_GET("interface/inspector/horizontal_vector_types_editing");
  2314. BoxContainer *bc;
  2315. if (horizontal) {
  2316. bc = memnew(HBoxContainer);
  2317. add_child(bc);
  2318. set_bottom_editor(bc);
  2319. } else {
  2320. bc = memnew(VBoxContainer);
  2321. add_child(bc);
  2322. }
  2323. static const char *desc[4] = { "x", "y", "z", "w" };
  2324. for (int i = 0; i < 4; i++) {
  2325. spin[i] = memnew(EditorSpinSlider);
  2326. spin[i]->set_flat(true);
  2327. spin[i]->set_label(desc[i]);
  2328. bc->add_child(spin[i]);
  2329. add_focusable(spin[i]);
  2330. spin[i]->connect("value_changed", callable_mp(this, &EditorPropertyVector4::_value_changed).bind(desc[i]));
  2331. if (horizontal) {
  2332. spin[i]->set_h_size_flags(SIZE_EXPAND_FILL);
  2333. }
  2334. }
  2335. if (!horizontal) {
  2336. set_label_reference(spin[0]); //show text and buttons around this
  2337. }
  2338. }
  2339. ///////////////////// VECTOR4I /////////////////////////
  2340. void EditorPropertyVector4i::_set_read_only(bool p_read_only) {
  2341. for (int i = 0; i < 4; i++) {
  2342. spin[i]->set_read_only(p_read_only);
  2343. }
  2344. };
  2345. void EditorPropertyVector4i::_value_changed(double val, const String &p_name) {
  2346. if (setting) {
  2347. return;
  2348. }
  2349. Vector4i p;
  2350. p.x = spin[0]->get_value();
  2351. p.y = spin[1]->get_value();
  2352. p.z = spin[2]->get_value();
  2353. p.w = spin[3]->get_value();
  2354. emit_changed(get_edited_property(), p, p_name);
  2355. }
  2356. void EditorPropertyVector4i::update_property() {
  2357. Vector4i val = get_edited_object()->get(get_edited_property());
  2358. setting = true;
  2359. spin[0]->set_value(val.x);
  2360. spin[1]->set_value(val.y);
  2361. spin[2]->set_value(val.z);
  2362. spin[3]->set_value(val.w);
  2363. setting = false;
  2364. }
  2365. void EditorPropertyVector4i::_notification(int p_what) {
  2366. switch (p_what) {
  2367. case NOTIFICATION_ENTER_TREE:
  2368. case NOTIFICATION_THEME_CHANGED: {
  2369. const Color *colors = _get_property_colors();
  2370. for (int i = 0; i < 4; i++) {
  2371. spin[i]->add_theme_color_override("label_color", colors[i]);
  2372. }
  2373. } break;
  2374. }
  2375. }
  2376. void EditorPropertyVector4i::_bind_methods() {
  2377. }
  2378. void EditorPropertyVector4i::setup(double p_min, double p_max, bool p_no_slider, const String &p_suffix) {
  2379. for (int i = 0; i < 4; i++) {
  2380. spin[i]->set_min(p_min);
  2381. spin[i]->set_max(p_max);
  2382. spin[i]->set_hide_slider(p_no_slider);
  2383. spin[i]->set_allow_greater(true);
  2384. spin[i]->set_allow_lesser(true);
  2385. spin[i]->set_suffix(p_suffix);
  2386. }
  2387. }
  2388. EditorPropertyVector4i::EditorPropertyVector4i() {
  2389. bool horizontal = EDITOR_GET("interface/inspector/horizontal_vector_types_editing");
  2390. BoxContainer *bc;
  2391. if (horizontal) {
  2392. bc = memnew(HBoxContainer);
  2393. add_child(bc);
  2394. set_bottom_editor(bc);
  2395. } else {
  2396. bc = memnew(VBoxContainer);
  2397. add_child(bc);
  2398. }
  2399. static const char *desc[4] = { "x", "y", "z", "w" };
  2400. for (int i = 0; i < 4; i++) {
  2401. spin[i] = memnew(EditorSpinSlider);
  2402. spin[i]->set_flat(true);
  2403. spin[i]->set_label(desc[i]);
  2404. bc->add_child(spin[i]);
  2405. add_focusable(spin[i]);
  2406. spin[i]->connect("value_changed", callable_mp(this, &EditorPropertyVector4i::_value_changed).bind(desc[i]));
  2407. if (horizontal) {
  2408. spin[i]->set_h_size_flags(SIZE_EXPAND_FILL);
  2409. }
  2410. }
  2411. if (!horizontal) {
  2412. set_label_reference(spin[0]); //show text and buttons around this
  2413. }
  2414. }
  2415. ///////////////////// AABB /////////////////////////
  2416. void EditorPropertyAABB::_set_read_only(bool p_read_only) {
  2417. for (int i = 0; i < 6; i++) {
  2418. spin[i]->set_read_only(p_read_only);
  2419. }
  2420. };
  2421. void EditorPropertyAABB::_value_changed(double val, const String &p_name) {
  2422. if (setting) {
  2423. return;
  2424. }
  2425. AABB p;
  2426. p.position.x = spin[0]->get_value();
  2427. p.position.y = spin[1]->get_value();
  2428. p.position.z = spin[2]->get_value();
  2429. p.size.x = spin[3]->get_value();
  2430. p.size.y = spin[4]->get_value();
  2431. p.size.z = spin[5]->get_value();
  2432. emit_changed(get_edited_property(), p, p_name);
  2433. }
  2434. void EditorPropertyAABB::update_property() {
  2435. AABB val = get_edited_object()->get(get_edited_property());
  2436. setting = true;
  2437. spin[0]->set_value(val.position.x);
  2438. spin[1]->set_value(val.position.y);
  2439. spin[2]->set_value(val.position.z);
  2440. spin[3]->set_value(val.size.x);
  2441. spin[4]->set_value(val.size.y);
  2442. spin[5]->set_value(val.size.z);
  2443. setting = false;
  2444. }
  2445. void EditorPropertyAABB::_notification(int p_what) {
  2446. switch (p_what) {
  2447. case NOTIFICATION_ENTER_TREE:
  2448. case NOTIFICATION_THEME_CHANGED: {
  2449. const Color *colors = _get_property_colors();
  2450. for (int i = 0; i < 6; i++) {
  2451. spin[i]->add_theme_color_override("label_color", colors[i % 3]);
  2452. }
  2453. } break;
  2454. }
  2455. }
  2456. void EditorPropertyAABB::_bind_methods() {
  2457. }
  2458. void EditorPropertyAABB::setup(double p_min, double p_max, double p_step, bool p_no_slider, const String &p_suffix) {
  2459. for (int i = 0; i < 6; i++) {
  2460. spin[i]->set_min(p_min);
  2461. spin[i]->set_max(p_max);
  2462. spin[i]->set_step(p_step);
  2463. spin[i]->set_hide_slider(p_no_slider);
  2464. spin[i]->set_allow_greater(true);
  2465. spin[i]->set_allow_lesser(true);
  2466. spin[i]->set_suffix(p_suffix);
  2467. }
  2468. }
  2469. EditorPropertyAABB::EditorPropertyAABB() {
  2470. GridContainer *g = memnew(GridContainer);
  2471. g->set_columns(3);
  2472. add_child(g);
  2473. static const char *desc[6] = { "x", "y", "z", "w", "h", "d" };
  2474. for (int i = 0; i < 6; i++) {
  2475. spin[i] = memnew(EditorSpinSlider);
  2476. spin[i]->set_label(desc[i]);
  2477. spin[i]->set_flat(true);
  2478. g->add_child(spin[i]);
  2479. spin[i]->set_h_size_flags(SIZE_EXPAND_FILL);
  2480. add_focusable(spin[i]);
  2481. spin[i]->connect("value_changed", callable_mp(this, &EditorPropertyAABB::_value_changed).bind(desc[i]));
  2482. }
  2483. set_bottom_editor(g);
  2484. }
  2485. ///////////////////// TRANSFORM2D /////////////////////////
  2486. void EditorPropertyTransform2D::_set_read_only(bool p_read_only) {
  2487. for (int i = 0; i < 6; i++) {
  2488. spin[i]->set_read_only(p_read_only);
  2489. }
  2490. };
  2491. void EditorPropertyTransform2D::_value_changed(double val, const String &p_name) {
  2492. if (setting) {
  2493. return;
  2494. }
  2495. Transform2D p;
  2496. p[0][0] = spin[0]->get_value();
  2497. p[1][0] = spin[1]->get_value();
  2498. p[2][0] = spin[2]->get_value();
  2499. p[0][1] = spin[3]->get_value();
  2500. p[1][1] = spin[4]->get_value();
  2501. p[2][1] = spin[5]->get_value();
  2502. emit_changed(get_edited_property(), p, p_name);
  2503. }
  2504. void EditorPropertyTransform2D::update_property() {
  2505. Transform2D val = get_edited_object()->get(get_edited_property());
  2506. setting = true;
  2507. spin[0]->set_value(val[0][0]);
  2508. spin[1]->set_value(val[1][0]);
  2509. spin[2]->set_value(val[2][0]);
  2510. spin[3]->set_value(val[0][1]);
  2511. spin[4]->set_value(val[1][1]);
  2512. spin[5]->set_value(val[2][1]);
  2513. setting = false;
  2514. }
  2515. void EditorPropertyTransform2D::_notification(int p_what) {
  2516. switch (p_what) {
  2517. case NOTIFICATION_ENTER_TREE:
  2518. case NOTIFICATION_THEME_CHANGED: {
  2519. const Color *colors = _get_property_colors();
  2520. for (int i = 0; i < 6; i++) {
  2521. // For Transform2D, use the 4th color (cyan) for the origin vector.
  2522. if (i % 3 == 2) {
  2523. spin[i]->add_theme_color_override("label_color", colors[3]);
  2524. } else {
  2525. spin[i]->add_theme_color_override("label_color", colors[i % 3]);
  2526. }
  2527. }
  2528. } break;
  2529. }
  2530. }
  2531. void EditorPropertyTransform2D::_bind_methods() {
  2532. }
  2533. void EditorPropertyTransform2D::setup(double p_min, double p_max, double p_step, bool p_no_slider, const String &p_suffix) {
  2534. for (int i = 0; i < 6; i++) {
  2535. spin[i]->set_min(p_min);
  2536. spin[i]->set_max(p_max);
  2537. spin[i]->set_step(p_step);
  2538. spin[i]->set_hide_slider(p_no_slider);
  2539. spin[i]->set_allow_greater(true);
  2540. spin[i]->set_allow_lesser(true);
  2541. if (i % 3 == 2) {
  2542. spin[i]->set_suffix(p_suffix);
  2543. }
  2544. }
  2545. }
  2546. EditorPropertyTransform2D::EditorPropertyTransform2D(bool p_include_origin) {
  2547. GridContainer *g = memnew(GridContainer);
  2548. g->set_columns(p_include_origin ? 3 : 2);
  2549. add_child(g);
  2550. static const char *desc[6] = { "xx", "xy", "xo", "yx", "yy", "yo" };
  2551. for (int i = 0; i < 6; i++) {
  2552. spin[i] = memnew(EditorSpinSlider);
  2553. spin[i]->set_label(desc[i]);
  2554. spin[i]->set_flat(true);
  2555. if (p_include_origin || i % 3 != 2) {
  2556. g->add_child(spin[i]);
  2557. }
  2558. spin[i]->set_h_size_flags(SIZE_EXPAND_FILL);
  2559. add_focusable(spin[i]);
  2560. spin[i]->connect("value_changed", callable_mp(this, &EditorPropertyTransform2D::_value_changed).bind(desc[i]));
  2561. }
  2562. set_bottom_editor(g);
  2563. }
  2564. ///////////////////// BASIS /////////////////////////
  2565. void EditorPropertyBasis::_set_read_only(bool p_read_only) {
  2566. for (int i = 0; i < 9; i++) {
  2567. spin[i]->set_read_only(p_read_only);
  2568. }
  2569. };
  2570. void EditorPropertyBasis::_value_changed(double val, const String &p_name) {
  2571. if (setting) {
  2572. return;
  2573. }
  2574. Basis p;
  2575. p[0][0] = spin[0]->get_value();
  2576. p[0][1] = spin[1]->get_value();
  2577. p[0][2] = spin[2]->get_value();
  2578. p[1][0] = spin[3]->get_value();
  2579. p[1][1] = spin[4]->get_value();
  2580. p[1][2] = spin[5]->get_value();
  2581. p[2][0] = spin[6]->get_value();
  2582. p[2][1] = spin[7]->get_value();
  2583. p[2][2] = spin[8]->get_value();
  2584. emit_changed(get_edited_property(), p, p_name);
  2585. }
  2586. void EditorPropertyBasis::update_property() {
  2587. Basis val = get_edited_object()->get(get_edited_property());
  2588. setting = true;
  2589. spin[0]->set_value(val[0][0]);
  2590. spin[1]->set_value(val[0][1]);
  2591. spin[2]->set_value(val[0][2]);
  2592. spin[3]->set_value(val[1][0]);
  2593. spin[4]->set_value(val[1][1]);
  2594. spin[5]->set_value(val[1][2]);
  2595. spin[6]->set_value(val[2][0]);
  2596. spin[7]->set_value(val[2][1]);
  2597. spin[8]->set_value(val[2][2]);
  2598. setting = false;
  2599. }
  2600. void EditorPropertyBasis::_notification(int p_what) {
  2601. switch (p_what) {
  2602. case NOTIFICATION_ENTER_TREE:
  2603. case NOTIFICATION_THEME_CHANGED: {
  2604. const Color *colors = _get_property_colors();
  2605. for (int i = 0; i < 9; i++) {
  2606. spin[i]->add_theme_color_override("label_color", colors[i % 3]);
  2607. }
  2608. } break;
  2609. }
  2610. }
  2611. void EditorPropertyBasis::_bind_methods() {
  2612. }
  2613. void EditorPropertyBasis::setup(double p_min, double p_max, double p_step, bool p_no_slider, const String &p_suffix) {
  2614. for (int i = 0; i < 9; i++) {
  2615. spin[i]->set_min(p_min);
  2616. spin[i]->set_max(p_max);
  2617. spin[i]->set_step(p_step);
  2618. spin[i]->set_hide_slider(p_no_slider);
  2619. spin[i]->set_allow_greater(true);
  2620. spin[i]->set_allow_lesser(true);
  2621. // Basis is inherently unitless, however someone may want to use it as
  2622. // a generic way to store 9 values, so we'll still respect the suffix.
  2623. spin[i]->set_suffix(p_suffix);
  2624. }
  2625. }
  2626. EditorPropertyBasis::EditorPropertyBasis() {
  2627. GridContainer *g = memnew(GridContainer);
  2628. g->set_columns(3);
  2629. add_child(g);
  2630. static const char *desc[9] = { "xx", "xy", "xz", "yx", "yy", "yz", "zx", "zy", "zz" };
  2631. for (int i = 0; i < 9; i++) {
  2632. spin[i] = memnew(EditorSpinSlider);
  2633. spin[i]->set_label(desc[i]);
  2634. spin[i]->set_flat(true);
  2635. g->add_child(spin[i]);
  2636. spin[i]->set_h_size_flags(SIZE_EXPAND_FILL);
  2637. add_focusable(spin[i]);
  2638. spin[i]->connect("value_changed", callable_mp(this, &EditorPropertyBasis::_value_changed).bind(desc[i]));
  2639. }
  2640. set_bottom_editor(g);
  2641. }
  2642. ///////////////////// TRANSFORM3D /////////////////////////
  2643. void EditorPropertyTransform3D::_set_read_only(bool p_read_only) {
  2644. for (int i = 0; i < 12; i++) {
  2645. spin[i]->set_read_only(p_read_only);
  2646. }
  2647. };
  2648. void EditorPropertyTransform3D::_value_changed(double val, const String &p_name) {
  2649. if (setting) {
  2650. return;
  2651. }
  2652. Transform3D p;
  2653. p.basis[0][0] = spin[0]->get_value();
  2654. p.basis[0][1] = spin[1]->get_value();
  2655. p.basis[0][2] = spin[2]->get_value();
  2656. p.origin[0] = spin[3]->get_value();
  2657. p.basis[1][0] = spin[4]->get_value();
  2658. p.basis[1][1] = spin[5]->get_value();
  2659. p.basis[1][2] = spin[6]->get_value();
  2660. p.origin[1] = spin[7]->get_value();
  2661. p.basis[2][0] = spin[8]->get_value();
  2662. p.basis[2][1] = spin[9]->get_value();
  2663. p.basis[2][2] = spin[10]->get_value();
  2664. p.origin[2] = spin[11]->get_value();
  2665. emit_changed(get_edited_property(), p, p_name);
  2666. }
  2667. void EditorPropertyTransform3D::update_property() {
  2668. update_using_transform(get_edited_object()->get(get_edited_property()));
  2669. }
  2670. void EditorPropertyTransform3D::update_using_transform(Transform3D p_transform) {
  2671. setting = true;
  2672. spin[0]->set_value(p_transform.basis[0][0]);
  2673. spin[1]->set_value(p_transform.basis[0][1]);
  2674. spin[2]->set_value(p_transform.basis[0][2]);
  2675. spin[3]->set_value(p_transform.origin[0]);
  2676. spin[4]->set_value(p_transform.basis[1][0]);
  2677. spin[5]->set_value(p_transform.basis[1][1]);
  2678. spin[6]->set_value(p_transform.basis[1][2]);
  2679. spin[7]->set_value(p_transform.origin[1]);
  2680. spin[8]->set_value(p_transform.basis[2][0]);
  2681. spin[9]->set_value(p_transform.basis[2][1]);
  2682. spin[10]->set_value(p_transform.basis[2][2]);
  2683. spin[11]->set_value(p_transform.origin[2]);
  2684. setting = false;
  2685. }
  2686. void EditorPropertyTransform3D::_notification(int p_what) {
  2687. switch (p_what) {
  2688. case NOTIFICATION_ENTER_TREE:
  2689. case NOTIFICATION_THEME_CHANGED: {
  2690. const Color *colors = _get_property_colors();
  2691. for (int i = 0; i < 12; i++) {
  2692. spin[i]->add_theme_color_override("label_color", colors[i % 4]);
  2693. }
  2694. } break;
  2695. }
  2696. }
  2697. void EditorPropertyTransform3D::_bind_methods() {
  2698. }
  2699. void EditorPropertyTransform3D::setup(double p_min, double p_max, double p_step, bool p_no_slider, const String &p_suffix) {
  2700. for (int i = 0; i < 12; i++) {
  2701. spin[i]->set_min(p_min);
  2702. spin[i]->set_max(p_max);
  2703. spin[i]->set_step(p_step);
  2704. spin[i]->set_hide_slider(p_no_slider);
  2705. spin[i]->set_allow_greater(true);
  2706. spin[i]->set_allow_lesser(true);
  2707. if (i % 4 == 3) {
  2708. spin[i]->set_suffix(p_suffix);
  2709. }
  2710. }
  2711. }
  2712. EditorPropertyTransform3D::EditorPropertyTransform3D() {
  2713. GridContainer *g = memnew(GridContainer);
  2714. g->set_columns(4);
  2715. add_child(g);
  2716. static const char *desc[12] = { "xx", "xy", "xz", "xo", "yx", "yy", "yz", "yo", "zx", "zy", "zz", "zo" };
  2717. for (int i = 0; i < 12; i++) {
  2718. spin[i] = memnew(EditorSpinSlider);
  2719. spin[i]->set_label(desc[i]);
  2720. spin[i]->set_flat(true);
  2721. g->add_child(spin[i]);
  2722. spin[i]->set_h_size_flags(SIZE_EXPAND_FILL);
  2723. add_focusable(spin[i]);
  2724. spin[i]->connect("value_changed", callable_mp(this, &EditorPropertyTransform3D::_value_changed).bind(desc[i]));
  2725. }
  2726. set_bottom_editor(g);
  2727. }
  2728. ///////////////////// PROJECTION /////////////////////////
  2729. void EditorPropertyProjection::_set_read_only(bool p_read_only) {
  2730. for (int i = 0; i < 12; i++) {
  2731. spin[i]->set_read_only(p_read_only);
  2732. }
  2733. };
  2734. void EditorPropertyProjection::_value_changed(double val, const String &p_name) {
  2735. if (setting) {
  2736. return;
  2737. }
  2738. Projection p;
  2739. p.matrix[0][0] = spin[0]->get_value();
  2740. p.matrix[0][1] = spin[1]->get_value();
  2741. p.matrix[0][2] = spin[2]->get_value();
  2742. p.matrix[0][3] = spin[3]->get_value();
  2743. p.matrix[1][0] = spin[4]->get_value();
  2744. p.matrix[1][1] = spin[5]->get_value();
  2745. p.matrix[1][2] = spin[6]->get_value();
  2746. p.matrix[1][3] = spin[7]->get_value();
  2747. p.matrix[2][0] = spin[8]->get_value();
  2748. p.matrix[2][1] = spin[9]->get_value();
  2749. p.matrix[2][2] = spin[10]->get_value();
  2750. p.matrix[2][3] = spin[11]->get_value();
  2751. p.matrix[3][0] = spin[12]->get_value();
  2752. p.matrix[3][1] = spin[13]->get_value();
  2753. p.matrix[3][2] = spin[14]->get_value();
  2754. p.matrix[3][3] = spin[15]->get_value();
  2755. emit_changed(get_edited_property(), p, p_name);
  2756. }
  2757. void EditorPropertyProjection::update_property() {
  2758. update_using_transform(get_edited_object()->get(get_edited_property()));
  2759. }
  2760. void EditorPropertyProjection::update_using_transform(Projection p_transform) {
  2761. setting = true;
  2762. spin[0]->set_value(p_transform.matrix[0][0]);
  2763. spin[1]->set_value(p_transform.matrix[0][1]);
  2764. spin[2]->set_value(p_transform.matrix[0][2]);
  2765. spin[3]->set_value(p_transform.matrix[0][3]);
  2766. spin[4]->set_value(p_transform.matrix[1][0]);
  2767. spin[5]->set_value(p_transform.matrix[1][1]);
  2768. spin[6]->set_value(p_transform.matrix[1][2]);
  2769. spin[7]->set_value(p_transform.matrix[1][3]);
  2770. spin[8]->set_value(p_transform.matrix[2][0]);
  2771. spin[9]->set_value(p_transform.matrix[2][1]);
  2772. spin[10]->set_value(p_transform.matrix[2][2]);
  2773. spin[11]->set_value(p_transform.matrix[2][3]);
  2774. spin[12]->set_value(p_transform.matrix[3][0]);
  2775. spin[13]->set_value(p_transform.matrix[3][1]);
  2776. spin[14]->set_value(p_transform.matrix[3][2]);
  2777. spin[15]->set_value(p_transform.matrix[3][3]);
  2778. setting = false;
  2779. }
  2780. void EditorPropertyProjection::_notification(int p_what) {
  2781. switch (p_what) {
  2782. case NOTIFICATION_ENTER_TREE:
  2783. case NOTIFICATION_THEME_CHANGED: {
  2784. const Color *colors = _get_property_colors();
  2785. for (int i = 0; i < 16; i++) {
  2786. spin[i]->add_theme_color_override("label_color", colors[i % 4]);
  2787. }
  2788. } break;
  2789. }
  2790. }
  2791. void EditorPropertyProjection::_bind_methods() {
  2792. }
  2793. void EditorPropertyProjection::setup(double p_min, double p_max, double p_step, bool p_no_slider, const String &p_suffix) {
  2794. for (int i = 0; i < 16; i++) {
  2795. spin[i]->set_min(p_min);
  2796. spin[i]->set_max(p_max);
  2797. spin[i]->set_step(p_step);
  2798. spin[i]->set_hide_slider(p_no_slider);
  2799. spin[i]->set_allow_greater(true);
  2800. spin[i]->set_allow_lesser(true);
  2801. if (i % 4 == 3) {
  2802. spin[i]->set_suffix(p_suffix);
  2803. }
  2804. }
  2805. }
  2806. EditorPropertyProjection::EditorPropertyProjection() {
  2807. GridContainer *g = memnew(GridContainer);
  2808. g->set_columns(4);
  2809. add_child(g);
  2810. static const char *desc[16] = { "xx", "xy", "xz", "xw", "yx", "yy", "yz", "yw", "zx", "zy", "zz", "zw", "wx", "wy", "wz", "ww" };
  2811. for (int i = 0; i < 16; i++) {
  2812. spin[i] = memnew(EditorSpinSlider);
  2813. spin[i]->set_label(desc[i]);
  2814. spin[i]->set_flat(true);
  2815. g->add_child(spin[i]);
  2816. spin[i]->set_h_size_flags(SIZE_EXPAND_FILL);
  2817. add_focusable(spin[i]);
  2818. spin[i]->connect("value_changed", callable_mp(this, &EditorPropertyProjection::_value_changed).bind(desc[i]));
  2819. }
  2820. set_bottom_editor(g);
  2821. }
  2822. ////////////// COLOR PICKER //////////////////////
  2823. void EditorPropertyColor::_set_read_only(bool p_read_only) {
  2824. picker->set_disabled(p_read_only);
  2825. };
  2826. void EditorPropertyColor::_color_changed(const Color &p_color) {
  2827. // Cancel the color change if the current color is identical to the new one.
  2828. if (get_edited_object()->get(get_edited_property()) == p_color) {
  2829. return;
  2830. }
  2831. emit_changed(get_edited_property(), p_color, "", true);
  2832. }
  2833. void EditorPropertyColor::_popup_closed() {
  2834. if (picker->get_pick_color() != last_color) {
  2835. emit_changed(get_edited_property(), picker->get_pick_color(), "", false);
  2836. }
  2837. }
  2838. void EditorPropertyColor::_picker_opening() {
  2839. last_color = picker->get_pick_color();
  2840. }
  2841. void EditorPropertyColor::_notification(int p_what) {
  2842. switch (p_what) {
  2843. case NOTIFICATION_ENTER_TREE:
  2844. case NOTIFICATION_THEME_CHANGED: {
  2845. picker->set_custom_minimum_size(Size2(0, get_theme_constant(SNAME("color_picker_button_height"), SNAME("Editor"))));
  2846. } break;
  2847. }
  2848. }
  2849. void EditorPropertyColor::update_property() {
  2850. picker->set_pick_color(get_edited_object()->get(get_edited_property()));
  2851. const Color color = picker->get_pick_color();
  2852. // Add a tooltip to display each channel's values without having to click the ColorPickerButton
  2853. if (picker->is_editing_alpha()) {
  2854. picker->set_tooltip(vformat(
  2855. "R: %s\nG: %s\nB: %s\nA: %s",
  2856. rtos(color.r).pad_decimals(2),
  2857. rtos(color.g).pad_decimals(2),
  2858. rtos(color.b).pad_decimals(2),
  2859. rtos(color.a).pad_decimals(2)));
  2860. } else {
  2861. picker->set_tooltip(vformat(
  2862. "R: %s\nG: %s\nB: %s",
  2863. rtos(color.r).pad_decimals(2),
  2864. rtos(color.g).pad_decimals(2),
  2865. rtos(color.b).pad_decimals(2)));
  2866. }
  2867. }
  2868. void EditorPropertyColor::setup(bool p_show_alpha) {
  2869. picker->set_edit_alpha(p_show_alpha);
  2870. }
  2871. EditorPropertyColor::EditorPropertyColor() {
  2872. picker = memnew(ColorPickerButton);
  2873. add_child(picker);
  2874. picker->set_flat(true);
  2875. picker->connect("color_changed", callable_mp(this, &EditorPropertyColor::_color_changed));
  2876. picker->connect("popup_closed", callable_mp(this, &EditorPropertyColor::_popup_closed));
  2877. picker->get_popup()->connect("about_to_popup", callable_mp(EditorNode::get_singleton(), &EditorNode::setup_color_picker).bind(picker->get_picker()));
  2878. picker->get_popup()->connect("about_to_popup", callable_mp(this, &EditorPropertyColor::_picker_opening));
  2879. }
  2880. ////////////// NODE PATH //////////////////////
  2881. void EditorPropertyNodePath::_set_read_only(bool p_read_only) {
  2882. assign->set_disabled(p_read_only);
  2883. clear->set_disabled(p_read_only);
  2884. };
  2885. String EditorPropertyNodePath::_get_meta_pointer_property() const {
  2886. ERR_FAIL_COND_V(!pointer_mode, String());
  2887. return SceneState::get_meta_pointer_property(get_edited_property());
  2888. }
  2889. Variant EditorPropertyNodePath::_get_cache_value(const StringName &p_prop, bool &r_valid) const {
  2890. if (p_prop == get_edited_property()) {
  2891. r_valid = true;
  2892. return const_cast<EditorPropertyNodePath *>(this)->get_edited_object()->get(pointer_mode ? StringName(_get_meta_pointer_property()) : get_edited_property(), &r_valid);
  2893. }
  2894. return Variant();
  2895. }
  2896. StringName EditorPropertyNodePath::_get_revert_property() const {
  2897. if (pointer_mode) {
  2898. return _get_meta_pointer_property();
  2899. } else {
  2900. return get_edited_property();
  2901. }
  2902. }
  2903. void EditorPropertyNodePath::_node_selected(const NodePath &p_path) {
  2904. NodePath path = p_path;
  2905. Node *base_node = nullptr;
  2906. if (!use_path_from_scene_root) {
  2907. base_node = Object::cast_to<Node>(get_edited_object());
  2908. if (!base_node) {
  2909. //try a base node within history
  2910. if (EditorNode::get_singleton()->get_editor_selection_history()->get_path_size() > 0) {
  2911. Object *base = ObjectDB::get_instance(EditorNode::get_singleton()->get_editor_selection_history()->get_path_object(0));
  2912. if (base) {
  2913. base_node = Object::cast_to<Node>(base);
  2914. }
  2915. }
  2916. }
  2917. }
  2918. if (!base_node && get_edited_object()->has_method("get_root_path")) {
  2919. base_node = Object::cast_to<Node>(get_edited_object()->call("get_root_path"));
  2920. }
  2921. if (!base_node && Object::cast_to<RefCounted>(get_edited_object())) {
  2922. Node *to_node = get_node(p_path);
  2923. ERR_FAIL_COND(!to_node);
  2924. path = get_tree()->get_edited_scene_root()->get_path_to(to_node);
  2925. }
  2926. if (base_node) { // for AnimationTrackKeyEdit
  2927. path = base_node->get_path().rel_path_to(p_path);
  2928. }
  2929. if (pointer_mode && base_node) {
  2930. emit_changed(_get_meta_pointer_property(), path);
  2931. } else {
  2932. emit_changed(get_edited_property(), path);
  2933. }
  2934. update_property();
  2935. }
  2936. void EditorPropertyNodePath::_node_assign() {
  2937. if (!scene_tree) {
  2938. scene_tree = memnew(SceneTreeDialog);
  2939. scene_tree->get_scene_tree()->set_show_enabled_subscene(true);
  2940. scene_tree->get_scene_tree()->set_valid_types(valid_types);
  2941. add_child(scene_tree);
  2942. scene_tree->connect("selected", callable_mp(this, &EditorPropertyNodePath::_node_selected));
  2943. }
  2944. scene_tree->popup_scenetree_dialog();
  2945. }
  2946. void EditorPropertyNodePath::_node_clear() {
  2947. if (pointer_mode) {
  2948. emit_changed(_get_meta_pointer_property(), NodePath());
  2949. } else {
  2950. emit_changed(get_edited_property(), NodePath());
  2951. }
  2952. update_property();
  2953. }
  2954. bool EditorPropertyNodePath::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
  2955. return !is_read_only() && is_drop_valid(p_data);
  2956. }
  2957. void EditorPropertyNodePath::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
  2958. ERR_FAIL_COND(!is_drop_valid(p_data));
  2959. Dictionary data = p_data;
  2960. Array nodes = data["nodes"];
  2961. Node *node = get_tree()->get_edited_scene_root()->get_node(nodes[0]);
  2962. if (node) {
  2963. _node_selected(node->get_path());
  2964. }
  2965. }
  2966. bool EditorPropertyNodePath::is_drop_valid(const Dictionary &p_drag_data) const {
  2967. if (p_drag_data["type"] != "nodes") {
  2968. return false;
  2969. }
  2970. Array nodes = p_drag_data["nodes"];
  2971. if (nodes.size() != 1) {
  2972. return false;
  2973. }
  2974. Node *dropped_node = get_tree()->get_edited_scene_root()->get_node(nodes[0]);
  2975. ERR_FAIL_NULL_V(dropped_node, false);
  2976. if (valid_types.is_empty()) {
  2977. // No type requirements specified so any type is valid.
  2978. return true;
  2979. }
  2980. for (const StringName &E : valid_types) {
  2981. if (dropped_node->is_class(E)) {
  2982. return true;
  2983. }
  2984. }
  2985. return false;
  2986. }
  2987. void EditorPropertyNodePath::update_property() {
  2988. NodePath p;
  2989. if (pointer_mode) {
  2990. p = get_edited_object()->get(_get_meta_pointer_property());
  2991. } else {
  2992. p = get_edited_object()->get(get_edited_property());
  2993. }
  2994. assign->set_tooltip(p);
  2995. if (p == NodePath()) {
  2996. assign->set_icon(Ref<Texture2D>());
  2997. assign->set_text(TTR("Assign..."));
  2998. assign->set_flat(false);
  2999. return;
  3000. }
  3001. assign->set_flat(true);
  3002. Node *base_node = nullptr;
  3003. if (base_hint != NodePath()) {
  3004. if (get_tree()->get_root()->has_node(base_hint)) {
  3005. base_node = get_tree()->get_root()->get_node(base_hint);
  3006. }
  3007. } else {
  3008. base_node = Object::cast_to<Node>(get_edited_object());
  3009. }
  3010. if (!base_node || !base_node->has_node(p)) {
  3011. assign->set_icon(Ref<Texture2D>());
  3012. assign->set_text(p);
  3013. return;
  3014. }
  3015. Node *target_node = base_node->get_node(p);
  3016. ERR_FAIL_COND(!target_node);
  3017. if (String(target_node->get_name()).contains("@")) {
  3018. assign->set_icon(Ref<Texture2D>());
  3019. assign->set_text(p);
  3020. return;
  3021. }
  3022. assign->set_text(target_node->get_name());
  3023. assign->set_icon(EditorNode::get_singleton()->get_object_icon(target_node, "Node"));
  3024. }
  3025. void EditorPropertyNodePath::setup(const NodePath &p_base_hint, Vector<StringName> p_valid_types, bool p_use_path_from_scene_root, bool p_pointer_mode) {
  3026. pointer_mode = p_pointer_mode;
  3027. base_hint = p_base_hint;
  3028. valid_types = p_valid_types;
  3029. use_path_from_scene_root = p_use_path_from_scene_root;
  3030. }
  3031. void EditorPropertyNodePath::_notification(int p_what) {
  3032. switch (p_what) {
  3033. case NOTIFICATION_ENTER_TREE:
  3034. case NOTIFICATION_THEME_CHANGED: {
  3035. Ref<Texture2D> t = get_theme_icon(SNAME("Clear"), SNAME("EditorIcons"));
  3036. clear->set_icon(t);
  3037. } break;
  3038. }
  3039. }
  3040. void EditorPropertyNodePath::_bind_methods() {
  3041. ClassDB::bind_method(D_METHOD("_can_drop_data_fw", "position", "data", "from"), &EditorPropertyNodePath::can_drop_data_fw);
  3042. ClassDB::bind_method(D_METHOD("_drop_data_fw", "position", "data", "from"), &EditorPropertyNodePath::drop_data_fw);
  3043. }
  3044. EditorPropertyNodePath::EditorPropertyNodePath() {
  3045. HBoxContainer *hbc = memnew(HBoxContainer);
  3046. hbc->add_theme_constant_override("separation", 0);
  3047. add_child(hbc);
  3048. assign = memnew(Button);
  3049. assign->set_flat(true);
  3050. assign->set_h_size_flags(SIZE_EXPAND_FILL);
  3051. assign->set_clip_text(true);
  3052. assign->connect("pressed", callable_mp(this, &EditorPropertyNodePath::_node_assign));
  3053. assign->set_drag_forwarding(this);
  3054. hbc->add_child(assign);
  3055. clear = memnew(Button);
  3056. clear->set_flat(true);
  3057. clear->connect("pressed", callable_mp(this, &EditorPropertyNodePath::_node_clear));
  3058. hbc->add_child(clear);
  3059. scene_tree = nullptr; //do not allocate unnecessarily
  3060. }
  3061. ///////////////////// RID /////////////////////////
  3062. void EditorPropertyRID::update_property() {
  3063. RID rid = get_edited_object()->get(get_edited_property());
  3064. if (rid.is_valid()) {
  3065. uint64_t id = rid.get_id();
  3066. label->set_text("RID: " + uitos(id));
  3067. } else {
  3068. label->set_text(TTR("Invalid RID"));
  3069. }
  3070. }
  3071. EditorPropertyRID::EditorPropertyRID() {
  3072. label = memnew(Label);
  3073. add_child(label);
  3074. }
  3075. ////////////// RESOURCE //////////////////////
  3076. void EditorPropertyResource::_set_read_only(bool p_read_only) {
  3077. resource_picker->set_editable(!p_read_only);
  3078. };
  3079. void EditorPropertyResource::_resource_selected(const Ref<Resource> &p_resource, bool p_inspect) {
  3080. if (p_resource->is_built_in() && !p_resource->get_path().is_empty()) {
  3081. String parent = p_resource->get_path().get_slice("::", 0);
  3082. List<String> extensions;
  3083. ResourceLoader::get_recognized_extensions_for_type("PackedScene", &extensions);
  3084. if (p_inspect) {
  3085. if (extensions.find(parent.get_extension()) && (!EditorNode::get_singleton()->get_edited_scene() || EditorNode::get_singleton()->get_edited_scene()->get_scene_file_path() != parent)) {
  3086. // If the resource belongs to another (non-imported) scene, edit it in that scene instead.
  3087. if (!FileAccess::exists(parent + ".import")) {
  3088. EditorNode::get_singleton()->call_deferred("edit_foreign_resource", p_resource);
  3089. return;
  3090. }
  3091. }
  3092. }
  3093. }
  3094. if (!p_inspect && use_sub_inspector) {
  3095. bool unfold = !get_edited_object()->editor_is_section_unfolded(get_edited_property());
  3096. get_edited_object()->editor_set_section_unfold(get_edited_property(), unfold);
  3097. update_property();
  3098. } else {
  3099. emit_signal(SNAME("resource_selected"), get_edited_property(), p_resource);
  3100. }
  3101. }
  3102. void EditorPropertyResource::_resource_changed(const Ref<Resource> &p_resource) {
  3103. // Make visual script the correct type.
  3104. Ref<Script> s = p_resource;
  3105. bool is_script = false;
  3106. if (get_edited_object() && s.is_valid()) {
  3107. is_script = true;
  3108. InspectorDock::get_singleton()->store_script_properties(get_edited_object());
  3109. s->call("set_instance_base_type", get_edited_object()->get_class());
  3110. }
  3111. // Prevent the creation of invalid ViewportTextures when possible.
  3112. Ref<ViewportTexture> vpt = p_resource;
  3113. if (vpt.is_valid()) {
  3114. Resource *r = Object::cast_to<Resource>(get_edited_object());
  3115. if (r && r->get_path().is_resource_file()) {
  3116. EditorNode::get_singleton()->show_warning(TTR("Can't create a ViewportTexture on resources saved as a file.\nResource needs to belong to a scene."));
  3117. emit_changed(get_edited_property(), Ref<Resource>());
  3118. update_property();
  3119. return;
  3120. }
  3121. if (r && !r->is_local_to_scene()) {
  3122. EditorNode::get_singleton()->show_warning(TTR("Can't create a ViewportTexture on this resource because it's not set as local to scene.\nPlease switch on the 'local to scene' property on it (and all resources containing it up to a node)."));
  3123. emit_changed(get_edited_property(), Ref<Resource>());
  3124. update_property();
  3125. return;
  3126. }
  3127. }
  3128. emit_changed(get_edited_property(), p_resource);
  3129. update_property();
  3130. if (is_script) {
  3131. // Restore properties if script was changed.
  3132. InspectorDock::get_singleton()->apply_script_properties(get_edited_object());
  3133. }
  3134. // Automatically suggest setting up the path for a ViewportTexture.
  3135. if (vpt.is_valid() && vpt->get_viewport_path_in_scene().is_empty()) {
  3136. if (!scene_tree) {
  3137. scene_tree = memnew(SceneTreeDialog);
  3138. scene_tree->set_title(TTR("Pick a Viewport"));
  3139. Vector<StringName> valid_types;
  3140. valid_types.push_back("Viewport");
  3141. scene_tree->get_scene_tree()->set_valid_types(valid_types);
  3142. scene_tree->get_scene_tree()->set_show_enabled_subscene(true);
  3143. add_child(scene_tree);
  3144. scene_tree->connect("selected", callable_mp(this, &EditorPropertyResource::_viewport_selected));
  3145. }
  3146. scene_tree->popup_scenetree_dialog();
  3147. }
  3148. }
  3149. void EditorPropertyResource::_sub_inspector_property_keyed(const String &p_property, const Variant &p_value, bool p_advance) {
  3150. // The second parameter could be null, causing the event to fire with less arguments, so use the pointer call which preserves it.
  3151. const Variant args[3] = { String(get_edited_property()) + ":" + p_property, p_value, p_advance };
  3152. const Variant *argp[3] = { &args[0], &args[1], &args[2] };
  3153. emit_signalp(SNAME("property_keyed_with_value"), argp, 3);
  3154. }
  3155. void EditorPropertyResource::_sub_inspector_resource_selected(const Ref<Resource> &p_resource, const String &p_property) {
  3156. emit_signal(SNAME("resource_selected"), String(get_edited_property()) + ":" + p_property, p_resource);
  3157. }
  3158. void EditorPropertyResource::_sub_inspector_object_id_selected(int p_id) {
  3159. emit_signal(SNAME("object_id_selected"), get_edited_property(), p_id);
  3160. }
  3161. void EditorPropertyResource::_open_editor_pressed() {
  3162. Ref<Resource> res = get_edited_object()->get(get_edited_property());
  3163. if (res.is_valid()) {
  3164. // May clear the editor so do it deferred.
  3165. EditorNode::get_singleton()->call_deferred(SNAME("edit_item_resource"), res);
  3166. }
  3167. }
  3168. void EditorPropertyResource::_fold_other_editors(Object *p_self) {
  3169. if (this == p_self) {
  3170. return;
  3171. }
  3172. Ref<Resource> res = get_edited_object()->get(get_edited_property());
  3173. if (!res.is_valid()) {
  3174. return;
  3175. }
  3176. bool use_editor = false;
  3177. for (int i = 0; i < EditorNode::get_editor_data().get_editor_plugin_count(); i++) {
  3178. EditorPlugin *ep = EditorNode::get_editor_data().get_editor_plugin(i);
  3179. if (ep->handles(res.ptr())) {
  3180. use_editor = true;
  3181. break;
  3182. }
  3183. }
  3184. if (!use_editor) {
  3185. return;
  3186. }
  3187. opened_editor = false;
  3188. bool unfolded = get_edited_object()->editor_is_section_unfolded(get_edited_property());
  3189. if (unfolded) {
  3190. // Refold.
  3191. resource_picker->set_toggle_pressed(false);
  3192. get_edited_object()->editor_set_section_unfold(get_edited_property(), false);
  3193. update_property();
  3194. }
  3195. }
  3196. void EditorPropertyResource::_update_property_bg() {
  3197. if (!is_inside_tree()) {
  3198. return;
  3199. }
  3200. updating_theme = true;
  3201. if (sub_inspector != nullptr) {
  3202. int count_subinspectors = 0;
  3203. Node *n = get_parent();
  3204. while (n) {
  3205. EditorInspector *ei = Object::cast_to<EditorInspector>(n);
  3206. if (ei && ei->is_sub_inspector()) {
  3207. count_subinspectors++;
  3208. }
  3209. n = n->get_parent();
  3210. }
  3211. count_subinspectors = MIN(15, count_subinspectors);
  3212. add_theme_color_override("property_color", get_theme_color(SNAME("sub_inspector_property_color"), SNAME("Editor")));
  3213. add_theme_style_override("bg_selected", get_theme_stylebox("sub_inspector_property_bg" + itos(count_subinspectors), SNAME("Editor")));
  3214. add_theme_style_override("bg", get_theme_stylebox("sub_inspector_property_bg" + itos(count_subinspectors), SNAME("Editor")));
  3215. add_theme_constant_override("v_separation", 0);
  3216. } else {
  3217. add_theme_color_override("property_color", get_theme_color(SNAME("property_color"), SNAME("EditorProperty")));
  3218. add_theme_style_override("bg_selected", get_theme_stylebox(SNAME("bg_selected"), SNAME("EditorProperty")));
  3219. add_theme_style_override("bg", get_theme_stylebox(SNAME("bg"), SNAME("EditorProperty")));
  3220. add_theme_constant_override("v_separation", get_theme_constant(SNAME("v_separation"), SNAME("EditorProperty")));
  3221. }
  3222. updating_theme = false;
  3223. update();
  3224. }
  3225. void EditorPropertyResource::_update_preferred_shader() {
  3226. Node *parent = get_parent();
  3227. EditorProperty *parent_property = nullptr;
  3228. while (parent && !parent_property) {
  3229. parent_property = Object::cast_to<EditorProperty>(parent);
  3230. parent = parent->get_parent();
  3231. }
  3232. if (parent_property) {
  3233. EditorShaderPicker *shader_picker = Object::cast_to<EditorShaderPicker>(resource_picker);
  3234. Object *object = parent_property->get_edited_object();
  3235. const StringName &property = parent_property->get_edited_property();
  3236. // Set preferred shader based on edited parent type.
  3237. if ((Object::cast_to<GPUParticles2D>(object) || Object::cast_to<GPUParticles3D>(object)) && property == SNAME("process_material")) {
  3238. shader_picker->set_preferred_mode(Shader::MODE_PARTICLES);
  3239. } else if (Object::cast_to<FogVolume>(object)) {
  3240. shader_picker->set_preferred_mode(Shader::MODE_FOG);
  3241. } else if (Object::cast_to<CanvasItem>(object)) {
  3242. shader_picker->set_preferred_mode(Shader::MODE_CANVAS_ITEM);
  3243. } else if (Object::cast_to<Node3D>(object) || Object::cast_to<Mesh>(object)) {
  3244. shader_picker->set_preferred_mode(Shader::MODE_SPATIAL);
  3245. } else if (Object::cast_to<Sky>(object)) {
  3246. shader_picker->set_preferred_mode(Shader::MODE_SKY);
  3247. }
  3248. }
  3249. }
  3250. void EditorPropertyResource::_viewport_selected(const NodePath &p_path) {
  3251. Node *to_node = get_node(p_path);
  3252. if (!Object::cast_to<Viewport>(to_node)) {
  3253. EditorNode::get_singleton()->show_warning(TTR("Selected node is not a Viewport!"));
  3254. return;
  3255. }
  3256. Ref<ViewportTexture> vt;
  3257. vt.instantiate();
  3258. vt->set_viewport_path_in_scene(get_tree()->get_edited_scene_root()->get_path_to(to_node));
  3259. vt->setup_local_to_scene();
  3260. emit_changed(get_edited_property(), vt);
  3261. update_property();
  3262. }
  3263. void EditorPropertyResource::setup(Object *p_object, const String &p_path, const String &p_base_type) {
  3264. if (resource_picker) {
  3265. memdelete(resource_picker);
  3266. resource_picker = nullptr;
  3267. }
  3268. if (p_path == "script" && p_base_type == "Script" && Object::cast_to<Node>(p_object)) {
  3269. EditorScriptPicker *script_picker = memnew(EditorScriptPicker);
  3270. script_picker->set_script_owner(Object::cast_to<Node>(p_object));
  3271. resource_picker = script_picker;
  3272. } else if (p_path == "shader" && p_base_type == "Shader" && Object::cast_to<ShaderMaterial>(p_object)) {
  3273. EditorShaderPicker *shader_picker = memnew(EditorShaderPicker);
  3274. shader_picker->set_edited_material(Object::cast_to<ShaderMaterial>(p_object));
  3275. resource_picker = shader_picker;
  3276. connect(SNAME("ready"), callable_mp(this, &EditorPropertyResource::_update_preferred_shader));
  3277. } else if (p_base_type == "AudioStream") {
  3278. EditorAudioStreamPicker *astream_picker = memnew(EditorAudioStreamPicker);
  3279. resource_picker = astream_picker;
  3280. } else {
  3281. resource_picker = memnew(EditorResourcePicker);
  3282. }
  3283. resource_picker->set_base_type(p_base_type);
  3284. resource_picker->set_editable(true);
  3285. resource_picker->set_h_size_flags(SIZE_EXPAND_FILL);
  3286. add_child(resource_picker);
  3287. resource_picker->connect("resource_selected", callable_mp(this, &EditorPropertyResource::_resource_selected));
  3288. resource_picker->connect("resource_changed", callable_mp(this, &EditorPropertyResource::_resource_changed));
  3289. for (int i = 0; i < resource_picker->get_child_count(); i++) {
  3290. Button *b = Object::cast_to<Button>(resource_picker->get_child(i));
  3291. if (b) {
  3292. add_focusable(b);
  3293. }
  3294. }
  3295. }
  3296. void EditorPropertyResource::update_property() {
  3297. Ref<Resource> res = get_edited_object()->get(get_edited_property());
  3298. if (use_sub_inspector) {
  3299. if (res.is_valid() != resource_picker->is_toggle_mode()) {
  3300. resource_picker->set_toggle_mode(res.is_valid());
  3301. }
  3302. if (res.is_valid() && get_edited_object()->editor_is_section_unfolded(get_edited_property())) {
  3303. if (!sub_inspector) {
  3304. sub_inspector = memnew(EditorInspector);
  3305. sub_inspector->set_vertical_scroll_mode(ScrollContainer::SCROLL_MODE_DISABLED);
  3306. sub_inspector->set_use_doc_hints(true);
  3307. sub_inspector->set_sub_inspector(true);
  3308. sub_inspector->set_property_name_style(InspectorDock::get_singleton()->get_property_name_style());
  3309. sub_inspector->connect("property_keyed", callable_mp(this, &EditorPropertyResource::_sub_inspector_property_keyed));
  3310. sub_inspector->connect("resource_selected", callable_mp(this, &EditorPropertyResource::_sub_inspector_resource_selected));
  3311. sub_inspector->connect("object_id_selected", callable_mp(this, &EditorPropertyResource::_sub_inspector_object_id_selected));
  3312. sub_inspector->set_keying(is_keying());
  3313. sub_inspector->set_read_only(is_read_only());
  3314. sub_inspector->set_use_folding(is_using_folding());
  3315. sub_inspector->set_undo_redo(EditorNode::get_undo_redo());
  3316. sub_inspector_vbox = memnew(VBoxContainer);
  3317. add_child(sub_inspector_vbox);
  3318. set_bottom_editor(sub_inspector_vbox);
  3319. sub_inspector_vbox->add_child(sub_inspector);
  3320. resource_picker->set_toggle_pressed(true);
  3321. bool use_editor = false;
  3322. for (int i = 0; i < EditorNode::get_editor_data().get_editor_plugin_count(); i++) {
  3323. EditorPlugin *ep = EditorNode::get_editor_data().get_editor_plugin(i);
  3324. if (ep->handles(res.ptr())) {
  3325. use_editor = true;
  3326. }
  3327. }
  3328. if (use_editor) {
  3329. // Open editor directly and hide other such editors which are currently open.
  3330. _open_editor_pressed();
  3331. if (is_inside_tree()) {
  3332. get_tree()->call_deferred(SNAME("call_group"), "_editor_resource_properties", "_fold_other_editors", this);
  3333. }
  3334. opened_editor = true;
  3335. }
  3336. _update_property_bg();
  3337. }
  3338. if (res.ptr() != sub_inspector->get_edited_object()) {
  3339. sub_inspector->edit(res.ptr());
  3340. }
  3341. } else {
  3342. if (sub_inspector) {
  3343. set_bottom_editor(nullptr);
  3344. memdelete(sub_inspector_vbox);
  3345. sub_inspector = nullptr;
  3346. sub_inspector_vbox = nullptr;
  3347. if (opened_editor) {
  3348. EditorNode::get_singleton()->hide_top_editors();
  3349. opened_editor = false;
  3350. }
  3351. _update_property_bg();
  3352. }
  3353. }
  3354. }
  3355. resource_picker->set_edited_resource(res);
  3356. }
  3357. void EditorPropertyResource::collapse_all_folding() {
  3358. if (sub_inspector) {
  3359. sub_inspector->collapse_all_folding();
  3360. }
  3361. }
  3362. void EditorPropertyResource::expand_all_folding() {
  3363. if (sub_inspector) {
  3364. sub_inspector->expand_all_folding();
  3365. }
  3366. }
  3367. void EditorPropertyResource::expand_revertable() {
  3368. if (sub_inspector) {
  3369. sub_inspector->expand_revertable();
  3370. }
  3371. }
  3372. void EditorPropertyResource::set_use_sub_inspector(bool p_enable) {
  3373. use_sub_inspector = p_enable;
  3374. }
  3375. void EditorPropertyResource::_notification(int p_what) {
  3376. switch (p_what) {
  3377. case NOTIFICATION_ENTER_TREE:
  3378. case NOTIFICATION_THEME_CHANGED: {
  3379. if (!updating_theme) {
  3380. _update_property_bg();
  3381. }
  3382. } break;
  3383. }
  3384. }
  3385. void EditorPropertyResource::_bind_methods() {
  3386. ClassDB::bind_method(D_METHOD("_open_editor_pressed"), &EditorPropertyResource::_open_editor_pressed);
  3387. ClassDB::bind_method(D_METHOD("_fold_other_editors"), &EditorPropertyResource::_fold_other_editors);
  3388. }
  3389. EditorPropertyResource::EditorPropertyResource() {
  3390. use_sub_inspector = bool(EDITOR_GET("interface/inspector/open_resources_in_current_inspector"));
  3391. add_to_group("_editor_resource_properties");
  3392. }
  3393. ////////////// DEFAULT PLUGIN //////////////////////
  3394. bool EditorInspectorDefaultPlugin::can_handle(Object *p_object) {
  3395. return true; // Can handle everything.
  3396. }
  3397. bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const uint32_t p_usage, const bool p_wide) {
  3398. Control *editor = EditorInspectorDefaultPlugin::get_editor_for_property(p_object, p_type, p_path, p_hint, p_hint_text, p_usage, p_wide);
  3399. if (editor) {
  3400. add_property_editor(p_path, editor);
  3401. }
  3402. return false;
  3403. }
  3404. struct EditorPropertyRangeHint {
  3405. bool greater = true;
  3406. bool lesser = true;
  3407. double min = -99999.0;
  3408. double max = 99999.0;
  3409. double step = 1.0;
  3410. String suffix;
  3411. bool exp_range = false;
  3412. bool hide_slider = true;
  3413. bool radians = false;
  3414. };
  3415. static EditorPropertyRangeHint _parse_range_hint(PropertyHint p_hint, const String &p_hint_text, double p_default_step) {
  3416. EditorPropertyRangeHint hint;
  3417. hint.step = p_default_step;
  3418. Vector<String> slices = p_hint_text.split(",");
  3419. if (p_hint == PROPERTY_HINT_RANGE) {
  3420. ERR_FAIL_COND_V_MSG(slices.size() < 2, hint,
  3421. vformat("Invalid PROPERTY_HINT_RANGE with hint \"%s\": Missing required min and/or max values.", p_hint_text));
  3422. hint.greater = false; // If using ranged, assume false by default.
  3423. hint.lesser = false;
  3424. hint.min = slices[0].to_float();
  3425. hint.max = slices[1].to_float();
  3426. if (slices.size() >= 3 && slices[2].is_valid_float()) {
  3427. // Step is optional, could be something else if not a number.
  3428. hint.step = slices[2].to_float();
  3429. }
  3430. hint.hide_slider = false;
  3431. for (int i = 2; i < slices.size(); i++) {
  3432. String slice = slices[i].strip_edges();
  3433. if (slice == "or_greater") {
  3434. hint.greater = true;
  3435. } else if (slice == "or_lesser") {
  3436. hint.lesser = true;
  3437. } else if (slice == "no_slider") {
  3438. hint.hide_slider = true;
  3439. } else if (slice == "exp") {
  3440. hint.exp_range = true;
  3441. }
  3442. }
  3443. }
  3444. bool degrees = false;
  3445. for (int i = 0; i < slices.size(); i++) {
  3446. String slice = slices[i].strip_edges();
  3447. if (slice == "radians") {
  3448. hint.radians = true;
  3449. } else if (slice == "degrees") {
  3450. degrees = true;
  3451. } else if (slice.begins_with("suffix:")) {
  3452. hint.suffix = " " + slice.replace_first("suffix:", "").strip_edges();
  3453. }
  3454. }
  3455. if ((hint.radians || degrees) && hint.suffix.is_empty()) {
  3456. hint.suffix = U"\u00B0";
  3457. }
  3458. ERR_FAIL_COND_V_MSG(hint.step == 0, hint,
  3459. vformat("Invalid PROPERTY_HINT_RANGE with hint \"%s\": Step cannot be 0.", p_hint_text));
  3460. return hint;
  3461. }
  3462. EditorProperty *EditorInspectorDefaultPlugin::get_editor_for_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const uint32_t p_usage, const bool p_wide) {
  3463. double default_float_step = EDITOR_GET("interface/inspector/default_float_step");
  3464. switch (p_type) {
  3465. // atomic types
  3466. case Variant::NIL: {
  3467. EditorPropertyNil *editor = memnew(EditorPropertyNil);
  3468. return editor;
  3469. } break;
  3470. case Variant::BOOL: {
  3471. EditorPropertyCheck *editor = memnew(EditorPropertyCheck);
  3472. return editor;
  3473. } break;
  3474. case Variant::INT: {
  3475. if (p_hint == PROPERTY_HINT_ENUM) {
  3476. EditorPropertyEnum *editor = memnew(EditorPropertyEnum);
  3477. Vector<String> options = p_hint_text.split(",");
  3478. editor->setup(options);
  3479. return editor;
  3480. } else if (p_hint == PROPERTY_HINT_FLAGS) {
  3481. EditorPropertyFlags *editor = memnew(EditorPropertyFlags);
  3482. Vector<String> options = p_hint_text.split(",");
  3483. editor->setup(options);
  3484. return editor;
  3485. } else if (p_hint == PROPERTY_HINT_LAYERS_2D_PHYSICS ||
  3486. p_hint == PROPERTY_HINT_LAYERS_2D_RENDER ||
  3487. p_hint == PROPERTY_HINT_LAYERS_2D_NAVIGATION ||
  3488. p_hint == PROPERTY_HINT_LAYERS_3D_PHYSICS ||
  3489. p_hint == PROPERTY_HINT_LAYERS_3D_RENDER ||
  3490. p_hint == PROPERTY_HINT_LAYERS_3D_NAVIGATION) {
  3491. EditorPropertyLayers::LayerType lt = EditorPropertyLayers::LAYER_RENDER_2D;
  3492. switch (p_hint) {
  3493. case PROPERTY_HINT_LAYERS_2D_RENDER:
  3494. lt = EditorPropertyLayers::LAYER_RENDER_2D;
  3495. break;
  3496. case PROPERTY_HINT_LAYERS_2D_PHYSICS:
  3497. lt = EditorPropertyLayers::LAYER_PHYSICS_2D;
  3498. break;
  3499. case PROPERTY_HINT_LAYERS_2D_NAVIGATION:
  3500. lt = EditorPropertyLayers::LAYER_NAVIGATION_2D;
  3501. break;
  3502. case PROPERTY_HINT_LAYERS_3D_RENDER:
  3503. lt = EditorPropertyLayers::LAYER_RENDER_3D;
  3504. break;
  3505. case PROPERTY_HINT_LAYERS_3D_PHYSICS:
  3506. lt = EditorPropertyLayers::LAYER_PHYSICS_3D;
  3507. break;
  3508. case PROPERTY_HINT_LAYERS_3D_NAVIGATION:
  3509. lt = EditorPropertyLayers::LAYER_NAVIGATION_3D;
  3510. break;
  3511. default: {
  3512. } //compiler could be smarter here and realize this can't happen
  3513. }
  3514. EditorPropertyLayers *editor = memnew(EditorPropertyLayers);
  3515. editor->setup(lt);
  3516. return editor;
  3517. } else if (p_hint == PROPERTY_HINT_OBJECT_ID) {
  3518. EditorPropertyObjectID *editor = memnew(EditorPropertyObjectID);
  3519. editor->setup(p_hint_text);
  3520. return editor;
  3521. } else {
  3522. EditorPropertyInteger *editor = memnew(EditorPropertyInteger);
  3523. EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, 1);
  3524. editor->setup(hint.min, hint.max, hint.step, hint.greater, hint.lesser, hint.suffix);
  3525. return editor;
  3526. }
  3527. } break;
  3528. case Variant::FLOAT: {
  3529. if (p_hint == PROPERTY_HINT_EXP_EASING) {
  3530. EditorPropertyEasing *editor = memnew(EditorPropertyEasing);
  3531. bool positive_only = false;
  3532. bool flip = false;
  3533. const Vector<String> hints = p_hint_text.split(",");
  3534. for (int i = 0; i < hints.size(); i++) {
  3535. const String hint = hints[i].strip_edges();
  3536. if (hint == "attenuation") {
  3537. flip = true;
  3538. }
  3539. if (hint == "positive_only") {
  3540. positive_only = true;
  3541. }
  3542. }
  3543. editor->setup(positive_only, flip);
  3544. return editor;
  3545. } else {
  3546. EditorPropertyFloat *editor = memnew(EditorPropertyFloat);
  3547. EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, default_float_step);
  3548. editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, hint.exp_range, hint.greater, hint.lesser, hint.suffix, hint.radians);
  3549. return editor;
  3550. }
  3551. } break;
  3552. case Variant::STRING: {
  3553. if (p_hint == PROPERTY_HINT_ENUM || p_hint == PROPERTY_HINT_ENUM_SUGGESTION) {
  3554. EditorPropertyTextEnum *editor = memnew(EditorPropertyTextEnum);
  3555. Vector<String> options = p_hint_text.split(",", false);
  3556. editor->setup(options, false, (p_hint == PROPERTY_HINT_ENUM_SUGGESTION));
  3557. return editor;
  3558. } else if (p_hint == PROPERTY_HINT_MULTILINE_TEXT) {
  3559. EditorPropertyMultilineText *editor = memnew(EditorPropertyMultilineText);
  3560. return editor;
  3561. } else if (p_hint == PROPERTY_HINT_EXPRESSION) {
  3562. EditorPropertyMultilineText *editor = memnew(EditorPropertyMultilineText(true));
  3563. return editor;
  3564. } else if (p_hint == PROPERTY_HINT_TYPE_STRING) {
  3565. EditorPropertyClassName *editor = memnew(EditorPropertyClassName);
  3566. editor->setup("Object", p_hint_text);
  3567. return editor;
  3568. } else if (p_hint == PROPERTY_HINT_LOCALE_ID) {
  3569. EditorPropertyLocale *editor = memnew(EditorPropertyLocale);
  3570. editor->setup(p_hint_text);
  3571. return editor;
  3572. } else if (p_hint == PROPERTY_HINT_DIR || p_hint == PROPERTY_HINT_FILE || p_hint == PROPERTY_HINT_SAVE_FILE || p_hint == PROPERTY_HINT_GLOBAL_SAVE_FILE || p_hint == PROPERTY_HINT_GLOBAL_DIR || p_hint == PROPERTY_HINT_GLOBAL_FILE) {
  3573. Vector<String> extensions = p_hint_text.split(",");
  3574. bool global = p_hint == PROPERTY_HINT_GLOBAL_DIR || p_hint == PROPERTY_HINT_GLOBAL_FILE || p_hint == PROPERTY_HINT_GLOBAL_SAVE_FILE;
  3575. bool folder = p_hint == PROPERTY_HINT_DIR || p_hint == PROPERTY_HINT_GLOBAL_DIR;
  3576. bool save = p_hint == PROPERTY_HINT_SAVE_FILE || p_hint == PROPERTY_HINT_GLOBAL_SAVE_FILE;
  3577. EditorPropertyPath *editor = memnew(EditorPropertyPath);
  3578. editor->setup(extensions, folder, global);
  3579. if (save) {
  3580. editor->set_save_mode();
  3581. }
  3582. return editor;
  3583. } else if (p_hint == PROPERTY_HINT_METHOD_OF_VARIANT_TYPE ||
  3584. p_hint == PROPERTY_HINT_METHOD_OF_BASE_TYPE ||
  3585. p_hint == PROPERTY_HINT_METHOD_OF_INSTANCE ||
  3586. p_hint == PROPERTY_HINT_METHOD_OF_SCRIPT ||
  3587. p_hint == PROPERTY_HINT_PROPERTY_OF_VARIANT_TYPE ||
  3588. p_hint == PROPERTY_HINT_PROPERTY_OF_BASE_TYPE ||
  3589. p_hint == PROPERTY_HINT_PROPERTY_OF_INSTANCE ||
  3590. p_hint == PROPERTY_HINT_PROPERTY_OF_SCRIPT) {
  3591. EditorPropertyMember *editor = memnew(EditorPropertyMember);
  3592. EditorPropertyMember::Type type = EditorPropertyMember::MEMBER_METHOD_OF_BASE_TYPE;
  3593. switch (p_hint) {
  3594. case PROPERTY_HINT_METHOD_OF_BASE_TYPE:
  3595. type = EditorPropertyMember::MEMBER_METHOD_OF_BASE_TYPE;
  3596. break;
  3597. case PROPERTY_HINT_METHOD_OF_INSTANCE:
  3598. type = EditorPropertyMember::MEMBER_METHOD_OF_INSTANCE;
  3599. break;
  3600. case PROPERTY_HINT_METHOD_OF_SCRIPT:
  3601. type = EditorPropertyMember::MEMBER_METHOD_OF_SCRIPT;
  3602. break;
  3603. case PROPERTY_HINT_PROPERTY_OF_VARIANT_TYPE:
  3604. type = EditorPropertyMember::MEMBER_PROPERTY_OF_VARIANT_TYPE;
  3605. break;
  3606. case PROPERTY_HINT_PROPERTY_OF_BASE_TYPE:
  3607. type = EditorPropertyMember::MEMBER_PROPERTY_OF_BASE_TYPE;
  3608. break;
  3609. case PROPERTY_HINT_PROPERTY_OF_INSTANCE:
  3610. type = EditorPropertyMember::MEMBER_PROPERTY_OF_INSTANCE;
  3611. break;
  3612. case PROPERTY_HINT_PROPERTY_OF_SCRIPT:
  3613. type = EditorPropertyMember::MEMBER_PROPERTY_OF_SCRIPT;
  3614. break;
  3615. default: {
  3616. }
  3617. }
  3618. editor->setup(type, p_hint_text);
  3619. return editor;
  3620. } else {
  3621. EditorPropertyText *editor = memnew(EditorPropertyText);
  3622. if (p_hint == PROPERTY_HINT_PLACEHOLDER_TEXT) {
  3623. editor->set_placeholder(p_hint_text);
  3624. }
  3625. return editor;
  3626. }
  3627. } break;
  3628. // math types
  3629. case Variant::VECTOR2: {
  3630. EditorPropertyVector2 *editor = memnew(EditorPropertyVector2(p_wide));
  3631. EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, default_float_step);
  3632. editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, p_hint == PROPERTY_HINT_LINK, hint.suffix);
  3633. return editor;
  3634. } break;
  3635. case Variant::VECTOR2I: {
  3636. EditorPropertyVector2i *editor = memnew(EditorPropertyVector2i(p_wide));
  3637. EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, 1);
  3638. editor->setup(hint.min, hint.max, hint.hide_slider, p_hint == PROPERTY_HINT_LINK, hint.suffix);
  3639. return editor;
  3640. } break;
  3641. case Variant::RECT2: {
  3642. EditorPropertyRect2 *editor = memnew(EditorPropertyRect2(p_wide));
  3643. EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, default_float_step);
  3644. editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, hint.suffix);
  3645. return editor;
  3646. } break;
  3647. case Variant::RECT2I: {
  3648. EditorPropertyRect2i *editor = memnew(EditorPropertyRect2i(p_wide));
  3649. EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, 1);
  3650. editor->setup(hint.min, hint.max, hint.hide_slider, hint.suffix);
  3651. return editor;
  3652. } break;
  3653. case Variant::VECTOR3: {
  3654. EditorPropertyVector3 *editor = memnew(EditorPropertyVector3(p_wide));
  3655. EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, default_float_step);
  3656. editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, p_hint == PROPERTY_HINT_LINK, hint.suffix, hint.radians);
  3657. return editor;
  3658. } break;
  3659. case Variant::VECTOR3I: {
  3660. EditorPropertyVector3i *editor = memnew(EditorPropertyVector3i(p_wide));
  3661. EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, 1);
  3662. editor->setup(hint.min, hint.max, hint.hide_slider, p_hint == PROPERTY_HINT_LINK, hint.suffix);
  3663. return editor;
  3664. } break;
  3665. case Variant::VECTOR4: {
  3666. EditorPropertyVector4 *editor = memnew(EditorPropertyVector4);
  3667. EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, default_float_step);
  3668. editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, hint.suffix);
  3669. return editor;
  3670. } break;
  3671. case Variant::VECTOR4I: {
  3672. EditorPropertyVector4i *editor = memnew(EditorPropertyVector4i);
  3673. EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, 1);
  3674. editor->setup(hint.min, hint.max, hint.hide_slider, hint.suffix);
  3675. return editor;
  3676. } break;
  3677. case Variant::TRANSFORM2D: {
  3678. EditorPropertyTransform2D *editor = memnew(EditorPropertyTransform2D);
  3679. EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, default_float_step);
  3680. editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, hint.suffix);
  3681. return editor;
  3682. } break;
  3683. case Variant::PLANE: {
  3684. EditorPropertyPlane *editor = memnew(EditorPropertyPlane(p_wide));
  3685. EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, default_float_step);
  3686. editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, hint.suffix);
  3687. return editor;
  3688. } break;
  3689. case Variant::QUATERNION: {
  3690. EditorPropertyQuaternion *editor = memnew(EditorPropertyQuaternion);
  3691. EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, default_float_step);
  3692. editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, hint.suffix);
  3693. return editor;
  3694. } break;
  3695. case Variant::AABB: {
  3696. EditorPropertyAABB *editor = memnew(EditorPropertyAABB);
  3697. EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, default_float_step);
  3698. editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, hint.suffix);
  3699. return editor;
  3700. } break;
  3701. case Variant::BASIS: {
  3702. EditorPropertyBasis *editor = memnew(EditorPropertyBasis);
  3703. EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, default_float_step);
  3704. editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, hint.suffix);
  3705. return editor;
  3706. } break;
  3707. case Variant::TRANSFORM3D: {
  3708. EditorPropertyTransform3D *editor = memnew(EditorPropertyTransform3D);
  3709. EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, default_float_step);
  3710. editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, hint.suffix);
  3711. return editor;
  3712. } break;
  3713. case Variant::PROJECTION: {
  3714. EditorPropertyProjection *editor = memnew(EditorPropertyProjection);
  3715. EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, default_float_step);
  3716. editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, hint.suffix);
  3717. return editor;
  3718. } break;
  3719. // misc types
  3720. case Variant::COLOR: {
  3721. EditorPropertyColor *editor = memnew(EditorPropertyColor);
  3722. editor->setup(p_hint != PROPERTY_HINT_COLOR_NO_ALPHA);
  3723. return editor;
  3724. } break;
  3725. case Variant::STRING_NAME: {
  3726. if (p_hint == PROPERTY_HINT_ENUM || p_hint == PROPERTY_HINT_ENUM_SUGGESTION) {
  3727. EditorPropertyTextEnum *editor = memnew(EditorPropertyTextEnum);
  3728. Vector<String> options = p_hint_text.split(",", false);
  3729. editor->setup(options, true, (p_hint == PROPERTY_HINT_ENUM_SUGGESTION));
  3730. return editor;
  3731. } else {
  3732. EditorPropertyText *editor = memnew(EditorPropertyText);
  3733. if (p_hint == PROPERTY_HINT_PLACEHOLDER_TEXT) {
  3734. editor->set_placeholder(p_hint_text);
  3735. }
  3736. editor->set_string_name(true);
  3737. return editor;
  3738. }
  3739. } break;
  3740. case Variant::NODE_PATH: {
  3741. EditorPropertyNodePath *editor = memnew(EditorPropertyNodePath);
  3742. if (p_hint == PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE && !p_hint_text.is_empty()) {
  3743. editor->setup(p_hint_text, Vector<StringName>(), (p_usage & PROPERTY_USAGE_NODE_PATH_FROM_SCENE_ROOT));
  3744. }
  3745. if (p_hint == PROPERTY_HINT_NODE_PATH_VALID_TYPES && !p_hint_text.is_empty()) {
  3746. Vector<String> types = p_hint_text.split(",", false);
  3747. Vector<StringName> sn = Variant(types); //convert via variant
  3748. editor->setup(NodePath(), sn, (p_usage & PROPERTY_USAGE_NODE_PATH_FROM_SCENE_ROOT));
  3749. }
  3750. return editor;
  3751. } break;
  3752. case Variant::RID: {
  3753. EditorPropertyRID *editor = memnew(EditorPropertyRID);
  3754. return editor;
  3755. } break;
  3756. case Variant::OBJECT: {
  3757. if (p_hint == PROPERTY_HINT_NODE_TYPE) {
  3758. EditorPropertyNodePath *editor = memnew(EditorPropertyNodePath);
  3759. Vector<String> types = p_hint_text.split(",", false);
  3760. Vector<StringName> sn = Variant(types); //convert via variant
  3761. editor->setup(NodePath(), sn, false, true);
  3762. return editor;
  3763. } else {
  3764. EditorPropertyResource *editor = memnew(EditorPropertyResource);
  3765. editor->setup(p_object, p_path, p_hint == PROPERTY_HINT_RESOURCE_TYPE ? p_hint_text : "Resource");
  3766. if (p_hint == PROPERTY_HINT_RESOURCE_TYPE) {
  3767. const PackedStringArray open_in_new_inspector = EDITOR_GET("interface/inspector/resources_to_open_in_new_inspector");
  3768. for (const String &type : open_in_new_inspector) {
  3769. for (int j = 0; j < p_hint_text.get_slice_count(","); j++) {
  3770. const String inherits = p_hint_text.get_slicec(',', j);
  3771. if (ClassDB::is_parent_class(inherits, type)) {
  3772. editor->set_use_sub_inspector(false);
  3773. }
  3774. }
  3775. }
  3776. }
  3777. return editor;
  3778. }
  3779. } break;
  3780. case Variant::CALLABLE: {
  3781. EditorPropertyCallable *editor = memnew(EditorPropertyCallable);
  3782. return editor;
  3783. } break;
  3784. case Variant::SIGNAL: {
  3785. EditorPropertySignal *editor = memnew(EditorPropertySignal);
  3786. return editor;
  3787. } break;
  3788. case Variant::DICTIONARY: {
  3789. if (p_hint == PROPERTY_HINT_LOCALIZABLE_STRING) {
  3790. EditorPropertyLocalizableString *editor = memnew(EditorPropertyLocalizableString);
  3791. return editor;
  3792. } else {
  3793. EditorPropertyDictionary *editor = memnew(EditorPropertyDictionary);
  3794. return editor;
  3795. }
  3796. } break;
  3797. case Variant::ARRAY: {
  3798. EditorPropertyArray *editor = memnew(EditorPropertyArray);
  3799. editor->setup(Variant::ARRAY, p_hint_text);
  3800. return editor;
  3801. } break;
  3802. case Variant::PACKED_BYTE_ARRAY: {
  3803. EditorPropertyArray *editor = memnew(EditorPropertyArray);
  3804. editor->setup(Variant::PACKED_BYTE_ARRAY);
  3805. return editor;
  3806. } break;
  3807. case Variant::PACKED_INT32_ARRAY: {
  3808. EditorPropertyArray *editor = memnew(EditorPropertyArray);
  3809. editor->setup(Variant::PACKED_INT32_ARRAY);
  3810. return editor;
  3811. } break;
  3812. case Variant::PACKED_INT64_ARRAY: {
  3813. EditorPropertyArray *editor = memnew(EditorPropertyArray);
  3814. editor->setup(Variant::PACKED_INT64_ARRAY);
  3815. return editor;
  3816. } break;
  3817. case Variant::PACKED_FLOAT32_ARRAY: {
  3818. EditorPropertyArray *editor = memnew(EditorPropertyArray);
  3819. editor->setup(Variant::PACKED_FLOAT32_ARRAY);
  3820. return editor;
  3821. } break;
  3822. case Variant::PACKED_FLOAT64_ARRAY: {
  3823. EditorPropertyArray *editor = memnew(EditorPropertyArray);
  3824. editor->setup(Variant::PACKED_FLOAT64_ARRAY);
  3825. return editor;
  3826. } break;
  3827. case Variant::PACKED_STRING_ARRAY: {
  3828. EditorPropertyArray *editor = memnew(EditorPropertyArray);
  3829. editor->setup(Variant::PACKED_STRING_ARRAY);
  3830. return editor;
  3831. } break;
  3832. case Variant::PACKED_VECTOR2_ARRAY: {
  3833. EditorPropertyArray *editor = memnew(EditorPropertyArray);
  3834. editor->setup(Variant::PACKED_VECTOR2_ARRAY);
  3835. return editor;
  3836. } break;
  3837. case Variant::PACKED_VECTOR3_ARRAY: {
  3838. EditorPropertyArray *editor = memnew(EditorPropertyArray);
  3839. editor->setup(Variant::PACKED_VECTOR3_ARRAY);
  3840. return editor;
  3841. } break;
  3842. case Variant::PACKED_COLOR_ARRAY: {
  3843. EditorPropertyArray *editor = memnew(EditorPropertyArray);
  3844. editor->setup(Variant::PACKED_COLOR_ARRAY);
  3845. return editor;
  3846. } break;
  3847. default: {
  3848. }
  3849. }
  3850. return nullptr;
  3851. }