property_editor.cpp 54 KB

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