project_settings_editor.cpp 72 KB

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