editor_inspector.cpp 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386
  1. /**************************************************************************/
  2. /* editor_inspector.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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 "editor_inspector.h"
  31. #include "array_property_edit.h"
  32. #include "core/os/input.h"
  33. #include "core/os/keyboard.h"
  34. #include "dictionary_property_edit.h"
  35. #include "editor_feature_profile.h"
  36. #include "editor_node.h"
  37. #include "editor_property_name_processor.h"
  38. #include "editor_scale.h"
  39. #include "editor_settings.h"
  40. #include "multi_node_edit.h"
  41. #include "scene/property_utils.h"
  42. #include "scene/resources/packed_scene.h"
  43. Size2 EditorProperty::get_minimum_size() const {
  44. Size2 ms;
  45. Ref<Font> font = get_font("font", "Tree");
  46. ms.height = font->get_height();
  47. for (int i = 0; i < get_child_count(); i++) {
  48. Control *c = Object::cast_to<Control>(get_child(i));
  49. if (!c) {
  50. continue;
  51. }
  52. if (c->is_set_as_toplevel()) {
  53. continue;
  54. }
  55. if (!c->is_visible()) {
  56. continue;
  57. }
  58. if (c == bottom_editor) {
  59. continue;
  60. }
  61. Size2 minsize = c->get_combined_minimum_size();
  62. ms.width = MAX(ms.width, minsize.width);
  63. ms.height = MAX(ms.height, minsize.height);
  64. }
  65. if (keying) {
  66. Ref<Texture> key = get_icon("Key", "EditorIcons");
  67. ms.width += key->get_width() + get_constant("hseparator", "Tree");
  68. }
  69. if (checkable) {
  70. Ref<Texture> check = get_icon("checked", "CheckBox");
  71. ms.width += check->get_width() + get_constant("hseparation", "CheckBox") + get_constant("hseparator", "Tree");
  72. }
  73. if (bottom_editor != nullptr && bottom_editor->is_visible()) {
  74. ms.height += get_constant("vseparation");
  75. Size2 bems = bottom_editor->get_combined_minimum_size();
  76. //bems.width += get_constant("item_margin", "Tree");
  77. ms.height += bems.height;
  78. ms.width = MAX(ms.width, bems.width);
  79. }
  80. return ms;
  81. }
  82. void EditorProperty::emit_changed(const StringName &p_property, const Variant &p_value, const StringName &p_field, bool p_changing) {
  83. Variant args[4] = { p_property, p_value, p_field, p_changing };
  84. const Variant *argptrs[4] = { &args[0], &args[1], &args[2], &args[3] };
  85. emit_signal("property_changed", (const Variant **)argptrs, 4);
  86. }
  87. void EditorProperty::_notification(int p_what) {
  88. if (p_what == NOTIFICATION_SORT_CHILDREN) {
  89. Size2 size = get_size();
  90. Rect2 rect;
  91. Rect2 bottom_rect;
  92. right_child_rect = Rect2();
  93. bottom_child_rect = Rect2();
  94. {
  95. int child_room = size.width * (1.0 - split_ratio);
  96. Ref<Font> font = get_font("font", "Tree");
  97. int height = font->get_height();
  98. bool no_children = true;
  99. //compute room needed
  100. for (int i = 0; i < get_child_count(); i++) {
  101. Control *c = Object::cast_to<Control>(get_child(i));
  102. if (!c) {
  103. continue;
  104. }
  105. if (c->is_set_as_toplevel()) {
  106. continue;
  107. }
  108. if (c == bottom_editor) {
  109. continue;
  110. }
  111. Size2 minsize = c->get_combined_minimum_size();
  112. child_room = MAX(child_room, minsize.width);
  113. height = MAX(height, minsize.height);
  114. no_children = false;
  115. }
  116. if (no_children) {
  117. text_size = size.width;
  118. rect = Rect2(size.width - 1, 0, 1, height);
  119. } else {
  120. text_size = MAX(0, size.width - (child_room + 4 * EDSCALE));
  121. rect = Rect2(size.width - child_room, 0, child_room, height);
  122. }
  123. if (bottom_editor) {
  124. int m = 0; //get_constant("item_margin", "Tree");
  125. bottom_rect = Rect2(m, rect.size.height + get_constant("vseparation"), size.width - m, bottom_editor->get_combined_minimum_size().height);
  126. }
  127. if (keying) {
  128. Ref<Texture> key;
  129. if (use_keying_next()) {
  130. key = get_icon("KeyNext", "EditorIcons");
  131. } else {
  132. key = get_icon("Key", "EditorIcons");
  133. }
  134. rect.size.x -= key->get_width() + get_constant("hseparator", "Tree");
  135. if (no_children) {
  136. text_size -= key->get_width() + 4 * EDSCALE;
  137. }
  138. }
  139. }
  140. //set children
  141. for (int i = 0; i < get_child_count(); i++) {
  142. Control *c = Object::cast_to<Control>(get_child(i));
  143. if (!c) {
  144. continue;
  145. }
  146. if (c->is_set_as_toplevel()) {
  147. continue;
  148. }
  149. if (c == bottom_editor) {
  150. continue;
  151. }
  152. fit_child_in_rect(c, rect);
  153. right_child_rect = rect;
  154. }
  155. if (bottom_editor) {
  156. fit_child_in_rect(bottom_editor, bottom_rect);
  157. bottom_child_rect = bottom_rect;
  158. }
  159. update(); //need to redraw text
  160. }
  161. if (p_what == NOTIFICATION_DRAW) {
  162. Ref<Font> font = get_font("font", "Tree");
  163. Color dark_color = get_color("dark_color_2", "Editor");
  164. Size2 size = get_size();
  165. if (bottom_editor) {
  166. size.height = bottom_editor->get_margin(MARGIN_TOP);
  167. } else if (label_reference) {
  168. size.height = label_reference->get_size().height;
  169. }
  170. Ref<StyleBox> sb;
  171. if (selected) {
  172. sb = get_stylebox("bg_selected");
  173. } else {
  174. sb = get_stylebox("bg");
  175. }
  176. draw_style_box(sb, Rect2(Vector2(), size));
  177. if (draw_top_bg && right_child_rect != Rect2()) {
  178. draw_rect(right_child_rect, dark_color);
  179. }
  180. if (bottom_child_rect != Rect2()) {
  181. draw_rect(bottom_child_rect, dark_color);
  182. }
  183. Color color;
  184. if (draw_red) {
  185. color = get_color("warning_color");
  186. } else {
  187. color = get_color("property_color");
  188. }
  189. if (label.find(".") != -1) {
  190. color.a = 0.5; //this should be un-hacked honestly, as it's used for editor overrides
  191. }
  192. int ofs = get_constant("font_offset");
  193. int text_limit = text_size - ofs;
  194. if (checkable) {
  195. Ref<Texture> checkbox;
  196. if (checked) {
  197. checkbox = get_icon("GuiChecked", "EditorIcons");
  198. } else {
  199. checkbox = get_icon("GuiUnchecked", "EditorIcons");
  200. }
  201. Color color2(1, 1, 1);
  202. if (check_hover) {
  203. color2.r *= 1.2;
  204. color2.g *= 1.2;
  205. color2.b *= 1.2;
  206. }
  207. check_rect = Rect2(ofs, ((size.height - checkbox->get_height()) / 2), checkbox->get_width(), checkbox->get_height());
  208. draw_texture(checkbox, check_rect.position, color2);
  209. int check_ofs = get_constant("hseparator", "Tree") + checkbox->get_width() + get_constant("hseparation", "CheckBox");
  210. ofs += check_ofs;
  211. text_limit -= check_ofs;
  212. } else {
  213. check_rect = Rect2();
  214. }
  215. if (can_revert) {
  216. Ref<Texture> reload_icon = get_icon("ReloadSmall", "EditorIcons");
  217. text_limit -= reload_icon->get_width() + get_constant("hseparator", "Tree") * 2;
  218. revert_rect = Rect2(ofs + text_limit, (size.height - reload_icon->get_height()) / 2, reload_icon->get_width(), reload_icon->get_height());
  219. Color color2(1, 1, 1);
  220. if (revert_hover) {
  221. color2.r *= 1.2;
  222. color2.g *= 1.2;
  223. color2.b *= 1.2;
  224. }
  225. draw_texture(reload_icon, revert_rect.position, color2);
  226. } else {
  227. revert_rect = Rect2();
  228. }
  229. if (!pin_hidden && is_pinned) {
  230. Ref<Texture> pinned_icon = get_icon("Pin", "EditorIcons");
  231. int margin_w = get_constant("hseparator", "Tree") * 2;
  232. text_limit -= margin_w + pinned_icon->get_width();
  233. int text_w = MIN(font->get_string_size(label).x, text_limit);
  234. draw_texture(pinned_icon, Vector2(ofs + text_w + margin_w, (size.height - pinned_icon->get_height()) / 2), color);
  235. }
  236. int v_ofs = (size.height - font->get_height()) / 2;
  237. draw_string(font, Point2(ofs, v_ofs + font->get_ascent()), label, color, text_limit);
  238. if (keying) {
  239. Ref<Texture> key;
  240. if (use_keying_next()) {
  241. key = get_icon("KeyNext", "EditorIcons");
  242. } else {
  243. key = get_icon("Key", "EditorIcons");
  244. }
  245. ofs = size.width - key->get_width() - get_constant("hseparator", "Tree");
  246. Color color2(1, 1, 1);
  247. if (keying_hover) {
  248. color2.r *= 1.2;
  249. color2.g *= 1.2;
  250. color2.b *= 1.2;
  251. }
  252. keying_rect = Rect2(ofs, ((size.height - key->get_height()) / 2), key->get_width(), key->get_height());
  253. draw_texture(key, keying_rect.position, color2);
  254. } else {
  255. keying_rect = Rect2();
  256. }
  257. }
  258. }
  259. void EditorProperty::set_label(const String &p_label) {
  260. label = p_label;
  261. update();
  262. }
  263. String EditorProperty::get_label() const {
  264. return label;
  265. }
  266. Object *EditorProperty::get_edited_object() {
  267. return object;
  268. }
  269. StringName EditorProperty::get_edited_property() {
  270. return property;
  271. }
  272. void EditorProperty::update_property() {
  273. if (get_script_instance()) {
  274. get_script_instance()->call("update_property");
  275. }
  276. }
  277. void EditorProperty::set_read_only(bool p_read_only) {
  278. read_only = p_read_only;
  279. }
  280. bool EditorProperty::is_read_only() const {
  281. return read_only;
  282. }
  283. Variant EditorPropertyRevert::get_property_revert_value(Object *p_object, const StringName &p_property, bool *r_is_valid) {
  284. if (p_object->has_method("property_can_revert") && p_object->call("property_can_revert", p_property)) {
  285. if (r_is_valid) {
  286. *r_is_valid = true;
  287. }
  288. return p_object->call("property_get_revert", p_property);
  289. }
  290. return PropertyUtils::get_property_default_value(p_object, p_property, r_is_valid);
  291. }
  292. bool EditorPropertyRevert::can_property_revert(Object *p_object, const StringName &p_property) {
  293. bool is_valid_revert = false;
  294. Variant revert_value = EditorPropertyRevert::get_property_revert_value(p_object, p_property, &is_valid_revert);
  295. if (!is_valid_revert) {
  296. return false;
  297. }
  298. Variant current_value = p_object->get(p_property);
  299. return PropertyUtils::is_property_value_different(current_value, revert_value);
  300. }
  301. void EditorProperty::update_revert_and_pin_status() {
  302. if (property == StringName()) {
  303. return; //no property, so nothing to do
  304. }
  305. bool new_is_pinned = false;
  306. if (can_pin) {
  307. Node *node = Object::cast_to<Node>(object);
  308. CRASH_COND(!node);
  309. new_is_pinned = node->is_property_pinned(property);
  310. }
  311. bool new_can_revert = EditorPropertyRevert::can_property_revert(object, property);
  312. if (new_can_revert != can_revert || new_is_pinned != is_pinned) {
  313. can_revert = new_can_revert;
  314. is_pinned = new_is_pinned;
  315. update();
  316. }
  317. }
  318. bool EditorProperty::use_keying_next() const {
  319. List<PropertyInfo> plist;
  320. object->get_property_list(&plist, true);
  321. for (List<PropertyInfo>::Element *I = plist.front(); I; I = I->next()) {
  322. PropertyInfo &p = I->get();
  323. if (p.name == property) {
  324. return (p.usage & PROPERTY_USAGE_KEYING_INCREMENTS);
  325. }
  326. }
  327. return false;
  328. }
  329. void EditorProperty::set_checkable(bool p_checkable) {
  330. checkable = p_checkable;
  331. update();
  332. queue_sort();
  333. }
  334. bool EditorProperty::is_checkable() const {
  335. return checkable;
  336. }
  337. void EditorProperty::set_checked(bool p_checked) {
  338. checked = p_checked;
  339. update();
  340. }
  341. bool EditorProperty::is_checked() const {
  342. return checked;
  343. }
  344. void EditorProperty::set_draw_red(bool p_draw_red) {
  345. draw_red = p_draw_red;
  346. update();
  347. }
  348. void EditorProperty::set_keying(bool p_keying) {
  349. keying = p_keying;
  350. update();
  351. queue_sort();
  352. }
  353. bool EditorProperty::is_keying() const {
  354. return keying;
  355. }
  356. bool EditorProperty::is_draw_red() const {
  357. return draw_red;
  358. }
  359. void EditorProperty::_focusable_focused(int p_index) {
  360. if (!selectable) {
  361. return;
  362. }
  363. bool already_selected = selected;
  364. selected = true;
  365. selected_focusable = p_index;
  366. update();
  367. if (!already_selected && selected) {
  368. emit_signal("selected", property, selected_focusable);
  369. }
  370. }
  371. void EditorProperty::add_focusable(Control *p_control) {
  372. p_control->connect("focus_entered", this, "_focusable_focused", varray(focusables.size()));
  373. focusables.push_back(p_control);
  374. }
  375. void EditorProperty::select(int p_focusable) {
  376. bool already_selected = selected;
  377. if (p_focusable >= 0) {
  378. ERR_FAIL_INDEX(p_focusable, focusables.size());
  379. focusables[p_focusable]->grab_focus();
  380. } else {
  381. selected = true;
  382. update();
  383. }
  384. if (!already_selected && selected) {
  385. emit_signal("selected", property, selected_focusable);
  386. }
  387. }
  388. void EditorProperty::deselect() {
  389. selected = false;
  390. selected_focusable = -1;
  391. update();
  392. }
  393. bool EditorProperty::is_selected() const {
  394. return selected;
  395. }
  396. void EditorProperty::_gui_input(const Ref<InputEvent> &p_event) {
  397. if (property == StringName()) {
  398. return;
  399. }
  400. Ref<InputEventMouse> me = p_event;
  401. if (me.is_valid()) {
  402. bool button_left = me->get_button_mask() & BUTTON_MASK_LEFT;
  403. bool new_keying_hover = keying_rect.has_point(me->get_position()) && !button_left;
  404. if (new_keying_hover != keying_hover) {
  405. keying_hover = new_keying_hover;
  406. update();
  407. }
  408. bool new_revert_hover = revert_rect.has_point(me->get_position()) && !button_left;
  409. if (new_revert_hover != revert_hover) {
  410. revert_hover = new_revert_hover;
  411. update();
  412. }
  413. bool new_check_hover = check_rect.has_point(me->get_position()) && !button_left;
  414. if (new_check_hover != check_hover) {
  415. check_hover = new_check_hover;
  416. update();
  417. }
  418. }
  419. Ref<InputEventMouseButton> mb = p_event;
  420. if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
  421. if (!selected && selectable) {
  422. selected = true;
  423. emit_signal("selected", property, -1);
  424. update();
  425. }
  426. if (keying_rect.has_point(mb->get_position())) {
  427. emit_signal("property_keyed", property, use_keying_next());
  428. if (use_keying_next()) {
  429. if (property == "frame_coords" && (object->is_class("Sprite") || object->is_class("Sprite3D"))) {
  430. Vector2 new_coords = object->get(property);
  431. new_coords.x++;
  432. if (new_coords.x >= object->get("hframes").operator int64_t()) {
  433. new_coords.x = 0;
  434. new_coords.y++;
  435. }
  436. call_deferred("emit_changed", property, new_coords, "", false);
  437. } else {
  438. call_deferred("emit_changed", property, object->get(property).operator int64_t() + 1, "", false);
  439. }
  440. call_deferred("update_property");
  441. }
  442. }
  443. if (revert_rect.has_point(mb->get_position())) {
  444. bool is_valid_revert = false;
  445. Variant revert_value = EditorPropertyRevert::get_property_revert_value(object, property, &is_valid_revert);
  446. ERR_FAIL_COND(!is_valid_revert);
  447. emit_changed(property, revert_value);
  448. update_property();
  449. }
  450. if (check_rect.has_point(mb->get_position())) {
  451. checked = !checked;
  452. update();
  453. emit_signal("property_checked", property, checked);
  454. }
  455. } else if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_RIGHT) {
  456. _update_popup();
  457. if (menu->get_item_count()) {
  458. menu->set_position(get_global_mouse_position());
  459. menu->set_as_minsize();
  460. menu->popup();
  461. select();
  462. }
  463. }
  464. }
  465. void EditorProperty::_unhandled_key_input(const Ref<InputEvent> &p_event) {
  466. if (!selected || !is_visible_in_tree()) {
  467. return;
  468. }
  469. const Ref<InputEventKey> k = p_event;
  470. if (k.is_valid() && k->is_pressed()) {
  471. if (ED_IS_SHORTCUT("property_editor/copy_property", p_event)) {
  472. _menu_option(MENU_COPY_PROPERTY);
  473. accept_event();
  474. } else if (ED_IS_SHORTCUT("property_editor/paste_property", p_event) && !is_read_only()) {
  475. _menu_option(MENU_PASTE_PROPERTY);
  476. accept_event();
  477. } else if (ED_IS_SHORTCUT("property_editor/copy_property_path", p_event)) {
  478. _menu_option(MENU_COPY_PROPERTY_PATH);
  479. accept_event();
  480. }
  481. }
  482. }
  483. void EditorProperty::set_label_reference(Control *p_control) {
  484. label_reference = p_control;
  485. }
  486. void EditorProperty::set_bottom_editor(Control *p_control) {
  487. bottom_editor = p_control;
  488. }
  489. Variant EditorProperty::get_drag_data(const Point2 &p_point) {
  490. if (property == StringName()) {
  491. return Variant();
  492. }
  493. Dictionary dp;
  494. dp["type"] = "obj_property";
  495. dp["object"] = object;
  496. dp["property"] = property;
  497. dp["value"] = object->get(property);
  498. Label *label = memnew(Label);
  499. label->set_text(property);
  500. set_drag_preview(label);
  501. return dp;
  502. }
  503. void EditorProperty::set_use_folding(bool p_use_folding) {
  504. use_folding = p_use_folding;
  505. }
  506. bool EditorProperty::is_using_folding() const {
  507. return use_folding;
  508. }
  509. void EditorProperty::expand_all_folding() {
  510. }
  511. void EditorProperty::collapse_all_folding() {
  512. }
  513. void EditorProperty::set_selectable(bool p_selectable) {
  514. selectable = p_selectable;
  515. }
  516. bool EditorProperty::is_selectable() const {
  517. return selectable;
  518. }
  519. void EditorProperty::set_name_split_ratio(float p_ratio) {
  520. split_ratio = p_ratio;
  521. }
  522. float EditorProperty::get_name_split_ratio() const {
  523. return split_ratio;
  524. }
  525. void EditorProperty::set_object_and_property(Object *p_object, const StringName &p_property) {
  526. object = p_object;
  527. property = p_property;
  528. _update_pin_flags();
  529. }
  530. static bool _is_value_potential_override(Node *p_node, const String &p_property) {
  531. // Consider a value is potentially overriding another if either of the following is true:
  532. // a) The node is foreign (inheriting or an instance), so the original value may come from another scene.
  533. // b) The node belongs to the scene, but the original value comes from somewhere but the builtin class (i.e., a script).
  534. Node *edited_scene = EditorNode::get_singleton()->get_edited_scene();
  535. Vector<SceneState::PackState> states_stack = PropertyUtils::get_node_states_stack(p_node, edited_scene);
  536. if (states_stack.size()) {
  537. return true;
  538. } else {
  539. bool is_valid_default = false;
  540. bool is_class_default = false;
  541. PropertyUtils::get_property_default_value(p_node, p_property, &is_valid_default, &states_stack, false, nullptr, &is_class_default);
  542. return !is_class_default;
  543. }
  544. }
  545. void EditorProperty::_update_pin_flags() {
  546. can_pin = false;
  547. pin_hidden = true;
  548. if (read_only) {
  549. return;
  550. }
  551. if (Node *node = Object::cast_to<Node>(object)) {
  552. // Avoid errors down the road by ignoring nodes which are not part of a scene
  553. if (!node->get_owner()) {
  554. bool is_scene_root = false;
  555. for (int i = 0; i < EditorNode::get_singleton()->get_editor_data().get_edited_scene_count(); ++i) {
  556. if (EditorNode::get_singleton()->get_editor_data().get_edited_scene_root(i) == node) {
  557. is_scene_root = true;
  558. break;
  559. }
  560. }
  561. if (!is_scene_root) {
  562. return;
  563. }
  564. }
  565. if (!_is_value_potential_override(node, property)) {
  566. return;
  567. }
  568. pin_hidden = false;
  569. {
  570. Set<StringName> storable_properties;
  571. node->get_storable_properties(storable_properties);
  572. if (storable_properties.has(node->get_property_store_alias(property))) {
  573. can_pin = true;
  574. }
  575. }
  576. }
  577. }
  578. Control *EditorProperty::make_custom_tooltip(const String &p_text) const {
  579. EditorHelpBit *help_bit = memnew(EditorHelpBit);
  580. help_bit->add_style_override("panel", get_stylebox("panel", "TooltipPanel"));
  581. help_bit->get_rich_text()->set_fixed_size_to_width(360 * EDSCALE);
  582. Vector<String> slices = p_text.split("::", false);
  583. if (!slices.empty()) {
  584. String property_name = slices[0].strip_edges();
  585. String text = TTR("Property:") + " [u][b]" + property_name + "[/b][/u]";
  586. if (slices.size() > 1) {
  587. String property_doc = slices[1].strip_edges();
  588. if (property_name != property_doc) {
  589. text += "\n" + property_doc;
  590. }
  591. }
  592. help_bit->call_deferred("set_text", text); //hack so it uses proper theme once inside scene
  593. }
  594. return help_bit;
  595. }
  596. void EditorProperty::_bind_methods() {
  597. ClassDB::bind_method(D_METHOD("set_label", "text"), &EditorProperty::set_label);
  598. ClassDB::bind_method(D_METHOD("get_label"), &EditorProperty::get_label);
  599. ClassDB::bind_method(D_METHOD("set_read_only", "read_only"), &EditorProperty::set_read_only);
  600. ClassDB::bind_method(D_METHOD("is_read_only"), &EditorProperty::is_read_only);
  601. ClassDB::bind_method(D_METHOD("set_checkable", "checkable"), &EditorProperty::set_checkable);
  602. ClassDB::bind_method(D_METHOD("is_checkable"), &EditorProperty::is_checkable);
  603. ClassDB::bind_method(D_METHOD("set_checked", "checked"), &EditorProperty::set_checked);
  604. ClassDB::bind_method(D_METHOD("is_checked"), &EditorProperty::is_checked);
  605. ClassDB::bind_method(D_METHOD("set_draw_red", "draw_red"), &EditorProperty::set_draw_red);
  606. ClassDB::bind_method(D_METHOD("is_draw_red"), &EditorProperty::is_draw_red);
  607. ClassDB::bind_method(D_METHOD("set_keying", "keying"), &EditorProperty::set_keying);
  608. ClassDB::bind_method(D_METHOD("is_keying"), &EditorProperty::is_keying);
  609. ClassDB::bind_method(D_METHOD("get_edited_property"), &EditorProperty::get_edited_property);
  610. ClassDB::bind_method(D_METHOD("get_edited_object"), &EditorProperty::get_edited_object);
  611. ClassDB::bind_method(D_METHOD("_gui_input"), &EditorProperty::_gui_input);
  612. ClassDB::bind_method(D_METHOD("_menu_option", "option"), &EditorProperty::_menu_option);
  613. ClassDB::bind_method(D_METHOD("_unhandled_key_input"), &EditorProperty::_unhandled_key_input);
  614. ClassDB::bind_method(D_METHOD("_focusable_focused"), &EditorProperty::_focusable_focused);
  615. ClassDB::bind_method(D_METHOD("add_focusable", "control"), &EditorProperty::add_focusable);
  616. ClassDB::bind_method(D_METHOD("set_bottom_editor", "editor"), &EditorProperty::set_bottom_editor);
  617. ClassDB::bind_method(D_METHOD("emit_changed", "property", "value", "field", "changing"), &EditorProperty::emit_changed, DEFVAL(StringName()), DEFVAL(false));
  618. ADD_PROPERTY(PropertyInfo(Variant::STRING, "label"), "set_label", "get_label");
  619. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "read_only"), "set_read_only", "is_read_only");
  620. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "checkable"), "set_checkable", "is_checkable");
  621. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "checked"), "set_checked", "is_checked");
  622. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draw_red"), "set_draw_red", "is_draw_red");
  623. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "keying"), "set_keying", "is_keying");
  624. ADD_SIGNAL(MethodInfo("property_changed", PropertyInfo(Variant::STRING, "property"), PropertyInfo(Variant::NIL, "value", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT), PropertyInfo(Variant::STRING, "field"), PropertyInfo(Variant::BOOL, "changing")));
  625. ADD_SIGNAL(MethodInfo("multiple_properties_changed", PropertyInfo(Variant::POOL_STRING_ARRAY, "properties"), PropertyInfo(Variant::ARRAY, "value")));
  626. ADD_SIGNAL(MethodInfo("property_keyed", PropertyInfo(Variant::STRING, "property")));
  627. ADD_SIGNAL(MethodInfo("property_keyed_with_value", PropertyInfo(Variant::STRING, "property"), PropertyInfo(Variant::NIL, "value", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT)));
  628. ADD_SIGNAL(MethodInfo("property_checked", PropertyInfo(Variant::STRING, "property"), PropertyInfo(Variant::BOOL, "checked")));
  629. ADD_SIGNAL(MethodInfo("property_pinned", PropertyInfo(Variant::STRING, "property"), PropertyInfo(Variant::BOOL, "pinned")));
  630. ADD_SIGNAL(MethodInfo("resource_selected", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::OBJECT, "resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource")));
  631. ADD_SIGNAL(MethodInfo("object_id_selected", PropertyInfo(Variant::STRING, "property"), PropertyInfo(Variant::INT, "id")));
  632. ADD_SIGNAL(MethodInfo("selected", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::INT, "focusable_idx")));
  633. MethodInfo vm;
  634. vm.name = "update_property";
  635. BIND_VMETHOD(vm);
  636. ClassDB::bind_method(D_METHOD("_update_revert_and_pin_status"), &EditorProperty::update_revert_and_pin_status);
  637. }
  638. EditorProperty::EditorProperty() {
  639. draw_top_bg = true;
  640. object = nullptr;
  641. split_ratio = 0.5;
  642. selectable = true;
  643. text_size = 0;
  644. read_only = false;
  645. checkable = false;
  646. checked = false;
  647. draw_red = false;
  648. keying = false;
  649. keying_hover = false;
  650. revert_hover = false;
  651. check_hover = false;
  652. can_revert = false;
  653. can_pin = false;
  654. pin_hidden = false;
  655. is_pinned = false;
  656. use_folding = false;
  657. property_usage = 0;
  658. selected = false;
  659. selected_focusable = -1;
  660. label_reference = nullptr;
  661. bottom_editor = nullptr;
  662. menu = nullptr;
  663. set_process_unhandled_key_input(true);
  664. }
  665. void EditorProperty::_update_popup() {
  666. if (menu) {
  667. menu->clear();
  668. } else {
  669. menu = memnew(PopupMenu);
  670. add_child(menu);
  671. menu->connect("id_pressed", this, "_menu_option");
  672. }
  673. menu->add_shortcut(ED_GET_SHORTCUT("property_editor/copy_property"), MENU_COPY_PROPERTY);
  674. menu->add_shortcut(ED_GET_SHORTCUT("property_editor/paste_property"), MENU_PASTE_PROPERTY);
  675. menu->add_shortcut(ED_GET_SHORTCUT("property_editor/copy_property_path"), MENU_COPY_PROPERTY_PATH);
  676. menu->set_item_disabled(MENU_PASTE_PROPERTY, is_read_only());
  677. if (!pin_hidden) {
  678. menu->add_separator();
  679. if (can_pin) {
  680. menu->add_check_item(TTR("Pin value"), MENU_PIN_VALUE);
  681. menu->set_item_checked(menu->get_item_index(MENU_PIN_VALUE), is_pinned);
  682. menu->set_item_tooltip(menu->get_item_index(MENU_PIN_VALUE), TTR("Pinning a value forces it to be saved even if it's equal to the default."));
  683. } else {
  684. menu->add_check_item(vformat(TTR("Pin value [Disabled because '%s' is editor-only]"), property), MENU_PIN_VALUE);
  685. menu->set_item_disabled(menu->get_item_index(MENU_PIN_VALUE), true);
  686. }
  687. }
  688. }
  689. void EditorProperty::_menu_option(int p_option) {
  690. switch (p_option) {
  691. case MENU_PIN_VALUE: {
  692. emit_signal("property_pinned", property, !is_pinned);
  693. update();
  694. } break;
  695. case MENU_COPY_PROPERTY: {
  696. EditorNode::get_singleton()->get_inspector()->set_property_clipboard(object->get(property));
  697. } break;
  698. case MENU_PASTE_PROPERTY: {
  699. emit_changed(property, EditorNode::get_singleton()->get_inspector()->get_property_clipboard());
  700. } break;
  701. case MENU_COPY_PROPERTY_PATH: {
  702. OS::get_singleton()->set_clipboard(property_path);
  703. } break;
  704. }
  705. }
  706. ////////////////////////////////////////////////
  707. ////////////////////////////////////////////////
  708. void EditorInspectorPlugin::add_custom_control(Control *control) {
  709. AddedEditor ae;
  710. ae.property_editor = control;
  711. added_editors.push_back(ae);
  712. }
  713. void EditorInspectorPlugin::add_property_editor(const String &p_for_property, Control *p_prop) {
  714. ERR_FAIL_COND(Object::cast_to<EditorProperty>(p_prop) == nullptr);
  715. AddedEditor ae;
  716. ae.properties.push_back(p_for_property);
  717. ae.property_editor = p_prop;
  718. added_editors.push_back(ae);
  719. }
  720. void EditorInspectorPlugin::add_property_editor_for_multiple_properties(const String &p_label, const Vector<String> &p_properties, Control *p_prop) {
  721. AddedEditor ae;
  722. ae.properties = p_properties;
  723. ae.property_editor = p_prop;
  724. ae.label = p_label;
  725. added_editors.push_back(ae);
  726. }
  727. bool EditorInspectorPlugin::can_handle(Object *p_object) {
  728. if (get_script_instance()) {
  729. return get_script_instance()->call("can_handle", p_object);
  730. }
  731. return false;
  732. }
  733. void EditorInspectorPlugin::parse_begin(Object *p_object) {
  734. if (get_script_instance()) {
  735. get_script_instance()->call("parse_begin", p_object);
  736. }
  737. }
  738. void EditorInspectorPlugin::parse_category(Object *p_object, const String &p_parse_category) {
  739. if (get_script_instance()) {
  740. get_script_instance()->call("parse_category", p_object, p_parse_category);
  741. }
  742. }
  743. bool EditorInspectorPlugin::parse_property(Object *p_object, Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, int p_usage) {
  744. if (get_script_instance()) {
  745. Variant arg[6] = {
  746. p_object, p_type, p_path, p_hint, p_hint_text, p_usage
  747. };
  748. const Variant *argptr[6] = {
  749. &arg[0], &arg[1], &arg[2], &arg[3], &arg[4], &arg[5]
  750. };
  751. Variant::CallError err;
  752. return get_script_instance()->call("parse_property", (const Variant **)&argptr, 6, err);
  753. }
  754. return false;
  755. }
  756. void EditorInspectorPlugin::parse_end() {
  757. if (get_script_instance()) {
  758. get_script_instance()->call("parse_end");
  759. }
  760. }
  761. void EditorInspectorPlugin::_bind_methods() {
  762. ClassDB::bind_method(D_METHOD("add_custom_control", "control"), &EditorInspectorPlugin::add_custom_control);
  763. ClassDB::bind_method(D_METHOD("add_property_editor", "property", "editor"), &EditorInspectorPlugin::add_property_editor);
  764. ClassDB::bind_method(D_METHOD("add_property_editor_for_multiple_properties", "label", "properties", "editor"), &EditorInspectorPlugin::add_property_editor_for_multiple_properties);
  765. MethodInfo vm;
  766. vm.name = "can_handle";
  767. vm.return_val.type = Variant::BOOL;
  768. vm.arguments.push_back(PropertyInfo(Variant::OBJECT, "object"));
  769. BIND_VMETHOD(vm);
  770. vm.name = "parse_begin";
  771. vm.return_val.type = Variant::NIL;
  772. BIND_VMETHOD(vm);
  773. vm.name = "parse_category";
  774. vm.arguments.push_back(PropertyInfo(Variant::STRING, "category"));
  775. BIND_VMETHOD(vm);
  776. vm.arguments.pop_back();
  777. vm.name = "parse_property";
  778. vm.return_val.type = Variant::BOOL;
  779. vm.arguments.push_back(PropertyInfo(Variant::INT, "type"));
  780. vm.arguments.push_back(PropertyInfo(Variant::STRING, "path"));
  781. vm.arguments.push_back(PropertyInfo(Variant::INT, "hint"));
  782. vm.arguments.push_back(PropertyInfo(Variant::STRING, "hint_text"));
  783. vm.arguments.push_back(PropertyInfo(Variant::INT, "usage"));
  784. BIND_VMETHOD(vm);
  785. vm.arguments.clear();
  786. vm.name = "parse_end";
  787. vm.return_val.type = Variant::NIL;
  788. BIND_VMETHOD(vm);
  789. }
  790. ////////////////////////////////////////////////
  791. ////////////////////////////////////////////////
  792. void EditorInspectorCategory::_notification(int p_what) {
  793. if (p_what == NOTIFICATION_DRAW) {
  794. draw_rect(Rect2(Vector2(), get_size()), bg_color);
  795. Ref<Font> font = get_font("font", "Tree");
  796. int hs = get_constant("hseparation", "Tree");
  797. int w = font->get_string_size(label).width;
  798. if (icon.is_valid()) {
  799. w += hs + icon->get_width();
  800. }
  801. w = MIN(w, get_size().width - hs * 2);
  802. int ofs = (get_size().width - w) / 2;
  803. if (icon.is_valid()) {
  804. draw_texture(icon, Point2(ofs, (get_size().height - icon->get_height()) / 2).floor());
  805. ofs += hs + icon->get_width();
  806. w -= hs + icon->get_width();
  807. }
  808. Color color = get_color("font_color", "Tree");
  809. draw_string(font, Point2(ofs, font->get_ascent() + (get_size().height - font->get_height()) / 2).floor(), label, color, w);
  810. }
  811. }
  812. Control *EditorInspectorCategory::make_custom_tooltip(const String &p_text) const {
  813. EditorHelpBit *help_bit = memnew(EditorHelpBit);
  814. help_bit->add_style_override("panel", get_stylebox("panel", "TooltipPanel"));
  815. help_bit->get_rich_text()->set_fixed_size_to_width(360 * EDSCALE);
  816. Vector<String> slices = p_text.split("::", false);
  817. if (!slices.empty()) {
  818. String property_name = slices[0].strip_edges();
  819. String text = "[u][b]" + property_name + "[/b][/u]";
  820. if (slices.size() > 1) {
  821. String property_doc = slices[1].strip_edges();
  822. if (property_name != property_doc) {
  823. text += "\n" + property_doc;
  824. }
  825. }
  826. help_bit->call_deferred("set_text", text); //hack so it uses proper theme once inside scene
  827. }
  828. return help_bit;
  829. }
  830. Size2 EditorInspectorCategory::get_minimum_size() const {
  831. Ref<Font> font = get_font("font", "Tree");
  832. Size2 ms;
  833. ms.width = 1;
  834. ms.height = font->get_height();
  835. if (icon.is_valid()) {
  836. ms.height = MAX(icon->get_height(), ms.height);
  837. }
  838. ms.height += get_constant("vseparation", "Tree");
  839. return ms;
  840. }
  841. EditorInspectorCategory::EditorInspectorCategory() {
  842. }
  843. ////////////////////////////////////////////////
  844. ////////////////////////////////////////////////
  845. void EditorInspectorSection::_test_unfold() {
  846. if (!vbox_added) {
  847. add_child(vbox);
  848. vbox_added = true;
  849. }
  850. }
  851. Ref<Texture> EditorInspectorSection::_get_arrow() {
  852. Ref<Texture> arrow;
  853. if (foldable) {
  854. if (object->editor_is_section_unfolded(section)) {
  855. arrow = get_icon("arrow", "Tree");
  856. } else {
  857. arrow = get_icon("arrow_collapsed", "Tree");
  858. }
  859. }
  860. return arrow;
  861. }
  862. int EditorInspectorSection::_get_header_height() {
  863. Ref<Font> font = get_font("font", "Tree");
  864. int header_height = font->get_height();
  865. Ref<Texture> arrow = _get_arrow();
  866. if (arrow.is_valid()) {
  867. header_height = MAX(header_height, arrow->get_height());
  868. }
  869. header_height += get_constant("vseparation", "Tree");
  870. return header_height;
  871. }
  872. void EditorInspectorSection::_notification(int p_what) {
  873. switch (p_what) {
  874. case NOTIFICATION_SORT_CHILDREN: {
  875. Size2 size = get_size();
  876. Point2 offset;
  877. offset.y = _get_header_height();
  878. offset.x += get_constant("inspector_margin", "Editor");
  879. Rect2 rect(offset, size - offset);
  880. //set children
  881. for (int i = 0; i < get_child_count(); i++) {
  882. Control *c = Object::cast_to<Control>(get_child(i));
  883. if (!c) {
  884. continue;
  885. }
  886. if (c->is_set_as_toplevel()) {
  887. continue;
  888. }
  889. if (!c->is_visible_in_tree()) {
  890. continue;
  891. }
  892. fit_child_in_rect(c, rect);
  893. }
  894. update(); //need to redraw text
  895. } break;
  896. case NOTIFICATION_DRAW: {
  897. int h = _get_header_height();
  898. Rect2 header_rect = Rect2(Vector2(), Vector2(get_size().width, h));
  899. Color c = bg_color;
  900. c.a *= 0.4;
  901. if (foldable && header_rect.has_point(get_local_mouse_position())) {
  902. c = c.lightened(Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT) ? -0.05 : 0.2);
  903. }
  904. draw_rect(header_rect, c);
  905. const int arrow_margin = 3;
  906. Color color = get_color("font_color", "Tree");
  907. Ref<Font> font = get_font("font", "Tree");
  908. draw_string(font, Point2(Math::round((16 + arrow_margin) * EDSCALE), font->get_ascent() + (h - font->get_height()) / 2).floor(), label, color, get_size().width);
  909. Ref<Texture> arrow = _get_arrow();
  910. if (arrow.is_valid()) {
  911. draw_texture(arrow, Point2(Math::round(arrow_margin * EDSCALE), (h - arrow->get_height()) / 2).floor());
  912. }
  913. } break;
  914. case NOTIFICATION_MOUSE_ENTER:
  915. case NOTIFICATION_MOUSE_EXIT: {
  916. update();
  917. } break;
  918. }
  919. }
  920. Size2 EditorInspectorSection::get_minimum_size() const {
  921. Size2 ms;
  922. for (int i = 0; i < get_child_count(); i++) {
  923. Control *c = Object::cast_to<Control>(get_child(i));
  924. if (!c) {
  925. continue;
  926. }
  927. if (c->is_set_as_toplevel()) {
  928. continue;
  929. }
  930. if (!c->is_visible()) {
  931. continue;
  932. }
  933. Size2 minsize = c->get_combined_minimum_size();
  934. ms.width = MAX(ms.width, minsize.width);
  935. ms.height = MAX(ms.height, minsize.height);
  936. }
  937. Ref<Font> font = get_font("font", "Tree");
  938. ms.height += font->get_height() + get_constant("vseparation", "Tree");
  939. ms.width += get_constant("inspector_margin", "Editor");
  940. return ms;
  941. }
  942. void EditorInspectorSection::setup(const String &p_section, const String &p_label, Object *p_object, const Color &p_bg_color, bool p_foldable) {
  943. section = p_section;
  944. label = p_label;
  945. object = p_object;
  946. bg_color = p_bg_color;
  947. foldable = p_foldable;
  948. if (!foldable && !vbox_added) {
  949. add_child(vbox);
  950. vbox_added = true;
  951. }
  952. if (foldable) {
  953. _test_unfold();
  954. if (object->editor_is_section_unfolded(section)) {
  955. vbox->show();
  956. } else {
  957. vbox->hide();
  958. }
  959. }
  960. }
  961. void EditorInspectorSection::_gui_input(const Ref<InputEvent> &p_event) {
  962. if (!foldable) {
  963. return;
  964. }
  965. Ref<InputEventMouseButton> mb = p_event;
  966. if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
  967. if (mb->get_position().y >= _get_header_height()) {
  968. return;
  969. }
  970. _test_unfold();
  971. bool unfold = !object->editor_is_section_unfolded(section);
  972. object->editor_set_section_unfold(section, unfold);
  973. if (unfold) {
  974. vbox->show();
  975. } else {
  976. vbox->hide();
  977. }
  978. } else if (mb.is_valid() && !mb->is_pressed()) {
  979. update();
  980. }
  981. }
  982. VBoxContainer *EditorInspectorSection::get_vbox() {
  983. return vbox;
  984. }
  985. void EditorInspectorSection::unfold() {
  986. if (!foldable) {
  987. return;
  988. }
  989. _test_unfold();
  990. object->editor_set_section_unfold(section, true);
  991. vbox->show();
  992. update();
  993. }
  994. void EditorInspectorSection::fold() {
  995. if (!foldable) {
  996. return;
  997. }
  998. if (!vbox_added) {
  999. return; //kinda pointless
  1000. }
  1001. object->editor_set_section_unfold(section, false);
  1002. vbox->hide();
  1003. update();
  1004. }
  1005. void EditorInspectorSection::_bind_methods() {
  1006. ClassDB::bind_method(D_METHOD("setup", "section", "label", "object", "bg_color", "foldable"), &EditorInspectorSection::setup);
  1007. ClassDB::bind_method(D_METHOD("get_vbox"), &EditorInspectorSection::get_vbox);
  1008. ClassDB::bind_method(D_METHOD("unfold"), &EditorInspectorSection::unfold);
  1009. ClassDB::bind_method(D_METHOD("fold"), &EditorInspectorSection::fold);
  1010. ClassDB::bind_method(D_METHOD("_gui_input"), &EditorInspectorSection::_gui_input);
  1011. }
  1012. EditorInspectorSection::EditorInspectorSection() {
  1013. object = nullptr;
  1014. foldable = false;
  1015. vbox = memnew(VBoxContainer);
  1016. vbox_added = false;
  1017. }
  1018. EditorInspectorSection::~EditorInspectorSection() {
  1019. if (!vbox_added) {
  1020. memdelete(vbox);
  1021. }
  1022. }
  1023. ////////////////////////////////////////////////
  1024. ////////////////////////////////////////////////
  1025. Ref<EditorInspectorPlugin> EditorInspector::inspector_plugins[MAX_PLUGINS];
  1026. int EditorInspector::inspector_plugin_count = 0;
  1027. bool EditorInspector::_property_path_matches(const String &p_property_path, const String &p_filter, EditorPropertyNameProcessor::Style p_style) {
  1028. if (p_property_path.findn(p_filter) != -1) {
  1029. return true;
  1030. }
  1031. const Vector<String> sections = p_property_path.split("/");
  1032. for (int i = 0; i < sections.size(); i++) {
  1033. if (p_filter.is_subsequence_ofi(EditorPropertyNameProcessor::get_singleton()->process_name(sections[i], p_style))) {
  1034. return true;
  1035. }
  1036. }
  1037. return false;
  1038. }
  1039. EditorProperty *EditorInspector::instantiate_property_editor(Object *p_object, Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, int p_usage) {
  1040. for (int i = inspector_plugin_count - 1; i >= 0; i--) {
  1041. inspector_plugins[i]->parse_property(p_object, p_type, p_path, p_hint, p_hint_text, p_usage);
  1042. if (inspector_plugins[i]->added_editors.size()) {
  1043. for (int j = 1; j < inspector_plugins[i]->added_editors.size(); j++) { //only keep first one
  1044. memdelete(inspector_plugins[i]->added_editors[j].property_editor);
  1045. }
  1046. EditorProperty *prop = Object::cast_to<EditorProperty>(inspector_plugins[i]->added_editors[0].property_editor);
  1047. if (prop) {
  1048. inspector_plugins[i]->added_editors.clear();
  1049. return prop;
  1050. } else {
  1051. memdelete(inspector_plugins[i]->added_editors[0].property_editor);
  1052. inspector_plugins[i]->added_editors.clear();
  1053. }
  1054. }
  1055. }
  1056. return nullptr;
  1057. }
  1058. void EditorInspector::add_inspector_plugin(const Ref<EditorInspectorPlugin> &p_plugin) {
  1059. ERR_FAIL_COND(inspector_plugin_count == MAX_PLUGINS);
  1060. for (int i = 0; i < inspector_plugin_count; i++) {
  1061. if (inspector_plugins[i] == p_plugin) {
  1062. return; //already exists
  1063. }
  1064. }
  1065. inspector_plugins[inspector_plugin_count++] = p_plugin;
  1066. }
  1067. void EditorInspector::remove_inspector_plugin(const Ref<EditorInspectorPlugin> &p_plugin) {
  1068. ERR_FAIL_COND(inspector_plugin_count == MAX_PLUGINS);
  1069. int idx = -1;
  1070. for (int i = 0; i < inspector_plugin_count; i++) {
  1071. if (inspector_plugins[i] == p_plugin) {
  1072. idx = i;
  1073. break;
  1074. }
  1075. }
  1076. ERR_FAIL_COND_MSG(idx == -1, "Trying to remove nonexistent inspector plugin.");
  1077. for (int i = idx; i < inspector_plugin_count - 1; i++) {
  1078. inspector_plugins[i] = inspector_plugins[i + 1];
  1079. }
  1080. inspector_plugins[inspector_plugin_count - 1] = Ref<EditorInspectorPlugin>();
  1081. inspector_plugin_count--;
  1082. }
  1083. void EditorInspector::cleanup_plugins() {
  1084. for (int i = 0; i < inspector_plugin_count; i++) {
  1085. inspector_plugins[i].unref();
  1086. }
  1087. inspector_plugin_count = 0;
  1088. }
  1089. void EditorInspector::set_undo_redo(UndoRedo *p_undo_redo) {
  1090. undo_redo = p_undo_redo;
  1091. }
  1092. String EditorInspector::get_selected_path() const {
  1093. return property_selected;
  1094. }
  1095. void EditorInspector::_parse_added_editors(VBoxContainer *current_vbox, Ref<EditorInspectorPlugin> ped) {
  1096. for (List<EditorInspectorPlugin::AddedEditor>::Element *F = ped->added_editors.front(); F; F = F->next()) {
  1097. EditorProperty *ep = Object::cast_to<EditorProperty>(F->get().property_editor);
  1098. current_vbox->add_child(F->get().property_editor);
  1099. if (ep) {
  1100. ep->object = object;
  1101. ep->connect("property_changed", this, "_property_changed");
  1102. ep->connect("property_keyed", this, "_property_keyed");
  1103. ep->connect("property_keyed_with_value", this, "_property_keyed_with_value");
  1104. ep->connect("property_checked", this, "_property_checked");
  1105. ep->connect("property_pinned", this, "_property_pinned");
  1106. ep->connect("selected", this, "_property_selected");
  1107. ep->connect("multiple_properties_changed", this, "_multiple_properties_changed");
  1108. ep->connect("resource_selected", this, "_resource_selected", varray(), CONNECT_DEFERRED);
  1109. ep->connect("object_id_selected", this, "_object_id_selected", varray(), CONNECT_DEFERRED);
  1110. if (F->get().properties.size()) {
  1111. if (F->get().properties.size() == 1) {
  1112. //since it's one, associate:
  1113. ep->property = F->get().properties[0];
  1114. ep->property_path = property_prefix + F->get().properties[0];
  1115. ep->property_usage = 0;
  1116. }
  1117. if (F->get().label != String()) {
  1118. ep->set_label(F->get().label);
  1119. }
  1120. for (int i = 0; i < F->get().properties.size(); i++) {
  1121. String prop = F->get().properties[i];
  1122. if (!editor_property_map.has(prop)) {
  1123. editor_property_map[prop] = List<EditorProperty *>();
  1124. }
  1125. editor_property_map[prop].push_back(ep);
  1126. }
  1127. }
  1128. ep->set_read_only(read_only);
  1129. ep->update_property();
  1130. ep->_update_pin_flags();
  1131. ep->update_revert_and_pin_status();
  1132. }
  1133. }
  1134. ped->added_editors.clear();
  1135. }
  1136. bool EditorInspector::_is_property_disabled_by_feature_profile(const StringName &p_property) {
  1137. Ref<EditorFeatureProfile> profile = EditorFeatureProfileManager::get_singleton()->get_current_profile();
  1138. if (profile.is_null()) {
  1139. return false;
  1140. }
  1141. StringName class_name = object->get_class();
  1142. while (class_name != StringName()) {
  1143. if (profile->is_class_property_disabled(class_name, p_property)) {
  1144. return true;
  1145. }
  1146. if (profile->is_class_disabled(class_name)) {
  1147. //won't see properties of a disabled class
  1148. return true;
  1149. }
  1150. class_name = ClassDB::get_parent_class(class_name);
  1151. }
  1152. return false;
  1153. }
  1154. void EditorInspector::update_tree() {
  1155. //to update properly if all is refreshed
  1156. StringName current_selected = property_selected;
  1157. int current_focusable = -1;
  1158. if (property_focusable != -1) {
  1159. //check focusable is really focusable
  1160. bool restore_focus = false;
  1161. Control *focused = get_focus_owner();
  1162. if (focused) {
  1163. Node *parent = focused->get_parent();
  1164. while (parent) {
  1165. EditorInspector *inspector = Object::cast_to<EditorInspector>(parent);
  1166. if (inspector) {
  1167. restore_focus = inspector == this; //may be owned by another inspector
  1168. break; //exit after the first inspector is found, since there may be nested ones
  1169. }
  1170. parent = parent->get_parent();
  1171. }
  1172. }
  1173. if (restore_focus) {
  1174. current_focusable = property_focusable;
  1175. }
  1176. }
  1177. _clear();
  1178. if (!object) {
  1179. return;
  1180. }
  1181. List<Ref<EditorInspectorPlugin>> valid_plugins;
  1182. for (int i = inspector_plugin_count - 1; i >= 0; i--) { //start by last, so lastly added can override newly added
  1183. if (!inspector_plugins[i]->can_handle(object)) {
  1184. continue;
  1185. }
  1186. valid_plugins.push_back(inspector_plugins[i]);
  1187. }
  1188. bool draw_red = false;
  1189. {
  1190. Node *nod = Object::cast_to<Node>(object);
  1191. Node *es = EditorNode::get_singleton()->get_edited_scene();
  1192. if (nod && es != nod && nod->get_owner() != es) {
  1193. draw_red = true;
  1194. }
  1195. }
  1196. // TreeItem *current_category = NULL;
  1197. String filter = search_box ? search_box->get_text() : "";
  1198. String group;
  1199. String group_base;
  1200. VBoxContainer *category_vbox = nullptr;
  1201. List<PropertyInfo> plist;
  1202. object->get_property_list(&plist, true);
  1203. HashMap<String, VBoxContainer *> item_path;
  1204. Map<VBoxContainer *, EditorInspectorSection *> section_map;
  1205. item_path[""] = main_vbox;
  1206. Color sscolor = get_color("prop_subsection", "Editor");
  1207. for (List<Ref<EditorInspectorPlugin>>::Element *E = valid_plugins.front(); E; E = E->next()) {
  1208. Ref<EditorInspectorPlugin> ped = E->get();
  1209. ped->parse_begin(object);
  1210. _parse_added_editors(main_vbox, ped);
  1211. }
  1212. for (List<PropertyInfo>::Element *I = plist.front(); I; I = I->next()) {
  1213. PropertyInfo &p = I->get();
  1214. //make sure the property can be edited
  1215. if (p.usage & PROPERTY_USAGE_GROUP) {
  1216. group = p.name;
  1217. group_base = p.hint_string;
  1218. continue;
  1219. } else if (p.usage & PROPERTY_USAGE_CATEGORY) {
  1220. group = "";
  1221. group_base = "";
  1222. if (!show_categories) {
  1223. continue;
  1224. }
  1225. List<PropertyInfo>::Element *N = I->next();
  1226. bool valid = true;
  1227. //if no properties in category, skip
  1228. while (N) {
  1229. if (N->get().usage & PROPERTY_USAGE_EDITOR) {
  1230. break;
  1231. }
  1232. if (N->get().usage & PROPERTY_USAGE_CATEGORY) {
  1233. valid = false;
  1234. break;
  1235. }
  1236. N = N->next();
  1237. }
  1238. if (!valid) {
  1239. continue; //empty, ignore
  1240. }
  1241. EditorInspectorCategory *category = memnew(EditorInspectorCategory);
  1242. main_vbox->add_child(category);
  1243. category_vbox = nullptr; //reset
  1244. String type = p.name;
  1245. category->icon = EditorNode::get_singleton()->get_class_icon(type, "Object");
  1246. category->label = type;
  1247. category->bg_color = get_color("prop_category", "Editor");
  1248. if (use_doc_hints) {
  1249. StringName type2 = p.name;
  1250. if (!class_descr_cache.has(type2)) {
  1251. String descr;
  1252. DocData *dd = EditorHelp::get_doc_data();
  1253. Map<String, DocData::ClassDoc>::Element *E = dd->class_list.find(type2);
  1254. if (E) {
  1255. descr = DTR(E->get().brief_description);
  1256. }
  1257. class_descr_cache[type2] = descr;
  1258. }
  1259. category->set_tooltip(p.name + "::" + (class_descr_cache[type2] == "" ? "" : class_descr_cache[type2]));
  1260. }
  1261. for (List<Ref<EditorInspectorPlugin>>::Element *E = valid_plugins.front(); E; E = E->next()) {
  1262. Ref<EditorInspectorPlugin> ped = E->get();
  1263. ped->parse_category(object, p.name);
  1264. _parse_added_editors(main_vbox, ped);
  1265. }
  1266. continue;
  1267. } else if (!(p.usage & PROPERTY_USAGE_EDITOR) || _is_property_disabled_by_feature_profile(p.name)) {
  1268. continue;
  1269. }
  1270. if (p.usage & PROPERTY_USAGE_HIGH_END_GFX && VS::get_singleton()->is_low_end()) {
  1271. continue; //do not show this property in low end gfx
  1272. }
  1273. if (p.name == "script" && (hide_script || bool(object->call("_hide_script_from_inspector")))) {
  1274. continue;
  1275. }
  1276. String basename = p.name;
  1277. if (group != "") {
  1278. if (group_base != "") {
  1279. if (basename.begins_with(group_base)) {
  1280. basename = basename.replace_first(group_base, "");
  1281. } else if (group_base.begins_with(basename)) {
  1282. //keep it, this is used pretty often
  1283. } else {
  1284. group = ""; //no longer using group base, clear
  1285. }
  1286. }
  1287. }
  1288. if (group != "") {
  1289. basename = group + "/" + basename;
  1290. }
  1291. String name = (basename.find("/") != -1) ? basename.right(basename.rfind("/") + 1) : basename;
  1292. String name_override = name;
  1293. String feature_tag;
  1294. {
  1295. const int dot = name.find(".");
  1296. if (dot != -1) {
  1297. name_override = name.substr(0, dot);
  1298. feature_tag = name.right(dot);
  1299. }
  1300. }
  1301. // Don't localize script variables.
  1302. EditorPropertyNameProcessor::Style name_style = property_name_style;
  1303. if ((p.usage & PROPERTY_USAGE_SCRIPT_VARIABLE) && name_style == EditorPropertyNameProcessor::STYLE_LOCALIZED) {
  1304. name_style = EditorPropertyNameProcessor::STYLE_CAPITALIZED;
  1305. }
  1306. name = EditorPropertyNameProcessor::get_singleton()->process_name(name_override, name_style) + feature_tag;
  1307. String path = basename.left(basename.rfind("/"));
  1308. if (use_filter && !filter.empty()) {
  1309. const String property_path = property_prefix + (path.empty() ? "" : path + "/") + name_override;
  1310. if (!_property_path_matches(property_path, filter, property_name_style)) {
  1311. continue;
  1312. }
  1313. }
  1314. if (category_vbox == nullptr) {
  1315. category_vbox = memnew(VBoxContainer);
  1316. main_vbox->add_child(category_vbox);
  1317. }
  1318. VBoxContainer *current_vbox = main_vbox;
  1319. {
  1320. String acc_path = "";
  1321. int level = 1;
  1322. for (int i = 0; i < path.get_slice_count("/"); i++) {
  1323. String path_name = path.get_slice("/", i);
  1324. if (i > 0) {
  1325. acc_path += "/";
  1326. }
  1327. acc_path += path_name;
  1328. if (!item_path.has(acc_path)) {
  1329. EditorInspectorSection *section = memnew(EditorInspectorSection);
  1330. current_vbox->add_child(section);
  1331. sections.push_back(section);
  1332. String label;
  1333. String tooltip;
  1334. // Don't localize groups for script variables.
  1335. EditorPropertyNameProcessor::Style section_name_style = property_name_style;
  1336. if ((p.usage & PROPERTY_USAGE_SCRIPT_VARIABLE) && section_name_style == EditorPropertyNameProcessor::STYLE_LOCALIZED) {
  1337. section_name_style = EditorPropertyNameProcessor::STYLE_CAPITALIZED;
  1338. }
  1339. // Only process group label if this is not the group or subgroup.
  1340. if ((i == 0 && path_name == group)) {
  1341. if (section_name_style == EditorPropertyNameProcessor::STYLE_LOCALIZED) {
  1342. label = TTRGET(path_name);
  1343. tooltip = path_name;
  1344. } else {
  1345. label = path_name;
  1346. tooltip = TTRGET(path_name);
  1347. }
  1348. } else {
  1349. label = EditorPropertyNameProcessor::get_singleton()->process_name(path_name, section_name_style);
  1350. tooltip = EditorPropertyNameProcessor::get_singleton()->process_name(path_name, EditorPropertyNameProcessor::get_tooltip_style(section_name_style));
  1351. }
  1352. Color c = sscolor;
  1353. c.a /= level;
  1354. section->setup(acc_path, label, object, c, use_folding);
  1355. section->set_tooltip(tooltip);
  1356. VBoxContainer *vb = section->get_vbox();
  1357. item_path[acc_path] = vb;
  1358. section_map[vb] = section;
  1359. }
  1360. current_vbox = item_path[acc_path];
  1361. level = (MIN(level + 1, 4));
  1362. }
  1363. if (current_vbox == main_vbox) {
  1364. //do not add directly to the main vbox, given it has no spacing
  1365. if (category_vbox == nullptr) {
  1366. category_vbox = memnew(VBoxContainer);
  1367. }
  1368. current_vbox = category_vbox;
  1369. }
  1370. }
  1371. bool checkable = false;
  1372. bool checked = false;
  1373. if (p.usage & PROPERTY_USAGE_CHECKABLE) {
  1374. checkable = true;
  1375. checked = p.usage & PROPERTY_USAGE_CHECKED;
  1376. }
  1377. if (p.usage & PROPERTY_USAGE_RESTART_IF_CHANGED) {
  1378. restart_request_props.insert(p.name);
  1379. }
  1380. String doc_hint;
  1381. if (use_doc_hints) {
  1382. StringName classname = object->get_class_name();
  1383. if (object_class != String()) {
  1384. classname = object_class;
  1385. } else if (Object::cast_to<MultiNodeEdit>(object)) {
  1386. classname = Object::cast_to<MultiNodeEdit>(object)->get_edited_class_name();
  1387. }
  1388. StringName propname = property_prefix + p.name;
  1389. String descr;
  1390. bool found = false;
  1391. Map<StringName, Map<StringName, String>>::Element *E = descr_cache.find(classname);
  1392. if (E) {
  1393. Map<StringName, String>::Element *F = E->get().find(propname);
  1394. if (F) {
  1395. found = true;
  1396. descr = F->get();
  1397. }
  1398. }
  1399. if (!found) {
  1400. DocData *dd = EditorHelp::get_doc_data();
  1401. Map<String, DocData::ClassDoc>::Element *F = dd->class_list.find(classname);
  1402. while (F && descr == String()) {
  1403. for (int i = 0; i < F->get().properties.size(); i++) {
  1404. if (F->get().properties[i].name == propname.operator String()) {
  1405. descr = DTR(F->get().properties[i].description);
  1406. break;
  1407. }
  1408. }
  1409. Vector<String> slices = propname.operator String().split("/");
  1410. if (slices.size() == 2 && slices[0].begins_with("custom_")) {
  1411. // Likely a theme property.
  1412. for (int i = 0; i < F->get().theme_properties.size(); i++) {
  1413. if (F->get().theme_properties[i].name == slices[1]) {
  1414. descr = DTR(F->get().theme_properties[i].description);
  1415. break;
  1416. }
  1417. }
  1418. }
  1419. if (!F->get().inherits.empty()) {
  1420. F = dd->class_list.find(F->get().inherits);
  1421. } else {
  1422. break;
  1423. }
  1424. }
  1425. descr_cache[classname][propname] = descr;
  1426. }
  1427. doc_hint = descr;
  1428. }
  1429. for (List<Ref<EditorInspectorPlugin>>::Element *E = valid_plugins.front(); E; E = E->next()) {
  1430. Ref<EditorInspectorPlugin> ped = E->get();
  1431. bool exclusive = ped->parse_property(object, p.type, p.name, p.hint, p.hint_string, p.usage);
  1432. List<EditorInspectorPlugin::AddedEditor> editors = ped->added_editors; //make a copy, since plugins may be used again in a sub-inspector
  1433. ped->added_editors.clear();
  1434. for (List<EditorInspectorPlugin::AddedEditor>::Element *F = editors.front(); F; F = F->next()) {
  1435. EditorProperty *ep = Object::cast_to<EditorProperty>(F->get().property_editor);
  1436. if (ep) {
  1437. //set all this before the control gets the ENTER_TREE notification
  1438. ep->object = object;
  1439. if (F->get().properties.size()) {
  1440. if (F->get().properties.size() == 1) {
  1441. //since it's one, associate:
  1442. ep->property = F->get().properties[0];
  1443. ep->property_path = property_prefix + F->get().properties[0];
  1444. ep->property_usage = p.usage;
  1445. //and set label?
  1446. }
  1447. if (F->get().label != String()) {
  1448. ep->set_label(F->get().label);
  1449. } else {
  1450. //use existing one
  1451. ep->set_label(name);
  1452. }
  1453. for (int i = 0; i < F->get().properties.size(); i++) {
  1454. String prop = F->get().properties[i];
  1455. if (!editor_property_map.has(prop)) {
  1456. editor_property_map[prop] = List<EditorProperty *>();
  1457. }
  1458. editor_property_map[prop].push_back(ep);
  1459. }
  1460. }
  1461. ep->set_draw_red(draw_red);
  1462. ep->set_use_folding(use_folding);
  1463. ep->set_checkable(checkable);
  1464. ep->set_checked(checked);
  1465. ep->set_keying(keying);
  1466. ep->set_read_only(read_only);
  1467. }
  1468. current_vbox->add_child(F->get().property_editor);
  1469. if (ep) {
  1470. ep->connect("property_changed", this, "_property_changed");
  1471. if (p.usage & PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED) {
  1472. ep->connect("property_changed", this, "_property_changed_update_all", varray(), CONNECT_DEFERRED);
  1473. }
  1474. ep->connect("property_keyed", this, "_property_keyed");
  1475. ep->connect("property_keyed_with_value", this, "_property_keyed_with_value");
  1476. ep->connect("property_checked", this, "_property_checked");
  1477. ep->connect("property_pinned", this, "_property_pinned");
  1478. ep->connect("selected", this, "_property_selected");
  1479. ep->connect("multiple_properties_changed", this, "_multiple_properties_changed");
  1480. ep->connect("resource_selected", this, "_resource_selected", varray(), CONNECT_DEFERRED);
  1481. ep->connect("object_id_selected", this, "_object_id_selected", varray(), CONNECT_DEFERRED);
  1482. if (doc_hint != String()) {
  1483. ep->set_tooltip(property_prefix + p.name + "::" + doc_hint);
  1484. } else {
  1485. ep->set_tooltip(property_prefix + p.name);
  1486. }
  1487. ep->update_property();
  1488. ep->_update_pin_flags();
  1489. ep->update_revert_and_pin_status();
  1490. if (current_selected && ep->property == current_selected) {
  1491. ep->select(current_focusable);
  1492. }
  1493. }
  1494. }
  1495. if (exclusive) {
  1496. break;
  1497. }
  1498. }
  1499. }
  1500. for (List<Ref<EditorInspectorPlugin>>::Element *E = valid_plugins.front(); E; E = E->next()) {
  1501. Ref<EditorInspectorPlugin> ped = E->get();
  1502. ped->parse_end();
  1503. _parse_added_editors(main_vbox, ped);
  1504. }
  1505. //see if this property exists and should be kept
  1506. }
  1507. void EditorInspector::update_property(const String &p_prop) {
  1508. if (!editor_property_map.has(p_prop)) {
  1509. return;
  1510. }
  1511. for (List<EditorProperty *>::Element *E = editor_property_map[p_prop].front(); E; E = E->next()) {
  1512. E->get()->update_property();
  1513. E->get()->update_revert_and_pin_status();
  1514. }
  1515. }
  1516. void EditorInspector::_clear() {
  1517. while (main_vbox->get_child_count()) {
  1518. memdelete(main_vbox->get_child(0));
  1519. }
  1520. property_selected = StringName();
  1521. property_focusable = -1;
  1522. editor_property_map.clear();
  1523. sections.clear();
  1524. pending.clear();
  1525. restart_request_props.clear();
  1526. }
  1527. void EditorInspector::refresh() {
  1528. if (refresh_countdown > 0 || changing) {
  1529. return;
  1530. }
  1531. refresh_countdown = EditorSettings::get_singleton()->get("docks/property_editor/auto_refresh_interval");
  1532. }
  1533. Object *EditorInspector::get_edited_object() {
  1534. return object;
  1535. }
  1536. void EditorInspector::edit(Object *p_object) {
  1537. if (object == p_object) {
  1538. return;
  1539. }
  1540. if (object) {
  1541. _clear();
  1542. object->remove_change_receptor(this);
  1543. }
  1544. object = p_object;
  1545. if (object) {
  1546. update_scroll_request = 0; //reset
  1547. if (scroll_cache.has(object->get_instance_id())) { //if exists, set something else
  1548. update_scroll_request = scroll_cache[object->get_instance_id()]; //done this way because wait until full size is accommodated
  1549. }
  1550. object->add_change_receptor(this);
  1551. update_tree();
  1552. }
  1553. }
  1554. void EditorInspector::set_keying(bool p_active) {
  1555. if (keying == p_active) {
  1556. return;
  1557. }
  1558. keying = p_active;
  1559. update_tree();
  1560. }
  1561. void EditorInspector::set_read_only(bool p_read_only) {
  1562. read_only = p_read_only;
  1563. update_tree();
  1564. }
  1565. EditorPropertyNameProcessor::Style EditorInspector::get_property_name_style() const {
  1566. return property_name_style;
  1567. }
  1568. void EditorInspector::set_property_name_style(EditorPropertyNameProcessor::Style p_style) {
  1569. if (property_name_style == p_style) {
  1570. return;
  1571. }
  1572. property_name_style = p_style;
  1573. update_tree();
  1574. }
  1575. void EditorInspector::set_autoclear(bool p_enable) {
  1576. autoclear = p_enable;
  1577. }
  1578. void EditorInspector::set_show_categories(bool p_show) {
  1579. show_categories = p_show;
  1580. update_tree();
  1581. }
  1582. void EditorInspector::set_use_doc_hints(bool p_enable) {
  1583. use_doc_hints = p_enable;
  1584. update_tree();
  1585. }
  1586. void EditorInspector::set_hide_script(bool p_hide) {
  1587. hide_script = p_hide;
  1588. update_tree();
  1589. }
  1590. void EditorInspector::set_use_filter(bool p_use) {
  1591. use_filter = p_use;
  1592. update_tree();
  1593. }
  1594. void EditorInspector::register_text_enter(Node *p_line_edit) {
  1595. search_box = Object::cast_to<LineEdit>(p_line_edit);
  1596. if (search_box) {
  1597. search_box->connect("text_changed", this, "_filter_changed");
  1598. }
  1599. }
  1600. void EditorInspector::_filter_changed(const String &p_text) {
  1601. _clear();
  1602. update_tree();
  1603. }
  1604. void EditorInspector::set_use_folding(bool p_enable) {
  1605. use_folding = p_enable;
  1606. update_tree();
  1607. }
  1608. bool EditorInspector::is_using_folding() {
  1609. return use_folding;
  1610. }
  1611. void EditorInspector::collapse_all_folding() {
  1612. for (List<EditorInspectorSection *>::Element *E = sections.front(); E; E = E->next()) {
  1613. E->get()->fold();
  1614. }
  1615. for (Map<StringName, List<EditorProperty *>>::Element *F = editor_property_map.front(); F; F = F->next()) {
  1616. for (List<EditorProperty *>::Element *E = F->get().front(); E; E = E->next()) {
  1617. E->get()->collapse_all_folding();
  1618. }
  1619. }
  1620. }
  1621. void EditorInspector::expand_all_folding() {
  1622. for (List<EditorInspectorSection *>::Element *E = sections.front(); E; E = E->next()) {
  1623. E->get()->unfold();
  1624. }
  1625. for (Map<StringName, List<EditorProperty *>>::Element *F = editor_property_map.front(); F; F = F->next()) {
  1626. for (List<EditorProperty *>::Element *E = F->get().front(); E; E = E->next()) {
  1627. E->get()->expand_all_folding();
  1628. }
  1629. }
  1630. }
  1631. void EditorInspector::set_scroll_offset(int p_offset) {
  1632. set_v_scroll(p_offset);
  1633. }
  1634. int EditorInspector::get_scroll_offset() const {
  1635. return get_v_scroll();
  1636. }
  1637. void EditorInspector::_update_inspector_bg() {
  1638. if (sub_inspector) {
  1639. int count_subinspectors = 0;
  1640. Node *n = get_parent();
  1641. while (n) {
  1642. EditorInspector *ei = Object::cast_to<EditorInspector>(n);
  1643. if (ei && ei->sub_inspector) {
  1644. count_subinspectors++;
  1645. }
  1646. n = n->get_parent();
  1647. }
  1648. count_subinspectors = MIN(15, count_subinspectors);
  1649. add_style_override("bg", get_stylebox("sub_inspector_bg" + itos(count_subinspectors), "Editor"));
  1650. } else {
  1651. add_style_override("bg", get_stylebox("bg", "Tree"));
  1652. }
  1653. }
  1654. void EditorInspector::set_sub_inspector(bool p_enable) {
  1655. sub_inspector = p_enable;
  1656. if (!is_inside_tree()) {
  1657. return;
  1658. }
  1659. _update_inspector_bg();
  1660. }
  1661. void EditorInspector::set_property_clipboard(const Variant &p_value) {
  1662. property_clipboard = p_value;
  1663. }
  1664. Variant EditorInspector::get_property_clipboard() const {
  1665. return property_clipboard;
  1666. }
  1667. void EditorInspector::_edit_request_change(Object *p_object, const String &p_property) {
  1668. if (object != p_object) { //may be undoing/redoing for a non edited object, so ignore
  1669. return;
  1670. }
  1671. if (changing) {
  1672. return;
  1673. }
  1674. if (p_property == String()) {
  1675. update_tree_pending = true;
  1676. } else {
  1677. pending.insert(p_property);
  1678. }
  1679. }
  1680. void EditorInspector::_edit_set(const String &p_name, const Variant &p_value, bool p_refresh_all, const String &p_changed_field) {
  1681. if (autoclear && editor_property_map.has(p_name)) {
  1682. for (List<EditorProperty *>::Element *E = editor_property_map[p_name].front(); E; E = E->next()) {
  1683. if (E->get()->is_checkable()) {
  1684. E->get()->set_checked(true);
  1685. }
  1686. }
  1687. }
  1688. if (!undo_redo || bool(object->call("_dont_undo_redo"))) {
  1689. object->set(p_name, p_value);
  1690. if (p_refresh_all) {
  1691. _edit_request_change(object, "");
  1692. } else {
  1693. _edit_request_change(object, p_name);
  1694. }
  1695. emit_signal(_prop_edited, p_name);
  1696. } else if (Object::cast_to<MultiNodeEdit>(object)) {
  1697. Object::cast_to<MultiNodeEdit>(object)->set_property_field(p_name, p_value, p_changed_field);
  1698. _edit_request_change(object, p_name);
  1699. emit_signal(_prop_edited, p_name);
  1700. } else {
  1701. undo_redo->create_action(vformat(TTR("Set %s"), p_name), UndoRedo::MERGE_ENDS);
  1702. undo_redo->add_do_property(object, p_name, p_value);
  1703. undo_redo->add_undo_property(object, p_name, object->get(p_name));
  1704. if (p_refresh_all) {
  1705. undo_redo->add_do_method(this, "_edit_request_change", object, "");
  1706. undo_redo->add_undo_method(this, "_edit_request_change", object, "");
  1707. } else {
  1708. undo_redo->add_do_method(this, "_edit_request_change", object, p_name);
  1709. undo_redo->add_undo_method(this, "_edit_request_change", object, p_name);
  1710. }
  1711. Resource *r = Object::cast_to<Resource>(object);
  1712. if (r) {
  1713. if (String(p_name) == "resource_local_to_scene") {
  1714. bool prev = object->get(p_name);
  1715. bool next = p_value;
  1716. if (next) {
  1717. undo_redo->add_do_method(r, "setup_local_to_scene");
  1718. }
  1719. if (prev) {
  1720. undo_redo->add_undo_method(r, "setup_local_to_scene");
  1721. }
  1722. }
  1723. }
  1724. undo_redo->add_do_method(this, "emit_signal", _prop_edited, p_name);
  1725. undo_redo->add_undo_method(this, "emit_signal", _prop_edited, p_name);
  1726. undo_redo->commit_action();
  1727. }
  1728. if (editor_property_map.has(p_name)) {
  1729. for (List<EditorProperty *>::Element *E = editor_property_map[p_name].front(); E; E = E->next()) {
  1730. E->get()->update_revert_and_pin_status();
  1731. }
  1732. }
  1733. }
  1734. void EditorInspector::_property_changed(const String &p_path, const Variant &p_value, const String &p_name, bool changing) {
  1735. // The "changing" variable must be true for properties that trigger events as typing occurs,
  1736. // like "text_changed" signal. eg: Text property of Label, Button, RichTextLabel, etc.
  1737. if (changing) {
  1738. this->changing++;
  1739. }
  1740. _edit_set(p_path, p_value, false, p_name);
  1741. if (changing) {
  1742. this->changing--;
  1743. }
  1744. if (restart_request_props.has(p_path)) {
  1745. emit_signal("restart_requested");
  1746. }
  1747. }
  1748. void EditorInspector::_property_changed_update_all(const String &p_path, const Variant &p_value, const String &p_name, bool p_changing) {
  1749. update_tree();
  1750. }
  1751. void EditorInspector::_multiple_properties_changed(Vector<String> p_paths, Array p_values) {
  1752. ERR_FAIL_COND(p_paths.size() == 0 || p_values.size() == 0);
  1753. ERR_FAIL_COND(p_paths.size() != p_values.size());
  1754. String names;
  1755. for (int i = 0; i < p_paths.size(); i++) {
  1756. if (i > 0) {
  1757. names += ",";
  1758. }
  1759. names += p_paths[i];
  1760. }
  1761. undo_redo->create_action(TTR("Set Multiple:") + " " + names, UndoRedo::MERGE_ENDS);
  1762. for (int i = 0; i < p_paths.size(); i++) {
  1763. _edit_set(p_paths[i], p_values[i], false, "");
  1764. if (restart_request_props.has(p_paths[i])) {
  1765. emit_signal("restart_requested");
  1766. }
  1767. }
  1768. changing++;
  1769. undo_redo->commit_action();
  1770. changing--;
  1771. }
  1772. void EditorInspector::_property_keyed(const String &p_path, bool p_advance) {
  1773. if (!object) {
  1774. return;
  1775. }
  1776. emit_signal("property_keyed", p_path, object->get(p_path), p_advance); //second param is deprecated
  1777. }
  1778. void EditorInspector::_property_keyed_with_value(const String &p_path, const Variant &p_value, bool p_advance) {
  1779. if (!object) {
  1780. return;
  1781. }
  1782. emit_signal("property_keyed", p_path, p_value, p_advance); //second param is deprecated
  1783. }
  1784. void EditorInspector::_property_checked(const String &p_path, bool p_checked) {
  1785. if (!object) {
  1786. return;
  1787. }
  1788. //property checked
  1789. if (autoclear) {
  1790. if (!p_checked) {
  1791. object->set(p_path, Variant());
  1792. } else {
  1793. Variant to_create;
  1794. List<PropertyInfo> pinfo;
  1795. object->get_property_list(&pinfo);
  1796. for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
  1797. if (E->get().name == p_path) {
  1798. Variant::CallError ce;
  1799. to_create = Variant::construct(E->get().type, nullptr, 0, ce);
  1800. break;
  1801. }
  1802. }
  1803. object->set(p_path, to_create);
  1804. }
  1805. if (editor_property_map.has(p_path)) {
  1806. for (List<EditorProperty *>::Element *E = editor_property_map[p_path].front(); E; E = E->next()) {
  1807. E->get()->update_property();
  1808. E->get()->update_revert_and_pin_status();
  1809. }
  1810. }
  1811. } else {
  1812. emit_signal("property_toggled", p_path, p_checked);
  1813. }
  1814. }
  1815. void EditorInspector::_property_pinned(const String &p_path, bool p_pinned) {
  1816. if (!object) {
  1817. return;
  1818. }
  1819. Node *node = Object::cast_to<Node>(object);
  1820. ERR_FAIL_COND(!node);
  1821. if (undo_redo) {
  1822. undo_redo->create_action(vformat(p_pinned ? TTR("Pinned %s") : TTR("Unpinned %s"), p_path));
  1823. undo_redo->add_do_method(node, "_set_property_pinned", p_path, p_pinned);
  1824. undo_redo->add_undo_method(node, "_set_property_pinned", p_path, !p_pinned);
  1825. if (editor_property_map.has(p_path)) {
  1826. for (List<EditorProperty *>::Element *E = editor_property_map[p_path].front(); E; E = E->next()) {
  1827. undo_redo->add_do_method(E->get(), "_update_revert_and_pin_status");
  1828. undo_redo->add_undo_method(E->get(), "_update_revert_and_pin_status");
  1829. }
  1830. }
  1831. undo_redo->commit_action();
  1832. } else {
  1833. node->set_property_pinned(p_path, p_pinned);
  1834. if (editor_property_map.has(p_path)) {
  1835. for (List<EditorProperty *>::Element *E = editor_property_map[p_path].front(); E; E = E->next()) {
  1836. E->get()->update_revert_and_pin_status();
  1837. }
  1838. }
  1839. }
  1840. }
  1841. void EditorInspector::_property_selected(const String &p_path, int p_focusable) {
  1842. property_selected = p_path;
  1843. property_focusable = p_focusable;
  1844. //deselect the others
  1845. for (Map<StringName, List<EditorProperty *>>::Element *F = editor_property_map.front(); F; F = F->next()) {
  1846. if (F->key() == property_selected) {
  1847. continue;
  1848. }
  1849. for (List<EditorProperty *>::Element *E = F->get().front(); E; E = E->next()) {
  1850. if (E->get()->is_selected()) {
  1851. E->get()->deselect();
  1852. }
  1853. }
  1854. }
  1855. emit_signal("property_selected", p_path);
  1856. }
  1857. void EditorInspector::_object_id_selected(const String &p_path, ObjectID p_id) {
  1858. emit_signal("object_id_selected", p_id);
  1859. }
  1860. void EditorInspector::_resource_selected(const String &p_path, RES p_resource) {
  1861. emit_signal("resource_selected", p_resource, p_path);
  1862. }
  1863. void EditorInspector::_node_removed(Node *p_node) {
  1864. if (p_node == object) {
  1865. edit(nullptr);
  1866. }
  1867. }
  1868. void EditorInspector::_notification(int p_what) {
  1869. if (p_what == NOTIFICATION_READY) {
  1870. EditorFeatureProfileManager::get_singleton()->connect("current_feature_profile_changed", this, "_feature_profile_changed");
  1871. _update_inspector_bg();
  1872. }
  1873. if (p_what == NOTIFICATION_ENTER_TREE) {
  1874. if (!sub_inspector) {
  1875. get_tree()->connect("node_removed", this, "_node_removed");
  1876. }
  1877. }
  1878. if (p_what == NOTIFICATION_PREDELETE) {
  1879. edit(nullptr); //just in case
  1880. }
  1881. if (p_what == NOTIFICATION_EXIT_TREE) {
  1882. if (!sub_inspector) {
  1883. get_tree()->disconnect("node_removed", this, "_node_removed");
  1884. }
  1885. edit(nullptr);
  1886. }
  1887. if (p_what == NOTIFICATION_PROCESS) {
  1888. if (update_scroll_request >= 0) {
  1889. get_v_scrollbar()->call_deferred("set_value", update_scroll_request);
  1890. update_scroll_request = -1;
  1891. }
  1892. if (refresh_countdown > 0) {
  1893. refresh_countdown -= get_process_delta_time();
  1894. if (refresh_countdown <= 0) {
  1895. for (Map<StringName, List<EditorProperty *>>::Element *F = editor_property_map.front(); F; F = F->next()) {
  1896. for (List<EditorProperty *>::Element *E = F->get().front(); E; E = E->next()) {
  1897. E->get()->update_property();
  1898. E->get()->update_revert_and_pin_status();
  1899. }
  1900. }
  1901. }
  1902. }
  1903. changing++;
  1904. if (update_tree_pending) {
  1905. update_tree();
  1906. update_tree_pending = false;
  1907. pending.clear();
  1908. } else {
  1909. while (pending.size()) {
  1910. StringName prop = pending.front()->get();
  1911. if (editor_property_map.has(prop)) {
  1912. for (List<EditorProperty *>::Element *E = editor_property_map[prop].front(); E; E = E->next()) {
  1913. E->get()->update_property();
  1914. E->get()->update_revert_and_pin_status();
  1915. }
  1916. }
  1917. pending.erase(pending.front());
  1918. }
  1919. }
  1920. changing--;
  1921. }
  1922. if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) {
  1923. _update_inspector_bg();
  1924. update_tree();
  1925. }
  1926. }
  1927. void EditorInspector::_changed_callback(Object *p_changed, const char *p_prop) {
  1928. //this is called when property change is notified via _change_notify()
  1929. _edit_request_change(p_changed, p_prop);
  1930. }
  1931. void EditorInspector::_vscroll_changed(double p_offset) {
  1932. if (update_scroll_request >= 0) { //waiting, do nothing
  1933. return;
  1934. }
  1935. if (object) {
  1936. scroll_cache[object->get_instance_id()] = p_offset;
  1937. }
  1938. }
  1939. void EditorInspector::set_property_prefix(const String &p_prefix) {
  1940. property_prefix = p_prefix;
  1941. }
  1942. String EditorInspector::get_property_prefix() const {
  1943. return property_prefix;
  1944. }
  1945. void EditorInspector::set_object_class(const String &p_class) {
  1946. object_class = p_class;
  1947. }
  1948. String EditorInspector::get_object_class() const {
  1949. return object_class;
  1950. }
  1951. void EditorInspector::_feature_profile_changed() {
  1952. update_tree();
  1953. }
  1954. void EditorInspector::_bind_methods() {
  1955. ClassDB::bind_method("_property_changed", &EditorInspector::_property_changed, DEFVAL(""), DEFVAL(false));
  1956. ClassDB::bind_method("_multiple_properties_changed", &EditorInspector::_multiple_properties_changed);
  1957. ClassDB::bind_method("_property_changed_update_all", &EditorInspector::_property_changed_update_all);
  1958. ClassDB::bind_method("_edit_request_change", &EditorInspector::_edit_request_change);
  1959. ClassDB::bind_method("_node_removed", &EditorInspector::_node_removed);
  1960. ClassDB::bind_method("_filter_changed", &EditorInspector::_filter_changed);
  1961. ClassDB::bind_method("_property_keyed", &EditorInspector::_property_keyed);
  1962. ClassDB::bind_method("_property_keyed_with_value", &EditorInspector::_property_keyed_with_value);
  1963. ClassDB::bind_method("_property_checked", &EditorInspector::_property_checked);
  1964. ClassDB::bind_method(D_METHOD("_property_pinned", "path", "pinned"), &EditorInspector::_property_pinned);
  1965. ClassDB::bind_method("_property_selected", &EditorInspector::_property_selected);
  1966. ClassDB::bind_method("_resource_selected", &EditorInspector::_resource_selected);
  1967. ClassDB::bind_method("_object_id_selected", &EditorInspector::_object_id_selected);
  1968. ClassDB::bind_method("_vscroll_changed", &EditorInspector::_vscroll_changed);
  1969. ClassDB::bind_method("_feature_profile_changed", &EditorInspector::_feature_profile_changed);
  1970. ClassDB::bind_method("get_edited_object", &EditorInspector::get_edited_object);
  1971. ClassDB::bind_method("refresh", &EditorInspector::refresh);
  1972. ADD_SIGNAL(MethodInfo("property_selected", PropertyInfo(Variant::STRING, "property")));
  1973. ADD_SIGNAL(MethodInfo("property_keyed", PropertyInfo(Variant::STRING, "property")));
  1974. ADD_SIGNAL(MethodInfo("resource_selected", PropertyInfo(Variant::OBJECT, "res"), PropertyInfo(Variant::STRING, "prop")));
  1975. ADD_SIGNAL(MethodInfo("object_id_selected", PropertyInfo(Variant::INT, "id")));
  1976. ADD_SIGNAL(MethodInfo("property_edited", PropertyInfo(Variant::STRING, "property")));
  1977. ADD_SIGNAL(MethodInfo("property_toggled", PropertyInfo(Variant::STRING, "property"), PropertyInfo(Variant::BOOL, "checked")));
  1978. ADD_SIGNAL(MethodInfo("restart_requested"));
  1979. }
  1980. EditorInspector::EditorInspector() {
  1981. object = nullptr;
  1982. undo_redo = nullptr;
  1983. main_vbox = memnew(VBoxContainer);
  1984. main_vbox->set_h_size_flags(SIZE_EXPAND_FILL);
  1985. main_vbox->add_constant_override("separation", 0);
  1986. add_child(main_vbox);
  1987. set_enable_h_scroll(false);
  1988. set_enable_v_scroll(true);
  1989. show_categories = false;
  1990. hide_script = true;
  1991. use_doc_hints = false;
  1992. property_name_style = EditorPropertyNameProcessor::STYLE_CAPITALIZED;
  1993. use_filter = false;
  1994. autoclear = false;
  1995. changing = 0;
  1996. use_folding = false;
  1997. update_all_pending = false;
  1998. update_tree_pending = false;
  1999. refresh_countdown = 0;
  2000. read_only = false;
  2001. search_box = nullptr;
  2002. keying = false;
  2003. _prop_edited = "property_edited";
  2004. set_process(true);
  2005. property_focusable = -1;
  2006. sub_inspector = false;
  2007. property_clipboard = Variant();
  2008. get_v_scrollbar()->connect("value_changed", this, "_vscroll_changed");
  2009. update_scroll_request = -1;
  2010. ED_SHORTCUT("property_editor/copy_property", TTR("Copy Property"), KEY_MASK_CMD | KEY_C);
  2011. ED_SHORTCUT("property_editor/paste_property", TTR("Paste Property"), KEY_MASK_CMD | KEY_V);
  2012. ED_SHORTCUT("property_editor/copy_property_path", TTR("Copy Property Path"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_C);
  2013. }