project_settings_editor.cpp 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179
  1. /*************************************************************************/
  2. /* project_settings_editor.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 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 "project_settings_editor.h"
  31. #include "core/global_constants.h"
  32. #include "core/input/input_map.h"
  33. #include "core/os/keyboard.h"
  34. #include "core/project_settings.h"
  35. #include "core/translation.h"
  36. #include "editor/editor_export.h"
  37. #include "editor/editor_node.h"
  38. #include "editor/editor_scale.h"
  39. #include "scene/gui/margin_container.h"
  40. #include "scene/gui/tab_container.h"
  41. ProjectSettingsEditor *ProjectSettingsEditor::singleton = nullptr;
  42. static const char *_button_descriptions[JOY_SDL_BUTTONS] = {
  43. "Face Bottom, DualShock Cross, Xbox A, Nintendo B",
  44. "Face Right, DualShock Circle, Xbox B, Nintendo A",
  45. "Face Left, DualShock Square, Xbox X, Nintendo Y",
  46. "Face Top, DualShock Triangle, Xbox Y, Nintendo X",
  47. "DualShock Select, Xbox Back, Nintendo -",
  48. "Home, DualShock PS, Guide",
  49. "Start, Nintendo +",
  50. "Left Stick, DualShock L3, Xbox L/LS",
  51. "Right Stick, DualShock R3, Xbox R/RS",
  52. "Left Shoulder, DualShock L1, Xbox LB",
  53. "Right Shoulder, DualShock R1, Xbox RB",
  54. "D-Pad Up",
  55. "D-Pad Down",
  56. "D-Pad Left",
  57. "D-Pad Right"
  58. };
  59. static const char *_axis_descriptions[JOY_AXIS_MAX * 2] = {
  60. "Left Stick Left",
  61. "Left Stick Right",
  62. "Left Stick Up",
  63. "Left Stick Down",
  64. "Right Stick Left",
  65. "Right Stick Right",
  66. "Right Stick Up",
  67. "Right Stick Down",
  68. "Joystick 2 Left",
  69. "Joystick 2 Right, Left Trigger, L2, LT",
  70. "Joystick 2 Up",
  71. "Joystick 2 Down, Right Trigger, R2, RT",
  72. "Joystick 3 Left",
  73. "Joystick 3 Right",
  74. "Joystick 3 Up",
  75. "Joystick 3 Down",
  76. "Joystick 4 Left",
  77. "Joystick 4 Right",
  78. "Joystick 4 Up",
  79. "Joystick 4 Down",
  80. };
  81. void ProjectSettingsEditor::_unhandled_input(const Ref<InputEvent> &p_event) {
  82. const Ref<InputEventKey> k = p_event;
  83. if (k.is_valid() && k->is_pressed()) {
  84. if (k->get_keycode_with_modifiers() == (KEY_MASK_CMD | KEY_F)) {
  85. if (search_button->is_pressed()) {
  86. search_box->grab_focus();
  87. search_box->select_all();
  88. } else {
  89. // This toggles the search bar display while giving the button its "pressed" appearance
  90. search_button->set_pressed(true);
  91. }
  92. set_input_as_handled();
  93. }
  94. }
  95. }
  96. void ProjectSettingsEditor::_notification(int p_what) {
  97. switch (p_what) {
  98. case NOTIFICATION_VISIBILITY_CHANGED: {
  99. if (!is_visible()) {
  100. EditorSettings::get_singleton()->set_project_metadata("dialog_bounds", "project_settings", Rect2(get_position(), get_size()));
  101. set_process_unhandled_input(false);
  102. }
  103. } break;
  104. case NOTIFICATION_ENTER_TREE: {
  105. globals_editor->edit(ProjectSettings::get_singleton());
  106. search_button->set_icon(input_editor->get_theme_icon("Search", "EditorIcons"));
  107. search_box->set_right_icon(input_editor->get_theme_icon("Search", "EditorIcons"));
  108. search_box->set_clear_button_enabled(true);
  109. action_add_error->add_theme_color_override("font_color", input_editor->get_theme_color("error_color", "Editor"));
  110. translation_list->connect("button_pressed", callable_mp(this, &ProjectSettingsEditor::_translation_delete));
  111. _update_actions();
  112. popup_add->add_icon_item(input_editor->get_theme_icon("Keyboard", "EditorIcons"), TTR("Key"), INPUT_KEY);
  113. popup_add->add_icon_item(input_editor->get_theme_icon("KeyboardPhysical", "EditorIcons"), TTR("Physical Key"), INPUT_KEY_PHYSICAL);
  114. popup_add->add_icon_item(input_editor->get_theme_icon("JoyButton", "EditorIcons"), TTR("Joy Button"), INPUT_JOY_BUTTON);
  115. popup_add->add_icon_item(input_editor->get_theme_icon("JoyAxis", "EditorIcons"), TTR("Joy Axis"), INPUT_JOY_MOTION);
  116. popup_add->add_icon_item(input_editor->get_theme_icon("Mouse", "EditorIcons"), TTR("Mouse Button"), INPUT_MOUSE_BUTTON);
  117. List<String> tfn;
  118. ResourceLoader::get_recognized_extensions_for_type("Translation", &tfn);
  119. for (List<String>::Element *E = tfn.front(); E; E = E->next()) {
  120. translation_file_open->add_filter("*." + E->get());
  121. }
  122. List<String> rfn;
  123. ResourceLoader::get_recognized_extensions_for_type("Resource", &rfn);
  124. for (List<String>::Element *E = rfn.front(); E; E = E->next()) {
  125. translation_res_file_open->add_filter("*." + E->get());
  126. translation_res_option_file_open->add_filter("*." + E->get());
  127. }
  128. restart_close_button->set_icon(input_editor->get_theme_icon("Close", "EditorIcons"));
  129. restart_container->add_theme_style_override("panel", input_editor->get_theme_stylebox("bg", "Tree"));
  130. restart_icon->set_texture(input_editor->get_theme_icon("StatusWarning", "EditorIcons"));
  131. restart_label->add_theme_color_override("font_color", input_editor->get_theme_color("warning_color", "Editor"));
  132. } break;
  133. case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
  134. search_button->set_icon(input_editor->get_theme_icon("Search", "EditorIcons"));
  135. search_box->set_right_icon(input_editor->get_theme_icon("Search", "EditorIcons"));
  136. search_box->set_clear_button_enabled(true);
  137. action_add_error->add_theme_color_override("font_color", input_editor->get_theme_color("error_color", "Editor"));
  138. popup_add->set_item_icon(popup_add->get_item_index(INPUT_KEY), input_editor->get_theme_icon("Keyboard", "EditorIcons"));
  139. popup_add->set_item_icon(popup_add->get_item_index(INPUT_KEY_PHYSICAL), input_editor->get_theme_icon("KeyboardPhysical", "EditorIcons"));
  140. popup_add->set_item_icon(popup_add->get_item_index(INPUT_JOY_BUTTON), input_editor->get_theme_icon("JoyButton", "EditorIcons"));
  141. popup_add->set_item_icon(popup_add->get_item_index(INPUT_JOY_MOTION), input_editor->get_theme_icon("JoyAxis", "EditorIcons"));
  142. popup_add->set_item_icon(popup_add->get_item_index(INPUT_MOUSE_BUTTON), input_editor->get_theme_icon("Mouse", "EditorIcons"));
  143. _update_actions();
  144. } break;
  145. }
  146. }
  147. static bool _validate_action_name(const String &p_name) {
  148. const CharType *cstr = p_name.c_str();
  149. for (int i = 0; cstr[i]; i++)
  150. if (cstr[i] == '/' || cstr[i] == ':' || cstr[i] == '"' ||
  151. cstr[i] == '=' || cstr[i] == '\\' || cstr[i] < 32)
  152. return false;
  153. return true;
  154. }
  155. void ProjectSettingsEditor::_action_selected() {
  156. TreeItem *ti = input_editor->get_selected();
  157. if (!ti || !ti->is_editable(0))
  158. return;
  159. add_at = "input/" + ti->get_text(0);
  160. edit_idx = -1;
  161. }
  162. void ProjectSettingsEditor::_action_edited() {
  163. TreeItem *ti = input_editor->get_selected();
  164. if (!ti)
  165. return;
  166. if (input_editor->get_selected_column() == 0) {
  167. String new_name = ti->get_text(0);
  168. String old_name = add_at.substr(add_at.find("/") + 1, add_at.length());
  169. if (new_name == old_name)
  170. return;
  171. if (new_name == "" || !_validate_action_name(new_name)) {
  172. ti->set_text(0, old_name);
  173. add_at = "input/" + old_name;
  174. message->set_text(TTR("Invalid action name. it cannot be empty nor contain '/', ':', '=', '\\' or '\"'"));
  175. message->popup_centered(Size2(300, 100) * EDSCALE);
  176. return;
  177. }
  178. String action_prop = "input/" + new_name;
  179. if (ProjectSettings::get_singleton()->has_setting(action_prop)) {
  180. ti->set_text(0, old_name);
  181. add_at = "input/" + old_name;
  182. message->set_text(vformat(TTR("An action with the name '%s' already exists."), new_name));
  183. message->popup_centered(Size2(300, 100) * EDSCALE);
  184. return;
  185. }
  186. int order = ProjectSettings::get_singleton()->get_order(add_at);
  187. Dictionary action = ProjectSettings::get_singleton()->get(add_at);
  188. setting = true;
  189. undo_redo->create_action(TTR("Rename Input Action Event"));
  190. undo_redo->add_do_method(ProjectSettings::get_singleton(), "clear", add_at);
  191. undo_redo->add_do_method(ProjectSettings::get_singleton(), "set", action_prop, action);
  192. undo_redo->add_do_method(ProjectSettings::get_singleton(), "set_order", action_prop, order);
  193. undo_redo->add_undo_method(ProjectSettings::get_singleton(), "clear", action_prop);
  194. undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set", add_at, action);
  195. undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set_order", add_at, order);
  196. undo_redo->add_do_method(this, "_update_actions");
  197. undo_redo->add_undo_method(this, "_update_actions");
  198. undo_redo->add_do_method(this, "_settings_changed");
  199. undo_redo->add_undo_method(this, "_settings_changed");
  200. undo_redo->commit_action();
  201. setting = false;
  202. add_at = action_prop;
  203. } else if (input_editor->get_selected_column() == 1) {
  204. String name = "input/" + ti->get_text(0);
  205. Dictionary old_action = ProjectSettings::get_singleton()->get(name);
  206. Dictionary new_action = old_action.duplicate();
  207. new_action["deadzone"] = ti->get_range(1);
  208. undo_redo->create_action(TTR("Change Action deadzone"));
  209. undo_redo->add_do_method(ProjectSettings::get_singleton(), "set", name, new_action);
  210. undo_redo->add_do_method(this, "_settings_changed");
  211. undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set", name, old_action);
  212. undo_redo->add_undo_method(this, "_settings_changed");
  213. undo_redo->commit_action();
  214. }
  215. }
  216. void ProjectSettingsEditor::_device_input_add() {
  217. Ref<InputEvent> ie;
  218. String name = add_at;
  219. int idx = edit_idx;
  220. Dictionary old_val = ProjectSettings::get_singleton()->get(name);
  221. Dictionary action = old_val.duplicate();
  222. Array events = action["events"];
  223. switch (add_type) {
  224. case INPUT_MOUSE_BUTTON: {
  225. Ref<InputEventMouseButton> mb;
  226. mb.instance();
  227. mb->set_button_index(device_index->get_selected() + 1);
  228. mb->set_device(_get_current_device());
  229. for (int i = 0; i < events.size(); i++) {
  230. Ref<InputEventMouseButton> aie = events[i];
  231. if (aie.is_null())
  232. continue;
  233. if (aie->get_device() == mb->get_device() && aie->get_button_index() == mb->get_button_index()) {
  234. return;
  235. }
  236. }
  237. ie = mb;
  238. } break;
  239. case INPUT_JOY_MOTION: {
  240. Ref<InputEventJoypadMotion> jm;
  241. jm.instance();
  242. jm->set_axis(device_index->get_selected() >> 1);
  243. jm->set_axis_value((device_index->get_selected() & 1) ? 1 : -1);
  244. jm->set_device(_get_current_device());
  245. for (int i = 0; i < events.size(); i++) {
  246. Ref<InputEventJoypadMotion> aie = events[i];
  247. if (aie.is_null())
  248. continue;
  249. if (aie->get_device() == jm->get_device() && aie->get_axis() == jm->get_axis() && aie->get_axis_value() == jm->get_axis_value()) {
  250. return;
  251. }
  252. }
  253. ie = jm;
  254. } break;
  255. case INPUT_JOY_BUTTON: {
  256. Ref<InputEventJoypadButton> jb;
  257. jb.instance();
  258. jb->set_button_index(device_index->get_selected());
  259. jb->set_device(_get_current_device());
  260. for (int i = 0; i < events.size(); i++) {
  261. Ref<InputEventJoypadButton> aie = events[i];
  262. if (aie.is_null())
  263. continue;
  264. if (aie->get_device() == jb->get_device() && aie->get_button_index() == jb->get_button_index()) {
  265. return;
  266. }
  267. }
  268. ie = jb;
  269. } break;
  270. default: {
  271. }
  272. }
  273. if (idx < 0 || idx >= events.size()) {
  274. events.push_back(ie);
  275. } else {
  276. events[idx] = ie;
  277. }
  278. action["events"] = events;
  279. undo_redo->create_action(TTR("Add Input Action Event"));
  280. undo_redo->add_do_method(ProjectSettings::get_singleton(), "set", name, action);
  281. undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set", name, old_val);
  282. undo_redo->add_do_method(this, "_update_actions");
  283. undo_redo->add_undo_method(this, "_update_actions");
  284. undo_redo->add_do_method(this, "_settings_changed");
  285. undo_redo->add_undo_method(this, "_settings_changed");
  286. undo_redo->commit_action();
  287. _show_last_added(ie, name);
  288. }
  289. void ProjectSettingsEditor::_set_current_device(int i_device) {
  290. device_id->select(i_device + 1);
  291. }
  292. int ProjectSettingsEditor::_get_current_device() {
  293. return device_id->get_selected() - 1;
  294. }
  295. String ProjectSettingsEditor::_get_device_string(int i_device) {
  296. if (i_device == InputMap::ALL_DEVICES)
  297. return TTR("All Devices");
  298. return TTR("Device") + " " + itos(i_device);
  299. }
  300. void ProjectSettingsEditor::_press_a_key_confirm() {
  301. if (last_wait_for_key.is_null())
  302. return;
  303. Ref<InputEventKey> ie;
  304. ie.instance();
  305. if (press_a_key_physical) {
  306. ie->set_physical_keycode(last_wait_for_key->get_physical_keycode());
  307. ie->set_keycode(0);
  308. } else {
  309. ie->set_physical_keycode(0);
  310. ie->set_keycode(last_wait_for_key->get_keycode());
  311. }
  312. ie->set_shift(last_wait_for_key->get_shift());
  313. ie->set_alt(last_wait_for_key->get_alt());
  314. ie->set_control(last_wait_for_key->get_control());
  315. ie->set_metakey(last_wait_for_key->get_metakey());
  316. String name = add_at;
  317. int idx = edit_idx;
  318. Dictionary old_val = ProjectSettings::get_singleton()->get(name);
  319. Dictionary action = old_val.duplicate();
  320. Array events = action["events"];
  321. for (int i = 0; i < events.size(); i++) {
  322. Ref<InputEventKey> aie = events[i];
  323. if (aie.is_null())
  324. continue;
  325. if (!press_a_key_physical) {
  326. if (aie->get_keycode_with_modifiers() == ie->get_keycode_with_modifiers()) {
  327. return;
  328. }
  329. } else {
  330. if (aie->get_physical_keycode_with_modifiers() == ie->get_physical_keycode_with_modifiers()) {
  331. return;
  332. }
  333. }
  334. }
  335. if (idx < 0 || idx >= events.size()) {
  336. events.push_back(ie);
  337. } else {
  338. events[idx] = ie;
  339. }
  340. action["events"] = events;
  341. undo_redo->create_action(TTR("Add Input Action Event"));
  342. undo_redo->add_do_method(ProjectSettings::get_singleton(), "set", name, action);
  343. undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set", name, old_val);
  344. undo_redo->add_do_method(this, "_update_actions");
  345. undo_redo->add_undo_method(this, "_update_actions");
  346. undo_redo->add_do_method(this, "_settings_changed");
  347. undo_redo->add_undo_method(this, "_settings_changed");
  348. undo_redo->commit_action();
  349. _show_last_added(ie, name);
  350. }
  351. void ProjectSettingsEditor::_show_last_added(const Ref<InputEvent> &p_event, const String &p_name) {
  352. TreeItem *r = input_editor->get_root();
  353. String name = p_name;
  354. name.erase(0, 6);
  355. if (!r)
  356. return;
  357. r = r->get_children();
  358. if (!r)
  359. return;
  360. bool found = false;
  361. while (r) {
  362. if (r->get_text(0) != name) {
  363. r = r->get_next();
  364. continue;
  365. }
  366. TreeItem *child = r->get_children();
  367. while (child) {
  368. Variant input = child->get_meta("__input");
  369. if (p_event == input) {
  370. r->set_collapsed(false);
  371. child->select(0);
  372. found = true;
  373. break;
  374. }
  375. child = child->get_next();
  376. }
  377. if (found)
  378. break;
  379. r = r->get_next();
  380. }
  381. if (found)
  382. input_editor->ensure_cursor_is_visible();
  383. }
  384. void ProjectSettingsEditor::_wait_for_key(const Ref<InputEvent> &p_event) {
  385. Ref<InputEventKey> k = p_event;
  386. if (k.is_valid() && k->is_pressed() && k->get_keycode() != 0) {
  387. last_wait_for_key = p_event;
  388. const String str = (press_a_key_physical) ? keycode_get_string(k->get_physical_keycode_with_modifiers()) + TTR(" (Physical)") : keycode_get_string(k->get_keycode_with_modifiers());
  389. press_a_key_label->set_text(str);
  390. press_a_key->get_ok()->set_disabled(false);
  391. press_a_key->set_input_as_handled();
  392. }
  393. }
  394. void ProjectSettingsEditor::_add_item(int p_item, Ref<InputEvent> p_exiting_event) {
  395. add_type = InputType(p_item);
  396. switch (add_type) {
  397. case INPUT_KEY: {
  398. press_a_key_physical = false;
  399. press_a_key_label->set_text(TTR("Press a Key..."));
  400. press_a_key->get_ok()->set_disabled(true);
  401. last_wait_for_key = Ref<InputEvent>();
  402. press_a_key->popup_centered(Size2(250, 80) * EDSCALE);
  403. //press_a_key->grab_focus();
  404. } break;
  405. case INPUT_KEY_PHYSICAL: {
  406. press_a_key_physical = true;
  407. press_a_key_label->set_text(TTR("Press a Key..."));
  408. last_wait_for_key = Ref<InputEvent>();
  409. press_a_key->popup_centered(Size2(250, 80) * EDSCALE);
  410. press_a_key->grab_focus();
  411. } break;
  412. case INPUT_MOUSE_BUTTON: {
  413. device_index_label->set_text(TTR("Mouse Button Index:"));
  414. device_index->clear();
  415. device_index->add_item(TTR("Left Button"));
  416. device_index->add_item(TTR("Right Button"));
  417. device_index->add_item(TTR("Middle Button"));
  418. device_index->add_item(TTR("Wheel Up Button"));
  419. device_index->add_item(TTR("Wheel Down Button"));
  420. device_index->add_item(TTR("Wheel Left Button"));
  421. device_index->add_item(TTR("Wheel Right Button"));
  422. device_index->add_item(TTR("X Button 1"));
  423. device_index->add_item(TTR("X Button 2"));
  424. device_input->popup_centered(Size2(350, 95) * EDSCALE);
  425. Ref<InputEventMouseButton> mb = p_exiting_event;
  426. if (mb.is_valid()) {
  427. device_index->select(mb->get_button_index() - 1);
  428. _set_current_device(mb->get_device());
  429. device_input->get_ok()->set_text(TTR("Change"));
  430. } else {
  431. _set_current_device(0);
  432. device_input->get_ok()->set_text(TTR("Add"));
  433. }
  434. } break;
  435. case INPUT_JOY_MOTION: {
  436. device_index_label->set_text(TTR("Joypad Axis Index:"));
  437. device_index->clear();
  438. for (int i = 0; i < JOY_AXIS_MAX * 2; i++) {
  439. String desc = TTR("Axis") + " " + itos(i / 2) + " " + ((i & 1) ? "+" : "-") +
  440. " (" + TTR(_axis_descriptions[i]) + ")";
  441. device_index->add_item(desc);
  442. }
  443. device_input->popup_centered(Size2(350, 95) * EDSCALE);
  444. Ref<InputEventJoypadMotion> jm = p_exiting_event;
  445. if (jm.is_valid()) {
  446. device_index->select(jm->get_axis() * 2 + (jm->get_axis_value() > 0 ? 1 : 0));
  447. _set_current_device(jm->get_device());
  448. device_input->get_ok()->set_text(TTR("Change"));
  449. } else {
  450. _set_current_device(0);
  451. device_input->get_ok()->set_text(TTR("Add"));
  452. }
  453. } break;
  454. case INPUT_JOY_BUTTON: {
  455. device_index_label->set_text(TTR("Joypad Button Index:"));
  456. device_index->clear();
  457. for (int i = 0; i < JOY_BUTTON_MAX; i++) {
  458. String desc = TTR("Button") + " " + itos(i);
  459. if (i < JOY_SDL_BUTTONS)
  460. desc += " (" + TTR(_button_descriptions[i]) + ")";
  461. device_index->add_item(desc);
  462. }
  463. device_input->popup_centered(Size2(350, 95) * EDSCALE);
  464. Ref<InputEventJoypadButton> jb = p_exiting_event;
  465. if (jb.is_valid()) {
  466. device_index->select(jb->get_button_index());
  467. _set_current_device(jb->get_device());
  468. device_input->get_ok()->set_text(TTR("Change"));
  469. } else {
  470. _set_current_device(0);
  471. device_input->get_ok()->set_text(TTR("Add"));
  472. }
  473. } break;
  474. default: {
  475. }
  476. }
  477. }
  478. void ProjectSettingsEditor::_edit_item(Ref<InputEvent> p_exiting_event) {
  479. InputType ie_type;
  480. if ((Ref<InputEventKey>(p_exiting_event)).is_valid()) {
  481. if ((Ref<InputEventKey>(p_exiting_event))->get_keycode() != 0) {
  482. ie_type = INPUT_KEY;
  483. } else {
  484. ie_type = INPUT_KEY_PHYSICAL;
  485. }
  486. } else if ((Ref<InputEventJoypadButton>(p_exiting_event)).is_valid()) {
  487. ie_type = INPUT_JOY_BUTTON;
  488. } else if ((Ref<InputEventMouseButton>(p_exiting_event)).is_valid()) {
  489. ie_type = INPUT_MOUSE_BUTTON;
  490. } else if ((Ref<InputEventJoypadMotion>(p_exiting_event)).is_valid()) {
  491. ie_type = INPUT_JOY_MOTION;
  492. } else {
  493. return;
  494. }
  495. _add_item(ie_type, p_exiting_event);
  496. }
  497. void ProjectSettingsEditor::_action_activated() {
  498. TreeItem *ti = input_editor->get_selected();
  499. if (!ti || ti->get_parent() == input_editor->get_root())
  500. return;
  501. String name = "input/" + ti->get_parent()->get_text(0);
  502. int idx = ti->get_metadata(0);
  503. Dictionary action = ProjectSettings::get_singleton()->get(name);
  504. Array events = action["events"];
  505. ERR_FAIL_INDEX(idx, events.size());
  506. Ref<InputEvent> event = events[idx];
  507. if (event.is_null())
  508. return;
  509. add_at = name;
  510. edit_idx = idx;
  511. _edit_item(event);
  512. }
  513. void ProjectSettingsEditor::_action_button_pressed(Object *p_obj, int p_column, int p_id) {
  514. TreeItem *ti = Object::cast_to<TreeItem>(p_obj);
  515. ERR_FAIL_COND(!ti);
  516. if (p_id == 1) {
  517. // Add action event
  518. Point2 ofs = input_editor->get_global_position();
  519. Rect2 ir = input_editor->get_item_rect(ti);
  520. ir.position.y -= input_editor->get_scroll().y;
  521. ofs += ir.position + ir.size;
  522. ofs.x -= 100;
  523. popup_add->set_position(ofs);
  524. popup_add->popup();
  525. add_at = "input/" + ti->get_text(0);
  526. edit_idx = -1;
  527. } else if (p_id == 2) {
  528. // Remove
  529. if (ti->get_parent() == input_editor->get_root()) {
  530. // Remove action
  531. String name = "input/" + ti->get_text(0);
  532. Dictionary old_val = ProjectSettings::get_singleton()->get(name);
  533. int order = ProjectSettings::get_singleton()->get_order(name);
  534. undo_redo->create_action(TTR("Erase Input Action"));
  535. undo_redo->add_do_method(ProjectSettings::get_singleton(), "clear", name);
  536. undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set", name, old_val);
  537. undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set_order", name, order);
  538. undo_redo->add_do_method(this, "_update_actions");
  539. undo_redo->add_undo_method(this, "_update_actions");
  540. undo_redo->add_do_method(this, "_settings_changed");
  541. undo_redo->add_undo_method(this, "_settings_changed");
  542. undo_redo->commit_action();
  543. } else {
  544. // Remove action event
  545. String name = "input/" + ti->get_parent()->get_text(0);
  546. Dictionary old_val = ProjectSettings::get_singleton()->get(name);
  547. Dictionary action = old_val.duplicate();
  548. int idx = ti->get_metadata(0);
  549. Array events = action["events"];
  550. ERR_FAIL_INDEX(idx, events.size());
  551. events.remove(idx);
  552. action["events"] = events;
  553. undo_redo->create_action(TTR("Erase Input Action Event"));
  554. undo_redo->add_do_method(ProjectSettings::get_singleton(), "set", name, action);
  555. undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set", name, old_val);
  556. undo_redo->add_do_method(this, "_update_actions");
  557. undo_redo->add_undo_method(this, "_update_actions");
  558. undo_redo->add_do_method(this, "_settings_changed");
  559. undo_redo->add_undo_method(this, "_settings_changed");
  560. undo_redo->commit_action();
  561. }
  562. } else if (p_id == 3) {
  563. // Edit
  564. if (ti->get_parent() == input_editor->get_root()) {
  565. // Edit action name
  566. ti->set_as_cursor(0);
  567. input_editor->edit_selected();
  568. } else {
  569. // Edit action event
  570. String name = "input/" + ti->get_parent()->get_text(0);
  571. int idx = ti->get_metadata(0);
  572. Dictionary action = ProjectSettings::get_singleton()->get(name);
  573. Array events = action["events"];
  574. ERR_FAIL_INDEX(idx, events.size());
  575. Ref<InputEvent> event = events[idx];
  576. if (event.is_null())
  577. return;
  578. ti->set_as_cursor(0);
  579. add_at = name;
  580. edit_idx = idx;
  581. _edit_item(event);
  582. }
  583. }
  584. }
  585. void ProjectSettingsEditor::_update_actions() {
  586. if (setting)
  587. return;
  588. Map<String, bool> collapsed;
  589. if (input_editor->get_root() && input_editor->get_root()->get_children()) {
  590. for (TreeItem *item = input_editor->get_root()->get_children(); item; item = item->get_next()) {
  591. collapsed[item->get_text(0)] = item->is_collapsed();
  592. }
  593. }
  594. input_editor->clear();
  595. TreeItem *root = input_editor->create_item();
  596. input_editor->set_hide_root(true);
  597. List<PropertyInfo> props;
  598. ProjectSettings::get_singleton()->get_property_list(&props);
  599. for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
  600. const PropertyInfo &pi = E->get();
  601. if (!pi.name.begins_with("input/"))
  602. continue;
  603. String name = pi.name.get_slice("/", 1);
  604. if (name == "")
  605. continue;
  606. Dictionary action = ProjectSettings::get_singleton()->get(pi.name);
  607. Array events = action["events"];
  608. TreeItem *item = input_editor->create_item(root);
  609. item->set_text(0, name);
  610. item->set_custom_bg_color(0, input_editor->get_theme_color("prop_subsection", "Editor"));
  611. if (collapsed.has(name))
  612. item->set_collapsed(collapsed[name]);
  613. item->set_editable(1, true);
  614. item->set_cell_mode(1, TreeItem::CELL_MODE_RANGE);
  615. item->set_range_config(1, 0.0, 1.0, 0.01);
  616. item->set_range(1, action["deadzone"]);
  617. item->set_custom_bg_color(1, input_editor->get_theme_color("prop_subsection", "Editor"));
  618. const bool is_builtin_input = ProjectSettings::get_singleton()->get_input_presets().find(pi.name) != nullptr;
  619. const String tooltip = is_builtin_input ? TTR("Built-in actions can't be removed as they're used for UI navigation.") : TTR("Remove");
  620. item->add_button(2, input_editor->get_theme_icon("Add", "EditorIcons"), 1, false, TTR("Add Event"));
  621. item->add_button(2, input_editor->get_theme_icon("Remove", "EditorIcons"), 2, false, tooltip);
  622. if (is_builtin_input) {
  623. // Built-in action (like `ui_up`). Make the action not removable,
  624. // but still display the button so the "Add" button is at the same
  625. // horizontal position as for custom actions.
  626. item->set_button_disabled(2, 1, true);
  627. } else {
  628. // Not a built-in action. Make the action name editable.
  629. item->set_editable(0, true);
  630. }
  631. for (int i = 0; i < events.size(); i++) {
  632. Ref<InputEvent> event = events[i];
  633. if (event.is_null())
  634. continue;
  635. TreeItem *action2 = input_editor->create_item(item);
  636. Ref<InputEventKey> k = event;
  637. if (k.is_valid()) {
  638. const String str = (k->get_keycode() == 0) ? keycode_get_string(k->get_physical_keycode_with_modifiers()) + TTR(" (Physical)") : keycode_get_string(k->get_keycode_with_modifiers());
  639. action2->set_text(0, str);
  640. if ((k->get_keycode() != 0)) {
  641. action2->set_icon(0, input_editor->get_theme_icon("Keyboard", "EditorIcons"));
  642. } else {
  643. action2->set_icon(0, input_editor->get_theme_icon("KeyboardPhysical", "EditorIcons"));
  644. }
  645. }
  646. Ref<InputEventJoypadButton> jb = event;
  647. if (jb.is_valid()) {
  648. String str = _get_device_string(jb->get_device()) + ", " +
  649. TTR("Button") + " " + itos(jb->get_button_index());
  650. if (jb->get_button_index() >= 0 && jb->get_button_index() < JOY_SDL_BUTTONS) {
  651. str += String() + " (" + TTR(_button_descriptions[jb->get_button_index()]) + ")";
  652. }
  653. action2->set_text(0, str);
  654. action2->set_icon(0, input_editor->get_theme_icon("JoyButton", "EditorIcons"));
  655. }
  656. Ref<InputEventMouseButton> mb = event;
  657. if (mb.is_valid()) {
  658. String str = _get_device_string(mb->get_device()) + ", ";
  659. switch (mb->get_button_index()) {
  660. case BUTTON_LEFT:
  661. str += TTR("Left Button");
  662. break;
  663. case BUTTON_RIGHT:
  664. str += TTR("Right Button");
  665. break;
  666. case BUTTON_MIDDLE:
  667. str += TTR("Middle Button");
  668. break;
  669. case BUTTON_WHEEL_UP:
  670. str += TTR("Wheel Up");
  671. break;
  672. case BUTTON_WHEEL_DOWN:
  673. str += TTR("Wheel Down");
  674. break;
  675. default:
  676. str += vformat(TTR("%d Button"), mb->get_button_index());
  677. }
  678. action2->set_text(0, str);
  679. action2->set_icon(0, input_editor->get_theme_icon("Mouse", "EditorIcons"));
  680. }
  681. Ref<InputEventJoypadMotion> jm = event;
  682. if (jm.is_valid()) {
  683. int ax = jm->get_axis();
  684. int n = 2 * ax + (jm->get_axis_value() < 0 ? 0 : 1);
  685. String str = _get_device_string(jm->get_device()) + ", " +
  686. TTR("Axis") + " " + itos(ax) + " " + (jm->get_axis_value() < 0 ? "-" : "+") +
  687. " (" + _axis_descriptions[n] + ")";
  688. action2->set_text(0, str);
  689. action2->set_icon(0, input_editor->get_theme_icon("JoyAxis", "EditorIcons"));
  690. }
  691. action2->set_metadata(0, i);
  692. action2->set_meta("__input", event);
  693. action2->add_button(2, input_editor->get_theme_icon("Edit", "EditorIcons"), 3, false, TTR("Edit"));
  694. action2->add_button(2, input_editor->get_theme_icon("Remove", "EditorIcons"), 2, false, TTR("Remove"));
  695. // Fade out the individual event buttons slightly to make the
  696. // Add/Remove buttons stand out more.
  697. action2->set_button_color(2, 0, Color(1, 1, 1, 0.75));
  698. action2->set_button_color(2, 1, Color(1, 1, 1, 0.75));
  699. }
  700. }
  701. _action_check(action_name->get_text());
  702. }
  703. void ProjectSettingsEditor::popup_project_settings() {
  704. // Restore valid window bounds or pop up at default size.
  705. Rect2 saved_size = EditorSettings::get_singleton()->get_project_metadata("dialog_bounds", "project_settings", Rect2());
  706. if (saved_size != Rect2()) {
  707. popup(saved_size);
  708. } else {
  709. popup_centered_clamped(Size2(900, 700) * EDSCALE, 0.8);
  710. }
  711. globals_editor->update_category_list();
  712. _update_translations();
  713. autoload_settings->update_autoload();
  714. plugin_settings->update_plugins();
  715. set_process_unhandled_input(true);
  716. }
  717. void ProjectSettingsEditor::update_plugins() {
  718. plugin_settings->update_plugins();
  719. }
  720. void ProjectSettingsEditor::_item_selected(const String &p_path) {
  721. const String &selected_path = p_path;
  722. if (selected_path == String())
  723. return;
  724. category->set_text(globals_editor->get_current_section());
  725. property->set_text(selected_path);
  726. popup_copy_to_feature->set_disabled(false);
  727. }
  728. void ProjectSettingsEditor::_item_adds(String) {
  729. _item_add();
  730. }
  731. void ProjectSettingsEditor::_item_add() {
  732. // Initialize the property with the default value for the given type.
  733. // The type list starts at 1 (as we exclude Nil), so add 1 to the selected value.
  734. Callable::CallError ce;
  735. const Variant value = Variant::construct(Variant::Type(type->get_selected() + 1), nullptr, 0, ce);
  736. String catname = category->get_text().strip_edges();
  737. String propname = property->get_text().strip_edges();
  738. if (propname.empty()) {
  739. return;
  740. }
  741. if (catname.empty()) {
  742. catname = "global";
  743. }
  744. String name = catname + "/" + propname;
  745. undo_redo->create_action(TTR("Add Global Property"));
  746. undo_redo->add_do_property(ProjectSettings::get_singleton(), name, value);
  747. if (ProjectSettings::get_singleton()->has_setting(name)) {
  748. undo_redo->add_undo_property(ProjectSettings::get_singleton(), name, ProjectSettings::get_singleton()->get(name));
  749. } else {
  750. undo_redo->add_undo_property(ProjectSettings::get_singleton(), name, Variant());
  751. }
  752. undo_redo->add_do_method(globals_editor, "update_category_list");
  753. undo_redo->add_undo_method(globals_editor, "update_category_list");
  754. undo_redo->add_do_method(this, "_settings_changed");
  755. undo_redo->add_undo_method(this, "_settings_changed");
  756. undo_redo->commit_action();
  757. globals_editor->set_current_section(catname);
  758. _settings_changed();
  759. }
  760. void ProjectSettingsEditor::_item_del() {
  761. String path = globals_editor->get_inspector()->get_selected_path();
  762. if (path == String()) {
  763. EditorNode::get_singleton()->show_warning(TTR("Select a setting item first!"));
  764. return;
  765. }
  766. String property = globals_editor->get_current_section().plus_file(path);
  767. if (!ProjectSettings::get_singleton()->has_setting(property)) {
  768. EditorNode::get_singleton()->show_warning(vformat(TTR("No property '%s' exists."), property));
  769. return;
  770. }
  771. if (ProjectSettings::get_singleton()->get_order(property) < ProjectSettings::NO_BUILTIN_ORDER_BASE) {
  772. EditorNode::get_singleton()->show_warning(vformat(TTR("Setting '%s' is internal, and it can't be deleted."), property));
  773. return;
  774. }
  775. undo_redo->create_action(TTR("Delete Item"));
  776. Variant value = ProjectSettings::get_singleton()->get(property);
  777. int order = ProjectSettings::get_singleton()->get_order(property);
  778. undo_redo->add_do_method(ProjectSettings::get_singleton(), "clear", property);
  779. undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set", property, value);
  780. undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set_order", property, order);
  781. undo_redo->add_do_method(globals_editor, "update_category_list");
  782. undo_redo->add_undo_method(globals_editor, "update_category_list");
  783. undo_redo->add_do_method(this, "_settings_changed");
  784. undo_redo->add_undo_method(this, "_settings_changed");
  785. undo_redo->commit_action();
  786. }
  787. void ProjectSettingsEditor::_action_check(String p_action) {
  788. if (p_action == "") {
  789. action_add->set_disabled(true);
  790. } else {
  791. if (!_validate_action_name(p_action)) {
  792. action_add_error->set_text(TTR("Invalid action name. It cannot be empty nor contain '/', ':', '=', '\\' or '\"'."));
  793. action_add_error->show();
  794. action_add->set_disabled(true);
  795. return;
  796. }
  797. if (ProjectSettings::get_singleton()->has_setting("input/" + p_action)) {
  798. action_add_error->set_text(vformat(TTR("An action with the name '%s' already exists."), p_action));
  799. action_add_error->show();
  800. action_add->set_disabled(true);
  801. return;
  802. }
  803. action_add->set_disabled(false);
  804. }
  805. action_add_error->hide();
  806. }
  807. void ProjectSettingsEditor::_action_adds(String) {
  808. if (!action_add->is_disabled()) {
  809. _action_add();
  810. }
  811. }
  812. void ProjectSettingsEditor::_action_add() {
  813. Dictionary action;
  814. action["events"] = Array();
  815. action["deadzone"] = 0.5f;
  816. String name = "input/" + action_name->get_text();
  817. undo_redo->create_action(TTR("Add Input Action"));
  818. undo_redo->add_do_method(ProjectSettings::get_singleton(), "set", name, action);
  819. undo_redo->add_undo_method(ProjectSettings::get_singleton(), "clear", name);
  820. undo_redo->add_do_method(this, "_update_actions");
  821. undo_redo->add_undo_method(this, "_update_actions");
  822. undo_redo->add_do_method(this, "_settings_changed");
  823. undo_redo->add_undo_method(this, "_settings_changed");
  824. undo_redo->commit_action();
  825. TreeItem *r = input_editor->get_root();
  826. if (!r)
  827. return;
  828. r = r->get_children();
  829. if (!r)
  830. return;
  831. while (r->get_next())
  832. r = r->get_next();
  833. r->select(0);
  834. input_editor->ensure_cursor_is_visible();
  835. action_add_error->hide();
  836. action_name->clear();
  837. }
  838. void ProjectSettingsEditor::_item_checked(const String &p_item, bool p_check) {
  839. }
  840. void ProjectSettingsEditor::_save() {
  841. Error err = ProjectSettings::get_singleton()->save();
  842. message->set_text(err != OK ? TTR("Error saving settings.") : TTR("Settings saved OK."));
  843. message->popup_centered(Size2(300, 100) * EDSCALE);
  844. }
  845. void ProjectSettingsEditor::_settings_prop_edited(const String &p_name) {
  846. // Method needed to discard the mandatory argument of the property_edited signal
  847. _settings_changed();
  848. }
  849. void ProjectSettingsEditor::_settings_changed() {
  850. timer->start();
  851. }
  852. void ProjectSettingsEditor::queue_save() {
  853. _settings_changed();
  854. }
  855. void ProjectSettingsEditor::_copy_to_platform_about_to_show() {
  856. Set<String> presets;
  857. presets.insert("bptc");
  858. presets.insert("s3tc");
  859. presets.insert("etc");
  860. presets.insert("etc2");
  861. presets.insert("pvrtc");
  862. presets.insert("debug");
  863. presets.insert("release");
  864. presets.insert("editor");
  865. presets.insert("standalone");
  866. presets.insert("32");
  867. presets.insert("64");
  868. // Not available as an export platform yet, so it needs to be added manually
  869. presets.insert("Server");
  870. for (int i = 0; i < EditorExport::get_singleton()->get_export_platform_count(); i++) {
  871. List<String> p;
  872. EditorExport::get_singleton()->get_export_platform(i)->get_platform_features(&p);
  873. for (List<String>::Element *E = p.front(); E; E = E->next()) {
  874. presets.insert(E->get());
  875. }
  876. }
  877. for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) {
  878. List<String> p;
  879. EditorExport::get_singleton()->get_export_preset(i)->get_platform()->get_preset_features(EditorExport::get_singleton()->get_export_preset(i), &p);
  880. for (List<String>::Element *E = p.front(); E; E = E->next()) {
  881. presets.insert(E->get());
  882. }
  883. String custom = EditorExport::get_singleton()->get_export_preset(i)->get_custom_features();
  884. Vector<String> custom_list = custom.split(",");
  885. for (int j = 0; j < custom_list.size(); j++) {
  886. String f = custom_list[j].strip_edges();
  887. if (f != String()) {
  888. presets.insert(f);
  889. }
  890. }
  891. }
  892. popup_copy_to_feature->get_popup()->clear();
  893. int id = 0;
  894. for (Set<String>::Element *E = presets.front(); E; E = E->next()) {
  895. popup_copy_to_feature->get_popup()->add_item(E->get(), id++);
  896. }
  897. }
  898. Variant ProjectSettingsEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
  899. TreeItem *selected = input_editor->get_selected();
  900. if (!selected || selected->get_parent() != input_editor->get_root())
  901. return Variant();
  902. String name = selected->get_text(0);
  903. VBoxContainer *vb = memnew(VBoxContainer);
  904. HBoxContainer *hb = memnew(HBoxContainer);
  905. Label *label = memnew(Label(name));
  906. hb->set_modulate(Color(1, 1, 1, 1.0f));
  907. hb->add_child(label);
  908. vb->add_child(hb);
  909. input_editor->set_drag_preview(vb);
  910. Dictionary drag_data;
  911. drag_data["type"] = "nodes";
  912. input_editor->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN);
  913. return drag_data;
  914. }
  915. bool ProjectSettingsEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
  916. Dictionary d = p_data;
  917. if (!d.has("type") || d["type"] != "nodes")
  918. return false;
  919. TreeItem *selected = input_editor->get_selected();
  920. TreeItem *item = input_editor->get_item_at_position(p_point);
  921. if (!selected || !item || item == selected || item->get_parent() == selected)
  922. return false;
  923. return true;
  924. }
  925. void ProjectSettingsEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
  926. if (!can_drop_data_fw(p_point, p_data, p_from))
  927. return;
  928. TreeItem *selected = input_editor->get_selected();
  929. TreeItem *item = input_editor->get_item_at_position(p_point);
  930. if (!item)
  931. return;
  932. TreeItem *target = item->get_parent() == input_editor->get_root() ? item : item->get_parent();
  933. String selected_name = "input/" + selected->get_text(0);
  934. int old_order = ProjectSettings::get_singleton()->get_order(selected_name);
  935. String target_name = "input/" + target->get_text(0);
  936. int target_order = ProjectSettings::get_singleton()->get_order(target_name);
  937. int order = old_order;
  938. bool is_below = target_order > old_order;
  939. TreeItem *iterator = is_below ? selected->get_next() : selected->get_prev();
  940. undo_redo->create_action(TTR("Moved Input Action Event"));
  941. while (iterator != target) {
  942. String iterator_name = "input/" + iterator->get_text(0);
  943. int iterator_order = ProjectSettings::get_singleton()->get_order(iterator_name);
  944. undo_redo->add_do_method(ProjectSettings::get_singleton(), "set_order", iterator_name, order);
  945. undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set_order", iterator_name, iterator_order);
  946. order = iterator_order;
  947. iterator = is_below ? iterator->get_next() : iterator->get_prev();
  948. }
  949. undo_redo->add_do_method(ProjectSettings::get_singleton(), "set_order", target_name, order);
  950. undo_redo->add_do_method(ProjectSettings::get_singleton(), "set_order", selected_name, target_order);
  951. undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set_order", target_name, target_order);
  952. undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set_order", selected_name, old_order);
  953. undo_redo->add_do_method(this, "_update_actions");
  954. undo_redo->add_undo_method(this, "_update_actions");
  955. undo_redo->add_do_method(this, "_settings_changed");
  956. undo_redo->add_undo_method(this, "_settings_changed");
  957. undo_redo->commit_action();
  958. }
  959. void ProjectSettingsEditor::_copy_to_platform(int p_which) {
  960. String path = globals_editor->get_inspector()->get_selected_path();
  961. if (path == String()) {
  962. EditorNode::get_singleton()->show_warning(TTR("Select a setting item first!"));
  963. return;
  964. }
  965. String property = globals_editor->get_current_section().plus_file(path);
  966. undo_redo->create_action(TTR("Override for Feature"));
  967. Variant value = ProjectSettings::get_singleton()->get(property);
  968. if (property.find(".") != -1) { //overwriting overwrite, keep overwrite
  969. undo_redo->add_do_method(ProjectSettings::get_singleton(), "clear", property);
  970. undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set", property, value);
  971. }
  972. String feature = popup_copy_to_feature->get_popup()->get_item_text(p_which);
  973. String new_path = property + "." + feature;
  974. undo_redo->add_do_method(ProjectSettings::get_singleton(), "set", new_path, value);
  975. if (ProjectSettings::get_singleton()->has_setting(new_path)) {
  976. undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set", new_path, ProjectSettings::get_singleton()->get(new_path));
  977. }
  978. undo_redo->add_do_method(globals_editor, "update_category_list");
  979. undo_redo->add_undo_method(globals_editor, "update_category_list");
  980. undo_redo->add_do_method(this, "_settings_changed");
  981. undo_redo->add_undo_method(this, "_settings_changed");
  982. undo_redo->commit_action();
  983. }
  984. void ProjectSettingsEditor::add_translation(const String &p_translation) {
  985. _translation_add(p_translation);
  986. }
  987. void ProjectSettingsEditor::_translation_add(const String &p_path) {
  988. PackedStringArray translations = ProjectSettings::get_singleton()->get("locale/translations");
  989. for (int i = 0; i < translations.size(); i++) {
  990. if (translations[i] == p_path)
  991. return; //exists
  992. }
  993. translations.push_back(p_path);
  994. undo_redo->create_action(TTR("Add Translation"));
  995. undo_redo->add_do_property(ProjectSettings::get_singleton(), "locale/translations", translations);
  996. undo_redo->add_undo_property(ProjectSettings::get_singleton(), "locale/translations", ProjectSettings::get_singleton()->get("locale/translations"));
  997. undo_redo->add_do_method(this, "_update_translations");
  998. undo_redo->add_undo_method(this, "_update_translations");
  999. undo_redo->add_do_method(this, "_settings_changed");
  1000. undo_redo->add_undo_method(this, "_settings_changed");
  1001. undo_redo->commit_action();
  1002. }
  1003. void ProjectSettingsEditor::_translation_file_open() {
  1004. translation_file_open->popup_centered_ratio();
  1005. }
  1006. void ProjectSettingsEditor::_translation_delete(Object *p_item, int p_column, int p_button) {
  1007. TreeItem *ti = Object::cast_to<TreeItem>(p_item);
  1008. ERR_FAIL_COND(!ti);
  1009. int idx = ti->get_metadata(0);
  1010. PackedStringArray translations = ProjectSettings::get_singleton()->get("locale/translations");
  1011. ERR_FAIL_INDEX(idx, translations.size());
  1012. translations.remove(idx);
  1013. undo_redo->create_action(TTR("Remove Translation"));
  1014. undo_redo->add_do_property(ProjectSettings::get_singleton(), "locale/translations", translations);
  1015. undo_redo->add_undo_property(ProjectSettings::get_singleton(), "locale/translations", ProjectSettings::get_singleton()->get("locale/translations"));
  1016. undo_redo->add_do_method(this, "_update_translations");
  1017. undo_redo->add_undo_method(this, "_update_translations");
  1018. undo_redo->add_do_method(this, "_settings_changed");
  1019. undo_redo->add_undo_method(this, "_settings_changed");
  1020. undo_redo->commit_action();
  1021. }
  1022. void ProjectSettingsEditor::_translation_res_file_open() {
  1023. translation_res_file_open->popup_centered_ratio();
  1024. }
  1025. void ProjectSettingsEditor::_translation_res_add(const String &p_path) {
  1026. Variant prev;
  1027. Dictionary remaps;
  1028. if (ProjectSettings::get_singleton()->has_setting("locale/translation_remaps")) {
  1029. remaps = ProjectSettings::get_singleton()->get("locale/translation_remaps");
  1030. prev = remaps;
  1031. }
  1032. if (remaps.has(p_path))
  1033. return; //pointless already has it
  1034. remaps[p_path] = PackedStringArray();
  1035. undo_redo->create_action(TTR("Add Remapped Path"));
  1036. undo_redo->add_do_property(ProjectSettings::get_singleton(), "locale/translation_remaps", remaps);
  1037. undo_redo->add_undo_property(ProjectSettings::get_singleton(), "locale/translation_remaps", prev);
  1038. undo_redo->add_do_method(this, "_update_translations");
  1039. undo_redo->add_undo_method(this, "_update_translations");
  1040. undo_redo->add_do_method(this, "_settings_changed");
  1041. undo_redo->add_undo_method(this, "_settings_changed");
  1042. undo_redo->commit_action();
  1043. }
  1044. void ProjectSettingsEditor::_translation_res_option_file_open() {
  1045. translation_res_option_file_open->popup_centered_ratio();
  1046. }
  1047. void ProjectSettingsEditor::_translation_res_option_add(const String &p_path) {
  1048. ERR_FAIL_COND(!ProjectSettings::get_singleton()->has_setting("locale/translation_remaps"));
  1049. Dictionary remaps = ProjectSettings::get_singleton()->get("locale/translation_remaps");
  1050. TreeItem *k = translation_remap->get_selected();
  1051. ERR_FAIL_COND(!k);
  1052. String key = k->get_metadata(0);
  1053. ERR_FAIL_COND(!remaps.has(key));
  1054. PackedStringArray r = remaps[key];
  1055. r.push_back(p_path + ":" + "en");
  1056. remaps[key] = r;
  1057. undo_redo->create_action(TTR("Resource Remap Add Remap"));
  1058. undo_redo->add_do_property(ProjectSettings::get_singleton(), "locale/translation_remaps", remaps);
  1059. undo_redo->add_undo_property(ProjectSettings::get_singleton(), "locale/translation_remaps", ProjectSettings::get_singleton()->get("locale/translation_remaps"));
  1060. undo_redo->add_do_method(this, "_update_translations");
  1061. undo_redo->add_undo_method(this, "_update_translations");
  1062. undo_redo->add_do_method(this, "_settings_changed");
  1063. undo_redo->add_undo_method(this, "_settings_changed");
  1064. undo_redo->commit_action();
  1065. }
  1066. void ProjectSettingsEditor::_translation_res_select() {
  1067. if (updating_translations)
  1068. return;
  1069. call_deferred("_update_translations");
  1070. }
  1071. void ProjectSettingsEditor::_translation_res_option_changed() {
  1072. if (updating_translations)
  1073. return;
  1074. if (!ProjectSettings::get_singleton()->has_setting("locale/translation_remaps"))
  1075. return;
  1076. Dictionary remaps = ProjectSettings::get_singleton()->get("locale/translation_remaps");
  1077. TreeItem *k = translation_remap->get_selected();
  1078. ERR_FAIL_COND(!k);
  1079. TreeItem *ed = translation_remap_options->get_edited();
  1080. ERR_FAIL_COND(!ed);
  1081. String key = k->get_metadata(0);
  1082. int idx = ed->get_metadata(0);
  1083. String path = ed->get_metadata(1);
  1084. int which = ed->get_range(1);
  1085. Vector<String> langs = TranslationServer::get_all_locales();
  1086. ERR_FAIL_INDEX(which, langs.size());
  1087. ERR_FAIL_COND(!remaps.has(key));
  1088. PackedStringArray r = remaps[key];
  1089. ERR_FAIL_INDEX(idx, r.size());
  1090. if (translation_locales_idxs_remap.size() > which) {
  1091. r.set(idx, path + ":" + langs[translation_locales_idxs_remap[which]]);
  1092. } else {
  1093. r.set(idx, path + ":" + langs[which]);
  1094. }
  1095. remaps[key] = r;
  1096. updating_translations = true;
  1097. undo_redo->create_action(TTR("Change Resource Remap Language"));
  1098. undo_redo->add_do_property(ProjectSettings::get_singleton(), "locale/translation_remaps", remaps);
  1099. undo_redo->add_undo_property(ProjectSettings::get_singleton(), "locale/translation_remaps", ProjectSettings::get_singleton()->get("locale/translation_remaps"));
  1100. undo_redo->add_do_method(this, "_update_translations");
  1101. undo_redo->add_undo_method(this, "_update_translations");
  1102. undo_redo->add_do_method(this, "_settings_changed");
  1103. undo_redo->add_undo_method(this, "_settings_changed");
  1104. undo_redo->commit_action();
  1105. updating_translations = false;
  1106. }
  1107. void ProjectSettingsEditor::_translation_res_delete(Object *p_item, int p_column, int p_button) {
  1108. if (updating_translations)
  1109. return;
  1110. if (!ProjectSettings::get_singleton()->has_setting("locale/translation_remaps"))
  1111. return;
  1112. Dictionary remaps = ProjectSettings::get_singleton()->get("locale/translation_remaps");
  1113. TreeItem *k = Object::cast_to<TreeItem>(p_item);
  1114. String key = k->get_metadata(0);
  1115. ERR_FAIL_COND(!remaps.has(key));
  1116. remaps.erase(key);
  1117. undo_redo->create_action(TTR("Remove Resource Remap"));
  1118. undo_redo->add_do_property(ProjectSettings::get_singleton(), "locale/translation_remaps", remaps);
  1119. undo_redo->add_undo_property(ProjectSettings::get_singleton(), "locale/translation_remaps", ProjectSettings::get_singleton()->get("locale/translation_remaps"));
  1120. undo_redo->add_do_method(this, "_update_translations");
  1121. undo_redo->add_undo_method(this, "_update_translations");
  1122. undo_redo->add_do_method(this, "_settings_changed");
  1123. undo_redo->add_undo_method(this, "_settings_changed");
  1124. undo_redo->commit_action();
  1125. }
  1126. void ProjectSettingsEditor::_translation_res_option_delete(Object *p_item, int p_column, int p_button) {
  1127. if (updating_translations)
  1128. return;
  1129. if (!ProjectSettings::get_singleton()->has_setting("locale/translation_remaps"))
  1130. return;
  1131. Dictionary remaps = ProjectSettings::get_singleton()->get("locale/translation_remaps");
  1132. TreeItem *k = translation_remap->get_selected();
  1133. ERR_FAIL_COND(!k);
  1134. TreeItem *ed = Object::cast_to<TreeItem>(p_item);
  1135. ERR_FAIL_COND(!ed);
  1136. String key = k->get_metadata(0);
  1137. int idx = ed->get_metadata(0);
  1138. ERR_FAIL_COND(!remaps.has(key));
  1139. PackedStringArray r = remaps[key];
  1140. ERR_FAIL_INDEX(idx, r.size());
  1141. r.remove(idx);
  1142. remaps[key] = r;
  1143. undo_redo->create_action(TTR("Remove Resource Remap Option"));
  1144. undo_redo->add_do_property(ProjectSettings::get_singleton(), "locale/translation_remaps", remaps);
  1145. undo_redo->add_undo_property(ProjectSettings::get_singleton(), "locale/translation_remaps", ProjectSettings::get_singleton()->get("locale/translation_remaps"));
  1146. undo_redo->add_do_method(this, "_update_translations");
  1147. undo_redo->add_undo_method(this, "_update_translations");
  1148. undo_redo->add_do_method(this, "_settings_changed");
  1149. undo_redo->add_undo_method(this, "_settings_changed");
  1150. undo_redo->commit_action();
  1151. }
  1152. void ProjectSettingsEditor::_translation_filter_option_changed() {
  1153. int sel_id = translation_locale_filter_mode->get_selected_id();
  1154. TreeItem *t = translation_filter->get_edited();
  1155. String locale = t->get_tooltip(0);
  1156. bool checked = t->is_checked(0);
  1157. Variant prev;
  1158. Array f_locales_all;
  1159. if (ProjectSettings::get_singleton()->has_setting("locale/locale_filter")) {
  1160. f_locales_all = ProjectSettings::get_singleton()->get("locale/locale_filter");
  1161. prev = f_locales_all;
  1162. if (f_locales_all.size() != 2) {
  1163. f_locales_all.clear();
  1164. f_locales_all.append(sel_id);
  1165. f_locales_all.append(Array());
  1166. }
  1167. } else {
  1168. f_locales_all.append(sel_id);
  1169. f_locales_all.append(Array());
  1170. }
  1171. Array f_locales = f_locales_all[1];
  1172. int l_idx = f_locales.find(locale);
  1173. if (checked) {
  1174. if (l_idx == -1) {
  1175. f_locales.append(locale);
  1176. }
  1177. } else {
  1178. if (l_idx != -1) {
  1179. f_locales.remove(l_idx);
  1180. }
  1181. }
  1182. f_locales = f_locales.sort();
  1183. undo_redo->create_action(TTR("Changed Locale Filter"));
  1184. undo_redo->add_do_property(ProjectSettings::get_singleton(), "locale/locale_filter", f_locales_all);
  1185. undo_redo->add_undo_property(ProjectSettings::get_singleton(), "locale/locale_filter", prev);
  1186. undo_redo->add_do_method(this, "_update_translations");
  1187. undo_redo->add_undo_method(this, "_update_translations");
  1188. undo_redo->add_do_method(this, "_settings_changed");
  1189. undo_redo->add_undo_method(this, "_settings_changed");
  1190. undo_redo->commit_action();
  1191. }
  1192. void ProjectSettingsEditor::_translation_filter_mode_changed(int p_mode) {
  1193. int sel_id = translation_locale_filter_mode->get_selected_id();
  1194. Variant prev;
  1195. Array f_locales_all;
  1196. if (ProjectSettings::get_singleton()->has_setting("locale/locale_filter")) {
  1197. f_locales_all = ProjectSettings::get_singleton()->get("locale/locale_filter");
  1198. prev = f_locales_all;
  1199. if (f_locales_all.size() != 2) {
  1200. f_locales_all.clear();
  1201. f_locales_all.append(sel_id);
  1202. f_locales_all.append(Array());
  1203. } else {
  1204. f_locales_all[0] = sel_id;
  1205. }
  1206. } else {
  1207. f_locales_all.append(sel_id);
  1208. f_locales_all.append(Array());
  1209. }
  1210. undo_redo->create_action(TTR("Changed Locale Filter Mode"));
  1211. undo_redo->add_do_property(ProjectSettings::get_singleton(), "locale/locale_filter", f_locales_all);
  1212. undo_redo->add_undo_property(ProjectSettings::get_singleton(), "locale/locale_filter", prev);
  1213. undo_redo->add_do_method(this, "_update_translations");
  1214. undo_redo->add_undo_method(this, "_update_translations");
  1215. undo_redo->add_do_method(this, "_settings_changed");
  1216. undo_redo->add_undo_method(this, "_settings_changed");
  1217. undo_redo->commit_action();
  1218. }
  1219. void ProjectSettingsEditor::_update_translations() {
  1220. //update translations
  1221. if (updating_translations)
  1222. return;
  1223. updating_translations = true;
  1224. translation_list->clear();
  1225. TreeItem *root = translation_list->create_item(nullptr);
  1226. translation_list->set_hide_root(true);
  1227. if (ProjectSettings::get_singleton()->has_setting("locale/translations")) {
  1228. PackedStringArray translations = ProjectSettings::get_singleton()->get("locale/translations");
  1229. for (int i = 0; i < translations.size(); i++) {
  1230. TreeItem *t = translation_list->create_item(root);
  1231. t->set_editable(0, false);
  1232. t->set_text(0, translations[i].replace_first("res://", ""));
  1233. t->set_tooltip(0, translations[i]);
  1234. t->set_metadata(0, i);
  1235. t->add_button(0, input_editor->get_theme_icon("Remove", "EditorIcons"), 0, false, TTR("Remove"));
  1236. }
  1237. }
  1238. Vector<String> langs = TranslationServer::get_all_locales();
  1239. Vector<String> names = TranslationServer::get_all_locale_names();
  1240. //update filter tab
  1241. Array l_filter_all;
  1242. bool is_arr_empty = true;
  1243. if (ProjectSettings::get_singleton()->has_setting("locale/locale_filter")) {
  1244. l_filter_all = ProjectSettings::get_singleton()->get("locale/locale_filter");
  1245. if (l_filter_all.size() == 2) {
  1246. translation_locale_filter_mode->select(l_filter_all[0]);
  1247. is_arr_empty = false;
  1248. }
  1249. }
  1250. if (is_arr_empty) {
  1251. l_filter_all.append(0);
  1252. l_filter_all.append(Array());
  1253. translation_locale_filter_mode->select(0);
  1254. }
  1255. int filter_mode = l_filter_all[0];
  1256. Array l_filter = l_filter_all[1];
  1257. int s = names.size();
  1258. bool is_short_list_when_show_all_selected = filter_mode == SHOW_ALL_LOCALES && translation_filter_treeitems.size() < s;
  1259. bool is_full_list_when_show_only_selected = filter_mode == SHOW_ONLY_SELECTED_LOCALES && translation_filter_treeitems.size() == s;
  1260. bool should_recreate_locales_list = is_short_list_when_show_all_selected || is_full_list_when_show_only_selected;
  1261. if (!translation_locales_list_created || should_recreate_locales_list) {
  1262. translation_locales_list_created = true;
  1263. translation_filter->clear();
  1264. root = translation_filter->create_item(nullptr);
  1265. translation_filter->set_hide_root(true);
  1266. translation_filter_treeitems.clear();
  1267. for (int i = 0; i < s; i++) {
  1268. String n = names[i];
  1269. String l = langs[i];
  1270. bool is_checked = l_filter.has(l);
  1271. if (filter_mode == SHOW_ONLY_SELECTED_LOCALES && !is_checked)
  1272. continue;
  1273. TreeItem *t = translation_filter->create_item(root);
  1274. t->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
  1275. t->set_text(0, n);
  1276. t->set_editable(0, true);
  1277. t->set_tooltip(0, l);
  1278. t->set_checked(0, is_checked);
  1279. translation_filter_treeitems.push_back(t);
  1280. }
  1281. } else {
  1282. for (int i = 0; i < translation_filter_treeitems.size(); i++) {
  1283. TreeItem *t = translation_filter_treeitems[i];
  1284. t->set_checked(0, l_filter.has(t->get_tooltip(0)));
  1285. }
  1286. }
  1287. //update translation remaps
  1288. String remap_selected;
  1289. if (translation_remap->get_selected()) {
  1290. remap_selected = translation_remap->get_selected()->get_metadata(0);
  1291. }
  1292. translation_remap->clear();
  1293. translation_remap_options->clear();
  1294. root = translation_remap->create_item(nullptr);
  1295. TreeItem *root2 = translation_remap_options->create_item(nullptr);
  1296. translation_remap->set_hide_root(true);
  1297. translation_remap_options->set_hide_root(true);
  1298. translation_res_option_add_button->set_disabled(true);
  1299. translation_locales_idxs_remap.clear();
  1300. translation_locales_idxs_remap.resize(l_filter.size());
  1301. int fl_idx_count = translation_locales_idxs_remap.size();
  1302. String langnames = "";
  1303. int l_idx = 0;
  1304. for (int i = 0; i < names.size(); i++) {
  1305. if (filter_mode == SHOW_ONLY_SELECTED_LOCALES && fl_idx_count != 0) {
  1306. if (l_filter.size() > 0) {
  1307. if (l_filter.find(langs[i]) != -1) {
  1308. if (langnames.length() > 0)
  1309. langnames += ",";
  1310. langnames += names[i];
  1311. translation_locales_idxs_remap.write[l_idx] = i;
  1312. l_idx++;
  1313. }
  1314. }
  1315. } else {
  1316. if (i > 0)
  1317. langnames += ",";
  1318. langnames += names[i];
  1319. }
  1320. }
  1321. if (ProjectSettings::get_singleton()->has_setting("locale/translation_remaps")) {
  1322. Dictionary remaps = ProjectSettings::get_singleton()->get("locale/translation_remaps");
  1323. List<Variant> rk;
  1324. remaps.get_key_list(&rk);
  1325. Vector<String> keys;
  1326. for (List<Variant>::Element *E = rk.front(); E; E = E->next()) {
  1327. keys.push_back(E->get());
  1328. }
  1329. keys.sort();
  1330. for (int i = 0; i < keys.size(); i++) {
  1331. TreeItem *t = translation_remap->create_item(root);
  1332. t->set_editable(0, false);
  1333. t->set_text(0, keys[i].replace_first("res://", ""));
  1334. t->set_tooltip(0, keys[i]);
  1335. t->set_metadata(0, keys[i]);
  1336. t->add_button(0, input_editor->get_theme_icon("Remove", "EditorIcons"), 0, false, TTR("Remove"));
  1337. if (keys[i] == remap_selected) {
  1338. t->select(0);
  1339. translation_res_option_add_button->set_disabled(false);
  1340. PackedStringArray selected = remaps[keys[i]];
  1341. for (int j = 0; j < selected.size(); j++) {
  1342. String s2 = selected[j];
  1343. int qp = s2.find_last(":");
  1344. String path = s2.substr(0, qp);
  1345. String locale = s2.substr(qp + 1, s2.length());
  1346. TreeItem *t2 = translation_remap_options->create_item(root2);
  1347. t2->set_editable(0, false);
  1348. t2->set_text(0, path.replace_first("res://", ""));
  1349. t2->set_tooltip(0, path);
  1350. t2->set_metadata(0, j);
  1351. t2->add_button(0, input_editor->get_theme_icon("Remove", "EditorIcons"), 0, false, TTR("Remove"));
  1352. t2->set_cell_mode(1, TreeItem::CELL_MODE_RANGE);
  1353. t2->set_text(1, langnames);
  1354. t2->set_editable(1, true);
  1355. t2->set_metadata(1, path);
  1356. int idx = langs.find(locale);
  1357. if (idx < 0)
  1358. idx = 0;
  1359. int f_idx = translation_locales_idxs_remap.find(idx);
  1360. if (f_idx != -1 && fl_idx_count > 0 && filter_mode == SHOW_ONLY_SELECTED_LOCALES) {
  1361. t2->set_range(1, f_idx);
  1362. } else {
  1363. t2->set_range(1, idx);
  1364. }
  1365. }
  1366. }
  1367. }
  1368. }
  1369. updating_translations = false;
  1370. }
  1371. void ProjectSettingsEditor::_toggle_search_bar(bool p_pressed) {
  1372. globals_editor->get_inspector()->set_use_filter(p_pressed);
  1373. if (p_pressed) {
  1374. search_bar->show();
  1375. add_prop_bar->hide();
  1376. search_box->grab_focus();
  1377. search_box->select_all();
  1378. } else {
  1379. search_box->clear();
  1380. search_bar->hide();
  1381. add_prop_bar->show();
  1382. }
  1383. }
  1384. void ProjectSettingsEditor::set_plugins_page() {
  1385. tab_container->set_current_tab(plugin_settings->get_index());
  1386. }
  1387. TabContainer *ProjectSettingsEditor::get_tabs() {
  1388. return tab_container;
  1389. }
  1390. void ProjectSettingsEditor::_editor_restart() {
  1391. EditorNode::get_singleton()->save_all_scenes();
  1392. EditorNode::get_singleton()->restart_editor();
  1393. }
  1394. void ProjectSettingsEditor::_editor_restart_request() {
  1395. restart_container->show();
  1396. }
  1397. void ProjectSettingsEditor::_editor_restart_close() {
  1398. restart_container->hide();
  1399. }
  1400. void ProjectSettingsEditor::_bind_methods() {
  1401. ClassDB::bind_method(D_METHOD("_unhandled_input"), &ProjectSettingsEditor::_unhandled_input);
  1402. ClassDB::bind_method(D_METHOD("_item_checked"), &ProjectSettingsEditor::_item_checked);
  1403. ClassDB::bind_method(D_METHOD("_save"), &ProjectSettingsEditor::_save);
  1404. ClassDB::bind_method(D_METHOD("_update_actions"), &ProjectSettingsEditor::_update_actions);
  1405. ClassDB::bind_method(D_METHOD("_update_translations"), &ProjectSettingsEditor::_update_translations);
  1406. ClassDB::bind_method(D_METHOD("get_tabs"), &ProjectSettingsEditor::get_tabs);
  1407. ClassDB::bind_method(D_METHOD("get_drag_data_fw"), &ProjectSettingsEditor::get_drag_data_fw);
  1408. ClassDB::bind_method(D_METHOD("can_drop_data_fw"), &ProjectSettingsEditor::can_drop_data_fw);
  1409. ClassDB::bind_method(D_METHOD("drop_data_fw"), &ProjectSettingsEditor::drop_data_fw);
  1410. }
  1411. ProjectSettingsEditor::ProjectSettingsEditor(EditorData *p_data) {
  1412. singleton = this;
  1413. set_title(TTR("Project Settings (project.godot)"));
  1414. undo_redo = &p_data->get_undo_redo();
  1415. data = p_data;
  1416. tab_container = memnew(TabContainer);
  1417. tab_container->set_tab_align(TabContainer::ALIGN_LEFT);
  1418. tab_container->set_use_hidden_tabs_for_min_size(true);
  1419. add_child(tab_container);
  1420. VBoxContainer *props_base = memnew(VBoxContainer);
  1421. props_base->set_alignment(BoxContainer::ALIGN_BEGIN);
  1422. props_base->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1423. tab_container->add_child(props_base);
  1424. props_base->set_name(TTR("General"));
  1425. HBoxContainer *hbc = memnew(HBoxContainer);
  1426. hbc->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1427. props_base->add_child(hbc);
  1428. search_button = memnew(Button);
  1429. search_button->set_toggle_mode(true);
  1430. search_button->set_pressed(false);
  1431. search_button->set_text(TTR("Search"));
  1432. hbc->add_child(search_button);
  1433. search_button->connect("toggled", callable_mp(this, &ProjectSettingsEditor::_toggle_search_bar));
  1434. hbc->add_child(memnew(VSeparator));
  1435. add_prop_bar = memnew(HBoxContainer);
  1436. add_prop_bar->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1437. hbc->add_child(add_prop_bar);
  1438. Label *l = memnew(Label);
  1439. add_prop_bar->add_child(l);
  1440. l->set_text(TTR("Category:"));
  1441. category = memnew(LineEdit);
  1442. category->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1443. add_prop_bar->add_child(category);
  1444. category->connect("text_entered", callable_mp(this, &ProjectSettingsEditor::_item_adds));
  1445. l = memnew(Label);
  1446. add_prop_bar->add_child(l);
  1447. l->set_text(TTR("Property:"));
  1448. property = memnew(LineEdit);
  1449. property->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1450. add_prop_bar->add_child(property);
  1451. property->connect("text_entered", callable_mp(this, &ProjectSettingsEditor::_item_adds));
  1452. l = memnew(Label);
  1453. add_prop_bar->add_child(l);
  1454. l->set_text(TTR("Type:"));
  1455. type = memnew(OptionButton);
  1456. type->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1457. add_prop_bar->add_child(type);
  1458. // Start at 1 to avoid adding "Nil" as an option
  1459. for (int i = 1; i < Variant::VARIANT_MAX; i++) {
  1460. type->add_item(Variant::get_type_name(Variant::Type(i)));
  1461. }
  1462. Button *add = memnew(Button);
  1463. add_prop_bar->add_child(add);
  1464. add->set_text(TTR("Add"));
  1465. add->connect("pressed", callable_mp(this, &ProjectSettingsEditor::_item_add));
  1466. search_bar = memnew(HBoxContainer);
  1467. search_bar->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1468. hbc->add_child(search_bar);
  1469. search_bar->hide();
  1470. search_box = memnew(LineEdit);
  1471. search_box->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1472. search_bar->add_child(search_box);
  1473. globals_editor = memnew(SectionedInspector);
  1474. props_base->add_child(globals_editor);
  1475. globals_editor->get_inspector()->set_undo_redo(EditorNode::get_singleton()->get_undo_redo());
  1476. globals_editor->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1477. globals_editor->register_search_box(search_box);
  1478. globals_editor->get_inspector()->connect("property_selected", callable_mp(this, &ProjectSettingsEditor::_item_selected));
  1479. globals_editor->get_inspector()->connect("property_edited", callable_mp(this, &ProjectSettingsEditor::_settings_prop_edited));
  1480. globals_editor->get_inspector()->connect("restart_requested", callable_mp(this, &ProjectSettingsEditor::_editor_restart_request));
  1481. Button *del = memnew(Button);
  1482. hbc->add_child(del);
  1483. del->set_text(TTR("Delete"));
  1484. del->connect("pressed", callable_mp(this, &ProjectSettingsEditor::_item_del));
  1485. add_prop_bar->add_child(memnew(VSeparator));
  1486. popup_copy_to_feature = memnew(MenuButton);
  1487. popup_copy_to_feature->set_text(TTR("Override For..."));
  1488. popup_copy_to_feature->set_disabled(true);
  1489. add_prop_bar->add_child(popup_copy_to_feature);
  1490. popup_copy_to_feature->get_popup()->connect("id_pressed", callable_mp(this, &ProjectSettingsEditor::_copy_to_platform));
  1491. popup_copy_to_feature->get_popup()->connect("about_to_popup", callable_mp(this, &ProjectSettingsEditor::_copy_to_platform_about_to_show));
  1492. get_ok()->set_text(TTR("Close"));
  1493. set_hide_on_ok(true);
  1494. restart_container = memnew(PanelContainer);
  1495. props_base->add_child(restart_container);
  1496. HBoxContainer *restart_hb = memnew(HBoxContainer);
  1497. restart_container->add_child(restart_hb);
  1498. restart_icon = memnew(TextureRect);
  1499. restart_icon->set_v_size_flags(Control::SIZE_SHRINK_CENTER);
  1500. restart_hb->add_child(restart_icon);
  1501. restart_label = memnew(Label);
  1502. restart_label->set_text(TTR("The editor must be restarted for changes to take effect."));
  1503. restart_hb->add_child(restart_label);
  1504. restart_hb->add_spacer();
  1505. Button *restart_button = memnew(Button);
  1506. restart_button->connect("pressed", callable_mp(this, &ProjectSettingsEditor::_editor_restart));
  1507. restart_hb->add_child(restart_button);
  1508. restart_button->set_text(TTR("Save & Restart"));
  1509. restart_close_button = memnew(ToolButton);
  1510. restart_close_button->connect("pressed", callable_mp(this, &ProjectSettingsEditor::_editor_restart_close));
  1511. restart_hb->add_child(restart_close_button);
  1512. restart_container->hide();
  1513. message = memnew(AcceptDialog);
  1514. add_child(message);
  1515. Control *input_base = memnew(Control);
  1516. input_base->set_name(TTR("Input Map"));
  1517. tab_container->add_child(input_base);
  1518. VBoxContainer *vbc = memnew(VBoxContainer);
  1519. input_base->add_child(vbc);
  1520. vbc->set_anchor_and_margin(MARGIN_TOP, Control::ANCHOR_BEGIN, 0);
  1521. vbc->set_anchor_and_margin(MARGIN_BOTTOM, Control::ANCHOR_END, 0);
  1522. vbc->set_anchor_and_margin(MARGIN_LEFT, Control::ANCHOR_BEGIN, 0);
  1523. vbc->set_anchor_and_margin(MARGIN_RIGHT, Control::ANCHOR_END, 0);
  1524. hbc = memnew(HBoxContainer);
  1525. vbc->add_child(hbc);
  1526. l = memnew(Label);
  1527. hbc->add_child(l);
  1528. l->set_text(TTR("Action:"));
  1529. action_name = memnew(LineEdit);
  1530. action_name->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1531. hbc->add_child(action_name);
  1532. action_name->connect("text_entered", callable_mp(this, &ProjectSettingsEditor::_action_adds));
  1533. action_name->connect("text_changed", callable_mp(this, &ProjectSettingsEditor::_action_check));
  1534. action_add_error = memnew(Label);
  1535. hbc->add_child(action_add_error);
  1536. action_add_error->hide();
  1537. add = memnew(Button);
  1538. hbc->add_child(add);
  1539. add->set_text(TTR("Add"));
  1540. add->set_disabled(true);
  1541. add->connect("pressed", callable_mp(this, &ProjectSettingsEditor::_action_add));
  1542. action_add = add;
  1543. input_editor = memnew(Tree);
  1544. vbc->add_child(input_editor);
  1545. input_editor->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1546. input_editor->set_columns(3);
  1547. input_editor->set_column_titles_visible(true);
  1548. input_editor->set_column_title(0, TTR("Action"));
  1549. input_editor->set_column_title(1, TTR("Deadzone"));
  1550. input_editor->set_column_expand(1, false);
  1551. input_editor->set_column_min_width(1, 80 * EDSCALE);
  1552. input_editor->set_column_expand(2, false);
  1553. input_editor->set_column_min_width(2, 50 * EDSCALE);
  1554. input_editor->connect("item_edited", callable_mp(this, &ProjectSettingsEditor::_action_edited));
  1555. input_editor->connect("item_activated", callable_mp(this, &ProjectSettingsEditor::_action_activated));
  1556. input_editor->connect("cell_selected", callable_mp(this, &ProjectSettingsEditor::_action_selected));
  1557. input_editor->connect("button_pressed", callable_mp(this, &ProjectSettingsEditor::_action_button_pressed));
  1558. #ifndef _MSC_VER
  1559. #warning need to make drag data forwarding to non controls happen
  1560. #endif
  1561. //input_editor->set_drag_forwarding(this);
  1562. popup_add = memnew(PopupMenu);
  1563. add_child(popup_add);
  1564. popup_add->connect("id_pressed", callable_mp(this, &ProjectSettingsEditor::_add_item), make_binds(Ref<InputEvent>()));
  1565. press_a_key_physical = false;
  1566. press_a_key = memnew(ConfirmationDialog);
  1567. //press_a_key->set_focus_mode(Control::FOCUS_ALL);
  1568. add_child(press_a_key);
  1569. l = memnew(Label);
  1570. l->set_text(TTR("Press a Key..."));
  1571. l->set_anchors_and_margins_preset(Control::PRESET_WIDE);
  1572. l->set_align(Label::ALIGN_CENTER);
  1573. l->set_margin(MARGIN_TOP, 20);
  1574. l->set_anchor_and_margin(MARGIN_BOTTOM, Control::ANCHOR_BEGIN, 30);
  1575. press_a_key->get_ok()->set_disabled(true);
  1576. press_a_key_label = l;
  1577. press_a_key->add_child(l);
  1578. press_a_key->connect("window_input", callable_mp(this, &ProjectSettingsEditor::_wait_for_key));
  1579. press_a_key->connect("confirmed", callable_mp(this, &ProjectSettingsEditor::_press_a_key_confirm));
  1580. device_input = memnew(ConfirmationDialog);
  1581. add_child(device_input);
  1582. device_input->get_ok()->set_text(TTR("Add"));
  1583. device_input->connect("confirmed", callable_mp(this, &ProjectSettingsEditor::_device_input_add));
  1584. hbc = memnew(HBoxContainer);
  1585. device_input->add_child(hbc);
  1586. VBoxContainer *vbc_left = memnew(VBoxContainer);
  1587. hbc->add_child(vbc_left);
  1588. l = memnew(Label);
  1589. l->set_text(TTR("Device:"));
  1590. vbc_left->add_child(l);
  1591. device_id = memnew(OptionButton);
  1592. for (int i = -1; i < 8; i++)
  1593. device_id->add_item(_get_device_string(i));
  1594. _set_current_device(0);
  1595. vbc_left->add_child(device_id);
  1596. VBoxContainer *vbc_right = memnew(VBoxContainer);
  1597. hbc->add_child(vbc_right);
  1598. vbc_right->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1599. l = memnew(Label);
  1600. l->set_text(TTR("Index:"));
  1601. vbc_right->add_child(l);
  1602. device_index_label = l;
  1603. device_index = memnew(OptionButton);
  1604. device_index->set_clip_text(true);
  1605. vbc_right->add_child(device_index);
  1606. setting = false;
  1607. //translations
  1608. TabContainer *translations = memnew(TabContainer);
  1609. translations->set_tab_align(TabContainer::ALIGN_LEFT);
  1610. translations->set_name(TTR("Localization"));
  1611. tab_container->add_child(translations);
  1612. //remap for properly select language in popup
  1613. translation_locales_idxs_remap = Vector<int>();
  1614. translation_locales_list_created = false;
  1615. {
  1616. VBoxContainer *tvb = memnew(VBoxContainer);
  1617. translations->add_child(tvb);
  1618. tvb->set_name(TTR("Translations"));
  1619. HBoxContainer *thb = memnew(HBoxContainer);
  1620. tvb->add_child(thb);
  1621. thb->add_child(memnew(Label(TTR("Translations:"))));
  1622. thb->add_spacer();
  1623. Button *addtr = memnew(Button(TTR("Add...")));
  1624. addtr->connect("pressed", callable_mp(this, &ProjectSettingsEditor::_translation_file_open));
  1625. thb->add_child(addtr);
  1626. VBoxContainer *tmc = memnew(VBoxContainer);
  1627. tvb->add_child(tmc);
  1628. tmc->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1629. translation_list = memnew(Tree);
  1630. translation_list->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1631. tmc->add_child(translation_list);
  1632. translation_file_open = memnew(EditorFileDialog);
  1633. add_child(translation_file_open);
  1634. translation_file_open->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE);
  1635. translation_file_open->connect("file_selected", callable_mp(this, &ProjectSettingsEditor::_translation_add));
  1636. }
  1637. {
  1638. VBoxContainer *tvb = memnew(VBoxContainer);
  1639. translations->add_child(tvb);
  1640. tvb->set_name(TTR("Remaps"));
  1641. HBoxContainer *thb = memnew(HBoxContainer);
  1642. tvb->add_child(thb);
  1643. thb->add_child(memnew(Label(TTR("Resources:"))));
  1644. thb->add_spacer();
  1645. Button *addtr = memnew(Button(TTR("Add...")));
  1646. addtr->connect("pressed", callable_mp(this, &ProjectSettingsEditor::_translation_res_file_open));
  1647. thb->add_child(addtr);
  1648. VBoxContainer *tmc = memnew(VBoxContainer);
  1649. tvb->add_child(tmc);
  1650. tmc->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1651. translation_remap = memnew(Tree);
  1652. translation_remap->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1653. translation_remap->connect("cell_selected", callable_mp(this, &ProjectSettingsEditor::_translation_res_select));
  1654. tmc->add_child(translation_remap);
  1655. translation_remap->connect("button_pressed", callable_mp(this, &ProjectSettingsEditor::_translation_res_delete));
  1656. translation_res_file_open = memnew(EditorFileDialog);
  1657. add_child(translation_res_file_open);
  1658. translation_res_file_open->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE);
  1659. translation_res_file_open->connect("file_selected", callable_mp(this, &ProjectSettingsEditor::_translation_res_add));
  1660. thb = memnew(HBoxContainer);
  1661. tvb->add_child(thb);
  1662. thb->add_child(memnew(Label(TTR("Remaps by Locale:"))));
  1663. thb->add_spacer();
  1664. addtr = memnew(Button(TTR("Add...")));
  1665. addtr->connect("pressed", callable_mp(this, &ProjectSettingsEditor::_translation_res_option_file_open));
  1666. translation_res_option_add_button = addtr;
  1667. thb->add_child(addtr);
  1668. tmc = memnew(VBoxContainer);
  1669. tvb->add_child(tmc);
  1670. tmc->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1671. translation_remap_options = memnew(Tree);
  1672. translation_remap_options->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1673. tmc->add_child(translation_remap_options);
  1674. translation_remap_options->set_columns(2);
  1675. translation_remap_options->set_column_title(0, TTR("Path"));
  1676. translation_remap_options->set_column_title(1, TTR("Locale"));
  1677. translation_remap_options->set_column_titles_visible(true);
  1678. translation_remap_options->set_column_expand(0, true);
  1679. translation_remap_options->set_column_expand(1, false);
  1680. translation_remap_options->set_column_min_width(1, 200);
  1681. translation_remap_options->connect("item_edited", callable_mp(this, &ProjectSettingsEditor::_translation_res_option_changed));
  1682. translation_remap_options->connect("button_pressed", callable_mp(this, &ProjectSettingsEditor::_translation_res_option_delete));
  1683. translation_res_option_file_open = memnew(EditorFileDialog);
  1684. add_child(translation_res_option_file_open);
  1685. translation_res_option_file_open->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE);
  1686. translation_res_option_file_open->connect("file_selected", callable_mp(this, &ProjectSettingsEditor::_translation_res_option_add));
  1687. }
  1688. {
  1689. VBoxContainer *tvb = memnew(VBoxContainer);
  1690. translations->add_child(tvb);
  1691. tvb->set_name(TTR("Locales Filter"));
  1692. VBoxContainer *tmc = memnew(VBoxContainer);
  1693. tmc->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1694. tvb->add_child(tmc);
  1695. translation_locale_filter_mode = memnew(OptionButton);
  1696. translation_locale_filter_mode->add_item(TTR("Show All Locales"), SHOW_ALL_LOCALES);
  1697. translation_locale_filter_mode->add_item(TTR("Show Selected Locales Only"), SHOW_ONLY_SELECTED_LOCALES);
  1698. translation_locale_filter_mode->select(0);
  1699. tmc->add_margin_child(TTR("Filter mode:"), translation_locale_filter_mode);
  1700. translation_locale_filter_mode->connect("item_selected", callable_mp(this, &ProjectSettingsEditor::_translation_filter_mode_changed));
  1701. translation_filter = memnew(Tree);
  1702. translation_filter->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1703. translation_filter->set_columns(1);
  1704. tmc->add_child(memnew(Label(TTR("Locales:"))));
  1705. tmc->add_child(translation_filter);
  1706. translation_filter->connect("item_edited", callable_mp(this, &ProjectSettingsEditor::_translation_filter_option_changed));
  1707. }
  1708. autoload_settings = memnew(EditorAutoloadSettings);
  1709. autoload_settings->set_name(TTR("AutoLoad"));
  1710. tab_container->add_child(autoload_settings);
  1711. autoload_settings->connect("autoload_changed", callable_mp(this, &ProjectSettingsEditor::_settings_changed));
  1712. shaders_global_variables_editor = memnew(ShaderGlobalsEditor);
  1713. shaders_global_variables_editor->set_name(TTR("Shader Globals"));
  1714. tab_container->add_child(shaders_global_variables_editor);
  1715. shaders_global_variables_editor->connect("globals_changed", callable_mp(this, &ProjectSettingsEditor::_settings_changed));
  1716. plugin_settings = memnew(EditorPluginSettings);
  1717. plugin_settings->set_name(TTR("Plugins"));
  1718. tab_container->add_child(plugin_settings);
  1719. timer = memnew(Timer);
  1720. timer->set_wait_time(1.5);
  1721. timer->connect("timeout", callable_mp(ProjectSettings::get_singleton(), &ProjectSettings::save));
  1722. timer->set_one_shot(true);
  1723. add_child(timer);
  1724. updating_translations = false;
  1725. }