editor_properties.cpp 103 KB

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