project_settings_editor.cpp 72 KB

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