project_settings_editor.cpp 70 KB

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