project_settings_editor.cpp 70 KB

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