property_editor.cpp 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980
  1. /*************************************************************************/
  2. /* property_editor.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "property_editor.h"
  31. #include "core/class_db.h"
  32. #include "core/input/input.h"
  33. #include "core/io/image_loader.h"
  34. #include "core/io/marshalls.h"
  35. #include "core/io/resource_loader.h"
  36. #include "core/math/expression.h"
  37. #include "core/os/keyboard.h"
  38. #include "core/pair.h"
  39. #include "core/print_string.h"
  40. #include "core/project_settings.h"
  41. #include "editor/array_property_edit.h"
  42. #include "editor/create_dialog.h"
  43. #include "editor/dictionary_property_edit.h"
  44. #include "editor/editor_export.h"
  45. #include "editor/editor_file_system.h"
  46. #include "editor/editor_help.h"
  47. #include "editor/editor_node.h"
  48. #include "editor/editor_scale.h"
  49. #include "editor/editor_settings.h"
  50. #include "editor/filesystem_dock.h"
  51. #include "editor/multi_node_edit.h"
  52. #include "editor/property_selector.h"
  53. #include "scene/gui/label.h"
  54. #include "scene/main/window.h"
  55. #include "scene/resources/font.h"
  56. #include "scene/resources/packed_scene.h"
  57. #include "scene/scene_string_names.h"
  58. void EditorResourceConversionPlugin::_bind_methods() {
  59. MethodInfo mi;
  60. mi.name = "_convert";
  61. mi.return_val.type = Variant::OBJECT;
  62. mi.return_val.class_name = "Resource";
  63. mi.return_val.hint = PROPERTY_HINT_RESOURCE_TYPE;
  64. mi.return_val.hint_string = "Resource";
  65. mi.arguments.push_back(mi.return_val);
  66. mi.arguments[0].name = "resource";
  67. BIND_VMETHOD(mi)
  68. mi.name = "_handles";
  69. mi.return_val = PropertyInfo(Variant::BOOL, "");
  70. BIND_VMETHOD(MethodInfo(Variant::STRING, "_converts_to"));
  71. }
  72. String EditorResourceConversionPlugin::converts_to() const {
  73. if (get_script_instance())
  74. return get_script_instance()->call("_converts_to");
  75. return "";
  76. }
  77. bool EditorResourceConversionPlugin::handles(const Ref<Resource> &p_resource) const {
  78. if (get_script_instance())
  79. return get_script_instance()->call("_handles", p_resource);
  80. return false;
  81. }
  82. Ref<Resource> EditorResourceConversionPlugin::convert(const Ref<Resource> &p_resource) const {
  83. if (get_script_instance())
  84. return get_script_instance()->call("_convert", p_resource);
  85. return Ref<Resource>();
  86. }
  87. void CustomPropertyEditor::_notification(int p_what) {
  88. if (p_what == NOTIFICATION_WM_CLOSE_REQUEST) {
  89. hide();
  90. }
  91. }
  92. void CustomPropertyEditor::_menu_option(int p_which) {
  93. switch (type) {
  94. case Variant::INT: {
  95. if (hint == PROPERTY_HINT_FLAGS) {
  96. int val = v;
  97. if (val & (1 << p_which)) {
  98. val &= ~(1 << p_which);
  99. } else {
  100. val |= (1 << p_which);
  101. }
  102. v = val;
  103. emit_signal("variant_changed");
  104. } else if (hint == PROPERTY_HINT_ENUM) {
  105. v = menu->get_item_metadata(p_which);
  106. emit_signal("variant_changed");
  107. }
  108. } break;
  109. case Variant::STRING: {
  110. if (hint == PROPERTY_HINT_ENUM) {
  111. v = hint_text.get_slice(",", p_which);
  112. emit_signal("variant_changed");
  113. }
  114. } break;
  115. case Variant::OBJECT: {
  116. switch (p_which) {
  117. case OBJ_MENU_LOAD: {
  118. file->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE);
  119. String type = (hint == PROPERTY_HINT_RESOURCE_TYPE) ? hint_text : String();
  120. List<String> extensions;
  121. for (int i = 0; i < type.get_slice_count(","); i++) {
  122. ResourceLoader::get_recognized_extensions_for_type(type.get_slice(",", i), &extensions);
  123. }
  124. Set<String> valid_extensions;
  125. for (List<String>::Element *E = extensions.front(); E; E = E->next()) {
  126. valid_extensions.insert(E->get());
  127. }
  128. file->clear_filters();
  129. for (Set<String>::Element *E = valid_extensions.front(); E; E = E->next()) {
  130. file->add_filter("*." + E->get() + " ; " + E->get().to_upper());
  131. }
  132. file->popup_centered_ratio();
  133. } break;
  134. case OBJ_MENU_EDIT: {
  135. REF r = v;
  136. if (!r.is_null()) {
  137. emit_signal("resource_edit_request");
  138. hide();
  139. }
  140. } break;
  141. case OBJ_MENU_CLEAR: {
  142. v = Variant();
  143. emit_signal("variant_changed");
  144. hide();
  145. } break;
  146. case OBJ_MENU_MAKE_UNIQUE: {
  147. Ref<Resource> res_orig = v;
  148. if (res_orig.is_null())
  149. return;
  150. List<PropertyInfo> property_list;
  151. res_orig->get_property_list(&property_list);
  152. List<Pair<String, Variant>> propvalues;
  153. for (List<PropertyInfo>::Element *E = property_list.front(); E; E = E->next()) {
  154. Pair<String, Variant> p;
  155. PropertyInfo &pi = E->get();
  156. if (pi.usage & PROPERTY_USAGE_STORAGE) {
  157. p.first = pi.name;
  158. p.second = res_orig->get(pi.name);
  159. }
  160. propvalues.push_back(p);
  161. }
  162. String orig_type = res_orig->get_class();
  163. Object *inst = ClassDB::instance(orig_type);
  164. Ref<Resource> res = Ref<Resource>(Object::cast_to<Resource>(inst));
  165. ERR_FAIL_COND(res.is_null());
  166. for (List<Pair<String, Variant>>::Element *E = propvalues.front(); E; E = E->next()) {
  167. Pair<String, Variant> &p = E->get();
  168. res->set(p.first, p.second);
  169. }
  170. v = res;
  171. emit_signal("variant_changed");
  172. hide();
  173. } break;
  174. case OBJ_MENU_COPY: {
  175. EditorSettings::get_singleton()->set_resource_clipboard(v);
  176. } break;
  177. case OBJ_MENU_PASTE: {
  178. v = EditorSettings::get_singleton()->get_resource_clipboard();
  179. emit_signal("variant_changed");
  180. } break;
  181. case OBJ_MENU_NEW_SCRIPT: {
  182. if (Object::cast_to<Node>(owner))
  183. EditorNode::get_singleton()->get_scene_tree_dock()->open_script_dialog(Object::cast_to<Node>(owner), false);
  184. } break;
  185. case OBJ_MENU_EXTEND_SCRIPT: {
  186. if (Object::cast_to<Node>(owner))
  187. EditorNode::get_singleton()->get_scene_tree_dock()->open_script_dialog(Object::cast_to<Node>(owner), true);
  188. } break;
  189. case OBJ_MENU_SHOW_IN_FILE_SYSTEM: {
  190. RES r = v;
  191. FileSystemDock *file_system_dock = EditorNode::get_singleton()->get_filesystem_dock();
  192. file_system_dock->navigate_to_path(r->get_path());
  193. // Ensure that the FileSystem dock is visible.
  194. TabContainer *tab_container = (TabContainer *)file_system_dock->get_parent_control();
  195. tab_container->set_current_tab(file_system_dock->get_index());
  196. } break;
  197. default: {
  198. if (p_which >= CONVERT_BASE_ID) {
  199. int to_type = p_which - CONVERT_BASE_ID;
  200. Vector<Ref<EditorResourceConversionPlugin>> conversions = EditorNode::get_singleton()->find_resource_conversion_plugin(RES(v));
  201. ERR_FAIL_INDEX(to_type, conversions.size());
  202. Ref<Resource> new_res = conversions[to_type]->convert(v);
  203. v = new_res;
  204. emit_signal("variant_changed");
  205. break;
  206. }
  207. ERR_FAIL_COND(inheritors_array.empty());
  208. String intype = inheritors_array[p_which - TYPE_BASE_ID];
  209. if (intype == "ViewportTexture") {
  210. scene_tree->set_title(TTR("Pick a Viewport"));
  211. scene_tree->popup_centered_ratio();
  212. picking_viewport = true;
  213. return;
  214. }
  215. Object *obj = ClassDB::instance(intype);
  216. if (!obj) {
  217. if (ScriptServer::is_global_class(intype)) {
  218. obj = EditorNode::get_editor_data().script_class_instance(intype);
  219. } else {
  220. obj = EditorNode::get_editor_data().instance_custom_type(intype, "Resource");
  221. }
  222. }
  223. ERR_BREAK(!obj);
  224. Resource *res = Object::cast_to<Resource>(obj);
  225. ERR_BREAK(!res);
  226. if (owner && hint == PROPERTY_HINT_RESOURCE_TYPE && hint_text == "Script") {
  227. //make visual script the right type
  228. res->call("set_instance_base_type", owner->get_class());
  229. }
  230. v = res;
  231. emit_signal("variant_changed");
  232. } break;
  233. }
  234. } break;
  235. default: {
  236. }
  237. }
  238. }
  239. void CustomPropertyEditor::hide_menu() {
  240. menu->hide();
  241. }
  242. Variant CustomPropertyEditor::get_variant() const {
  243. return v;
  244. }
  245. String CustomPropertyEditor::get_name() const {
  246. return name;
  247. }
  248. bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant::Type p_type, const Variant &p_variant, int p_hint, String p_hint_text) {
  249. owner = p_owner;
  250. updating = true;
  251. name = p_name;
  252. v = p_variant;
  253. field_names.clear();
  254. hint = p_hint;
  255. hint_text = p_hint_text;
  256. type_button->hide();
  257. if (color_picker)
  258. color_picker->hide();
  259. texture_preview->hide();
  260. inheritors_array.clear();
  261. text_edit->hide();
  262. easing_draw->hide();
  263. spinbox->hide();
  264. slider->hide();
  265. menu->clear();
  266. menu->set_size(Size2(1, 1) * EDSCALE);
  267. for (int i = 0; i < MAX_VALUE_EDITORS; i++) {
  268. value_editor[i]->hide();
  269. value_label[i]->hide();
  270. if (i < 4)
  271. scroll[i]->hide();
  272. }
  273. for (int i = 0; i < MAX_ACTION_BUTTONS; i++) {
  274. action_buttons[i]->hide();
  275. }
  276. checks20gc->hide();
  277. for (int i = 0; i < 20; i++)
  278. checks20[i]->hide();
  279. type = (p_variant.get_type() != Variant::NIL && p_variant.get_type() != Variant::_RID && p_type != Variant::OBJECT) ? p_variant.get_type() : p_type;
  280. switch (type) {
  281. case Variant::BOOL: {
  282. checks20gc->show();
  283. CheckBox *c = checks20[0];
  284. c->set_text("True");
  285. checks20gc->set_position(Vector2(4, 4) * EDSCALE);
  286. c->set_pressed(v);
  287. c->show();
  288. checks20gc->set_size(checks20gc->get_minimum_size());
  289. set_size(checks20gc->get_position() + checks20gc->get_size() + c->get_size() + Vector2(4, 4) * EDSCALE);
  290. } break;
  291. case Variant::INT:
  292. case Variant::FLOAT: {
  293. if (hint == PROPERTY_HINT_RANGE) {
  294. int c = hint_text.get_slice_count(",");
  295. float min = 0, max = 100, step = type == Variant::FLOAT ? .01 : 1;
  296. if (c >= 1) {
  297. if (!hint_text.get_slice(",", 0).empty())
  298. min = hint_text.get_slice(",", 0).to_double();
  299. }
  300. if (c >= 2) {
  301. if (!hint_text.get_slice(",", 1).empty())
  302. max = hint_text.get_slice(",", 1).to_double();
  303. }
  304. if (c >= 3) {
  305. if (!hint_text.get_slice(",", 2).empty())
  306. step = hint_text.get_slice(",", 2).to_double();
  307. }
  308. if (c >= 4 && hint_text.get_slice(",", 3) == "slider") {
  309. slider->set_min(min);
  310. slider->set_max(max);
  311. slider->set_step(step);
  312. slider->set_value(v);
  313. slider->show();
  314. set_size(Size2(110, 30) * EDSCALE);
  315. } else {
  316. spinbox->set_min(min);
  317. spinbox->set_max(max);
  318. spinbox->set_step(step);
  319. spinbox->set_value(v);
  320. spinbox->show();
  321. set_size(Size2(70, 35) * EDSCALE);
  322. }
  323. } else if (hint == PROPERTY_HINT_ENUM) {
  324. Vector<String> options = hint_text.split(",");
  325. int current_val = 0;
  326. for (int i = 0; i < options.size(); i++) {
  327. Vector<String> text_split = options[i].split(":");
  328. if (text_split.size() != 1)
  329. current_val = text_split[1].to_int();
  330. menu->add_item(text_split[0]);
  331. menu->set_item_metadata(i, current_val);
  332. current_val += 1;
  333. }
  334. menu->set_position(get_position());
  335. menu->popup();
  336. hide();
  337. updating = false;
  338. return false;
  339. } else if (hint == PROPERTY_HINT_LAYERS_2D_PHYSICS || hint == PROPERTY_HINT_LAYERS_2D_RENDER || hint == PROPERTY_HINT_LAYERS_3D_PHYSICS || hint == PROPERTY_HINT_LAYERS_3D_RENDER) {
  340. String basename;
  341. switch (hint) {
  342. case PROPERTY_HINT_LAYERS_2D_RENDER:
  343. basename = "layer_names/2d_render";
  344. break;
  345. case PROPERTY_HINT_LAYERS_2D_PHYSICS:
  346. basename = "layer_names/2d_physics";
  347. break;
  348. case PROPERTY_HINT_LAYERS_3D_RENDER:
  349. basename = "layer_names/3d_render";
  350. break;
  351. case PROPERTY_HINT_LAYERS_3D_PHYSICS:
  352. basename = "layer_names/3d_physics";
  353. break;
  354. }
  355. checks20gc->show();
  356. uint32_t flgs = v;
  357. for (int i = 0; i < 2; i++) {
  358. Point2 ofs(4, 4);
  359. ofs.y += 22 * i;
  360. for (int j = 0; j < 10; j++) {
  361. int idx = i * 10 + j;
  362. CheckBox *c = checks20[idx];
  363. c->set_text(ProjectSettings::get_singleton()->get(basename + "/layer_" + itos(idx + 1)));
  364. c->set_pressed(flgs & (1 << (i * 10 + j)));
  365. c->show();
  366. }
  367. }
  368. show();
  369. checks20gc->set_position(Vector2(4, 4) * EDSCALE);
  370. checks20gc->set_size(checks20gc->get_minimum_size());
  371. set_size(Vector2(4, 4) * EDSCALE + checks20gc->get_position() + checks20gc->get_size());
  372. } else if (hint == PROPERTY_HINT_EXP_EASING) {
  373. easing_draw->set_anchor_and_margin(MARGIN_LEFT, Control::ANCHOR_BEGIN, 5 * EDSCALE);
  374. easing_draw->set_anchor_and_margin(MARGIN_RIGHT, Control::ANCHOR_END, -5 * EDSCALE);
  375. easing_draw->set_anchor_and_margin(MARGIN_TOP, Control::ANCHOR_BEGIN, 5 * EDSCALE);
  376. easing_draw->set_anchor_and_margin(MARGIN_BOTTOM, Control::ANCHOR_END, -30 * EDSCALE);
  377. type_button->set_anchor_and_margin(MARGIN_LEFT, Control::ANCHOR_BEGIN, 3 * EDSCALE);
  378. type_button->set_anchor_and_margin(MARGIN_RIGHT, Control::ANCHOR_END, -3 * EDSCALE);
  379. type_button->set_anchor_and_margin(MARGIN_TOP, Control::ANCHOR_END, -25 * EDSCALE);
  380. type_button->set_anchor_and_margin(MARGIN_BOTTOM, Control::ANCHOR_END, -7 * EDSCALE);
  381. type_button->set_text(TTR("Preset..."));
  382. type_button->get_popup()->clear();
  383. type_button->get_popup()->add_item(TTR("Linear"), EASING_LINEAR);
  384. type_button->get_popup()->add_item(TTR("Ease In"), EASING_EASE_IN);
  385. type_button->get_popup()->add_item(TTR("Ease Out"), EASING_EASE_OUT);
  386. if (hint_text != "attenuation") {
  387. type_button->get_popup()->add_item(TTR("Zero"), EASING_ZERO);
  388. type_button->get_popup()->add_item(TTR("Easing In-Out"), EASING_IN_OUT);
  389. type_button->get_popup()->add_item(TTR("Easing Out-In"), EASING_OUT_IN);
  390. }
  391. type_button->show();
  392. easing_draw->show();
  393. set_size(Size2(200, 150) * EDSCALE);
  394. } else if (hint == PROPERTY_HINT_FLAGS) {
  395. Vector<String> flags = hint_text.split(",");
  396. for (int i = 0; i < flags.size(); i++) {
  397. String flag = flags[i];
  398. if (flag == "")
  399. continue;
  400. menu->add_check_item(flag, i);
  401. int f = v;
  402. if (f & (1 << i))
  403. menu->set_item_checked(menu->get_item_index(i), true);
  404. }
  405. menu->set_position(get_position());
  406. menu->popup();
  407. hide();
  408. updating = false;
  409. return false;
  410. } else {
  411. List<String> names;
  412. names.push_back("value:");
  413. config_value_editors(1, 1, 50, names);
  414. value_editor[0]->set_text(String::num(v));
  415. }
  416. } break;
  417. case Variant::STRING: {
  418. if (hint == PROPERTY_HINT_FILE || hint == PROPERTY_HINT_GLOBAL_FILE) {
  419. List<String> names;
  420. names.push_back(TTR("File..."));
  421. names.push_back(TTR("Clear"));
  422. config_action_buttons(names);
  423. } else if (hint == PROPERTY_HINT_DIR || hint == PROPERTY_HINT_GLOBAL_DIR) {
  424. List<String> names;
  425. names.push_back(TTR("Dir..."));
  426. names.push_back(TTR("Clear"));
  427. config_action_buttons(names);
  428. } else if (hint == PROPERTY_HINT_ENUM) {
  429. Vector<String> options = hint_text.split(",");
  430. for (int i = 0; i < options.size(); i++) {
  431. menu->add_item(options[i], i);
  432. }
  433. menu->set_position(get_position());
  434. menu->popup();
  435. hide();
  436. updating = false;
  437. return false;
  438. } else if (hint == PROPERTY_HINT_MULTILINE_TEXT) {
  439. text_edit->show();
  440. text_edit->set_text(v);
  441. text_edit->deselect();
  442. int button_margin = text_edit->get_theme_constant("button_margin", "Dialogs");
  443. int margin = text_edit->get_theme_constant("margin", "Dialogs");
  444. action_buttons[0]->set_anchor(MARGIN_LEFT, Control::ANCHOR_END);
  445. action_buttons[0]->set_anchor(MARGIN_TOP, Control::ANCHOR_END);
  446. action_buttons[0]->set_anchor(MARGIN_RIGHT, Control::ANCHOR_END);
  447. action_buttons[0]->set_anchor(MARGIN_BOTTOM, Control::ANCHOR_END);
  448. action_buttons[0]->set_begin(Point2(-70 * EDSCALE, -button_margin + 5 * EDSCALE));
  449. action_buttons[0]->set_end(Point2(-margin, -margin));
  450. action_buttons[0]->set_text(TTR("Close"));
  451. action_buttons[0]->show();
  452. } else if (hint == PROPERTY_HINT_TYPE_STRING) {
  453. if (!create_dialog) {
  454. create_dialog = memnew(CreateDialog);
  455. create_dialog->connect("create", callable_mp(this, &CustomPropertyEditor::_create_dialog_callback));
  456. add_child(create_dialog);
  457. }
  458. if (hint_text != String()) {
  459. create_dialog->set_base_type(hint_text);
  460. } else {
  461. create_dialog->set_base_type("Object");
  462. }
  463. create_dialog->popup_create(false);
  464. hide();
  465. updating = false;
  466. return false;
  467. } else if (hint == PROPERTY_HINT_METHOD_OF_VARIANT_TYPE) {
  468. #define MAKE_PROPSELECT \
  469. if (!property_select) { \
  470. property_select = memnew(PropertySelector); \
  471. property_select->connect("selected", callable_mp(this, &CustomPropertyEditor::_create_selected_property)); \
  472. add_child(property_select); \
  473. } \
  474. hide();
  475. MAKE_PROPSELECT;
  476. Variant::Type type = Variant::NIL;
  477. for (int i = 0; i < Variant::VARIANT_MAX; i++) {
  478. if (hint_text == Variant::get_type_name(Variant::Type(i))) {
  479. type = Variant::Type(i);
  480. }
  481. }
  482. if (type != Variant::NIL)
  483. property_select->select_method_from_basic_type(type, v);
  484. updating = false;
  485. return false;
  486. } else if (hint == PROPERTY_HINT_METHOD_OF_BASE_TYPE) {
  487. MAKE_PROPSELECT
  488. property_select->select_method_from_base_type(hint_text, v);
  489. updating = false;
  490. return false;
  491. } else if (hint == PROPERTY_HINT_METHOD_OF_INSTANCE) {
  492. MAKE_PROPSELECT
  493. Object *instance = ObjectDB::get_instance(ObjectID(hint_text.to_int64()));
  494. if (instance)
  495. property_select->select_method_from_instance(instance, v);
  496. updating = false;
  497. return false;
  498. } else if (hint == PROPERTY_HINT_METHOD_OF_SCRIPT) {
  499. MAKE_PROPSELECT
  500. Object *obj = ObjectDB::get_instance(ObjectID(hint_text.to_int64()));
  501. if (Object::cast_to<Script>(obj)) {
  502. property_select->select_method_from_script(Object::cast_to<Script>(obj), v);
  503. }
  504. updating = false;
  505. return false;
  506. } else if (hint == PROPERTY_HINT_PROPERTY_OF_VARIANT_TYPE) {
  507. MAKE_PROPSELECT
  508. Variant::Type type = Variant::NIL;
  509. String tname = hint_text;
  510. if (tname.find(".") != -1)
  511. tname = tname.get_slice(".", 0);
  512. for (int i = 0; i < Variant::VARIANT_MAX; i++) {
  513. if (tname == Variant::get_type_name(Variant::Type(i))) {
  514. type = Variant::Type(Variant::Type(i));
  515. }
  516. }
  517. if (type != Variant::NIL)
  518. property_select->select_property_from_basic_type(type, v);
  519. updating = false;
  520. return false;
  521. } else if (hint == PROPERTY_HINT_PROPERTY_OF_BASE_TYPE) {
  522. MAKE_PROPSELECT
  523. property_select->select_property_from_base_type(hint_text, v);
  524. updating = false;
  525. return false;
  526. } else if (hint == PROPERTY_HINT_PROPERTY_OF_INSTANCE) {
  527. MAKE_PROPSELECT
  528. Object *instance = ObjectDB::get_instance(ObjectID(hint_text.to_int64()));
  529. if (instance)
  530. property_select->select_property_from_instance(instance, v);
  531. updating = false;
  532. return false;
  533. } else if (hint == PROPERTY_HINT_PROPERTY_OF_SCRIPT) {
  534. MAKE_PROPSELECT
  535. Object *obj = ObjectDB::get_instance(ObjectID(hint_text.to_int64()));
  536. if (Object::cast_to<Script>(obj)) {
  537. property_select->select_property_from_script(Object::cast_to<Script>(obj), v);
  538. }
  539. updating = false;
  540. return false;
  541. } else {
  542. List<String> names;
  543. names.push_back("string:");
  544. config_value_editors(1, 1, 50, names);
  545. value_editor[0]->set_text(v);
  546. }
  547. } break;
  548. case Variant::VECTOR2: {
  549. field_names.push_back("x");
  550. field_names.push_back("y");
  551. config_value_editors(2, 2, 10, field_names);
  552. Vector2 vec = v;
  553. value_editor[0]->set_text(String::num(vec.x));
  554. value_editor[1]->set_text(String::num(vec.y));
  555. } break;
  556. case Variant::RECT2: {
  557. field_names.push_back("x");
  558. field_names.push_back("y");
  559. field_names.push_back("w");
  560. field_names.push_back("h");
  561. config_value_editors(4, 4, 10, field_names);
  562. Rect2 r = v;
  563. value_editor[0]->set_text(String::num(r.position.x));
  564. value_editor[1]->set_text(String::num(r.position.y));
  565. value_editor[2]->set_text(String::num(r.size.x));
  566. value_editor[3]->set_text(String::num(r.size.y));
  567. } break;
  568. case Variant::VECTOR3: {
  569. field_names.push_back("x");
  570. field_names.push_back("y");
  571. field_names.push_back("z");
  572. config_value_editors(3, 3, 10, field_names);
  573. Vector3 vec = v;
  574. value_editor[0]->set_text(String::num(vec.x));
  575. value_editor[1]->set_text(String::num(vec.y));
  576. value_editor[2]->set_text(String::num(vec.z));
  577. } break;
  578. case Variant::PLANE: {
  579. field_names.push_back("x");
  580. field_names.push_back("y");
  581. field_names.push_back("z");
  582. field_names.push_back("d");
  583. config_value_editors(4, 4, 10, field_names);
  584. Plane plane = v;
  585. value_editor[0]->set_text(String::num(plane.normal.x));
  586. value_editor[1]->set_text(String::num(plane.normal.y));
  587. value_editor[2]->set_text(String::num(plane.normal.z));
  588. value_editor[3]->set_text(String::num(plane.distance));
  589. } break;
  590. case Variant::QUAT: {
  591. field_names.push_back("x");
  592. field_names.push_back("y");
  593. field_names.push_back("z");
  594. field_names.push_back("w");
  595. config_value_editors(4, 4, 10, field_names);
  596. Quat q = v;
  597. value_editor[0]->set_text(String::num(q.x));
  598. value_editor[1]->set_text(String::num(q.y));
  599. value_editor[2]->set_text(String::num(q.z));
  600. value_editor[3]->set_text(String::num(q.w));
  601. } break;
  602. case Variant::AABB: {
  603. field_names.push_back("px");
  604. field_names.push_back("py");
  605. field_names.push_back("pz");
  606. field_names.push_back("sx");
  607. field_names.push_back("sy");
  608. field_names.push_back("sz");
  609. config_value_editors(6, 3, 16, field_names);
  610. AABB aabb = v;
  611. value_editor[0]->set_text(String::num(aabb.position.x));
  612. value_editor[1]->set_text(String::num(aabb.position.y));
  613. value_editor[2]->set_text(String::num(aabb.position.z));
  614. value_editor[3]->set_text(String::num(aabb.size.x));
  615. value_editor[4]->set_text(String::num(aabb.size.y));
  616. value_editor[5]->set_text(String::num(aabb.size.z));
  617. } break;
  618. case Variant::TRANSFORM2D: {
  619. field_names.push_back("xx");
  620. field_names.push_back("xy");
  621. field_names.push_back("yx");
  622. field_names.push_back("yy");
  623. field_names.push_back("ox");
  624. field_names.push_back("oy");
  625. config_value_editors(6, 2, 16, field_names);
  626. Transform2D basis = v;
  627. for (int i = 0; i < 6; i++) {
  628. value_editor[i]->set_text(String::num(basis.elements[i / 2][i % 2]));
  629. }
  630. } break;
  631. case Variant::BASIS: {
  632. field_names.push_back("xx");
  633. field_names.push_back("xy");
  634. field_names.push_back("xz");
  635. field_names.push_back("yx");
  636. field_names.push_back("yy");
  637. field_names.push_back("yz");
  638. field_names.push_back("zx");
  639. field_names.push_back("zy");
  640. field_names.push_back("zz");
  641. config_value_editors(9, 3, 16, field_names);
  642. Basis basis = v;
  643. for (int i = 0; i < 9; i++) {
  644. value_editor[i]->set_text(String::num(basis.elements[i / 3][i % 3]));
  645. }
  646. } break;
  647. case Variant::TRANSFORM: {
  648. field_names.push_back("xx");
  649. field_names.push_back("xy");
  650. field_names.push_back("xz");
  651. field_names.push_back("xo");
  652. field_names.push_back("yx");
  653. field_names.push_back("yy");
  654. field_names.push_back("yz");
  655. field_names.push_back("yo");
  656. field_names.push_back("zx");
  657. field_names.push_back("zy");
  658. field_names.push_back("zz");
  659. field_names.push_back("zo");
  660. config_value_editors(12, 4, 16, field_names);
  661. Transform tr = v;
  662. for (int i = 0; i < 9; i++) {
  663. value_editor[(i / 3) * 4 + i % 3]->set_text(String::num(tr.basis.elements[i / 3][i % 3]));
  664. }
  665. value_editor[3]->set_text(String::num(tr.origin.x));
  666. value_editor[7]->set_text(String::num(tr.origin.y));
  667. value_editor[11]->set_text(String::num(tr.origin.z));
  668. } break;
  669. case Variant::COLOR: {
  670. if (!color_picker) {
  671. //late init for performance
  672. color_picker = memnew(ColorPicker);
  673. color_picker->set_deferred_mode(true);
  674. add_child(color_picker);
  675. color_picker->hide();
  676. color_picker->connect("color_changed", callable_mp(this, &CustomPropertyEditor::_color_changed));
  677. // get default color picker mode from editor settings
  678. int default_color_mode = EDITOR_GET("interface/inspector/default_color_picker_mode");
  679. if (default_color_mode == 1)
  680. color_picker->set_hsv_mode(true);
  681. else if (default_color_mode == 2)
  682. color_picker->set_raw_mode(true);
  683. }
  684. color_picker->show();
  685. color_picker->set_edit_alpha(hint != PROPERTY_HINT_COLOR_NO_ALPHA);
  686. color_picker->set_pick_color(v);
  687. color_picker->set_focus_on_line_edit();
  688. } break;
  689. case Variant::NODE_PATH: {
  690. List<String> names;
  691. names.push_back(TTR("Assign"));
  692. names.push_back(TTR("Clear"));
  693. if (owner && owner->is_class("Node") && (v.get_type() == Variant::NODE_PATH) && Object::cast_to<Node>(owner)->has_node(v))
  694. names.push_back(TTR("Select Node"));
  695. config_action_buttons(names);
  696. } break;
  697. case Variant::OBJECT: {
  698. if (hint != PROPERTY_HINT_RESOURCE_TYPE)
  699. break;
  700. if (p_name == "script" && hint_text == "Script" && Object::cast_to<Node>(owner)) {
  701. menu->add_item(TTR("New Script"), OBJ_MENU_NEW_SCRIPT);
  702. menu->add_separator();
  703. } else if (hint_text != "") {
  704. int idx = 0;
  705. Vector<EditorData::CustomType> custom_resources;
  706. if (EditorNode::get_editor_data().get_custom_types().has("Resource")) {
  707. custom_resources = EditorNode::get_editor_data().get_custom_types()["Resource"];
  708. }
  709. for (int i = 0; i < hint_text.get_slice_count(","); i++) {
  710. String base = hint_text.get_slice(",", i);
  711. Set<String> valid_inheritors;
  712. valid_inheritors.insert(base);
  713. List<StringName> inheritors;
  714. ClassDB::get_inheriters_from_class(base.strip_edges(), &inheritors);
  715. for (int j = 0; j < custom_resources.size(); j++) {
  716. inheritors.push_back(custom_resources[j].name);
  717. }
  718. List<StringName>::Element *E = inheritors.front();
  719. while (E) {
  720. valid_inheritors.insert(E->get());
  721. E = E->next();
  722. }
  723. for (Set<String>::Element *j = valid_inheritors.front(); j; j = j->next()) {
  724. const String &t = j->get();
  725. bool is_custom_resource = false;
  726. Ref<Texture2D> icon;
  727. if (!custom_resources.empty()) {
  728. for (int k = 0; k < custom_resources.size(); k++) {
  729. if (custom_resources[k].name == t) {
  730. is_custom_resource = true;
  731. if (custom_resources[k].icon.is_valid())
  732. icon = custom_resources[k].icon;
  733. break;
  734. }
  735. }
  736. }
  737. if (!is_custom_resource && !ClassDB::can_instance(t))
  738. continue;
  739. inheritors_array.push_back(t);
  740. int id = TYPE_BASE_ID + idx;
  741. menu->add_item(vformat(TTR("New %s"), t), id);
  742. idx++;
  743. }
  744. }
  745. if (menu->get_item_count())
  746. menu->add_separator();
  747. }
  748. menu->add_item(TTR("Load"), OBJ_MENU_LOAD);
  749. if (!RES(v).is_null()) {
  750. menu->add_item(TTR("Edit"), OBJ_MENU_EDIT);
  751. menu->add_item(TTR("Clear"), OBJ_MENU_CLEAR);
  752. menu->add_item(TTR("Make Unique"), OBJ_MENU_MAKE_UNIQUE);
  753. RES r = v;
  754. if (r.is_valid() && r->get_path().is_resource_file()) {
  755. menu->add_separator();
  756. menu->add_item(TTR("Show in FileSystem"), OBJ_MENU_SHOW_IN_FILE_SYSTEM);
  757. }
  758. }
  759. RES cb = EditorSettings::get_singleton()->get_resource_clipboard();
  760. bool paste_valid = false;
  761. if (cb.is_valid()) {
  762. if (hint_text == "")
  763. paste_valid = true;
  764. else
  765. for (int i = 0; i < hint_text.get_slice_count(","); i++)
  766. if (ClassDB::is_parent_class(cb->get_class(), hint_text.get_slice(",", i))) {
  767. paste_valid = true;
  768. break;
  769. }
  770. }
  771. if (!RES(v).is_null() || paste_valid) {
  772. menu->add_separator();
  773. if (!RES(v).is_null()) {
  774. menu->add_item(TTR("Copy"), OBJ_MENU_COPY);
  775. }
  776. if (paste_valid) {
  777. menu->add_item(TTR("Paste"), OBJ_MENU_PASTE);
  778. }
  779. }
  780. if (!RES(v).is_null()) {
  781. Vector<Ref<EditorResourceConversionPlugin>> conversions = EditorNode::get_singleton()->find_resource_conversion_plugin(RES(v));
  782. if (conversions.size()) {
  783. menu->add_separator();
  784. }
  785. for (int i = 0; i < conversions.size(); i++) {
  786. String what = conversions[i]->converts_to();
  787. menu->add_item(vformat(TTR("Convert To %s"), what), CONVERT_BASE_ID + i);
  788. }
  789. }
  790. menu->set_position(get_position());
  791. menu->popup();
  792. hide();
  793. updating = false;
  794. return false;
  795. } break;
  796. case Variant::DICTIONARY: {
  797. } break;
  798. case Variant::PACKED_BYTE_ARRAY: {
  799. } break;
  800. case Variant::PACKED_INT32_ARRAY: {
  801. } break;
  802. case Variant::PACKED_FLOAT32_ARRAY: {
  803. } break;
  804. case Variant::PACKED_INT64_ARRAY: {
  805. } break;
  806. case Variant::PACKED_FLOAT64_ARRAY: {
  807. } break;
  808. case Variant::PACKED_STRING_ARRAY: {
  809. } break;
  810. case Variant::PACKED_VECTOR3_ARRAY: {
  811. } break;
  812. case Variant::PACKED_COLOR_ARRAY: {
  813. } break;
  814. default: {
  815. }
  816. }
  817. updating = false;
  818. return true;
  819. }
  820. void CustomPropertyEditor::_file_selected(String p_file) {
  821. switch (type) {
  822. case Variant::STRING: {
  823. if (hint == PROPERTY_HINT_FILE || hint == PROPERTY_HINT_DIR) {
  824. v = ProjectSettings::get_singleton()->localize_path(p_file);
  825. emit_signal("variant_changed");
  826. hide();
  827. }
  828. if (hint == PROPERTY_HINT_GLOBAL_FILE || hint == PROPERTY_HINT_GLOBAL_DIR) {
  829. v = p_file;
  830. emit_signal("variant_changed");
  831. hide();
  832. }
  833. } break;
  834. case Variant::OBJECT: {
  835. String type = (hint == PROPERTY_HINT_RESOURCE_TYPE) ? hint_text : String();
  836. RES res = ResourceLoader::load(p_file, type);
  837. if (res.is_null()) {
  838. error->set_text(TTR("Error loading file: Not a resource!"));
  839. error->popup_centered();
  840. break;
  841. }
  842. v = res;
  843. emit_signal("variant_changed");
  844. hide();
  845. } break;
  846. default: {
  847. }
  848. }
  849. }
  850. void CustomPropertyEditor::_type_create_selected(int p_idx) {
  851. if (type == Variant::INT || type == Variant::FLOAT) {
  852. float newval = 0;
  853. switch (p_idx) {
  854. case EASING_LINEAR: {
  855. newval = 1;
  856. } break;
  857. case EASING_EASE_IN: {
  858. newval = 2.0;
  859. } break;
  860. case EASING_EASE_OUT: {
  861. newval = 0.5;
  862. } break;
  863. case EASING_ZERO: {
  864. newval = 0;
  865. } break;
  866. case EASING_IN_OUT: {
  867. newval = -0.5;
  868. } break;
  869. case EASING_OUT_IN: {
  870. newval = -2.0;
  871. } break;
  872. }
  873. v = newval;
  874. emit_signal("variant_changed");
  875. easing_draw->update();
  876. } else if (type == Variant::OBJECT) {
  877. ERR_FAIL_INDEX(p_idx, inheritors_array.size());
  878. String intype = inheritors_array[p_idx];
  879. Object *obj = ClassDB::instance(intype);
  880. if (!obj) {
  881. if (ScriptServer::is_global_class(intype)) {
  882. obj = EditorNode::get_editor_data().script_class_instance(intype);
  883. } else {
  884. obj = EditorNode::get_editor_data().instance_custom_type(intype, "Resource");
  885. }
  886. }
  887. ERR_FAIL_COND(!obj);
  888. Resource *res = Object::cast_to<Resource>(obj);
  889. ERR_FAIL_COND(!res);
  890. v = res;
  891. emit_signal("variant_changed");
  892. hide();
  893. }
  894. }
  895. void CustomPropertyEditor::_color_changed(const Color &p_color) {
  896. v = p_color;
  897. emit_signal("variant_changed");
  898. }
  899. void CustomPropertyEditor::_node_path_selected(NodePath p_path) {
  900. if (picking_viewport) {
  901. Node *to_node = get_node(p_path);
  902. if (!Object::cast_to<Viewport>(to_node)) {
  903. EditorNode::get_singleton()->show_warning(TTR("Selected node is not a Viewport!"));
  904. return;
  905. }
  906. Ref<ViewportTexture> vt;
  907. vt.instance();
  908. vt->set_viewport_path_in_scene(get_tree()->get_edited_scene_root()->get_path_to(to_node));
  909. vt->setup_local_to_scene();
  910. v = vt;
  911. emit_signal("variant_changed");
  912. return;
  913. }
  914. if (hint == PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE && hint_text != String()) {
  915. Node *node = get_node(hint_text);
  916. if (node) {
  917. Node *tonode = node->get_node(p_path);
  918. if (tonode) {
  919. p_path = node->get_path_to(tonode);
  920. }
  921. }
  922. } else if (owner) {
  923. Node *node = nullptr;
  924. if (owner->is_class("Node"))
  925. node = Object::cast_to<Node>(owner);
  926. else if (owner->is_class("ArrayPropertyEdit"))
  927. node = Object::cast_to<ArrayPropertyEdit>(owner)->get_node();
  928. else if (owner->is_class("DictionaryPropertyEdit"))
  929. node = Object::cast_to<DictionaryPropertyEdit>(owner)->get_node();
  930. if (!node) {
  931. v = p_path;
  932. emit_signal("variant_changed");
  933. call_deferred("hide"); //to not mess with dialogs
  934. return;
  935. }
  936. Node *tonode = node->get_node(p_path);
  937. if (tonode) {
  938. p_path = node->get_path_to(tonode);
  939. }
  940. }
  941. v = p_path;
  942. emit_signal("variant_changed");
  943. call_deferred("hide"); //to not mess with dialogs
  944. }
  945. void CustomPropertyEditor::_action_pressed(int p_which) {
  946. if (updating)
  947. return;
  948. switch (type) {
  949. case Variant::BOOL: {
  950. v = checks20[0]->is_pressed();
  951. emit_signal("variant_changed");
  952. } break;
  953. case Variant::INT: {
  954. if (hint == PROPERTY_HINT_LAYERS_2D_PHYSICS || hint == PROPERTY_HINT_LAYERS_2D_RENDER || hint == PROPERTY_HINT_LAYERS_3D_PHYSICS || hint == PROPERTY_HINT_LAYERS_3D_RENDER) {
  955. uint32_t f = v;
  956. if (checks20[p_which]->is_pressed())
  957. f |= (1 << p_which);
  958. else
  959. f &= ~(1 << p_which);
  960. v = f;
  961. emit_signal("variant_changed");
  962. }
  963. } break;
  964. case Variant::STRING: {
  965. if (hint == PROPERTY_HINT_MULTILINE_TEXT) {
  966. hide();
  967. } else if (hint == PROPERTY_HINT_FILE || hint == PROPERTY_HINT_GLOBAL_FILE) {
  968. if (p_which == 0) {
  969. if (hint == PROPERTY_HINT_FILE)
  970. file->set_access(EditorFileDialog::ACCESS_RESOURCES);
  971. else
  972. file->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
  973. file->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE);
  974. file->clear_filters();
  975. file->clear_filters();
  976. if (hint_text != "") {
  977. Vector<String> extensions = hint_text.split(",");
  978. for (int i = 0; i < extensions.size(); i++) {
  979. String filter = extensions[i];
  980. if (filter.begins_with("."))
  981. filter = "*" + extensions[i];
  982. else if (!filter.begins_with("*"))
  983. filter = "*." + extensions[i];
  984. file->add_filter(filter + " ; " + extensions[i].to_upper());
  985. }
  986. }
  987. file->popup_centered_ratio();
  988. } else {
  989. v = "";
  990. emit_signal("variant_changed");
  991. hide();
  992. }
  993. } else if (hint == PROPERTY_HINT_DIR || hint == PROPERTY_HINT_GLOBAL_DIR) {
  994. if (p_which == 0) {
  995. if (hint == PROPERTY_HINT_DIR)
  996. file->set_access(EditorFileDialog::ACCESS_RESOURCES);
  997. else
  998. file->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
  999. file->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_DIR);
  1000. file->clear_filters();
  1001. file->popup_centered_ratio();
  1002. } else {
  1003. v = "";
  1004. emit_signal("variant_changed");
  1005. hide();
  1006. }
  1007. }
  1008. } break;
  1009. case Variant::NODE_PATH: {
  1010. if (p_which == 0) {
  1011. picking_viewport = false;
  1012. scene_tree->set_title(TTR("Pick a Node"));
  1013. scene_tree->popup_centered_ratio();
  1014. } else if (p_which == 1) {
  1015. v = NodePath();
  1016. emit_signal("variant_changed");
  1017. hide();
  1018. } else if (p_which == 2) {
  1019. if (owner->is_class("Node") && (v.get_type() == Variant::NODE_PATH) && Object::cast_to<Node>(owner)->has_node(v)) {
  1020. Node *target_node = Object::cast_to<Node>(owner)->get_node(v);
  1021. EditorNode::get_singleton()->get_editor_selection()->clear();
  1022. EditorNode::get_singleton()->get_scene_tree_dock()->set_selected(target_node);
  1023. }
  1024. hide();
  1025. }
  1026. } break;
  1027. case Variant::OBJECT: {
  1028. if (p_which == 0) {
  1029. ERR_FAIL_COND(inheritors_array.empty());
  1030. String intype = inheritors_array[0];
  1031. if (hint == PROPERTY_HINT_RESOURCE_TYPE) {
  1032. Object *obj = ClassDB::instance(intype);
  1033. if (!obj) {
  1034. if (ScriptServer::is_global_class(intype)) {
  1035. obj = EditorNode::get_editor_data().script_class_instance(intype);
  1036. } else {
  1037. obj = EditorNode::get_editor_data().instance_custom_type(intype, "Resource");
  1038. }
  1039. }
  1040. ERR_BREAK(!obj);
  1041. Resource *res = Object::cast_to<Resource>(obj);
  1042. ERR_BREAK(!res);
  1043. v = res;
  1044. emit_signal("variant_changed");
  1045. hide();
  1046. }
  1047. } else if (p_which == 1) {
  1048. file->set_access(EditorFileDialog::ACCESS_RESOURCES);
  1049. file->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE);
  1050. List<String> extensions;
  1051. String type = (hint == PROPERTY_HINT_RESOURCE_TYPE) ? hint_text : String();
  1052. ResourceLoader::get_recognized_extensions_for_type(type, &extensions);
  1053. file->clear_filters();
  1054. for (List<String>::Element *E = extensions.front(); E; E = E->next()) {
  1055. file->add_filter("*." + E->get() + " ; " + E->get().to_upper());
  1056. }
  1057. file->popup_centered_ratio();
  1058. } else if (p_which == 2) {
  1059. RES r = v;
  1060. if (!r.is_null()) {
  1061. emit_signal("resource_edit_request");
  1062. hide();
  1063. }
  1064. } else if (p_which == 3) {
  1065. v = Variant();
  1066. emit_signal("variant_changed");
  1067. hide();
  1068. } else if (p_which == 4) {
  1069. Ref<Resource> res_orig = v;
  1070. if (res_orig.is_null())
  1071. return;
  1072. List<PropertyInfo> property_list;
  1073. res_orig->get_property_list(&property_list);
  1074. List<Pair<String, Variant>> propvalues;
  1075. for (List<PropertyInfo>::Element *E = property_list.front(); E; E = E->next()) {
  1076. Pair<String, Variant> p;
  1077. PropertyInfo &pi = E->get();
  1078. if (pi.usage & PROPERTY_USAGE_STORAGE) {
  1079. p.first = pi.name;
  1080. p.second = res_orig->get(pi.name);
  1081. }
  1082. propvalues.push_back(p);
  1083. }
  1084. Ref<Resource> res = Ref<Resource>(ClassDB::instance(res_orig->get_class()));
  1085. ERR_FAIL_COND(res.is_null());
  1086. for (List<Pair<String, Variant>>::Element *E = propvalues.front(); E; E = E->next()) {
  1087. Pair<String, Variant> &p = E->get();
  1088. res->set(p.first, p.second);
  1089. }
  1090. v = res;
  1091. emit_signal("variant_changed");
  1092. hide();
  1093. }
  1094. } break;
  1095. default: {
  1096. };
  1097. }
  1098. }
  1099. void CustomPropertyEditor::_drag_easing(const Ref<InputEvent> &p_ev) {
  1100. Ref<InputEventMouseMotion> mm = p_ev;
  1101. if (mm.is_valid() && mm->get_button_mask() & BUTTON_MASK_LEFT) {
  1102. float rel = mm->get_relative().x;
  1103. if (rel == 0)
  1104. return;
  1105. bool flip = hint_text == "attenuation";
  1106. if (flip)
  1107. rel = -rel;
  1108. float val = v;
  1109. if (val == 0)
  1110. return;
  1111. bool sg = val < 0;
  1112. val = Math::absf(val);
  1113. val = Math::log(val) / Math::log((float)2.0);
  1114. //logspace
  1115. val += rel * 0.05;
  1116. val = Math::pow(2.0f, val);
  1117. if (sg)
  1118. val = -val;
  1119. v = val;
  1120. easing_draw->update();
  1121. emit_signal("variant_changed");
  1122. }
  1123. }
  1124. void CustomPropertyEditor::_draw_easing() {
  1125. RID ci = easing_draw->get_canvas_item();
  1126. Size2 s = easing_draw->get_size();
  1127. Rect2 r(Point2(), s);
  1128. r = r.grow(3);
  1129. easing_draw->get_theme_stylebox("normal", "LineEdit")->draw(ci, r);
  1130. int points = 48;
  1131. float prev = 1.0;
  1132. float exp = v;
  1133. bool flip = hint_text == "attenuation";
  1134. Ref<Font> f = easing_draw->get_theme_font("font", "Label");
  1135. Color color = easing_draw->get_theme_color("font_color", "Label");
  1136. for (int i = 1; i <= points; i++) {
  1137. float ifl = i / float(points);
  1138. float iflp = (i - 1) / float(points);
  1139. float h = 1.0 - Math::ease(ifl, exp);
  1140. if (flip) {
  1141. ifl = 1.0 - ifl;
  1142. iflp = 1.0 - iflp;
  1143. }
  1144. RenderingServer::get_singleton()->canvas_item_add_line(ci, Point2(iflp * s.width, prev * s.height), Point2(ifl * s.width, h * s.height), color);
  1145. prev = h;
  1146. }
  1147. f->draw(ci, Point2(10, 10 + f->get_ascent()), String::num(exp, 2), color);
  1148. }
  1149. void CustomPropertyEditor::_text_edit_changed() {
  1150. v = text_edit->get_text();
  1151. emit_signal("variant_changed");
  1152. }
  1153. void CustomPropertyEditor::_create_dialog_callback() {
  1154. v = create_dialog->get_selected_type();
  1155. emit_signal("variant_changed");
  1156. }
  1157. void CustomPropertyEditor::_create_selected_property(const String &p_prop) {
  1158. v = p_prop;
  1159. emit_signal("variant_changed");
  1160. }
  1161. void CustomPropertyEditor::_modified(String p_string) {
  1162. if (updating)
  1163. return;
  1164. updating = true;
  1165. switch (type) {
  1166. case Variant::INT: {
  1167. String text = value_editor[0]->get_text();
  1168. Ref<Expression> expr;
  1169. expr.instance();
  1170. Error err = expr->parse(text);
  1171. if (err != OK) {
  1172. v = value_editor[0]->get_text().to_int();
  1173. return;
  1174. } else {
  1175. v = expr->execute(Array(), nullptr, false);
  1176. }
  1177. emit_signal("variant_changed");
  1178. } break;
  1179. case Variant::FLOAT: {
  1180. if (hint != PROPERTY_HINT_EXP_EASING) {
  1181. String text = value_editor[0]->get_text();
  1182. v = _parse_real_expression(text);
  1183. emit_signal("variant_changed");
  1184. }
  1185. } break;
  1186. case Variant::STRING: {
  1187. v = value_editor[0]->get_text();
  1188. emit_signal("variant_changed");
  1189. } break;
  1190. case Variant::VECTOR2: {
  1191. Vector2 vec;
  1192. vec.x = _parse_real_expression(value_editor[0]->get_text());
  1193. vec.y = _parse_real_expression(value_editor[1]->get_text());
  1194. v = vec;
  1195. _emit_changed_whole_or_field();
  1196. } break;
  1197. case Variant::RECT2: {
  1198. Rect2 r2;
  1199. r2.position.x = _parse_real_expression(value_editor[0]->get_text());
  1200. r2.position.y = _parse_real_expression(value_editor[1]->get_text());
  1201. r2.size.x = _parse_real_expression(value_editor[2]->get_text());
  1202. r2.size.y = _parse_real_expression(value_editor[3]->get_text());
  1203. v = r2;
  1204. _emit_changed_whole_or_field();
  1205. } break;
  1206. case Variant::VECTOR3: {
  1207. Vector3 vec;
  1208. vec.x = _parse_real_expression(value_editor[0]->get_text());
  1209. vec.y = _parse_real_expression(value_editor[1]->get_text());
  1210. vec.z = _parse_real_expression(value_editor[2]->get_text());
  1211. v = vec;
  1212. _emit_changed_whole_or_field();
  1213. } break;
  1214. case Variant::PLANE: {
  1215. Plane pl;
  1216. pl.normal.x = _parse_real_expression(value_editor[0]->get_text());
  1217. pl.normal.y = _parse_real_expression(value_editor[1]->get_text());
  1218. pl.normal.z = _parse_real_expression(value_editor[2]->get_text());
  1219. pl.distance = _parse_real_expression(value_editor[3]->get_text());
  1220. v = pl;
  1221. _emit_changed_whole_or_field();
  1222. } break;
  1223. case Variant::QUAT: {
  1224. Quat q;
  1225. q.x = _parse_real_expression(value_editor[0]->get_text());
  1226. q.y = _parse_real_expression(value_editor[1]->get_text());
  1227. q.z = _parse_real_expression(value_editor[2]->get_text());
  1228. q.w = _parse_real_expression(value_editor[3]->get_text());
  1229. v = q;
  1230. _emit_changed_whole_or_field();
  1231. } break;
  1232. case Variant::AABB: {
  1233. Vector3 pos;
  1234. Vector3 size;
  1235. pos.x = _parse_real_expression(value_editor[0]->get_text());
  1236. pos.y = _parse_real_expression(value_editor[1]->get_text());
  1237. pos.z = _parse_real_expression(value_editor[2]->get_text());
  1238. size.x = _parse_real_expression(value_editor[3]->get_text());
  1239. size.y = _parse_real_expression(value_editor[4]->get_text());
  1240. size.z = _parse_real_expression(value_editor[5]->get_text());
  1241. v = AABB(pos, size);
  1242. _emit_changed_whole_or_field();
  1243. } break;
  1244. case Variant::TRANSFORM2D: {
  1245. Transform2D m;
  1246. for (int i = 0; i < 6; i++) {
  1247. m.elements[i / 2][i % 2] = _parse_real_expression(value_editor[i]->get_text());
  1248. }
  1249. v = m;
  1250. _emit_changed_whole_or_field();
  1251. } break;
  1252. case Variant::BASIS: {
  1253. Basis m;
  1254. for (int i = 0; i < 9; i++) {
  1255. m.elements[i / 3][i % 3] = _parse_real_expression(value_editor[i]->get_text());
  1256. }
  1257. v = m;
  1258. _emit_changed_whole_or_field();
  1259. } break;
  1260. case Variant::TRANSFORM: {
  1261. Basis basis;
  1262. for (int i = 0; i < 9; i++) {
  1263. basis.elements[i / 3][i % 3] = _parse_real_expression(value_editor[(i / 3) * 4 + i % 3]->get_text());
  1264. }
  1265. Vector3 origin;
  1266. origin.x = _parse_real_expression(value_editor[3]->get_text());
  1267. origin.y = _parse_real_expression(value_editor[7]->get_text());
  1268. origin.z = _parse_real_expression(value_editor[11]->get_text());
  1269. v = Transform(basis, origin);
  1270. _emit_changed_whole_or_field();
  1271. } break;
  1272. case Variant::COLOR: {
  1273. } break;
  1274. case Variant::NODE_PATH: {
  1275. v = NodePath(value_editor[0]->get_text());
  1276. emit_signal("variant_changed");
  1277. } break;
  1278. case Variant::DICTIONARY: {
  1279. } break;
  1280. case Variant::PACKED_BYTE_ARRAY: {
  1281. } break;
  1282. case Variant::PACKED_INT32_ARRAY: {
  1283. } break;
  1284. case Variant::PACKED_FLOAT32_ARRAY: {
  1285. } break;
  1286. case Variant::PACKED_STRING_ARRAY: {
  1287. } break;
  1288. case Variant::PACKED_VECTOR3_ARRAY: {
  1289. } break;
  1290. case Variant::PACKED_COLOR_ARRAY: {
  1291. } break;
  1292. default: {
  1293. }
  1294. }
  1295. updating = false;
  1296. }
  1297. real_t CustomPropertyEditor::_parse_real_expression(String text) {
  1298. Ref<Expression> expr;
  1299. expr.instance();
  1300. Error err = expr->parse(text);
  1301. real_t out;
  1302. if (err != OK) {
  1303. out = value_editor[0]->get_text().to_double();
  1304. } else {
  1305. out = expr->execute(Array(), nullptr, false);
  1306. }
  1307. return out;
  1308. }
  1309. void CustomPropertyEditor::_emit_changed_whole_or_field() {
  1310. if (!Input::get_singleton()->is_key_pressed(KEY_SHIFT)) {
  1311. emit_signal("variant_changed");
  1312. } else {
  1313. emit_signal("variant_field_changed", field_names[focused_value_editor]);
  1314. }
  1315. }
  1316. void CustomPropertyEditor::_range_modified(double p_value) {
  1317. v = p_value;
  1318. emit_signal("variant_changed");
  1319. }
  1320. void CustomPropertyEditor::_focus_enter() {
  1321. switch (type) {
  1322. case Variant::FLOAT:
  1323. case Variant::STRING:
  1324. case Variant::VECTOR2:
  1325. case Variant::RECT2:
  1326. case Variant::VECTOR3:
  1327. case Variant::PLANE:
  1328. case Variant::QUAT:
  1329. case Variant::AABB:
  1330. case Variant::TRANSFORM2D:
  1331. case Variant::BASIS:
  1332. case Variant::TRANSFORM: {
  1333. for (int i = 0; i < MAX_VALUE_EDITORS; ++i) {
  1334. if (value_editor[i]->has_focus()) {
  1335. focused_value_editor = i;
  1336. value_editor[i]->select_all();
  1337. break;
  1338. }
  1339. }
  1340. } break;
  1341. default: {
  1342. }
  1343. }
  1344. }
  1345. void CustomPropertyEditor::_focus_exit() {
  1346. switch (type) {
  1347. case Variant::FLOAT:
  1348. case Variant::STRING:
  1349. case Variant::VECTOR2:
  1350. case Variant::RECT2:
  1351. case Variant::VECTOR3:
  1352. case Variant::PLANE:
  1353. case Variant::QUAT:
  1354. case Variant::AABB:
  1355. case Variant::TRANSFORM2D:
  1356. case Variant::BASIS:
  1357. case Variant::TRANSFORM: {
  1358. for (int i = 0; i < MAX_VALUE_EDITORS; ++i) {
  1359. value_editor[i]->select(0, 0);
  1360. }
  1361. } break;
  1362. default: {
  1363. }
  1364. }
  1365. }
  1366. void CustomPropertyEditor::config_action_buttons(const List<String> &p_strings) {
  1367. Ref<StyleBox> sb = action_buttons[0]->get_theme_stylebox("panel");
  1368. int margin_top = sb->get_margin(MARGIN_TOP);
  1369. int margin_left = sb->get_margin(MARGIN_LEFT);
  1370. int margin_bottom = sb->get_margin(MARGIN_BOTTOM);
  1371. int margin_right = sb->get_margin(MARGIN_RIGHT);
  1372. int max_width = 0;
  1373. int height = 0;
  1374. for (int i = 0; i < MAX_ACTION_BUTTONS; i++) {
  1375. if (i < p_strings.size()) {
  1376. action_buttons[i]->show();
  1377. action_buttons[i]->set_text(p_strings[i]);
  1378. Size2 btn_m_size = action_buttons[i]->get_minimum_size();
  1379. if (btn_m_size.width > max_width)
  1380. max_width = btn_m_size.width;
  1381. } else {
  1382. action_buttons[i]->hide();
  1383. }
  1384. }
  1385. for (int i = 0; i < p_strings.size(); i++) {
  1386. Size2 btn_m_size = action_buttons[i]->get_size();
  1387. action_buttons[i]->set_position(Point2(0, height) + Point2(margin_left, margin_top));
  1388. action_buttons[i]->set_size(Size2(max_width, btn_m_size.height));
  1389. height += btn_m_size.height;
  1390. }
  1391. set_size(Size2(max_width, height) + Size2(margin_left + margin_right, margin_top + margin_bottom));
  1392. }
  1393. void CustomPropertyEditor::config_value_editors(int p_amount, int p_columns, int p_label_w, const List<String> &p_strings) {
  1394. int cell_width = 95;
  1395. int cell_height = 25;
  1396. int cell_margin = 5;
  1397. int hor_spacing = 5; // Spacing between labels and their values
  1398. int rows = ((p_amount - 1) / p_columns) + 1;
  1399. set_size(Size2(cell_margin + p_label_w + (cell_width + cell_margin + p_label_w) * p_columns, cell_margin + (cell_height + cell_margin) * rows) * EDSCALE);
  1400. for (int i = 0; i < MAX_VALUE_EDITORS; i++) {
  1401. int c = i % p_columns;
  1402. int r = i / p_columns;
  1403. if (i < p_amount) {
  1404. value_editor[i]->show();
  1405. value_label[i]->show();
  1406. value_label[i]->set_text(i < p_strings.size() ? p_strings[i] : String(""));
  1407. value_editor[i]->set_position(Point2(cell_margin + p_label_w + hor_spacing + (cell_width + cell_margin + p_label_w + hor_spacing) * c, cell_margin + (cell_height + cell_margin) * r) * EDSCALE);
  1408. value_editor[i]->set_size(Size2(cell_width, cell_height));
  1409. value_label[i]->set_position(Point2(cell_margin + (cell_width + cell_margin + p_label_w + hor_spacing) * c, cell_margin + (cell_height + cell_margin) * r) * EDSCALE);
  1410. value_editor[i]->set_editable(!read_only);
  1411. } else {
  1412. value_editor[i]->hide();
  1413. value_label[i]->hide();
  1414. }
  1415. }
  1416. }
  1417. void CustomPropertyEditor::_bind_methods() {
  1418. ADD_SIGNAL(MethodInfo("variant_changed"));
  1419. ADD_SIGNAL(MethodInfo("variant_field_changed", PropertyInfo(Variant::STRING, "field")));
  1420. ADD_SIGNAL(MethodInfo("resource_edit_request"));
  1421. }
  1422. CustomPropertyEditor::CustomPropertyEditor() {
  1423. read_only = false;
  1424. updating = false;
  1425. for (int i = 0; i < MAX_VALUE_EDITORS; i++) {
  1426. value_editor[i] = memnew(LineEdit);
  1427. add_child(value_editor[i]);
  1428. value_label[i] = memnew(Label);
  1429. add_child(value_label[i]);
  1430. value_editor[i]->hide();
  1431. value_label[i]->hide();
  1432. value_editor[i]->connect("text_entered", callable_mp(this, &CustomPropertyEditor::_modified));
  1433. value_editor[i]->connect("focus_entered", callable_mp(this, &CustomPropertyEditor::_focus_enter));
  1434. value_editor[i]->connect("focus_exited", callable_mp(this, &CustomPropertyEditor::_focus_exit));
  1435. }
  1436. focused_value_editor = -1;
  1437. for (int i = 0; i < 4; i++) {
  1438. scroll[i] = memnew(HScrollBar);
  1439. scroll[i]->hide();
  1440. scroll[i]->set_min(0);
  1441. scroll[i]->set_max(1.0);
  1442. scroll[i]->set_step(0.01);
  1443. add_child(scroll[i]);
  1444. }
  1445. checks20gc = memnew(GridContainer);
  1446. add_child(checks20gc);
  1447. checks20gc->set_columns(11);
  1448. for (int i = 0; i < 20; i++) {
  1449. if (i == 5 || i == 15) {
  1450. Control *space = memnew(Control);
  1451. space->set_custom_minimum_size(Size2(20, 0) * EDSCALE);
  1452. checks20gc->add_child(space);
  1453. }
  1454. checks20[i] = memnew(CheckBox);
  1455. checks20[i]->set_toggle_mode(true);
  1456. checks20[i]->set_focus_mode(Control::FOCUS_NONE);
  1457. checks20gc->add_child(checks20[i]);
  1458. checks20[i]->hide();
  1459. checks20[i]->connect("pressed", callable_mp(this, &CustomPropertyEditor::_action_pressed), make_binds(i));
  1460. checks20[i]->set_tooltip(vformat(TTR("Bit %d, val %d."), i, 1 << i));
  1461. }
  1462. text_edit = memnew(TextEdit);
  1463. add_child(text_edit);
  1464. text_edit->set_anchors_and_margins_preset(Control::PRESET_WIDE, Control::PRESET_MODE_MINSIZE, 5);
  1465. text_edit->set_margin(MARGIN_BOTTOM, -30);
  1466. text_edit->hide();
  1467. text_edit->connect("text_changed", callable_mp(this, &CustomPropertyEditor::_text_edit_changed));
  1468. for (int i = 0; i < MAX_ACTION_BUTTONS; i++) {
  1469. action_buttons[i] = memnew(Button);
  1470. action_buttons[i]->hide();
  1471. add_child(action_buttons[i]);
  1472. Vector<Variant> binds;
  1473. binds.push_back(i);
  1474. action_buttons[i]->connect("pressed", callable_mp(this, &CustomPropertyEditor::_action_pressed), binds);
  1475. action_buttons[i]->set_flat(true);
  1476. }
  1477. color_picker = nullptr;
  1478. file = memnew(EditorFileDialog);
  1479. add_child(file);
  1480. file->hide();
  1481. file->connect("file_selected", callable_mp(this, &CustomPropertyEditor::_file_selected));
  1482. file->connect("dir_selected", callable_mp(this, &CustomPropertyEditor::_file_selected));
  1483. error = memnew(ConfirmationDialog);
  1484. error->set_title(TTR("Error!"));
  1485. add_child(error);
  1486. scene_tree = memnew(SceneTreeDialog);
  1487. add_child(scene_tree);
  1488. scene_tree->connect("selected", callable_mp(this, &CustomPropertyEditor::_node_path_selected));
  1489. scene_tree->get_scene_tree()->set_show_enabled_subscene(true);
  1490. texture_preview = memnew(TextureRect);
  1491. add_child(texture_preview);
  1492. texture_preview->hide();
  1493. easing_draw = memnew(Control);
  1494. add_child(easing_draw);
  1495. easing_draw->hide();
  1496. easing_draw->connect("draw", callable_mp(this, &CustomPropertyEditor::_draw_easing));
  1497. easing_draw->connect("gui_input", callable_mp(this, &CustomPropertyEditor::_drag_easing));
  1498. easing_draw->set_default_cursor_shape(Control::CURSOR_MOVE);
  1499. type_button = memnew(MenuButton);
  1500. add_child(type_button);
  1501. type_button->hide();
  1502. type_button->get_popup()->connect("id_pressed", callable_mp(this, &CustomPropertyEditor::_type_create_selected));
  1503. menu = memnew(PopupMenu);
  1504. // menu->set_pass_on_modal_close_click(false);
  1505. add_child(menu);
  1506. menu->connect("id_pressed", callable_mp(this, &CustomPropertyEditor::_menu_option));
  1507. evaluator = nullptr;
  1508. spinbox = memnew(SpinBox);
  1509. add_child(spinbox);
  1510. spinbox->set_anchors_and_margins_preset(Control::PRESET_WIDE, Control::PRESET_MODE_MINSIZE, 5);
  1511. spinbox->connect("value_changed", callable_mp(this, &CustomPropertyEditor::_range_modified));
  1512. slider = memnew(HSlider);
  1513. add_child(slider);
  1514. slider->set_anchors_and_margins_preset(Control::PRESET_WIDE, Control::PRESET_MODE_MINSIZE, 5);
  1515. slider->connect("value_changed", callable_mp(this, &CustomPropertyEditor::_range_modified));
  1516. create_dialog = nullptr;
  1517. property_select = nullptr;
  1518. }