project_settings_editor.cpp 72 KB

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