editor_properties.cpp 107 KB

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