property_editor.cpp 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002
  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. }
  238. void CustomPropertyEditor::hide_menu() {
  239. menu->hide();
  240. }
  241. Variant CustomPropertyEditor::get_variant() const {
  242. return v;
  243. }
  244. String CustomPropertyEditor::get_name() const {
  245. return name;
  246. }
  247. 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) {
  248. owner = p_owner;
  249. updating = true;
  250. name = p_name;
  251. v = p_variant;
  252. field_names.clear();
  253. hint = p_hint;
  254. hint_text = p_hint_text;
  255. type_button->hide();
  256. if (color_picker)
  257. color_picker->hide();
  258. texture_preview->hide();
  259. inheritors_array.clear();
  260. text_edit->hide();
  261. easing_draw->hide();
  262. spinbox->hide();
  263. slider->hide();
  264. menu->clear();
  265. menu->set_size(Size2(1, 1) * EDSCALE);
  266. for (int i = 0; i < MAX_VALUE_EDITORS; i++) {
  267. value_editor[i]->hide();
  268. value_label[i]->hide();
  269. if (i < 4)
  270. scroll[i]->hide();
  271. }
  272. for (int i = 0; i < MAX_ACTION_BUTTONS; i++) {
  273. action_buttons[i]->hide();
  274. }
  275. checks20gc->hide();
  276. for (int i = 0; i < 20; i++)
  277. checks20[i]->hide();
  278. type = (p_variant.get_type() != Variant::NIL && p_variant.get_type() != Variant::_RID && p_type != Variant::OBJECT) ? p_variant.get_type() : p_type;
  279. switch (type) {
  280. case Variant::BOOL: {
  281. checks20gc->show();
  282. CheckBox *c = checks20[0];
  283. c->set_text("True");
  284. checks20gc->set_position(Vector2(4, 4) * EDSCALE);
  285. c->set_pressed(v);
  286. c->show();
  287. checks20gc->set_size(checks20gc->get_minimum_size());
  288. set_size(checks20gc->get_position() + checks20gc->get_size() + c->get_size() + Vector2(4, 4) * EDSCALE);
  289. } break;
  290. case Variant::INT:
  291. case Variant::REAL: {
  292. if (hint == PROPERTY_HINT_RANGE) {
  293. int c = hint_text.get_slice_count(",");
  294. float min = 0, max = 100, step = type == Variant::REAL ? .01 : 1;
  295. if (c >= 1) {
  296. if (!hint_text.get_slice(",", 0).empty())
  297. min = hint_text.get_slice(",", 0).to_double();
  298. }
  299. if (c >= 2) {
  300. if (!hint_text.get_slice(",", 1).empty())
  301. max = hint_text.get_slice(",", 1).to_double();
  302. }
  303. if (c >= 3) {
  304. if (!hint_text.get_slice(",", 2).empty())
  305. step = hint_text.get_slice(",", 2).to_double();
  306. }
  307. if (c >= 4 && hint_text.get_slice(",", 3) == "slider") {
  308. slider->set_min(min);
  309. slider->set_max(max);
  310. slider->set_step(step);
  311. slider->set_value(v);
  312. slider->show();
  313. set_size(Size2(110, 30) * EDSCALE);
  314. } else {
  315. spinbox->set_min(min);
  316. spinbox->set_max(max);
  317. spinbox->set_step(step);
  318. spinbox->set_value(v);
  319. spinbox->show();
  320. set_size(Size2(70, 35) * EDSCALE);
  321. }
  322. } else if (hint == PROPERTY_HINT_ENUM) {
  323. Vector<String> options = hint_text.split(",");
  324. int current_val = 0;
  325. for (int i = 0; i < options.size(); i++) {
  326. Vector<String> text_split = options[i].split(":");
  327. if (text_split.size() != 1)
  328. current_val = text_split[1].to_int();
  329. menu->add_item(text_split[0]);
  330. menu->set_item_metadata(i, current_val);
  331. current_val += 1;
  332. }
  333. menu->set_position(get_position());
  334. menu->popup();
  335. hide();
  336. updating = false;
  337. return false;
  338. } 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) {
  339. String basename;
  340. switch (hint) {
  341. case PROPERTY_HINT_LAYERS_2D_RENDER:
  342. basename = "layer_names/2d_render";
  343. break;
  344. case PROPERTY_HINT_LAYERS_2D_PHYSICS:
  345. basename = "layer_names/2d_physics";
  346. break;
  347. case PROPERTY_HINT_LAYERS_3D_RENDER:
  348. basename = "layer_names/3d_render";
  349. break;
  350. case PROPERTY_HINT_LAYERS_3D_PHYSICS:
  351. basename = "layer_names/3d_physics";
  352. break;
  353. }
  354. checks20gc->show();
  355. uint32_t flgs = v;
  356. for (int i = 0; i < 2; i++) {
  357. Point2 ofs(4, 4);
  358. ofs.y += 22 * i;
  359. for (int j = 0; j < 10; j++) {
  360. int idx = i * 10 + j;
  361. CheckBox *c = checks20[idx];
  362. c->set_text(ProjectSettings::get_singleton()->get(basename + "/layer_" + itos(idx + 1)));
  363. c->set_pressed(flgs & (1 << (i * 10 + j)));
  364. c->show();
  365. }
  366. }
  367. show();
  368. checks20gc->set_position(Vector2(4, 4) * EDSCALE);
  369. checks20gc->set_size(checks20gc->get_minimum_size());
  370. set_size(Vector2(4, 4) * EDSCALE + checks20gc->get_position() + checks20gc->get_size());
  371. } else if (hint == PROPERTY_HINT_EXP_EASING) {
  372. easing_draw->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_BEGIN, 5 * EDSCALE);
  373. easing_draw->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, -5 * EDSCALE);
  374. easing_draw->set_anchor_and_margin(MARGIN_TOP, ANCHOR_BEGIN, 5 * EDSCALE);
  375. easing_draw->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, -30 * EDSCALE);
  376. type_button->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_BEGIN, 3 * EDSCALE);
  377. type_button->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, -3 * EDSCALE);
  378. type_button->set_anchor_and_margin(MARGIN_TOP, ANCHOR_END, -25 * EDSCALE);
  379. type_button->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, -7 * EDSCALE);
  380. type_button->set_text(TTR("Preset..."));
  381. type_button->get_popup()->clear();
  382. type_button->get_popup()->add_item(TTR("Linear"), EASING_LINEAR);
  383. type_button->get_popup()->add_item(TTR("Ease In"), EASING_EASE_IN);
  384. type_button->get_popup()->add_item(TTR("Ease Out"), EASING_EASE_OUT);
  385. if (hint_text != "attenuation") {
  386. type_button->get_popup()->add_item(TTR("Zero"), EASING_ZERO);
  387. type_button->get_popup()->add_item(TTR("Easing In-Out"), EASING_IN_OUT);
  388. type_button->get_popup()->add_item(TTR("Easing Out-In"), EASING_OUT_IN);
  389. }
  390. type_button->show();
  391. easing_draw->show();
  392. set_size(Size2(200, 150) * EDSCALE);
  393. } else if (hint == PROPERTY_HINT_FLAGS) {
  394. Vector<String> flags = hint_text.split(",");
  395. for (int i = 0; i < flags.size(); i++) {
  396. String flag = flags[i];
  397. if (flag == "")
  398. continue;
  399. menu->add_check_item(flag, i);
  400. int f = v;
  401. if (f & (1 << i))
  402. menu->set_item_checked(menu->get_item_index(i), true);
  403. }
  404. menu->set_position(get_position());
  405. menu->popup();
  406. hide();
  407. updating = false;
  408. return false;
  409. } else {
  410. List<String> names;
  411. names.push_back("value:");
  412. config_value_editors(1, 1, 50, names);
  413. value_editor[0]->set_text(String::num(v));
  414. }
  415. } break;
  416. case Variant::STRING: {
  417. if (hint == PROPERTY_HINT_FILE || hint == PROPERTY_HINT_GLOBAL_FILE) {
  418. List<String> names;
  419. names.push_back(TTR("File..."));
  420. names.push_back(TTR("Clear"));
  421. config_action_buttons(names);
  422. } else if (hint == PROPERTY_HINT_DIR || hint == PROPERTY_HINT_GLOBAL_DIR) {
  423. List<String> names;
  424. names.push_back(TTR("Dir..."));
  425. names.push_back(TTR("Clear"));
  426. config_action_buttons(names);
  427. } else if (hint == PROPERTY_HINT_ENUM) {
  428. Vector<String> options = hint_text.split(",");
  429. for (int i = 0; i < options.size(); i++) {
  430. menu->add_item(options[i], i);
  431. }
  432. menu->set_position(get_position());
  433. menu->popup();
  434. hide();
  435. updating = false;
  436. return false;
  437. } else if (hint == PROPERTY_HINT_MULTILINE_TEXT) {
  438. text_edit->show();
  439. text_edit->set_text(v);
  440. text_edit->deselect();
  441. int button_margin = get_constant("button_margin", "Dialogs");
  442. int margin = get_constant("margin", "Dialogs");
  443. action_buttons[0]->set_anchor(MARGIN_LEFT, ANCHOR_END);
  444. action_buttons[0]->set_anchor(MARGIN_TOP, ANCHOR_END);
  445. action_buttons[0]->set_anchor(MARGIN_RIGHT, ANCHOR_END);
  446. action_buttons[0]->set_anchor(MARGIN_BOTTOM, ANCHOR_END);
  447. action_buttons[0]->set_begin(Point2(-70 * EDSCALE, -button_margin + 5 * EDSCALE));
  448. action_buttons[0]->set_end(Point2(-margin, -margin));
  449. action_buttons[0]->set_text(TTR("Close"));
  450. action_buttons[0]->show();
  451. } else if (hint == PROPERTY_HINT_TYPE_STRING) {
  452. if (!create_dialog) {
  453. create_dialog = memnew(CreateDialog);
  454. create_dialog->connect("create", this, "_create_dialog_callback");
  455. add_child(create_dialog);
  456. }
  457. if (hint_text != String()) {
  458. create_dialog->set_base_type(hint_text);
  459. } else {
  460. create_dialog->set_base_type("Object");
  461. }
  462. create_dialog->popup_create(false);
  463. hide();
  464. updating = false;
  465. return false;
  466. } else if (hint == PROPERTY_HINT_METHOD_OF_VARIANT_TYPE) {
  467. #define MAKE_PROPSELECT \
  468. if (!property_select) { \
  469. property_select = memnew(PropertySelector); \
  470. property_select->connect("selected", this, "_create_selected_property"); \
  471. add_child(property_select); \
  472. } \
  473. hide();
  474. MAKE_PROPSELECT;
  475. Variant::Type type = Variant::NIL;
  476. for (int i = 0; i < Variant::VARIANT_MAX; i++) {
  477. if (hint_text == Variant::get_type_name(Variant::Type(i))) {
  478. type = Variant::Type(i);
  479. }
  480. }
  481. if (type)
  482. property_select->select_method_from_basic_type(type, v);
  483. updating = false;
  484. return false;
  485. } else if (hint == PROPERTY_HINT_METHOD_OF_BASE_TYPE) {
  486. MAKE_PROPSELECT
  487. property_select->select_method_from_base_type(hint_text, v);
  488. updating = false;
  489. return false;
  490. } else if (hint == PROPERTY_HINT_METHOD_OF_INSTANCE) {
  491. MAKE_PROPSELECT
  492. Object *instance = ObjectDB::get_instance(hint_text.to_int64());
  493. if (instance)
  494. property_select->select_method_from_instance(instance, v);
  495. updating = false;
  496. return false;
  497. } else if (hint == PROPERTY_HINT_METHOD_OF_SCRIPT) {
  498. MAKE_PROPSELECT
  499. Object *obj = ObjectDB::get_instance(hint_text.to_int64());
  500. if (Object::cast_to<Script>(obj)) {
  501. property_select->select_method_from_script(Object::cast_to<Script>(obj), v);
  502. }
  503. updating = false;
  504. return false;
  505. } else if (hint == PROPERTY_HINT_PROPERTY_OF_VARIANT_TYPE) {
  506. MAKE_PROPSELECT
  507. Variant::Type type = Variant::NIL;
  508. String tname = hint_text;
  509. if (tname.find(".") != -1)
  510. tname = tname.get_slice(".", 0);
  511. for (int i = 0; i < Variant::VARIANT_MAX; i++) {
  512. if (tname == Variant::get_type_name(Variant::Type(i))) {
  513. type = Variant::Type(Variant::Type(i));
  514. }
  515. }
  516. if (type != Variant::NIL)
  517. property_select->select_property_from_basic_type(type, v);
  518. updating = false;
  519. return false;
  520. } else if (hint == PROPERTY_HINT_PROPERTY_OF_BASE_TYPE) {
  521. MAKE_PROPSELECT
  522. property_select->select_property_from_base_type(hint_text, v);
  523. updating = false;
  524. return false;
  525. } else if (hint == PROPERTY_HINT_PROPERTY_OF_INSTANCE) {
  526. MAKE_PROPSELECT
  527. Object *instance = ObjectDB::get_instance(hint_text.to_int64());
  528. if (instance)
  529. property_select->select_property_from_instance(instance, v);
  530. updating = false;
  531. return false;
  532. } else if (hint == PROPERTY_HINT_PROPERTY_OF_SCRIPT) {
  533. MAKE_PROPSELECT
  534. Object *obj = ObjectDB::get_instance(hint_text.to_int64());
  535. if (Object::cast_to<Script>(obj)) {
  536. property_select->select_property_from_script(Object::cast_to<Script>(obj), v);
  537. }
  538. updating = false;
  539. return false;
  540. } else {
  541. List<String> names;
  542. names.push_back("string:");
  543. config_value_editors(1, 1, 50, names);
  544. value_editor[0]->set_text(v);
  545. }
  546. } break;
  547. case Variant::VECTOR2: {
  548. field_names.push_back("x");
  549. field_names.push_back("y");
  550. config_value_editors(2, 2, 10, field_names);
  551. Vector2 vec = v;
  552. value_editor[0]->set_text(String::num(vec.x));
  553. value_editor[1]->set_text(String::num(vec.y));
  554. } break;
  555. case Variant::RECT2: {
  556. field_names.push_back("x");
  557. field_names.push_back("y");
  558. field_names.push_back("w");
  559. field_names.push_back("h");
  560. config_value_editors(4, 4, 10, field_names);
  561. Rect2 r = v;
  562. value_editor[0]->set_text(String::num(r.position.x));
  563. value_editor[1]->set_text(String::num(r.position.y));
  564. value_editor[2]->set_text(String::num(r.size.x));
  565. value_editor[3]->set_text(String::num(r.size.y));
  566. } break;
  567. case Variant::VECTOR3: {
  568. field_names.push_back("x");
  569. field_names.push_back("y");
  570. field_names.push_back("z");
  571. config_value_editors(3, 3, 10, field_names);
  572. Vector3 vec = v;
  573. value_editor[0]->set_text(String::num(vec.x));
  574. value_editor[1]->set_text(String::num(vec.y));
  575. value_editor[2]->set_text(String::num(vec.z));
  576. } break;
  577. case Variant::PLANE: {
  578. field_names.push_back("x");
  579. field_names.push_back("y");
  580. field_names.push_back("z");
  581. field_names.push_back("d");
  582. config_value_editors(4, 4, 10, field_names);
  583. Plane plane = v;
  584. value_editor[0]->set_text(String::num(plane.normal.x));
  585. value_editor[1]->set_text(String::num(plane.normal.y));
  586. value_editor[2]->set_text(String::num(plane.normal.z));
  587. value_editor[3]->set_text(String::num(plane.d));
  588. } break;
  589. case Variant::QUAT: {
  590. field_names.push_back("x");
  591. field_names.push_back("y");
  592. field_names.push_back("z");
  593. field_names.push_back("w");
  594. config_value_editors(4, 4, 10, field_names);
  595. Quat q = v;
  596. value_editor[0]->set_text(String::num(q.x));
  597. value_editor[1]->set_text(String::num(q.y));
  598. value_editor[2]->set_text(String::num(q.z));
  599. value_editor[3]->set_text(String::num(q.w));
  600. } break;
  601. case Variant::AABB: {
  602. field_names.push_back("px");
  603. field_names.push_back("py");
  604. field_names.push_back("pz");
  605. field_names.push_back("sx");
  606. field_names.push_back("sy");
  607. field_names.push_back("sz");
  608. config_value_editors(6, 3, 16, field_names);
  609. AABB aabb = v;
  610. value_editor[0]->set_text(String::num(aabb.position.x));
  611. value_editor[1]->set_text(String::num(aabb.position.y));
  612. value_editor[2]->set_text(String::num(aabb.position.z));
  613. value_editor[3]->set_text(String::num(aabb.size.x));
  614. value_editor[4]->set_text(String::num(aabb.size.y));
  615. value_editor[5]->set_text(String::num(aabb.size.z));
  616. } break;
  617. case Variant::TRANSFORM2D: {
  618. field_names.push_back("xx");
  619. field_names.push_back("xy");
  620. field_names.push_back("yx");
  621. field_names.push_back("yy");
  622. field_names.push_back("ox");
  623. field_names.push_back("oy");
  624. config_value_editors(6, 2, 16, field_names);
  625. Transform2D basis = v;
  626. for (int i = 0; i < 6; i++) {
  627. value_editor[i]->set_text(String::num(basis.elements[i / 2][i % 2]));
  628. }
  629. } break;
  630. case Variant::BASIS: {
  631. field_names.push_back("xx");
  632. field_names.push_back("xy");
  633. field_names.push_back("xz");
  634. field_names.push_back("yx");
  635. field_names.push_back("yy");
  636. field_names.push_back("yz");
  637. field_names.push_back("zx");
  638. field_names.push_back("zy");
  639. field_names.push_back("zz");
  640. config_value_editors(9, 3, 16, field_names);
  641. Basis basis = v;
  642. for (int i = 0; i < 9; i++) {
  643. value_editor[i]->set_text(String::num(basis.elements[i / 3][i % 3]));
  644. }
  645. } break;
  646. case Variant::TRANSFORM: {
  647. field_names.push_back("xx");
  648. field_names.push_back("xy");
  649. field_names.push_back("xz");
  650. field_names.push_back("xo");
  651. field_names.push_back("yx");
  652. field_names.push_back("yy");
  653. field_names.push_back("yz");
  654. field_names.push_back("yo");
  655. field_names.push_back("zx");
  656. field_names.push_back("zy");
  657. field_names.push_back("zz");
  658. field_names.push_back("zo");
  659. config_value_editors(12, 4, 16, field_names);
  660. Transform tr = v;
  661. for (int i = 0; i < 9; i++) {
  662. value_editor[(i / 3) * 4 + i % 3]->set_text(String::num(tr.basis.elements[i / 3][i % 3]));
  663. }
  664. value_editor[3]->set_text(String::num(tr.origin.x));
  665. value_editor[7]->set_text(String::num(tr.origin.y));
  666. value_editor[11]->set_text(String::num(tr.origin.z));
  667. } break;
  668. case Variant::COLOR: {
  669. if (!color_picker) {
  670. //late init for performance
  671. color_picker = memnew(ColorPicker);
  672. color_picker->set_deferred_mode(true);
  673. add_child(color_picker);
  674. color_picker->hide();
  675. color_picker->connect("color_changed", this, "_color_changed");
  676. }
  677. color_picker->show();
  678. color_picker->set_edit_alpha(hint != PROPERTY_HINT_COLOR_NO_ALPHA);
  679. color_picker->set_pick_color(v);
  680. color_picker->set_focus_on_line_edit();
  681. } break;
  682. case Variant::NODE_PATH: {
  683. List<String> names;
  684. names.push_back(TTR("Assign"));
  685. names.push_back(TTR("Clear"));
  686. if (owner && owner->is_class("Node") && (v.get_type() == Variant::NODE_PATH) && Object::cast_to<Node>(owner)->has_node(v))
  687. names.push_back(TTR("Select Node"));
  688. config_action_buttons(names);
  689. } break;
  690. case Variant::OBJECT: {
  691. if (hint != PROPERTY_HINT_RESOURCE_TYPE)
  692. break;
  693. if (p_name == "script" && hint_text == "Script" && Object::cast_to<Node>(owner)) {
  694. menu->add_icon_item(get_icon("Script", "EditorIcons"), TTR("New Script"), OBJ_MENU_NEW_SCRIPT);
  695. menu->add_separator();
  696. } else if (hint_text != "") {
  697. int idx = 0;
  698. Vector<EditorData::CustomType> custom_resources;
  699. if (EditorNode::get_editor_data().get_custom_types().has("Resource")) {
  700. custom_resources = EditorNode::get_editor_data().get_custom_types()["Resource"];
  701. }
  702. for (int i = 0; i < hint_text.get_slice_count(","); i++) {
  703. String base = hint_text.get_slice(",", i);
  704. Set<String> valid_inheritors;
  705. valid_inheritors.insert(base);
  706. List<StringName> inheritors;
  707. ClassDB::get_inheriters_from_class(base.strip_edges(), &inheritors);
  708. for (int j = 0; j < custom_resources.size(); j++) {
  709. inheritors.push_back(custom_resources[j].name);
  710. }
  711. List<StringName>::Element *E = inheritors.front();
  712. while (E) {
  713. valid_inheritors.insert(E->get());
  714. E = E->next();
  715. }
  716. for (Set<String>::Element *j = valid_inheritors.front(); j; j = j->next()) {
  717. String t = j->get();
  718. bool is_custom_resource = false;
  719. Ref<Texture> icon;
  720. if (!custom_resources.empty()) {
  721. for (int k = 0; k < custom_resources.size(); k++) {
  722. if (custom_resources[k].name == t) {
  723. is_custom_resource = true;
  724. if (custom_resources[k].icon.is_valid())
  725. icon = custom_resources[k].icon;
  726. break;
  727. }
  728. }
  729. }
  730. if (!is_custom_resource && !ClassDB::can_instance(t))
  731. continue;
  732. inheritors_array.push_back(t);
  733. int id = TYPE_BASE_ID + idx;
  734. if (!icon.is_valid() && has_icon(t, "EditorIcons")) {
  735. icon = get_icon(t, "EditorIcons");
  736. }
  737. if (icon.is_valid()) {
  738. menu->add_icon_item(icon, vformat(TTR("New %s"), t), id);
  739. } else {
  740. menu->add_item(vformat(TTR("New %s"), t), id);
  741. }
  742. idx++;
  743. }
  744. }
  745. if (menu->get_item_count())
  746. menu->add_separator();
  747. }
  748. menu->add_icon_item(get_icon("Load", "EditorIcons"), TTR("Load"), OBJ_MENU_LOAD);
  749. if (!RES(v).is_null()) {
  750. menu->add_icon_item(get_icon("Edit", "EditorIcons"), TTR("Edit"), OBJ_MENU_EDIT);
  751. menu->add_icon_item(get_icon("Clear", "EditorIcons"), TTR("Clear"), OBJ_MENU_CLEAR);
  752. menu->add_icon_item(get_icon("Duplicate", "EditorIcons"), TTR("Make Unique"), OBJ_MENU_MAKE_UNIQUE);
  753. RES r = v;
  754. if (r.is_valid() && r->get_path().is_resource_file()) {
  755. menu->add_separator();
  756. menu->add_item(TTR("Show in FileSystem"), OBJ_MENU_SHOW_IN_FILE_SYSTEM);
  757. }
  758. } else {
  759. }
  760. RES cb = EditorSettings::get_singleton()->get_resource_clipboard();
  761. bool paste_valid = false;
  762. if (cb.is_valid()) {
  763. if (hint_text == "")
  764. paste_valid = true;
  765. else
  766. for (int i = 0; i < hint_text.get_slice_count(","); i++)
  767. if (ClassDB::is_parent_class(cb->get_class(), hint_text.get_slice(",", i))) {
  768. paste_valid = true;
  769. break;
  770. }
  771. }
  772. if (!RES(v).is_null() || paste_valid) {
  773. menu->add_separator();
  774. if (!RES(v).is_null()) {
  775. menu->add_item(TTR("Copy"), OBJ_MENU_COPY);
  776. }
  777. if (paste_valid) {
  778. menu->add_item(TTR("Paste"), OBJ_MENU_PASTE);
  779. }
  780. }
  781. if (!RES(v).is_null()) {
  782. Vector<Ref<EditorResourceConversionPlugin> > conversions = EditorNode::get_singleton()->find_resource_conversion_plugin(RES(v));
  783. if (conversions.size()) {
  784. menu->add_separator();
  785. }
  786. for (int i = 0; i < conversions.size(); i++) {
  787. String what = conversions[i]->converts_to();
  788. Ref<Texture> icon;
  789. if (has_icon(what, "EditorIcons")) {
  790. icon = get_icon(what, "EditorIcons");
  791. } else {
  792. icon = get_icon(what, "Resource");
  793. }
  794. menu->add_icon_item(icon, vformat(TTR("Convert To %s"), what), CONVERT_BASE_ID + i);
  795. }
  796. }
  797. menu->set_position(get_position());
  798. menu->popup();
  799. hide();
  800. updating = false;
  801. return false;
  802. } break;
  803. case Variant::DICTIONARY: {
  804. } break;
  805. case Variant::POOL_BYTE_ARRAY: {
  806. } break;
  807. case Variant::POOL_INT_ARRAY: {
  808. } break;
  809. case Variant::POOL_REAL_ARRAY: {
  810. } break;
  811. case Variant::POOL_STRING_ARRAY: {
  812. } break;
  813. case Variant::POOL_VECTOR3_ARRAY: {
  814. } break;
  815. case Variant::POOL_COLOR_ARRAY: {
  816. } break;
  817. default: {
  818. }
  819. }
  820. updating = false;
  821. return true;
  822. }
  823. void CustomPropertyEditor::_file_selected(String p_file) {
  824. switch (type) {
  825. case Variant::STRING: {
  826. if (hint == PROPERTY_HINT_FILE || hint == PROPERTY_HINT_DIR) {
  827. v = ProjectSettings::get_singleton()->localize_path(p_file);
  828. emit_signal("variant_changed");
  829. hide();
  830. }
  831. if (hint == PROPERTY_HINT_GLOBAL_FILE || hint == PROPERTY_HINT_GLOBAL_DIR) {
  832. v = p_file;
  833. emit_signal("variant_changed");
  834. hide();
  835. }
  836. } break;
  837. case Variant::OBJECT: {
  838. String type = (hint == PROPERTY_HINT_RESOURCE_TYPE) ? hint_text : String();
  839. RES res = ResourceLoader::load(p_file, type);
  840. if (res.is_null()) {
  841. error->set_text(TTR("Error loading file: Not a resource!"));
  842. error->popup_centered_minsize();
  843. break;
  844. }
  845. v = res.get_ref_ptr();
  846. emit_signal("variant_changed");
  847. hide();
  848. } break;
  849. default: {
  850. }
  851. }
  852. }
  853. void CustomPropertyEditor::_type_create_selected(int p_idx) {
  854. if (type == Variant::INT || type == Variant::REAL) {
  855. float newval = 0;
  856. switch (p_idx) {
  857. case EASING_LINEAR: {
  858. newval = 1;
  859. } break;
  860. case EASING_EASE_IN: {
  861. newval = 2.0;
  862. } break;
  863. case EASING_EASE_OUT: {
  864. newval = 0.5;
  865. } break;
  866. case EASING_ZERO: {
  867. newval = 0;
  868. } break;
  869. case EASING_IN_OUT: {
  870. newval = -0.5;
  871. } break;
  872. case EASING_OUT_IN: {
  873. newval = -2.0;
  874. } break;
  875. }
  876. v = newval;
  877. emit_signal("variant_changed");
  878. easing_draw->update();
  879. } else if (type == Variant::OBJECT) {
  880. ERR_FAIL_INDEX(p_idx, inheritors_array.size());
  881. String intype = inheritors_array[p_idx];
  882. Object *obj = ClassDB::instance(intype);
  883. if (!obj) {
  884. if (ScriptServer::is_global_class(intype)) {
  885. obj = EditorNode::get_editor_data().script_class_instance(intype);
  886. } else {
  887. obj = EditorNode::get_editor_data().instance_custom_type(intype, "Resource");
  888. }
  889. }
  890. ERR_FAIL_COND(!obj);
  891. Resource *res = Object::cast_to<Resource>(obj);
  892. ERR_FAIL_COND(!res);
  893. v = Ref<Resource>(res).get_ref_ptr();
  894. emit_signal("variant_changed");
  895. hide();
  896. }
  897. }
  898. void CustomPropertyEditor::_color_changed(const Color &p_color) {
  899. v = p_color;
  900. emit_signal("variant_changed");
  901. }
  902. void CustomPropertyEditor::_node_path_selected(NodePath p_path) {
  903. if (picking_viewport) {
  904. Node *to_node = get_node(p_path);
  905. if (!Object::cast_to<Viewport>(to_node)) {
  906. EditorNode::get_singleton()->show_warning(TTR("Selected node is not a Viewport!"));
  907. return;
  908. }
  909. Ref<ViewportTexture> vt;
  910. vt.instance();
  911. vt->set_viewport_path_in_scene(get_tree()->get_edited_scene_root()->get_path_to(to_node));
  912. vt->setup_local_to_scene();
  913. v = vt;
  914. emit_signal("variant_changed");
  915. return;
  916. }
  917. if (hint == PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE && hint_text != String()) {
  918. Node *node = get_node(hint_text);
  919. if (node) {
  920. Node *tonode = node->get_node(p_path);
  921. if (tonode) {
  922. p_path = node->get_path_to(tonode);
  923. }
  924. }
  925. } else if (owner) {
  926. Node *node = NULL;
  927. if (owner->is_class("Node"))
  928. node = Object::cast_to<Node>(owner);
  929. else if (owner->is_class("ArrayPropertyEdit"))
  930. node = Object::cast_to<ArrayPropertyEdit>(owner)->get_node();
  931. else if (owner->is_class("DictionaryPropertyEdit"))
  932. node = Object::cast_to<DictionaryPropertyEdit>(owner)->get_node();
  933. if (!node) {
  934. v = p_path;
  935. emit_signal("variant_changed");
  936. call_deferred("hide"); //to not mess with dialogs
  937. return;
  938. }
  939. Node *tonode = node->get_node(p_path);
  940. if (tonode) {
  941. p_path = node->get_path_to(tonode);
  942. }
  943. }
  944. v = p_path;
  945. emit_signal("variant_changed");
  946. call_deferred("hide"); //to not mess with dialogs
  947. }
  948. void CustomPropertyEditor::_action_pressed(int p_which) {
  949. if (updating)
  950. return;
  951. switch (type) {
  952. case Variant::BOOL: {
  953. v = checks20[0]->is_pressed();
  954. emit_signal("variant_changed");
  955. } break;
  956. case Variant::INT: {
  957. 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) {
  958. uint32_t f = v;
  959. if (checks20[p_which]->is_pressed())
  960. f |= (1 << p_which);
  961. else
  962. f &= ~(1 << p_which);
  963. v = f;
  964. emit_signal("variant_changed");
  965. }
  966. } break;
  967. case Variant::STRING: {
  968. if (hint == PROPERTY_HINT_MULTILINE_TEXT) {
  969. hide();
  970. } else if (hint == PROPERTY_HINT_FILE || hint == PROPERTY_HINT_GLOBAL_FILE) {
  971. if (p_which == 0) {
  972. if (hint == PROPERTY_HINT_FILE)
  973. file->set_access(EditorFileDialog::ACCESS_RESOURCES);
  974. else
  975. file->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
  976. file->set_mode(EditorFileDialog::MODE_OPEN_FILE);
  977. file->clear_filters();
  978. file->clear_filters();
  979. if (hint_text != "") {
  980. Vector<String> extensions = hint_text.split(",");
  981. for (int i = 0; i < extensions.size(); i++) {
  982. String filter = extensions[i];
  983. if (filter.begins_with("."))
  984. filter = "*" + extensions[i];
  985. else if (!filter.begins_with("*"))
  986. filter = "*." + extensions[i];
  987. file->add_filter(filter + " ; " + extensions[i].to_upper());
  988. }
  989. }
  990. file->popup_centered_ratio();
  991. } else {
  992. v = "";
  993. emit_signal("variant_changed");
  994. hide();
  995. }
  996. } else if (hint == PROPERTY_HINT_DIR || hint == PROPERTY_HINT_GLOBAL_DIR) {
  997. if (p_which == 0) {
  998. if (hint == PROPERTY_HINT_DIR)
  999. file->set_access(EditorFileDialog::ACCESS_RESOURCES);
  1000. else
  1001. file->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
  1002. file->set_mode(EditorFileDialog::MODE_OPEN_DIR);
  1003. file->clear_filters();
  1004. file->popup_centered_ratio();
  1005. } else {
  1006. v = "";
  1007. emit_signal("variant_changed");
  1008. hide();
  1009. }
  1010. }
  1011. } break;
  1012. case Variant::NODE_PATH: {
  1013. if (p_which == 0) {
  1014. picking_viewport = false;
  1015. scene_tree->set_title(TTR("Pick a Node"));
  1016. scene_tree->popup_centered_ratio();
  1017. } else if (p_which == 1) {
  1018. v = NodePath();
  1019. emit_signal("variant_changed");
  1020. hide();
  1021. } else if (p_which == 2) {
  1022. if (owner->is_class("Node") && (v.get_type() == Variant::NODE_PATH) && Object::cast_to<Node>(owner)->has_node(v)) {
  1023. Node *target_node = Object::cast_to<Node>(owner)->get_node(v);
  1024. EditorNode::get_singleton()->get_editor_selection()->clear();
  1025. EditorNode::get_singleton()->get_scene_tree_dock()->set_selected(target_node);
  1026. }
  1027. hide();
  1028. }
  1029. } break;
  1030. case Variant::OBJECT: {
  1031. if (p_which == 0) {
  1032. ERR_FAIL_COND(inheritors_array.empty());
  1033. String intype = inheritors_array[0];
  1034. if (hint == PROPERTY_HINT_RESOURCE_TYPE) {
  1035. Object *obj = ClassDB::instance(intype);
  1036. if (!obj) {
  1037. if (ScriptServer::is_global_class(intype)) {
  1038. obj = EditorNode::get_editor_data().script_class_instance(intype);
  1039. } else {
  1040. obj = EditorNode::get_editor_data().instance_custom_type(intype, "Resource");
  1041. }
  1042. }
  1043. ERR_BREAK(!obj);
  1044. Resource *res = Object::cast_to<Resource>(obj);
  1045. ERR_BREAK(!res);
  1046. v = Ref<Resource>(res).get_ref_ptr();
  1047. emit_signal("variant_changed");
  1048. hide();
  1049. }
  1050. } else if (p_which == 1) {
  1051. file->set_access(EditorFileDialog::ACCESS_RESOURCES);
  1052. file->set_mode(EditorFileDialog::MODE_OPEN_FILE);
  1053. List<String> extensions;
  1054. String type = (hint == PROPERTY_HINT_RESOURCE_TYPE) ? hint_text : String();
  1055. ResourceLoader::get_recognized_extensions_for_type(type, &extensions);
  1056. file->clear_filters();
  1057. for (List<String>::Element *E = extensions.front(); E; E = E->next()) {
  1058. file->add_filter("*." + E->get() + " ; " + E->get().to_upper());
  1059. }
  1060. file->popup_centered_ratio();
  1061. } else if (p_which == 2) {
  1062. RefPtr RefPtr = v;
  1063. if (!RefPtr.is_null()) {
  1064. emit_signal("resource_edit_request");
  1065. hide();
  1066. }
  1067. } else if (p_which == 3) {
  1068. v = Variant();
  1069. emit_signal("variant_changed");
  1070. hide();
  1071. } else if (p_which == 4) {
  1072. RefPtr RefPtr = v;
  1073. Ref<Resource> res_orig = RefPtr;
  1074. if (res_orig.is_null())
  1075. return;
  1076. List<PropertyInfo> property_list;
  1077. res_orig->get_property_list(&property_list);
  1078. List<Pair<String, Variant> > propvalues;
  1079. for (List<PropertyInfo>::Element *E = property_list.front(); E; E = E->next()) {
  1080. Pair<String, Variant> p;
  1081. PropertyInfo &pi = E->get();
  1082. if (pi.usage & PROPERTY_USAGE_STORAGE) {
  1083. p.first = pi.name;
  1084. p.second = res_orig->get(pi.name);
  1085. }
  1086. propvalues.push_back(p);
  1087. }
  1088. Ref<Resource> res = Ref<Resource>(ClassDB::instance(res_orig->get_class()));
  1089. ERR_FAIL_COND(res.is_null());
  1090. for (List<Pair<String, Variant> >::Element *E = propvalues.front(); E; E = E->next()) {
  1091. Pair<String, Variant> &p = E->get();
  1092. res->set(p.first, p.second);
  1093. }
  1094. v = res.get_ref_ptr();
  1095. emit_signal("variant_changed");
  1096. hide();
  1097. }
  1098. } break;
  1099. default: {
  1100. };
  1101. }
  1102. }
  1103. void CustomPropertyEditor::_drag_easing(const Ref<InputEvent> &p_ev) {
  1104. Ref<InputEventMouseMotion> mm = p_ev;
  1105. if (mm.is_valid() && mm->get_button_mask() & BUTTON_MASK_LEFT) {
  1106. float rel = mm->get_relative().x;
  1107. if (rel == 0)
  1108. return;
  1109. bool flip = hint_text == "attenuation";
  1110. if (flip)
  1111. rel = -rel;
  1112. float val = v;
  1113. if (val == 0)
  1114. return;
  1115. bool sg = val < 0;
  1116. val = Math::absf(val);
  1117. val = Math::log(val) / Math::log((float)2.0);
  1118. //logspace
  1119. val += rel * 0.05;
  1120. val = Math::pow(2.0f, val);
  1121. if (sg)
  1122. val = -val;
  1123. v = val;
  1124. easing_draw->update();
  1125. emit_signal("variant_changed");
  1126. }
  1127. }
  1128. void CustomPropertyEditor::_draw_easing() {
  1129. RID ci = easing_draw->get_canvas_item();
  1130. Size2 s = easing_draw->get_size();
  1131. Rect2 r(Point2(), s);
  1132. r = r.grow(3);
  1133. get_stylebox("normal", "LineEdit")->draw(ci, r);
  1134. int points = 48;
  1135. float prev = 1.0;
  1136. float exp = v;
  1137. bool flip = hint_text == "attenuation";
  1138. Ref<Font> f = get_font("font", "Label");
  1139. Color color = get_color("font_color", "Label");
  1140. for (int i = 1; i <= points; i++) {
  1141. float ifl = i / float(points);
  1142. float iflp = (i - 1) / float(points);
  1143. float h = 1.0 - Math::ease(ifl, exp);
  1144. if (flip) {
  1145. ifl = 1.0 - ifl;
  1146. iflp = 1.0 - iflp;
  1147. }
  1148. VisualServer::get_singleton()->canvas_item_add_line(ci, Point2(iflp * s.width, prev * s.height), Point2(ifl * s.width, h * s.height), color);
  1149. prev = h;
  1150. }
  1151. f->draw(ci, Point2(10, 10 + f->get_ascent()), String::num(exp, 2), color);
  1152. }
  1153. void CustomPropertyEditor::_text_edit_changed() {
  1154. v = text_edit->get_text();
  1155. emit_signal("variant_changed");
  1156. }
  1157. void CustomPropertyEditor::_create_dialog_callback() {
  1158. v = create_dialog->get_selected_type();
  1159. emit_signal("variant_changed");
  1160. }
  1161. void CustomPropertyEditor::_create_selected_property(const String &p_prop) {
  1162. v = p_prop;
  1163. emit_signal("variant_changed");
  1164. }
  1165. void CustomPropertyEditor::_modified(String p_string) {
  1166. if (updating)
  1167. return;
  1168. updating = true;
  1169. switch (type) {
  1170. case Variant::INT: {
  1171. String text = value_editor[0]->get_text();
  1172. Ref<Expression> expr;
  1173. expr.instance();
  1174. Error err = expr->parse(text);
  1175. if (err != OK) {
  1176. v = value_editor[0]->get_text().to_int();
  1177. return;
  1178. } else {
  1179. v = expr->execute(Array(), NULL, false);
  1180. }
  1181. emit_signal("variant_changed");
  1182. } break;
  1183. case Variant::REAL: {
  1184. if (hint != PROPERTY_HINT_EXP_EASING) {
  1185. String text = value_editor[0]->get_text();
  1186. v = _parse_real_expression(text);
  1187. emit_signal("variant_changed");
  1188. }
  1189. } break;
  1190. case Variant::STRING: {
  1191. v = value_editor[0]->get_text();
  1192. emit_signal("variant_changed");
  1193. } break;
  1194. case Variant::VECTOR2: {
  1195. Vector2 vec;
  1196. vec.x = _parse_real_expression(value_editor[0]->get_text());
  1197. vec.y = _parse_real_expression(value_editor[1]->get_text());
  1198. v = vec;
  1199. _emit_changed_whole_or_field();
  1200. } break;
  1201. case Variant::RECT2: {
  1202. Rect2 r2;
  1203. r2.position.x = _parse_real_expression(value_editor[0]->get_text());
  1204. r2.position.y = _parse_real_expression(value_editor[1]->get_text());
  1205. r2.size.x = _parse_real_expression(value_editor[2]->get_text());
  1206. r2.size.y = _parse_real_expression(value_editor[3]->get_text());
  1207. v = r2;
  1208. _emit_changed_whole_or_field();
  1209. } break;
  1210. case Variant::VECTOR3: {
  1211. Vector3 vec;
  1212. vec.x = _parse_real_expression(value_editor[0]->get_text());
  1213. vec.y = _parse_real_expression(value_editor[1]->get_text());
  1214. vec.z = _parse_real_expression(value_editor[2]->get_text());
  1215. v = vec;
  1216. _emit_changed_whole_or_field();
  1217. } break;
  1218. case Variant::PLANE: {
  1219. Plane pl;
  1220. pl.normal.x = _parse_real_expression(value_editor[0]->get_text());
  1221. pl.normal.y = _parse_real_expression(value_editor[1]->get_text());
  1222. pl.normal.z = _parse_real_expression(value_editor[2]->get_text());
  1223. pl.d = _parse_real_expression(value_editor[3]->get_text());
  1224. v = pl;
  1225. _emit_changed_whole_or_field();
  1226. } break;
  1227. case Variant::QUAT: {
  1228. Quat q;
  1229. q.x = _parse_real_expression(value_editor[0]->get_text());
  1230. q.y = _parse_real_expression(value_editor[1]->get_text());
  1231. q.z = _parse_real_expression(value_editor[2]->get_text());
  1232. q.w = _parse_real_expression(value_editor[3]->get_text());
  1233. v = q;
  1234. _emit_changed_whole_or_field();
  1235. } break;
  1236. case Variant::AABB: {
  1237. Vector3 pos;
  1238. Vector3 size;
  1239. pos.x = _parse_real_expression(value_editor[0]->get_text());
  1240. pos.y = _parse_real_expression(value_editor[1]->get_text());
  1241. pos.z = _parse_real_expression(value_editor[2]->get_text());
  1242. size.x = _parse_real_expression(value_editor[3]->get_text());
  1243. size.y = _parse_real_expression(value_editor[4]->get_text());
  1244. size.z = _parse_real_expression(value_editor[5]->get_text());
  1245. v = AABB(pos, size);
  1246. _emit_changed_whole_or_field();
  1247. } break;
  1248. case Variant::TRANSFORM2D: {
  1249. Transform2D m;
  1250. for (int i = 0; i < 6; i++) {
  1251. m.elements[i / 2][i % 2] = _parse_real_expression(value_editor[i]->get_text());
  1252. }
  1253. v = m;
  1254. _emit_changed_whole_or_field();
  1255. } break;
  1256. case Variant::BASIS: {
  1257. Basis m;
  1258. for (int i = 0; i < 9; i++) {
  1259. m.elements[i / 3][i % 3] = _parse_real_expression(value_editor[i]->get_text());
  1260. }
  1261. v = m;
  1262. _emit_changed_whole_or_field();
  1263. } break;
  1264. case Variant::TRANSFORM: {
  1265. Basis basis;
  1266. for (int i = 0; i < 9; i++) {
  1267. basis.elements[i / 3][i % 3] = _parse_real_expression(value_editor[(i / 3) * 4 + i % 3]->get_text());
  1268. }
  1269. Vector3 origin;
  1270. origin.x = _parse_real_expression(value_editor[3]->get_text());
  1271. origin.y = _parse_real_expression(value_editor[7]->get_text());
  1272. origin.z = _parse_real_expression(value_editor[11]->get_text());
  1273. v = Transform(basis, origin);
  1274. _emit_changed_whole_or_field();
  1275. } break;
  1276. case Variant::COLOR: {
  1277. } break;
  1278. case Variant::NODE_PATH: {
  1279. v = NodePath(value_editor[0]->get_text());
  1280. emit_signal("variant_changed");
  1281. } break;
  1282. case Variant::DICTIONARY: {
  1283. } break;
  1284. case Variant::POOL_BYTE_ARRAY: {
  1285. } break;
  1286. case Variant::POOL_INT_ARRAY: {
  1287. } break;
  1288. case Variant::POOL_REAL_ARRAY: {
  1289. } break;
  1290. case Variant::POOL_STRING_ARRAY: {
  1291. } break;
  1292. case Variant::POOL_VECTOR3_ARRAY: {
  1293. } break;
  1294. case Variant::POOL_COLOR_ARRAY: {
  1295. } break;
  1296. default: {
  1297. }
  1298. }
  1299. updating = false;
  1300. }
  1301. real_t CustomPropertyEditor::_parse_real_expression(String text) {
  1302. Ref<Expression> expr;
  1303. expr.instance();
  1304. Error err = expr->parse(text);
  1305. real_t out;
  1306. if (err != OK) {
  1307. out = value_editor[0]->get_text().to_double();
  1308. } else {
  1309. out = expr->execute(Array(), NULL, false);
  1310. }
  1311. return out;
  1312. }
  1313. void CustomPropertyEditor::_emit_changed_whole_or_field() {
  1314. if (!Input::get_singleton()->is_key_pressed(KEY_SHIFT)) {
  1315. emit_signal("variant_changed");
  1316. } else {
  1317. emit_signal("variant_field_changed", field_names[focused_value_editor]);
  1318. }
  1319. }
  1320. void CustomPropertyEditor::_range_modified(double p_value) {
  1321. v = p_value;
  1322. emit_signal("variant_changed");
  1323. }
  1324. void CustomPropertyEditor::_focus_enter() {
  1325. switch (type) {
  1326. case Variant::REAL:
  1327. case Variant::STRING:
  1328. case Variant::VECTOR2:
  1329. case Variant::RECT2:
  1330. case Variant::VECTOR3:
  1331. case Variant::PLANE:
  1332. case Variant::QUAT:
  1333. case Variant::AABB:
  1334. case Variant::TRANSFORM2D:
  1335. case Variant::BASIS:
  1336. case Variant::TRANSFORM: {
  1337. for (int i = 0; i < MAX_VALUE_EDITORS; ++i) {
  1338. if (value_editor[i]->has_focus()) {
  1339. focused_value_editor = i;
  1340. value_editor[i]->select_all();
  1341. break;
  1342. }
  1343. }
  1344. } break;
  1345. default: {
  1346. }
  1347. }
  1348. }
  1349. void CustomPropertyEditor::_focus_exit() {
  1350. switch (type) {
  1351. case Variant::REAL:
  1352. case Variant::STRING:
  1353. case Variant::VECTOR2:
  1354. case Variant::RECT2:
  1355. case Variant::VECTOR3:
  1356. case Variant::PLANE:
  1357. case Variant::QUAT:
  1358. case Variant::AABB:
  1359. case Variant::TRANSFORM2D:
  1360. case Variant::BASIS:
  1361. case Variant::TRANSFORM: {
  1362. for (int i = 0; i < MAX_VALUE_EDITORS; ++i) {
  1363. value_editor[i]->select(0, 0);
  1364. }
  1365. } break;
  1366. default: {
  1367. }
  1368. }
  1369. }
  1370. void CustomPropertyEditor::config_action_buttons(const List<String> &p_strings) {
  1371. Ref<StyleBox> sb = get_stylebox("panel");
  1372. int margin_top = sb->get_margin(MARGIN_TOP);
  1373. int margin_left = sb->get_margin(MARGIN_LEFT);
  1374. int margin_bottom = sb->get_margin(MARGIN_BOTTOM);
  1375. int margin_right = sb->get_margin(MARGIN_RIGHT);
  1376. int max_width = 0;
  1377. int height = 0;
  1378. for (int i = 0; i < MAX_ACTION_BUTTONS; i++) {
  1379. if (i < p_strings.size()) {
  1380. action_buttons[i]->show();
  1381. action_buttons[i]->set_text(p_strings[i]);
  1382. Size2 btn_m_size = action_buttons[i]->get_minimum_size();
  1383. if (btn_m_size.width > max_width)
  1384. max_width = btn_m_size.width;
  1385. } else {
  1386. action_buttons[i]->hide();
  1387. }
  1388. }
  1389. for (int i = 0; i < p_strings.size(); i++) {
  1390. Size2 btn_m_size = action_buttons[i]->get_size();
  1391. action_buttons[i]->set_position(Point2(0, height) + Point2(margin_left, margin_top));
  1392. action_buttons[i]->set_size(Size2(max_width, btn_m_size.height));
  1393. height += btn_m_size.height;
  1394. }
  1395. set_size(Size2(max_width, height) + Size2(margin_left + margin_right, margin_top + margin_bottom));
  1396. }
  1397. void CustomPropertyEditor::config_value_editors(int p_amount, int p_columns, int p_label_w, const List<String> &p_strings) {
  1398. int cell_width = 95;
  1399. int cell_height = 25;
  1400. int cell_margin = 5;
  1401. int hor_spacing = 5; // Spacing between labels and their values
  1402. int rows = ((p_amount - 1) / p_columns) + 1;
  1403. 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);
  1404. for (int i = 0; i < MAX_VALUE_EDITORS; i++) {
  1405. int c = i % p_columns;
  1406. int r = i / p_columns;
  1407. if (i < p_amount) {
  1408. value_editor[i]->show();
  1409. value_label[i]->show();
  1410. value_label[i]->set_text(i < p_strings.size() ? p_strings[i] : String(""));
  1411. 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);
  1412. value_editor[i]->set_size(Size2(cell_width, cell_height));
  1413. 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);
  1414. value_editor[i]->set_editable(!read_only);
  1415. } else {
  1416. value_editor[i]->hide();
  1417. value_label[i]->hide();
  1418. }
  1419. }
  1420. }
  1421. void CustomPropertyEditor::_bind_methods() {
  1422. ClassDB::bind_method("_focus_enter", &CustomPropertyEditor::_focus_enter);
  1423. ClassDB::bind_method("_focus_exit", &CustomPropertyEditor::_focus_exit);
  1424. ClassDB::bind_method("_modified", &CustomPropertyEditor::_modified);
  1425. ClassDB::bind_method("_range_modified", &CustomPropertyEditor::_range_modified);
  1426. ClassDB::bind_method("_action_pressed", &CustomPropertyEditor::_action_pressed);
  1427. ClassDB::bind_method("_file_selected", &CustomPropertyEditor::_file_selected);
  1428. ClassDB::bind_method("_type_create_selected", &CustomPropertyEditor::_type_create_selected);
  1429. ClassDB::bind_method("_node_path_selected", &CustomPropertyEditor::_node_path_selected);
  1430. ClassDB::bind_method("_color_changed", &CustomPropertyEditor::_color_changed);
  1431. ClassDB::bind_method("_draw_easing", &CustomPropertyEditor::_draw_easing);
  1432. ClassDB::bind_method("_drag_easing", &CustomPropertyEditor::_drag_easing);
  1433. ClassDB::bind_method("_text_edit_changed", &CustomPropertyEditor::_text_edit_changed);
  1434. ClassDB::bind_method("_menu_option", &CustomPropertyEditor::_menu_option);
  1435. ClassDB::bind_method("_create_dialog_callback", &CustomPropertyEditor::_create_dialog_callback);
  1436. ClassDB::bind_method("_create_selected_property", &CustomPropertyEditor::_create_selected_property);
  1437. ADD_SIGNAL(MethodInfo("variant_changed"));
  1438. ADD_SIGNAL(MethodInfo("variant_field_changed", PropertyInfo(Variant::STRING, "field")));
  1439. ADD_SIGNAL(MethodInfo("resource_edit_request"));
  1440. }
  1441. CustomPropertyEditor::CustomPropertyEditor() {
  1442. read_only = false;
  1443. updating = false;
  1444. for (int i = 0; i < MAX_VALUE_EDITORS; i++) {
  1445. value_editor[i] = memnew(LineEdit);
  1446. add_child(value_editor[i]);
  1447. value_label[i] = memnew(Label);
  1448. add_child(value_label[i]);
  1449. value_editor[i]->hide();
  1450. value_label[i]->hide();
  1451. value_editor[i]->connect("text_entered", this, "_modified");
  1452. value_editor[i]->connect("focus_entered", this, "_focus_enter");
  1453. value_editor[i]->connect("focus_exited", this, "_focus_exit");
  1454. }
  1455. focused_value_editor = -1;
  1456. for (int i = 0; i < 4; i++) {
  1457. scroll[i] = memnew(HScrollBar);
  1458. scroll[i]->hide();
  1459. scroll[i]->set_min(0);
  1460. scroll[i]->set_max(1.0);
  1461. scroll[i]->set_step(0.01);
  1462. add_child(scroll[i]);
  1463. }
  1464. checks20gc = memnew(GridContainer);
  1465. add_child(checks20gc);
  1466. checks20gc->set_columns(11);
  1467. for (int i = 0; i < 20; i++) {
  1468. if (i == 5 || i == 15) {
  1469. Control *space = memnew(Control);
  1470. space->set_custom_minimum_size(Size2(20, 0) * EDSCALE);
  1471. checks20gc->add_child(space);
  1472. }
  1473. checks20[i] = memnew(CheckBox);
  1474. checks20[i]->set_toggle_mode(true);
  1475. checks20[i]->set_focus_mode(FOCUS_NONE);
  1476. checks20gc->add_child(checks20[i]);
  1477. checks20[i]->hide();
  1478. checks20[i]->connect("pressed", this, "_action_pressed", make_binds(i));
  1479. checks20[i]->set_tooltip(vformat(TTR("Bit %d, val %d."), i, 1 << i));
  1480. }
  1481. text_edit = memnew(TextEdit);
  1482. add_child(text_edit);
  1483. text_edit->set_anchors_and_margins_preset(Control::PRESET_WIDE, Control::PRESET_MODE_MINSIZE, 5);
  1484. text_edit->set_margin(MARGIN_BOTTOM, -30);
  1485. text_edit->hide();
  1486. text_edit->connect("text_changed", this, "_text_edit_changed");
  1487. for (int i = 0; i < MAX_ACTION_BUTTONS; i++) {
  1488. action_buttons[i] = memnew(Button);
  1489. action_buttons[i]->hide();
  1490. add_child(action_buttons[i]);
  1491. Vector<Variant> binds;
  1492. binds.push_back(i);
  1493. action_buttons[i]->connect("pressed", this, "_action_pressed", binds);
  1494. action_buttons[i]->set_flat(true);
  1495. }
  1496. color_picker = NULL;
  1497. set_as_toplevel(true);
  1498. file = memnew(EditorFileDialog);
  1499. add_child(file);
  1500. file->hide();
  1501. file->connect("file_selected", this, "_file_selected");
  1502. file->connect("dir_selected", this, "_file_selected");
  1503. error = memnew(ConfirmationDialog);
  1504. error->set_title(TTR("Error!"));
  1505. add_child(error);
  1506. scene_tree = memnew(SceneTreeDialog);
  1507. add_child(scene_tree);
  1508. scene_tree->connect("selected", this, "_node_path_selected");
  1509. scene_tree->get_scene_tree()->set_show_enabled_subscene(true);
  1510. texture_preview = memnew(TextureRect);
  1511. add_child(texture_preview);
  1512. texture_preview->hide();
  1513. easing_draw = memnew(Control);
  1514. add_child(easing_draw);
  1515. easing_draw->hide();
  1516. easing_draw->connect("draw", this, "_draw_easing");
  1517. easing_draw->connect("gui_input", this, "_drag_easing");
  1518. easing_draw->set_default_cursor_shape(Control::CURSOR_MOVE);
  1519. type_button = memnew(MenuButton);
  1520. add_child(type_button);
  1521. type_button->hide();
  1522. type_button->get_popup()->connect("id_pressed", this, "_type_create_selected");
  1523. menu = memnew(PopupMenu);
  1524. menu->set_pass_on_modal_close_click(false);
  1525. add_child(menu);
  1526. menu->connect("id_pressed", this, "_menu_option");
  1527. evaluator = NULL;
  1528. spinbox = memnew(SpinBox);
  1529. add_child(spinbox);
  1530. spinbox->set_anchors_and_margins_preset(Control::PRESET_WIDE, Control::PRESET_MODE_MINSIZE, 5);
  1531. spinbox->connect("value_changed", this, "_range_modified");
  1532. slider = memnew(HSlider);
  1533. add_child(slider);
  1534. slider->set_anchors_and_margins_preset(Control::PRESET_WIDE, Control::PRESET_MODE_MINSIZE, 5);
  1535. slider->connect("value_changed", this, "_range_modified");
  1536. create_dialog = NULL;
  1537. property_select = NULL;
  1538. }