project_settings_editor.cpp 73 KB

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