project_settings_editor.cpp 74 KB

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