editor_properties.cpp 103 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419
  1. /**************************************************************************/
  2. /* editor_properties.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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 "editor/editor_resource_preview.h"
  32. #include "editor/filesystem_dock.h"
  33. #include "editor/project_settings_editor.h"
  34. #include "editor_node.h"
  35. #include "editor_properties_array_dict.h"
  36. #include "editor_scale.h"
  37. #include "scene/main/viewport.h"
  38. ///////////////////// NULL /////////////////////////
  39. void EditorPropertyNil::update_property() {
  40. }
  41. EditorPropertyNil::EditorPropertyNil() {
  42. Label *label = memnew(Label);
  43. label->set_text("[null]");
  44. add_child(label);
  45. }
  46. ///////////////////// TEXT /////////////////////////
  47. void EditorPropertyText::_text_entered(const String &p_string) {
  48. if (updating) {
  49. return;
  50. }
  51. if (text->has_focus()) {
  52. text->release_focus();
  53. _text_changed(p_string);
  54. }
  55. }
  56. void EditorPropertyText::_text_changed(const String &p_string) {
  57. if (updating) {
  58. return;
  59. }
  60. emit_changed(get_edited_property(), p_string, "", true);
  61. }
  62. void EditorPropertyText::update_property() {
  63. String s = get_edited_object()->get(get_edited_property());
  64. updating = true;
  65. if (text->get_text() != s) {
  66. text->set_text(s);
  67. }
  68. text->set_editable(!is_read_only());
  69. updating = false;
  70. }
  71. void EditorPropertyText::set_placeholder(const String &p_string) {
  72. text->set_placeholder(p_string);
  73. }
  74. void EditorPropertyText::_bind_methods() {
  75. ClassDB::bind_method(D_METHOD("_text_changed", "txt"), &EditorPropertyText::_text_changed);
  76. ClassDB::bind_method(D_METHOD("_text_entered", "txt"), &EditorPropertyText::_text_entered);
  77. }
  78. EditorPropertyText::EditorPropertyText() {
  79. text = memnew(LineEdit);
  80. add_child(text);
  81. add_focusable(text);
  82. text->connect("text_changed", this, "_text_changed");
  83. text->connect("text_entered", this, "_text_entered");
  84. updating = false;
  85. }
  86. ///////////////////// MULTILINE TEXT /////////////////////////
  87. void EditorPropertyMultilineText::_big_text_changed() {
  88. text->set_text(big_text->get_text());
  89. emit_changed(get_edited_property(), big_text->get_text(), "", true);
  90. }
  91. void EditorPropertyMultilineText::_text_changed() {
  92. emit_changed(get_edited_property(), text->get_text(), "", true);
  93. }
  94. void EditorPropertyMultilineText::_open_big_text() {
  95. if (!big_text_dialog) {
  96. big_text = memnew(TextEdit);
  97. big_text->connect("text_changed", this, "_big_text_changed");
  98. big_text->set_wrap_enabled(true);
  99. big_text_dialog = memnew(AcceptDialog);
  100. big_text_dialog->add_child(big_text);
  101. big_text_dialog->set_title(TTR("Edit Text:"));
  102. add_child(big_text_dialog);
  103. }
  104. big_text_dialog->popup_centered_clamped(Size2(1000, 900) * EDSCALE, 0.8);
  105. big_text->set_text(text->get_text());
  106. big_text->grab_focus();
  107. }
  108. void EditorPropertyMultilineText::update_property() {
  109. String t = get_edited_object()->get(get_edited_property());
  110. if (text->get_text() != t) {
  111. text->set_text(t);
  112. if (big_text && big_text->is_visible_in_tree()) {
  113. big_text->set_text(t);
  114. }
  115. }
  116. }
  117. void EditorPropertyMultilineText::_notification(int p_what) {
  118. switch (p_what) {
  119. case NOTIFICATION_THEME_CHANGED:
  120. case NOTIFICATION_ENTER_TREE: {
  121. Ref<Texture> df = get_icon("DistractionFree", "EditorIcons");
  122. open_big_text->set_icon(df);
  123. Ref<Font> font = get_font("font", "Label");
  124. text->set_custom_minimum_size(Vector2(0, font->get_height() * 6));
  125. } break;
  126. }
  127. }
  128. void EditorPropertyMultilineText::_bind_methods() {
  129. ClassDB::bind_method(D_METHOD("_text_changed"), &EditorPropertyMultilineText::_text_changed);
  130. ClassDB::bind_method(D_METHOD("_big_text_changed"), &EditorPropertyMultilineText::_big_text_changed);
  131. ClassDB::bind_method(D_METHOD("_open_big_text"), &EditorPropertyMultilineText::_open_big_text);
  132. }
  133. EditorPropertyMultilineText::EditorPropertyMultilineText() {
  134. HBoxContainer *hb = memnew(HBoxContainer);
  135. hb->add_constant_override("separation", 0);
  136. add_child(hb);
  137. set_bottom_editor(hb);
  138. text = memnew(TextEdit);
  139. text->connect("text_changed", this, "_text_changed");
  140. text->set_wrap_enabled(true);
  141. add_focusable(text);
  142. hb->add_child(text);
  143. text->set_h_size_flags(SIZE_EXPAND_FILL);
  144. open_big_text = memnew(ToolButton);
  145. open_big_text->connect("pressed", this, "_open_big_text");
  146. hb->add_child(open_big_text);
  147. big_text_dialog = nullptr;
  148. big_text = nullptr;
  149. }
  150. ///////////////////// TEXT ENUM /////////////////////////
  151. void EditorPropertyTextEnum::_emit_changed_value(String p_string) {
  152. emit_changed(get_edited_property(), p_string);
  153. }
  154. void EditorPropertyTextEnum::_option_selected(int p_which) {
  155. _emit_changed_value(option_button->get_item_text(p_which));
  156. }
  157. void EditorPropertyTextEnum::_edit_custom_value() {
  158. default_layout->hide();
  159. edit_custom_layout->show();
  160. custom_value_edit->grab_focus();
  161. }
  162. void EditorPropertyTextEnum::_custom_value_submitted(String p_value) {
  163. edit_custom_layout->hide();
  164. default_layout->show();
  165. _emit_changed_value(p_value.strip_edges());
  166. }
  167. void EditorPropertyTextEnum::_custom_value_accepted() {
  168. String new_value = custom_value_edit->get_text().strip_edges();
  169. _custom_value_submitted(new_value);
  170. }
  171. void EditorPropertyTextEnum::_custom_value_cancelled() {
  172. custom_value_edit->set_text(get_edited_object()->get(get_edited_property()));
  173. edit_custom_layout->hide();
  174. default_layout->show();
  175. }
  176. void EditorPropertyTextEnum::update_property() {
  177. String current_value = get_edited_object()->get(get_edited_property());
  178. int default_option = options.find(current_value);
  179. // The list can change in the loose mode.
  180. if (loose_mode) {
  181. custom_value_edit->set_text(current_value);
  182. option_button->clear();
  183. // Manually entered value.
  184. if (default_option < 0 && !current_value.empty()) {
  185. option_button->add_item(current_value, options.size() + 1001);
  186. option_button->select(0);
  187. option_button->add_separator();
  188. }
  189. // Add an explicit empty value for clearing the property.
  190. option_button->add_item("", options.size() + 1000);
  191. for (int i = 0; i < options.size(); i++) {
  192. option_button->add_item(options[i], i);
  193. if (options[i] == current_value) {
  194. option_button->select(option_button->get_item_count() - 1);
  195. }
  196. }
  197. } else {
  198. option_button->select(default_option);
  199. }
  200. }
  201. void EditorPropertyTextEnum::setup(const Vector<String> &p_options, bool p_loose_mode) {
  202. loose_mode = p_loose_mode;
  203. options.clear();
  204. if (loose_mode) {
  205. // Add an explicit empty value for clearing the property in the loose mode.
  206. option_button->add_item("", options.size() + 1000);
  207. }
  208. for (int i = 0; i < p_options.size(); i++) {
  209. options.push_back(p_options[i]);
  210. option_button->add_item(p_options[i], i);
  211. }
  212. if (loose_mode) {
  213. edit_button->show();
  214. }
  215. }
  216. void EditorPropertyTextEnum::_bind_methods() {
  217. ClassDB::bind_method(D_METHOD("_option_selected"), &EditorPropertyTextEnum::_option_selected);
  218. ClassDB::bind_method(D_METHOD("_edit_custom_value"), &EditorPropertyTextEnum::_edit_custom_value);
  219. ClassDB::bind_method(D_METHOD("_custom_value_submitted"), &EditorPropertyTextEnum::_custom_value_submitted);
  220. ClassDB::bind_method(D_METHOD("_custom_value_accepted"), &EditorPropertyTextEnum::_custom_value_accepted);
  221. ClassDB::bind_method(D_METHOD("_custom_value_cancelled"), &EditorPropertyTextEnum::_custom_value_cancelled);
  222. }
  223. void EditorPropertyTextEnum::_notification(int p_what) {
  224. switch (p_what) {
  225. case NOTIFICATION_ENTER_TREE:
  226. case NOTIFICATION_THEME_CHANGED:
  227. edit_button->set_icon(get_icon("Edit", "EditorIcons"));
  228. accept_button->set_icon(get_icon("ImportCheck", "EditorIcons"));
  229. cancel_button->set_icon(get_icon("ImportFail", "EditorIcons"));
  230. break;
  231. }
  232. }
  233. EditorPropertyTextEnum::EditorPropertyTextEnum() {
  234. default_layout = memnew(HBoxContainer);
  235. add_child(default_layout);
  236. edit_custom_layout = memnew(HBoxContainer);
  237. edit_custom_layout->hide();
  238. add_child(edit_custom_layout);
  239. option_button = memnew(OptionButton);
  240. option_button->set_h_size_flags(SIZE_EXPAND_FILL);
  241. option_button->set_clip_text(true);
  242. option_button->set_flat(true);
  243. default_layout->add_child(option_button);
  244. option_button->connect("item_selected", this, "_option_selected");
  245. edit_button = memnew(Button);
  246. edit_button->set_flat(true);
  247. edit_button->hide();
  248. default_layout->add_child(edit_button);
  249. edit_button->connect("pressed", this, "_edit_custom_value");
  250. custom_value_edit = memnew(LineEdit);
  251. custom_value_edit->set_h_size_flags(SIZE_EXPAND_FILL);
  252. edit_custom_layout->add_child(custom_value_edit);
  253. custom_value_edit->connect("text_entered", this, "_custom_value_submitted");
  254. accept_button = memnew(Button);
  255. accept_button->set_flat(true);
  256. edit_custom_layout->add_child(accept_button);
  257. accept_button->connect("pressed", this, "_custom_value_accepted");
  258. cancel_button = memnew(Button);
  259. cancel_button->set_flat(true);
  260. edit_custom_layout->add_child(cancel_button);
  261. cancel_button->connect("pressed", this, "_custom_value_cancelled");
  262. add_focusable(option_button);
  263. add_focusable(edit_button);
  264. add_focusable(custom_value_edit);
  265. add_focusable(accept_button);
  266. add_focusable(cancel_button);
  267. }
  268. //////////////////// LOCALE ////////////////////////
  269. void EditorPropertyLocale::_locale_selected(const String &p_locale) {
  270. emit_changed(get_edited_property(), p_locale);
  271. update_property();
  272. }
  273. void EditorPropertyLocale::_locale_pressed() {
  274. if (!dialog) {
  275. dialog = memnew(EditorLocaleDialog);
  276. dialog->connect("locale_selected", this, "_locale_selected");
  277. add_child(dialog);
  278. }
  279. String locale_code = get_edited_object()->get(get_edited_property());
  280. dialog->set_locale(locale_code);
  281. dialog->popup_locale_dialog();
  282. }
  283. void EditorPropertyLocale::update_property() {
  284. String locale_code = get_edited_object()->get(get_edited_property());
  285. locale->set_text(locale_code);
  286. locale->set_tooltip(locale_code);
  287. }
  288. void EditorPropertyLocale::setup(const String &p_hint_text) {
  289. }
  290. void EditorPropertyLocale::_notification(int p_what) {
  291. if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
  292. locale_edit->set_icon(get_icon("Translation", "EditorIcons"));
  293. }
  294. }
  295. void EditorPropertyLocale::_locale_focus_exited() {
  296. _locale_selected(locale->get_text());
  297. }
  298. void EditorPropertyLocale::_bind_methods() {
  299. ClassDB::bind_method(D_METHOD("_locale_selected"), &EditorPropertyLocale::_locale_selected);
  300. ClassDB::bind_method(D_METHOD("_locale_pressed"), &EditorPropertyLocale::_locale_pressed);
  301. ClassDB::bind_method(D_METHOD("_locale_focus_exited"), &EditorPropertyLocale::_locale_focus_exited);
  302. }
  303. EditorPropertyLocale::EditorPropertyLocale() {
  304. HBoxContainer *locale_hb = memnew(HBoxContainer);
  305. add_child(locale_hb);
  306. locale = memnew(LineEdit);
  307. locale_hb->add_child(locale);
  308. locale->connect("text_entered", this, "_locale_selected");
  309. locale->connect("focus_exited", this, "_locale_focus_exited");
  310. locale->set_h_size_flags(SIZE_EXPAND_FILL);
  311. locale_edit = memnew(Button);
  312. locale_edit->set_clip_text(true);
  313. locale_hb->add_child(locale_edit);
  314. add_focusable(locale);
  315. dialog = nullptr;
  316. locale_edit->connect("pressed", this, "_locale_pressed");
  317. }
  318. ///////////////////// PATH /////////////////////////
  319. void EditorPropertyPath::_path_selected(const String &p_path) {
  320. emit_changed(get_edited_property(), p_path);
  321. update_property();
  322. }
  323. void EditorPropertyPath::_path_pressed() {
  324. if (!dialog) {
  325. dialog = memnew(EditorFileDialog);
  326. dialog->connect("file_selected", this, "_path_selected");
  327. dialog->connect("dir_selected", this, "_path_selected");
  328. add_child(dialog);
  329. }
  330. String full_path = get_edited_object()->get(get_edited_property());
  331. dialog->clear_filters();
  332. if (global) {
  333. dialog->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
  334. } else {
  335. dialog->set_access(EditorFileDialog::ACCESS_RESOURCES);
  336. }
  337. if (folder) {
  338. dialog->set_mode(EditorFileDialog::MODE_OPEN_DIR);
  339. dialog->set_current_dir(full_path);
  340. } else {
  341. dialog->set_mode(save_mode ? EditorFileDialog::MODE_SAVE_FILE : EditorFileDialog::MODE_OPEN_FILE);
  342. for (int i = 0; i < extensions.size(); i++) {
  343. String e = extensions[i].strip_edges();
  344. if (e != String()) {
  345. dialog->add_filter(extensions[i].strip_edges());
  346. }
  347. }
  348. dialog->set_current_path(full_path);
  349. }
  350. dialog->popup_centered_ratio();
  351. }
  352. void EditorPropertyPath::update_property() {
  353. String full_path = get_edited_object()->get(get_edited_property());
  354. path->set_text(full_path);
  355. path->set_tooltip(full_path);
  356. }
  357. void EditorPropertyPath::setup(const Vector<String> &p_extensions, bool p_folder, bool p_global) {
  358. extensions = p_extensions;
  359. folder = p_folder;
  360. global = p_global;
  361. }
  362. void EditorPropertyPath::set_save_mode() {
  363. save_mode = true;
  364. }
  365. void EditorPropertyPath::_notification(int p_what) {
  366. if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
  367. path_edit->set_icon(get_icon("Folder", "EditorIcons"));
  368. }
  369. }
  370. void EditorPropertyPath::_path_focus_exited() {
  371. _path_selected(path->get_text());
  372. }
  373. void EditorPropertyPath::_bind_methods() {
  374. ClassDB::bind_method(D_METHOD("_path_pressed"), &EditorPropertyPath::_path_pressed);
  375. ClassDB::bind_method(D_METHOD("_path_selected"), &EditorPropertyPath::_path_selected);
  376. ClassDB::bind_method(D_METHOD("_path_focus_exited"), &EditorPropertyPath::_path_focus_exited);
  377. }
  378. EditorPropertyPath::EditorPropertyPath() {
  379. HBoxContainer *path_hb = memnew(HBoxContainer);
  380. add_child(path_hb);
  381. path = memnew(LineEdit);
  382. path_hb->add_child(path);
  383. path->connect("text_entered", this, "_path_selected");
  384. path->connect("focus_exited", this, "_path_focus_exited");
  385. path->set_h_size_flags(SIZE_EXPAND_FILL);
  386. path_edit = memnew(Button);
  387. path_edit->set_clip_text(true);
  388. path_hb->add_child(path_edit);
  389. add_focusable(path);
  390. dialog = nullptr;
  391. path_edit->connect("pressed", this, "_path_pressed");
  392. folder = false;
  393. global = false;
  394. save_mode = false;
  395. }
  396. ///////////////////// CLASS NAME /////////////////////////
  397. void EditorPropertyClassName::setup(const String &p_base_type, const String &p_selected_type) {
  398. base_type = p_base_type;
  399. dialog->set_base_type(base_type);
  400. selected_type = p_selected_type;
  401. property->set_text(selected_type);
  402. }
  403. void EditorPropertyClassName::update_property() {
  404. String s = get_edited_object()->get(get_edited_property());
  405. property->set_text(s);
  406. selected_type = s;
  407. }
  408. void EditorPropertyClassName::_property_selected() {
  409. dialog->popup_create(true);
  410. }
  411. void EditorPropertyClassName::_dialog_created() {
  412. selected_type = dialog->get_selected_type();
  413. emit_changed(get_edited_property(), selected_type);
  414. update_property();
  415. }
  416. void EditorPropertyClassName::_bind_methods() {
  417. ClassDB::bind_method(D_METHOD("_dialog_created"), &EditorPropertyClassName::_dialog_created);
  418. ClassDB::bind_method(D_METHOD("_property_selected"), &EditorPropertyClassName::_property_selected);
  419. }
  420. EditorPropertyClassName::EditorPropertyClassName() {
  421. property = memnew(Button);
  422. property->set_clip_text(true);
  423. add_child(property);
  424. add_focusable(property);
  425. property->set_text(selected_type);
  426. property->connect("pressed", this, "_property_selected");
  427. dialog = memnew(CreateDialog);
  428. dialog->set_base_type(base_type);
  429. dialog->connect("create", this, "_dialog_created");
  430. add_child(dialog);
  431. }
  432. ///////////////////// MEMBER /////////////////////////
  433. void EditorPropertyMember::_property_selected(const String &p_selected) {
  434. emit_changed(get_edited_property(), p_selected);
  435. update_property();
  436. }
  437. void EditorPropertyMember::_property_select() {
  438. if (!selector) {
  439. selector = memnew(PropertySelector);
  440. selector->connect("selected", this, "_property_selected");
  441. add_child(selector);
  442. }
  443. String current = get_edited_object()->get(get_edited_property());
  444. if (hint == MEMBER_METHOD_OF_VARIANT_TYPE) {
  445. Variant::Type type = Variant::NIL;
  446. for (int i = 0; i < Variant::VARIANT_MAX; i++) {
  447. if (hint_text == Variant::get_type_name(Variant::Type(i))) {
  448. type = Variant::Type(i);
  449. }
  450. }
  451. if (type != Variant::NIL) {
  452. selector->select_method_from_basic_type(type, current);
  453. }
  454. } else if (hint == MEMBER_METHOD_OF_BASE_TYPE) {
  455. selector->select_method_from_base_type(hint_text, current);
  456. } else if (hint == MEMBER_METHOD_OF_INSTANCE) {
  457. Object *instance = ObjectDB::get_instance(hint_text.to_int64());
  458. if (instance) {
  459. selector->select_method_from_instance(instance, current);
  460. }
  461. } else if (hint == MEMBER_METHOD_OF_SCRIPT) {
  462. Object *obj = ObjectDB::get_instance(hint_text.to_int64());
  463. if (Object::cast_to<Script>(obj)) {
  464. selector->select_method_from_script(Object::cast_to<Script>(obj), current);
  465. }
  466. } else if (hint == MEMBER_PROPERTY_OF_VARIANT_TYPE) {
  467. Variant::Type type = Variant::NIL;
  468. String tname = hint_text;
  469. if (tname.find(".") != -1) {
  470. tname = tname.get_slice(".", 0);
  471. }
  472. for (int i = 0; i < Variant::VARIANT_MAX; i++) {
  473. if (tname == Variant::get_type_name(Variant::Type(i))) {
  474. type = Variant::Type(Variant::Type(i));
  475. }
  476. }
  477. if (type != Variant::NIL) {
  478. selector->select_property_from_basic_type(type, current);
  479. }
  480. } else if (hint == MEMBER_PROPERTY_OF_BASE_TYPE) {
  481. selector->select_property_from_base_type(hint_text, current);
  482. } else if (hint == MEMBER_PROPERTY_OF_INSTANCE) {
  483. Object *instance = ObjectDB::get_instance(hint_text.to_int64());
  484. if (instance) {
  485. selector->select_property_from_instance(instance, current);
  486. }
  487. } else if (hint == MEMBER_PROPERTY_OF_SCRIPT) {
  488. Object *obj = ObjectDB::get_instance(hint_text.to_int64());
  489. if (Object::cast_to<Script>(obj)) {
  490. selector->select_property_from_script(Object::cast_to<Script>(obj), current);
  491. }
  492. }
  493. }
  494. void EditorPropertyMember::setup(Type p_hint, const String &p_hint_text) {
  495. hint = p_hint;
  496. hint_text = p_hint_text;
  497. }
  498. void EditorPropertyMember::update_property() {
  499. String full_path = get_edited_object()->get(get_edited_property());
  500. property->set_text(full_path);
  501. }
  502. void EditorPropertyMember::_bind_methods() {
  503. ClassDB::bind_method(D_METHOD("_property_selected"), &EditorPropertyMember::_property_selected);
  504. ClassDB::bind_method(D_METHOD("_property_select"), &EditorPropertyMember::_property_select);
  505. }
  506. EditorPropertyMember::EditorPropertyMember() {
  507. selector = nullptr;
  508. property = memnew(Button);
  509. property->set_clip_text(true);
  510. add_child(property);
  511. add_focusable(property);
  512. property->connect("pressed", this, "_property_select");
  513. }
  514. ///////////////////// CHECK /////////////////////////
  515. void EditorPropertyCheck::_checkbox_pressed() {
  516. emit_changed(get_edited_property(), checkbox->is_pressed());
  517. }
  518. void EditorPropertyCheck::update_property() {
  519. bool c = get_edited_object()->get(get_edited_property());
  520. checkbox->set_pressed(c);
  521. checkbox->set_disabled(is_read_only());
  522. }
  523. void EditorPropertyCheck::_bind_methods() {
  524. ClassDB::bind_method(D_METHOD("_checkbox_pressed"), &EditorPropertyCheck::_checkbox_pressed);
  525. }
  526. EditorPropertyCheck::EditorPropertyCheck() {
  527. checkbox = memnew(CheckBox);
  528. checkbox->set_text(TTR("On"));
  529. add_child(checkbox);
  530. add_focusable(checkbox);
  531. checkbox->connect("pressed", this, "_checkbox_pressed");
  532. }
  533. ///////////////////// ENUM /////////////////////////
  534. void EditorPropertyEnum::_option_selected(int p_which) {
  535. int64_t val = options->get_item_metadata(p_which);
  536. emit_changed(get_edited_property(), val);
  537. }
  538. void EditorPropertyEnum::update_property() {
  539. int64_t which = get_edited_object()->get(get_edited_property());
  540. for (int i = 0; i < options->get_item_count(); i++) {
  541. if (which == (int64_t)options->get_item_metadata(i)) {
  542. options->select(i);
  543. return;
  544. }
  545. }
  546. }
  547. void EditorPropertyEnum::setup(const Vector<String> &p_options) {
  548. int64_t current_val = 0;
  549. for (int i = 0; i < p_options.size(); i++) {
  550. Vector<String> text_split = p_options[i].split(":");
  551. if (text_split.size() != 1) {
  552. current_val = text_split[1].to_int64();
  553. }
  554. options->add_item(text_split[0]);
  555. options->set_item_metadata(i, current_val);
  556. current_val += 1;
  557. }
  558. }
  559. void EditorPropertyEnum::set_option_button_clip(bool p_enable) {
  560. options->set_clip_text(p_enable);
  561. }
  562. void EditorPropertyEnum::_bind_methods() {
  563. ClassDB::bind_method(D_METHOD("_option_selected"), &EditorPropertyEnum::_option_selected);
  564. }
  565. EditorPropertyEnum::EditorPropertyEnum() {
  566. options = memnew(OptionButton);
  567. options->set_clip_text(true);
  568. options->set_flat(true);
  569. add_child(options);
  570. add_focusable(options);
  571. options->connect("item_selected", this, "_option_selected");
  572. }
  573. ///////////////////// FLAGS /////////////////////////
  574. void EditorPropertyFlags::_flag_toggled(int p_index) {
  575. uint32_t value = get_edited_object()->get(get_edited_property());
  576. if (flags[p_index]->is_pressed()) {
  577. value |= flag_values[p_index];
  578. } else {
  579. value &= ~flag_values[p_index];
  580. }
  581. emit_changed(get_edited_property(), value);
  582. }
  583. void EditorPropertyFlags::update_property() {
  584. uint32_t value = get_edited_object()->get(get_edited_property());
  585. for (int i = 0; i < flags.size(); i++) {
  586. flags[i]->set_pressed((value & flag_values[i]) == flag_values[i]);
  587. }
  588. }
  589. void EditorPropertyFlags::setup(const Vector<String> &p_options) {
  590. ERR_FAIL_COND(flags.size());
  591. bool first = true;
  592. uint32_t current_val;
  593. for (int i = 0; i < p_options.size(); i++) {
  594. String option = p_options[i].strip_edges();
  595. if (option != "") {
  596. CheckBox *cb = memnew(CheckBox);
  597. cb->set_text(option);
  598. cb->set_clip_text(true);
  599. cb->connect("pressed", this, "_flag_toggled", varray(i));
  600. add_focusable(cb);
  601. vbox->add_child(cb);
  602. flags.push_back(cb);
  603. Vector<String> text_split = p_options[i].split(":");
  604. if (text_split.size() != 1) {
  605. current_val = text_split[1].to_int();
  606. } else {
  607. current_val = 1 << i;
  608. }
  609. flag_values.push_back(current_val);
  610. if (first) {
  611. set_label_reference(cb);
  612. first = false;
  613. }
  614. }
  615. }
  616. }
  617. void EditorPropertyFlags::_bind_methods() {
  618. ClassDB::bind_method(D_METHOD("_flag_toggled"), &EditorPropertyFlags::_flag_toggled);
  619. }
  620. EditorPropertyFlags::EditorPropertyFlags() {
  621. vbox = memnew(VBoxContainer);
  622. add_child(vbox);
  623. }
  624. ///////////////////// LAYERS /////////////////////////
  625. class EditorPropertyLayersGrid : public Control {
  626. GDCLASS(EditorPropertyLayersGrid, Control);
  627. private:
  628. Vector<Rect2> flag_rects;
  629. Rect2 expand_rect;
  630. bool expand_hovered = false;
  631. bool expanded = false;
  632. int expansion_rows = 0;
  633. int hovered_index = -1;
  634. Size2 get_grid_size() const {
  635. Ref<Font> font = get_font("font", "Label");
  636. return Size2(0, font->get_height() * 3);
  637. }
  638. public:
  639. uint32_t value = 0;
  640. int layer_group_size = 0;
  641. int layer_count = 0;
  642. Vector<String> names;
  643. Vector<String> tooltips;
  644. virtual Size2 get_minimum_size() const {
  645. Size2 min_size = get_grid_size();
  646. // Add extra rows when expanded.
  647. if (expanded) {
  648. const int bsize = (min_size.height * 80 / 100) / 2;
  649. for (int i = 0; i < expansion_rows; ++i) {
  650. min_size.y += 2 * (bsize + 1) + 3;
  651. }
  652. }
  653. return min_size;
  654. }
  655. virtual String get_tooltip(const Point2 &p_pos) const {
  656. for (int i = 0; i < flag_rects.size(); i++) {
  657. if (i < tooltips.size() && flag_rects[i].has_point(p_pos)) {
  658. return tooltips[i];
  659. }
  660. }
  661. return String();
  662. }
  663. void _update_hovered(const Vector2 &p_position) {
  664. bool expand_was_hovered = expand_hovered;
  665. expand_hovered = expand_rect.has_point(p_position);
  666. if (expand_hovered != expand_was_hovered) {
  667. update();
  668. }
  669. if (!expand_hovered) {
  670. for (int i = 0; i < flag_rects.size(); i++) {
  671. if (flag_rects[i].has_point(p_position)) {
  672. // Used to highlight the hovered flag in the layers grid.
  673. hovered_index = i;
  674. update();
  675. return;
  676. }
  677. }
  678. }
  679. // Remove highlight when no square is hovered.
  680. if (hovered_index != -1) {
  681. hovered_index = -1;
  682. update();
  683. }
  684. }
  685. void _on_hover_exit() {
  686. if (expand_hovered) {
  687. expand_hovered = false;
  688. update();
  689. }
  690. if (hovered_index != -1) {
  691. hovered_index = -1;
  692. update();
  693. }
  694. }
  695. void _update_flag() {
  696. if (hovered_index >= 0) {
  697. // Toggle the flag.
  698. // We base our choice on the hovered flag, so that it always matches the hovered flag.
  699. if (value & (1 << hovered_index)) {
  700. value &= ~(1 << hovered_index);
  701. } else {
  702. value |= (1 << hovered_index);
  703. }
  704. emit_signal("flag_changed", value);
  705. update();
  706. } else if (expand_hovered) {
  707. expanded = !expanded;
  708. minimum_size_changed();
  709. update();
  710. }
  711. }
  712. void _gui_input(const Ref<InputEvent> &p_ev) {
  713. const Ref<InputEventMouseMotion> mm = p_ev;
  714. if (mm.is_valid()) {
  715. _update_hovered(mm->get_position());
  716. return;
  717. }
  718. const Ref<InputEventMouseButton> mb = p_ev;
  719. if (mb.is_valid() && mb->get_button_index() == BUTTON_LEFT && mb->is_pressed()) {
  720. _update_hovered(mb->get_position());
  721. _update_flag();
  722. }
  723. }
  724. void _notification(int p_what) {
  725. switch (p_what) {
  726. case NOTIFICATION_DRAW: {
  727. Size2 grid_size = get_grid_size();
  728. grid_size.x = get_size().x;
  729. flag_rects.clear();
  730. int prev_expansion_rows = expansion_rows;
  731. expansion_rows = 0;
  732. const int bsize = (grid_size.height * 80 / 100) / 2;
  733. const int h = bsize * 2 + 1;
  734. Color color = get_color("highlight_color", "Editor");
  735. Color text_color = get_color("font_color", "Editor");
  736. text_color.a *= 0.5;
  737. Color text_color_on = get_color("dark_color_3", "Editor");
  738. text_color_on.a *= 0.8;
  739. const int vofs = (grid_size.height - h) / 2;
  740. int layer_index = 0;
  741. Point2 arrow_pos;
  742. Point2 block_ofs(4, vofs);
  743. while (true) {
  744. Point2 ofs = block_ofs;
  745. for (int i = 0; i < 2; i++) {
  746. for (int j = 0; j < layer_group_size; j++) {
  747. const bool on = value & (1 << layer_index);
  748. Rect2 rect2 = Rect2(ofs, Size2(bsize, bsize));
  749. color.a = on ? 0.6 : 0.2;
  750. if (layer_index == hovered_index) {
  751. // Add visual feedback when hovering a flag.
  752. color.a += 0.15;
  753. }
  754. draw_rect(rect2, color);
  755. flag_rects.push_back(rect2);
  756. Ref<Font> font = get_font("font", "Label");
  757. Vector2 offset;
  758. if (layer_index + 1 > 9) {
  759. // Offset for double digit numbers.
  760. offset.x = rect2.size.x * 0.1;
  761. } else {
  762. offset.x = rect2.size.x * 0.3;
  763. }
  764. offset.y = rect2.size.y * 0.75;
  765. draw_string(font, rect2.position + offset, itos(layer_index + 1), on ? text_color_on : text_color);
  766. ofs.x += bsize + 1;
  767. ++layer_index;
  768. }
  769. ofs.x = block_ofs.x;
  770. ofs.y += bsize + 1;
  771. }
  772. if (layer_index >= layer_count) {
  773. if (!flag_rects.empty() && (expansion_rows == 0)) {
  774. const Rect2 &last_rect = flag_rects[flag_rects.size() - 1];
  775. arrow_pos = last_rect.position + last_rect.size;
  776. }
  777. break;
  778. }
  779. int block_size_x = layer_group_size * (bsize + 1);
  780. block_ofs.x += block_size_x + 3;
  781. if (block_ofs.x + block_size_x + 12 > grid_size.width) {
  782. // Keep last valid cell position for the expansion icon.
  783. if (!flag_rects.empty() && (expansion_rows == 0)) {
  784. const Rect2 &last_rect = flag_rects[flag_rects.size() - 1];
  785. arrow_pos = last_rect.position + last_rect.size;
  786. }
  787. ++expansion_rows;
  788. if (expanded) {
  789. // Expand grid to next line.
  790. block_ofs.x = 4;
  791. block_ofs.y += 2 * (bsize + 1) + 3;
  792. } else {
  793. // Skip remaining blocks.
  794. break;
  795. }
  796. }
  797. }
  798. if ((expansion_rows != prev_expansion_rows) && expanded) {
  799. minimum_size_changed();
  800. }
  801. if ((expansion_rows == 0) && (layer_index == layer_count)) {
  802. // Whole grid was drawn, no need for expansion icon.
  803. break;
  804. }
  805. Ref<Texture> arrow = get_icon("arrow", "Tree");
  806. ERR_FAIL_COND(arrow.is_null());
  807. Color arrow_color = get_color("highlight_color", "Editor");
  808. arrow_color.a = expand_hovered ? 1.0 : 0.6;
  809. arrow_pos.x += 2.0;
  810. arrow_pos.y -= arrow->get_height();
  811. Rect2 arrow_draw_rect(arrow_pos, arrow->get_size());
  812. expand_rect = arrow_draw_rect;
  813. if (expanded) {
  814. arrow_draw_rect.size.y *= -1.0; // Flip arrow vertically when expanded.
  815. }
  816. RID ci = get_canvas_item();
  817. arrow->draw_rect(ci, arrow_draw_rect, false, arrow_color);
  818. } break;
  819. case NOTIFICATION_MOUSE_EXIT: {
  820. _on_hover_exit();
  821. } break;
  822. default:
  823. break;
  824. }
  825. }
  826. void set_flag(uint32_t p_flag) {
  827. value = p_flag;
  828. update();
  829. }
  830. static void _bind_methods() {
  831. ClassDB::bind_method(D_METHOD("_gui_input"), &EditorPropertyLayersGrid::_gui_input);
  832. ADD_SIGNAL(MethodInfo("flag_changed", PropertyInfo(Variant::INT, "flag")));
  833. }
  834. };
  835. void EditorPropertyLayers::_grid_changed(uint32_t p_grid) {
  836. emit_changed(get_edited_property(), p_grid);
  837. }
  838. void EditorPropertyLayers::update_property() {
  839. uint32_t value = get_edited_object()->get(get_edited_property());
  840. grid->set_flag(value);
  841. }
  842. void EditorPropertyLayers::setup(LayerType p_layer_type) {
  843. layer_type = p_layer_type;
  844. int layer_group_size = 0;
  845. int layer_count = 0;
  846. switch (p_layer_type) {
  847. case LAYER_RENDER_2D: {
  848. basename = "layer_names/2d_render";
  849. layer_group_size = 5;
  850. layer_count = 20;
  851. } break;
  852. case LAYER_PHYSICS_2D: {
  853. basename = "layer_names/2d_physics";
  854. layer_group_size = 4;
  855. layer_count = 32;
  856. } break;
  857. case LAYER_NAVIGATION_2D: {
  858. basename = "layer_names/2d_navigation";
  859. layer_group_size = 4;
  860. layer_count = 32;
  861. } break;
  862. case LAYER_RENDER_3D: {
  863. basename = "layer_names/3d_render";
  864. layer_group_size = 5;
  865. layer_count = 20;
  866. } break;
  867. case LAYER_PHYSICS_3D: {
  868. basename = "layer_names/3d_physics";
  869. layer_group_size = 4;
  870. layer_count = 32;
  871. } break;
  872. case LAYER_NAVIGATION_3D: {
  873. basename = "layer_names/3d_navigation";
  874. layer_group_size = 4;
  875. layer_count = 32;
  876. } break;
  877. }
  878. Vector<String> names;
  879. Vector<String> tooltips;
  880. for (int i = 0; i < layer_count; i++) {
  881. String name = _get_layer_name(i);
  882. if (name.empty()) {
  883. name = TTR("Layer") + " " + itos(i + 1);
  884. }
  885. names.push_back(name);
  886. tooltips.push_back(name + "\n" + vformat(TTR("Bit %d, value %d"), i, 1 << i));
  887. }
  888. grid->names = names;
  889. grid->tooltips = tooltips;
  890. grid->layer_group_size = layer_group_size;
  891. grid->layer_count = layer_count;
  892. }
  893. void EditorPropertyLayers::_button_pressed() {
  894. int layer_count = grid->layer_count;
  895. layers->clear();
  896. for (int i = 0; i < layer_count; i++) {
  897. const String name = _get_layer_name(i);
  898. if (name.empty()) {
  899. continue;
  900. }
  901. layers->add_check_item(name, i);
  902. int idx = layers->get_item_index(i);
  903. layers->set_item_checked(idx, grid->value & (1 << i));
  904. }
  905. if (layers->get_item_count() == 0) {
  906. layers->add_item(TTR("No Named Layers"));
  907. layers->set_item_disabled(0, true);
  908. }
  909. layers->add_separator();
  910. layers->add_icon_item(get_icon("Edit", "EditorIcons"), TTR("Edit Layer Names"), grid->layer_count);
  911. Rect2 gp = button->get_global_rect();
  912. layers->set_as_minsize();
  913. Vector2 popup_pos = gp.position - Vector2(layers->get_combined_minimum_size().x, 0);
  914. layers->set_global_position(popup_pos);
  915. layers->popup();
  916. }
  917. void EditorPropertyLayers::_menu_pressed(int p_menu) {
  918. if (p_menu == grid->layer_count) {
  919. ProjectSettingsEditor::get_singleton()->popup_project_settings();
  920. ProjectSettingsEditor::get_singleton()->set_general_page(basename);
  921. } else {
  922. if (grid->value & (1 << p_menu)) {
  923. grid->value &= ~(1 << p_menu);
  924. } else {
  925. grid->value |= (1 << p_menu);
  926. }
  927. grid->update();
  928. layers->set_item_checked(layers->get_item_index(p_menu), grid->value & (1 << p_menu));
  929. _grid_changed(grid->value);
  930. }
  931. }
  932. void EditorPropertyLayers::_refresh_names() {
  933. setup(layer_type);
  934. }
  935. String EditorPropertyLayers::_get_layer_name(int p_index) const {
  936. const String property_name = basename + vformat("/layer_%d", p_index + 1);
  937. if (ProjectSettings::get_singleton()->has_setting(property_name)) {
  938. return ProjectSettings::get_singleton()->get(property_name);
  939. }
  940. return String();
  941. }
  942. void EditorPropertyLayers::_bind_methods() {
  943. ClassDB::bind_method(D_METHOD("_grid_changed"), &EditorPropertyLayers::_grid_changed);
  944. ClassDB::bind_method(D_METHOD("_button_pressed"), &EditorPropertyLayers::_button_pressed);
  945. ClassDB::bind_method(D_METHOD("_menu_pressed"), &EditorPropertyLayers::_menu_pressed);
  946. ClassDB::bind_method(D_METHOD("_refresh_names"), &EditorPropertyLayers::_refresh_names);
  947. }
  948. EditorPropertyLayers::EditorPropertyLayers() {
  949. HBoxContainer *hb = memnew(HBoxContainer);
  950. hb->set_clip_contents(true);
  951. add_child(hb);
  952. grid = memnew(EditorPropertyLayersGrid);
  953. grid->connect("flag_changed", this, "_grid_changed");
  954. grid->set_h_size_flags(SIZE_EXPAND_FILL);
  955. hb->add_child(grid);
  956. button = memnew(Button);
  957. button->set_toggle_mode(true);
  958. button->set_text("...");
  959. button->connect("pressed", this, "_button_pressed");
  960. hb->add_child(button);
  961. set_bottom_editor(hb);
  962. layers = memnew(PopupMenu);
  963. add_child(layers);
  964. layers->set_hide_on_checkable_item_selection(false);
  965. layers->connect("id_pressed", this, "_menu_pressed");
  966. layers->connect("popup_hide", button, "set_pressed", varray(false));
  967. ProjectSettings::get_singleton()->connect("project_settings_changed", this, "_refresh_names");
  968. }
  969. ///////////////////// INT /////////////////////////
  970. void EditorPropertyInteger::_value_changed(int64_t val) {
  971. if (setting) {
  972. return;
  973. }
  974. emit_changed(get_edited_property(), val);
  975. }
  976. void EditorPropertyInteger::update_property() {
  977. int64_t val = get_edited_object()->get(get_edited_property());
  978. setting = true;
  979. spin->set_value(val);
  980. setting = false;
  981. #ifdef DEBUG_ENABLED
  982. // If spin (currently EditorSplinSlider : Range) is changed so that it can use int64_t, then the below warning wouldn't be a problem.
  983. if (val != (int64_t)(double)(val)) {
  984. WARN_PRINT("Cannot reliably represent '" + itos(val) + "' in the inspector, value is too large.");
  985. }
  986. #endif
  987. }
  988. void EditorPropertyInteger::_bind_methods() {
  989. ClassDB::bind_method(D_METHOD("_value_changed"), &EditorPropertyInteger::_value_changed);
  990. }
  991. void EditorPropertyInteger::setup(int64_t p_min, int64_t p_max, int64_t p_step, bool p_allow_greater, bool p_allow_lesser) {
  992. spin->set_min(p_min);
  993. spin->set_max(p_max);
  994. spin->set_step(p_step);
  995. spin->set_allow_greater(p_allow_greater);
  996. spin->set_allow_lesser(p_allow_lesser);
  997. }
  998. EditorPropertyInteger::EditorPropertyInteger() {
  999. spin = memnew(EditorSpinSlider);
  1000. spin->set_flat(true);
  1001. add_child(spin);
  1002. add_focusable(spin);
  1003. spin->connect("value_changed", this, "_value_changed");
  1004. setting = false;
  1005. }
  1006. ///////////////////// OBJECT ID /////////////////////////
  1007. void EditorPropertyObjectID::_edit_pressed() {
  1008. emit_signal("object_id_selected", get_edited_property(), get_edited_object()->get(get_edited_property()));
  1009. }
  1010. void EditorPropertyObjectID::update_property() {
  1011. String type = base_type;
  1012. if (type == "") {
  1013. type = "Object";
  1014. }
  1015. ObjectID id = get_edited_object()->get(get_edited_property());
  1016. if (id != 0) {
  1017. edit->set_text(type + " ID: " + itos(id));
  1018. edit->set_disabled(false);
  1019. edit->set_icon(EditorNode::get_singleton()->get_class_icon(type));
  1020. } else {
  1021. edit->set_text(TTR("[Empty]"));
  1022. edit->set_disabled(true);
  1023. edit->set_icon(Ref<Texture>());
  1024. }
  1025. }
  1026. void EditorPropertyObjectID::setup(const String &p_base_type) {
  1027. base_type = p_base_type;
  1028. }
  1029. void EditorPropertyObjectID::_bind_methods() {
  1030. ClassDB::bind_method(D_METHOD("_edit_pressed"), &EditorPropertyObjectID::_edit_pressed);
  1031. }
  1032. EditorPropertyObjectID::EditorPropertyObjectID() {
  1033. edit = memnew(Button);
  1034. add_child(edit);
  1035. add_focusable(edit);
  1036. edit->connect("pressed", this, "_edit_pressed");
  1037. }
  1038. ///////////////////// FLOAT /////////////////////////
  1039. void EditorPropertyFloat::_value_changed(double val) {
  1040. if (setting) {
  1041. return;
  1042. }
  1043. emit_changed(get_edited_property(), val);
  1044. }
  1045. void EditorPropertyFloat::update_property() {
  1046. double val = get_edited_object()->get(get_edited_property());
  1047. setting = true;
  1048. spin->set_value(val);
  1049. setting = false;
  1050. }
  1051. void EditorPropertyFloat::_bind_methods() {
  1052. ClassDB::bind_method(D_METHOD("_value_changed"), &EditorPropertyFloat::_value_changed);
  1053. }
  1054. 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) {
  1055. spin->set_min(p_min);
  1056. spin->set_max(p_max);
  1057. spin->set_step(p_step);
  1058. spin->set_hide_slider(p_no_slider);
  1059. spin->set_exp_ratio(p_exp_range);
  1060. spin->set_allow_greater(p_greater);
  1061. spin->set_allow_lesser(p_lesser);
  1062. }
  1063. EditorPropertyFloat::EditorPropertyFloat() {
  1064. spin = memnew(EditorSpinSlider);
  1065. spin->set_flat(true);
  1066. add_child(spin);
  1067. add_focusable(spin);
  1068. spin->connect("value_changed", this, "_value_changed");
  1069. setting = false;
  1070. }
  1071. ///////////////////// EASING /////////////////////////
  1072. void EditorPropertyEasing::_drag_easing(const Ref<InputEvent> &p_ev) {
  1073. const Ref<InputEventMouseButton> mb = p_ev;
  1074. if (mb.is_valid()) {
  1075. if (mb->is_doubleclick() && mb->get_button_index() == BUTTON_LEFT) {
  1076. _setup_spin();
  1077. }
  1078. if (mb->is_pressed() && mb->get_button_index() == BUTTON_RIGHT) {
  1079. preset->set_global_position(easing_draw->get_global_transform().xform(mb->get_position()));
  1080. preset->popup();
  1081. // Ensure the easing doesn't appear as being dragged
  1082. dragging = false;
  1083. easing_draw->update();
  1084. }
  1085. if (mb->get_button_index() == BUTTON_LEFT) {
  1086. dragging = mb->is_pressed();
  1087. // Update to display the correct dragging color
  1088. easing_draw->update();
  1089. }
  1090. }
  1091. const Ref<InputEventMouseMotion> mm = p_ev;
  1092. if (dragging && mm.is_valid() && mm->get_button_mask() & BUTTON_MASK_LEFT) {
  1093. float rel = mm->get_relative().x;
  1094. if (rel == 0) {
  1095. return;
  1096. }
  1097. if (flip) {
  1098. rel = -rel;
  1099. }
  1100. float val = get_edited_object()->get(get_edited_property());
  1101. bool sg = val < 0;
  1102. val = Math::absf(val);
  1103. val = Math::log(val) / Math::log((float)2.0);
  1104. // Logarithmic space.
  1105. val += rel * 0.05;
  1106. val = Math::pow(2.0f, val);
  1107. if (sg) {
  1108. val = -val;
  1109. }
  1110. // 0 is a singularity, but both positive and negative values
  1111. // are otherwise allowed. Enforce 0+ as workaround.
  1112. if (Math::is_zero_approx(val)) {
  1113. val = 0.00001;
  1114. }
  1115. // Limit to a reasonable value to prevent the curve going into infinity,
  1116. // which can cause crashes and other issues.
  1117. val = CLAMP(val, -1000000, 1000000);
  1118. emit_changed(get_edited_property(), val);
  1119. easing_draw->update();
  1120. }
  1121. }
  1122. void EditorPropertyEasing::_draw_easing() {
  1123. RID ci = easing_draw->get_canvas_item();
  1124. Size2 s = easing_draw->get_size();
  1125. const int point_count = 48;
  1126. const float exp = get_edited_object()->get(get_edited_property());
  1127. const Ref<Font> f = get_font("font", "Label");
  1128. const Color font_color = get_color("font_color", "Label");
  1129. Color line_color;
  1130. if (dragging) {
  1131. line_color = get_color("accent_color", "Editor");
  1132. } else {
  1133. line_color = get_color("font_color", "Label") * Color(1, 1, 1, 0.9);
  1134. }
  1135. Vector<Point2> points;
  1136. for (int i = 0; i <= point_count; i++) {
  1137. float ifl = i / float(point_count);
  1138. const float h = 1.0 - Math::ease(ifl, exp);
  1139. if (flip) {
  1140. ifl = 1.0 - ifl;
  1141. }
  1142. points.push_back(Point2(ifl * s.width, h * s.height));
  1143. }
  1144. easing_draw->draw_polyline(points, line_color, 1.0, true);
  1145. // Draw more decimals for small numbers since higher precision is usually required for fine adjustments.
  1146. int decimals;
  1147. if (Math::abs(exp) < 0.1 - CMP_EPSILON) {
  1148. decimals = 4;
  1149. } else if (Math::abs(exp) < 1 - CMP_EPSILON) {
  1150. decimals = 3;
  1151. } else if (Math::abs(exp) < 10 - CMP_EPSILON) {
  1152. decimals = 2;
  1153. } else {
  1154. decimals = 1;
  1155. }
  1156. f->draw(ci, Point2(10, 10 + f->get_ascent()), rtos(exp).pad_decimals(decimals), font_color);
  1157. }
  1158. void EditorPropertyEasing::update_property() {
  1159. easing_draw->update();
  1160. }
  1161. void EditorPropertyEasing::_set_preset(int p_preset) {
  1162. static const float preset_value[EASING_MAX] = { 0.0, 1.0, 2.0, 0.5, -2.0, -0.5 };
  1163. emit_changed(get_edited_property(), preset_value[p_preset]);
  1164. easing_draw->update();
  1165. }
  1166. void EditorPropertyEasing::_setup_spin() {
  1167. setting = true;
  1168. spin->setup_and_show();
  1169. spin->get_line_edit()->set_text(rtos(get_edited_object()->get(get_edited_property())));
  1170. setting = false;
  1171. spin->show();
  1172. }
  1173. void EditorPropertyEasing::_spin_value_changed(double p_value) {
  1174. if (setting) {
  1175. return;
  1176. }
  1177. // 0 is a singularity, but both positive and negative values
  1178. // are otherwise allowed. Enforce 0+ as workaround.
  1179. if (Math::is_zero_approx(p_value)) {
  1180. p_value = 0.00001;
  1181. }
  1182. // Limit to a reasonable value to prevent the curve going into infinity,
  1183. // which can cause crashes and other issues.
  1184. p_value = CLAMP(p_value, -1000000, 1000000);
  1185. emit_changed(get_edited_property(), p_value);
  1186. _spin_focus_exited();
  1187. }
  1188. void EditorPropertyEasing::_spin_focus_exited() {
  1189. spin->hide();
  1190. // Ensure the easing doesn't appear as being dragged
  1191. dragging = false;
  1192. easing_draw->update();
  1193. }
  1194. void EditorPropertyEasing::setup(bool p_full, bool p_flip) {
  1195. flip = p_flip;
  1196. full = p_full;
  1197. }
  1198. void EditorPropertyEasing::_notification(int p_what) {
  1199. switch (p_what) {
  1200. case NOTIFICATION_THEME_CHANGED:
  1201. case NOTIFICATION_ENTER_TREE: {
  1202. preset->clear();
  1203. preset->add_icon_item(get_icon("CurveConstant", "EditorIcons"), "Zero", EASING_ZERO);
  1204. preset->add_icon_item(get_icon("CurveLinear", "EditorIcons"), "Linear", EASING_LINEAR);
  1205. preset->add_icon_item(get_icon("CurveIn", "EditorIcons"), "In", EASING_IN);
  1206. preset->add_icon_item(get_icon("CurveOut", "EditorIcons"), "Out", EASING_OUT);
  1207. if (full) {
  1208. preset->add_icon_item(get_icon("CurveInOut", "EditorIcons"), "In-Out", EASING_IN_OUT);
  1209. preset->add_icon_item(get_icon("CurveOutIn", "EditorIcons"), "Out-In", EASING_OUT_IN);
  1210. }
  1211. easing_draw->set_custom_minimum_size(Size2(0, get_font("font", "Label")->get_height() * 2));
  1212. } break;
  1213. }
  1214. }
  1215. void EditorPropertyEasing::_bind_methods() {
  1216. ClassDB::bind_method("_draw_easing", &EditorPropertyEasing::_draw_easing);
  1217. ClassDB::bind_method("_drag_easing", &EditorPropertyEasing::_drag_easing);
  1218. ClassDB::bind_method("_set_preset", &EditorPropertyEasing::_set_preset);
  1219. ClassDB::bind_method("_spin_value_changed", &EditorPropertyEasing::_spin_value_changed);
  1220. ClassDB::bind_method("_spin_focus_exited", &EditorPropertyEasing::_spin_focus_exited);
  1221. }
  1222. EditorPropertyEasing::EditorPropertyEasing() {
  1223. easing_draw = memnew(Control);
  1224. easing_draw->connect("draw", this, "_draw_easing");
  1225. easing_draw->connect("gui_input", this, "_drag_easing");
  1226. easing_draw->set_default_cursor_shape(Control::CURSOR_MOVE);
  1227. add_child(easing_draw);
  1228. preset = memnew(PopupMenu);
  1229. add_child(preset);
  1230. preset->connect("id_pressed", this, "_set_preset");
  1231. spin = memnew(EditorSpinSlider);
  1232. spin->set_flat(true);
  1233. spin->set_min(-100);
  1234. spin->set_max(100);
  1235. spin->set_step(0);
  1236. spin->set_hide_slider(true);
  1237. spin->set_allow_lesser(true);
  1238. spin->set_allow_greater(true);
  1239. spin->connect("value_changed", this, "_spin_value_changed");
  1240. spin->get_line_edit()->connect("focus_exited", this, "_spin_focus_exited");
  1241. spin->hide();
  1242. add_child(spin);
  1243. dragging = false;
  1244. flip = false;
  1245. full = false;
  1246. }
  1247. ///////////////////// VECTOR2 /////////////////////////
  1248. void EditorPropertyVector2::_value_changed(double val, const String &p_name) {
  1249. if (setting) {
  1250. return;
  1251. }
  1252. if (linked->is_pressed()) {
  1253. setting = true;
  1254. if (p_name == "x") {
  1255. spin[1]->set_value(spin[0]->get_value() * ratio_yx);
  1256. }
  1257. if (p_name == "y") {
  1258. spin[0]->set_value(spin[1]->get_value() * ratio_xy);
  1259. }
  1260. setting = false;
  1261. }
  1262. Vector2 v2;
  1263. v2.x = spin[0]->get_value();
  1264. v2.y = spin[1]->get_value();
  1265. emit_changed(get_edited_property(), v2, linked->is_pressed() ? "" : p_name);
  1266. }
  1267. void EditorPropertyVector2::update_property() {
  1268. Vector2 val = get_edited_object()->get(get_edited_property());
  1269. setting = true;
  1270. spin[0]->set_value(val.x);
  1271. spin[1]->set_value(val.y);
  1272. setting = false;
  1273. _update_ratio();
  1274. }
  1275. void EditorPropertyVector2::_update_ratio() {
  1276. linked->set_modulate(Color(1, 1, 1, linked->is_pressed() ? 1.0 : 0.5));
  1277. if (spin[0]->get_value() != 0 && spin[1]->get_value() != 0) {
  1278. ratio_xy = spin[0]->get_value() / spin[1]->get_value();
  1279. ratio_yx = spin[1]->get_value() / spin[0]->get_value();
  1280. } else {
  1281. ratio_xy = 1.0;
  1282. ratio_yx = 1.0;
  1283. }
  1284. }
  1285. void EditorPropertyVector2::_notification(int p_what) {
  1286. switch (p_what) {
  1287. case NOTIFICATION_ENTER_TREE:
  1288. case NOTIFICATION_THEME_CHANGED: {
  1289. Ref<Texture> normal_icon = get_icon("Unlinked", "EditorIcons");
  1290. linked->set_custom_minimum_size(Vector2(normal_icon->get_width(), 0));
  1291. linked->set_normal_texture(normal_icon);
  1292. linked->set_pressed_texture(get_icon("Instance", "EditorIcons"));
  1293. Color base = get_color("accent_color", "Editor");
  1294. for (int i = 0; i < 2; i++) {
  1295. Color c = base;
  1296. c.set_hsv(float(i) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v());
  1297. spin[i]->set_custom_label_color(true, c);
  1298. }
  1299. } break;
  1300. }
  1301. }
  1302. void EditorPropertyVector2::_bind_methods() {
  1303. ClassDB::bind_method(D_METHOD("_update_ratio"), &EditorPropertyVector2::_update_ratio);
  1304. ClassDB::bind_method(D_METHOD("_value_changed"), &EditorPropertyVector2::_value_changed);
  1305. }
  1306. void EditorPropertyVector2::setup(double p_min, double p_max, double p_step, bool p_no_slider, bool p_link) {
  1307. for (int i = 0; i < 2; i++) {
  1308. spin[i]->set_min(p_min);
  1309. spin[i]->set_max(p_max);
  1310. spin[i]->set_step(p_step);
  1311. spin[i]->set_hide_slider(p_no_slider);
  1312. spin[i]->set_allow_greater(true);
  1313. spin[i]->set_allow_lesser(true);
  1314. }
  1315. if (!p_link) {
  1316. linked->hide();
  1317. } else {
  1318. linked->set_pressed(true);
  1319. }
  1320. }
  1321. EditorPropertyVector2::EditorPropertyVector2() {
  1322. bool horizontal = EDITOR_GET("interface/inspector/horizontal_vector2_editing");
  1323. HBoxContainer *hb = memnew(HBoxContainer);
  1324. hb->set_h_size_flags(SIZE_EXPAND_FILL);
  1325. BoxContainer *bc;
  1326. if (horizontal) {
  1327. bc = memnew(HBoxContainer);
  1328. hb->add_child(bc);
  1329. set_bottom_editor(hb);
  1330. } else {
  1331. bc = memnew(VBoxContainer);
  1332. hb->add_child(bc);
  1333. }
  1334. bc->set_h_size_flags(SIZE_EXPAND_FILL);
  1335. static const char *desc[2] = { "x", "y" };
  1336. for (int i = 0; i < 2; i++) {
  1337. spin[i] = memnew(EditorSpinSlider);
  1338. spin[i]->set_flat(true);
  1339. spin[i]->set_label(desc[i]);
  1340. bc->add_child(spin[i]);
  1341. add_focusable(spin[i]);
  1342. spin[i]->connect("value_changed", this, "_value_changed", varray(desc[i]));
  1343. if (horizontal) {
  1344. spin[i]->set_h_size_flags(SIZE_EXPAND_FILL);
  1345. }
  1346. }
  1347. linked = memnew(TextureButton);
  1348. linked->set_toggle_mode(true);
  1349. linked->set_expand(true);
  1350. linked->set_stretch_mode(TextureButton::STRETCH_KEEP_CENTERED);
  1351. linked->connect("pressed", this, "_update_ratio");
  1352. hb->add_child(linked);
  1353. add_child(hb);
  1354. if (!horizontal) {
  1355. set_label_reference(spin[0]); //show text and buttons around this
  1356. }
  1357. setting = false;
  1358. }
  1359. ///////////////////// RECT2 /////////////////////////
  1360. void EditorPropertyRect2::_value_changed(double val, const String &p_name) {
  1361. if (setting) {
  1362. return;
  1363. }
  1364. Rect2 r2;
  1365. r2.position.x = spin[0]->get_value();
  1366. r2.position.y = spin[1]->get_value();
  1367. r2.size.x = spin[2]->get_value();
  1368. r2.size.y = spin[3]->get_value();
  1369. emit_changed(get_edited_property(), r2, p_name);
  1370. }
  1371. void EditorPropertyRect2::update_property() {
  1372. Rect2 val = get_edited_object()->get(get_edited_property());
  1373. setting = true;
  1374. spin[0]->set_value(val.position.x);
  1375. spin[1]->set_value(val.position.y);
  1376. spin[2]->set_value(val.size.x);
  1377. spin[3]->set_value(val.size.y);
  1378. setting = false;
  1379. }
  1380. void EditorPropertyRect2::_notification(int p_what) {
  1381. if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
  1382. Color base = get_color("accent_color", "Editor");
  1383. for (int i = 0; i < 4; i++) {
  1384. Color c = base;
  1385. c.set_hsv(float(i % 2) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v());
  1386. spin[i]->set_custom_label_color(true, c);
  1387. }
  1388. }
  1389. }
  1390. void EditorPropertyRect2::_bind_methods() {
  1391. ClassDB::bind_method(D_METHOD("_value_changed"), &EditorPropertyRect2::_value_changed);
  1392. }
  1393. void EditorPropertyRect2::setup(double p_min, double p_max, double p_step, bool p_no_slider) {
  1394. for (int i = 0; i < 4; i++) {
  1395. spin[i]->set_min(p_min);
  1396. spin[i]->set_max(p_max);
  1397. spin[i]->set_step(p_step);
  1398. spin[i]->set_hide_slider(p_no_slider);
  1399. spin[i]->set_allow_greater(true);
  1400. spin[i]->set_allow_lesser(true);
  1401. }
  1402. }
  1403. EditorPropertyRect2::EditorPropertyRect2() {
  1404. bool horizontal = EDITOR_GET("interface/inspector/horizontal_vector_types_editing");
  1405. BoxContainer *bc;
  1406. if (horizontal) {
  1407. bc = memnew(HBoxContainer);
  1408. add_child(bc);
  1409. set_bottom_editor(bc);
  1410. } else {
  1411. bc = memnew(VBoxContainer);
  1412. add_child(bc);
  1413. }
  1414. static const char *desc[4] = { "x", "y", "w", "h" };
  1415. for (int i = 0; i < 4; i++) {
  1416. spin[i] = memnew(EditorSpinSlider);
  1417. spin[i]->set_label(desc[i]);
  1418. spin[i]->set_flat(true);
  1419. bc->add_child(spin[i]);
  1420. add_focusable(spin[i]);
  1421. spin[i]->connect("value_changed", this, "_value_changed", varray(desc[i]));
  1422. if (horizontal) {
  1423. spin[i]->set_h_size_flags(SIZE_EXPAND_FILL);
  1424. }
  1425. }
  1426. if (!horizontal) {
  1427. set_label_reference(spin[0]); //show text and buttons around this
  1428. }
  1429. setting = false;
  1430. }
  1431. ///////////////////// VECTOR3 /////////////////////////
  1432. void EditorPropertyVector3::_value_changed(double val, const String &p_name) {
  1433. if (setting) {
  1434. return;
  1435. }
  1436. if (linked->is_pressed()) {
  1437. setting = true;
  1438. if (p_name == "x") {
  1439. spin[1]->set_value(spin[0]->get_value() * ratio_yx);
  1440. spin[2]->set_value(spin[0]->get_value() * ratio_zx);
  1441. }
  1442. if (p_name == "y") {
  1443. spin[0]->set_value(spin[1]->get_value() * ratio_xy);
  1444. spin[2]->set_value(spin[1]->get_value() * ratio_zy);
  1445. }
  1446. if (p_name == "z") {
  1447. spin[0]->set_value(spin[2]->get_value() * ratio_xz);
  1448. spin[1]->set_value(spin[2]->get_value() * ratio_yz);
  1449. }
  1450. setting = false;
  1451. }
  1452. Vector3 v3;
  1453. v3.x = spin[0]->get_value();
  1454. v3.y = spin[1]->get_value();
  1455. v3.z = spin[2]->get_value();
  1456. emit_changed(get_edited_property(), v3, linked->is_pressed() ? "" : p_name);
  1457. }
  1458. void EditorPropertyVector3::update_property() {
  1459. Vector3 val = get_edited_object()->get(get_edited_property());
  1460. setting = true;
  1461. spin[0]->set_value(val.x);
  1462. spin[1]->set_value(val.y);
  1463. spin[2]->set_value(val.z);
  1464. setting = false;
  1465. _update_ratio();
  1466. }
  1467. void EditorPropertyVector3::_update_ratio() {
  1468. linked->set_modulate(Color(1, 1, 1, linked->is_pressed() ? 1.0 : 0.5));
  1469. if (spin[0]->get_value() != 0 && spin[1]->get_value() != 0) {
  1470. ratio_yx = spin[1]->get_value() / spin[0]->get_value();
  1471. ratio_zx = spin[2]->get_value() / spin[0]->get_value();
  1472. ratio_xy = spin[0]->get_value() / spin[1]->get_value();
  1473. ratio_zy = spin[2]->get_value() / spin[1]->get_value();
  1474. ratio_xz = spin[0]->get_value() / spin[2]->get_value();
  1475. ratio_yz = spin[1]->get_value() / spin[2]->get_value();
  1476. } else {
  1477. ratio_yx = 1.0;
  1478. ratio_zx = 1.0;
  1479. ratio_xy = 1.0;
  1480. ratio_zy = 1.0;
  1481. ratio_xz = 1.0;
  1482. ratio_yz = 1.0;
  1483. }
  1484. }
  1485. void EditorPropertyVector3::_notification(int p_what) {
  1486. switch (p_what) {
  1487. case NOTIFICATION_ENTER_TREE:
  1488. case NOTIFICATION_THEME_CHANGED: {
  1489. Ref<Texture> normal_icon = get_icon("Unlinked", "EditorIcons");
  1490. linked->set_custom_minimum_size(Vector2(normal_icon->get_width(), 0));
  1491. linked->set_normal_texture(normal_icon);
  1492. linked->set_pressed_texture(get_icon("Instance", "EditorIcons"));
  1493. Color base = get_color("accent_color", "Editor");
  1494. for (int i = 0; i < 3; i++) {
  1495. Color c = base;
  1496. c.set_hsv(float(i) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v());
  1497. spin[i]->set_custom_label_color(true, c);
  1498. }
  1499. } break;
  1500. }
  1501. }
  1502. void EditorPropertyVector3::_bind_methods() {
  1503. ClassDB::bind_method(D_METHOD("_update_ratio"), &EditorPropertyVector3::_update_ratio);
  1504. ClassDB::bind_method(D_METHOD("_value_changed"), &EditorPropertyVector3::_value_changed);
  1505. }
  1506. void EditorPropertyVector3::setup(double p_min, double p_max, double p_step, bool p_no_slider, bool p_link) {
  1507. for (int i = 0; i < 3; i++) {
  1508. spin[i]->set_min(p_min);
  1509. spin[i]->set_max(p_max);
  1510. spin[i]->set_step(p_step);
  1511. spin[i]->set_hide_slider(p_no_slider);
  1512. spin[i]->set_allow_greater(true);
  1513. spin[i]->set_allow_lesser(true);
  1514. }
  1515. if (!p_link) {
  1516. linked->hide();
  1517. } else {
  1518. linked->set_pressed(true);
  1519. }
  1520. }
  1521. EditorPropertyVector3::EditorPropertyVector3() {
  1522. bool horizontal = EDITOR_GET("interface/inspector/horizontal_vector_types_editing");
  1523. HBoxContainer *hb = memnew(HBoxContainer);
  1524. hb->set_h_size_flags(SIZE_EXPAND_FILL);
  1525. BoxContainer *bc;
  1526. if (horizontal) {
  1527. bc = memnew(HBoxContainer);
  1528. hb->add_child(bc);
  1529. set_bottom_editor(hb);
  1530. } else {
  1531. bc = memnew(VBoxContainer);
  1532. hb->add_child(bc);
  1533. }
  1534. bc->set_h_size_flags(SIZE_EXPAND_FILL);
  1535. static const char *desc[3] = { "x", "y", "z" };
  1536. for (int i = 0; i < 3; i++) {
  1537. spin[i] = memnew(EditorSpinSlider);
  1538. spin[i]->set_flat(true);
  1539. spin[i]->set_label(desc[i]);
  1540. bc->add_child(spin[i]);
  1541. add_focusable(spin[i]);
  1542. spin[i]->connect("value_changed", this, "_value_changed", varray(desc[i]));
  1543. if (horizontal) {
  1544. spin[i]->set_h_size_flags(SIZE_EXPAND_FILL);
  1545. }
  1546. }
  1547. linked = memnew(TextureButton);
  1548. linked->set_toggle_mode(true);
  1549. linked->set_expand(true);
  1550. linked->set_stretch_mode(TextureButton::STRETCH_KEEP_CENTERED);
  1551. linked->connect("pressed", this, "_update_ratio");
  1552. hb->add_child(linked);
  1553. add_child(hb);
  1554. if (!horizontal) {
  1555. set_label_reference(spin[0]); //show text and buttons around this
  1556. }
  1557. setting = false;
  1558. _update_ratio();
  1559. }
  1560. ///////////////////// PLANE /////////////////////////
  1561. void EditorPropertyPlane::_value_changed(double val, const String &p_name) {
  1562. if (setting) {
  1563. return;
  1564. }
  1565. Plane p;
  1566. p.normal.x = spin[0]->get_value();
  1567. p.normal.y = spin[1]->get_value();
  1568. p.normal.z = spin[2]->get_value();
  1569. p.d = spin[3]->get_value();
  1570. emit_changed(get_edited_property(), p, p_name);
  1571. }
  1572. void EditorPropertyPlane::update_property() {
  1573. Plane val = get_edited_object()->get(get_edited_property());
  1574. setting = true;
  1575. spin[0]->set_value(val.normal.x);
  1576. spin[1]->set_value(val.normal.y);
  1577. spin[2]->set_value(val.normal.z);
  1578. spin[3]->set_value(val.d);
  1579. setting = false;
  1580. }
  1581. void EditorPropertyPlane::_notification(int p_what) {
  1582. if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
  1583. Color base = get_color("accent_color", "Editor");
  1584. for (int i = 0; i < 3; i++) {
  1585. Color c = base;
  1586. c.set_hsv(float(i) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v());
  1587. spin[i]->set_custom_label_color(true, c);
  1588. }
  1589. }
  1590. }
  1591. void EditorPropertyPlane::_bind_methods() {
  1592. ClassDB::bind_method(D_METHOD("_value_changed"), &EditorPropertyPlane::_value_changed);
  1593. }
  1594. void EditorPropertyPlane::setup(double p_min, double p_max, double p_step, bool p_no_slider) {
  1595. for (int i = 0; i < 4; i++) {
  1596. spin[i]->set_min(p_min);
  1597. spin[i]->set_max(p_max);
  1598. spin[i]->set_step(p_step);
  1599. spin[i]->set_hide_slider(p_no_slider);
  1600. spin[i]->set_allow_greater(true);
  1601. spin[i]->set_allow_lesser(true);
  1602. }
  1603. }
  1604. EditorPropertyPlane::EditorPropertyPlane() {
  1605. bool horizontal = EDITOR_GET("interface/inspector/horizontal_vector_types_editing");
  1606. BoxContainer *bc;
  1607. if (horizontal) {
  1608. bc = memnew(HBoxContainer);
  1609. add_child(bc);
  1610. set_bottom_editor(bc);
  1611. } else {
  1612. bc = memnew(VBoxContainer);
  1613. add_child(bc);
  1614. }
  1615. static const char *desc[4] = { "x", "y", "z", "d" };
  1616. for (int i = 0; i < 4; i++) {
  1617. spin[i] = memnew(EditorSpinSlider);
  1618. spin[i]->set_flat(true);
  1619. spin[i]->set_label(desc[i]);
  1620. bc->add_child(spin[i]);
  1621. add_focusable(spin[i]);
  1622. spin[i]->connect("value_changed", this, "_value_changed", varray(desc[i]));
  1623. if (horizontal) {
  1624. spin[i]->set_h_size_flags(SIZE_EXPAND_FILL);
  1625. }
  1626. }
  1627. if (!horizontal) {
  1628. set_label_reference(spin[0]); //show text and buttons around this
  1629. }
  1630. setting = false;
  1631. }
  1632. ///////////////////// QUAT /////////////////////////
  1633. void EditorPropertyQuat::_value_changed(double val, const String &p_name) {
  1634. if (setting) {
  1635. return;
  1636. }
  1637. Quat p;
  1638. p.x = spin[0]->get_value();
  1639. p.y = spin[1]->get_value();
  1640. p.z = spin[2]->get_value();
  1641. p.w = spin[3]->get_value();
  1642. emit_changed(get_edited_property(), p, p_name);
  1643. }
  1644. void EditorPropertyQuat::update_property() {
  1645. Quat val = get_edited_object()->get(get_edited_property());
  1646. setting = true;
  1647. spin[0]->set_value(val.x);
  1648. spin[1]->set_value(val.y);
  1649. spin[2]->set_value(val.z);
  1650. spin[3]->set_value(val.w);
  1651. setting = false;
  1652. }
  1653. void EditorPropertyQuat::_notification(int p_what) {
  1654. if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
  1655. Color base = get_color("accent_color", "Editor");
  1656. for (int i = 0; i < 3; i++) {
  1657. Color c = base;
  1658. c.set_hsv(float(i) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v());
  1659. spin[i]->set_custom_label_color(true, c);
  1660. }
  1661. }
  1662. }
  1663. void EditorPropertyQuat::_bind_methods() {
  1664. ClassDB::bind_method(D_METHOD("_value_changed"), &EditorPropertyQuat::_value_changed);
  1665. }
  1666. void EditorPropertyQuat::setup(double p_min, double p_max, double p_step, bool p_no_slider) {
  1667. for (int i = 0; i < 4; i++) {
  1668. spin[i]->set_min(p_min);
  1669. spin[i]->set_max(p_max);
  1670. spin[i]->set_step(p_step);
  1671. spin[i]->set_hide_slider(p_no_slider);
  1672. spin[i]->set_allow_greater(true);
  1673. spin[i]->set_allow_lesser(true);
  1674. }
  1675. }
  1676. EditorPropertyQuat::EditorPropertyQuat() {
  1677. bool horizontal = EDITOR_GET("interface/inspector/horizontal_vector_types_editing");
  1678. BoxContainer *bc;
  1679. if (horizontal) {
  1680. bc = memnew(HBoxContainer);
  1681. add_child(bc);
  1682. set_bottom_editor(bc);
  1683. } else {
  1684. bc = memnew(VBoxContainer);
  1685. add_child(bc);
  1686. }
  1687. static const char *desc[4] = { "x", "y", "z", "w" };
  1688. for (int i = 0; i < 4; i++) {
  1689. spin[i] = memnew(EditorSpinSlider);
  1690. spin[i]->set_flat(true);
  1691. spin[i]->set_label(desc[i]);
  1692. bc->add_child(spin[i]);
  1693. add_focusable(spin[i]);
  1694. spin[i]->connect("value_changed", this, "_value_changed", varray(desc[i]));
  1695. if (horizontal) {
  1696. spin[i]->set_h_size_flags(SIZE_EXPAND_FILL);
  1697. }
  1698. }
  1699. if (!horizontal) {
  1700. set_label_reference(spin[0]); //show text and buttons around this
  1701. }
  1702. setting = false;
  1703. }
  1704. ///////////////////// AABB /////////////////////////
  1705. void EditorPropertyAABB::_value_changed(double val, const String &p_name) {
  1706. if (setting) {
  1707. return;
  1708. }
  1709. AABB p;
  1710. p.position.x = spin[0]->get_value();
  1711. p.position.y = spin[1]->get_value();
  1712. p.position.z = spin[2]->get_value();
  1713. p.size.x = spin[3]->get_value();
  1714. p.size.y = spin[4]->get_value();
  1715. p.size.z = spin[5]->get_value();
  1716. emit_changed(get_edited_property(), p, p_name);
  1717. }
  1718. void EditorPropertyAABB::update_property() {
  1719. AABB val = get_edited_object()->get(get_edited_property());
  1720. setting = true;
  1721. spin[0]->set_value(val.position.x);
  1722. spin[1]->set_value(val.position.y);
  1723. spin[2]->set_value(val.position.z);
  1724. spin[3]->set_value(val.size.x);
  1725. spin[4]->set_value(val.size.y);
  1726. spin[5]->set_value(val.size.z);
  1727. setting = false;
  1728. }
  1729. void EditorPropertyAABB::_notification(int p_what) {
  1730. if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
  1731. Color base = get_color("accent_color", "Editor");
  1732. for (int i = 0; i < 6; i++) {
  1733. Color c = base;
  1734. c.set_hsv(float(i % 3) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v());
  1735. spin[i]->set_custom_label_color(true, c);
  1736. }
  1737. }
  1738. }
  1739. void EditorPropertyAABB::_bind_methods() {
  1740. ClassDB::bind_method(D_METHOD("_value_changed"), &EditorPropertyAABB::_value_changed);
  1741. }
  1742. void EditorPropertyAABB::setup(double p_min, double p_max, double p_step, bool p_no_slider) {
  1743. for (int i = 0; i < 6; i++) {
  1744. spin[i]->set_min(p_min);
  1745. spin[i]->set_max(p_max);
  1746. spin[i]->set_step(p_step);
  1747. spin[i]->set_hide_slider(p_no_slider);
  1748. spin[i]->set_allow_greater(true);
  1749. spin[i]->set_allow_lesser(true);
  1750. }
  1751. }
  1752. EditorPropertyAABB::EditorPropertyAABB() {
  1753. GridContainer *g = memnew(GridContainer);
  1754. g->set_columns(3);
  1755. add_child(g);
  1756. static const char *desc[6] = { "x", "y", "z", "w", "h", "d" };
  1757. for (int i = 0; i < 6; i++) {
  1758. spin[i] = memnew(EditorSpinSlider);
  1759. spin[i]->set_label(desc[i]);
  1760. spin[i]->set_flat(true);
  1761. g->add_child(spin[i]);
  1762. spin[i]->set_h_size_flags(SIZE_EXPAND_FILL);
  1763. add_focusable(spin[i]);
  1764. spin[i]->connect("value_changed", this, "_value_changed", varray(desc[i]));
  1765. }
  1766. set_bottom_editor(g);
  1767. setting = false;
  1768. }
  1769. ///////////////////// TRANSFORM2D /////////////////////////
  1770. void EditorPropertyTransform2D::_value_changed(double val, const String &p_name) {
  1771. if (setting) {
  1772. return;
  1773. }
  1774. Transform2D p;
  1775. p[0][0] = spin[0]->get_value();
  1776. p[0][1] = spin[1]->get_value();
  1777. p[1][0] = spin[2]->get_value();
  1778. p[1][1] = spin[3]->get_value();
  1779. p[2][0] = spin[4]->get_value();
  1780. p[2][1] = spin[5]->get_value();
  1781. emit_changed(get_edited_property(), p, p_name);
  1782. }
  1783. void EditorPropertyTransform2D::update_property() {
  1784. Transform2D val = get_edited_object()->get(get_edited_property());
  1785. setting = true;
  1786. spin[0]->set_value(val[0][0]);
  1787. spin[1]->set_value(val[0][1]);
  1788. spin[2]->set_value(val[1][0]);
  1789. spin[3]->set_value(val[1][1]);
  1790. spin[4]->set_value(val[2][0]);
  1791. spin[5]->set_value(val[2][1]);
  1792. setting = false;
  1793. }
  1794. void EditorPropertyTransform2D::_notification(int p_what) {
  1795. if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
  1796. Color base = get_color("accent_color", "Editor");
  1797. for (int i = 0; i < 6; i++) {
  1798. Color c = base;
  1799. c.set_hsv(float(i % 2) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v());
  1800. spin[i]->set_custom_label_color(true, c);
  1801. }
  1802. }
  1803. }
  1804. void EditorPropertyTransform2D::_bind_methods() {
  1805. ClassDB::bind_method(D_METHOD("_value_changed"), &EditorPropertyTransform2D::_value_changed);
  1806. }
  1807. void EditorPropertyTransform2D::setup(double p_min, double p_max, double p_step, bool p_no_slider) {
  1808. for (int i = 0; i < 6; i++) {
  1809. spin[i]->set_min(p_min);
  1810. spin[i]->set_max(p_max);
  1811. spin[i]->set_step(p_step);
  1812. spin[i]->set_hide_slider(p_no_slider);
  1813. spin[i]->set_allow_greater(true);
  1814. spin[i]->set_allow_lesser(true);
  1815. }
  1816. }
  1817. EditorPropertyTransform2D::EditorPropertyTransform2D() {
  1818. GridContainer *g = memnew(GridContainer);
  1819. g->set_columns(2);
  1820. add_child(g);
  1821. static const char *desc[6] = { "x", "y", "x", "y", "x", "y" };
  1822. for (int i = 0; i < 6; i++) {
  1823. spin[i] = memnew(EditorSpinSlider);
  1824. spin[i]->set_label(desc[i]);
  1825. spin[i]->set_flat(true);
  1826. g->add_child(spin[i]);
  1827. spin[i]->set_h_size_flags(SIZE_EXPAND_FILL);
  1828. add_focusable(spin[i]);
  1829. spin[i]->connect("value_changed", this, "_value_changed", varray(desc[i]));
  1830. }
  1831. set_bottom_editor(g);
  1832. setting = false;
  1833. }
  1834. ///////////////////// BASIS /////////////////////////
  1835. void EditorPropertyBasis::_value_changed(double val, const String &p_name) {
  1836. if (setting) {
  1837. return;
  1838. }
  1839. Basis p;
  1840. p[0][0] = spin[0]->get_value();
  1841. p[1][0] = spin[1]->get_value();
  1842. p[2][0] = spin[2]->get_value();
  1843. p[0][1] = spin[3]->get_value();
  1844. p[1][1] = spin[4]->get_value();
  1845. p[2][1] = spin[5]->get_value();
  1846. p[0][2] = spin[6]->get_value();
  1847. p[1][2] = spin[7]->get_value();
  1848. p[2][2] = spin[8]->get_value();
  1849. emit_changed(get_edited_property(), p, p_name);
  1850. }
  1851. void EditorPropertyBasis::update_property() {
  1852. Basis val = get_edited_object()->get(get_edited_property());
  1853. setting = true;
  1854. spin[0]->set_value(val[0][0]);
  1855. spin[1]->set_value(val[1][0]);
  1856. spin[2]->set_value(val[2][0]);
  1857. spin[3]->set_value(val[0][1]);
  1858. spin[4]->set_value(val[1][1]);
  1859. spin[5]->set_value(val[2][1]);
  1860. spin[6]->set_value(val[0][2]);
  1861. spin[7]->set_value(val[1][2]);
  1862. spin[8]->set_value(val[2][2]);
  1863. setting = false;
  1864. }
  1865. void EditorPropertyBasis::_notification(int p_what) {
  1866. if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
  1867. Color base = get_color("accent_color", "Editor");
  1868. for (int i = 0; i < 9; i++) {
  1869. Color c = base;
  1870. c.set_hsv(float(i % 3) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v());
  1871. spin[i]->set_custom_label_color(true, c);
  1872. }
  1873. }
  1874. }
  1875. void EditorPropertyBasis::_bind_methods() {
  1876. ClassDB::bind_method(D_METHOD("_value_changed"), &EditorPropertyBasis::_value_changed);
  1877. }
  1878. void EditorPropertyBasis::setup(double p_min, double p_max, double p_step, bool p_no_slider) {
  1879. for (int i = 0; i < 9; i++) {
  1880. spin[i]->set_min(p_min);
  1881. spin[i]->set_max(p_max);
  1882. spin[i]->set_step(p_step);
  1883. spin[i]->set_hide_slider(p_no_slider);
  1884. spin[i]->set_allow_greater(true);
  1885. spin[i]->set_allow_lesser(true);
  1886. }
  1887. }
  1888. EditorPropertyBasis::EditorPropertyBasis() {
  1889. GridContainer *g = memnew(GridContainer);
  1890. g->set_columns(3);
  1891. add_child(g);
  1892. static const char *desc[9] = { "x", "y", "z", "x", "y", "z", "x", "y", "z" };
  1893. for (int i = 0; i < 9; i++) {
  1894. spin[i] = memnew(EditorSpinSlider);
  1895. spin[i]->set_label(desc[i]);
  1896. spin[i]->set_flat(true);
  1897. g->add_child(spin[i]);
  1898. spin[i]->set_h_size_flags(SIZE_EXPAND_FILL);
  1899. add_focusable(spin[i]);
  1900. spin[i]->connect("value_changed", this, "_value_changed", varray(desc[i]));
  1901. }
  1902. set_bottom_editor(g);
  1903. setting = false;
  1904. }
  1905. ///////////////////// TRANSFORM /////////////////////////
  1906. void EditorPropertyTransform::_value_changed(double val, const String &p_name) {
  1907. if (setting) {
  1908. return;
  1909. }
  1910. Transform p;
  1911. p.basis[0][0] = spin[0]->get_value();
  1912. p.basis[1][0] = spin[1]->get_value();
  1913. p.basis[2][0] = spin[2]->get_value();
  1914. p.basis[0][1] = spin[3]->get_value();
  1915. p.basis[1][1] = spin[4]->get_value();
  1916. p.basis[2][1] = spin[5]->get_value();
  1917. p.basis[0][2] = spin[6]->get_value();
  1918. p.basis[1][2] = spin[7]->get_value();
  1919. p.basis[2][2] = spin[8]->get_value();
  1920. p.origin[0] = spin[9]->get_value();
  1921. p.origin[1] = spin[10]->get_value();
  1922. p.origin[2] = spin[11]->get_value();
  1923. emit_changed(get_edited_property(), p, p_name);
  1924. }
  1925. void EditorPropertyTransform::update_property() {
  1926. Transform val = get_edited_object()->get(get_edited_property());
  1927. setting = true;
  1928. spin[0]->set_value(val.basis[0][0]);
  1929. spin[1]->set_value(val.basis[1][0]);
  1930. spin[2]->set_value(val.basis[2][0]);
  1931. spin[3]->set_value(val.basis[0][1]);
  1932. spin[4]->set_value(val.basis[1][1]);
  1933. spin[5]->set_value(val.basis[2][1]);
  1934. spin[6]->set_value(val.basis[0][2]);
  1935. spin[7]->set_value(val.basis[1][2]);
  1936. spin[8]->set_value(val.basis[2][2]);
  1937. spin[9]->set_value(val.origin[0]);
  1938. spin[10]->set_value(val.origin[1]);
  1939. spin[11]->set_value(val.origin[2]);
  1940. setting = false;
  1941. }
  1942. void EditorPropertyTransform::_notification(int p_what) {
  1943. if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
  1944. Color base = get_color("accent_color", "Editor");
  1945. for (int i = 0; i < 12; i++) {
  1946. Color c = base;
  1947. c.set_hsv(float(i % 3) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v());
  1948. spin[i]->set_custom_label_color(true, c);
  1949. }
  1950. }
  1951. }
  1952. void EditorPropertyTransform::_bind_methods() {
  1953. ClassDB::bind_method(D_METHOD("_value_changed"), &EditorPropertyTransform::_value_changed);
  1954. }
  1955. void EditorPropertyTransform::setup(double p_min, double p_max, double p_step, bool p_no_slider) {
  1956. for (int i = 0; i < 12; i++) {
  1957. spin[i]->set_min(p_min);
  1958. spin[i]->set_max(p_max);
  1959. spin[i]->set_step(p_step);
  1960. spin[i]->set_hide_slider(p_no_slider);
  1961. spin[i]->set_allow_greater(true);
  1962. spin[i]->set_allow_lesser(true);
  1963. }
  1964. }
  1965. EditorPropertyTransform::EditorPropertyTransform() {
  1966. GridContainer *g = memnew(GridContainer);
  1967. g->set_columns(3);
  1968. add_child(g);
  1969. static const char *desc[12] = { "x", "y", "z", "x", "y", "z", "x", "y", "z", "x", "y", "z" };
  1970. for (int i = 0; i < 12; i++) {
  1971. spin[i] = memnew(EditorSpinSlider);
  1972. spin[i]->set_label(desc[i]);
  1973. spin[i]->set_flat(true);
  1974. g->add_child(spin[i]);
  1975. spin[i]->set_h_size_flags(SIZE_EXPAND_FILL);
  1976. add_focusable(spin[i]);
  1977. spin[i]->connect("value_changed", this, "_value_changed", varray(desc[i]));
  1978. }
  1979. set_bottom_editor(g);
  1980. setting = false;
  1981. }
  1982. ////////////// COLOR PICKER //////////////////////
  1983. void EditorPropertyColor::_color_changed(const Color &p_color) {
  1984. // Cancel the color change if the current color is identical to the new one.
  1985. if (get_edited_object()->get(get_edited_property()) == p_color) {
  1986. return;
  1987. }
  1988. emit_changed(get_edited_property(), p_color, "", true);
  1989. }
  1990. void EditorPropertyColor::_popup_closed() {
  1991. if (picker->get_pick_color() != last_color) {
  1992. emit_changed(get_edited_property(), picker->get_pick_color(), "", false);
  1993. }
  1994. }
  1995. void EditorPropertyColor::_picker_created() {
  1996. // get default color picker mode from editor settings
  1997. int default_color_mode = EDITOR_GET("interface/inspector/default_color_picker_mode");
  1998. if (default_color_mode == 1) {
  1999. picker->get_picker()->set_hsv_mode(true);
  2000. } else if (default_color_mode == 2) {
  2001. picker->get_picker()->set_raw_mode(true);
  2002. }
  2003. }
  2004. void EditorPropertyColor::_picker_opening() {
  2005. last_color = picker->get_pick_color();
  2006. }
  2007. void EditorPropertyColor::_bind_methods() {
  2008. ClassDB::bind_method(D_METHOD("_color_changed"), &EditorPropertyColor::_color_changed);
  2009. ClassDB::bind_method(D_METHOD("_popup_closed"), &EditorPropertyColor::_popup_closed);
  2010. ClassDB::bind_method(D_METHOD("_picker_created"), &EditorPropertyColor::_picker_created);
  2011. ClassDB::bind_method(D_METHOD("_picker_opening"), &EditorPropertyColor::_picker_opening);
  2012. }
  2013. void EditorPropertyColor::update_property() {
  2014. picker->set_pick_color(get_edited_object()->get(get_edited_property()));
  2015. const Color color = picker->get_pick_color();
  2016. // Add a tooltip to display each channel's values without having to click the ColorPickerButton
  2017. if (picker->is_editing_alpha()) {
  2018. picker->set_tooltip(vformat(
  2019. "R: %s\nG: %s\nB: %s\nA: %s",
  2020. rtos(color.r).pad_decimals(2),
  2021. rtos(color.g).pad_decimals(2),
  2022. rtos(color.b).pad_decimals(2),
  2023. rtos(color.a).pad_decimals(2)));
  2024. } else {
  2025. picker->set_tooltip(vformat(
  2026. "R: %s\nG: %s\nB: %s",
  2027. rtos(color.r).pad_decimals(2),
  2028. rtos(color.g).pad_decimals(2),
  2029. rtos(color.b).pad_decimals(2)));
  2030. }
  2031. }
  2032. void EditorPropertyColor::setup(bool p_show_alpha) {
  2033. picker->set_edit_alpha(p_show_alpha);
  2034. }
  2035. EditorPropertyColor::EditorPropertyColor() {
  2036. picker = memnew(ColorPickerButton);
  2037. add_child(picker);
  2038. picker->set_flat(true);
  2039. picker->connect("color_changed", this, "_color_changed");
  2040. picker->connect("popup_closed", this, "_popup_closed");
  2041. picker->connect("picker_created", this, "_picker_created");
  2042. picker->get_popup()->connect("about_to_show", this, "_picker_opening");
  2043. }
  2044. ////////////// NODE PATH //////////////////////
  2045. void EditorPropertyNodePath::_node_selected(const NodePath &p_path) {
  2046. NodePath path = p_path;
  2047. Node *base_node = nullptr;
  2048. if (!use_path_from_scene_root) {
  2049. base_node = Object::cast_to<Node>(get_edited_object());
  2050. if (!base_node) {
  2051. //try a base node within history
  2052. if (EditorNode::get_singleton()->get_editor_history()->get_path_size() > 0) {
  2053. Object *base = ObjectDB::get_instance(EditorNode::get_singleton()->get_editor_history()->get_path_object(0));
  2054. if (base) {
  2055. base_node = Object::cast_to<Node>(base);
  2056. }
  2057. }
  2058. }
  2059. }
  2060. if (!base_node && get_edited_object()->has_method("get_root_path")) {
  2061. base_node = get_edited_object()->call("get_root_path");
  2062. }
  2063. if (!base_node && Object::cast_to<Reference>(get_edited_object())) {
  2064. Node *to_node = get_node(p_path);
  2065. ERR_FAIL_COND(!to_node);
  2066. path = get_tree()->get_edited_scene_root()->get_path_to(to_node);
  2067. }
  2068. if (base_node) { // for AnimationTrackKeyEdit
  2069. path = base_node->get_path().rel_path_to(p_path);
  2070. }
  2071. emit_changed(get_edited_property(), path);
  2072. update_property();
  2073. }
  2074. void EditorPropertyNodePath::_node_assign() {
  2075. if (!scene_tree) {
  2076. scene_tree = memnew(SceneTreeDialog);
  2077. scene_tree->get_scene_tree()->set_show_enabled_subscene(true);
  2078. scene_tree->get_scene_tree()->set_valid_types(valid_types);
  2079. add_child(scene_tree);
  2080. scene_tree->connect("selected", this, "_node_selected");
  2081. }
  2082. scene_tree->popup_centered_ratio();
  2083. }
  2084. void EditorPropertyNodePath::_node_clear() {
  2085. emit_changed(get_edited_property(), NodePath());
  2086. update_property();
  2087. }
  2088. bool EditorPropertyNodePath::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
  2089. return !is_read_only() && is_drop_valid(p_data);
  2090. }
  2091. void EditorPropertyNodePath::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
  2092. ERR_FAIL_COND(!is_drop_valid(p_data));
  2093. Dictionary data = p_data;
  2094. Array nodes = data["nodes"];
  2095. Node *node = get_tree()->get_edited_scene_root()->get_node(nodes[0]);
  2096. if (node) {
  2097. _node_selected(node->get_path());
  2098. }
  2099. }
  2100. bool EditorPropertyNodePath::is_drop_valid(const Dictionary &p_drag_data) const {
  2101. if (p_drag_data["type"] != "nodes") {
  2102. return false;
  2103. }
  2104. Array nodes = p_drag_data["nodes"];
  2105. return nodes.size() == 1;
  2106. }
  2107. void EditorPropertyNodePath::update_property() {
  2108. NodePath p = get_edited_object()->get(get_edited_property());
  2109. assign->set_tooltip(p);
  2110. if (p == NodePath()) {
  2111. assign->set_icon(Ref<Texture>());
  2112. assign->set_text(TTR("Assign..."));
  2113. assign->set_flat(false);
  2114. return;
  2115. }
  2116. assign->set_flat(true);
  2117. Node *base_node = nullptr;
  2118. if (base_hint != NodePath()) {
  2119. if (get_tree()->get_root()->has_node(base_hint)) {
  2120. base_node = get_tree()->get_root()->get_node(base_hint);
  2121. }
  2122. } else {
  2123. base_node = Object::cast_to<Node>(get_edited_object());
  2124. }
  2125. if (!base_node || !base_node->has_node(p)) {
  2126. assign->set_icon(Ref<Texture>());
  2127. assign->set_text(p);
  2128. return;
  2129. }
  2130. Node *target_node = base_node->get_node(p);
  2131. ERR_FAIL_COND(!target_node);
  2132. if (String(target_node->get_name()).find("@") != -1) {
  2133. assign->set_icon(Ref<Texture>());
  2134. assign->set_text(p);
  2135. return;
  2136. }
  2137. assign->set_text(target_node->get_name());
  2138. assign->set_icon(EditorNode::get_singleton()->get_object_icon(target_node, "Node"));
  2139. }
  2140. void EditorPropertyNodePath::setup(const NodePath &p_base_hint, Vector<StringName> p_valid_types, bool p_use_path_from_scene_root) {
  2141. base_hint = p_base_hint;
  2142. valid_types = p_valid_types;
  2143. use_path_from_scene_root = p_use_path_from_scene_root;
  2144. }
  2145. void EditorPropertyNodePath::_notification(int p_what) {
  2146. if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
  2147. Ref<Texture> t = get_icon("Clear", "EditorIcons");
  2148. clear->set_icon(t);
  2149. }
  2150. }
  2151. void EditorPropertyNodePath::_bind_methods() {
  2152. ClassDB::bind_method(D_METHOD("_node_selected"), &EditorPropertyNodePath::_node_selected);
  2153. ClassDB::bind_method(D_METHOD("_node_assign"), &EditorPropertyNodePath::_node_assign);
  2154. ClassDB::bind_method(D_METHOD("_node_clear"), &EditorPropertyNodePath::_node_clear);
  2155. ClassDB::bind_method(D_METHOD("can_drop_data_fw", "position", "data", "from"), &EditorPropertyNodePath::can_drop_data_fw);
  2156. ClassDB::bind_method(D_METHOD("drop_data_fw", "position", "data", "from"), &EditorPropertyNodePath::drop_data_fw);
  2157. }
  2158. EditorPropertyNodePath::EditorPropertyNodePath() {
  2159. HBoxContainer *hbc = memnew(HBoxContainer);
  2160. hbc->add_constant_override("separation", 0);
  2161. add_child(hbc);
  2162. assign = memnew(Button);
  2163. assign->set_flat(true);
  2164. assign->set_h_size_flags(SIZE_EXPAND_FILL);
  2165. assign->set_clip_text(true);
  2166. assign->connect("pressed", this, "_node_assign");
  2167. assign->set_drag_forwarding(this);
  2168. hbc->add_child(assign);
  2169. clear = memnew(Button);
  2170. clear->set_flat(true);
  2171. clear->connect("pressed", this, "_node_clear");
  2172. hbc->add_child(clear);
  2173. use_path_from_scene_root = false;
  2174. scene_tree = nullptr; //do not allocate unnecessarily
  2175. }
  2176. ///////////////////// RID /////////////////////////
  2177. void EditorPropertyRID::update_property() {
  2178. RID rid = get_edited_object()->get(get_edited_property());
  2179. if (rid.is_valid()) {
  2180. int id = rid.get_id();
  2181. label->set_text("RID: " + itos(id));
  2182. } else {
  2183. label->set_text(TTR("Invalid RID"));
  2184. }
  2185. }
  2186. EditorPropertyRID::EditorPropertyRID() {
  2187. label = memnew(Label);
  2188. add_child(label);
  2189. }
  2190. ////////////// RESOURCE //////////////////////
  2191. void EditorPropertyResource::_resource_selected(const RES &p_resource, bool p_edit) {
  2192. if (!p_edit && _can_use_sub_inspector(p_resource)) {
  2193. bool unfold = !get_edited_object()->editor_is_section_unfolded(get_edited_property());
  2194. get_edited_object()->editor_set_section_unfold(get_edited_property(), unfold);
  2195. update_property();
  2196. } else {
  2197. emit_signal("resource_selected", get_edited_property(), p_resource);
  2198. }
  2199. }
  2200. void EditorPropertyResource::_resource_changed(const RES &p_resource) {
  2201. // Make visual script the correct type.
  2202. Ref<Script> s = p_resource;
  2203. bool is_script = false;
  2204. if (get_edited_object() && s.is_valid()) {
  2205. is_script = true;
  2206. EditorNode::get_singleton()->get_inspector_dock()->store_script_properties(get_edited_object());
  2207. s->call("set_instance_base_type", get_edited_object()->get_class());
  2208. }
  2209. // Prevent the creation of invalid ViewportTextures when possible.
  2210. Ref<ViewportTexture> vpt = p_resource;
  2211. if (vpt.is_valid()) {
  2212. Resource *r = Object::cast_to<Resource>(get_edited_object());
  2213. if (r && r->get_path().is_resource_file()) {
  2214. EditorNode::get_singleton()->show_warning(TTR("Can't create a ViewportTexture on resources saved as a file.\nResource needs to belong to a scene."));
  2215. emit_changed(get_edited_property(), RES());
  2216. update_property();
  2217. return;
  2218. }
  2219. if (r && !r->is_local_to_scene()) {
  2220. 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)."));
  2221. emit_changed(get_edited_property(), RES());
  2222. update_property();
  2223. return;
  2224. }
  2225. }
  2226. emit_changed(get_edited_property(), p_resource);
  2227. update_property();
  2228. if (is_script) {
  2229. // Restore properties if script was changed.
  2230. EditorNode::get_singleton()->get_inspector_dock()->apply_script_properties(get_edited_object());
  2231. }
  2232. // Automatically suggest setting up the path for a ViewportTexture.
  2233. if (vpt.is_valid() && vpt->get_viewport_path_in_scene().is_empty()) {
  2234. if (!scene_tree) {
  2235. scene_tree = memnew(SceneTreeDialog);
  2236. scene_tree->set_title(TTR("Pick a Viewport"));
  2237. Vector<StringName> valid_types;
  2238. valid_types.push_back("Viewport");
  2239. scene_tree->get_scene_tree()->set_valid_types(valid_types);
  2240. scene_tree->get_scene_tree()->set_show_enabled_subscene(true);
  2241. add_child(scene_tree);
  2242. scene_tree->connect("selected", this, "_viewport_selected");
  2243. }
  2244. scene_tree->popup_centered_ratio();
  2245. }
  2246. }
  2247. void EditorPropertyResource::_sub_inspector_property_keyed(const String &p_property, const Variant &p_value, bool) {
  2248. emit_signal("property_keyed_with_value", String(get_edited_property()) + ":" + p_property, p_value, false);
  2249. }
  2250. void EditorPropertyResource::_sub_inspector_resource_selected(const RES &p_resource, const String &p_property) {
  2251. emit_signal("resource_selected", String(get_edited_property()) + ":" + p_property, p_resource);
  2252. }
  2253. void EditorPropertyResource::_sub_inspector_object_id_selected(int p_id) {
  2254. emit_signal("object_id_selected", get_edited_property(), p_id);
  2255. }
  2256. void EditorPropertyResource::_open_editor_pressed() {
  2257. RES res = get_edited_object()->get(get_edited_property());
  2258. if (res.is_valid()) {
  2259. // May clear the editor so do it deferred.
  2260. EditorNode::get_singleton()->call_deferred("edit_item_resource", res);
  2261. }
  2262. }
  2263. void EditorPropertyResource::_fold_other_editors(Object *p_self) {
  2264. if (this == p_self) {
  2265. return;
  2266. }
  2267. RES res = get_edited_object()->get(get_edited_property());
  2268. if (!res.is_valid()) {
  2269. return;
  2270. }
  2271. bool use_editor = false;
  2272. for (int i = 0; i < EditorNode::get_editor_data().get_editor_plugin_count(); i++) {
  2273. EditorPlugin *ep = EditorNode::get_editor_data().get_editor_plugin(i);
  2274. if (ep->handles(res.ptr())) {
  2275. use_editor = true;
  2276. }
  2277. }
  2278. if (!use_editor) {
  2279. return;
  2280. }
  2281. opened_editor = false;
  2282. bool unfolded = get_edited_object()->editor_is_section_unfolded(get_edited_property());
  2283. if (unfolded) {
  2284. // Refold.
  2285. resource_picker->set_toggle_pressed(false);
  2286. get_edited_object()->editor_set_section_unfold(get_edited_property(), false);
  2287. update_property();
  2288. }
  2289. }
  2290. void EditorPropertyResource::_update_property_bg() {
  2291. if (!is_inside_tree()) {
  2292. return;
  2293. }
  2294. updating_theme = true;
  2295. if (sub_inspector != nullptr) {
  2296. int count_subinspectors = 0;
  2297. Node *n = get_parent();
  2298. while (n) {
  2299. EditorInspector *ei = Object::cast_to<EditorInspector>(n);
  2300. if (ei && ei->is_sub_inspector()) {
  2301. count_subinspectors++;
  2302. }
  2303. n = n->get_parent();
  2304. }
  2305. count_subinspectors = MIN(15, count_subinspectors);
  2306. add_color_override("property_color", get_color("sub_inspector_property_color", "Editor"));
  2307. add_style_override("bg_selected", get_stylebox("sub_inspector_property_bg_selected" + itos(count_subinspectors), "Editor"));
  2308. add_style_override("bg", get_stylebox("sub_inspector_property_bg" + itos(count_subinspectors), "Editor"));
  2309. add_constant_override("font_offset", get_constant("sub_inspector_font_offset", "Editor"));
  2310. add_constant_override("vseparation", 0);
  2311. } else {
  2312. add_color_override("property_color", get_color("property_color", "EditorProperty"));
  2313. add_style_override("bg_selected", get_stylebox("bg_selected", "EditorProperty"));
  2314. add_style_override("bg", get_stylebox("bg", "EditorProperty"));
  2315. add_constant_override("vseparation", get_constant("vseparation", "EditorProperty"));
  2316. add_constant_override("font_offset", get_constant("font_offset", "EditorProperty"));
  2317. }
  2318. updating_theme = false;
  2319. update();
  2320. }
  2321. void EditorPropertyResource::_viewport_selected(const NodePath &p_path) {
  2322. Node *to_node = get_node(p_path);
  2323. if (!Object::cast_to<Viewport>(to_node)) {
  2324. EditorNode::get_singleton()->show_warning(TTR("Selected node is not a Viewport!"));
  2325. return;
  2326. }
  2327. Ref<ViewportTexture> vt;
  2328. vt.instance();
  2329. vt->set_viewport_path_in_scene(get_tree()->get_edited_scene_root()->get_path_to(to_node));
  2330. vt->setup_local_to_scene();
  2331. emit_changed(get_edited_property(), vt);
  2332. update_property();
  2333. }
  2334. bool EditorPropertyResource::_can_use_sub_inspector(const RES &p_resource) {
  2335. bool use_editor = false;
  2336. if (p_resource.is_valid()) {
  2337. for (int i = 0; i < EditorNode::get_editor_data().get_editor_plugin_count(); i++) {
  2338. EditorPlugin *ep = EditorNode::get_editor_data().get_editor_plugin(i);
  2339. if (ep->handles((Resource *)p_resource.ptr())) {
  2340. use_editor = true;
  2341. }
  2342. }
  2343. }
  2344. return !use_editor && use_sub_inspector;
  2345. }
  2346. void EditorPropertyResource::setup(Object *p_object, const String &p_path, const String &p_base_type) {
  2347. if (resource_picker) {
  2348. resource_picker->disconnect("resource_selected", this, "_resource_selected");
  2349. resource_picker->disconnect("resource_changed", this, "_resource_changed");
  2350. memdelete(resource_picker);
  2351. }
  2352. if (p_path == "script" && p_base_type == "Script" && Object::cast_to<Node>(p_object)) {
  2353. EditorScriptPicker *script_picker = memnew(EditorScriptPicker);
  2354. script_picker->set_script_owner(Object::cast_to<Node>(p_object));
  2355. resource_picker = script_picker;
  2356. } else {
  2357. resource_picker = memnew(EditorResourcePicker);
  2358. }
  2359. resource_picker->set_base_type(p_base_type);
  2360. resource_picker->set_editable(true);
  2361. resource_picker->set_h_size_flags(SIZE_EXPAND_FILL);
  2362. add_child(resource_picker);
  2363. resource_picker->connect("resource_selected", this, "_resource_selected");
  2364. resource_picker->connect("resource_changed", this, "_resource_changed");
  2365. for (int i = 0; i < resource_picker->get_child_count(); i++) {
  2366. Button *b = Object::cast_to<Button>(resource_picker->get_child(i));
  2367. if (b) {
  2368. add_focusable(b);
  2369. }
  2370. }
  2371. }
  2372. void EditorPropertyResource::update_property() {
  2373. RES res = get_edited_object()->get(get_edited_property());
  2374. if (_can_use_sub_inspector(res)) {
  2375. if (res.is_valid() != resource_picker->is_toggle_mode()) {
  2376. resource_picker->set_toggle_mode(res.is_valid());
  2377. }
  2378. if (res.is_valid() && get_edited_object()->editor_is_section_unfolded(get_edited_property())) {
  2379. if (!sub_inspector) {
  2380. sub_inspector = memnew(EditorInspector);
  2381. sub_inspector->set_enable_v_scroll(false);
  2382. sub_inspector->set_use_doc_hints(true);
  2383. sub_inspector->set_sub_inspector(true);
  2384. sub_inspector->set_property_name_style(EditorNode::get_singleton()->get_inspector_dock()->get_property_name_style());
  2385. sub_inspector->connect("property_keyed", this, "_sub_inspector_property_keyed");
  2386. sub_inspector->connect("resource_selected", this, "_sub_inspector_resource_selected");
  2387. sub_inspector->connect("object_id_selected", this, "_sub_inspector_object_id_selected");
  2388. sub_inspector->set_keying(is_keying());
  2389. sub_inspector->set_read_only(is_read_only());
  2390. sub_inspector->set_use_folding(is_using_folding());
  2391. sub_inspector->set_undo_redo(EditorNode::get_undo_redo());
  2392. sub_inspector_vbox = memnew(VBoxContainer);
  2393. add_child(sub_inspector_vbox);
  2394. set_bottom_editor(sub_inspector_vbox);
  2395. sub_inspector_vbox->add_child(sub_inspector);
  2396. resource_picker->set_toggle_pressed(true);
  2397. _update_property_bg();
  2398. }
  2399. if (res.ptr() != sub_inspector->get_edited_object()) {
  2400. sub_inspector->edit(res.ptr());
  2401. }
  2402. sub_inspector->refresh();
  2403. } else {
  2404. if (sub_inspector) {
  2405. set_bottom_editor(nullptr);
  2406. memdelete(sub_inspector_vbox);
  2407. sub_inspector = nullptr;
  2408. sub_inspector_vbox = nullptr;
  2409. if (opened_editor) {
  2410. EditorNode::get_singleton()->hide_top_editors();
  2411. opened_editor = false;
  2412. }
  2413. _update_property_bg();
  2414. }
  2415. }
  2416. }
  2417. resource_picker->set_edited_resource(res);
  2418. }
  2419. void EditorPropertyResource::collapse_all_folding() {
  2420. if (sub_inspector) {
  2421. sub_inspector->collapse_all_folding();
  2422. }
  2423. }
  2424. void EditorPropertyResource::expand_all_folding() {
  2425. if (sub_inspector) {
  2426. sub_inspector->expand_all_folding();
  2427. }
  2428. }
  2429. void EditorPropertyResource::set_use_sub_inspector(bool p_enable) {
  2430. use_sub_inspector = p_enable;
  2431. }
  2432. void EditorPropertyResource::_notification(int p_what) {
  2433. switch (p_what) {
  2434. case NOTIFICATION_ENTER_TREE:
  2435. case NOTIFICATION_THEME_CHANGED: {
  2436. if (!updating_theme) {
  2437. _update_property_bg();
  2438. }
  2439. } break;
  2440. }
  2441. }
  2442. void EditorPropertyResource::_bind_methods() {
  2443. ClassDB::bind_method(D_METHOD("_resource_selected"), &EditorPropertyResource::_resource_selected);
  2444. ClassDB::bind_method(D_METHOD("_resource_changed"), &EditorPropertyResource::_resource_changed);
  2445. ClassDB::bind_method(D_METHOD("_viewport_selected"), &EditorPropertyResource::_viewport_selected);
  2446. ClassDB::bind_method(D_METHOD("_sub_inspector_property_keyed"), &EditorPropertyResource::_sub_inspector_property_keyed);
  2447. ClassDB::bind_method(D_METHOD("_sub_inspector_resource_selected"), &EditorPropertyResource::_sub_inspector_resource_selected);
  2448. ClassDB::bind_method(D_METHOD("_sub_inspector_object_id_selected"), &EditorPropertyResource::_sub_inspector_object_id_selected);
  2449. ClassDB::bind_method(D_METHOD("_open_editor_pressed"), &EditorPropertyResource::_open_editor_pressed);
  2450. ClassDB::bind_method(D_METHOD("_fold_other_editors"), &EditorPropertyResource::_fold_other_editors);
  2451. }
  2452. EditorPropertyResource::EditorPropertyResource() {
  2453. use_sub_inspector = bool(EDITOR_GET("interface/inspector/open_resources_in_current_inspector"));
  2454. add_to_group("_editor_resource_properties");
  2455. }
  2456. ////////////// DEFAULT PLUGIN //////////////////////
  2457. bool EditorInspectorDefaultPlugin::can_handle(Object *p_object) {
  2458. return true; //can handle everything
  2459. }
  2460. void EditorInspectorDefaultPlugin::parse_begin(Object *p_object) {
  2461. //do none
  2462. }
  2463. bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, int p_usage) {
  2464. double default_float_step = EDITOR_GET("interface/inspector/default_float_step");
  2465. switch (p_type) {
  2466. // atomic types
  2467. case Variant::NIL: {
  2468. EditorPropertyNil *editor = memnew(EditorPropertyNil);
  2469. add_property_editor(p_path, editor);
  2470. } break;
  2471. case Variant::BOOL: {
  2472. EditorPropertyCheck *editor = memnew(EditorPropertyCheck);
  2473. add_property_editor(p_path, editor);
  2474. } break;
  2475. case Variant::INT: {
  2476. if (p_hint == PROPERTY_HINT_ENUM) {
  2477. EditorPropertyEnum *editor = memnew(EditorPropertyEnum);
  2478. Vector<String> options = p_hint_text.split(",");
  2479. editor->setup(options);
  2480. add_property_editor(p_path, editor);
  2481. } else if (p_hint == PROPERTY_HINT_FLAGS) {
  2482. EditorPropertyFlags *editor = memnew(EditorPropertyFlags);
  2483. Vector<String> options = p_hint_text.split(",");
  2484. editor->setup(options);
  2485. add_property_editor(p_path, editor);
  2486. } else if (p_hint == PROPERTY_HINT_LAYERS_2D_PHYSICS || p_hint == PROPERTY_HINT_LAYERS_2D_RENDER || p_hint == PROPERTY_HINT_LAYERS_2D_NAVIGATION || p_hint == PROPERTY_HINT_LAYERS_3D_PHYSICS || p_hint == PROPERTY_HINT_LAYERS_3D_RENDER || p_hint == PROPERTY_HINT_LAYERS_3D_NAVIGATION) {
  2487. EditorPropertyLayers::LayerType lt = EditorPropertyLayers::LAYER_RENDER_2D;
  2488. switch (p_hint) {
  2489. case PROPERTY_HINT_LAYERS_2D_RENDER:
  2490. lt = EditorPropertyLayers::LAYER_RENDER_2D;
  2491. break;
  2492. case PROPERTY_HINT_LAYERS_2D_PHYSICS:
  2493. lt = EditorPropertyLayers::LAYER_PHYSICS_2D;
  2494. break;
  2495. case PROPERTY_HINT_LAYERS_2D_NAVIGATION:
  2496. lt = EditorPropertyLayers::LAYER_NAVIGATION_2D;
  2497. break;
  2498. case PROPERTY_HINT_LAYERS_3D_RENDER:
  2499. lt = EditorPropertyLayers::LAYER_RENDER_3D;
  2500. break;
  2501. case PROPERTY_HINT_LAYERS_3D_PHYSICS:
  2502. lt = EditorPropertyLayers::LAYER_PHYSICS_3D;
  2503. break;
  2504. case PROPERTY_HINT_LAYERS_3D_NAVIGATION:
  2505. lt = EditorPropertyLayers::LAYER_NAVIGATION_3D;
  2506. break;
  2507. default: {
  2508. } //compiler could be smarter here and realize this can't happen
  2509. }
  2510. EditorPropertyLayers *editor = memnew(EditorPropertyLayers);
  2511. editor->setup(lt);
  2512. add_property_editor(p_path, editor);
  2513. } else if (p_hint == PROPERTY_HINT_OBJECT_ID) {
  2514. EditorPropertyObjectID *editor = memnew(EditorPropertyObjectID);
  2515. editor->setup(p_hint_text);
  2516. add_property_editor(p_path, editor);
  2517. } else {
  2518. EditorPropertyInteger *editor = memnew(EditorPropertyInteger);
  2519. int min = 0, max = 65535, step = 1;
  2520. bool greater = true, lesser = true;
  2521. Vector<String> slices = p_hint_text.split(",");
  2522. if (p_hint == PROPERTY_HINT_RANGE && slices.size() >= 2) {
  2523. greater = false; // If using ranged, assume false by default.
  2524. lesser = false;
  2525. min = slices[0].to_int();
  2526. max = slices[1].to_int();
  2527. if (slices.size() >= 3 && slices[2].is_valid_integer()) {
  2528. // Step is optional, could be something else if not a number.
  2529. step = slices[2].to_int();
  2530. }
  2531. for (int i = 2; i < slices.size(); i++) {
  2532. String slice = slices[i].strip_edges();
  2533. if (slice == "or_greater") {
  2534. greater = true;
  2535. }
  2536. if (slice == "or_lesser") {
  2537. lesser = true;
  2538. }
  2539. }
  2540. }
  2541. editor->setup(min, max, step, greater, lesser);
  2542. add_property_editor(p_path, editor);
  2543. }
  2544. } break;
  2545. case Variant::REAL: {
  2546. if (p_hint == PROPERTY_HINT_EXP_EASING) {
  2547. EditorPropertyEasing *editor = memnew(EditorPropertyEasing);
  2548. bool full = true;
  2549. bool flip = false;
  2550. Vector<String> hints = p_hint_text.split(",");
  2551. for (int i = 0; i < hints.size(); i++) {
  2552. String h = hints[i].strip_edges();
  2553. if (h == "attenuation") {
  2554. flip = true;
  2555. }
  2556. if (h == "inout") {
  2557. full = true;
  2558. }
  2559. }
  2560. editor->setup(full, flip);
  2561. add_property_editor(p_path, editor);
  2562. } else {
  2563. EditorPropertyFloat *editor = memnew(EditorPropertyFloat);
  2564. double min = -65535, max = 65535, step = default_float_step;
  2565. bool hide_slider = true;
  2566. bool exp_range = false;
  2567. bool greater = true, lesser = true;
  2568. Vector<String> slices = p_hint_text.split(",");
  2569. if ((p_hint == PROPERTY_HINT_RANGE || p_hint == PROPERTY_HINT_EXP_RANGE) && slices.size() >= 2) {
  2570. greater = false; // If using ranged, assume false by default.
  2571. lesser = false;
  2572. min = slices[0].to_double();
  2573. max = slices[1].to_double();
  2574. if (slices.size() >= 3 && slices[2].is_valid_float()) {
  2575. // Step is optional, could be something else if not a number.
  2576. step = slices[2].to_double();
  2577. }
  2578. hide_slider = false;
  2579. exp_range = p_hint == PROPERTY_HINT_EXP_RANGE;
  2580. for (int i = 2; i < slices.size(); i++) {
  2581. String slice = slices[i].strip_edges();
  2582. if (slice == "or_greater") {
  2583. greater = true;
  2584. }
  2585. if (slice == "or_lesser") {
  2586. lesser = true;
  2587. }
  2588. }
  2589. }
  2590. editor->setup(min, max, step, hide_slider, exp_range, greater, lesser);
  2591. add_property_editor(p_path, editor);
  2592. }
  2593. } break;
  2594. case Variant::STRING: {
  2595. if (p_hint == PROPERTY_HINT_ENUM || p_hint == PROPERTY_HINT_ENUM_SUGGESTION) {
  2596. EditorPropertyTextEnum *editor = memnew(EditorPropertyTextEnum);
  2597. Vector<String> options = p_hint_text.split(",", false);
  2598. editor->setup(options, (p_hint == PROPERTY_HINT_ENUM_SUGGESTION));
  2599. add_property_editor(p_path, editor);
  2600. } else if (p_hint == PROPERTY_HINT_MULTILINE_TEXT) {
  2601. EditorPropertyMultilineText *editor = memnew(EditorPropertyMultilineText);
  2602. add_property_editor(p_path, editor);
  2603. } else if (p_hint == PROPERTY_HINT_TYPE_STRING) {
  2604. EditorPropertyClassName *editor = memnew(EditorPropertyClassName);
  2605. editor->setup("Object", p_hint_text);
  2606. add_property_editor(p_path, editor);
  2607. } else if (p_hint == PROPERTY_HINT_LOCALE_ID) {
  2608. EditorPropertyLocale *editor = memnew(EditorPropertyLocale);
  2609. editor->setup(p_hint_text);
  2610. add_property_editor(p_path, editor);
  2611. } else if (p_hint == PROPERTY_HINT_DIR || p_hint == PROPERTY_HINT_FILE || p_hint == PROPERTY_HINT_SAVE_FILE || p_hint == PROPERTY_HINT_GLOBAL_DIR || p_hint == PROPERTY_HINT_GLOBAL_FILE) {
  2612. Vector<String> extensions = p_hint_text.split(",");
  2613. bool global = p_hint == PROPERTY_HINT_GLOBAL_DIR || p_hint == PROPERTY_HINT_GLOBAL_FILE;
  2614. bool folder = p_hint == PROPERTY_HINT_DIR || p_hint == PROPERTY_HINT_GLOBAL_DIR;
  2615. bool save = p_hint == PROPERTY_HINT_SAVE_FILE;
  2616. EditorPropertyPath *editor = memnew(EditorPropertyPath);
  2617. editor->setup(extensions, folder, global);
  2618. if (save) {
  2619. editor->set_save_mode();
  2620. }
  2621. add_property_editor(p_path, editor);
  2622. } else if (p_hint == PROPERTY_HINT_METHOD_OF_VARIANT_TYPE ||
  2623. p_hint == PROPERTY_HINT_METHOD_OF_BASE_TYPE ||
  2624. p_hint == PROPERTY_HINT_METHOD_OF_INSTANCE ||
  2625. p_hint == PROPERTY_HINT_METHOD_OF_SCRIPT ||
  2626. p_hint == PROPERTY_HINT_PROPERTY_OF_VARIANT_TYPE ||
  2627. p_hint == PROPERTY_HINT_PROPERTY_OF_BASE_TYPE ||
  2628. p_hint == PROPERTY_HINT_PROPERTY_OF_INSTANCE ||
  2629. p_hint == PROPERTY_HINT_PROPERTY_OF_SCRIPT) {
  2630. EditorPropertyMember *editor = memnew(EditorPropertyMember);
  2631. EditorPropertyMember::Type type = EditorPropertyMember::MEMBER_METHOD_OF_BASE_TYPE;
  2632. switch (p_hint) {
  2633. case PROPERTY_HINT_METHOD_OF_BASE_TYPE:
  2634. type = EditorPropertyMember::MEMBER_METHOD_OF_BASE_TYPE;
  2635. break;
  2636. case PROPERTY_HINT_METHOD_OF_INSTANCE:
  2637. type = EditorPropertyMember::MEMBER_METHOD_OF_INSTANCE;
  2638. break;
  2639. case PROPERTY_HINT_METHOD_OF_SCRIPT:
  2640. type = EditorPropertyMember::MEMBER_METHOD_OF_SCRIPT;
  2641. break;
  2642. case PROPERTY_HINT_PROPERTY_OF_VARIANT_TYPE:
  2643. type = EditorPropertyMember::MEMBER_PROPERTY_OF_VARIANT_TYPE;
  2644. break;
  2645. case PROPERTY_HINT_PROPERTY_OF_BASE_TYPE:
  2646. type = EditorPropertyMember::MEMBER_PROPERTY_OF_BASE_TYPE;
  2647. break;
  2648. case PROPERTY_HINT_PROPERTY_OF_INSTANCE:
  2649. type = EditorPropertyMember::MEMBER_PROPERTY_OF_INSTANCE;
  2650. break;
  2651. case PROPERTY_HINT_PROPERTY_OF_SCRIPT:
  2652. type = EditorPropertyMember::MEMBER_PROPERTY_OF_SCRIPT;
  2653. break;
  2654. default: {
  2655. }
  2656. }
  2657. editor->setup(type, p_hint_text);
  2658. add_property_editor(p_path, editor);
  2659. } else {
  2660. EditorPropertyText *editor = memnew(EditorPropertyText);
  2661. if (p_hint == PROPERTY_HINT_PLACEHOLDER_TEXT) {
  2662. editor->set_placeholder(p_hint_text);
  2663. }
  2664. add_property_editor(p_path, editor);
  2665. }
  2666. } break;
  2667. // math types
  2668. case Variant::VECTOR2: {
  2669. EditorPropertyVector2 *editor = memnew(EditorPropertyVector2);
  2670. double min = -65535, max = 65535, step = default_float_step;
  2671. bool hide_slider = true;
  2672. if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) {
  2673. min = p_hint_text.get_slice(",", 0).to_double();
  2674. max = p_hint_text.get_slice(",", 1).to_double();
  2675. if (p_hint_text.get_slice_count(",") >= 3) {
  2676. step = p_hint_text.get_slice(",", 2).to_double();
  2677. }
  2678. hide_slider = false;
  2679. }
  2680. editor->setup(min, max, step, hide_slider, p_hint == PROPERTY_HINT_LINK);
  2681. add_property_editor(p_path, editor);
  2682. } break; // 5
  2683. case Variant::RECT2: {
  2684. EditorPropertyRect2 *editor = memnew(EditorPropertyRect2);
  2685. double min = -65535, max = 65535, step = default_float_step;
  2686. bool hide_slider = true;
  2687. if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) {
  2688. min = p_hint_text.get_slice(",", 0).to_double();
  2689. max = p_hint_text.get_slice(",", 1).to_double();
  2690. if (p_hint_text.get_slice_count(",") >= 3) {
  2691. step = p_hint_text.get_slice(",", 2).to_double();
  2692. }
  2693. hide_slider = false;
  2694. }
  2695. editor->setup(min, max, step, hide_slider);
  2696. add_property_editor(p_path, editor);
  2697. } break;
  2698. case Variant::VECTOR3: {
  2699. EditorPropertyVector3 *editor = memnew(EditorPropertyVector3);
  2700. double min = -65535, max = 65535, step = default_float_step;
  2701. bool hide_slider = true;
  2702. if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) {
  2703. min = p_hint_text.get_slice(",", 0).to_double();
  2704. max = p_hint_text.get_slice(",", 1).to_double();
  2705. if (p_hint_text.get_slice_count(",") >= 3) {
  2706. step = p_hint_text.get_slice(",", 2).to_double();
  2707. }
  2708. hide_slider = false;
  2709. }
  2710. editor->setup(min, max, step, hide_slider, p_hint == PROPERTY_HINT_LINK);
  2711. add_property_editor(p_path, editor);
  2712. } break;
  2713. case Variant::TRANSFORM2D: {
  2714. EditorPropertyTransform2D *editor = memnew(EditorPropertyTransform2D);
  2715. double min = -65535, max = 65535, step = default_float_step;
  2716. bool hide_slider = true;
  2717. if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) {
  2718. min = p_hint_text.get_slice(",", 0).to_double();
  2719. max = p_hint_text.get_slice(",", 1).to_double();
  2720. if (p_hint_text.get_slice_count(",") >= 3) {
  2721. step = p_hint_text.get_slice(",", 2).to_double();
  2722. }
  2723. hide_slider = false;
  2724. }
  2725. editor->setup(min, max, step, hide_slider);
  2726. add_property_editor(p_path, editor);
  2727. } break;
  2728. case Variant::PLANE: {
  2729. EditorPropertyPlane *editor = memnew(EditorPropertyPlane);
  2730. double min = -65535, max = 65535, step = default_float_step;
  2731. bool hide_slider = true;
  2732. if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) {
  2733. min = p_hint_text.get_slice(",", 0).to_double();
  2734. max = p_hint_text.get_slice(",", 1).to_double();
  2735. if (p_hint_text.get_slice_count(",") >= 3) {
  2736. step = p_hint_text.get_slice(",", 2).to_double();
  2737. }
  2738. hide_slider = false;
  2739. }
  2740. editor->setup(min, max, step, hide_slider);
  2741. add_property_editor(p_path, editor);
  2742. } break;
  2743. case Variant::QUAT: {
  2744. EditorPropertyQuat *editor = memnew(EditorPropertyQuat);
  2745. double min = -65535, max = 65535, step = default_float_step;
  2746. bool hide_slider = true;
  2747. if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) {
  2748. min = p_hint_text.get_slice(",", 0).to_double();
  2749. max = p_hint_text.get_slice(",", 1).to_double();
  2750. if (p_hint_text.get_slice_count(",") >= 3) {
  2751. step = p_hint_text.get_slice(",", 2).to_double();
  2752. }
  2753. hide_slider = false;
  2754. }
  2755. editor->setup(min, max, step, hide_slider);
  2756. add_property_editor(p_path, editor);
  2757. } break; // 10
  2758. case Variant::AABB: {
  2759. EditorPropertyAABB *editor = memnew(EditorPropertyAABB);
  2760. double min = -65535, max = 65535, step = default_float_step;
  2761. bool hide_slider = true;
  2762. if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) {
  2763. min = p_hint_text.get_slice(",", 0).to_double();
  2764. max = p_hint_text.get_slice(",", 1).to_double();
  2765. if (p_hint_text.get_slice_count(",") >= 3) {
  2766. step = p_hint_text.get_slice(",", 2).to_double();
  2767. }
  2768. hide_slider = false;
  2769. }
  2770. editor->setup(min, max, step, hide_slider);
  2771. add_property_editor(p_path, editor);
  2772. } break;
  2773. case Variant::BASIS: {
  2774. EditorPropertyBasis *editor = memnew(EditorPropertyBasis);
  2775. double min = -65535, max = 65535, step = default_float_step;
  2776. bool hide_slider = true;
  2777. if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) {
  2778. min = p_hint_text.get_slice(",", 0).to_double();
  2779. max = p_hint_text.get_slice(",", 1).to_double();
  2780. if (p_hint_text.get_slice_count(",") >= 3) {
  2781. step = p_hint_text.get_slice(",", 2).to_double();
  2782. }
  2783. hide_slider = false;
  2784. }
  2785. editor->setup(min, max, step, hide_slider);
  2786. add_property_editor(p_path, editor);
  2787. } break;
  2788. case Variant::TRANSFORM: {
  2789. EditorPropertyTransform *editor = memnew(EditorPropertyTransform);
  2790. double min = -65535, max = 65535, step = default_float_step;
  2791. bool hide_slider = true;
  2792. if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) {
  2793. min = p_hint_text.get_slice(",", 0).to_double();
  2794. max = p_hint_text.get_slice(",", 1).to_double();
  2795. if (p_hint_text.get_slice_count(",") >= 3) {
  2796. step = p_hint_text.get_slice(",", 2).to_double();
  2797. }
  2798. hide_slider = false;
  2799. }
  2800. editor->setup(min, max, step, hide_slider);
  2801. add_property_editor(p_path, editor);
  2802. } break;
  2803. // misc types
  2804. case Variant::COLOR: {
  2805. EditorPropertyColor *editor = memnew(EditorPropertyColor);
  2806. editor->setup(p_hint != PROPERTY_HINT_COLOR_NO_ALPHA);
  2807. add_property_editor(p_path, editor);
  2808. } break;
  2809. case Variant::NODE_PATH: {
  2810. EditorPropertyNodePath *editor = memnew(EditorPropertyNodePath);
  2811. if (p_hint == PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE && p_hint_text != String()) {
  2812. editor->setup(p_hint_text, Vector<StringName>(), (p_usage & PROPERTY_USAGE_NODE_PATH_FROM_SCENE_ROOT));
  2813. }
  2814. if (p_hint == PROPERTY_HINT_NODE_PATH_VALID_TYPES && p_hint_text != String()) {
  2815. Vector<String> types = p_hint_text.split(",", false);
  2816. Vector<StringName> sn = Variant(types); //convert via variant
  2817. editor->setup(NodePath(), sn, (p_usage & PROPERTY_USAGE_NODE_PATH_FROM_SCENE_ROOT));
  2818. }
  2819. add_property_editor(p_path, editor);
  2820. } break; // 15
  2821. case Variant::_RID: {
  2822. EditorPropertyRID *editor = memnew(EditorPropertyRID);
  2823. add_property_editor(p_path, editor);
  2824. } break;
  2825. case Variant::OBJECT: {
  2826. EditorPropertyResource *editor = memnew(EditorPropertyResource);
  2827. editor->setup(p_object, p_path, p_hint == PROPERTY_HINT_RESOURCE_TYPE ? p_hint_text : "Resource");
  2828. if (p_hint == PROPERTY_HINT_RESOURCE_TYPE) {
  2829. String open_in_new = EDITOR_GET("interface/inspector/resources_to_open_in_new_inspector");
  2830. for (int i = 0; i < open_in_new.get_slice_count(","); i++) {
  2831. String type = open_in_new.get_slicec(',', i).strip_edges();
  2832. for (int j = 0; j < p_hint_text.get_slice_count(","); j++) {
  2833. String inherits = p_hint_text.get_slicec(',', j);
  2834. if (ClassDB::is_parent_class(inherits, type)) {
  2835. editor->set_use_sub_inspector(false);
  2836. }
  2837. }
  2838. }
  2839. }
  2840. add_property_editor(p_path, editor);
  2841. } break;
  2842. case Variant::DICTIONARY: {
  2843. EditorPropertyDictionary *editor = memnew(EditorPropertyDictionary);
  2844. add_property_editor(p_path, editor);
  2845. } break;
  2846. case Variant::ARRAY: {
  2847. EditorPropertyArray *editor = memnew(EditorPropertyArray);
  2848. editor->setup(Variant::ARRAY, p_hint_text);
  2849. add_property_editor(p_path, editor);
  2850. } break;
  2851. case Variant::POOL_BYTE_ARRAY: {
  2852. EditorPropertyArray *editor = memnew(EditorPropertyArray);
  2853. editor->setup(Variant::POOL_BYTE_ARRAY);
  2854. add_property_editor(p_path, editor);
  2855. } break; // 20
  2856. case Variant::POOL_INT_ARRAY: {
  2857. EditorPropertyArray *editor = memnew(EditorPropertyArray);
  2858. editor->setup(Variant::POOL_INT_ARRAY);
  2859. add_property_editor(p_path, editor);
  2860. } break;
  2861. case Variant::POOL_REAL_ARRAY: {
  2862. EditorPropertyArray *editor = memnew(EditorPropertyArray);
  2863. editor->setup(Variant::POOL_REAL_ARRAY);
  2864. add_property_editor(p_path, editor);
  2865. } break;
  2866. case Variant::POOL_STRING_ARRAY: {
  2867. EditorPropertyArray *editor = memnew(EditorPropertyArray);
  2868. editor->setup(Variant::POOL_STRING_ARRAY);
  2869. add_property_editor(p_path, editor);
  2870. } break;
  2871. case Variant::POOL_VECTOR2_ARRAY: {
  2872. EditorPropertyArray *editor = memnew(EditorPropertyArray);
  2873. editor->setup(Variant::POOL_VECTOR2_ARRAY);
  2874. add_property_editor(p_path, editor);
  2875. } break;
  2876. case Variant::POOL_VECTOR3_ARRAY: {
  2877. EditorPropertyArray *editor = memnew(EditorPropertyArray);
  2878. editor->setup(Variant::POOL_VECTOR3_ARRAY);
  2879. add_property_editor(p_path, editor);
  2880. } break; // 25
  2881. case Variant::POOL_COLOR_ARRAY: {
  2882. EditorPropertyArray *editor = memnew(EditorPropertyArray);
  2883. editor->setup(Variant::POOL_COLOR_ARRAY);
  2884. add_property_editor(p_path, editor);
  2885. } break;
  2886. default: {
  2887. }
  2888. }
  2889. return false; //can be overridden, although it will most likely be last anyway
  2890. }
  2891. void EditorInspectorDefaultPlugin::parse_end() {
  2892. //do none
  2893. }