project_settings_editor.cpp 67 KB

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