project_settings_editor.cpp 67 KB

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