project_settings_editor.cpp 79 KB

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