property_editor.cpp 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996
  1. /*************************************************************************/
  2. /* property_editor.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "property_editor.h"
  31. #include "core/class_db.h"
  32. #include "core/io/image_loader.h"
  33. #include "core/io/marshalls.h"
  34. #include "core/io/resource_loader.h"
  35. #include "core/math/expression.h"
  36. #include "core/os/input.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_settings.h"
  49. #include "editor/multi_node_edit.h"
  50. #include "editor/property_selector.h"
  51. #include "scene/gui/label.h"
  52. #include "scene/main/viewport.h"
  53. #include "scene/resources/font.h"
  54. #include "scene/resources/packed_scene.h"
  55. #include "scene/scene_string_names.h"
  56. void EditorResourceConversionPlugin::_bind_methods() {
  57. MethodInfo mi;
  58. mi.name = "_convert";
  59. mi.return_val.type = Variant::OBJECT;
  60. mi.return_val.class_name = "Resource";
  61. mi.return_val.hint = PROPERTY_HINT_RESOURCE_TYPE;
  62. mi.return_val.hint_string = "Resource";
  63. mi.arguments.push_back(mi.return_val);
  64. mi.arguments[0].name = "resource";
  65. BIND_VMETHOD(mi)
  66. mi.name = "_handles";
  67. mi.return_val = PropertyInfo(Variant::BOOL, "");
  68. BIND_VMETHOD(MethodInfo(Variant::STRING, "_converts_to"));
  69. }
  70. String EditorResourceConversionPlugin::converts_to() const {
  71. if (get_script_instance())
  72. return get_script_instance()->call("_converts_to");
  73. return "";
  74. }
  75. bool EditorResourceConversionPlugin::handles(const Ref<Resource> &p_resource) const {
  76. if (get_script_instance())
  77. return get_script_instance()->call("_handles", p_resource);
  78. return false;
  79. }
  80. Ref<Resource> EditorResourceConversionPlugin::convert(const Ref<Resource> &p_resource) const {
  81. if (get_script_instance())
  82. return get_script_instance()->call("_convert", p_resource);
  83. return Ref<Resource>();
  84. }
  85. void CustomPropertyEditor::_notification(int p_what) {
  86. if (p_what == NOTIFICATION_DRAW) {
  87. RID ci = get_canvas_item();
  88. get_stylebox("panel", "PopupMenu")->draw(ci, Rect2(Point2(), get_size()));
  89. }
  90. if (p_what == MainLoop::NOTIFICATION_WM_QUIT_REQUEST) {
  91. hide();
  92. }
  93. }
  94. void CustomPropertyEditor::_menu_option(int p_which) {
  95. switch (type) {
  96. case Variant::INT: {
  97. if (hint == PROPERTY_HINT_FLAGS) {
  98. int val = v;
  99. if (val & (1 << p_which)) {
  100. val &= ~(1 << p_which);
  101. } else {
  102. val |= (1 << p_which);
  103. }
  104. v = val;
  105. emit_signal("variant_changed");
  106. } else if (hint == PROPERTY_HINT_ENUM) {
  107. v = menu->get_item_metadata(p_which);
  108. emit_signal("variant_changed");
  109. }
  110. } break;
  111. case Variant::STRING: {
  112. if (hint == PROPERTY_HINT_ENUM) {
  113. v = hint_text.get_slice(",", p_which);
  114. emit_signal("variant_changed");
  115. }
  116. } break;
  117. case Variant::OBJECT: {
  118. switch (p_which) {
  119. case OBJ_MENU_LOAD: {
  120. file->set_mode(EditorFileDialog::MODE_OPEN_FILE);
  121. String type = (hint == PROPERTY_HINT_RESOURCE_TYPE) ? hint_text : String();
  122. List<String> extensions;
  123. for (int i = 0; i < type.get_slice_count(","); i++) {
  124. ResourceLoader::get_recognized_extensions_for_type(type.get_slice(",", i), &extensions);
  125. }
  126. Set<String> valid_extensions;
  127. for (List<String>::Element *E = extensions.front(); E; E = E->next()) {
  128. valid_extensions.insert(E->get());
  129. }
  130. file->clear_filters();
  131. for (Set<String>::Element *E = valid_extensions.front(); E; E = E->next()) {
  132. file->add_filter("*." + E->get() + " ; " + E->get().to_upper());
  133. }
  134. file->popup_centered_ratio();
  135. } break;
  136. case OBJ_MENU_EDIT: {
  137. RefPtr RefPtr = v;
  138. if (!RefPtr.is_null()) {
  139. emit_signal("resource_edit_request");
  140. hide();
  141. }
  142. } break;
  143. case OBJ_MENU_CLEAR: {
  144. v = Variant();
  145. emit_signal("variant_changed");
  146. hide();
  147. } break;
  148. case OBJ_MENU_MAKE_UNIQUE: {
  149. RefPtr RefPtr = v;
  150. Ref<Resource> res_orig = RefPtr;
  151. if (res_orig.is_null())
  152. return;
  153. List<PropertyInfo> property_list;
  154. res_orig->get_property_list(&property_list);
  155. List<Pair<String, Variant> > propvalues;
  156. for (List<PropertyInfo>::Element *E = property_list.front(); E; E = E->next()) {
  157. Pair<String, Variant> p;
  158. PropertyInfo &pi = E->get();
  159. if (pi.usage & PROPERTY_USAGE_STORAGE) {
  160. p.first = pi.name;
  161. p.second = res_orig->get(pi.name);
  162. }
  163. propvalues.push_back(p);
  164. }
  165. String orig_type = res_orig->get_class();
  166. Object *inst = ClassDB::instance(orig_type);
  167. Ref<Resource> res = Ref<Resource>(Object::cast_to<Resource>(inst));
  168. ERR_FAIL_COND(res.is_null());
  169. for (List<Pair<String, Variant> >::Element *E = propvalues.front(); E; E = E->next()) {
  170. Pair<String, Variant> &p = E->get();
  171. res->set(p.first, p.second);
  172. }
  173. v = res.get_ref_ptr();
  174. emit_signal("variant_changed");
  175. hide();
  176. } break;
  177. case OBJ_MENU_COPY: {
  178. EditorSettings::get_singleton()->set_resource_clipboard(v);
  179. } break;
  180. case OBJ_MENU_PASTE: {
  181. v = EditorSettings::get_singleton()->get_resource_clipboard();
  182. emit_signal("variant_changed");
  183. } break;
  184. case OBJ_MENU_NEW_SCRIPT: {
  185. if (Object::cast_to<Node>(owner))
  186. EditorNode::get_singleton()->get_scene_tree_dock()->open_script_dialog(Object::cast_to<Node>(owner));
  187. } break;
  188. case OBJ_MENU_SHOW_IN_FILE_SYSTEM: {
  189. RES r = v;
  190. FileSystemDock *file_system_dock = EditorNode::get_singleton()->get_filesystem_dock();
  191. file_system_dock->navigate_to_path(r->get_path());
  192. // Ensure that the FileSystem dock is visible.
  193. TabContainer *tab_container = (TabContainer *)file_system_dock->get_parent_control();
  194. tab_container->set_current_tab(file_system_dock->get_position_in_parent());
  195. } break;
  196. default: {
  197. if (p_which >= CONVERT_BASE_ID) {
  198. int to_type = p_which - CONVERT_BASE_ID;
  199. Vector<Ref<EditorResourceConversionPlugin> > conversions = EditorNode::get_singleton()->find_resource_conversion_plugin(RES(v));
  200. ERR_FAIL_INDEX(to_type, conversions.size());
  201. Ref<Resource> new_res = conversions[to_type]->convert(v);
  202. v = new_res;
  203. emit_signal("variant_changed");
  204. break;
  205. }
  206. ERR_FAIL_COND(inheritors_array.empty());
  207. String intype = inheritors_array[p_which - TYPE_BASE_ID];
  208. if (intype == "ViewportTexture") {
  209. scene_tree->set_title(TTR("Pick a Viewport"));
  210. scene_tree->popup_centered_ratio();
  211. picking_viewport = true;
  212. return;
  213. }
  214. Object *obj = ClassDB::instance(intype);
  215. if (!obj) {
  216. if (ScriptServer::is_global_class(intype)) {
  217. obj = EditorNode::get_editor_data().script_class_instance(intype);
  218. } else {
  219. obj = EditorNode::get_editor_data().instance_custom_type(intype, "Resource");
  220. }
  221. }
  222. ERR_BREAK(!obj);
  223. Resource *res = Object::cast_to<Resource>(obj);
  224. ERR_BREAK(!res);
  225. if (owner && hint == PROPERTY_HINT_RESOURCE_TYPE && hint_text == "Script") {
  226. //make visual script the right type
  227. res->call("set_instance_base_type", owner->get_class());
  228. }
  229. v = Ref<Resource>(res).get_ref_ptr();
  230. emit_signal("variant_changed");
  231. } break;
  232. }
  233. } break;
  234. default: {}
  235. }
  236. }
  237. void CustomPropertyEditor::hide_menu() {
  238. menu->hide();
  239. }
  240. Variant CustomPropertyEditor::get_variant() const {
  241. return v;
  242. }
  243. String CustomPropertyEditor::get_name() const {
  244. return name;
  245. }
  246. 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) {
  247. owner = p_owner;
  248. updating = true;
  249. name = p_name;
  250. v = p_variant;
  251. field_names.clear();
  252. hint = p_hint;
  253. hint_text = p_hint_text;
  254. type_button->hide();
  255. if (color_picker)
  256. color_picker->hide();
  257. texture_preview->hide();
  258. inheritors_array.clear();
  259. text_edit->hide();
  260. easing_draw->hide();
  261. spinbox->hide();
  262. slider->hide();
  263. menu->clear();
  264. menu->set_size(Size2(1, 1) * EDSCALE);
  265. for (int i = 0; i < MAX_VALUE_EDITORS; i++) {
  266. value_editor[i]->hide();
  267. value_label[i]->hide();
  268. if (i < 4)
  269. scroll[i]->hide();
  270. }
  271. for (int i = 0; i < MAX_ACTION_BUTTONS; i++) {
  272. action_buttons[i]->hide();
  273. }
  274. checks20gc->hide();
  275. for (int i = 0; i < 20; i++)
  276. checks20[i]->hide();
  277. type = (p_variant.get_type() != Variant::NIL && p_variant.get_type() != Variant::_RID && p_type != Variant::OBJECT) ? p_variant.get_type() : p_type;
  278. switch (type) {
  279. case Variant::BOOL: {
  280. checks20gc->show();
  281. CheckBox *c = checks20[0];
  282. c->set_text("True");
  283. checks20gc->set_position(Vector2(4, 4) * EDSCALE);
  284. c->set_pressed(v);
  285. c->show();
  286. checks20gc->set_size(checks20gc->get_minimum_size());
  287. set_size(checks20gc->get_position() + checks20gc->get_size() + c->get_size() + Vector2(4, 4) * EDSCALE);
  288. } break;
  289. case Variant::INT:
  290. case Variant::REAL: {
  291. if (hint == PROPERTY_HINT_RANGE) {
  292. int c = hint_text.get_slice_count(",");
  293. float min = 0, max = 100, step = type == Variant::REAL ? .01 : 1;
  294. if (c >= 1) {
  295. if (!hint_text.get_slice(",", 0).empty())
  296. min = hint_text.get_slice(",", 0).to_double();
  297. }
  298. if (c >= 2) {
  299. if (!hint_text.get_slice(",", 1).empty())
  300. max = hint_text.get_slice(",", 1).to_double();
  301. }
  302. if (c >= 3) {
  303. if (!hint_text.get_slice(",", 2).empty())
  304. step = hint_text.get_slice(",", 2).to_double();
  305. }
  306. if (c >= 4 && hint_text.get_slice(",", 3) == "slider") {
  307. slider->set_min(min);
  308. slider->set_max(max);
  309. slider->set_step(step);
  310. slider->set_value(v);
  311. slider->show();
  312. set_size(Size2(110, 30) * EDSCALE);
  313. } else {
  314. spinbox->set_min(min);
  315. spinbox->set_max(max);
  316. spinbox->set_step(step);
  317. spinbox->set_value(v);
  318. spinbox->show();
  319. set_size(Size2(70, 35) * EDSCALE);
  320. }
  321. } else if (hint == PROPERTY_HINT_ENUM) {
  322. Vector<String> options = hint_text.split(",");
  323. int current_val = 0;
  324. for (int i = 0; i < options.size(); i++) {
  325. Vector<String> text_split = options[i].split(":");
  326. if (text_split.size() != 1)
  327. current_val = text_split[1].to_int();
  328. menu->add_item(text_split[0]);
  329. menu->set_item_metadata(i, current_val);
  330. current_val += 1;
  331. }
  332. menu->set_position(get_position());
  333. menu->popup();
  334. hide();
  335. updating = false;
  336. return false;
  337. } 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) {
  338. String basename;
  339. switch (hint) {
  340. case PROPERTY_HINT_LAYERS_2D_RENDER:
  341. basename = "layer_names/2d_render";
  342. break;
  343. case PROPERTY_HINT_LAYERS_2D_PHYSICS:
  344. basename = "layer_names/2d_physics";
  345. break;
  346. case PROPERTY_HINT_LAYERS_3D_RENDER:
  347. basename = "layer_names/3d_render";
  348. break;
  349. case PROPERTY_HINT_LAYERS_3D_PHYSICS:
  350. basename = "layer_names/3d_physics";
  351. break;
  352. }
  353. checks20gc->show();
  354. uint32_t flgs = v;
  355. for (int i = 0; i < 2; i++) {
  356. Point2 ofs(4, 4);
  357. ofs.y += 22 * i;
  358. for (int j = 0; j < 10; j++) {
  359. int idx = i * 10 + j;
  360. CheckBox *c = checks20[idx];
  361. c->set_text(ProjectSettings::get_singleton()->get(basename + "/layer_" + itos(idx + 1)));
  362. c->set_pressed(flgs & (1 << (i * 10 + j)));
  363. c->show();
  364. }
  365. }
  366. show();
  367. checks20gc->set_position(Vector2(4, 4) * EDSCALE);
  368. checks20gc->set_size(checks20gc->get_minimum_size());
  369. set_size(Vector2(4, 4) * EDSCALE + checks20gc->get_position() + checks20gc->get_size());
  370. } else if (hint == PROPERTY_HINT_EXP_EASING) {
  371. easing_draw->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_BEGIN, 5 * EDSCALE);
  372. easing_draw->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, -5 * EDSCALE);
  373. easing_draw->set_anchor_and_margin(MARGIN_TOP, ANCHOR_BEGIN, 5 * EDSCALE);
  374. easing_draw->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, -30 * EDSCALE);
  375. type_button->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_BEGIN, 3 * EDSCALE);
  376. type_button->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, -3 * EDSCALE);
  377. type_button->set_anchor_and_margin(MARGIN_TOP, ANCHOR_END, -25 * EDSCALE);
  378. type_button->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, -7 * EDSCALE);
  379. type_button->set_text(TTR("Preset..."));
  380. type_button->get_popup()->clear();
  381. type_button->get_popup()->add_item(TTR("Linear"), EASING_LINEAR);
  382. type_button->get_popup()->add_item(TTR("Ease In"), EASING_EASE_IN);
  383. type_button->get_popup()->add_item(TTR("Ease Out"), EASING_EASE_OUT);
  384. if (hint_text != "attenuation") {
  385. type_button->get_popup()->add_item(TTR("Zero"), EASING_ZERO);
  386. type_button->get_popup()->add_item(TTR("Easing In-Out"), EASING_IN_OUT);
  387. type_button->get_popup()->add_item(TTR("Easing Out-In"), EASING_OUT_IN);
  388. }
  389. type_button->show();
  390. easing_draw->show();
  391. set_size(Size2(200, 150) * EDSCALE);
  392. } else if (hint == PROPERTY_HINT_FLAGS) {
  393. Vector<String> flags = hint_text.split(",");
  394. for (int i = 0; i < flags.size(); i++) {
  395. String flag = flags[i];
  396. if (flag == "")
  397. continue;
  398. menu->add_check_item(flag, i);
  399. int f = v;
  400. if (f & (1 << i))
  401. menu->set_item_checked(menu->get_item_index(i), true);
  402. }
  403. menu->set_position(get_position());
  404. menu->popup();
  405. hide();
  406. updating = false;
  407. return false;
  408. } else {
  409. List<String> names;
  410. names.push_back("value:");
  411. config_value_editors(1, 1, 50, names);
  412. value_editor[0]->set_text(String::num(v));
  413. }
  414. } break;
  415. case Variant::STRING: {
  416. if (hint == PROPERTY_HINT_FILE || hint == PROPERTY_HINT_GLOBAL_FILE) {
  417. List<String> names;
  418. names.push_back(TTR("File..."));
  419. names.push_back(TTR("Clear"));
  420. config_action_buttons(names);
  421. } else if (hint == PROPERTY_HINT_DIR || hint == PROPERTY_HINT_GLOBAL_DIR) {
  422. List<String> names;
  423. names.push_back(TTR("Dir..."));
  424. names.push_back(TTR("Clear"));
  425. config_action_buttons(names);
  426. } else if (hint == PROPERTY_HINT_ENUM) {
  427. Vector<String> options = hint_text.split(",");
  428. for (int i = 0; i < options.size(); i++) {
  429. menu->add_item(options[i], i);
  430. }
  431. menu->set_position(get_position());
  432. menu->popup();
  433. hide();
  434. updating = false;
  435. return false;
  436. } else if (hint == PROPERTY_HINT_MULTILINE_TEXT) {
  437. text_edit->show();
  438. text_edit->set_text(v);
  439. text_edit->deselect();
  440. int button_margin = get_constant("button_margin", "Dialogs");
  441. int margin = get_constant("margin", "Dialogs");
  442. action_buttons[0]->set_anchor(MARGIN_LEFT, ANCHOR_END);
  443. action_buttons[0]->set_anchor(MARGIN_TOP, ANCHOR_END);
  444. action_buttons[0]->set_anchor(MARGIN_RIGHT, ANCHOR_END);
  445. action_buttons[0]->set_anchor(MARGIN_BOTTOM, ANCHOR_END);
  446. action_buttons[0]->set_begin(Point2(-70 * EDSCALE, -button_margin + 5 * EDSCALE));
  447. action_buttons[0]->set_end(Point2(-margin, -margin));
  448. action_buttons[0]->set_text(TTR("Close"));
  449. action_buttons[0]->show();
  450. } else if (hint == PROPERTY_HINT_TYPE_STRING) {
  451. if (!create_dialog) {
  452. create_dialog = memnew(CreateDialog);
  453. create_dialog->connect("create", this, "_create_dialog_callback");
  454. add_child(create_dialog);
  455. }
  456. if (hint_text != String()) {
  457. create_dialog->set_base_type(hint_text);
  458. } else {
  459. create_dialog->set_base_type("Object");
  460. }
  461. create_dialog->popup_create(false);
  462. hide();
  463. updating = false;
  464. return false;
  465. } else if (hint == PROPERTY_HINT_METHOD_OF_VARIANT_TYPE) {
  466. #define MAKE_PROPSELECT \
  467. if (!property_select) { \
  468. property_select = memnew(PropertySelector); \
  469. property_select->connect("selected", this, "_create_selected_property"); \
  470. add_child(property_select); \
  471. } \
  472. hide();
  473. MAKE_PROPSELECT;
  474. Variant::Type type = Variant::NIL;
  475. for (int i = 0; i < Variant::VARIANT_MAX; i++) {
  476. if (hint_text == Variant::get_type_name(Variant::Type(i))) {
  477. type = Variant::Type(i);
  478. }
  479. }
  480. if (type)
  481. property_select->select_method_from_basic_type(type, v);
  482. updating = false;
  483. return false;
  484. } else if (hint == PROPERTY_HINT_METHOD_OF_BASE_TYPE) {
  485. MAKE_PROPSELECT
  486. property_select->select_method_from_base_type(hint_text, v);
  487. updating = false;
  488. return false;
  489. } else if (hint == PROPERTY_HINT_METHOD_OF_INSTANCE) {
  490. MAKE_PROPSELECT
  491. Object *instance = ObjectDB::get_instance(hint_text.to_int64());
  492. if (instance)
  493. property_select->select_method_from_instance(instance, v);
  494. updating = false;
  495. return false;
  496. } else if (hint == PROPERTY_HINT_METHOD_OF_SCRIPT) {
  497. MAKE_PROPSELECT
  498. Object *obj = ObjectDB::get_instance(hint_text.to_int64());
  499. if (Object::cast_to<Script>(obj)) {
  500. property_select->select_method_from_script(Object::cast_to<Script>(obj), v);
  501. }
  502. updating = false;
  503. return false;
  504. } else if (hint == PROPERTY_HINT_PROPERTY_OF_VARIANT_TYPE) {
  505. MAKE_PROPSELECT
  506. Variant::Type type = Variant::NIL;
  507. String tname = hint_text;
  508. if (tname.find(".") != -1)
  509. tname = tname.get_slice(".", 0);
  510. for (int i = 0; i < Variant::VARIANT_MAX; i++) {
  511. if (tname == Variant::get_type_name(Variant::Type(i))) {
  512. type = Variant::Type(Variant::Type(i));
  513. }
  514. }
  515. if (type != Variant::NIL)
  516. property_select->select_property_from_basic_type(type, v);
  517. updating = false;
  518. return false;
  519. } else if (hint == PROPERTY_HINT_PROPERTY_OF_BASE_TYPE) {
  520. MAKE_PROPSELECT
  521. property_select->select_property_from_base_type(hint_text, v);
  522. updating = false;
  523. return false;
  524. } else if (hint == PROPERTY_HINT_PROPERTY_OF_INSTANCE) {
  525. MAKE_PROPSELECT
  526. Object *instance = ObjectDB::get_instance(hint_text.to_int64());
  527. if (instance)
  528. property_select->select_property_from_instance(instance, v);
  529. updating = false;
  530. return false;
  531. } else if (hint == PROPERTY_HINT_PROPERTY_OF_SCRIPT) {
  532. MAKE_PROPSELECT
  533. Object *obj = ObjectDB::get_instance(hint_text.to_int64());
  534. if (Object::cast_to<Script>(obj)) {
  535. property_select->select_property_from_script(Object::cast_to<Script>(obj), v);
  536. }
  537. updating = false;
  538. return false;
  539. } else {
  540. List<String> names;
  541. names.push_back("string:");
  542. config_value_editors(1, 1, 50, names);
  543. value_editor[0]->set_text(v);
  544. }
  545. } break;
  546. case Variant::VECTOR2: {
  547. field_names.push_back("x");
  548. field_names.push_back("y");
  549. config_value_editors(2, 2, 10, field_names);
  550. Vector2 vec = v;
  551. value_editor[0]->set_text(String::num(vec.x));
  552. value_editor[1]->set_text(String::num(vec.y));
  553. } break;
  554. case Variant::RECT2: {
  555. field_names.push_back("x");
  556. field_names.push_back("y");
  557. field_names.push_back("w");
  558. field_names.push_back("h");
  559. config_value_editors(4, 4, 10, field_names);
  560. Rect2 r = v;
  561. value_editor[0]->set_text(String::num(r.position.x));
  562. value_editor[1]->set_text(String::num(r.position.y));
  563. value_editor[2]->set_text(String::num(r.size.x));
  564. value_editor[3]->set_text(String::num(r.size.y));
  565. } break;
  566. case Variant::VECTOR3: {
  567. field_names.push_back("x");
  568. field_names.push_back("y");
  569. field_names.push_back("z");
  570. config_value_editors(3, 3, 10, field_names);
  571. Vector3 vec = v;
  572. value_editor[0]->set_text(String::num(vec.x));
  573. value_editor[1]->set_text(String::num(vec.y));
  574. value_editor[2]->set_text(String::num(vec.z));
  575. } break;
  576. case Variant::PLANE: {
  577. field_names.push_back("x");
  578. field_names.push_back("y");
  579. field_names.push_back("z");
  580. field_names.push_back("d");
  581. config_value_editors(4, 4, 10, field_names);
  582. Plane plane = v;
  583. value_editor[0]->set_text(String::num(plane.normal.x));
  584. value_editor[1]->set_text(String::num(plane.normal.y));
  585. value_editor[2]->set_text(String::num(plane.normal.z));
  586. value_editor[3]->set_text(String::num(plane.d));
  587. } break;
  588. case Variant::QUAT: {
  589. field_names.push_back("x");
  590. field_names.push_back("y");
  591. field_names.push_back("z");
  592. field_names.push_back("w");
  593. config_value_editors(4, 4, 10, field_names);
  594. Quat q = v;
  595. value_editor[0]->set_text(String::num(q.x));
  596. value_editor[1]->set_text(String::num(q.y));
  597. value_editor[2]->set_text(String::num(q.z));
  598. value_editor[3]->set_text(String::num(q.w));
  599. } break;
  600. case Variant::AABB: {
  601. field_names.push_back("px");
  602. field_names.push_back("py");
  603. field_names.push_back("pz");
  604. field_names.push_back("sx");
  605. field_names.push_back("sy");
  606. field_names.push_back("sz");
  607. config_value_editors(6, 3, 16, field_names);
  608. AABB aabb = v;
  609. value_editor[0]->set_text(String::num(aabb.position.x));
  610. value_editor[1]->set_text(String::num(aabb.position.y));
  611. value_editor[2]->set_text(String::num(aabb.position.z));
  612. value_editor[3]->set_text(String::num(aabb.size.x));
  613. value_editor[4]->set_text(String::num(aabb.size.y));
  614. value_editor[5]->set_text(String::num(aabb.size.z));
  615. } break;
  616. case Variant::TRANSFORM2D: {
  617. field_names.push_back("xx");
  618. field_names.push_back("xy");
  619. field_names.push_back("yx");
  620. field_names.push_back("yy");
  621. field_names.push_back("ox");
  622. field_names.push_back("oy");
  623. config_value_editors(6, 2, 16, field_names);
  624. Transform2D basis = v;
  625. for (int i = 0; i < 6; i++) {
  626. value_editor[i]->set_text(String::num(basis.elements[i / 2][i % 2]));
  627. }
  628. } break;
  629. case Variant::BASIS: {
  630. field_names.push_back("xx");
  631. field_names.push_back("xy");
  632. field_names.push_back("xz");
  633. field_names.push_back("yx");
  634. field_names.push_back("yy");
  635. field_names.push_back("yz");
  636. field_names.push_back("zx");
  637. field_names.push_back("zy");
  638. field_names.push_back("zz");
  639. config_value_editors(9, 3, 16, field_names);
  640. Basis basis = v;
  641. for (int i = 0; i < 9; i++) {
  642. value_editor[i]->set_text(String::num(basis.elements[i / 3][i % 3]));
  643. }
  644. } break;
  645. case Variant::TRANSFORM: {
  646. field_names.push_back("xx");
  647. field_names.push_back("xy");
  648. field_names.push_back("xz");
  649. field_names.push_back("xo");
  650. field_names.push_back("yx");
  651. field_names.push_back("yy");
  652. field_names.push_back("yz");
  653. field_names.push_back("yo");
  654. field_names.push_back("zx");
  655. field_names.push_back("zy");
  656. field_names.push_back("zz");
  657. field_names.push_back("zo");
  658. config_value_editors(12, 4, 16, field_names);
  659. Transform tr = v;
  660. for (int i = 0; i < 9; i++) {
  661. value_editor[(i / 3) * 4 + i % 3]->set_text(String::num(tr.basis.elements[i / 3][i % 3]));
  662. }
  663. value_editor[3]->set_text(String::num(tr.origin.x));
  664. value_editor[7]->set_text(String::num(tr.origin.y));
  665. value_editor[11]->set_text(String::num(tr.origin.z));
  666. } break;
  667. case Variant::COLOR: {
  668. if (!color_picker) {
  669. //late init for performance
  670. color_picker = memnew(ColorPicker);
  671. color_picker->set_deferred_mode(true);
  672. add_child(color_picker);
  673. color_picker->hide();
  674. color_picker->connect("color_changed", this, "_color_changed");
  675. }
  676. color_picker->show();
  677. color_picker->set_edit_alpha(hint != PROPERTY_HINT_COLOR_NO_ALPHA);
  678. color_picker->set_pick_color(v);
  679. color_picker->set_focus_on_line_edit();
  680. } break;
  681. case Variant::NODE_PATH: {
  682. List<String> names;
  683. names.push_back(TTR("Assign"));
  684. names.push_back(TTR("Clear"));
  685. if (owner && owner->is_class("Node") && (v.get_type() == Variant::NODE_PATH) && Object::cast_to<Node>(owner)->has_node(v))
  686. names.push_back(TTR("Select Node"));
  687. config_action_buttons(names);
  688. } break;
  689. case Variant::OBJECT: {
  690. if (hint != PROPERTY_HINT_RESOURCE_TYPE)
  691. break;
  692. if (p_name == "script" && hint_text == "Script" && Object::cast_to<Node>(owner)) {
  693. menu->add_icon_item(get_icon("Script", "EditorIcons"), TTR("New Script"), OBJ_MENU_NEW_SCRIPT);
  694. menu->add_separator();
  695. } else if (hint_text != "") {
  696. int idx = 0;
  697. Vector<EditorData::CustomType> custom_resources;
  698. if (EditorNode::get_editor_data().get_custom_types().has("Resource")) {
  699. custom_resources = EditorNode::get_editor_data().get_custom_types()["Resource"];
  700. }
  701. for (int i = 0; i < hint_text.get_slice_count(","); i++) {
  702. String base = hint_text.get_slice(",", i);
  703. Set<String> valid_inheritors;
  704. valid_inheritors.insert(base);
  705. List<StringName> inheritors;
  706. ClassDB::get_inheriters_from_class(base.strip_edges(), &inheritors);
  707. for (int i = 0; i < custom_resources.size(); i++) {
  708. inheritors.push_back(custom_resources[i].name);
  709. }
  710. List<StringName>::Element *E = inheritors.front();
  711. while (E) {
  712. valid_inheritors.insert(E->get());
  713. E = E->next();
  714. }
  715. for (Set<String>::Element *E = valid_inheritors.front(); E; E = E->next()) {
  716. String t = E->get();
  717. bool is_custom_resource = false;
  718. Ref<Texture> icon;
  719. if (!custom_resources.empty()) {
  720. for (int i = 0; i < custom_resources.size(); i++) {
  721. if (custom_resources[i].name == t) {
  722. is_custom_resource = true;
  723. if (custom_resources[i].icon.is_valid())
  724. icon = custom_resources[i].icon;
  725. break;
  726. }
  727. }
  728. }
  729. if (!is_custom_resource && !ClassDB::can_instance(t))
  730. continue;
  731. inheritors_array.push_back(t);
  732. int id = TYPE_BASE_ID + idx;
  733. if (!icon.is_valid() && has_icon(t, "EditorIcons")) {
  734. icon = get_icon(t, "EditorIcons");
  735. }
  736. if (icon.is_valid()) {
  737. menu->add_icon_item(icon, vformat(TTR("New %s"), t), id);
  738. } else {
  739. menu->add_item(vformat(TTR("New %s"), t), id);
  740. }
  741. idx++;
  742. }
  743. }
  744. if (menu->get_item_count())
  745. menu->add_separator();
  746. }
  747. menu->add_icon_item(get_icon("Load", "EditorIcons"), TTR("Load"), OBJ_MENU_LOAD);
  748. if (!RES(v).is_null()) {
  749. menu->add_icon_item(get_icon("Edit", "EditorIcons"), TTR("Edit"), OBJ_MENU_EDIT);
  750. menu->add_icon_item(get_icon("Clear", "EditorIcons"), TTR("Clear"), OBJ_MENU_CLEAR);
  751. menu->add_icon_item(get_icon("Duplicate", "EditorIcons"), TTR("Make Unique"), OBJ_MENU_MAKE_UNIQUE);
  752. RES r = v;
  753. if (r.is_valid() && r->get_path().is_resource_file()) {
  754. menu->add_separator();
  755. menu->add_item(TTR("Show in FileSystem"), OBJ_MENU_SHOW_IN_FILE_SYSTEM);
  756. }
  757. } else {
  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. Ref<Texture> icon;
  788. if (has_icon(what, "EditorIcons")) {
  789. icon = get_icon(what, "EditorIcons");
  790. } else {
  791. icon = get_icon(what, "Resource");
  792. }
  793. menu->add_icon_item(icon, vformat(TTR("Convert To %s"), what), CONVERT_BASE_ID + i);
  794. }
  795. }
  796. menu->set_position(get_position());
  797. menu->popup();
  798. hide();
  799. updating = false;
  800. return false;
  801. } break;
  802. case Variant::DICTIONARY: {
  803. } break;
  804. case Variant::POOL_BYTE_ARRAY: {
  805. } break;
  806. case Variant::POOL_INT_ARRAY: {
  807. } break;
  808. case Variant::POOL_REAL_ARRAY: {
  809. } break;
  810. case Variant::POOL_STRING_ARRAY: {
  811. } break;
  812. case Variant::POOL_VECTOR3_ARRAY: {
  813. } break;
  814. case Variant::POOL_COLOR_ARRAY: {
  815. } break;
  816. default: {}
  817. }
  818. updating = false;
  819. return true;
  820. }
  821. void CustomPropertyEditor::_file_selected(String p_file) {
  822. switch (type) {
  823. case Variant::STRING: {
  824. if (hint == PROPERTY_HINT_FILE || hint == PROPERTY_HINT_DIR) {
  825. v = ProjectSettings::get_singleton()->localize_path(p_file);
  826. emit_signal("variant_changed");
  827. hide();
  828. }
  829. if (hint == PROPERTY_HINT_GLOBAL_FILE || hint == PROPERTY_HINT_GLOBAL_DIR) {
  830. v = p_file;
  831. emit_signal("variant_changed");
  832. hide();
  833. }
  834. } break;
  835. case Variant::OBJECT: {
  836. String type = (hint == PROPERTY_HINT_RESOURCE_TYPE) ? hint_text : String();
  837. RES res = ResourceLoader::load(p_file, type);
  838. if (res.is_null()) {
  839. error->set_text(TTR("Error loading file: Not a resource!"));
  840. error->popup_centered_minsize();
  841. break;
  842. }
  843. v = res.get_ref_ptr();
  844. emit_signal("variant_changed");
  845. hide();
  846. } break;
  847. default: {}
  848. }
  849. }
  850. void CustomPropertyEditor::_type_create_selected(int p_idx) {
  851. if (type == Variant::INT || type == Variant::REAL) {
  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 = Ref<Resource>(res).get_ref_ptr();
  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 = NULL;
  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_mode(EditorFileDialog::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_mode(EditorFileDialog::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 = Ref<Resource>(res).get_ref_ptr();
  1044. emit_signal("variant_changed");
  1045. hide();
  1046. }
  1047. } else if (p_which == 1) {
  1048. file->set_access(EditorFileDialog::ACCESS_RESOURCES);
  1049. file->set_mode(EditorFileDialog::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. RefPtr RefPtr = v;
  1060. if (!RefPtr.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. RefPtr RefPtr = v;
  1070. Ref<Resource> res_orig = RefPtr;
  1071. if (res_orig.is_null())
  1072. return;
  1073. List<PropertyInfo> property_list;
  1074. res_orig->get_property_list(&property_list);
  1075. List<Pair<String, Variant> > propvalues;
  1076. for (List<PropertyInfo>::Element *E = property_list.front(); E; E = E->next()) {
  1077. Pair<String, Variant> p;
  1078. PropertyInfo &pi = E->get();
  1079. if (pi.usage & PROPERTY_USAGE_STORAGE) {
  1080. p.first = pi.name;
  1081. p.second = res_orig->get(pi.name);
  1082. }
  1083. propvalues.push_back(p);
  1084. }
  1085. Ref<Resource> res = Ref<Resource>(ClassDB::instance(res_orig->get_class()));
  1086. ERR_FAIL_COND(res.is_null());
  1087. for (List<Pair<String, Variant> >::Element *E = propvalues.front(); E; E = E->next()) {
  1088. Pair<String, Variant> &p = E->get();
  1089. res->set(p.first, p.second);
  1090. }
  1091. v = res.get_ref_ptr();
  1092. emit_signal("variant_changed");
  1093. hide();
  1094. }
  1095. } break;
  1096. default: {};
  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. get_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 = get_font("font", "Label");
  1135. Color color = get_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. VisualServer::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(), NULL, false);
  1176. }
  1177. emit_signal("variant_changed");
  1178. } break;
  1179. case Variant::REAL: {
  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.d = _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::POOL_BYTE_ARRAY: {
  1281. } break;
  1282. case Variant::POOL_INT_ARRAY: {
  1283. } break;
  1284. case Variant::POOL_REAL_ARRAY: {
  1285. } break;
  1286. case Variant::POOL_STRING_ARRAY: {
  1287. } break;
  1288. case Variant::POOL_VECTOR3_ARRAY: {
  1289. } break;
  1290. case Variant::POOL_COLOR_ARRAY: {
  1291. } break;
  1292. default: {}
  1293. }
  1294. updating = false;
  1295. }
  1296. real_t CustomPropertyEditor::_parse_real_expression(String text) {
  1297. Ref<Expression> expr;
  1298. expr.instance();
  1299. Error err = expr->parse(text);
  1300. real_t out;
  1301. if (err != OK) {
  1302. out = value_editor[0]->get_text().to_double();
  1303. } else {
  1304. out = expr->execute(Array(), NULL, false);
  1305. }
  1306. return out;
  1307. }
  1308. void CustomPropertyEditor::_emit_changed_whole_or_field() {
  1309. if (!Input::get_singleton()->is_key_pressed(KEY_SHIFT)) {
  1310. emit_signal("variant_changed");
  1311. } else {
  1312. emit_signal("variant_field_changed", field_names[focused_value_editor]);
  1313. }
  1314. }
  1315. void CustomPropertyEditor::_range_modified(double p_value) {
  1316. v = p_value;
  1317. emit_signal("variant_changed");
  1318. }
  1319. void CustomPropertyEditor::_focus_enter() {
  1320. switch (type) {
  1321. case Variant::REAL:
  1322. case Variant::STRING:
  1323. case Variant::VECTOR2:
  1324. case Variant::RECT2:
  1325. case Variant::VECTOR3:
  1326. case Variant::PLANE:
  1327. case Variant::QUAT:
  1328. case Variant::AABB:
  1329. case Variant::TRANSFORM2D:
  1330. case Variant::BASIS:
  1331. case Variant::TRANSFORM: {
  1332. for (int i = 0; i < MAX_VALUE_EDITORS; ++i) {
  1333. if (value_editor[i]->has_focus()) {
  1334. focused_value_editor = i;
  1335. value_editor[i]->select_all();
  1336. break;
  1337. }
  1338. }
  1339. } break;
  1340. default: {}
  1341. }
  1342. }
  1343. void CustomPropertyEditor::_focus_exit() {
  1344. switch (type) {
  1345. case Variant::REAL:
  1346. case Variant::STRING:
  1347. case Variant::VECTOR2:
  1348. case Variant::RECT2:
  1349. case Variant::VECTOR3:
  1350. case Variant::PLANE:
  1351. case Variant::QUAT:
  1352. case Variant::AABB:
  1353. case Variant::TRANSFORM2D:
  1354. case Variant::BASIS:
  1355. case Variant::TRANSFORM: {
  1356. for (int i = 0; i < MAX_VALUE_EDITORS; ++i) {
  1357. value_editor[i]->select(0, 0);
  1358. }
  1359. } break;
  1360. default: {}
  1361. }
  1362. }
  1363. void CustomPropertyEditor::config_action_buttons(const List<String> &p_strings) {
  1364. Ref<StyleBox> sb = get_stylebox("panel");
  1365. int margin_top = sb->get_margin(MARGIN_TOP);
  1366. int margin_left = sb->get_margin(MARGIN_LEFT);
  1367. int margin_bottom = sb->get_margin(MARGIN_BOTTOM);
  1368. int margin_right = sb->get_margin(MARGIN_RIGHT);
  1369. int max_width = 0;
  1370. int height = 0;
  1371. for (int i = 0; i < MAX_ACTION_BUTTONS; i++) {
  1372. if (i < p_strings.size()) {
  1373. action_buttons[i]->show();
  1374. action_buttons[i]->set_text(p_strings[i]);
  1375. Size2 btn_m_size = action_buttons[i]->get_minimum_size();
  1376. if (btn_m_size.width > max_width)
  1377. max_width = btn_m_size.width;
  1378. } else {
  1379. action_buttons[i]->hide();
  1380. }
  1381. }
  1382. for (int i = 0; i < p_strings.size(); i++) {
  1383. Size2 btn_m_size = action_buttons[i]->get_size();
  1384. action_buttons[i]->set_position(Point2(0, height) + Point2(margin_left, margin_top));
  1385. action_buttons[i]->set_size(Size2(max_width, btn_m_size.height));
  1386. height += btn_m_size.height;
  1387. }
  1388. set_size(Size2(max_width, height) + Size2(margin_left + margin_right, margin_top + margin_bottom));
  1389. }
  1390. void CustomPropertyEditor::config_value_editors(int p_amount, int p_columns, int p_label_w, const List<String> &p_strings) {
  1391. int cell_width = 95;
  1392. int cell_height = 25;
  1393. int cell_margin = 5;
  1394. int hor_spacing = 5; // Spacing between labels and their values
  1395. int rows = ((p_amount - 1) / p_columns) + 1;
  1396. 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);
  1397. for (int i = 0; i < MAX_VALUE_EDITORS; i++) {
  1398. int c = i % p_columns;
  1399. int r = i / p_columns;
  1400. if (i < p_amount) {
  1401. value_editor[i]->show();
  1402. value_label[i]->show();
  1403. value_label[i]->set_text(i < p_strings.size() ? p_strings[i] : String(""));
  1404. 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);
  1405. value_editor[i]->set_size(Size2(cell_width, cell_height));
  1406. 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);
  1407. value_editor[i]->set_editable(!read_only);
  1408. } else {
  1409. value_editor[i]->hide();
  1410. value_label[i]->hide();
  1411. }
  1412. }
  1413. }
  1414. void CustomPropertyEditor::_bind_methods() {
  1415. ClassDB::bind_method("_focus_enter", &CustomPropertyEditor::_focus_enter);
  1416. ClassDB::bind_method("_focus_exit", &CustomPropertyEditor::_focus_exit);
  1417. ClassDB::bind_method("_modified", &CustomPropertyEditor::_modified);
  1418. ClassDB::bind_method("_range_modified", &CustomPropertyEditor::_range_modified);
  1419. ClassDB::bind_method("_action_pressed", &CustomPropertyEditor::_action_pressed);
  1420. ClassDB::bind_method("_file_selected", &CustomPropertyEditor::_file_selected);
  1421. ClassDB::bind_method("_type_create_selected", &CustomPropertyEditor::_type_create_selected);
  1422. ClassDB::bind_method("_node_path_selected", &CustomPropertyEditor::_node_path_selected);
  1423. ClassDB::bind_method("_color_changed", &CustomPropertyEditor::_color_changed);
  1424. ClassDB::bind_method("_draw_easing", &CustomPropertyEditor::_draw_easing);
  1425. ClassDB::bind_method("_drag_easing", &CustomPropertyEditor::_drag_easing);
  1426. ClassDB::bind_method("_text_edit_changed", &CustomPropertyEditor::_text_edit_changed);
  1427. ClassDB::bind_method("_menu_option", &CustomPropertyEditor::_menu_option);
  1428. ClassDB::bind_method("_create_dialog_callback", &CustomPropertyEditor::_create_dialog_callback);
  1429. ClassDB::bind_method("_create_selected_property", &CustomPropertyEditor::_create_selected_property);
  1430. ADD_SIGNAL(MethodInfo("variant_changed"));
  1431. ADD_SIGNAL(MethodInfo("variant_field_changed", PropertyInfo(Variant::STRING, "field")));
  1432. ADD_SIGNAL(MethodInfo("resource_edit_request"));
  1433. }
  1434. CustomPropertyEditor::CustomPropertyEditor() {
  1435. read_only = false;
  1436. updating = false;
  1437. for (int i = 0; i < MAX_VALUE_EDITORS; i++) {
  1438. value_editor[i] = memnew(LineEdit);
  1439. add_child(value_editor[i]);
  1440. value_label[i] = memnew(Label);
  1441. add_child(value_label[i]);
  1442. value_editor[i]->hide();
  1443. value_label[i]->hide();
  1444. value_editor[i]->connect("text_entered", this, "_modified");
  1445. value_editor[i]->connect("focus_entered", this, "_focus_enter");
  1446. value_editor[i]->connect("focus_exited", this, "_focus_exit");
  1447. }
  1448. focused_value_editor = -1;
  1449. for (int i = 0; i < 4; i++) {
  1450. scroll[i] = memnew(HScrollBar);
  1451. scroll[i]->hide();
  1452. scroll[i]->set_min(0);
  1453. scroll[i]->set_max(1.0);
  1454. scroll[i]->set_step(0.01);
  1455. add_child(scroll[i]);
  1456. }
  1457. checks20gc = memnew(GridContainer);
  1458. add_child(checks20gc);
  1459. checks20gc->set_columns(11);
  1460. for (int i = 0; i < 20; i++) {
  1461. if (i == 5 || i == 15) {
  1462. Control *space = memnew(Control);
  1463. space->set_custom_minimum_size(Size2(20, 0) * EDSCALE);
  1464. checks20gc->add_child(space);
  1465. }
  1466. checks20[i] = memnew(CheckBox);
  1467. checks20[i]->set_toggle_mode(true);
  1468. checks20[i]->set_focus_mode(FOCUS_NONE);
  1469. checks20gc->add_child(checks20[i]);
  1470. checks20[i]->hide();
  1471. checks20[i]->connect("pressed", this, "_action_pressed", make_binds(i));
  1472. checks20[i]->set_tooltip(vformat(TTR("Bit %d, val %d."), i, 1 << i));
  1473. }
  1474. text_edit = memnew(TextEdit);
  1475. add_child(text_edit);
  1476. text_edit->set_anchors_and_margins_preset(Control::PRESET_WIDE, Control::PRESET_MODE_MINSIZE, 5);
  1477. text_edit->set_margin(MARGIN_BOTTOM, -30);
  1478. text_edit->hide();
  1479. text_edit->connect("text_changed", this, "_text_edit_changed");
  1480. for (int i = 0; i < MAX_ACTION_BUTTONS; i++) {
  1481. action_buttons[i] = memnew(Button);
  1482. action_buttons[i]->hide();
  1483. add_child(action_buttons[i]);
  1484. Vector<Variant> binds;
  1485. binds.push_back(i);
  1486. action_buttons[i]->connect("pressed", this, "_action_pressed", binds);
  1487. action_buttons[i]->set_flat(true);
  1488. }
  1489. color_picker = NULL;
  1490. set_as_toplevel(true);
  1491. file = memnew(EditorFileDialog);
  1492. add_child(file);
  1493. file->hide();
  1494. file->connect("file_selected", this, "_file_selected");
  1495. file->connect("dir_selected", this, "_file_selected");
  1496. error = memnew(ConfirmationDialog);
  1497. error->set_title(TTR("Error!"));
  1498. add_child(error);
  1499. scene_tree = memnew(SceneTreeDialog);
  1500. add_child(scene_tree);
  1501. scene_tree->connect("selected", this, "_node_path_selected");
  1502. scene_tree->get_scene_tree()->set_show_enabled_subscene(true);
  1503. texture_preview = memnew(TextureRect);
  1504. add_child(texture_preview);
  1505. texture_preview->hide();
  1506. easing_draw = memnew(Control);
  1507. add_child(easing_draw);
  1508. easing_draw->hide();
  1509. easing_draw->connect("draw", this, "_draw_easing");
  1510. easing_draw->connect("gui_input", this, "_drag_easing");
  1511. easing_draw->set_default_cursor_shape(Control::CURSOR_MOVE);
  1512. type_button = memnew(MenuButton);
  1513. add_child(type_button);
  1514. type_button->hide();
  1515. type_button->get_popup()->connect("id_pressed", this, "_type_create_selected");
  1516. menu = memnew(PopupMenu);
  1517. menu->set_pass_on_modal_close_click(false);
  1518. add_child(menu);
  1519. menu->connect("id_pressed", this, "_menu_option");
  1520. evaluator = NULL;
  1521. spinbox = memnew(SpinBox);
  1522. add_child(spinbox);
  1523. spinbox->set_anchors_and_margins_preset(Control::PRESET_WIDE, Control::PRESET_MODE_MINSIZE, 5);
  1524. spinbox->connect("value_changed", this, "_range_modified");
  1525. slider = memnew(HSlider);
  1526. add_child(slider);
  1527. slider->set_anchors_and_margins_preset(Control::PRESET_WIDE, Control::PRESET_MODE_MINSIZE, 5);
  1528. slider->connect("value_changed", this, "_range_modified");
  1529. create_dialog = NULL;
  1530. property_select = NULL;
  1531. }