project_settings_editor.cpp 67 KB

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