property_editor.cpp 54 KB

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