project_settings.cpp 52 KB

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