2
0

project_settings_editor.cpp 75 KB

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