editor_properties.cpp 103 KB

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