project_settings_editor.cpp 71 KB

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