editor_properties.cpp 96 KB

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