project_settings.cpp 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561
  1. /*************************************************************************/
  2. /* project_settings.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "project_settings.h"
  31. #include "editor_node.h"
  32. #include "global_constants.h"
  33. #include "globals.h"
  34. #include "os/keyboard.h"
  35. #include "scene/gui/margin_container.h"
  36. #include "scene/gui/tab_container.h"
  37. #include "translation.h"
  38. ProjectSettings *ProjectSettings::singleton = NULL;
  39. static const char *_button_names[JOY_BUTTON_MAX] = {
  40. "PS Cross, XBox A, Nintendo B",
  41. "PS Circle, XBox B, Nintendo A",
  42. "PS Square, XBox X, Nintendo Y",
  43. "PS Triangle, XBox Y, Nintendo X",
  44. "L, L1",
  45. "R, R1",
  46. "L2",
  47. "R2",
  48. "L3",
  49. "R3",
  50. "Select, Nintendo -",
  51. "Start, Nintendo +",
  52. "D-Pad Up",
  53. "D-Pad Down",
  54. "D-Pad Left",
  55. "D-Pad Right"
  56. };
  57. static const char *_axis_names[JOY_AXIS_MAX * 2] = {
  58. " (Left Stick Left)",
  59. " (Left Stick Right)",
  60. " (Left Stick Up)",
  61. " (Left Stick Down)",
  62. " (Right Stick Left)",
  63. " (Right Stick Right)",
  64. " (Right Stick Up)",
  65. " (Right Stick Down)",
  66. "", "", "", "",
  67. "", " (L2)",
  68. "", " (R2)"
  69. };
  70. void ProjectSettings::_notification(int p_what) {
  71. if (p_what == NOTIFICATION_ENTER_TREE) {
  72. globals_editor->edit(Globals::get_singleton());
  73. search_button->set_icon(get_icon("Zoom", "EditorIcons"));
  74. clear_button->set_icon(get_icon("Close", "EditorIcons"));
  75. translation_list->connect("button_pressed", this, "_translation_delete");
  76. _update_actions();
  77. popup_add->add_icon_item(get_icon("Keyboard", "EditorIcons"), TTR("Key "), InputEvent::KEY); //"Key " - because the word 'key' has already been used as a key animation
  78. popup_add->add_icon_item(get_icon("JoyButton", "EditorIcons"), TTR("Joy Button"), InputEvent::JOYSTICK_BUTTON);
  79. popup_add->add_icon_item(get_icon("JoyAxis", "EditorIcons"), TTR("Joy Axis"), InputEvent::JOYSTICK_MOTION);
  80. popup_add->add_icon_item(get_icon("Mouse", "EditorIcons"), TTR("Mouse Button"), InputEvent::MOUSE_BUTTON);
  81. List<String> tfn;
  82. ResourceLoader::get_recognized_extensions_for_type("Translation", &tfn);
  83. for (List<String>::Element *E = tfn.front(); E; E = E->next()) {
  84. translation_file_open->add_filter("*." + E->get());
  85. }
  86. List<String> rfn;
  87. ResourceLoader::get_recognized_extensions_for_type("Resource", &rfn);
  88. for (List<String>::Element *E = rfn.front(); E; E = E->next()) {
  89. translation_res_file_open->add_filter("*." + E->get());
  90. translation_res_option_file_open->add_filter("*." + E->get());
  91. }
  92. }
  93. }
  94. void ProjectSettings::_action_selected() {
  95. TreeItem *ti = input_editor->get_selected();
  96. if (!ti || !ti->is_editable(0))
  97. return;
  98. add_at = "input/" + ti->get_text(0);
  99. }
  100. void ProjectSettings::_action_edited() {
  101. TreeItem *ti = input_editor->get_selected();
  102. if (!ti)
  103. return;
  104. String new_name = ti->get_text(0);
  105. String old_name = add_at.substr(add_at.find("/") + 1, add_at.length());
  106. if (new_name == old_name)
  107. return;
  108. if (new_name.find("/") != -1 || new_name.find(":") != -1 || new_name == "") {
  109. ti->set_text(0, old_name);
  110. add_at = "input/" + old_name;
  111. message->set_text(TTR("Invalid action (anything goes but '/' or ':')."));
  112. message->popup_centered(Size2(300, 100));
  113. return;
  114. }
  115. String action_prop = "input/" + new_name;
  116. if (Globals::get_singleton()->has(action_prop)) {
  117. ti->set_text(0, old_name);
  118. add_at = "input/" + old_name;
  119. message->set_text(vformat(TTR("Action '%s' already exists!"), new_name));
  120. message->popup_centered(Size2(300, 100));
  121. return;
  122. }
  123. int order = Globals::get_singleton()->get_order(add_at);
  124. Array va = Globals::get_singleton()->get(add_at);
  125. bool persisting = Globals::get_singleton()->is_persisting(add_at);
  126. setting = true;
  127. undo_redo->create_action(TTR("Rename Input Action Event"));
  128. undo_redo->add_do_method(Globals::get_singleton(), "clear", add_at);
  129. undo_redo->add_do_method(Globals::get_singleton(), "set", action_prop, va);
  130. undo_redo->add_do_method(Globals::get_singleton(), "set_persisting", action_prop, persisting);
  131. undo_redo->add_do_method(Globals::get_singleton(), "set_order", action_prop, order);
  132. undo_redo->add_undo_method(Globals::get_singleton(), "clear", action_prop);
  133. undo_redo->add_undo_method(Globals::get_singleton(), "set", add_at, va);
  134. undo_redo->add_undo_method(Globals::get_singleton(), "set_persisting", add_at, persisting);
  135. undo_redo->add_undo_method(Globals::get_singleton(), "set_order", add_at, order);
  136. undo_redo->add_do_method(this, "_update_actions");
  137. undo_redo->add_undo_method(this, "_update_actions");
  138. undo_redo->add_do_method(this, "_settings_changed");
  139. undo_redo->add_undo_method(this, "_settings_changed");
  140. undo_redo->commit_action();
  141. setting = false;
  142. add_at = action_prop;
  143. }
  144. void ProjectSettings::_device_input_add() {
  145. InputEvent ie;
  146. String name = add_at;
  147. Variant old_val = Globals::get_singleton()->get(name);
  148. Array arr = old_val;
  149. ie.device = device_id->get_val();
  150. ie.type = add_type;
  151. switch (add_type) {
  152. case InputEvent::MOUSE_BUTTON: {
  153. ie.mouse_button.button_index = device_index->get_selected() + 1;
  154. for (int i = 0; i < arr.size(); i++) {
  155. InputEvent aie = arr[i];
  156. if (aie.device == ie.device && aie.type == InputEvent::MOUSE_BUTTON && aie.mouse_button.button_index == ie.mouse_button.button_index) {
  157. return;
  158. }
  159. }
  160. } break;
  161. case InputEvent::JOYSTICK_MOTION: {
  162. ie.joy_motion.axis = device_index->get_selected() >> 1;
  163. ie.joy_motion.axis_value = device_index->get_selected() & 1 ? 1 : -1;
  164. for (int i = 0; i < arr.size(); i++) {
  165. InputEvent aie = arr[i];
  166. if (aie.device == ie.device && aie.type == InputEvent::JOYSTICK_MOTION && aie.joy_motion.axis == ie.joy_motion.axis && aie.joy_motion.axis_value == ie.joy_motion.axis_value) {
  167. return;
  168. }
  169. }
  170. } break;
  171. case InputEvent::JOYSTICK_BUTTON: {
  172. ie.joy_button.button_index = device_index->get_selected();
  173. for (int i = 0; i < arr.size(); i++) {
  174. InputEvent aie = arr[i];
  175. if (aie.device == ie.device && aie.type == InputEvent::JOYSTICK_BUTTON && aie.joy_button.button_index == ie.joy_button.button_index) {
  176. return;
  177. }
  178. }
  179. } break;
  180. default: {}
  181. }
  182. arr.push_back(ie);
  183. undo_redo->create_action(TTR("Add Input Action Event"));
  184. undo_redo->add_do_method(Globals::get_singleton(), "set", name, arr);
  185. undo_redo->add_do_method(Globals::get_singleton(), "set_persisting", name, true);
  186. undo_redo->add_undo_method(Globals::get_singleton(), "set", name, old_val);
  187. undo_redo->add_do_method(this, "_update_actions");
  188. undo_redo->add_undo_method(this, "_update_actions");
  189. undo_redo->add_do_method(this, "_settings_changed");
  190. undo_redo->add_undo_method(this, "_settings_changed");
  191. undo_redo->commit_action();
  192. _show_last_added(ie, name);
  193. }
  194. void ProjectSettings::_press_a_key_confirm() {
  195. if (last_wait_for_key.type != InputEvent::KEY)
  196. return;
  197. InputEvent ie;
  198. ie.type = InputEvent::KEY;
  199. ie.key.scancode = last_wait_for_key.key.scancode;
  200. ie.key.mod = last_wait_for_key.key.mod;
  201. String name = add_at;
  202. Variant old_val = Globals::get_singleton()->get(name);
  203. Array arr = old_val;
  204. for (int i = 0; i < arr.size(); i++) {
  205. InputEvent aie = arr[i];
  206. if (aie.type == InputEvent::KEY && aie.key.scancode == ie.key.scancode && aie.key.mod == ie.key.mod) {
  207. return;
  208. }
  209. }
  210. arr.push_back(ie);
  211. undo_redo->create_action(TTR("Add Input Action Event"));
  212. undo_redo->add_do_method(Globals::get_singleton(), "set", name, arr);
  213. undo_redo->add_do_method(Globals::get_singleton(), "set_persisting", name, true);
  214. undo_redo->add_undo_method(Globals::get_singleton(), "set", name, old_val);
  215. undo_redo->add_do_method(this, "_update_actions");
  216. undo_redo->add_undo_method(this, "_update_actions");
  217. undo_redo->add_do_method(this, "_settings_changed");
  218. undo_redo->add_undo_method(this, "_settings_changed");
  219. undo_redo->commit_action();
  220. _show_last_added(ie, name);
  221. }
  222. void ProjectSettings::_show_last_added(const InputEvent &p_event, const String &p_name) {
  223. TreeItem *r = input_editor->get_root();
  224. String name = p_name;
  225. name.erase(0, 6);
  226. if (!r)
  227. return;
  228. r = r->get_children();
  229. if (!r)
  230. return;
  231. bool found = false;
  232. while (r) {
  233. if (r->get_text(0) != name) {
  234. r = r->get_next();
  235. continue;
  236. }
  237. TreeItem *child = r->get_children();
  238. while (child) {
  239. Variant input = child->get_meta("__input");
  240. if (p_event == input) {
  241. child->select(0);
  242. found = true;
  243. break;
  244. }
  245. child = child->get_next();
  246. }
  247. if (found) break;
  248. r = r->get_next();
  249. }
  250. if (found) input_editor->ensure_cursor_is_visible();
  251. }
  252. void ProjectSettings::_wait_for_key(const InputEvent &p_event) {
  253. if (p_event.type == InputEvent::KEY && p_event.key.pressed && p_event.key.scancode != 0) {
  254. last_wait_for_key = p_event;
  255. String str = keycode_get_string(p_event.key.scancode).capitalize();
  256. if (p_event.key.mod.meta)
  257. str = TTR("Meta+") + str;
  258. if (p_event.key.mod.shift)
  259. str = TTR("Shift+") + str;
  260. if (p_event.key.mod.alt)
  261. str = TTR("Alt+") + str;
  262. if (p_event.key.mod.control)
  263. str = TTR("Control+") + str;
  264. press_a_key_label->set_text(str);
  265. press_a_key->accept_event();
  266. }
  267. }
  268. void ProjectSettings::_add_item(int p_item) {
  269. add_type = InputEvent::Type(p_item);
  270. switch (add_type) {
  271. case InputEvent::KEY: {
  272. press_a_key_label->set_text(TTR("Press a Key.."));
  273. last_wait_for_key = InputEvent();
  274. press_a_key->popup_centered(Size2(250, 80) * EDSCALE);
  275. press_a_key->grab_focus();
  276. } break;
  277. case InputEvent::MOUSE_BUTTON: {
  278. device_id->set_val(0);
  279. device_index_label->set_text(TTR("Mouse Button Index:"));
  280. device_index->clear();
  281. device_index->add_item(TTR("Left Button"));
  282. device_index->add_item(TTR("Right Button"));
  283. device_index->add_item(TTR("Middle Button"));
  284. device_index->add_item(TTR("Wheel Up Button"));
  285. device_index->add_item(TTR("Wheel Down Button"));
  286. device_index->add_item(TTR("Button 6"));
  287. device_index->add_item(TTR("Button 7"));
  288. device_index->add_item(TTR("Button 8"));
  289. device_index->add_item(TTR("Button 9"));
  290. device_input->popup_centered_minsize(Size2(350, 95));
  291. } break;
  292. case InputEvent::JOYSTICK_MOTION: {
  293. device_id->set_val(0);
  294. device_index_label->set_text(TTR("Joystick Axis Index:"));
  295. device_index->clear();
  296. for (int i = 0; i < JOY_AXIS_MAX * 2; i++) {
  297. String desc = _axis_names[i];
  298. device_index->add_item(TTR("Axis") + " " + itos(i / 2) + " " + (i & 1 ? "+" : "-") + desc);
  299. }
  300. device_input->popup_centered_minsize(Size2(350, 95));
  301. } break;
  302. case InputEvent::JOYSTICK_BUTTON: {
  303. device_id->set_val(0);
  304. device_index_label->set_text(TTR("Joystick Button Index:"));
  305. device_index->clear();
  306. for (int i = 0; i < JOY_BUTTON_MAX; i++) {
  307. device_index->add_item(itos(i) + ": " + String(_button_names[i]));
  308. }
  309. device_input->popup_centered_minsize(Size2(350, 95));
  310. } break;
  311. default: {}
  312. }
  313. }
  314. void ProjectSettings::_action_button_pressed(Object *p_obj, int p_column, int p_id) {
  315. TreeItem *ti = p_obj->cast_to<TreeItem>();
  316. ERR_FAIL_COND(!ti);
  317. if (p_id == 1) {
  318. Point2 ofs = input_editor->get_global_pos();
  319. Rect2 ir = input_editor->get_item_rect(ti);
  320. ir.pos.y -= input_editor->get_scroll().y;
  321. ofs += ir.pos + ir.size;
  322. ofs.x -= 100;
  323. popup_add->set_pos(ofs);
  324. popup_add->popup();
  325. add_at = "input/" + ti->get_text(0);
  326. } else if (p_id == 2) {
  327. //remove
  328. if (ti->get_parent() == input_editor->get_root()) {
  329. //remove main thing
  330. String name = "input/" + ti->get_text(0);
  331. Variant old_val = Globals::get_singleton()->get(name);
  332. int order = Globals::get_singleton()->get_order(name);
  333. undo_redo->create_action(TTR("Add Input Action"));
  334. undo_redo->add_do_method(Globals::get_singleton(), "clear", name);
  335. undo_redo->add_undo_method(Globals::get_singleton(), "set", name, old_val);
  336. undo_redo->add_undo_method(Globals::get_singleton(), "set_order", name, order);
  337. undo_redo->add_undo_method(Globals::get_singleton(), "set_persisting", name, Globals::get_singleton()->is_persisting(name));
  338. undo_redo->add_do_method(this, "_update_actions");
  339. undo_redo->add_undo_method(this, "_update_actions");
  340. undo_redo->add_do_method(this, "_settings_changed");
  341. undo_redo->add_undo_method(this, "_settings_changed");
  342. undo_redo->commit_action();
  343. } else {
  344. //remove action
  345. String name = "input/" + ti->get_parent()->get_text(0);
  346. Variant old_val = Globals::get_singleton()->get(name);
  347. int idx = ti->get_metadata(0);
  348. Array va = old_val;
  349. ERR_FAIL_INDEX(idx, va.size());
  350. for (int i = idx; i < va.size() - 1; i++) {
  351. va[i] = va[i + 1];
  352. }
  353. va.resize(va.size() - 1);
  354. undo_redo->create_action(TTR("Erase Input Action Event"));
  355. undo_redo->add_do_method(Globals::get_singleton(), "set", name, va);
  356. undo_redo->add_undo_method(Globals::get_singleton(), "set", name, old_val);
  357. undo_redo->add_do_method(this, "_update_actions");
  358. undo_redo->add_undo_method(this, "_update_actions");
  359. undo_redo->add_do_method(this, "_settings_changed");
  360. undo_redo->add_undo_method(this, "_settings_changed");
  361. undo_redo->commit_action();
  362. }
  363. }
  364. }
  365. void ProjectSettings::_update_actions() {
  366. if (setting)
  367. return;
  368. input_editor->clear();
  369. TreeItem *root = input_editor->create_item();
  370. input_editor->set_hide_root(true);
  371. List<PropertyInfo> props;
  372. Globals::get_singleton()->get_property_list(&props);
  373. for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
  374. const PropertyInfo &pi = E->get();
  375. if (!pi.name.begins_with("input/"))
  376. continue;
  377. String name = pi.name.get_slice("/", 1);
  378. if (name == "")
  379. continue;
  380. TreeItem *item = input_editor->create_item(root);
  381. //item->set_cell_mode(0,TreeItem::CELL_MODE_CHECK);
  382. item->set_text(0, name);
  383. item->add_button(0, get_icon("Add", "EditorIcons"), 1, false, TTR("Add Event"));
  384. if (!Globals::get_singleton()->get_input_presets().find(pi.name)) {
  385. item->add_button(0, get_icon("Remove", "EditorIcons"), 2, false, TTR("Remove"));
  386. item->set_editable(0, true);
  387. }
  388. item->set_custom_bg_color(0, get_color("prop_subsection", "Editor"));
  389. //item->set_checked(0,pi.usage&PROPERTY_USAGE_CHECKED);
  390. Array actions = Globals::get_singleton()->get(pi.name);
  391. for (int i = 0; i < actions.size(); i++) {
  392. if (actions[i].get_type() != Variant::INPUT_EVENT)
  393. continue;
  394. InputEvent ie = actions[i];
  395. TreeItem *action = input_editor->create_item(item);
  396. switch (ie.type) {
  397. case InputEvent::KEY: {
  398. String str = keycode_get_string(ie.key.scancode).capitalize();
  399. if (ie.key.mod.meta)
  400. str = TTR("Meta+") + str;
  401. if (ie.key.mod.shift)
  402. str = TTR("Shift+") + str;
  403. if (ie.key.mod.alt)
  404. str = TTR("Alt+") + str;
  405. if (ie.key.mod.control)
  406. str = TTR("Control+") + str;
  407. action->set_text(0, str);
  408. action->set_icon(0, get_icon("Keyboard", "EditorIcons"));
  409. } break;
  410. case InputEvent::JOYSTICK_BUTTON: {
  411. String str = TTR("Device") + " " + itos(ie.device) + ", " + TTR("Button") + " " + itos(ie.joy_button.button_index);
  412. if (ie.joy_button.button_index >= 0 && ie.joy_button.button_index < JOY_BUTTON_MAX)
  413. str += String() + " (" + _button_names[ie.joy_button.button_index] + ").";
  414. else
  415. str += ".";
  416. action->set_text(0, str);
  417. action->set_icon(0, get_icon("JoyButton", "EditorIcons"));
  418. } break;
  419. case InputEvent::MOUSE_BUTTON: {
  420. String str = TTR("Device") + " " + itos(ie.device) + ", ";
  421. switch (ie.mouse_button.button_index) {
  422. case BUTTON_LEFT: str += TTR("Left Button."); break;
  423. case BUTTON_RIGHT: str += TTR("Right Button."); break;
  424. case BUTTON_MIDDLE: str += TTR("Middle Button."); break;
  425. case BUTTON_WHEEL_UP: str += TTR("Wheel Up."); break;
  426. case BUTTON_WHEEL_DOWN: str += TTR("Wheel Down."); break;
  427. default: str += TTR("Button") + " " + itos(ie.mouse_button.button_index) + ".";
  428. }
  429. action->set_text(0, str);
  430. action->set_icon(0, get_icon("Mouse", "EditorIcons"));
  431. } break;
  432. case InputEvent::JOYSTICK_MOTION: {
  433. int ax = ie.joy_motion.axis;
  434. int n = 2 * ax + (ie.joy_motion.axis_value < 0 ? 0 : 1);
  435. String desc = _axis_names[n];
  436. String str = TTR("Device") + " " + itos(ie.device) + ", " + TTR("Axis") + " " + itos(ax) + " " + (ie.joy_motion.axis_value < 0 ? "-" : "+") + desc + ".";
  437. action->set_text(0, str);
  438. action->set_icon(0, get_icon("JoyAxis", "EditorIcons"));
  439. } break;
  440. }
  441. action->add_button(0, get_icon("Remove", "EditorIcons"), 2, false, TTR("Remove"));
  442. action->set_metadata(0, i);
  443. action->set_meta("__input", ie);
  444. }
  445. }
  446. }
  447. void ProjectSettings::popup_project_settings() {
  448. //popup_centered(Size2(500,400));
  449. popup_centered_ratio();
  450. globals_editor->update_category_list();
  451. _update_translations();
  452. autoload_settings->update_autoload();
  453. plugin_settings->update_plugins();
  454. }
  455. void ProjectSettings::_item_selected() {
  456. TreeItem *ti = globals_editor->get_property_editor()->get_scene_tree()->get_selected();
  457. if (!ti)
  458. return;
  459. if (!ti->get_parent())
  460. return;
  461. category->set_text(globals_editor->get_current_section());
  462. property->set_text(ti->get_text(0));
  463. popup_platform->set_disabled(false);
  464. }
  465. void ProjectSettings::_item_adds(String) {
  466. _item_add();
  467. }
  468. void ProjectSettings::_item_add() {
  469. Variant value;
  470. switch (type->get_selected()) {
  471. case 0: value = false; break;
  472. case 1: value = 0; break;
  473. case 2: value = 0.0; break;
  474. case 3: value = ""; break;
  475. }
  476. String catname = category->get_text().strip_edges();
  477. /*if (!catname.is_valid_identifier()) {
  478. message->set_text("Invalid Category.\nValid characters: a-z,A-Z,0-9 or _");
  479. message->popup_centered(Size2(300,100));
  480. return;
  481. }*/
  482. String propname = property->get_text().strip_edges();
  483. /*if (!propname.is_valid_identifier()) {
  484. message->set_text("Invalid Property.\nValid characters: a-z,A-Z,0-9 or _");
  485. message->popup_centered(Size2(300,100));
  486. return;
  487. }*/
  488. String name = catname != "" ? catname + "/" + propname : propname;
  489. undo_redo->create_action("Add Global Property");
  490. undo_redo->add_do_property(Globals::get_singleton(), name, value);
  491. undo_redo->add_do_method(Globals::get_singleton(), "set_persisting", name, true);
  492. if (Globals::get_singleton()->has(name)) {
  493. undo_redo->add_undo_property(Globals::get_singleton(), name, Globals::get_singleton()->get(name));
  494. } else {
  495. undo_redo->add_undo_property(Globals::get_singleton(), name, Variant());
  496. }
  497. undo_redo->add_do_method(globals_editor, "update_category_list");
  498. undo_redo->add_undo_method(globals_editor, "update_category_list");
  499. undo_redo->add_do_method(this, "_settings_changed");
  500. undo_redo->add_undo_method(this, "_settings_changed");
  501. undo_redo->commit_action();
  502. globals_editor->set_current_section(catname);
  503. _settings_changed();
  504. }
  505. void ProjectSettings::_item_del() {
  506. String catname = category->get_text().strip_edges();
  507. //ERR_FAIL_COND(!catname.is_valid_identifier());
  508. String propname = property->get_text().strip_edges();
  509. //ERR_FAIL_COND(!propname.is_valid_identifier());
  510. String name = catname != "" ? catname + "/" + propname : propname;
  511. undo_redo->create_action("Delete Global Property");
  512. undo_redo->add_do_property(Globals::get_singleton(), name, Variant());
  513. undo_redo->add_undo_property(Globals::get_singleton(), name, Globals::get_singleton()->get(name));
  514. undo_redo->add_undo_method(Globals::get_singleton(), "set_persisting", name, Globals::get_singleton()->is_persisting(name));
  515. undo_redo->add_do_method(globals_editor, "update_category_list");
  516. undo_redo->add_undo_method(globals_editor, "update_category_list");
  517. undo_redo->add_do_method(this, "_settings_changed");
  518. undo_redo->add_undo_method(this, "_settings_changed");
  519. undo_redo->commit_action();
  520. _settings_changed();
  521. }
  522. void ProjectSettings::_action_adds(String) {
  523. _action_add();
  524. }
  525. void ProjectSettings::_action_add() {
  526. String action = action_name->get_text();
  527. if (action.find("/") != -1 || action.find(":") != -1 || action == "") {
  528. message->set_text(TTR("Invalid action (anything goes but '/' or ':')."));
  529. message->popup_centered(Size2(300, 100));
  530. return;
  531. }
  532. if (Globals::get_singleton()->has("input/" + action)) {
  533. message->set_text(vformat(TTR("Action '%s' already exists!"), action));
  534. message->popup_centered(Size2(300, 100));
  535. return;
  536. }
  537. Array va;
  538. String name = "input/" + action;
  539. undo_redo->create_action(TTR("Add Input Action Event"));
  540. undo_redo->add_do_method(Globals::get_singleton(), "set", name, va);
  541. undo_redo->add_do_method(Globals::get_singleton(), "set_persisting", name, true);
  542. undo_redo->add_undo_method(Globals::get_singleton(), "clear", name);
  543. undo_redo->add_do_method(this, "_update_actions");
  544. undo_redo->add_undo_method(this, "_update_actions");
  545. undo_redo->add_do_method(this, "_settings_changed");
  546. undo_redo->add_undo_method(this, "_settings_changed");
  547. undo_redo->commit_action();
  548. TreeItem *r = input_editor->get_root();
  549. if (!r)
  550. return;
  551. r = r->get_children();
  552. if (!r)
  553. return;
  554. while (r->get_next())
  555. r = r->get_next();
  556. if (!r)
  557. return;
  558. r->select(0);
  559. input_editor->ensure_cursor_is_visible();
  560. }
  561. void ProjectSettings::_item_checked(const String &p_item, bool p_check) {
  562. undo_redo->create_action(TTR("Toggle Persisting"));
  563. String full_item = globals_editor->get_full_item_path(p_item);
  564. undo_redo->add_do_method(Globals::get_singleton(), "set_persisting", full_item, p_check);
  565. undo_redo->add_undo_method(Globals::get_singleton(), "set_persisting", full_item, !p_check);
  566. undo_redo->add_do_method(this, "_settings_changed");
  567. undo_redo->add_undo_method(this, "_settings_changed");
  568. undo_redo->add_do_method(globals_editor->get_property_editor(), "update_tree");
  569. undo_redo->add_undo_method(globals_editor->get_property_editor(), "update_tree");
  570. undo_redo->commit_action();
  571. }
  572. void ProjectSettings::_save() {
  573. Error err = Globals::get_singleton()->save();
  574. message->set_text(err != OK ? TTR("Error saving settings.") : TTR("Settings saved OK."));
  575. message->popup_centered(Size2(300, 100));
  576. }
  577. void ProjectSettings::_settings_prop_edited(const String &p_name) {
  578. String full_item = globals_editor->get_full_item_path(p_name);
  579. if (!Globals::get_singleton()->is_persisting(full_item)) {
  580. Globals::get_singleton()->set_persisting(full_item, true);
  581. {
  582. //small usability workaround, if anything related to resolution scaling or size is modified, change all of them together
  583. if (full_item == "display/width" || full_item == "display/height" || full_item == "display/stretch_mode") {
  584. Globals::get_singleton()->set_persisting("display/height", true);
  585. Globals::get_singleton()->set_persisting("display/width", true);
  586. }
  587. }
  588. // globals_editor->update_property(p_name);
  589. globals_editor->get_property_editor()->update_tree();
  590. }
  591. _settings_changed();
  592. }
  593. void ProjectSettings::_settings_changed() {
  594. timer->start();
  595. }
  596. void ProjectSettings::queue_save() {
  597. _settings_changed();
  598. }
  599. void ProjectSettings::_copy_to_platform(int p_which) {
  600. String catname = category->get_text();
  601. if (!catname.is_valid_identifier()) {
  602. message->set_text("Invalid Category.\nValid characters: a-z,A-Z,0-9 or _");
  603. message->popup_centered(Size2(300, 100));
  604. return;
  605. }
  606. String propname = property->get_text();
  607. if (!propname.is_valid_identifier()) {
  608. message->set_text("Invalid Property.\nValid characters: a-z,A-Z,0-9 or _");
  609. message->popup_centered(Size2(300, 100));
  610. return;
  611. }
  612. String name = catname + "/" + propname;
  613. Variant value = Globals::get_singleton()->get(name);
  614. catname += "." + popup_platform->get_popup()->get_item_text(p_which);
  615. name = catname + "/" + propname;
  616. Globals::get_singleton()->set(name, value);
  617. globals_editor->get_property_editor()->update_tree();
  618. }
  619. void ProjectSettings::add_translation(const String &p_translation) {
  620. _translation_add(p_translation);
  621. }
  622. void ProjectSettings::_translation_add(const String &p_path) {
  623. StringArray translations = Globals::get_singleton()->get("locale/translations");
  624. for (int i = 0; i < translations.size(); i++) {
  625. if (translations[i] == p_path)
  626. return; //exists
  627. }
  628. translations.push_back(p_path);
  629. undo_redo->create_action(TTR("Add Translation"));
  630. undo_redo->add_do_property(Globals::get_singleton(), "locale/translations", translations);
  631. undo_redo->add_undo_property(Globals::get_singleton(), "locale/translations", Globals::get_singleton()->get("locale/translations"));
  632. undo_redo->add_do_method(Globals::get_singleton(), "set_persisting", "locale/translations", true);
  633. undo_redo->add_do_method(this, "_update_translations");
  634. undo_redo->add_undo_method(this, "_update_translations");
  635. undo_redo->add_do_method(this, "_settings_changed");
  636. undo_redo->add_undo_method(this, "_settings_changed");
  637. undo_redo->commit_action();
  638. }
  639. void ProjectSettings::_translation_file_open() {
  640. translation_file_open->popup_centered_ratio();
  641. }
  642. void ProjectSettings::_translation_delete(Object *p_item, int p_column, int p_button) {
  643. TreeItem *ti = p_item->cast_to<TreeItem>();
  644. ERR_FAIL_COND(!ti);
  645. int idx = ti->get_metadata(0);
  646. StringArray translations = Globals::get_singleton()->get("locale/translations");
  647. ERR_FAIL_INDEX(idx, translations.size());
  648. translations.remove(idx);
  649. undo_redo->create_action(TTR("Remove Translation"));
  650. undo_redo->add_do_property(Globals::get_singleton(), "locale/translations", translations);
  651. undo_redo->add_undo_property(Globals::get_singleton(), "locale/translations", Globals::get_singleton()->get("locale/translations"));
  652. undo_redo->add_do_method(this, "_update_translations");
  653. undo_redo->add_undo_method(this, "_update_translations");
  654. undo_redo->add_do_method(this, "_settings_changed");
  655. undo_redo->add_undo_method(this, "_settings_changed");
  656. undo_redo->commit_action();
  657. }
  658. void ProjectSettings::_translation_res_file_open() {
  659. translation_res_file_open->popup_centered_ratio();
  660. }
  661. void ProjectSettings::_translation_res_add(const String &p_path) {
  662. Variant prev;
  663. Dictionary remaps;
  664. if (Globals::get_singleton()->has("locale/translation_remaps")) {
  665. remaps = Globals::get_singleton()->get("locale/translation_remaps");
  666. prev = remaps;
  667. }
  668. if (remaps.has(p_path))
  669. return; //pointless already has it
  670. remaps[p_path] = StringArray();
  671. undo_redo->create_action(TTR("Add Remapped Path"));
  672. undo_redo->add_do_property(Globals::get_singleton(), "locale/translation_remaps", remaps);
  673. undo_redo->add_do_method(Globals::get_singleton(), "set_persisting", "locale/translation_remaps", true);
  674. undo_redo->add_undo_property(Globals::get_singleton(), "locale/translation_remaps", prev);
  675. undo_redo->add_do_method(this, "_update_translations");
  676. undo_redo->add_undo_method(this, "_update_translations");
  677. undo_redo->add_do_method(this, "_settings_changed");
  678. undo_redo->add_undo_method(this, "_settings_changed");
  679. undo_redo->commit_action();
  680. }
  681. void ProjectSettings::_translation_res_option_file_open() {
  682. translation_res_option_file_open->popup_centered_ratio();
  683. }
  684. void ProjectSettings::_translation_res_option_add(const String &p_path) {
  685. ERR_FAIL_COND(!Globals::get_singleton()->has("locale/translation_remaps"));
  686. Dictionary remaps = Globals::get_singleton()->get("locale/translation_remaps");
  687. TreeItem *k = translation_remap->get_selected();
  688. ERR_FAIL_COND(!k);
  689. String key = k->get_metadata(0);
  690. ERR_FAIL_COND(!remaps.has(key));
  691. StringArray r = remaps[key];
  692. r.push_back(p_path + ":" + "en");
  693. remaps[key] = r;
  694. undo_redo->create_action(TTR("Resource Remap Add Remap"));
  695. undo_redo->add_do_property(Globals::get_singleton(), "locale/translation_remaps", remaps);
  696. undo_redo->add_do_method(Globals::get_singleton(), "set_persisting", "locale/translation_remaps", true);
  697. undo_redo->add_undo_property(Globals::get_singleton(), "locale/translation_remaps", Globals::get_singleton()->get("locale/translation_remaps"));
  698. undo_redo->add_do_method(this, "_update_translations");
  699. undo_redo->add_undo_method(this, "_update_translations");
  700. undo_redo->add_do_method(this, "_settings_changed");
  701. undo_redo->add_undo_method(this, "_settings_changed");
  702. undo_redo->commit_action();
  703. }
  704. void ProjectSettings::_translation_res_select() {
  705. if (updating_translations)
  706. return;
  707. call_deferred("_update_translations");
  708. }
  709. void ProjectSettings::_translation_res_option_changed() {
  710. if (updating_translations)
  711. return;
  712. if (!Globals::get_singleton()->has("locale/translation_remaps"))
  713. return;
  714. Dictionary remaps = Globals::get_singleton()->get("locale/translation_remaps");
  715. TreeItem *k = translation_remap->get_selected();
  716. ERR_FAIL_COND(!k);
  717. TreeItem *ed = translation_remap_options->get_edited();
  718. ERR_FAIL_COND(!ed);
  719. String key = k->get_metadata(0);
  720. int idx = ed->get_metadata(0);
  721. String path = ed->get_metadata(1);
  722. int which = ed->get_range(1);
  723. Vector<String> langs = TranslationServer::get_all_locales();
  724. ERR_FAIL_INDEX(which, langs.size());
  725. ERR_FAIL_COND(!remaps.has(key));
  726. StringArray r = remaps[key];
  727. ERR_FAIL_INDEX(idx, r.size());
  728. r.set(idx, path + ":" + langs[which]);
  729. remaps[key] = r;
  730. updating_translations = true;
  731. undo_redo->create_action(TTR("Change Resource Remap Language"));
  732. undo_redo->add_do_property(Globals::get_singleton(), "locale/translation_remaps", remaps);
  733. undo_redo->add_do_method(Globals::get_singleton(), "set_persisting", "locale/translation_remaps", true);
  734. undo_redo->add_undo_property(Globals::get_singleton(), "locale/translation_remaps", Globals::get_singleton()->get("locale/translation_remaps"));
  735. undo_redo->add_do_method(this, "_update_translations");
  736. undo_redo->add_undo_method(this, "_update_translations");
  737. undo_redo->add_do_method(this, "_settings_changed");
  738. undo_redo->add_undo_method(this, "_settings_changed");
  739. undo_redo->commit_action();
  740. updating_translations = false;
  741. }
  742. void ProjectSettings::_translation_res_delete(Object *p_item, int p_column, int p_button) {
  743. if (updating_translations)
  744. return;
  745. if (!Globals::get_singleton()->has("locale/translation_remaps"))
  746. return;
  747. Dictionary remaps = Globals::get_singleton()->get("locale/translation_remaps");
  748. TreeItem *k = p_item->cast_to<TreeItem>();
  749. String key = k->get_metadata(0);
  750. ERR_FAIL_COND(!remaps.has(key));
  751. remaps.erase(key);
  752. undo_redo->create_action(TTR("Remove Resource Remap"));
  753. undo_redo->add_do_property(Globals::get_singleton(), "locale/translation_remaps", remaps);
  754. undo_redo->add_do_method(Globals::get_singleton(), "set_persisting", "locale/translation_remaps", true);
  755. undo_redo->add_undo_property(Globals::get_singleton(), "locale/translation_remaps", Globals::get_singleton()->get("locale/translation_remaps"));
  756. undo_redo->add_do_method(this, "_update_translations");
  757. undo_redo->add_undo_method(this, "_update_translations");
  758. undo_redo->add_do_method(this, "_settings_changed");
  759. undo_redo->add_undo_method(this, "_settings_changed");
  760. undo_redo->commit_action();
  761. }
  762. void ProjectSettings::_translation_res_option_delete(Object *p_item, int p_column, int p_button) {
  763. if (updating_translations)
  764. return;
  765. if (!Globals::get_singleton()->has("locale/translation_remaps"))
  766. return;
  767. Dictionary remaps = Globals::get_singleton()->get("locale/translation_remaps");
  768. TreeItem *k = translation_remap->get_selected();
  769. ERR_FAIL_COND(!k);
  770. TreeItem *ed = p_item->cast_to<TreeItem>();
  771. ERR_FAIL_COND(!ed);
  772. String key = k->get_metadata(0);
  773. int idx = ed->get_metadata(0);
  774. ERR_FAIL_COND(!remaps.has(key));
  775. StringArray r = remaps[key];
  776. ERR_FAIL_INDEX(idx, remaps.size());
  777. r.remove(idx);
  778. remaps[key] = r;
  779. undo_redo->create_action(TTR("Remove Resource Remap Option"));
  780. undo_redo->add_do_property(Globals::get_singleton(), "locale/translation_remaps", remaps);
  781. undo_redo->add_do_method(Globals::get_singleton(), "set_persisting", "locale/translation_remaps", true);
  782. undo_redo->add_undo_property(Globals::get_singleton(), "locale/translation_remaps", Globals::get_singleton()->get("locale/translation_remaps"));
  783. undo_redo->add_do_method(this, "_update_translations");
  784. undo_redo->add_undo_method(this, "_update_translations");
  785. undo_redo->add_do_method(this, "_settings_changed");
  786. undo_redo->add_undo_method(this, "_settings_changed");
  787. undo_redo->commit_action();
  788. }
  789. void ProjectSettings::_update_translations() {
  790. //update translations
  791. if (updating_translations)
  792. return;
  793. updating_translations = true;
  794. translation_list->clear();
  795. TreeItem *root = translation_list->create_item(NULL);
  796. translation_list->set_hide_root(true);
  797. if (Globals::get_singleton()->has("locale/translations")) {
  798. StringArray translations = Globals::get_singleton()->get("locale/translations");
  799. for (int i = 0; i < translations.size(); i++) {
  800. TreeItem *t = translation_list->create_item(root);
  801. t->set_editable(0, false);
  802. t->set_text(0, translations[i].replace_first("res://", ""));
  803. t->set_tooltip(0, translations[i]);
  804. t->set_metadata(0, i);
  805. t->add_button(0, get_icon("Del", "EditorIcons"), 0, false, TTR("Remove"));
  806. }
  807. }
  808. //update translation remaps
  809. String remap_selected;
  810. if (translation_remap->get_selected()) {
  811. remap_selected = translation_remap->get_selected()->get_metadata(0);
  812. }
  813. translation_remap->clear();
  814. translation_remap_options->clear();
  815. root = translation_remap->create_item(NULL);
  816. TreeItem *root2 = translation_remap_options->create_item(NULL);
  817. translation_remap->set_hide_root(true);
  818. translation_remap_options->set_hide_root(true);
  819. translation_res_option_add_button->set_disabled(true);
  820. Vector<String> langs = TranslationServer::get_all_locales();
  821. Vector<String> names = TranslationServer::get_all_locale_names();
  822. String langnames;
  823. for (int i = 0; i < names.size(); i++) {
  824. if (i > 0)
  825. langnames += ",";
  826. langnames += names[i];
  827. }
  828. if (Globals::get_singleton()->has("locale/translation_remaps")) {
  829. Dictionary remaps = Globals::get_singleton()->get("locale/translation_remaps");
  830. List<Variant> rk;
  831. remaps.get_key_list(&rk);
  832. Vector<String> keys;
  833. for (List<Variant>::Element *E = rk.front(); E; E = E->next()) {
  834. keys.push_back(E->get());
  835. }
  836. keys.sort();
  837. for (int i = 0; i < keys.size(); i++) {
  838. TreeItem *t = translation_remap->create_item(root);
  839. t->set_editable(0, false);
  840. t->set_text(0, keys[i].replace_first("res://", ""));
  841. t->set_tooltip(0, keys[i]);
  842. t->set_metadata(0, keys[i]);
  843. t->add_button(0, get_icon("Del", "EditorIcons"), 0, false, TTR("Remove"));
  844. if (keys[i] == remap_selected) {
  845. t->select(0);
  846. translation_res_option_add_button->set_disabled(false);
  847. StringArray selected = remaps[keys[i]];
  848. for (int j = 0; j < selected.size(); j++) {
  849. String s = selected[j];
  850. int qp = s.find_last(":");
  851. String path = s.substr(0, qp);
  852. String locale = s.substr(qp + 1, s.length());
  853. TreeItem *t2 = translation_remap_options->create_item(root2);
  854. t2->set_editable(0, false);
  855. t2->set_text(0, path.replace_first("res://", ""));
  856. t2->set_tooltip(0, path);
  857. t2->set_metadata(0, j);
  858. t2->add_button(0, get_icon("Del", "EditorIcons"), 0, false, TTR("Remove"));
  859. t2->set_cell_mode(1, TreeItem::CELL_MODE_RANGE);
  860. t2->set_text(1, langnames);
  861. t2->set_editable(1, true);
  862. t2->set_metadata(1, path);
  863. int idx = langs.find(locale);
  864. print_line("find " + locale + " at " + itos(idx));
  865. if (idx < 0)
  866. idx = 0;
  867. t2->set_range(1, idx);
  868. }
  869. }
  870. }
  871. }
  872. updating_translations = false;
  873. }
  874. void ProjectSettings::_toggle_search_bar(bool p_pressed) {
  875. globals_editor->get_property_editor()->set_use_filter(p_pressed);
  876. if (p_pressed) {
  877. search_bar->show();
  878. add_prop_bar->hide();
  879. search_box->grab_focus();
  880. search_box->select_all();
  881. } else {
  882. search_bar->hide();
  883. add_prop_bar->show();
  884. }
  885. }
  886. void ProjectSettings::_clear_search_box() {
  887. if (search_box->get_text() == "")
  888. return;
  889. search_box->clear();
  890. globals_editor->get_property_editor()->update_tree();
  891. }
  892. void ProjectSettings::set_plugins_page() {
  893. tab_container->set_current_tab(plugin_settings->get_index());
  894. }
  895. void ProjectSettings::_bind_methods() {
  896. ObjectTypeDB::bind_method(_MD("_item_selected"), &ProjectSettings::_item_selected);
  897. ObjectTypeDB::bind_method(_MD("_item_add"), &ProjectSettings::_item_add);
  898. ObjectTypeDB::bind_method(_MD("_item_adds"), &ProjectSettings::_item_adds);
  899. ObjectTypeDB::bind_method(_MD("_item_del"), &ProjectSettings::_item_del);
  900. ObjectTypeDB::bind_method(_MD("_item_checked"), &ProjectSettings::_item_checked);
  901. ObjectTypeDB::bind_method(_MD("_save"), &ProjectSettings::_save);
  902. ObjectTypeDB::bind_method(_MD("_action_add"), &ProjectSettings::_action_add);
  903. ObjectTypeDB::bind_method(_MD("_action_adds"), &ProjectSettings::_action_adds);
  904. ObjectTypeDB::bind_method(_MD("_action_selected"), &ProjectSettings::_action_selected);
  905. ObjectTypeDB::bind_method(_MD("_action_edited"), &ProjectSettings::_action_edited);
  906. ObjectTypeDB::bind_method(_MD("_action_button_pressed"), &ProjectSettings::_action_button_pressed);
  907. ObjectTypeDB::bind_method(_MD("_update_actions"), &ProjectSettings::_update_actions);
  908. ObjectTypeDB::bind_method(_MD("_wait_for_key"), &ProjectSettings::_wait_for_key);
  909. ObjectTypeDB::bind_method(_MD("_add_item"), &ProjectSettings::_add_item);
  910. ObjectTypeDB::bind_method(_MD("_device_input_add"), &ProjectSettings::_device_input_add);
  911. ObjectTypeDB::bind_method(_MD("_press_a_key_confirm"), &ProjectSettings::_press_a_key_confirm);
  912. ObjectTypeDB::bind_method(_MD("_settings_prop_edited"), &ProjectSettings::_settings_prop_edited);
  913. ObjectTypeDB::bind_method(_MD("_copy_to_platform"), &ProjectSettings::_copy_to_platform);
  914. ObjectTypeDB::bind_method(_MD("_update_translations"), &ProjectSettings::_update_translations);
  915. ObjectTypeDB::bind_method(_MD("_translation_delete"), &ProjectSettings::_translation_delete);
  916. ObjectTypeDB::bind_method(_MD("_settings_changed"), &ProjectSettings::_settings_changed);
  917. ObjectTypeDB::bind_method(_MD("_translation_add"), &ProjectSettings::_translation_add);
  918. ObjectTypeDB::bind_method(_MD("_translation_file_open"), &ProjectSettings::_translation_file_open);
  919. ObjectTypeDB::bind_method(_MD("_translation_res_add"), &ProjectSettings::_translation_res_add);
  920. ObjectTypeDB::bind_method(_MD("_translation_res_file_open"), &ProjectSettings::_translation_res_file_open);
  921. ObjectTypeDB::bind_method(_MD("_translation_res_option_add"), &ProjectSettings::_translation_res_option_add);
  922. ObjectTypeDB::bind_method(_MD("_translation_res_option_file_open"), &ProjectSettings::_translation_res_option_file_open);
  923. ObjectTypeDB::bind_method(_MD("_translation_res_select"), &ProjectSettings::_translation_res_select);
  924. ObjectTypeDB::bind_method(_MD("_translation_res_option_changed"), &ProjectSettings::_translation_res_option_changed);
  925. ObjectTypeDB::bind_method(_MD("_translation_res_delete"), &ProjectSettings::_translation_res_delete);
  926. ObjectTypeDB::bind_method(_MD("_translation_res_option_delete"), &ProjectSettings::_translation_res_option_delete);
  927. ObjectTypeDB::bind_method(_MD("_clear_search_box"), &ProjectSettings::_clear_search_box);
  928. ObjectTypeDB::bind_method(_MD("_toggle_search_bar"), &ProjectSettings::_toggle_search_bar);
  929. }
  930. ProjectSettings::ProjectSettings(EditorData *p_data) {
  931. singleton = this;
  932. set_title(TTR("Project Settings (engine.cfg)"));
  933. undo_redo = &p_data->get_undo_redo();
  934. data = p_data;
  935. tab_container = memnew(TabContainer);
  936. add_child(tab_container);
  937. set_child_rect(tab_container);
  938. //tab_container->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_BEGIN, 15 );
  939. //tab_container->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END, 15 );
  940. //tab_container->set_anchor_and_margin(MARGIN_TOP,ANCHOR_BEGIN, 15 );
  941. //tab_container->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_END, 35 );
  942. VBoxContainer *props_base = memnew(VBoxContainer);
  943. props_base->set_alignment(BoxContainer::ALIGN_BEGIN);
  944. props_base->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  945. tab_container->add_child(props_base);
  946. props_base->set_name(TTR("General"));
  947. HBoxContainer *hbc = memnew(HBoxContainer);
  948. hbc->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  949. props_base->add_child(hbc);
  950. search_button = memnew(ToolButton);
  951. search_button->set_toggle_mode(true);
  952. search_button->set_pressed(false);
  953. search_button->set_text(TTR("Search"));
  954. hbc->add_child(search_button);
  955. search_button->connect("toggled", this, "_toggle_search_bar");
  956. hbc->add_child(memnew(VSeparator));
  957. add_prop_bar = memnew(HBoxContainer);
  958. add_prop_bar->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  959. hbc->add_child(add_prop_bar);
  960. Label *l = memnew(Label);
  961. add_prop_bar->add_child(l);
  962. l->set_text(TTR("Category:"));
  963. category = memnew(LineEdit);
  964. category->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  965. add_prop_bar->add_child(category);
  966. category->connect("text_entered", this, "_item_adds");
  967. l = memnew(Label);
  968. add_prop_bar->add_child(l);
  969. l->set_text(TTR("Property:"));
  970. property = memnew(LineEdit);
  971. property->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  972. add_prop_bar->add_child(property);
  973. property->connect("text_entered", this, "_item_adds");
  974. l = memnew(Label);
  975. add_prop_bar->add_child(l);
  976. l->set_text(TTR("Type:"));
  977. type = memnew(OptionButton);
  978. type->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  979. add_prop_bar->add_child(type);
  980. type->add_item("bool");
  981. type->add_item("int");
  982. type->add_item("float");
  983. type->add_item("string");
  984. Button *add = memnew(Button);
  985. add_prop_bar->add_child(add);
  986. add->set_text(TTR("Add"));
  987. add->connect("pressed", this, "_item_add");
  988. Button *del = memnew(Button);
  989. add_prop_bar->add_child(del);
  990. del->set_text(TTR("Del"));
  991. del->connect("pressed", this, "_item_del");
  992. search_bar = memnew(HBoxContainer);
  993. search_bar->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  994. hbc->add_child(search_bar);
  995. search_bar->hide();
  996. search_box = memnew(LineEdit);
  997. search_box->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  998. search_bar->add_child(search_box);
  999. clear_button = memnew(ToolButton);
  1000. search_bar->add_child(clear_button);
  1001. clear_button->connect("pressed", this, "_clear_search_box");
  1002. globals_editor = memnew(SectionedPropertyEditor);
  1003. props_base->add_child(globals_editor);
  1004. //globals_editor->hide_top_label();
  1005. globals_editor->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1006. globals_editor->get_property_editor()->register_text_enter(search_box);
  1007. globals_editor->get_property_editor()->get_scene_tree()->connect("cell_selected", this, "_item_selected");
  1008. globals_editor->get_property_editor()->connect("property_toggled", this, "_item_checked", varray(), CONNECT_DEFERRED);
  1009. globals_editor->get_property_editor()->connect("property_edited", this, "_settings_prop_edited");
  1010. /*
  1011. Button *save = memnew( Button );
  1012. props_base->add_child(save);
  1013. save->set_anchor(MARGIN_LEFT,ANCHOR_END);
  1014. save->set_anchor(MARGIN_RIGHT,ANCHOR_END);
  1015. save->set_anchor(MARGIN_TOP,ANCHOR_END);
  1016. save->set_anchor(MARGIN_BOTTOM,ANCHOR_END);
  1017. save->set_begin( Point2(80,28) );
  1018. save->set_end( Point2(10,20) );
  1019. save->set_text("Save");
  1020. save->connect("pressed",this,"_save");
  1021. */
  1022. hbc = memnew(HBoxContainer);
  1023. props_base->add_child(hbc);
  1024. popup_platform = memnew(MenuButton);
  1025. popup_platform->set_text(TTR("Copy To Platform.."));
  1026. popup_platform->set_disabled(true);
  1027. hbc->add_child(popup_platform);
  1028. hbc->add_spacer();
  1029. List<StringName> ep;
  1030. EditorImportExport::get_singleton()->get_export_platforms(&ep);
  1031. ep.sort_custom<StringName::AlphCompare>();
  1032. for (List<StringName>::Element *E = ep.front(); E; E = E->next()) {
  1033. popup_platform->get_popup()->add_item(E->get());
  1034. }
  1035. popup_platform->get_popup()->connect("item_pressed", this, "_copy_to_platform");
  1036. get_ok()->set_text(TTR("Close"));
  1037. set_hide_on_ok(true);
  1038. message = memnew(ConfirmationDialog);
  1039. add_child(message);
  1040. // message->get_cancel()->hide();
  1041. message->set_hide_on_ok(true);
  1042. Control *input_base = memnew(Control);
  1043. input_base->set_name(TTR("Input Map"));
  1044. input_base->set_area_as_parent_rect();
  1045. tab_container->add_child(input_base);
  1046. VBoxContainer *vbc = memnew(VBoxContainer);
  1047. input_base->add_child(vbc);
  1048. vbc->set_anchor_and_margin(MARGIN_TOP, ANCHOR_BEGIN, 5);
  1049. vbc->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, 5);
  1050. vbc->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_BEGIN, 5);
  1051. vbc->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, 5);
  1052. l = memnew(Label);
  1053. vbc->add_child(l);
  1054. l->set_pos(Point2(6, 5));
  1055. l->set_text(TTR("Action:"));
  1056. hbc = memnew(HBoxContainer);
  1057. vbc->add_child(hbc);
  1058. action_name = memnew(LineEdit);
  1059. action_name->set_h_size_flags(SIZE_EXPAND_FILL);
  1060. hbc->add_child(action_name);
  1061. action_name->connect("text_entered", this, "_action_adds");
  1062. add = memnew(Button);
  1063. hbc->add_child(add);
  1064. add->set_custom_minimum_size(Size2(150, 0));
  1065. add->set_text(TTR("Add"));
  1066. add->connect("pressed", this, "_action_add");
  1067. input_editor = memnew(Tree);
  1068. vbc->add_child(input_editor);
  1069. input_editor->set_v_size_flags(SIZE_EXPAND_FILL);
  1070. input_editor->connect("item_edited", this, "_action_edited");
  1071. input_editor->connect("cell_selected", this, "_action_selected");
  1072. input_editor->connect("button_pressed", this, "_action_button_pressed");
  1073. popup_add = memnew(PopupMenu);
  1074. add_child(popup_add);
  1075. popup_add->connect("item_pressed", this, "_add_item");
  1076. press_a_key = memnew(ConfirmationDialog);
  1077. press_a_key->set_focus_mode(FOCUS_ALL);
  1078. add_child(press_a_key);
  1079. l = memnew(Label);
  1080. l->set_text(TTR("Press a Key.."));
  1081. l->set_area_as_parent_rect();
  1082. l->set_align(Label::ALIGN_CENTER);
  1083. l->set_margin(MARGIN_TOP, 20);
  1084. l->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_BEGIN, 30);
  1085. press_a_key_label = l;
  1086. press_a_key->add_child(l);
  1087. press_a_key->connect("input_event", this, "_wait_for_key");
  1088. press_a_key->connect("confirmed", this, "_press_a_key_confirm");
  1089. device_input = memnew(ConfirmationDialog);
  1090. add_child(device_input);
  1091. device_input->get_ok()->set_text(TTR("Add"));
  1092. device_input->connect("confirmed", this, "_device_input_add");
  1093. hbc = memnew(HBoxContainer);
  1094. device_input->add_child(hbc);
  1095. device_input->set_child_rect(hbc);
  1096. VBoxContainer *vbc_left = memnew(VBoxContainer);
  1097. hbc->add_child(vbc_left);
  1098. l = memnew(Label);
  1099. l->set_text(TTR("Device:"));
  1100. vbc_left->add_child(l);
  1101. device_id = memnew(SpinBox);
  1102. device_id->set_val(0);
  1103. vbc_left->add_child(device_id);
  1104. VBoxContainer *vbc_right = memnew(VBoxContainer);
  1105. hbc->add_child(vbc_right);
  1106. vbc_right->set_h_size_flags(SIZE_EXPAND_FILL);
  1107. l = memnew(Label);
  1108. l->set_text(TTR("Index:"));
  1109. vbc_right->add_child(l);
  1110. device_index_label = l;
  1111. device_index = memnew(OptionButton);
  1112. vbc_right->add_child(device_index);
  1113. /*
  1114. save = memnew( Button );
  1115. input_base->add_child(save);
  1116. save->set_anchor(MARGIN_LEFT,ANCHOR_END);
  1117. save->set_anchor(MARGIN_RIGHT,ANCHOR_END);
  1118. save->set_anchor(MARGIN_TOP,ANCHOR_END);
  1119. save->set_anchor(MARGIN_BOTTOM,ANCHOR_END);
  1120. save->set_begin( Point2(80,28) );
  1121. save->set_end( Point2(10,20) );
  1122. save->set_text("Save");
  1123. save->connect("pressed",this,"_save");
  1124. */
  1125. setting = false;
  1126. //translations
  1127. TabContainer *translations = memnew(TabContainer);
  1128. translations->set_name(TTR("Localization"));
  1129. tab_container->add_child(translations);
  1130. {
  1131. VBoxContainer *tvb = memnew(VBoxContainer);
  1132. translations->add_child(tvb);
  1133. tvb->set_name(TTR("Translations"));
  1134. HBoxContainer *thb = memnew(HBoxContainer);
  1135. tvb->add_child(thb);
  1136. thb->add_child(memnew(Label(TTR("Translations:"))));
  1137. thb->add_spacer();
  1138. Button *addtr = memnew(Button(TTR("Add..")));
  1139. addtr->connect("pressed", this, "_translation_file_open");
  1140. thb->add_child(addtr);
  1141. MarginContainer *tmc = memnew(MarginContainer);
  1142. tvb->add_child(tmc);
  1143. tmc->set_v_size_flags(SIZE_EXPAND_FILL);
  1144. translation_list = memnew(Tree);
  1145. translation_list->set_v_size_flags(SIZE_EXPAND_FILL);
  1146. tmc->add_child(translation_list);
  1147. translation_file_open = memnew(EditorFileDialog);
  1148. add_child(translation_file_open);
  1149. translation_file_open->set_mode(EditorFileDialog::MODE_OPEN_FILE);
  1150. translation_file_open->connect("file_selected", this, "_translation_add");
  1151. }
  1152. {
  1153. VBoxContainer *tvb = memnew(VBoxContainer);
  1154. translations->add_child(tvb);
  1155. tvb->set_name(TTR("Remaps"));
  1156. HBoxContainer *thb = memnew(HBoxContainer);
  1157. tvb->add_child(thb);
  1158. thb->add_child(memnew(Label(TTR("Resources:"))));
  1159. thb->add_spacer();
  1160. Button *addtr = memnew(Button(TTR("Add..")));
  1161. addtr->connect("pressed", this, "_translation_res_file_open");
  1162. thb->add_child(addtr);
  1163. MarginContainer *tmc = memnew(MarginContainer);
  1164. tvb->add_child(tmc);
  1165. tmc->set_v_size_flags(SIZE_EXPAND_FILL);
  1166. translation_remap = memnew(Tree);
  1167. translation_remap->set_v_size_flags(SIZE_EXPAND_FILL);
  1168. translation_remap->connect("cell_selected", this, "_translation_res_select");
  1169. tmc->add_child(translation_remap);
  1170. translation_remap->connect("button_pressed", this, "_translation_res_delete");
  1171. translation_res_file_open = memnew(EditorFileDialog);
  1172. add_child(translation_res_file_open);
  1173. translation_res_file_open->set_mode(EditorFileDialog::MODE_OPEN_FILE);
  1174. translation_res_file_open->connect("file_selected", this, "_translation_res_add");
  1175. thb = memnew(HBoxContainer);
  1176. tvb->add_child(thb);
  1177. thb->add_child(memnew(Label(TTR("Remaps by Locale:"))));
  1178. thb->add_spacer();
  1179. addtr = memnew(Button(TTR("Add..")));
  1180. addtr->connect("pressed", this, "_translation_res_option_file_open");
  1181. translation_res_option_add_button = addtr;
  1182. thb->add_child(addtr);
  1183. tmc = memnew(MarginContainer);
  1184. tvb->add_child(tmc);
  1185. tmc->set_v_size_flags(SIZE_EXPAND_FILL);
  1186. translation_remap_options = memnew(Tree);
  1187. translation_remap_options->set_v_size_flags(SIZE_EXPAND_FILL);
  1188. tmc->add_child(translation_remap_options);
  1189. translation_remap_options->set_columns(2);
  1190. translation_remap_options->set_column_title(0, TTR("Path"));
  1191. translation_remap_options->set_column_title(1, TTR("Locale"));
  1192. translation_remap_options->set_column_titles_visible(true);
  1193. translation_remap_options->set_column_expand(0, true);
  1194. translation_remap_options->set_column_expand(1, false);
  1195. translation_remap_options->set_column_min_width(1, 200);
  1196. translation_remap_options->connect("item_edited", this, "_translation_res_option_changed");
  1197. translation_remap_options->connect("button_pressed", this, "_translation_res_option_delete");
  1198. translation_res_option_file_open = memnew(EditorFileDialog);
  1199. add_child(translation_res_option_file_open);
  1200. translation_res_option_file_open->set_mode(EditorFileDialog::MODE_OPEN_FILE);
  1201. translation_res_option_file_open->connect("file_selected", this, "_translation_res_option_add");
  1202. }
  1203. {
  1204. autoload_settings = memnew(EditorAutoloadSettings);
  1205. autoload_settings->set_name(TTR("AutoLoad"));
  1206. tab_container->add_child(autoload_settings);
  1207. autoload_settings->connect("autoload_changed", this, "_settings_changed");
  1208. }
  1209. {
  1210. plugin_settings = memnew(EditorPluginSettings);
  1211. plugin_settings->set_name(TTR("Plugins"));
  1212. tab_container->add_child(plugin_settings);
  1213. }
  1214. timer = memnew(Timer);
  1215. timer->set_wait_time(1.5);
  1216. timer->connect("timeout", Globals::get_singleton(), "save");
  1217. timer->set_one_shot(true);
  1218. add_child(timer);
  1219. updating_translations = false;
  1220. /*
  1221. Control * es = memnew( Control );
  1222. es->set_name("Export");
  1223. tab_container->add_child(es);
  1224. export_settings = memnew( ProjectExportSettings );
  1225. es->add_child(export_settings);
  1226. export_settings->set_area_as_parent_rect();
  1227. export_settings->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_END, 35 );
  1228. */
  1229. }