editor_properties.cpp 93 KB

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