From 2d5de0b185b97cf246eacef88d308c54585aad40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Sat, 28 Oct 2017 15:40:55 +0200 Subject: Reorder EditorSettings code for better legibility No functional change, only moving stuff around. --- editor/editor_settings.cpp | 1330 ++++++++++++++++++++++---------------------- editor/editor_settings.h | 87 ++- 2 files changed, 706 insertions(+), 711 deletions(-) diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index 78cc215421..5ce6884a9e 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -47,12 +47,11 @@ #include "scene/main/scene_tree.h" #include "scene/main/viewport.h" -Ref EditorSettings::singleton = NULL; +// PRIVATE METHODS -EditorSettings *EditorSettings::get_singleton() { +Ref EditorSettings::singleton = NULL; - return singleton.ptr(); -} +// Properties bool EditorSettings::_set(const StringName &p_name, const Variant &p_value, bool p_emit_signal) { @@ -195,163 +194,505 @@ void EditorSettings::_get_property_list(List *p_list) const { p_list->push_back(PropertyInfo(Variant::ARRAY, "shortcuts", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR)); //do not edit } -void EditorSettings::set_setting(const String &p_setting, const Variant &p_value) { - _THREAD_SAFE_METHOD_ - set(p_setting, p_value); -} +void EditorSettings::_add_property_info_bind(const Dictionary &p_info) { -Variant EditorSettings::get_setting(const String &p_setting) const { - _THREAD_SAFE_METHOD_ - return get(p_setting); -} + ERR_FAIL_COND(!p_info.has("name")); + ERR_FAIL_COND(!p_info.has("type")); -bool EditorSettings::has_setting(String p_var) const { + PropertyInfo pinfo; + pinfo.name = p_info["name"]; + ERR_FAIL_COND(!props.has(pinfo.name)); + pinfo.type = Variant::Type(p_info["type"].operator int()); + ERR_FAIL_INDEX(pinfo.type, Variant::VARIANT_MAX); - _THREAD_SAFE_METHOD_ + if (p_info.has("hint")) + pinfo.hint = PropertyHint(p_info["hint"].operator int()); + if (p_info.has("hint_string")) + pinfo.hint_string = p_info["hint_string"]; - return props.has(p_var); + add_property_hint(pinfo); } -void EditorSettings::erase(String p_var) { - - _THREAD_SAFE_METHOD_ +// Default configs - props.erase(p_var); -} +void EditorSettings::_load_defaults(Ref p_extra_config) { -void EditorSettings::raise_order(const String &p_name) { _THREAD_SAFE_METHOD_ - ERR_FAIL_COND(!props.has(p_name)); - props[p_name].order = ++last_order; -} - -Variant _EDITOR_DEF(const String &p_var, const Variant &p_default) { + { + String lang_hint = "en"; + String host_lang = OS::get_singleton()->get_locale(); + host_lang = TranslationServer::standardize_locale(host_lang); - if (EditorSettings::get_singleton()->has_setting(p_var)) - return EditorSettings::get_singleton()->get(p_var); - EditorSettings::get_singleton()->set(p_var, p_default); - EditorSettings::get_singleton()->set_initial_value(p_var, p_default); + String best; - return p_default; -} + for (int i = 0; i < translations.size(); i++) { + String locale = translations[i]->get_locale(); + lang_hint += ","; + lang_hint += locale; -Variant _EDITOR_GET(const String &p_var) { + if (host_lang == locale) { + best = locale; + } - ERR_FAIL_COND_V(!EditorSettings::get_singleton()->has_setting(p_var), Variant()) - return EditorSettings::get_singleton()->get(p_var); -} + if (best == String() && host_lang.begins_with(locale)) { + best = locale; + } + } -static Dictionary _get_builtin_script_templates() { - Dictionary templates; + if (best == String()) { + best = "en"; + } - //No Comments - templates["no_comments.gd"] = - "extends %BASE%\n" - "\n" - "func _ready():\n" - "%TS%pass\n"; + _initial_set("interface/editor/editor_language", best); + hints["interface/editor/editor_language"] = PropertyInfo(Variant::STRING, "interface/editor/editor_language", PROPERTY_HINT_ENUM, lang_hint, PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); + } - //Empty - templates["empty.gd"] = - "extends %BASE%" - "\n" - "\n"; + _initial_set("interface/editor/hidpi_mode", 0); + hints["interface/editor/hidpi_mode"] = PropertyInfo(Variant::INT, "interface/editor/hidpi_mode", PROPERTY_HINT_ENUM, "Auto,VeryLoDPI,LoDPI,MidDPI,HiDPI", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); + _initial_set("interface/editor/show_script_in_scene_tabs", false); + _initial_set("interface/editor/font_size", 14); + hints["interface/editor/font_size"] = PropertyInfo(Variant::INT, "interface/editor/font_size", PROPERTY_HINT_RANGE, "10,40,1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); + _initial_set("interface/editor/source_font_size", 14); + hints["interface/editor/source_font_size"] = PropertyInfo(Variant::INT, "interface/editor/source_font_size", PROPERTY_HINT_RANGE, "8,96,1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); + _initial_set("interface/editor/custom_font", ""); + hints["interface/editor/custom_font"] = PropertyInfo(Variant::STRING, "interface/editor/custom_font", PROPERTY_HINT_GLOBAL_FILE, "*.font,*.tres,*.res", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); + _initial_set("interface/editor/dim_editor_on_dialog_popup", true); + _initial_set("interface/editor/dim_amount", 0.6f); + hints["interface/editor/dim_amount"] = PropertyInfo(Variant::REAL, "interface/editor/dim_amount", PROPERTY_HINT_RANGE, "0,1,0.01", PROPERTY_USAGE_DEFAULT); + _initial_set("interface/editor/dim_transition_time", 0.08f); + hints["interface/editor/dim_transition_time"] = PropertyInfo(Variant::REAL, "interface/editor/dim_transition_time", PROPERTY_HINT_RANGE, "0,1,0.001", PROPERTY_USAGE_DEFAULT); - return templates; -} + _initial_set("interface/editor/separate_distraction_mode", false); -static void _create_script_templates(const String &p_path) { + _initial_set("interface/editor/save_each_scene_on_quit", true); // Regression + _initial_set("interface/editor/quit_confirmation", true); - Dictionary templates = _get_builtin_script_templates(); - List keys; - templates.get_key_list(&keys); - FileAccess *file = FileAccess::create(FileAccess::ACCESS_FILESYSTEM); + _initial_set("interface/theme/preset", 0); + hints["interface/theme/preset"] = PropertyInfo(Variant::INT, "interface/theme/preset", PROPERTY_HINT_ENUM, "Default,Grey,Godot 2,Arc,Light,Alien,Custom", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); + _initial_set("interface/theme/icon_and_font_color", 0); + hints["interface/theme/icon_and_font_color"] = PropertyInfo(Variant::INT, "interface/theme/icon_and_font_color", PROPERTY_HINT_ENUM, "Auto,Dark,Light", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); + _initial_set("interface/theme/base_color", Color::html("#323b4f")); + hints["interface/theme/accent_color"] = PropertyInfo(Variant::COLOR, "interface/theme/accent_color", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); + _initial_set("interface/theme/accent_color", Color::html("#699ce8")); + hints["interface/theme/base_color"] = PropertyInfo(Variant::COLOR, "interface/theme/base_color", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); + _initial_set("interface/theme/contrast", 0.25); + hints["interface/theme/contrast"] = PropertyInfo(Variant::REAL, "interface/theme/contrast", PROPERTY_HINT_RANGE, "0.01, 1, 0.01"); + _initial_set("interface/theme/highlight_tabs", false); + _initial_set("interface/theme/border_size", 1); + _initial_set("interface/theme/use_graph_node_headers", false); + hints["interface/theme/border_size"] = PropertyInfo(Variant::INT, "interface/theme/border_size", PROPERTY_HINT_RANGE, "0,2,1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); + _initial_set("interface/theme/additional_spacing", 0); + hints["interface/theme/additional_spacing"] = PropertyInfo(Variant::REAL, "interface/theme/additional_spacing", PROPERTY_HINT_RANGE, "0,5,0.1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); + _initial_set("interface/theme/custom_theme", ""); + hints["interface/theme/custom_theme"] = PropertyInfo(Variant::STRING, "interface/theme/custom_theme", PROPERTY_HINT_GLOBAL_FILE, "*.res,*.tres,*.theme", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); - DirAccess *dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); - dir->change_dir(p_path); - for (int i = 0; i < keys.size(); i++) { - if (!dir->file_exists(keys[i])) { - Error err = file->reopen(p_path.plus_file((String)keys[i]), FileAccess::WRITE); - ERR_FAIL_COND(err != OK); - file->store_string(templates[keys[i]]); - file->close(); - } - } + _initial_set("interface/scene_tabs/show_extension", false); + _initial_set("interface/scene_tabs/show_thumbnail_on_hover", true); + _initial_set("interface/scene_tabs/resize_if_many_tabs", true); + _initial_set("interface/scene_tabs/minimum_width", 50); + hints["interface/scene_tabs/minimum_width"] = PropertyInfo(Variant::INT, "interface/scene_tabs/minimum_width", PROPERTY_HINT_RANGE, "50,500,1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); - memdelete(dir); - memdelete(file); -} + _initial_set("filesystem/directories/autoscan_project_path", ""); + hints["filesystem/directories/autoscan_project_path"] = PropertyInfo(Variant::STRING, "filesystem/directories/autoscan_project_path", PROPERTY_HINT_GLOBAL_DIR); + _initial_set("filesystem/directories/default_project_path", OS::get_singleton()->has_environment("HOME") ? OS::get_singleton()->get_environment("HOME") : OS::get_singleton()->get_system_dir(OS::SYSTEM_DIR_DOCUMENTS)); + hints["filesystem/directories/default_project_path"] = PropertyInfo(Variant::STRING, "filesystem/directories/default_project_path", PROPERTY_HINT_GLOBAL_DIR); + _initial_set("filesystem/directories/default_project_export_path", ""); + hints["global/default_project_export_path"] = PropertyInfo(Variant::STRING, "global/default_project_export_path", PROPERTY_HINT_GLOBAL_DIR); + _initial_set("interface/editor/show_script_in_scene_tabs", false); -void EditorSettings::create() { + _initial_set("text_editor/theme/color_theme", "Adaptive"); + hints["text_editor/theme/color_theme"] = PropertyInfo(Variant::STRING, "text_editor/theme/color_theme", PROPERTY_HINT_ENUM, "Adaptive,Default"); - if (singleton.ptr()) - return; //pointless + _initial_set("text_editor/theme/line_spacing", 4); - DirAccess *dir = NULL; - Variant meta; + _load_default_text_editor_theme(); - String config_path; - String config_dir; - Ref extra_config = memnew(ConfigFile); + _initial_set("text_editor/highlighting/syntax_highlighting", true); - String exe_path = OS::get_singleton()->get_executable_path().get_base_dir(); - DirAccess *d = DirAccess::create_for_path(exe_path); - bool self_contained = false; + _initial_set("text_editor/highlighting/highlight_all_occurrences", true); + _initial_set("text_editor/highlighting/highlight_current_line", true); + _initial_set("text_editor/cursor/scroll_past_end_of_file", false); - if (d->file_exists(exe_path + "/._sc_")) { - self_contained = true; - extra_config->load(exe_path + "/._sc_"); - } else if (d->file_exists(exe_path + "/_sc_")) { - self_contained = true; - extra_config->load(exe_path + "/_sc_"); - } - memdelete(d); + _initial_set("text_editor/indent/type", 0); + hints["text_editor/indent/type"] = PropertyInfo(Variant::INT, "text_editor/indent/type", PROPERTY_HINT_ENUM, "Tabs,Spaces"); + _initial_set("text_editor/indent/size", 4); + hints["text_editor/indent/size"] = PropertyInfo(Variant::INT, "text_editor/indent/size", PROPERTY_HINT_RANGE, "1, 64, 1"); // size of 0 crashes. + _initial_set("text_editor/indent/auto_indent", true); + _initial_set("text_editor/indent/convert_indent_on_save", false); + _initial_set("text_editor/indent/draw_tabs", true); - if (self_contained) { - // editor is self contained - config_path = exe_path; - config_dir = "editor_data"; - } else { + _initial_set("text_editor/line_numbers/show_line_numbers", true); + _initial_set("text_editor/line_numbers/line_numbers_zero_padded", false); + _initial_set("text_editor/line_numbers/show_breakpoint_gutter", true); + _initial_set("text_editor/line_numbers/show_line_length_guideline", false); + _initial_set("text_editor/line_numbers/line_length_guideline_column", 80); + hints["text_editor/line_numbers/line_length_guideline_column"] = PropertyInfo(Variant::INT, "text_editor/line_numbers/line_length_guideline_column", PROPERTY_HINT_RANGE, "20, 160, 10"); - if (OS::get_singleton()->has_environment("APPDATA")) { - // Most likely under windows, save here - config_path = OS::get_singleton()->get_environment("APPDATA"); - config_dir = String(_MKSTR(VERSION_SHORT_NAME)).capitalize(); - } else if (OS::get_singleton()->has_environment("HOME")) { + _initial_set("text_editor/open_scripts/smooth_scrolling", true); + _initial_set("text_editor/open_scripts/v_scroll_speed", 80); + _initial_set("text_editor/open_scripts/show_members_overview", true); - config_path = OS::get_singleton()->get_environment("HOME"); - config_dir = "." + String(_MKSTR(VERSION_SHORT_NAME)).to_lower(); - } - }; + _initial_set("text_editor/files/trim_trailing_whitespace_on_save", false); + _initial_set("text_editor/completion/idle_parse_delay", 2); + _initial_set("text_editor/tools/create_signal_callbacks", true); + _initial_set("text_editor/files/autosave_interval_secs", 0); - ClassDB::register_class(); //otherwise it can't be unserialized - String config_file_path; + _initial_set("text_editor/cursor/block_caret", false); + _initial_set("text_editor/cursor/caret_blink", false); + _initial_set("text_editor/cursor/caret_blink_speed", 0.65); + hints["text_editor/cursor/caret_blink_speed"] = PropertyInfo(Variant::REAL, "text_editor/cursor/caret_blink_speed", PROPERTY_HINT_RANGE, "0.1, 10, 0.1"); - if (config_path != "") { + _initial_set("text_editor/theme/font", ""); + hints["text_editor/theme/font"] = PropertyInfo(Variant::STRING, "text_editor/theme/font", PROPERTY_HINT_GLOBAL_FILE, "*.font,*.tres,*.res"); + _initial_set("text_editor/completion/auto_brace_complete", false); + _initial_set("text_editor/files/restore_scripts_on_load", true); + _initial_set("text_editor/completion/complete_file_paths", true); + _initial_set("text_editor/files/maximum_recent_files", 20); + hints["text_editor/files/maximum_recent_files"] = PropertyInfo(Variant::INT, "text_editor/files/maximum_recent_files", PROPERTY_HINT_RANGE, "1, 200, 0"); - dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); - if (dir->change_dir(config_path) != OK) { - ERR_PRINT("Cannot find path for config directory!"); - memdelete(dir); - goto fail; - } + _initial_set("docks/scene_tree/start_create_dialog_fully_expanded", false); + _initial_set("docks/scene_tree/draw_relationship_lines", false); + _initial_set("docks/scene_tree/relationship_line_color", Color::html("464646")); - if (dir->change_dir(config_dir) != OK) { - dir->make_dir(config_dir); - if (dir->change_dir(config_dir) != OK) { - ERR_PRINT("Cannot create config directory!"); - memdelete(dir); - goto fail; - } - } + _initial_set("editors/grid_map/pick_distance", 5000.0); - if (dir->change_dir("templates") != OK) { - dir->make_dir("templates"); - } else { + _initial_set("editors/3d/grid_color", Color::html("808080")); + hints["editors/3d/grid_color"] = PropertyInfo(Variant::COLOR, "editors/3d/grid_color", PROPERTY_HINT_COLOR_NO_ALPHA, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); - dir->change_dir(".."); - } + _initial_set("editors/3d/default_fov", 55.0); + _initial_set("editors/3d/default_z_near", 0.1); + _initial_set("editors/3d/default_z_far", 500.0); + + // navigation + _initial_set("editors/3d/navigation/navigation_scheme", 0); + hints["editors/3d/navigation/navigation_scheme"] = PropertyInfo(Variant::INT, "editors/3d/navigation/navigation_scheme", PROPERTY_HINT_ENUM, "Godot,Maya,Modo"); + _initial_set("editors/3d/navigation/zoom_style", 0); + hints["editors/3d/navigation/zoom_style"] = PropertyInfo(Variant::INT, "editors/3d/navigation/zoom_style", PROPERTY_HINT_ENUM, "Vertical, Horizontal"); + + _initial_set("editors/3d/navigation/emulate_3_button_mouse", false); + _initial_set("editors/3d/navigation/orbit_modifier", 0); + hints["editors/3d/navigation/orbit_modifier"] = PropertyInfo(Variant::INT, "editors/3d/navigation/orbit_modifier", PROPERTY_HINT_ENUM, "None,Shift,Alt,Meta,Ctrl"); + _initial_set("editors/3d/navigation/pan_modifier", 1); + hints["editors/3d/navigation/pan_modifier"] = PropertyInfo(Variant::INT, "editors/3d/navigation/pan_modifier", PROPERTY_HINT_ENUM, "None,Shift,Alt,Meta,Ctrl"); + _initial_set("editors/3d/navigation/zoom_modifier", 4); + hints["editors/3d/navigation/zoom_modifier"] = PropertyInfo(Variant::INT, "editors/3d/navigation/zoom_modifier", PROPERTY_HINT_ENUM, "None,Shift,Alt,Meta,Ctrl"); + + // _initial_set("editors/3d/navigation/emulate_numpad", false); not used at the moment + _initial_set("editors/3d/navigation/warped_mouse_panning", true); + + // navigation feel + _initial_set("editors/3d/navigation_feel/orbit_sensitivity", 0.4); + hints["editors/3d/navigation_feel/orbit_sensitivity"] = PropertyInfo(Variant::REAL, "editors/3d/navigation_feel/orbit_sensitivity", PROPERTY_HINT_RANGE, "0.0, 2, 0.01"); + + _initial_set("editors/3d/navigation_feel/orbit_inertia", 0.05); + hints["editors/3d/navigation_feel/orbit_inertia"] = PropertyInfo(Variant::REAL, "editors/3d/navigation_feel/orbit_inertia", PROPERTY_HINT_RANGE, "0.0, 1, 0.01"); + _initial_set("editors/3d/navigation_feel/translation_inertia", 0.15); + hints["editors/3d/navigation_feel/translation_inertia"] = PropertyInfo(Variant::REAL, "editors/3d/navigation_feel/translation_inertia", PROPERTY_HINT_RANGE, "0.0, 1, 0.01"); + _initial_set("editors/3d/navigation_feel/zoom_inertia", 0.075); + hints["editors/3d/navigation_feel/zoom_inertia"] = PropertyInfo(Variant::REAL, "editors/3d/navigation_feel/zoom_inertia", PROPERTY_HINT_RANGE, "0.0, 1, 0.01"); + _initial_set("editors/3d/navigation_feel/manipulation_orbit_inertia", 0.075); + hints["editors/3d/navigation_feel/manipulation_orbit_inertia"] = PropertyInfo(Variant::REAL, "editors/3d/navigation_feel/manipulation_orbit_inertia", PROPERTY_HINT_RANGE, "0.0, 1, 0.01"); + _initial_set("editors/3d/navigation_feel/manipulation_translation_inertia", 0.075); + hints["editors/3d/navigation_feel/manipulation_translation_inertia"] = PropertyInfo(Variant::REAL, "editors/3d/navigation_feel/manipulation_translation_inertia", PROPERTY_HINT_RANGE, "0.0, 1, 0.01"); + + // freelook + _initial_set("editors/3d/freelook/freelook_inertia", 0.1); + hints["editors/3d/freelook/freelook_inertia"] = PropertyInfo(Variant::REAL, "editors/3d/freelook/freelook_inertia", PROPERTY_HINT_RANGE, "0.0, 1, 0.01"); + _initial_set("editors/3d/freelook/freelook_base_speed", 5.0); + hints["editors/3d/freelook/freelook_base_speed"] = PropertyInfo(Variant::REAL, "editors/3d/freelook/freelook_base_speed", PROPERTY_HINT_RANGE, "0.0, 10, 0.01"); + _initial_set("editors/3d/freelook/freelook_activation_modifier", 0); + hints["editors/3d/freelook/freelook_activation_modifier"] = PropertyInfo(Variant::INT, "editors/3d/freelook/freelook_activation_modifier", PROPERTY_HINT_ENUM, "None,Shift,Alt,Meta,Ctrl"); + _initial_set("editors/3d/freelook/freelook_modifier_speed_factor", 3.0); + hints["editors/3d/freelook/freelook_modifier_speed_factor"] = PropertyInfo(Variant::REAL, "editors/3d/freelook/freelook_modifier_speed_factor", PROPERTY_HINT_RANGE, "0.0, 10.0, 0.1"); + _initial_set("editors/3d/freelook/freelook_speed_zoom_link", false); + + _initial_set("editors/2d/bone_width", 5); + _initial_set("editors/2d/bone_color1", Color(1.0, 1.0, 1.0, 0.9)); + _initial_set("editors/2d/bone_color2", Color(0.75, 0.75, 0.75, 0.9)); + _initial_set("editors/2d/bone_selected_color", Color(0.9, 0.45, 0.45, 0.9)); + _initial_set("editors/2d/bone_ik_color", Color(0.9, 0.9, 0.45, 0.9)); + _initial_set("editors/2d/keep_margins_when_changing_anchors", false); + _initial_set("editors/2d/warped_mouse_panning", true); + _initial_set("editors/2d/scroll_to_pan", false); + _initial_set("editors/2d/pan_speed", 20); + + _initial_set("editors/poly_editor/point_grab_radius", 8); + _initial_set("editors/poly_editor/show_previous_outline", true); + + _initial_set("run/window_placement/rect", 1); + hints["run/window_placement/rect"] = PropertyInfo(Variant::INT, "run/window_placement/rect", PROPERTY_HINT_ENUM, "Top Left,Centered,Custom Position,Force Maximized,Force Fullscreen"); + String screen_hints = TTR("Default (Same as Editor)"); + for (int i = 0; i < OS::get_singleton()->get_screen_count(); i++) { + screen_hints += ",Monitor " + itos(i + 1); + } + _initial_set("run/window_placement/rect_custom_position", Vector2()); + _initial_set("run/window_placement/screen", 0); + hints["run/window_placement/screen"] = PropertyInfo(Variant::INT, "run/window_placement/screen", PROPERTY_HINT_ENUM, screen_hints); + + _initial_set("filesystem/on_save/compress_binary_resources", true); + _initial_set("filesystem/on_save/save_modified_external_resources", true); + + _initial_set("text_editor/tools/create_signal_callbacks", true); + + _initial_set("filesystem/file_dialog/show_hidden_files", false); + _initial_set("filesystem/file_dialog/display_mode", 0); + hints["filesystem/file_dialog/display_mode"] = PropertyInfo(Variant::INT, "filesystem/file_dialog/display_mode", PROPERTY_HINT_ENUM, "Thumbnails,List"); + _initial_set("filesystem/file_dialog/thumbnail_size", 64); + hints["filesystem/file_dialog/thumbnail_size"] = PropertyInfo(Variant::INT, "filesystem/file_dialog/thumbnail_size", PROPERTY_HINT_RANGE, "32,128,16"); + + _initial_set("docks/filesystem/display_mode", 0); + hints["docks/filesystem/display_mode"] = PropertyInfo(Variant::INT, "docks/filesystem/display_mode", PROPERTY_HINT_ENUM, "Thumbnails,List"); + _initial_set("docks/filesystem/thumbnail_size", 64); + hints["docks/filesystem/thumbnail_size"] = PropertyInfo(Variant::INT, "docks/filesystem/thumbnail_size", PROPERTY_HINT_RANGE, "32,128,16"); + _initial_set("docks/filesystem/display_mode", 0); + hints["docks/filesystem/display_mode"] = PropertyInfo(Variant::INT, "docks/filesystem/display_mode", PROPERTY_HINT_ENUM, "Thumbnails,List"); + _initial_set("docks/filesystem/always_show_folders", true); + + _initial_set("editors/animation/autorename_animation_tracks", true); + _initial_set("editors/animation/confirm_insert_track", true); + + _initial_set("docks/property_editor/texture_preview_width", 48); + _initial_set("docks/property_editor/auto_refresh_interval", 0.3); + _initial_set("text_editor/help/doc_path", ""); + _initial_set("text_editor/help/show_help_index", true); + + _initial_set("filesystem/import/ask_save_before_reimport", false); + + _initial_set("filesystem/import/pvrtc_texture_tool", ""); +#ifdef WINDOWS_ENABLED + hints["filesystem/import/pvrtc_texture_tool"] = PropertyInfo(Variant::STRING, "filesystem/import/pvrtc_texture_tool", PROPERTY_HINT_GLOBAL_FILE, "*.exe"); +#else + hints["filesystem/import/pvrtc_texture_tool"] = PropertyInfo(Variant::STRING, "filesystem/import/pvrtc_texture_tool", PROPERTY_HINT_GLOBAL_FILE, ""); +#endif + _initial_set("filesystem/import/pvrtc_fast_conversion", false); + + _initial_set("run/auto_save/save_before_running", true); + _initial_set("run/output/always_clear_output_on_play", true); + _initial_set("run/output/always_open_output_on_play", true); + _initial_set("run/output/always_close_output_on_stop", false); + _initial_set("filesystem/resources/save_compressed_resources", true); + _initial_set("filesystem/resources/auto_reload_modified_images", true); + + _initial_set("filesystem/import/automatic_reimport_on_sources_changed", true); + + if (p_extra_config.is_valid()) { + + if (p_extra_config->has_section("init_projects") && p_extra_config->has_section_key("init_projects", "list")) { + + Vector list = p_extra_config->get_value("init_projects", "list"); + for (int i = 0; i < list.size(); i++) { + + String name = list[i].replace("/", "::"); + set("projects/" + name, list[i]); + }; + }; + + if (p_extra_config->has_section("presets")) { + + List keys; + p_extra_config->get_section_keys("presets", &keys); + + for (List::Element *E = keys.front(); E; E = E->next()) { + + String key = E->get(); + Variant val = p_extra_config->get_value("presets", key); + set(key, val); + }; + }; + }; +} + +void EditorSettings::_load_default_text_editor_theme() { + _initial_set("text_editor/highlighting/background_color", Color::html("3b000000")); + _initial_set("text_editor/highlighting/completion_background_color", Color::html("2C2A32")); + _initial_set("text_editor/highlighting/completion_selected_color", Color::html("434244")); + _initial_set("text_editor/highlighting/completion_existing_color", Color::html("21dfdfdf")); + _initial_set("text_editor/highlighting/completion_scroll_color", Color::html("ffffff")); + _initial_set("text_editor/highlighting/completion_font_color", Color::html("aaaaaa")); + _initial_set("text_editor/highlighting/caret_color", Color::html("aaaaaa")); + _initial_set("text_editor/highlighting/caret_background_color", Color::html("000000")); + _initial_set("text_editor/highlighting/line_number_color", Color::html("66aaaaaa")); + _initial_set("text_editor/highlighting/text_color", Color::html("aaaaaa")); + _initial_set("text_editor/highlighting/text_selected_color", Color::html("000000")); + _initial_set("text_editor/highlighting/keyword_color", Color::html("ffffb3")); + _initial_set("text_editor/highlighting/base_type_color", Color::html("a4ffd4")); + _initial_set("text_editor/highlighting/engine_type_color", Color::html("83d3ff")); + _initial_set("text_editor/highlighting/function_color", Color::html("66a2ce")); + _initial_set("text_editor/highlighting/member_variable_color", Color::html("e64e59")); + _initial_set("text_editor/highlighting/comment_color", Color::html("676767")); + _initial_set("text_editor/highlighting/string_color", Color::html("ef6ebe")); + _initial_set("text_editor/highlighting/number_color", Color::html("EB9532")); + _initial_set("text_editor/highlighting/symbol_color", Color::html("badfff")); + _initial_set("text_editor/highlighting/selection_color", Color::html("6ca9c2")); + _initial_set("text_editor/highlighting/brace_mismatch_color", Color(1, 0.2, 0.2)); + _initial_set("text_editor/highlighting/current_line_color", Color(0.3, 0.5, 0.8, 0.15)); + _initial_set("text_editor/highlighting/line_length_guideline_color", Color(0.3, 0.5, 0.8, 0.1)); + _initial_set("text_editor/highlighting/mark_color", Color(1.0, 0.4, 0.4, 0.4)); + _initial_set("text_editor/highlighting/breakpoint_color", Color(0.8, 0.8, 0.4, 0.2)); + _initial_set("text_editor/highlighting/word_highlighted_color", Color(0.8, 0.9, 0.9, 0.15)); + _initial_set("text_editor/highlighting/search_result_color", Color(0.05, 0.25, 0.05, 1)); + _initial_set("text_editor/highlighting/search_result_border_color", Color(0.1, 0.45, 0.1, 1)); +} + +bool EditorSettings::_save_text_editor_theme(String p_file) { + String theme_section = "color_theme"; + Ref cf = memnew(ConfigFile); // hex is better? + cf->set_value(theme_section, "background_color", ((Color)get("text_editor/highlighting/background_color")).to_html()); + cf->set_value(theme_section, "completion_background_color", ((Color)get("text_editor/highlighting/completion_background_color")).to_html()); + cf->set_value(theme_section, "completion_selected_color", ((Color)get("text_editor/highlighting/completion_selected_color")).to_html()); + cf->set_value(theme_section, "completion_existing_color", ((Color)get("text_editor/highlighting/completion_existing_color")).to_html()); + cf->set_value(theme_section, "completion_scroll_color", ((Color)get("text_editor/highlighting/completion_scroll_color")).to_html()); + cf->set_value(theme_section, "completion_font_color", ((Color)get("text_editor/highlighting/completion_font_color")).to_html()); + cf->set_value(theme_section, "caret_color", ((Color)get("text_editor/highlighting/caret_color")).to_html()); + cf->set_value(theme_section, "caret_background_color", ((Color)get("text_editor/highlighting/caret_background_color")).to_html()); + cf->set_value(theme_section, "line_number_color", ((Color)get("text_editor/highlighting/line_number_color")).to_html()); + cf->set_value(theme_section, "text_color", ((Color)get("text_editor/highlighting/text_color")).to_html()); + cf->set_value(theme_section, "text_selected_color", ((Color)get("text_editor/highlighting/text_selected_color")).to_html()); + cf->set_value(theme_section, "keyword_color", ((Color)get("text_editor/highlighting/keyword_color")).to_html()); + cf->set_value(theme_section, "base_type_color", ((Color)get("text_editor/highlighting/base_type_color")).to_html()); + cf->set_value(theme_section, "engine_type_color", ((Color)get("text_editor/highlighting/engine_type_color")).to_html()); + cf->set_value(theme_section, "function_color", ((Color)get("text_editor/highlighting/function_color")).to_html()); + cf->set_value(theme_section, "member_variable_color", ((Color)get("text_editor/highlighting/member_variable_color")).to_html()); + cf->set_value(theme_section, "comment_color", ((Color)get("text_editor/highlighting/comment_color")).to_html()); + cf->set_value(theme_section, "string_color", ((Color)get("text_editor/highlighting/string_color")).to_html()); + cf->set_value(theme_section, "number_color", ((Color)get("text_editor/highlighting/number_color")).to_html()); + cf->set_value(theme_section, "symbol_color", ((Color)get("text_editor/highlighting/symbol_color")).to_html()); + cf->set_value(theme_section, "selection_color", ((Color)get("text_editor/highlighting/selection_color")).to_html()); + cf->set_value(theme_section, "brace_mismatch_color", ((Color)get("text_editor/highlighting/brace_mismatch_color")).to_html()); + cf->set_value(theme_section, "current_line_color", ((Color)get("text_editor/highlighting/current_line_color")).to_html()); + cf->set_value(theme_section, "line_length_guideline_color", ((Color)get("text_editor/highlighting/line_length_guideline_color")).to_html()); + cf->set_value(theme_section, "mark_color", ((Color)get("text_editor/highlighting/mark_color")).to_html()); + cf->set_value(theme_section, "breakpoint_color", ((Color)get("text_editor/highlighting/breakpoint_color")).to_html()); + cf->set_value(theme_section, "word_highlighted_color", ((Color)get("text_editor/highlighting/word_highlighted_color")).to_html()); + cf->set_value(theme_section, "search_result_color", ((Color)get("text_editor/highlighting/search_result_color")).to_html()); + cf->set_value(theme_section, "search_result_border_color", ((Color)get("text_editor/highlighting/search_result_border_color")).to_html()); + + Error err = cf->save(p_file); + + if (err == OK) { + return true; + } + return false; +} + +static Dictionary _get_builtin_script_templates() { + Dictionary templates; + + //No Comments + templates["no_comments.gd"] = + "extends %BASE%\n" + "\n" + "func _ready():\n" + "%TS%pass\n"; + + //Empty + templates["empty.gd"] = + "extends %BASE%" + "\n" + "\n"; + + return templates; +} + +static void _create_script_templates(const String &p_path) { + + Dictionary templates = _get_builtin_script_templates(); + List keys; + templates.get_key_list(&keys); + FileAccess *file = FileAccess::create(FileAccess::ACCESS_FILESYSTEM); + + DirAccess *dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); + dir->change_dir(p_path); + for (int i = 0; i < keys.size(); i++) { + if (!dir->file_exists(keys[i])) { + Error err = file->reopen(p_path.plus_file((String)keys[i]), FileAccess::WRITE); + ERR_FAIL_COND(err != OK); + file->store_string(templates[keys[i]]); + file->close(); + } + } + + memdelete(dir); + memdelete(file); +} + +// PUBLIC METHODS + +EditorSettings *EditorSettings::get_singleton() { + + return singleton.ptr(); +} + +void EditorSettings::create() { + + if (singleton.ptr()) + return; //pointless + + DirAccess *dir = NULL; + Variant meta; + + String config_path; + String config_dir; + Ref extra_config = memnew(ConfigFile); + + String exe_path = OS::get_singleton()->get_executable_path().get_base_dir(); + DirAccess *d = DirAccess::create_for_path(exe_path); + bool self_contained = false; + + if (d->file_exists(exe_path + "/._sc_")) { + self_contained = true; + extra_config->load(exe_path + "/._sc_"); + } else if (d->file_exists(exe_path + "/_sc_")) { + self_contained = true; + extra_config->load(exe_path + "/_sc_"); + } + memdelete(d); + + if (self_contained) { + // editor is self contained + config_path = exe_path; + config_dir = "editor_data"; + } else { + + if (OS::get_singleton()->has_environment("APPDATA")) { + // Most likely under windows, save here + config_path = OS::get_singleton()->get_environment("APPDATA"); + config_dir = String(_MKSTR(VERSION_SHORT_NAME)).capitalize(); + } else if (OS::get_singleton()->has_environment("HOME")) { + + config_path = OS::get_singleton()->get_environment("HOME"); + config_dir = "." + String(_MKSTR(VERSION_SHORT_NAME)).to_lower(); + } + }; + + ClassDB::register_class(); //otherwise it can't be unserialized + String config_file_path; + + if (config_path != "") { + + dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); + if (dir->change_dir(config_path) != OK) { + ERR_PRINT("Cannot find path for config directory!"); + memdelete(dir); + goto fail; + } + + if (dir->change_dir(config_dir) != OK) { + dir->make_dir(config_dir); + if (dir->change_dir(config_dir) != OK) { + ERR_PRINT("Cannot create config directory!"); + memdelete(dir); + goto fail; + } + } + + if (dir->change_dir("templates") != OK) { + dir->make_dir("templates"); + } else { + + dir->change_dir(".."); + } if (dir->change_dir("text_editor_themes") != OK) { dir->make_dir("text_editor_themes"); @@ -434,464 +775,178 @@ void EditorSettings::create() { return; } -fail: - - // patch init projects - if (extra_config->has_section("init_projects")) { - Vector list = extra_config->get_value("init_projects", "list"); - for (int i = 0; i < list.size(); i++) { - - list[i] = exe_path + "/" + list[i]; - }; - extra_config->set_value("init_projects", "list", list); - }; - - singleton = Ref(memnew(EditorSettings)); - singleton->save_changed_setting = true; - singleton->config_file_path = config_file_path; - singleton->settings_path = config_path + "/" + config_dir; - singleton->_load_defaults(extra_config); - singleton->setup_language(); - singleton->setup_network(); - singleton->list_text_editor_themes(); -} - -String EditorSettings::get_settings_path() const { - - return settings_path; -} - -void EditorSettings::setup_language() { - - String lang = get("interface/editor/editor_language"); - if (lang == "en") - return; //none to do - - for (int i = 0; i < translations.size(); i++) { - if (translations[i]->get_locale() == lang) { - TranslationServer::get_singleton()->set_tool_translation(translations[i]); - break; - } - } -} - -void EditorSettings::setup_network() { - - List local_ip; - IP::get_singleton()->get_local_addresses(&local_ip); - String lip = "127.0.0.1"; - String hint; - String current = has_setting("network/debug/remote_host") ? get("network/debug/remote_host") : ""; - int port = has_setting("network/debug/remote_port") ? (int)get("network/debug/remote_port") : 6007; - - for (List::Element *E = local_ip.front(); E; E = E->next()) { - - String ip = E->get(); - - // link-local IPv6 addresses don't work, skipping them - if (ip.begins_with("fe80:0:0:0:")) // fe80::/64 - continue; - if (ip == current) - lip = current; //so it saves - if (hint != "") - hint += ","; - hint += ip; - } - - set("network/debug/remote_host", lip); - add_property_hint(PropertyInfo(Variant::STRING, "network/debug/remote_host", PROPERTY_HINT_ENUM, hint)); - - set("network/debug/remote_port", port); - add_property_hint(PropertyInfo(Variant::INT, "network/debug/remote_port", PROPERTY_HINT_RANGE, "1,65535,1")); -} - -void EditorSettings::save() { - - //_THREAD_SAFE_METHOD_ - - if (!singleton.ptr()) - return; - - if (singleton->config_file_path == "") { - ERR_PRINT("Cannot save EditorSettings config, no valid path"); - return; - } - - Error err = ResourceSaver::save(singleton->config_file_path, singleton); - - if (err != OK) { - ERR_PRINT("Can't Save!"); - return; - } - - if (OS::get_singleton()->is_stdout_verbose()) { - print_line("EditorSettings Save OK!"); - } -} - -void EditorSettings::destroy() { - - if (!singleton.ptr()) - return; - save(); - singleton = Ref(); -} - -void EditorSettings::_load_defaults(Ref p_extra_config) { - - _THREAD_SAFE_METHOD_ - - { - String lang_hint = "en"; - String host_lang = OS::get_singleton()->get_locale(); - host_lang = TranslationServer::standardize_locale(host_lang); - - String best; - - for (int i = 0; i < translations.size(); i++) { - String locale = translations[i]->get_locale(); - lang_hint += ","; - lang_hint += locale; - - if (host_lang == locale) { - best = locale; - } - - if (best == String() && host_lang.begins_with(locale)) { - best = locale; - } - } - - if (best == String()) { - best = "en"; - } - - _initial_set("interface/editor/editor_language", best); - hints["interface/editor/editor_language"] = PropertyInfo(Variant::STRING, "interface/editor/editor_language", PROPERTY_HINT_ENUM, lang_hint, PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); - } - - _initial_set("interface/editor/hidpi_mode", 0); - hints["interface/editor/hidpi_mode"] = PropertyInfo(Variant::INT, "interface/editor/hidpi_mode", PROPERTY_HINT_ENUM, "Auto,VeryLoDPI,LoDPI,MidDPI,HiDPI", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); - _initial_set("interface/editor/show_script_in_scene_tabs", false); - _initial_set("interface/editor/font_size", 14); - hints["interface/editor/font_size"] = PropertyInfo(Variant::INT, "interface/editor/font_size", PROPERTY_HINT_RANGE, "10,40,1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); - _initial_set("interface/editor/source_font_size", 14); - hints["interface/editor/source_font_size"] = PropertyInfo(Variant::INT, "interface/editor/source_font_size", PROPERTY_HINT_RANGE, "8,96,1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); - _initial_set("interface/editor/custom_font", ""); - hints["interface/editor/custom_font"] = PropertyInfo(Variant::STRING, "interface/editor/custom_font", PROPERTY_HINT_GLOBAL_FILE, "*.font,*.tres,*.res", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); - _initial_set("interface/editor/dim_editor_on_dialog_popup", true); - _initial_set("interface/editor/dim_amount", 0.6f); - hints["interface/editor/dim_amount"] = PropertyInfo(Variant::REAL, "interface/editor/dim_amount", PROPERTY_HINT_RANGE, "0,1,0.01", PROPERTY_USAGE_DEFAULT); - _initial_set("interface/editor/dim_transition_time", 0.08f); - hints["interface/editor/dim_transition_time"] = PropertyInfo(Variant::REAL, "interface/editor/dim_transition_time", PROPERTY_HINT_RANGE, "0,1,0.001", PROPERTY_USAGE_DEFAULT); - - _initial_set("interface/editor/separate_distraction_mode", false); - - _initial_set("interface/editor/save_each_scene_on_quit", true); // Regression - _initial_set("interface/editor/quit_confirmation", true); - - _initial_set("interface/theme/preset", 0); - hints["interface/theme/preset"] = PropertyInfo(Variant::INT, "interface/theme/preset", PROPERTY_HINT_ENUM, "Default,Grey,Godot 2,Arc,Light,Alien,Custom", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); - _initial_set("interface/theme/icon_and_font_color", 0); - hints["interface/theme/icon_and_font_color"] = PropertyInfo(Variant::INT, "interface/theme/icon_and_font_color", PROPERTY_HINT_ENUM, "Auto,Dark,Light", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); - _initial_set("interface/theme/base_color", Color::html("#323b4f")); - hints["interface/theme/accent_color"] = PropertyInfo(Variant::COLOR, "interface/theme/accent_color", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); - _initial_set("interface/theme/accent_color", Color::html("#699ce8")); - hints["interface/theme/base_color"] = PropertyInfo(Variant::COLOR, "interface/theme/base_color", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); - _initial_set("interface/theme/contrast", 0.25); - hints["interface/theme/contrast"] = PropertyInfo(Variant::REAL, "interface/theme/contrast", PROPERTY_HINT_RANGE, "0.01, 1, 0.01"); - _initial_set("interface/theme/highlight_tabs", false); - _initial_set("interface/theme/border_size", 1); - _initial_set("interface/theme/use_graph_node_headers", false); - hints["interface/theme/border_size"] = PropertyInfo(Variant::INT, "interface/theme/border_size", PROPERTY_HINT_RANGE, "0,2,1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); - _initial_set("interface/theme/additional_spacing", 0); - hints["interface/theme/additional_spacing"] = PropertyInfo(Variant::REAL, "interface/theme/additional_spacing", PROPERTY_HINT_RANGE, "0,5,0.1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); - _initial_set("interface/theme/custom_theme", ""); - hints["interface/theme/custom_theme"] = PropertyInfo(Variant::STRING, "interface/theme/custom_theme", PROPERTY_HINT_GLOBAL_FILE, "*.res,*.tres,*.theme", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); - - _initial_set("interface/scene_tabs/show_extension", false); - _initial_set("interface/scene_tabs/show_thumbnail_on_hover", true); - _initial_set("interface/scene_tabs/resize_if_many_tabs", true); - _initial_set("interface/scene_tabs/minimum_width", 50); - hints["interface/scene_tabs/minimum_width"] = PropertyInfo(Variant::INT, "interface/scene_tabs/minimum_width", PROPERTY_HINT_RANGE, "50,500,1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); - - _initial_set("filesystem/directories/autoscan_project_path", ""); - hints["filesystem/directories/autoscan_project_path"] = PropertyInfo(Variant::STRING, "filesystem/directories/autoscan_project_path", PROPERTY_HINT_GLOBAL_DIR); - _initial_set("filesystem/directories/default_project_path", OS::get_singleton()->has_environment("HOME") ? OS::get_singleton()->get_environment("HOME") : OS::get_singleton()->get_system_dir(OS::SYSTEM_DIR_DOCUMENTS)); - hints["filesystem/directories/default_project_path"] = PropertyInfo(Variant::STRING, "filesystem/directories/default_project_path", PROPERTY_HINT_GLOBAL_DIR); - _initial_set("filesystem/directories/default_project_export_path", ""); - hints["global/default_project_export_path"] = PropertyInfo(Variant::STRING, "global/default_project_export_path", PROPERTY_HINT_GLOBAL_DIR); - _initial_set("interface/editor/show_script_in_scene_tabs", false); - - _initial_set("text_editor/theme/color_theme", "Adaptive"); - hints["text_editor/theme/color_theme"] = PropertyInfo(Variant::STRING, "text_editor/theme/color_theme", PROPERTY_HINT_ENUM, "Adaptive,Default"); - - _initial_set("text_editor/theme/line_spacing", 4); - - _load_default_text_editor_theme(); - - _initial_set("text_editor/highlighting/syntax_highlighting", true); - - _initial_set("text_editor/highlighting/highlight_all_occurrences", true); - _initial_set("text_editor/highlighting/highlight_current_line", true); - _initial_set("text_editor/cursor/scroll_past_end_of_file", false); - - _initial_set("text_editor/indent/type", 0); - hints["text_editor/indent/type"] = PropertyInfo(Variant::INT, "text_editor/indent/type", PROPERTY_HINT_ENUM, "Tabs,Spaces"); - _initial_set("text_editor/indent/size", 4); - hints["text_editor/indent/size"] = PropertyInfo(Variant::INT, "text_editor/indent/size", PROPERTY_HINT_RANGE, "1, 64, 1"); // size of 0 crashes. - _initial_set("text_editor/indent/auto_indent", true); - _initial_set("text_editor/indent/convert_indent_on_save", false); - _initial_set("text_editor/indent/draw_tabs", true); - - _initial_set("text_editor/line_numbers/show_line_numbers", true); - _initial_set("text_editor/line_numbers/line_numbers_zero_padded", false); - _initial_set("text_editor/line_numbers/show_breakpoint_gutter", true); - _initial_set("text_editor/line_numbers/show_line_length_guideline", false); - _initial_set("text_editor/line_numbers/line_length_guideline_column", 80); - hints["text_editor/line_numbers/line_length_guideline_column"] = PropertyInfo(Variant::INT, "text_editor/line_numbers/line_length_guideline_column", PROPERTY_HINT_RANGE, "20, 160, 10"); - - _initial_set("text_editor/open_scripts/smooth_scrolling", true); - _initial_set("text_editor/open_scripts/v_scroll_speed", 80); - _initial_set("text_editor/open_scripts/show_members_overview", true); - - _initial_set("text_editor/files/trim_trailing_whitespace_on_save", false); - _initial_set("text_editor/completion/idle_parse_delay", 2); - _initial_set("text_editor/tools/create_signal_callbacks", true); - _initial_set("text_editor/files/autosave_interval_secs", 0); - - _initial_set("text_editor/cursor/block_caret", false); - _initial_set("text_editor/cursor/caret_blink", false); - _initial_set("text_editor/cursor/caret_blink_speed", 0.65); - hints["text_editor/cursor/caret_blink_speed"] = PropertyInfo(Variant::REAL, "text_editor/cursor/caret_blink_speed", PROPERTY_HINT_RANGE, "0.1, 10, 0.1"); +fail: - _initial_set("text_editor/theme/font", ""); - hints["text_editor/theme/font"] = PropertyInfo(Variant::STRING, "text_editor/theme/font", PROPERTY_HINT_GLOBAL_FILE, "*.font,*.tres,*.res"); - _initial_set("text_editor/completion/auto_brace_complete", false); - _initial_set("text_editor/files/restore_scripts_on_load", true); - _initial_set("text_editor/completion/complete_file_paths", true); - _initial_set("text_editor/files/maximum_recent_files", 20); - hints["text_editor/files/maximum_recent_files"] = PropertyInfo(Variant::INT, "text_editor/files/maximum_recent_files", PROPERTY_HINT_RANGE, "1, 200, 0"); + // patch init projects + if (extra_config->has_section("init_projects")) { + Vector list = extra_config->get_value("init_projects", "list"); + for (int i = 0; i < list.size(); i++) { - _initial_set("docks/scene_tree/start_create_dialog_fully_expanded", false); - _initial_set("docks/scene_tree/draw_relationship_lines", false); - _initial_set("docks/scene_tree/relationship_line_color", Color::html("464646")); + list[i] = exe_path + "/" + list[i]; + }; + extra_config->set_value("init_projects", "list", list); + }; - _initial_set("editors/grid_map/pick_distance", 5000.0); + singleton = Ref(memnew(EditorSettings)); + singleton->save_changed_setting = true; + singleton->config_file_path = config_file_path; + singleton->settings_path = config_path + "/" + config_dir; + singleton->_load_defaults(extra_config); + singleton->setup_language(); + singleton->setup_network(); + singleton->list_text_editor_themes(); +} - _initial_set("editors/3d/grid_color", Color::html("808080")); - hints["editors/3d/grid_color"] = PropertyInfo(Variant::COLOR, "editors/3d/grid_color", PROPERTY_HINT_COLOR_NO_ALPHA, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); +void EditorSettings::setup_language() { - _initial_set("editors/3d/default_fov", 55.0); - _initial_set("editors/3d/default_z_near", 0.1); - _initial_set("editors/3d/default_z_far", 500.0); + String lang = get("interface/editor/editor_language"); + if (lang == "en") + return; //none to do - // navigation - _initial_set("editors/3d/navigation/navigation_scheme", 0); - hints["editors/3d/navigation/navigation_scheme"] = PropertyInfo(Variant::INT, "editors/3d/navigation/navigation_scheme", PROPERTY_HINT_ENUM, "Godot,Maya,Modo"); - _initial_set("editors/3d/navigation/zoom_style", 0); - hints["editors/3d/navigation/zoom_style"] = PropertyInfo(Variant::INT, "editors/3d/navigation/zoom_style", PROPERTY_HINT_ENUM, "Vertical, Horizontal"); + for (int i = 0; i < translations.size(); i++) { + if (translations[i]->get_locale() == lang) { + TranslationServer::get_singleton()->set_tool_translation(translations[i]); + break; + } + } +} - _initial_set("editors/3d/navigation/emulate_3_button_mouse", false); - _initial_set("editors/3d/navigation/orbit_modifier", 0); - hints["editors/3d/navigation/orbit_modifier"] = PropertyInfo(Variant::INT, "editors/3d/navigation/orbit_modifier", PROPERTY_HINT_ENUM, "None,Shift,Alt,Meta,Ctrl"); - _initial_set("editors/3d/navigation/pan_modifier", 1); - hints["editors/3d/navigation/pan_modifier"] = PropertyInfo(Variant::INT, "editors/3d/navigation/pan_modifier", PROPERTY_HINT_ENUM, "None,Shift,Alt,Meta,Ctrl"); - _initial_set("editors/3d/navigation/zoom_modifier", 4); - hints["editors/3d/navigation/zoom_modifier"] = PropertyInfo(Variant::INT, "editors/3d/navigation/zoom_modifier", PROPERTY_HINT_ENUM, "None,Shift,Alt,Meta,Ctrl"); +void EditorSettings::setup_network() { - // _initial_set("editors/3d/navigation/emulate_numpad", false); not used at the moment - _initial_set("editors/3d/navigation/warped_mouse_panning", true); + List local_ip; + IP::get_singleton()->get_local_addresses(&local_ip); + String lip = "127.0.0.1"; + String hint; + String current = has_setting("network/debug/remote_host") ? get("network/debug/remote_host") : ""; + int port = has_setting("network/debug/remote_port") ? (int)get("network/debug/remote_port") : 6007; - // navigation feel - _initial_set("editors/3d/navigation_feel/orbit_sensitivity", 0.4); - hints["editors/3d/navigation_feel/orbit_sensitivity"] = PropertyInfo(Variant::REAL, "editors/3d/navigation_feel/orbit_sensitivity", PROPERTY_HINT_RANGE, "0.0, 2, 0.01"); + for (List::Element *E = local_ip.front(); E; E = E->next()) { - _initial_set("editors/3d/navigation_feel/orbit_inertia", 0.05); - hints["editors/3d/navigation_feel/orbit_inertia"] = PropertyInfo(Variant::REAL, "editors/3d/navigation_feel/orbit_inertia", PROPERTY_HINT_RANGE, "0.0, 1, 0.01"); - _initial_set("editors/3d/navigation_feel/translation_inertia", 0.15); - hints["editors/3d/navigation_feel/translation_inertia"] = PropertyInfo(Variant::REAL, "editors/3d/navigation_feel/translation_inertia", PROPERTY_HINT_RANGE, "0.0, 1, 0.01"); - _initial_set("editors/3d/navigation_feel/zoom_inertia", 0.075); - hints["editors/3d/navigation_feel/zoom_inertia"] = PropertyInfo(Variant::REAL, "editors/3d/navigation_feel/zoom_inertia", PROPERTY_HINT_RANGE, "0.0, 1, 0.01"); - _initial_set("editors/3d/navigation_feel/manipulation_orbit_inertia", 0.075); - hints["editors/3d/navigation_feel/manipulation_orbit_inertia"] = PropertyInfo(Variant::REAL, "editors/3d/navigation_feel/manipulation_orbit_inertia", PROPERTY_HINT_RANGE, "0.0, 1, 0.01"); - _initial_set("editors/3d/navigation_feel/manipulation_translation_inertia", 0.075); - hints["editors/3d/navigation_feel/manipulation_translation_inertia"] = PropertyInfo(Variant::REAL, "editors/3d/navigation_feel/manipulation_translation_inertia", PROPERTY_HINT_RANGE, "0.0, 1, 0.01"); + String ip = E->get(); - // freelook - _initial_set("editors/3d/freelook/freelook_inertia", 0.1); - hints["editors/3d/freelook/freelook_inertia"] = PropertyInfo(Variant::REAL, "editors/3d/freelook/freelook_inertia", PROPERTY_HINT_RANGE, "0.0, 1, 0.01"); - _initial_set("editors/3d/freelook/freelook_base_speed", 5.0); - hints["editors/3d/freelook/freelook_base_speed"] = PropertyInfo(Variant::REAL, "editors/3d/freelook/freelook_base_speed", PROPERTY_HINT_RANGE, "0.0, 10, 0.01"); - _initial_set("editors/3d/freelook/freelook_activation_modifier", 0); - hints["editors/3d/freelook/freelook_activation_modifier"] = PropertyInfo(Variant::INT, "editors/3d/freelook/freelook_activation_modifier", PROPERTY_HINT_ENUM, "None,Shift,Alt,Meta,Ctrl"); - _initial_set("editors/3d/freelook/freelook_modifier_speed_factor", 3.0); - hints["editors/3d/freelook/freelook_modifier_speed_factor"] = PropertyInfo(Variant::REAL, "editors/3d/freelook/freelook_modifier_speed_factor", PROPERTY_HINT_RANGE, "0.0, 10.0, 0.1"); - _initial_set("editors/3d/freelook/freelook_speed_zoom_link", false); + // link-local IPv6 addresses don't work, skipping them + if (ip.begins_with("fe80:0:0:0:")) // fe80::/64 + continue; + if (ip == current) + lip = current; //so it saves + if (hint != "") + hint += ","; + hint += ip; + } - _initial_set("editors/2d/bone_width", 5); - _initial_set("editors/2d/bone_color1", Color(1.0, 1.0, 1.0, 0.9)); - _initial_set("editors/2d/bone_color2", Color(0.75, 0.75, 0.75, 0.9)); - _initial_set("editors/2d/bone_selected_color", Color(0.9, 0.45, 0.45, 0.9)); - _initial_set("editors/2d/bone_ik_color", Color(0.9, 0.9, 0.45, 0.9)); - _initial_set("editors/2d/keep_margins_when_changing_anchors", false); - _initial_set("editors/2d/warped_mouse_panning", true); - _initial_set("editors/2d/scroll_to_pan", false); - _initial_set("editors/2d/pan_speed", 20); + set("network/debug/remote_host", lip); + add_property_hint(PropertyInfo(Variant::STRING, "network/debug/remote_host", PROPERTY_HINT_ENUM, hint)); - _initial_set("editors/poly_editor/point_grab_radius", 8); - _initial_set("editors/poly_editor/show_previous_outline", true); + set("network/debug/remote_port", port); + add_property_hint(PropertyInfo(Variant::INT, "network/debug/remote_port", PROPERTY_HINT_RANGE, "1,65535,1")); +} - _initial_set("run/window_placement/rect", 1); - hints["run/window_placement/rect"] = PropertyInfo(Variant::INT, "run/window_placement/rect", PROPERTY_HINT_ENUM, "Top Left,Centered,Custom Position,Force Maximized,Force Fullscreen"); - String screen_hints = TTR("Default (Same as Editor)"); - for (int i = 0; i < OS::get_singleton()->get_screen_count(); i++) { - screen_hints += ",Monitor " + itos(i + 1); - } - _initial_set("run/window_placement/rect_custom_position", Vector2()); - _initial_set("run/window_placement/screen", 0); - hints["run/window_placement/screen"] = PropertyInfo(Variant::INT, "run/window_placement/screen", PROPERTY_HINT_ENUM, screen_hints); +void EditorSettings::save() { - _initial_set("filesystem/on_save/compress_binary_resources", true); - _initial_set("filesystem/on_save/save_modified_external_resources", true); + //_THREAD_SAFE_METHOD_ - _initial_set("text_editor/tools/create_signal_callbacks", true); + if (!singleton.ptr()) + return; - _initial_set("filesystem/file_dialog/show_hidden_files", false); - _initial_set("filesystem/file_dialog/display_mode", 0); - hints["filesystem/file_dialog/display_mode"] = PropertyInfo(Variant::INT, "filesystem/file_dialog/display_mode", PROPERTY_HINT_ENUM, "Thumbnails,List"); - _initial_set("filesystem/file_dialog/thumbnail_size", 64); - hints["filesystem/file_dialog/thumbnail_size"] = PropertyInfo(Variant::INT, "filesystem/file_dialog/thumbnail_size", PROPERTY_HINT_RANGE, "32,128,16"); + if (singleton->config_file_path == "") { + ERR_PRINT("Cannot save EditorSettings config, no valid path"); + return; + } - _initial_set("docks/filesystem/display_mode", 0); - hints["docks/filesystem/display_mode"] = PropertyInfo(Variant::INT, "docks/filesystem/display_mode", PROPERTY_HINT_ENUM, "Thumbnails,List"); - _initial_set("docks/filesystem/thumbnail_size", 64); - hints["docks/filesystem/thumbnail_size"] = PropertyInfo(Variant::INT, "docks/filesystem/thumbnail_size", PROPERTY_HINT_RANGE, "32,128,16"); - _initial_set("docks/filesystem/display_mode", 0); - hints["docks/filesystem/display_mode"] = PropertyInfo(Variant::INT, "docks/filesystem/display_mode", PROPERTY_HINT_ENUM, "Thumbnails,List"); - _initial_set("docks/filesystem/always_show_folders", true); + Error err = ResourceSaver::save(singleton->config_file_path, singleton); - _initial_set("editors/animation/autorename_animation_tracks", true); - _initial_set("editors/animation/confirm_insert_track", true); + if (err != OK) { + ERR_PRINT("Can't Save!"); + return; + } - _initial_set("docks/property_editor/texture_preview_width", 48); - _initial_set("docks/property_editor/auto_refresh_interval", 0.3); - _initial_set("text_editor/help/doc_path", ""); - _initial_set("text_editor/help/show_help_index", true); + if (OS::get_singleton()->is_stdout_verbose()) { + print_line("EditorSettings Save OK!"); + } +} - _initial_set("filesystem/import/ask_save_before_reimport", false); +void EditorSettings::destroy() { - _initial_set("filesystem/import/pvrtc_texture_tool", ""); -#ifdef WINDOWS_ENABLED - hints["filesystem/import/pvrtc_texture_tool"] = PropertyInfo(Variant::STRING, "filesystem/import/pvrtc_texture_tool", PROPERTY_HINT_GLOBAL_FILE, "*.exe"); -#else - hints["filesystem/import/pvrtc_texture_tool"] = PropertyInfo(Variant::STRING, "filesystem/import/pvrtc_texture_tool", PROPERTY_HINT_GLOBAL_FILE, ""); -#endif - _initial_set("filesystem/import/pvrtc_fast_conversion", false); + if (!singleton.ptr()) + return; + save(); + singleton = Ref(); +} - _initial_set("run/auto_save/save_before_running", true); - _initial_set("run/output/always_clear_output_on_play", true); - _initial_set("run/output/always_open_output_on_play", true); - _initial_set("run/output/always_close_output_on_stop", false); - _initial_set("filesystem/resources/save_compressed_resources", true); - _initial_set("filesystem/resources/auto_reload_modified_images", true); +void EditorSettings::set_optimize_save(bool p_optimize) { - _initial_set("filesystem/import/automatic_reimport_on_sources_changed", true); + optimize_save = p_optimize; +} - if (p_extra_config.is_valid()) { +// Properties - if (p_extra_config->has_section("init_projects") && p_extra_config->has_section_key("init_projects", "list")) { +void EditorSettings::set_setting(const String &p_setting, const Variant &p_value) { + _THREAD_SAFE_METHOD_ + set(p_setting, p_value); +} - Vector list = p_extra_config->get_value("init_projects", "list"); - for (int i = 0; i < list.size(); i++) { +Variant EditorSettings::get_setting(const String &p_setting) const { + _THREAD_SAFE_METHOD_ + return get(p_setting); +} - String name = list[i].replace("/", "::"); - set("projects/" + name, list[i]); - }; - }; +bool EditorSettings::has_setting(String p_var) const { - if (p_extra_config->has_section("presets")) { + _THREAD_SAFE_METHOD_ - List keys; - p_extra_config->get_section_keys("presets", &keys); + return props.has(p_var); +} - for (List::Element *E = keys.front(); E; E = E->next()) { +void EditorSettings::erase(String p_var) { - String key = E->get(); - Variant val = p_extra_config->get_value("presets", key); - set(key, val); - }; - }; - }; + _THREAD_SAFE_METHOD_ + + props.erase(p_var); } -void EditorSettings::_load_default_text_editor_theme() { - _initial_set("text_editor/highlighting/background_color", Color::html("3b000000")); - _initial_set("text_editor/highlighting/completion_background_color", Color::html("2C2A32")); - _initial_set("text_editor/highlighting/completion_selected_color", Color::html("434244")); - _initial_set("text_editor/highlighting/completion_existing_color", Color::html("21dfdfdf")); - _initial_set("text_editor/highlighting/completion_scroll_color", Color::html("ffffff")); - _initial_set("text_editor/highlighting/completion_font_color", Color::html("aaaaaa")); - _initial_set("text_editor/highlighting/caret_color", Color::html("aaaaaa")); - _initial_set("text_editor/highlighting/caret_background_color", Color::html("000000")); - _initial_set("text_editor/highlighting/line_number_color", Color::html("66aaaaaa")); - _initial_set("text_editor/highlighting/text_color", Color::html("aaaaaa")); - _initial_set("text_editor/highlighting/text_selected_color", Color::html("000000")); - _initial_set("text_editor/highlighting/keyword_color", Color::html("ffffb3")); - _initial_set("text_editor/highlighting/base_type_color", Color::html("a4ffd4")); - _initial_set("text_editor/highlighting/engine_type_color", Color::html("83d3ff")); - _initial_set("text_editor/highlighting/function_color", Color::html("66a2ce")); - _initial_set("text_editor/highlighting/member_variable_color", Color::html("e64e59")); - _initial_set("text_editor/highlighting/comment_color", Color::html("676767")); - _initial_set("text_editor/highlighting/string_color", Color::html("ef6ebe")); - _initial_set("text_editor/highlighting/number_color", Color::html("EB9532")); - _initial_set("text_editor/highlighting/symbol_color", Color::html("badfff")); - _initial_set("text_editor/highlighting/selection_color", Color::html("6ca9c2")); - _initial_set("text_editor/highlighting/brace_mismatch_color", Color(1, 0.2, 0.2)); - _initial_set("text_editor/highlighting/current_line_color", Color(0.3, 0.5, 0.8, 0.15)); - _initial_set("text_editor/highlighting/line_length_guideline_color", Color(0.3, 0.5, 0.8, 0.1)); - _initial_set("text_editor/highlighting/mark_color", Color(1.0, 0.4, 0.4, 0.4)); - _initial_set("text_editor/highlighting/breakpoint_color", Color(0.8, 0.8, 0.4, 0.2)); - _initial_set("text_editor/highlighting/word_highlighted_color", Color(0.8, 0.9, 0.9, 0.15)); - _initial_set("text_editor/highlighting/search_result_color", Color(0.05, 0.25, 0.05, 1)); - _initial_set("text_editor/highlighting/search_result_border_color", Color(0.1, 0.45, 0.1, 1)); +void EditorSettings::raise_order(const String &p_name) { + _THREAD_SAFE_METHOD_ + + ERR_FAIL_COND(!props.has(p_name)); + props[p_name].order = ++last_order; } -void EditorSettings::notify_changes() { +void EditorSettings::set_initial_value(const StringName &p_name, const Variant &p_value) { - _THREAD_SAFE_METHOD_ + ERR_FAIL_COND(!props.has(p_name)); + props[p_name].initial = p_value; +} - SceneTree *sml = Object::cast_to(OS::get_singleton()->get_main_loop()); +Variant _EDITOR_DEF(const String &p_var, const Variant &p_default) { - if (!sml) { - return; - } + if (EditorSettings::get_singleton()->has_setting(p_var)) + return EditorSettings::get_singleton()->get(p_var); + EditorSettings::get_singleton()->set(p_var, p_default); + EditorSettings::get_singleton()->set_initial_value(p_var, p_default); - Node *root = sml->get_root()->get_child(0); + return p_default; +} - if (!root) { - return; - } - root->propagate_notification(NOTIFICATION_EDITOR_SETTINGS_CHANGED); +Variant _EDITOR_GET(const String &p_var) { + + ERR_FAIL_COND_V(!EditorSettings::get_singleton()->has_setting(p_var), Variant()) + return EditorSettings::get_singleton()->get(p_var); } -void EditorSettings::_add_property_info_bind(const Dictionary &p_info) { +bool EditorSettings::property_can_revert(const String &p_name) { - ERR_FAIL_COND(!p_info.has("name")); - ERR_FAIL_COND(!p_info.has("type")); + if (!props.has(p_name)) + return false; - PropertyInfo pinfo; - pinfo.name = p_info["name"]; - ERR_FAIL_COND(!props.has(pinfo.name)); - pinfo.type = Variant::Type(p_info["type"].operator int()); - ERR_FAIL_INDEX(pinfo.type, Variant::VARIANT_MAX); + return props[p_name].initial != props[p_name].variant; +} - if (p_info.has("hint")) - pinfo.hint = PropertyHint(p_info["hint"].operator int()); - if (p_info.has("hint_string")) - pinfo.hint_string = p_info["hint_string"]; +Variant EditorSettings::property_get_revert(const String &p_name) { - add_property_hint(pinfo); + if (!props.has(p_name)) + return Variant(); + + return props[p_name].initial; } void EditorSettings::add_property_hint(const PropertyInfo &p_hint) { @@ -901,6 +956,36 @@ void EditorSettings::add_property_hint(const PropertyInfo &p_hint) { hints[p_hint.name] = p_hint; } +// Settings paths and saved metadata + +String EditorSettings::get_settings_path() const { + + return settings_path; +} + +String EditorSettings::get_project_settings_path() const { + + return get_settings_path().plus_file("config").plus_file(project_config_path); +} + +void EditorSettings::set_project_metadata(const String &p_section, const String &p_key, Variant p_data) { + Ref cf = memnew(ConfigFile); + String path = get_project_settings_path().plus_file("project_metadata.cfg"); + cf->load(path); + cf->set_value(p_section, p_key, p_data); + cf->save(path); +} + +Variant EditorSettings::get_project_metadata(const String &p_section, const String &p_key, Variant p_default) { + Ref cf = memnew(ConfigFile); + String path = get_project_settings_path().plus_file("project_metadata.cfg"); + Error err = cf->load(path); + if (err != OK) { + return p_default; + } + return cf->get_value(p_section, p_key, p_default); +} + void EditorSettings::set_favorite_dirs(const Vector &p_favorites_dirs) { favorite_dirs = p_favorites_dirs; @@ -933,11 +1018,6 @@ Vector EditorSettings::get_recent_dirs() const { return recent_dirs; } -String EditorSettings::get_project_settings_path() const { - - return get_settings_path().plus_file("config").plus_file(project_config_path); -} - void EditorSettings::load_favorites() { FileAccess *f = FileAccess::open(get_project_settings_path().plus_file("favorite_dirs"), FileAccess::READ); @@ -1086,46 +1166,7 @@ Vector EditorSettings::get_script_templates(const String &p_extension) { return templates; } -bool EditorSettings::_save_text_editor_theme(String p_file) { - String theme_section = "color_theme"; - Ref cf = memnew(ConfigFile); // hex is better? - cf->set_value(theme_section, "background_color", ((Color)get("text_editor/highlighting/background_color")).to_html()); - cf->set_value(theme_section, "completion_background_color", ((Color)get("text_editor/highlighting/completion_background_color")).to_html()); - cf->set_value(theme_section, "completion_selected_color", ((Color)get("text_editor/highlighting/completion_selected_color")).to_html()); - cf->set_value(theme_section, "completion_existing_color", ((Color)get("text_editor/highlighting/completion_existing_color")).to_html()); - cf->set_value(theme_section, "completion_scroll_color", ((Color)get("text_editor/highlighting/completion_scroll_color")).to_html()); - cf->set_value(theme_section, "completion_font_color", ((Color)get("text_editor/highlighting/completion_font_color")).to_html()); - cf->set_value(theme_section, "caret_color", ((Color)get("text_editor/highlighting/caret_color")).to_html()); - cf->set_value(theme_section, "caret_background_color", ((Color)get("text_editor/highlighting/caret_background_color")).to_html()); - cf->set_value(theme_section, "line_number_color", ((Color)get("text_editor/highlighting/line_number_color")).to_html()); - cf->set_value(theme_section, "text_color", ((Color)get("text_editor/highlighting/text_color")).to_html()); - cf->set_value(theme_section, "text_selected_color", ((Color)get("text_editor/highlighting/text_selected_color")).to_html()); - cf->set_value(theme_section, "keyword_color", ((Color)get("text_editor/highlighting/keyword_color")).to_html()); - cf->set_value(theme_section, "base_type_color", ((Color)get("text_editor/highlighting/base_type_color")).to_html()); - cf->set_value(theme_section, "engine_type_color", ((Color)get("text_editor/highlighting/engine_type_color")).to_html()); - cf->set_value(theme_section, "function_color", ((Color)get("text_editor/highlighting/function_color")).to_html()); - cf->set_value(theme_section, "member_variable_color", ((Color)get("text_editor/highlighting/member_variable_color")).to_html()); - cf->set_value(theme_section, "comment_color", ((Color)get("text_editor/highlighting/comment_color")).to_html()); - cf->set_value(theme_section, "string_color", ((Color)get("text_editor/highlighting/string_color")).to_html()); - cf->set_value(theme_section, "number_color", ((Color)get("text_editor/highlighting/number_color")).to_html()); - cf->set_value(theme_section, "symbol_color", ((Color)get("text_editor/highlighting/symbol_color")).to_html()); - cf->set_value(theme_section, "selection_color", ((Color)get("text_editor/highlighting/selection_color")).to_html()); - cf->set_value(theme_section, "brace_mismatch_color", ((Color)get("text_editor/highlighting/brace_mismatch_color")).to_html()); - cf->set_value(theme_section, "current_line_color", ((Color)get("text_editor/highlighting/current_line_color")).to_html()); - cf->set_value(theme_section, "line_length_guideline_color", ((Color)get("text_editor/highlighting/line_length_guideline_color")).to_html()); - cf->set_value(theme_section, "mark_color", ((Color)get("text_editor/highlighting/mark_color")).to_html()); - cf->set_value(theme_section, "breakpoint_color", ((Color)get("text_editor/highlighting/breakpoint_color")).to_html()); - cf->set_value(theme_section, "word_highlighted_color", ((Color)get("text_editor/highlighting/word_highlighted_color")).to_html()); - cf->set_value(theme_section, "search_result_color", ((Color)get("text_editor/highlighting/search_result_color")).to_html()); - cf->set_value(theme_section, "search_result_border_color", ((Color)get("text_editor/highlighting/search_result_border_color")).to_html()); - - Error err = cf->save(p_file); - - if (err == OK) { - return true; - } - return false; -} +// Shortcuts void EditorSettings::add_shortcut(const String &p_name, Ref &p_shortcut) { @@ -1160,49 +1201,64 @@ void EditorSettings::get_shortcut_list(List *r_shortcuts) { } } -void EditorSettings::set_optimize_save(bool p_optimize) { +Ref ED_GET_SHORTCUT(const String &p_path) { - optimize_save = p_optimize; + Ref sc = EditorSettings::get_singleton()->get_shortcut(p_path); + if (!sc.is_valid()) { + ERR_EXPLAIN("Used ED_GET_SHORTCUT with invalid shortcut: " + p_path); + ERR_FAIL_COND_V(!sc.is_valid(), sc); + } + + return sc; } -Variant EditorSettings::get_project_metadata(const String &p_section, const String &p_key, Variant p_default) { - Ref cf = memnew(ConfigFile); - String path = get_project_settings_path().plus_file("project_metadata.cfg"); - Error err = cf->load(path); - if (err != OK) { - return p_default; +Ref ED_SHORTCUT(const String &p_path, const String &p_name, uint32_t p_keycode) { + + Ref ie; + if (p_keycode) { + ie.instance(); + + ie->set_unicode(p_keycode & KEY_CODE_MASK); + ie->set_scancode(p_keycode & KEY_CODE_MASK); + ie->set_shift(bool(p_keycode & KEY_MASK_SHIFT)); + ie->set_alt(bool(p_keycode & KEY_MASK_ALT)); + ie->set_control(bool(p_keycode & KEY_MASK_CTRL)); + ie->set_metakey(bool(p_keycode & KEY_MASK_META)); } - return cf->get_value(p_section, p_key, p_default); -} -void EditorSettings::set_project_metadata(const String &p_section, const String &p_key, Variant p_data) { - Ref cf = memnew(ConfigFile); - String path = get_project_settings_path().plus_file("project_metadata.cfg"); - cf->load(path); - cf->set_value(p_section, p_key, p_data); - cf->save(path); -} + Ref sc = EditorSettings::get_singleton()->get_shortcut(p_path); + if (sc.is_valid()) { -bool EditorSettings::property_can_revert(const String &p_name) { + sc->set_name(p_name); //keep name (the ones that come from disk have no name) + sc->set_meta("original", ie); //to compare against changes + return sc; + } - if (!props.has(p_name)) - return false; + sc.instance(); + sc->set_name(p_name); + sc->set_shortcut(ie); + sc->set_meta("original", ie); //to compare against changes + EditorSettings::get_singleton()->add_shortcut(p_path, sc); - return props[p_name].initial != props[p_name].variant; + return sc; } -Variant EditorSettings::property_get_revert(const String &p_name) { +void EditorSettings::notify_changes() { - if (!props.has(p_name)) - return Variant(); + _THREAD_SAFE_METHOD_ - return props[p_name].initial; -} + SceneTree *sml = Object::cast_to(OS::get_singleton()->get_main_loop()); -void EditorSettings::set_initial_value(const StringName &p_name, const Variant &p_value) { + if (!sml) { + return; + } - ERR_FAIL_COND(!props.has(p_name)); - props[p_name].initial = p_value; + Node *root = sml->get_root()->get_child(0); + + if (!root) { + return; + } + root->propagate_notification(NOTIFICATION_EDITOR_SETTINGS_CHANGED); } void EditorSettings::_bind_methods() { @@ -1210,24 +1266,20 @@ void EditorSettings::_bind_methods() { ClassDB::bind_method(D_METHOD("has_setting", "name"), &EditorSettings::has_setting); ClassDB::bind_method(D_METHOD("set_setting", "name", "value"), &EditorSettings::set_setting); ClassDB::bind_method(D_METHOD("get_setting", "name"), &EditorSettings::get_setting); - ClassDB::bind_method(D_METHOD("erase", "property"), &EditorSettings::erase); + ClassDB::bind_method(D_METHOD("set_initial_value", "name", "value"), &EditorSettings::set_initial_value); + ClassDB::bind_method(D_METHOD("property_can_revert", "name"), &EditorSettings::property_can_revert); + ClassDB::bind_method(D_METHOD("property_get_revert", "name"), &EditorSettings::property_get_revert); + ClassDB::bind_method(D_METHOD("add_property_info", "info"), &EditorSettings::_add_property_info_bind); + ClassDB::bind_method(D_METHOD("get_settings_path"), &EditorSettings::get_settings_path); ClassDB::bind_method(D_METHOD("get_project_settings_path"), &EditorSettings::get_project_settings_path); - ClassDB::bind_method(D_METHOD("add_property_info", "info"), &EditorSettings::_add_property_info_bind); - ClassDB::bind_method(D_METHOD("set_favorite_dirs", "dirs"), &EditorSettings::set_favorite_dirs); ClassDB::bind_method(D_METHOD("get_favorite_dirs"), &EditorSettings::get_favorite_dirs); - ClassDB::bind_method(D_METHOD("set_recent_dirs", "dirs"), &EditorSettings::set_recent_dirs); ClassDB::bind_method(D_METHOD("get_recent_dirs"), &EditorSettings::get_recent_dirs); - ClassDB::bind_method(D_METHOD("property_can_revert", "name"), &EditorSettings::property_can_revert); - ClassDB::bind_method(D_METHOD("property_get_revert", "name"), &EditorSettings::property_get_revert); - - ClassDB::bind_method(D_METHOD("set_initial_value", "name", "value"), &EditorSettings::set_initial_value); - ADD_SIGNAL(MethodInfo("settings_changed")); } @@ -1263,45 +1315,3 @@ EditorSettings::EditorSettings() { EditorSettings::~EditorSettings() { } - -Ref ED_GET_SHORTCUT(const String &p_path) { - - Ref sc = EditorSettings::get_singleton()->get_shortcut(p_path); - if (!sc.is_valid()) { - ERR_EXPLAIN("Used ED_GET_SHORTCUT with invalid shortcut: " + p_path); - ERR_FAIL_COND_V(!sc.is_valid(), sc); - } - - return sc; -} - -Ref ED_SHORTCUT(const String &p_path, const String &p_name, uint32_t p_keycode) { - - Ref ie; - if (p_keycode) { - ie.instance(); - - ie->set_unicode(p_keycode & KEY_CODE_MASK); - ie->set_scancode(p_keycode & KEY_CODE_MASK); - ie->set_shift(bool(p_keycode & KEY_MASK_SHIFT)); - ie->set_alt(bool(p_keycode & KEY_MASK_ALT)); - ie->set_control(bool(p_keycode & KEY_MASK_CTRL)); - ie->set_metakey(bool(p_keycode & KEY_MASK_META)); - } - - Ref sc = EditorSettings::get_singleton()->get_shortcut(p_path); - if (sc.is_valid()) { - - sc->set_name(p_name); //keep name (the ones that come from disk have no name) - sc->set_meta("original", ie); //to compare against changes - return sc; - } - - sc.instance(); - sc->set_name(p_name); - sc->set_shortcut(ie); - sc->set_meta("original", ie); //to compare against changes - EditorSettings::get_singleton()->add_shortcut(p_path, sc); - - return sc; -} diff --git a/editor/editor_settings.h b/editor/editor_settings.h index c5d2670650..cb6981f9e1 100644 --- a/editor/editor_settings.h +++ b/editor/editor_settings.h @@ -80,44 +80,37 @@ private: } }; + static Ref singleton; + HashMap hints; - int last_order; HashMap props; - String resource_path; - - bool _set(const StringName &p_name, const Variant &p_value, bool p_emit_signal = true); - bool _get(const StringName &p_name, Variant &r_ret) const; - void _get_property_list(List *p_list) const; - - void _initial_set(const StringName &p_name, const Variant &p_value); + int last_order; - static Ref singleton; + Ref clipboard; + Vector > translations; + Map > shortcuts; + String resource_path; String config_file_path; String settings_path; + String project_config_path; - Ref clipboard; + Vector favorite_dirs; + Vector recent_dirs; bool save_changed_setting; - bool optimize_save; //do not save stuff that came from config but was not set from engine + bool _set(const StringName &p_name, const Variant &p_value, bool p_emit_signal = true); + bool _get(const StringName &p_name, Variant &r_ret) const; + void _initial_set(const StringName &p_name, const Variant &p_value); + void _get_property_list(List *p_list) const; + void _add_property_info_bind(const Dictionary &p_info); + void _load_defaults(Ref p_extra_config = NULL); void _load_default_text_editor_theme(); - bool _save_text_editor_theme(String p_file); - String project_config_path; - - Vector favorite_dirs; - Vector recent_dirs; - - Vector > translations; - - Map > shortcuts; - - void _add_property_info_bind(const Dictionary &p_info); - protected: static void _bind_methods(); @@ -126,41 +119,41 @@ public: NOTIFICATION_EDITOR_SETTINGS_CHANGED = 10000 }; - void set_manually(const StringName &p_name, const Variant &p_value, bool p_emit_signal = false) { - _set(p_name, p_value, p_emit_signal); - } - - void set_setting(const String &p_setting, const Variant &p_value); - Variant get_setting(const String &p_setting) const; - - bool has_setting(String p_var) const; static EditorSettings *get_singleton(); - void erase(String p_var); - String get_settings_path() const; - //String get_global_settings_path() const; - String get_project_settings_path() const; + static void create(); void setup_language(); void setup_network(); - - void raise_order(const String &p_name); - static void create(); static void save(); static void destroy(); + void set_optimize_save(bool p_optimize); - void notify_changes(); + void set_setting(const String &p_setting, const Variant &p_value); + Variant get_setting(const String &p_setting) const; + bool has_setting(String p_var) const; + void erase(String p_var); + void raise_order(const String &p_name); + void set_initial_value(const StringName &p_name, const Variant &p_value); + void set_manually(const StringName &p_name, const Variant &p_value, bool p_emit_signal = false) { + _set(p_name, p_value, p_emit_signal); + } + bool property_can_revert(const String &p_name); + Variant property_get_revert(const String &p_name); + void add_property_hint(const PropertyInfo &p_hint); void set_resource_clipboard(const Ref &p_resource) { clipboard = p_resource; } Ref get_resource_clipboard() const { return clipboard; } - void add_property_hint(const PropertyInfo &p_hint); + String get_settings_path() const; + String get_project_settings_path() const; + + void set_project_metadata(const String &p_section, const String &p_key, Variant p_data); + Variant get_project_metadata(const String &p_section, const String &p_key, Variant p_default); void set_favorite_dirs(const Vector &p_favorites_dirs); Vector get_favorite_dirs() const; - void set_recent_dirs(const Vector &p_recent_dirs); Vector get_recent_dirs() const; - void load_favorites(); void list_text_editor_themes(); @@ -176,15 +169,7 @@ public: Ref get_shortcut(const String &p_name) const; void get_shortcut_list(List *r_shortcuts); - void set_optimize_save(bool p_optimize); - - Variant get_project_metadata(const String &p_section, const String &p_key, Variant p_default); - void set_project_metadata(const String &p_section, const String &p_key, Variant p_data); - - bool property_can_revert(const String &p_name); - Variant property_get_revert(const String &p_name); - - void set_initial_value(const StringName &p_name, const Variant &p_value); + void notify_changes(); EditorSettings(); ~EditorSettings(); -- cgit v1.2.3