From 7e9e3b767c4a5472163fc56001f3a0c4ef366e44 Mon Sep 17 00:00:00 2001 From: kit Date: Tue, 8 Jul 2025 22:18:10 -0400 Subject: [PATCH] Fix some Text Editor theme issues and clean up --- doc/classes/EditorSettings.xml | 41 ++- editor/script/script_editor_plugin.cpp | 96 +++-- editor/script/script_editor_plugin.h | 6 +- editor/settings/editor_settings.cpp | 329 ++++++------------ editor/settings/editor_settings.h | 12 +- editor/settings/editor_settings_dialog.cpp | 2 +- editor/themes/editor_theme_manager.cpp | 220 ++++++------ .../gdscript/editor/gdscript_highlighter.cpp | 79 ----- 8 files changed, 354 insertions(+), 431 deletions(-) diff --git a/doc/classes/EditorSettings.xml b/doc/classes/EditorSettings.xml index 4bfa4a57029..c07d48c5a1a 100644 --- a/doc/classes/EditorSettings.xml +++ b/doc/classes/EditorSettings.xml @@ -1499,6 +1499,27 @@ The script editor's comment color. [b]Note:[/b] In GDScript, unlike Python, multiline strings are not considered to be comments, and will use the string highlighting color instead. + + The script editor's critical comment marker text color. These markers are determined by [member text_editor/theme/highlighting/comment_markers/critical_list]. + + + A comma-separated list of case-sensitive words to highlight in comments. The text will be highlighted in the script editor with the [member text_editor/theme/highlighting/comment_markers/critical_color] color. These must not include spaces or symbols or they will not be highlighted. + [b]Note:[/b] This is only implemented in the GDScript syntax highlighter. + + + The script editor's notice comment marker text color. These markers are determined by [member text_editor/theme/highlighting/comment_markers/notice_list]. + + + A comma-separated list of case-sensitive words to highlight in comments. The text will be highlighted in the script editor with the [member text_editor/theme/highlighting/comment_markers/notice_color] color. These must not include spaces or symbols or they will not be highlighted. + [b]Note:[/b] This is only implemented in the GDScript syntax highlighter. + + + The script editor's warning comment marker text color. These markers are determined by [member text_editor/theme/highlighting/comment_markers/warning_list]. + + + A comma-separated list of case-sensitive words to highlight in comments. The text will be highlighted in the script editor with the [member text_editor/theme/highlighting/comment_markers/warning_color] color. These must not include spaces or symbols or they will not be highlighted. + [b]Note:[/b] This is only implemented in the GDScript syntax highlighter. + The script editor's autocompletion box background color. @@ -1537,7 +1558,25 @@ The script editor's function call color. - [b]Note:[/b] When using the GDScript syntax highlighter, this is replaced by the function definition color configured in the syntax theme for function definitions (e.g. [code]func _ready():[/code]). + [b]Note:[/b] When using the GDScript syntax highlighter, this is only used when calling some functions since function definitions and global functions have their own colors [member text_editor/theme/highlighting/gdscript/function_definition_color] and [member text_editor/theme/highlighting/gdscript/global_function_color]. + + + The GDScript syntax highlighter text color for annotations (e.g. [code]@export[/code]). + + + The GDScript syntax highlighter text color for function definitions (e.g. the [code]_ready[/code] in [code]func _ready():[/code]). + + + The GDScript syntax highlighter text color for global functions, such as the ones in [@GlobalScope] (e.g. [code]preload()[/code]). + + + The GDScript syntax highlighter text color for [NodePath] literals (e.g. [code]^"position:x"[/code]). + + + The GDScript syntax highlighter text color for node reference literals (e.g. [code]$"Sprite"[/code] and [code]%"Sprite"[/code]]). + + + The GDScript syntax highlighter text color for [StringName] literals (e.g. [code]>"example"[/code]). The script editor's non-control flow keyword color (used for keywords like [code]var[/code], [code]func[/code], [code]extends[/code], ...). diff --git a/editor/script/script_editor_plugin.cpp b/editor/script/script_editor_plugin.cpp index 1b5068fec5a..2eca9e0f88b 100644 --- a/editor/script/script_editor_plugin.cpp +++ b/editor/script/script_editor_plugin.cpp @@ -1222,6 +1222,73 @@ bool ScriptEditor::_test_script_times_on_disk(Ref p_for_script) { return need_reload; } +void _import_text_editor_theme(const String &p_file) { + if (p_file.get_extension() != "tet") { + EditorToaster::get_singleton()->popup_str(TTR("Importing theme failed. File is not a text editor theme file (.tet)."), EditorToaster::SEVERITY_ERROR); + return; + } + const String theme_name = p_file.get_file().get_basename(); + if (EditorSettings::is_default_text_editor_theme(theme_name.to_lower())) { + EditorToaster::get_singleton()->popup_str(TTR("Importing theme failed. File name cannot be 'Default', 'Custom', or 'Godot 2'."), EditorToaster::SEVERITY_ERROR); + return; + } + + const String theme_dir = EditorPaths::get_singleton()->get_text_editor_themes_dir(); + Ref d = DirAccess::open(theme_dir); + Error err = FAILED; + if (d.is_valid()) { + err = d->copy(p_file, theme_dir.path_join(p_file.get_file())); + } + + if (err != OK) { + EditorToaster::get_singleton()->popup_str(TTR("Importing theme failed. Failed to copy theme file."), EditorToaster::SEVERITY_ERROR); + return; + } + + // Reload themes and switch to new theme. + EditorSettings::get_singleton()->update_text_editor_themes_list(); + EditorSettings::get_singleton()->set_manually("text_editor/theme/color_theme", theme_name, true); + EditorSettings::get_singleton()->notify_changes(); +} + +void _save_text_editor_theme_as(const String &p_file) { + String file = p_file; + if (p_file.get_extension() != "tet") { + file += ".tet"; + } + + const String theme_name = file.get_file().get_basename(); + if (EditorSettings::is_default_text_editor_theme(theme_name.to_lower())) { + EditorToaster::get_singleton()->popup_str(TTR("Saving theme failed. File name cannot be 'Default', 'Custom', or 'Godot 2'."), EditorToaster::SEVERITY_ERROR); + return; + } + + const String theme_section = "color_theme"; + const Ref cf = memnew(ConfigFile); + + // Use the keys from the Godot 2 theme to know which settings to save. + HashMap text_colors = EditorSettings::get_godot2_text_editor_theme(); + text_colors.sort(); + for (const KeyValue &text_color : text_colors) { + const Color val = EditorSettings::get_singleton()->get_setting(text_color.key); + const String &key = text_color.key.operator String().replace("text_editor/theme/highlighting/", ""); + cf->set_value(theme_section, key, val.to_html()); + } + + const Error err = cf->save(file); + if (err != OK) { + EditorToaster::get_singleton()->popup_str(TTR("Saving theme failed."), EditorToaster::SEVERITY_ERROR); + return; + } + + // Reload themes and switch to saved theme. + EditorSettings::get_singleton()->update_text_editor_themes_list(); + if (p_file.get_base_dir() == EditorPaths::get_singleton()->get_text_editor_themes_dir()) { + // Don't need to emit signal or notify changes as the colors are already set. + EditorSettings::get_singleton()->set_manually("text_editor/theme/color_theme", theme_name, false); + } +} + void ScriptEditor::_file_dialog_action(const String &p_file) { switch (file_dialog_option) { case FILE_MENU_NEW_TEXTFILE: { @@ -1266,14 +1333,10 @@ void ScriptEditor::_file_dialog_action(const String &p_file) { } } break; case THEME_SAVE_AS: { - if (!EditorSettings::get_singleton()->save_text_editor_theme_as(p_file)) { - EditorNode::get_singleton()->show_warning(TTR("Error while saving theme."), TTR("Error Saving")); - } + _save_text_editor_theme_as(p_file); } break; case THEME_IMPORT: { - if (!EditorSettings::get_singleton()->import_text_editor_theme(p_file)) { - EditorNode::get_singleton()->show_warning(TTR("Error importing theme."), TTR("Error Importing")); - } + _import_text_editor_theme(p_file); } break; } file_dialog_option = -1; @@ -1642,14 +1705,8 @@ void ScriptEditor::_theme_option(int p_option) { file_dialog->popup_file_dialog(); } break; case THEME_RELOAD: { - EditorSettings::get_singleton()->load_text_editor_theme(); - } break; - case THEME_SAVE: { - if (EditorSettings::get_singleton()->is_default_text_editor_theme()) { - ScriptEditor::_show_save_theme_as_dialog(); - } else if (!EditorSettings::get_singleton()->save_text_editor_theme()) { - EditorNode::get_singleton()->show_warning(TTR("Error while saving theme"), TTR("Error saving")); - } + EditorSettings::get_singleton()->mark_setting_changed("text_editor/theme/color_theme"); + EditorSettings::get_singleton()->notify_changes(); } break; case THEME_SAVE_AS: { ScriptEditor::_show_save_theme_as_dialog(); @@ -1663,7 +1720,7 @@ void ScriptEditor::_show_save_theme_as_dialog() { file_dialog_option = THEME_SAVE_AS; file_dialog->clear_filters(); file_dialog->add_filter("*.tet"); - file_dialog->set_current_path(EditorPaths::get_singleton()->get_text_editor_themes_dir().path_join(EDITOR_GET("text_editor/theme/color_theme"))); + file_dialog->set_current_path(EditorPaths::get_singleton()->get_text_editor_themes_dir().path_join(EDITOR_GET("text_editor/theme/color_theme")) + " New"); file_dialog->set_title(TTRC("Save Theme As...")); file_dialog->popup_file_dialog(); } @@ -3033,13 +3090,6 @@ void ScriptEditor::_apply_editor_settings() { _update_autosave_timer(); - if (current_theme.is_empty()) { - current_theme = EDITOR_GET("text_editor/theme/color_theme"); - } else if (current_theme != String(EDITOR_GET("text_editor/theme/color_theme"))) { - current_theme = EDITOR_GET("text_editor/theme/color_theme"); - EditorSettings::get_singleton()->load_text_editor_theme(); - } - _update_script_names(); ScriptServer::set_reload_scripts_on_save(EDITOR_GET("text_editor/behavior/files/auto_reload_and_parse_scripts_on_save")); @@ -4161,7 +4211,6 @@ void ScriptEditor::_bind_methods() { ScriptEditor::ScriptEditor(WindowWrapper *p_wrapper) { window_wrapper = p_wrapper; - current_theme = ""; script_editor_cache.instantiate(); script_editor_cache->load(EditorPaths::get_singleton()->get_project_settings_dir().path_join("script_editor_cache.cfg")); @@ -4340,7 +4389,6 @@ ScriptEditor::ScriptEditor(WindowWrapper *p_wrapper) { theme_submenu->connect(SceneStringName(id_pressed), callable_mp(this, &ScriptEditor::_theme_option)); theme_submenu->add_separator(); - theme_submenu->add_shortcut(ED_SHORTCUT("script_editor/save_theme", TTRC("Save Theme")), THEME_SAVE); theme_submenu->add_shortcut(ED_SHORTCUT("script_editor/save_theme_as", TTRC("Save Theme As...")), THEME_SAVE_AS); file_menu->get_popup()->add_separator(); diff --git a/editor/script/script_editor_plugin.h b/editor/script/script_editor_plugin.h index 32aadaced7c..2a7f1f14a04 100644 --- a/editor/script/script_editor_plugin.h +++ b/editor/script/script_editor_plugin.h @@ -301,12 +301,10 @@ class ScriptEditor : public PanelContainer { SEARCH_HELP, SEARCH_WEBSITE, - }; - enum ThemeMenu { + // Theme. THEME_IMPORT, THEME_RELOAD, - THEME_SAVE, THEME_SAVE_AS, }; @@ -362,8 +360,6 @@ class ScriptEditor : public PanelContainer { Button *scripts_visible = nullptr; FindReplaceBar *find_replace_bar = nullptr; - String current_theme; - float zoom_factor = 1.0f; TextureRect *script_icon = nullptr; diff --git a/editor/settings/editor_settings.cpp b/editor/settings/editor_settings.cpp index 6175cc57039..14ee8f97b6c 100644 --- a/editor/settings/editor_settings.cpp +++ b/editor/settings/editor_settings.cpp @@ -695,45 +695,47 @@ void EditorSettings::_load_defaults(Ref p_extra_config) { EDITOR_SETTING_BASIC(Variant::STRING, PROPERTY_HINT_ENUM, "text_editor/theme/color_theme", "Default", "Default,Godot 2,Custom") // Theme: Highlighting - EDITOR_SETTING_BASIC(Variant::COLOR, PROPERTY_HINT_NONE, "text_editor/theme/highlighting/symbol_color", Color(0.73, 0.87, 1.0), "") - EDITOR_SETTING_BASIC(Variant::COLOR, PROPERTY_HINT_NONE, "text_editor/theme/highlighting/keyword_color", Color(1.0, 1.0, 0.7), "") - EDITOR_SETTING_BASIC(Variant::COLOR, PROPERTY_HINT_NONE, "text_editor/theme/highlighting/control_flow_keyword_color", Color(1.0, 0.85, 0.7), "") - EDITOR_SETTING_BASIC(Variant::COLOR, PROPERTY_HINT_NONE, "text_editor/theme/highlighting/base_type_color", Color(0.64, 1.0, 0.83), "") - EDITOR_SETTING_BASIC(Variant::COLOR, PROPERTY_HINT_NONE, "text_editor/theme/highlighting/engine_type_color", Color(0.51, 0.83, 1.0), "") - EDITOR_SETTING_BASIC(Variant::COLOR, PROPERTY_HINT_NONE, "text_editor/theme/highlighting/user_type_color", Color(0.42, 0.67, 0.93), "") - EDITOR_SETTING_BASIC(Variant::COLOR, PROPERTY_HINT_NONE, "text_editor/theme/highlighting/comment_color", Color(0.4, 0.4, 0.4), "") - EDITOR_SETTING_BASIC(Variant::COLOR, PROPERTY_HINT_NONE, "text_editor/theme/highlighting/doc_comment_color", Color(0.5, 0.6, 0.7), "") - EDITOR_SETTING_BASIC(Variant::COLOR, PROPERTY_HINT_NONE, "text_editor/theme/highlighting/string_color", Color(0.94, 0.43, 0.75), "") - EDITOR_SETTING_BASIC(Variant::COLOR, PROPERTY_HINT_NONE, "text_editor/theme/highlighting/background_color", Color(0.13, 0.12, 0.15), "") - EDITOR_SETTING(Variant::COLOR, PROPERTY_HINT_NONE, "text_editor/theme/highlighting/completion_background_color", Color(0.17, 0.16, 0.2), "") - EDITOR_SETTING(Variant::COLOR, PROPERTY_HINT_NONE, "text_editor/theme/highlighting/completion_selected_color", Color(0.26, 0.26, 0.27), "") - EDITOR_SETTING(Variant::COLOR, PROPERTY_HINT_NONE, "text_editor/theme/highlighting/completion_existing_color", Color(0.87, 0.87, 0.87, 0.13), "") - EDITOR_SETTING(Variant::COLOR, PROPERTY_HINT_NONE, "text_editor/theme/highlighting/completion_scroll_color", Color(1, 1, 1, 0.29), "") - EDITOR_SETTING(Variant::COLOR, PROPERTY_HINT_NONE, "text_editor/theme/highlighting/completion_scroll_hovered_color", Color(1, 1, 1, 0.4), "") - EDITOR_SETTING(Variant::COLOR, PROPERTY_HINT_NONE, "text_editor/theme/highlighting/completion_font_color", Color(0.67, 0.67, 0.67), "") - EDITOR_SETTING_BASIC(Variant::COLOR, PROPERTY_HINT_NONE, "text_editor/theme/highlighting/text_color", Color(0.67, 0.67, 0.67), "") - EDITOR_SETTING_BASIC(Variant::COLOR, PROPERTY_HINT_NONE, "text_editor/theme/highlighting/line_number_color", Color(0.67, 0.67, 0.67, 0.4), "") - EDITOR_SETTING_BASIC(Variant::COLOR, PROPERTY_HINT_NONE, "text_editor/theme/highlighting/safe_line_number_color", Color(0.67, 0.78, 0.67, 0.6), "") - EDITOR_SETTING_BASIC(Variant::COLOR, PROPERTY_HINT_NONE, "text_editor/theme/highlighting/caret_color", Color(0.67, 0.67, 0.67), "") - EDITOR_SETTING_BASIC(Variant::COLOR, PROPERTY_HINT_NONE, "text_editor/theme/highlighting/caret_background_color", Color(0, 0, 0), "") - EDITOR_SETTING_BASIC(Variant::COLOR, PROPERTY_HINT_NONE, "text_editor/theme/highlighting/text_selected_color", Color(0, 0, 0, 0), "") - EDITOR_SETTING_BASIC(Variant::COLOR, PROPERTY_HINT_NONE, "text_editor/theme/highlighting/selection_color", Color(0.41, 0.61, 0.91, 0.35), "") - EDITOR_SETTING_BASIC(Variant::COLOR, PROPERTY_HINT_NONE, "text_editor/theme/highlighting/brace_mismatch_color", Color(1, 0.2, 0.2), "") - EDITOR_SETTING_BASIC(Variant::COLOR, PROPERTY_HINT_NONE, "text_editor/theme/highlighting/current_line_color", Color(0.3, 0.5, 0.8, 0.15), "") - EDITOR_SETTING_BASIC(Variant::COLOR, PROPERTY_HINT_NONE, "text_editor/theme/highlighting/line_length_guideline_color", Color(0.3, 0.5, 0.8, 0.1), "") - EDITOR_SETTING_BASIC(Variant::COLOR, PROPERTY_HINT_NONE, "text_editor/theme/highlighting/word_highlighted_color", Color(0.8, 0.9, 0.9, 0.15), "") - EDITOR_SETTING_BASIC(Variant::COLOR, PROPERTY_HINT_NONE, "text_editor/theme/highlighting/number_color", Color(0.92, 0.58, 0.2), "") - EDITOR_SETTING_BASIC(Variant::COLOR, PROPERTY_HINT_NONE, "text_editor/theme/highlighting/function_color", Color(0.4, 0.64, 0.81), "") - EDITOR_SETTING_BASIC(Variant::COLOR, PROPERTY_HINT_NONE, "text_editor/theme/highlighting/member_variable_color", Color(0.9, 0.31, 0.35), "") - EDITOR_SETTING_BASIC(Variant::COLOR, PROPERTY_HINT_NONE, "text_editor/theme/highlighting/mark_color", Color(1.0, 0.4, 0.4, 0.4), "") - EDITOR_SETTING_BASIC(Variant::COLOR, PROPERTY_HINT_NONE, "text_editor/theme/highlighting/warning_color", Color(1.0, 0.8, 0.4, 0.1), "") - EDITOR_SETTING(Variant::COLOR, PROPERTY_HINT_NONE, "text_editor/theme/highlighting/bookmark_color", Color(0.08, 0.49, 0.98), "") - EDITOR_SETTING(Variant::COLOR, PROPERTY_HINT_NONE, "text_editor/theme/highlighting/breakpoint_color", Color(0.9, 0.29, 0.3), "") - EDITOR_SETTING(Variant::COLOR, PROPERTY_HINT_NONE, "text_editor/theme/highlighting/executing_line_color", Color(0.98, 0.89, 0.27), "") - EDITOR_SETTING(Variant::COLOR, PROPERTY_HINT_NONE, "text_editor/theme/highlighting/code_folding_color", Color(0.8, 0.8, 0.8, 0.8), "") - EDITOR_SETTING(Variant::COLOR, PROPERTY_HINT_NONE, "text_editor/theme/highlighting/folded_code_region_color", Color(0.68, 0.46, 0.77, 0.2), "") - EDITOR_SETTING(Variant::COLOR, PROPERTY_HINT_NONE, "text_editor/theme/highlighting/search_result_color", Color(0.05, 0.25, 0.05, 1), "") - EDITOR_SETTING(Variant::COLOR, PROPERTY_HINT_NONE, "text_editor/theme/highlighting/search_result_border_color", Color(0.41, 0.61, 0.91, 0.38), "") + const LocalVector basic_text_editor_settings = { + "text_editor/theme/highlighting/symbol_color", + "text_editor/theme/highlighting/keyword_color", + "text_editor/theme/highlighting/control_flow_keyword_color", + "text_editor/theme/highlighting/base_type_color", + "text_editor/theme/highlighting/engine_type_color", + "text_editor/theme/highlighting/user_type_color", + "text_editor/theme/highlighting/comment_color", + "text_editor/theme/highlighting/doc_comment_color", + "text_editor/theme/highlighting/string_color", + "text_editor/theme/highlighting/background_color", + "text_editor/theme/highlighting/text_color", + "text_editor/theme/highlighting/line_number_color", + "text_editor/theme/highlighting/safe_line_number_color", + "text_editor/theme/highlighting/caret_color", + "text_editor/theme/highlighting/caret_background_color", + "text_editor/theme/highlighting/text_selected_color", + "text_editor/theme/highlighting/selection_color", + "text_editor/theme/highlighting/brace_mismatch_color", + "text_editor/theme/highlighting/current_line_color", + "text_editor/theme/highlighting/line_length_guideline_color", + "text_editor/theme/highlighting/word_highlighted_color", + "text_editor/theme/highlighting/number_color", + "text_editor/theme/highlighting/function_color", + "text_editor/theme/highlighting/member_variable_color", + "text_editor/theme/highlighting/mark_color", + }; + // These values will be overwritten by EditorThemeManager, but can still be seen in some edge cases. + const HashMap text_colors = get_godot2_text_editor_theme(); + for (const KeyValue &text_color : text_colors) { + if (basic_text_editor_settings.has(text_color.key)) { + EDITOR_SETTING_BASIC(Variant::COLOR, PROPERTY_HINT_NONE, text_color.key, text_color.value, "") + } else { + EDITOR_SETTING(Variant::COLOR, PROPERTY_HINT_NONE, text_color.key, text_color.value, "") + } + } + + // The list is based on . + _initial_set("text_editor/theme/highlighting/comment_markers/critical_list", "ALERT,ATTENTION,CAUTION,CRITICAL,DANGER,SECURITY"); + _initial_set("text_editor/theme/highlighting/comment_markers/warning_list", "BUG,DEPRECATED,FIXME,HACK,TASK,TBD,TODO,WARNING"); + _initial_set("text_editor/theme/highlighting/comment_markers/notice_list", "INFO,NOTE,NOTICE,TEST,TESTING"); // Appearance EDITOR_SETTING_BASIC(Variant::BOOL, PROPERTY_HINT_NONE, "text_editor/appearance/enable_inline_color_picker", true, ""); @@ -1140,49 +1142,6 @@ void EditorSettings::_load_defaults(Ref p_extra_config) { } } -void EditorSettings::_load_godot2_text_editor_theme() { - // Godot 2 is only a dark theme; it doesn't have a light theme counterpart. - _initial_set("text_editor/theme/highlighting/symbol_color", Color(0.73, 0.87, 1.0), true); - _initial_set("text_editor/theme/highlighting/keyword_color", Color(1.0, 1.0, 0.7), true); - _initial_set("text_editor/theme/highlighting/control_flow_keyword_color", Color(1.0, 0.85, 0.7), true); - _initial_set("text_editor/theme/highlighting/base_type_color", Color(0.64, 1.0, 0.83), true); - _initial_set("text_editor/theme/highlighting/engine_type_color", Color(0.51, 0.83, 1.0), true); - _initial_set("text_editor/theme/highlighting/user_type_color", Color(0.42, 0.67, 0.93), true); - _initial_set("text_editor/theme/highlighting/comment_color", Color(0.4, 0.4, 0.4), true); - _initial_set("text_editor/theme/highlighting/doc_comment_color", Color(0.5, 0.6, 0.7), true); - _initial_set("text_editor/theme/highlighting/string_color", Color(0.94, 0.43, 0.75), true); - _initial_set("text_editor/theme/highlighting/background_color", Color(0.13, 0.12, 0.15), true); - _initial_set("text_editor/theme/highlighting/completion_background_color", Color(0.17, 0.16, 0.2)); - _initial_set("text_editor/theme/highlighting/completion_selected_color", Color(0.26, 0.26, 0.27)); - _initial_set("text_editor/theme/highlighting/completion_existing_color", Color(0.87, 0.87, 0.87, 0.13)); - _initial_set("text_editor/theme/highlighting/completion_scroll_color", Color(1, 1, 1, 0.29)); - _initial_set("text_editor/theme/highlighting/completion_scroll_hovered_color", Color(1, 1, 1, 0.4)); - _initial_set("text_editor/theme/highlighting/completion_font_color", Color(0.67, 0.67, 0.67)); - _initial_set("text_editor/theme/highlighting/text_color", Color(0.67, 0.67, 0.67), true); - _initial_set("text_editor/theme/highlighting/line_number_color", Color(0.67, 0.67, 0.67, 0.4), true); - _initial_set("text_editor/theme/highlighting/safe_line_number_color", Color(0.67, 0.78, 0.67, 0.6), true); - _initial_set("text_editor/theme/highlighting/caret_color", Color(0.67, 0.67, 0.67), true); - _initial_set("text_editor/theme/highlighting/caret_background_color", Color(0, 0, 0), true); - _initial_set("text_editor/theme/highlighting/text_selected_color", Color(0, 0, 0, 0), true); - _initial_set("text_editor/theme/highlighting/selection_color", Color(0.41, 0.61, 0.91, 0.35), true); - _initial_set("text_editor/theme/highlighting/brace_mismatch_color", Color(1, 0.2, 0.2), true); - _initial_set("text_editor/theme/highlighting/current_line_color", Color(0.3, 0.5, 0.8, 0.15), true); - _initial_set("text_editor/theme/highlighting/line_length_guideline_color", Color(0.3, 0.5, 0.8, 0.1), true); - _initial_set("text_editor/theme/highlighting/word_highlighted_color", Color(0.8, 0.9, 0.9, 0.15), true); - _initial_set("text_editor/theme/highlighting/number_color", Color(0.92, 0.58, 0.2), true); - _initial_set("text_editor/theme/highlighting/function_color", Color(0.4, 0.64, 0.81), true); - _initial_set("text_editor/theme/highlighting/member_variable_color", Color(0.9, 0.31, 0.35), true); - _initial_set("text_editor/theme/highlighting/mark_color", Color(1.0, 0.4, 0.4, 0.4), true); - _initial_set("text_editor/theme/highlighting/warning_color", Color(1.0, 0.8, 0.4, 0.1), true); - _initial_set("text_editor/theme/highlighting/bookmark_color", Color(0.08, 0.49, 0.98)); - _initial_set("text_editor/theme/highlighting/breakpoint_color", Color(0.9, 0.29, 0.3)); - _initial_set("text_editor/theme/highlighting/executing_line_color", Color(0.98, 0.89, 0.27)); - _initial_set("text_editor/theme/highlighting/code_folding_color", Color(0.8, 0.8, 0.8, 0.8)); - _initial_set("text_editor/theme/highlighting/folded_code_region_color", Color(0.68, 0.46, 0.77, 0.2)); - _initial_set("text_editor/theme/highlighting/search_result_color", Color(0.05, 0.25, 0.05, 1)); - _initial_set("text_editor/theme/highlighting/search_result_border_color", Color(0.41, 0.61, 0.91, 0.38)); -} - void EditorSettings::_load_default_visual_shader_editor_theme() { // Connection type colors _initial_set("editors/visual_editors/connection_colors/scalar_color", Color(0.55, 0.55, 0.55)); @@ -1241,33 +1200,6 @@ String EditorSettings::_guess_exec_args_for_extenal_editor(const String &p_path) return new_exec_flags; } -bool EditorSettings::_save_text_editor_theme(const String &p_file) { - String theme_section = "color_theme"; - Ref cf = memnew(ConfigFile); // hex is better? - - List keys; - - for (const KeyValue &E : props) { - keys.push_back(E.key); - } - - keys.sort(); - - for (const String &key : keys) { - if (key.begins_with("text_editor/theme/highlighting/") && key.contains("color")) { - cf->set_value(theme_section, key.replace("text_editor/theme/highlighting/", ""), ((Color)props[key].variant).to_html()); - } - } - - Error err = cf->save(p_file); - - return err == OK; -} - -bool EditorSettings::_is_default_text_editor_theme(const String &p_theme_name) { - return p_theme_name == "default" || p_theme_name == "godot 2" || p_theme_name == "custom"; -} - const String EditorSettings::_get_project_metadata_path() const { return EditorPaths::get_singleton()->get_project_settings_dir().path_join("project_metadata.cfg"); } @@ -1360,7 +1292,7 @@ void EditorSettings::create() { singleton->setup_language(); singleton->setup_network(); singleton->load_favorites_and_recent_dirs(); - singleton->list_text_editor_themes(); + singleton->update_text_editor_themes_list(); #ifndef DISABLE_DEPRECATED singleton->_remove_deprecated_settings(); #endif @@ -1386,7 +1318,7 @@ fail: singleton->_load_defaults(extra_config); singleton->setup_language(); singleton->setup_network(); - singleton->list_text_editor_themes(); + singleton->update_text_editor_themes_list(); } void EditorSettings::setup_language() { @@ -1748,118 +1680,89 @@ void EditorSettings::load_favorites_and_recent_dirs() { } } -void EditorSettings::list_text_editor_themes() { +HashMap EditorSettings::get_godot2_text_editor_theme() { + // Godot 2 is only a dark theme; it doesn't have a light theme counterpart. + HashMap colors; + colors["text_editor/theme/highlighting/symbol_color"] = Color(0.73, 0.87, 1.0); + colors["text_editor/theme/highlighting/keyword_color"] = Color(1.0, 1.0, 0.7); + colors["text_editor/theme/highlighting/control_flow_keyword_color"] = Color(1.0, 0.85, 0.7); + colors["text_editor/theme/highlighting/base_type_color"] = Color(0.64, 1.0, 0.83); + colors["text_editor/theme/highlighting/engine_type_color"] = Color(0.51, 0.83, 1.0); + colors["text_editor/theme/highlighting/user_type_color"] = Color(0.42, 0.67, 0.93); + colors["text_editor/theme/highlighting/comment_color"] = Color(0.4, 0.4, 0.4); + colors["text_editor/theme/highlighting/doc_comment_color"] = Color(0.5, 0.6, 0.7); + colors["text_editor/theme/highlighting/string_color"] = Color(0.94, 0.43, 0.75); + colors["text_editor/theme/highlighting/background_color"] = Color(0.13, 0.12, 0.15); + colors["text_editor/theme/highlighting/completion_background_color"] = Color(0.17, 0.16, 0.2); + colors["text_editor/theme/highlighting/completion_selected_color"] = Color(0.26, 0.26, 0.27); + colors["text_editor/theme/highlighting/completion_existing_color"] = Color(0.87, 0.87, 0.87, 0.13); + colors["text_editor/theme/highlighting/completion_scroll_color"] = Color(1, 1, 1, 0.29); + colors["text_editor/theme/highlighting/completion_scroll_hovered_color"] = Color(1, 1, 1, 0.4); + colors["text_editor/theme/highlighting/completion_font_color"] = Color(0.67, 0.67, 0.67); + colors["text_editor/theme/highlighting/text_color"] = Color(0.67, 0.67, 0.67); + colors["text_editor/theme/highlighting/line_number_color"] = Color(0.67, 0.67, 0.67, 0.4); + colors["text_editor/theme/highlighting/safe_line_number_color"] = Color(0.67, 0.78, 0.67, 0.6); + colors["text_editor/theme/highlighting/caret_color"] = Color(0.67, 0.67, 0.67); + colors["text_editor/theme/highlighting/caret_background_color"] = Color(0, 0, 0); + colors["text_editor/theme/highlighting/text_selected_color"] = Color(0, 0, 0, 0); + colors["text_editor/theme/highlighting/selection_color"] = Color(0.41, 0.61, 0.91, 0.35); + colors["text_editor/theme/highlighting/brace_mismatch_color"] = Color(1, 0.2, 0.2); + colors["text_editor/theme/highlighting/current_line_color"] = Color(0.3, 0.5, 0.8, 0.15); + colors["text_editor/theme/highlighting/line_length_guideline_color"] = Color(0.3, 0.5, 0.8, 0.1); + colors["text_editor/theme/highlighting/word_highlighted_color"] = Color(0.8, 0.9, 0.9, 0.15); + colors["text_editor/theme/highlighting/number_color"] = Color(0.92, 0.58, 0.2); + colors["text_editor/theme/highlighting/function_color"] = Color(0.4, 0.64, 0.81); + colors["text_editor/theme/highlighting/member_variable_color"] = Color(0.9, 0.31, 0.35); + colors["text_editor/theme/highlighting/mark_color"] = Color(1.0, 0.4, 0.4, 0.4); + colors["text_editor/theme/highlighting/warning_color"] = Color(1.0, 0.8, 0.4, 0.1); + colors["text_editor/theme/highlighting/bookmark_color"] = Color(0.08, 0.49, 0.98); + colors["text_editor/theme/highlighting/breakpoint_color"] = Color(0.9, 0.29, 0.3); + colors["text_editor/theme/highlighting/executing_line_color"] = Color(0.98, 0.89, 0.27); + colors["text_editor/theme/highlighting/code_folding_color"] = Color(0.8, 0.8, 0.8, 0.8); + colors["text_editor/theme/highlighting/folded_code_region_color"] = Color(0.68, 0.46, 0.77, 0.2); + colors["text_editor/theme/highlighting/search_result_color"] = Color(0.05, 0.25, 0.05, 1); + colors["text_editor/theme/highlighting/search_result_border_color"] = Color(0.41, 0.61, 0.91, 0.38); + colors["text_editor/theme/highlighting/gdscript/function_definition_color"] = Color(0.4, 0.9, 1.0); + + colors["text_editor/theme/highlighting/gdscript/global_function_color"] = Color(0.64, 0.64, 0.96); + colors["text_editor/theme/highlighting/gdscript/node_path_color"] = Color(0.72, 0.77, 0.49); + colors["text_editor/theme/highlighting/gdscript/node_reference_color"] = Color(0.39, 0.76, 0.35); + colors["text_editor/theme/highlighting/gdscript/annotation_color"] = Color(1.0, 0.7, 0.45); + colors["text_editor/theme/highlighting/gdscript/string_name_color"] = Color(1.0, 0.76, 0.65); + colors["text_editor/theme/highlighting/comment_markers/critical_color"] = Color(0.77, 0.35, 0.35); + colors["text_editor/theme/highlighting/comment_markers/warning_color"] = Color(0.72, 0.61, 0.48); + colors["text_editor/theme/highlighting/comment_markers/notice_color"] = Color(0.56, 0.67, 0.51); + return colors; +} + +bool EditorSettings::is_default_text_editor_theme(const String &p_theme_name) { + return p_theme_name == "default" || p_theme_name == "godot 2" || p_theme_name == "custom"; +} + +void EditorSettings::update_text_editor_themes_list() { String themes = "Default,Godot 2,Custom"; Ref d = DirAccess::open(EditorPaths::get_singleton()->get_text_editor_themes_dir()); - if (d.is_valid()) { - List custom_themes; - d->list_dir_begin(); - String file = d->get_next(); - while (!file.is_empty()) { - if (file.get_extension() == "tet" && !_is_default_text_editor_theme(file.get_basename().to_lower())) { - custom_themes.push_back(file.get_basename()); - } - file = d->get_next(); - } - d->list_dir_end(); - - custom_themes.sort(); - for (const String &E : custom_themes) { - themes += "," + E; - } - } - add_property_hint(PropertyInfo(Variant::STRING, "text_editor/theme/color_theme", PROPERTY_HINT_ENUM, themes)); -} - -void EditorSettings::load_text_editor_theme() { - String p_file = get("text_editor/theme/color_theme"); - - if (_is_default_text_editor_theme(p_file.get_file().to_lower())) { - if (p_file == "Godot 2") { - _load_godot2_text_editor_theme(); - } - return; // sorry for "Settings changed" console spam - } - - String theme_path = EditorPaths::get_singleton()->get_text_editor_themes_dir().path_join(p_file + ".tet"); - - Ref cf = memnew(ConfigFile); - Error err = cf->load(theme_path); - - if (err != OK) { + if (d.is_null()) { return; } - Vector keys = cf->get_section_keys("color_theme"); - - for (const String &key : keys) { - String val = cf->get_value("color_theme", key); - - // don't load if it's not already there! - if (has_setting("text_editor/theme/highlighting/" + key)) { - // make sure it is actually a color - if (val.is_valid_html_color() && key.contains("color")) { - props["text_editor/theme/highlighting/" + key].variant = Color::html(val); // change manually to prevent "Settings changed" console spam - } + PackedStringArray custom_themes; + d->list_dir_begin(); + String file = d->get_next(); + while (!file.is_empty()) { + if (file.get_extension() == "tet" && !is_default_text_editor_theme(file.get_basename().to_lower())) { + custom_themes.push_back(file.get_basename()); } + file = d->get_next(); } - emit_signal(SNAME("settings_changed")); - // if it doesn't load just use what is currently loaded -} + d->list_dir_end(); -bool EditorSettings::import_text_editor_theme(const String &p_file) { - if (!p_file.ends_with(".tet")) { - return false; - } else { - if (p_file.get_file().to_lower() == "default.tet") { - return false; - } - - Ref d = DirAccess::open(EditorPaths::get_singleton()->get_text_editor_themes_dir()); - if (d.is_valid()) { - d->copy(p_file, EditorPaths::get_singleton()->get_text_editor_themes_dir().path_join(p_file.get_file())); - return true; - } + if (!custom_themes.is_empty()) { + custom_themes.sort(); + themes += "," + String(",").join(custom_themes); } - return false; -} - -bool EditorSettings::save_text_editor_theme() { - String p_file = get("text_editor/theme/color_theme"); - - if (_is_default_text_editor_theme(p_file.get_file().to_lower())) { - return false; - } - String theme_path = EditorPaths::get_singleton()->get_text_editor_themes_dir().path_join(p_file + ".tet"); - return _save_text_editor_theme(theme_path); -} - -bool EditorSettings::save_text_editor_theme_as(String p_file) { - if (!p_file.ends_with(".tet")) { - p_file += ".tet"; - } - - if (_is_default_text_editor_theme(p_file.get_file().to_lower().trim_suffix(".tet"))) { - return false; - } - if (_save_text_editor_theme(p_file)) { - // switch to theme is saved in the theme directory - list_text_editor_themes(); - String theme_name = p_file.substr(0, p_file.length() - 4).get_file(); - - if (p_file.get_base_dir() == EditorPaths::get_singleton()->get_text_editor_themes_dir()) { - _initial_set("text_editor/theme/color_theme", theme_name); - load_text_editor_theme(); - } - return true; - } - return false; -} - -bool EditorSettings::is_default_text_editor_theme() { - String p_file = get("text_editor/theme/color_theme"); - return _is_default_text_editor_theme(p_file.get_file().to_lower()); + add_property_hint(PropertyInfo(Variant::STRING, "text_editor/theme/color_theme", PROPERTY_HINT_ENUM, themes)); } Vector EditorSettings::get_script_templates(const String &p_extension, const String &p_custom_path) { diff --git a/editor/settings/editor_settings.h b/editor/settings/editor_settings.h index e58eeec5863..78e8aa053de 100644 --- a/editor/settings/editor_settings.h +++ b/editor/settings/editor_settings.h @@ -118,10 +118,7 @@ private: void _set_initialized(); void _load_defaults(Ref p_extra_config = Ref()); - void _load_godot2_text_editor_theme(); void _load_default_visual_shader_editor_theme(); - bool _save_text_editor_theme(const String &p_file); - bool _is_default_text_editor_theme(const String &p_theme_name); static String _guess_exec_args_for_extenal_editor(const String &p_value); const String _get_project_metadata_path() const; #ifndef DISABLE_DEPRECATED @@ -182,12 +179,9 @@ public: Vector get_recent_dirs() const; void load_favorites_and_recent_dirs(); - void list_text_editor_themes(); - void load_text_editor_theme(); - bool import_text_editor_theme(const String &p_file); - bool save_text_editor_theme(); - bool save_text_editor_theme_as(String p_file); - bool is_default_text_editor_theme(); + static HashMap get_godot2_text_editor_theme(); + static bool is_default_text_editor_theme(const String &p_theme_name); + void update_text_editor_themes_list(); Vector get_script_templates(const String &p_extension, const String &p_custom_path = String()); String get_editor_layouts_config() const; diff --git a/editor/settings/editor_settings_dialog.cpp b/editor/settings/editor_settings_dialog.cpp index a51e4a2ec2e..5f500ae19af 100644 --- a/editor/settings/editor_settings_dialog.cpp +++ b/editor/settings/editor_settings_dialog.cpp @@ -196,7 +196,7 @@ void EditorSettingsDialog::popup_edit_settings() { return; } - EditorSettings::get_singleton()->list_text_editor_themes(); // make sure we have an up to date list of themes + EditorSettings::get_singleton()->update_text_editor_themes_list(); // Make sure we have an up to date list of themes. _update_dynamic_property_hints(); diff --git a/editor/themes/editor_theme_manager.cpp b/editor/themes/editor_theme_manager.cpp index 0fcbd690ef4..750e96c198f 100644 --- a/editor/themes/editor_theme_manager.cpp +++ b/editor/themes/editor_theme_manager.cpp @@ -33,6 +33,7 @@ #include "core/error/error_macros.h" #include "core/io/resource_loader.h" #include "editor/editor_string_names.h" +#include "editor/file_system/editor_paths.h" #include "editor/settings/editor_settings.h" #include "editor/themes/editor_color_map.h" #include "editor/themes/editor_fonts.h" @@ -2633,111 +2634,132 @@ void EditorThemeManager::_populate_editor_styles(const Ref &p_theme } } +void _load_text_editor_theme() { + EditorSettings *settings = EditorSettings::get_singleton(); + const String theme_name = settings->get_setting("text_editor/theme/color_theme"); + + ERR_FAIL_COND(EditorSettings::is_default_text_editor_theme(theme_name.get_file().to_lower())); + + const String theme_path = EditorPaths::get_singleton()->get_text_editor_themes_dir().path_join(theme_name + ".tet"); + + Ref cf; + cf.instantiate(); + Error err = cf->load(theme_path); + ERR_FAIL_COND_MSG(err != OK, vformat("Failed to load text editor theme file '%s': %s", theme_name, error_names[err])); + + const PackedStringArray keys = cf->get_section_keys("color_theme"); + + for (const String &key : keys) { + const String setting_key = "text_editor/theme/highlighting/" + key; + // Don't load if it's not an actual setting, or if it isn't a color setting. + if (!settings->has_setting(setting_key) || !key.contains("color")) { + continue; + } + const String val = cf->get_value("color_theme", key); + // Make sure it is actually a color. + if (val.is_valid_html_color()) { + const Color color_value = Color::html(val); + // Change manually to prevent settings_changed spam. + settings->set_initial_value(setting_key, color_value); + settings->set_manually(setting_key, color_value); + } + } + // If it doesn't load a setting just use what is currently loaded. +} + void EditorThemeManager::_populate_text_editor_styles(const Ref &p_theme, ThemeConfiguration &p_config) { - String text_editor_color_theme = EDITOR_GET("text_editor/theme/color_theme"); - if (text_editor_color_theme == "Default" || text_editor_color_theme == "Custom") { - // Adaptive colors for comments and elements with lower relevance. - const Color dim_color = Color(p_config.font_color, 0.5); - const float mono_value = p_config.mono_color.r; - const Color alpha1 = Color(mono_value, mono_value, mono_value, 0.07); - const Color alpha2 = Color(mono_value, mono_value, mono_value, 0.14); - const Color alpha3 = Color(mono_value, mono_value, mono_value, 0.27); - - /* clang-format off */ - // Syntax highlight token colors. - const Color symbol_color = p_config.dark_theme ? Color(0.67, 0.79, 1) : Color(0, 0, 0.61); - const Color keyword_color = p_config.dark_theme ? Color(1.0, 0.44, 0.52) : Color(0.9, 0.135, 0.51); - const Color control_flow_keyword_color = p_config.dark_theme ? Color(1.0, 0.55, 0.8) : Color(0.743, 0.12, 0.8); - const Color base_type_color = p_config.dark_theme ? Color(0.26, 1.0, 0.76) : Color(0, 0.6, 0.2); - const Color engine_type_color = p_config.dark_theme ? Color(0.56, 1, 0.86) : Color(0.11, 0.55, 0.4); - const Color user_type_color = p_config.dark_theme ? Color(0.78, 1, 0.93) : Color(0.18, 0.45, 0.4); - const Color comment_color = p_config.dark_theme ? dim_color : Color(0.08, 0.08, 0.08, 0.5); - const Color doc_comment_color = p_config.dark_theme ? Color(0.6, 0.7, 0.8, 0.8) : Color(0.15, 0.15, 0.4, 0.7); - const Color string_color = p_config.dark_theme ? Color(1, 0.93, 0.63) : Color(0.6, 0.42, 0); - - // Use the brightest background color on a light theme (which generally uses a negative contrast rate). - const Color te_background_color = p_config.dark_theme ? p_config.dark_color_2 : p_config.dark_color_3; - const Color completion_background_color = p_config.dark_theme ? p_config.base_color : p_config.dark_color_2; - const Color completion_selected_color = alpha1; - const Color completion_existing_color = alpha2; - // Same opacity as the scroll grabber editor icon. - const Color completion_scroll_color = Color(mono_value, mono_value, mono_value, 0.29); - const Color completion_scroll_hovered_color = Color(mono_value, mono_value, mono_value, 0.4); - const Color completion_font_color = p_config.font_color; - const Color text_color = p_config.font_color; - const Color line_number_color = dim_color; - const Color safe_line_number_color = p_config.dark_theme ? (dim_color * Color(1, 1.2, 1, 1.5)) : Color(0, 0.4, 0, 0.75); - const Color caret_color = p_config.mono_color; - const Color caret_background_color = p_config.mono_color.inverted(); - const Color text_selected_color = Color(0, 0, 0, 0); - const Color selection_color = p_config.selection_color; - const Color brace_mismatch_color = p_config.dark_theme ? p_config.error_color : Color(1, 0.08, 0, 1); - const Color current_line_color = alpha1; - const Color line_length_guideline_color = p_config.dark_theme ? p_config.base_color : p_config.dark_color_2; - const Color word_highlighted_color = alpha1; - const Color number_color = p_config.dark_theme ? Color(0.63, 1, 0.88) : Color(0, 0.55, 0.28, 1); - const Color function_color = p_config.dark_theme ? Color(0.34, 0.7, 1.0) : Color(0, 0.225, 0.9, 1); - const Color member_variable_color = p_config.dark_theme ? Color(0.34, 0.7, 1.0).lerp(p_config.mono_color, 0.6) : Color(0, 0.4, 0.68, 1); - const Color mark_color = Color(p_config.error_color.r, p_config.error_color.g, p_config.error_color.b, 0.3); - const Color warning_color = Color(p_config.warning_color.r, p_config.warning_color.g, p_config.warning_color.b, 0.15); - const Color bookmark_color = Color(0.08, 0.49, 0.98); - const Color breakpoint_color = p_config.dark_theme ? p_config.error_color : Color(1, 0.27, 0.2, 1); - const Color executing_line_color = Color(0.98, 0.89, 0.27); - const Color code_folding_color = alpha3; - const Color folded_code_region_color = Color(0.68, 0.46, 0.77, 0.2); - const Color search_result_color = alpha1; - const Color search_result_border_color = p_config.dark_theme ? Color(0.41, 0.61, 0.91, 0.38) : Color(0, 0.4, 1, 0.38); - /* clang-format on */ - + const String text_editor_color_theme = EDITOR_GET("text_editor/theme/color_theme"); + const bool is_default_theme = text_editor_color_theme == "Default"; + const bool is_godot2_theme = text_editor_color_theme == "Godot 2"; + const bool is_custom_theme = text_editor_color_theme == "Custom"; + if (is_default_theme || is_godot2_theme || is_custom_theme) { HashMap colors; - colors["text_editor/theme/highlighting/symbol_color"] = symbol_color; - colors["text_editor/theme/highlighting/keyword_color"] = keyword_color; - colors["text_editor/theme/highlighting/control_flow_keyword_color"] = control_flow_keyword_color; - colors["text_editor/theme/highlighting/base_type_color"] = base_type_color; - colors["text_editor/theme/highlighting/engine_type_color"] = engine_type_color; - colors["text_editor/theme/highlighting/user_type_color"] = user_type_color; - colors["text_editor/theme/highlighting/comment_color"] = comment_color; - colors["text_editor/theme/highlighting/doc_comment_color"] = doc_comment_color; - colors["text_editor/theme/highlighting/string_color"] = string_color; - colors["text_editor/theme/highlighting/background_color"] = te_background_color; - colors["text_editor/theme/highlighting/completion_background_color"] = completion_background_color; - colors["text_editor/theme/highlighting/completion_selected_color"] = completion_selected_color; - colors["text_editor/theme/highlighting/completion_existing_color"] = completion_existing_color; - colors["text_editor/theme/highlighting/completion_scroll_color"] = completion_scroll_color; - colors["text_editor/theme/highlighting/completion_scroll_hovered_color"] = completion_scroll_hovered_color; - colors["text_editor/theme/highlighting/completion_font_color"] = completion_font_color; - colors["text_editor/theme/highlighting/text_color"] = text_color; - colors["text_editor/theme/highlighting/line_number_color"] = line_number_color; - colors["text_editor/theme/highlighting/safe_line_number_color"] = safe_line_number_color; - colors["text_editor/theme/highlighting/caret_color"] = caret_color; - colors["text_editor/theme/highlighting/caret_background_color"] = caret_background_color; - colors["text_editor/theme/highlighting/text_selected_color"] = text_selected_color; - colors["text_editor/theme/highlighting/selection_color"] = selection_color; - colors["text_editor/theme/highlighting/brace_mismatch_color"] = brace_mismatch_color; - colors["text_editor/theme/highlighting/current_line_color"] = current_line_color; - colors["text_editor/theme/highlighting/line_length_guideline_color"] = line_length_guideline_color; - colors["text_editor/theme/highlighting/word_highlighted_color"] = word_highlighted_color; - colors["text_editor/theme/highlighting/number_color"] = number_color; - colors["text_editor/theme/highlighting/function_color"] = function_color; - colors["text_editor/theme/highlighting/member_variable_color"] = member_variable_color; - colors["text_editor/theme/highlighting/mark_color"] = mark_color; - colors["text_editor/theme/highlighting/warning_color"] = warning_color; - colors["text_editor/theme/highlighting/bookmark_color"] = bookmark_color; - colors["text_editor/theme/highlighting/breakpoint_color"] = breakpoint_color; - colors["text_editor/theme/highlighting/executing_line_color"] = executing_line_color; - colors["text_editor/theme/highlighting/code_folding_color"] = code_folding_color; - colors["text_editor/theme/highlighting/folded_code_region_color"] = folded_code_region_color; - colors["text_editor/theme/highlighting/search_result_color"] = search_result_color; - colors["text_editor/theme/highlighting/search_result_border_color"] = search_result_border_color; + if (is_default_theme || is_custom_theme) { + // Adaptive colors for comments and elements with lower relevance. + const Color dim_color = Color(p_config.font_color, 0.5); + const float mono_value = p_config.mono_color.r; + const Color alpha1 = Color(mono_value, mono_value, mono_value, 0.07); + const Color alpha2 = Color(mono_value, mono_value, mono_value, 0.14); + const Color alpha3 = Color(mono_value, mono_value, mono_value, 0.27); + // Syntax highlight token colors. + colors["text_editor/theme/highlighting/symbol_color"] = p_config.dark_theme ? Color(0.67, 0.79, 1) : Color(0, 0, 0.61); + colors["text_editor/theme/highlighting/keyword_color"] = p_config.dark_theme ? Color(1.0, 0.44, 0.52) : Color(0.9, 0.135, 0.51); + colors["text_editor/theme/highlighting/control_flow_keyword_color"] = p_config.dark_theme ? Color(1.0, 0.55, 0.8) : Color(0.743, 0.12, 0.8); + colors["text_editor/theme/highlighting/base_type_color"] = p_config.dark_theme ? Color(0.26, 1.0, 0.76) : Color(0, 0.6, 0.2); + colors["text_editor/theme/highlighting/engine_type_color"] = p_config.dark_theme ? Color(0.56, 1, 0.86) : Color(0.11, 0.55, 0.4); + colors["text_editor/theme/highlighting/user_type_color"] = p_config.dark_theme ? Color(0.78, 1, 0.93) : Color(0.18, 0.45, 0.4); + colors["text_editor/theme/highlighting/comment_color"] = p_config.dark_theme ? dim_color : Color(0.08, 0.08, 0.08, 0.5); + colors["text_editor/theme/highlighting/doc_comment_color"] = p_config.dark_theme ? Color(0.6, 0.7, 0.8, 0.8) : Color(0.15, 0.15, 0.4, 0.7); + colors["text_editor/theme/highlighting/string_color"] = p_config.dark_theme ? Color(1, 0.93, 0.63) : Color(0.6, 0.42, 0); + + // Use the brightest background color on a light theme (which generally uses a negative contrast rate). + colors["text_editor/theme/highlighting/background_color"] = p_config.dark_theme ? p_config.dark_color_2 : p_config.dark_color_3; + colors["text_editor/theme/highlighting/completion_background_color"] = p_config.dark_theme ? p_config.base_color : p_config.dark_color_2; + colors["text_editor/theme/highlighting/completion_selected_color"] = alpha1; + colors["text_editor/theme/highlighting/completion_existing_color"] = alpha2; + // Same opacity as the scroll grabber editor icon. + colors["text_editor/theme/highlighting/completion_scroll_color"] = Color(mono_value, mono_value, mono_value, 0.29); + colors["text_editor/theme/highlighting/completion_scroll_hovered_color"] = Color(mono_value, mono_value, mono_value, 0.4); + colors["text_editor/theme/highlighting/completion_font_color"] = p_config.font_color; + colors["text_editor/theme/highlighting/text_color"] = p_config.font_color; + colors["text_editor/theme/highlighting/line_number_color"] = dim_color; + colors["text_editor/theme/highlighting/safe_line_number_color"] = p_config.dark_theme ? (dim_color * Color(1, 1.2, 1, 1.5)) : Color(0, 0.4, 0, 0.75); + colors["text_editor/theme/highlighting/caret_color"] = p_config.mono_color; + colors["text_editor/theme/highlighting/caret_background_color"] = p_config.mono_color.inverted(); + colors["text_editor/theme/highlighting/text_selected_color"] = Color(0, 0, 0, 0); + colors["text_editor/theme/highlighting/selection_color"] = p_config.selection_color; + colors["text_editor/theme/highlighting/brace_mismatch_color"] = p_config.dark_theme ? p_config.error_color : Color(1, 0.08, 0, 1); + colors["text_editor/theme/highlighting/current_line_color"] = alpha1; + colors["text_editor/theme/highlighting/line_length_guideline_color"] = p_config.dark_theme ? p_config.base_color : p_config.dark_color_2; + colors["text_editor/theme/highlighting/word_highlighted_color"] = alpha1; + colors["text_editor/theme/highlighting/number_color"] = p_config.dark_theme ? Color(0.63, 1, 0.88) : Color(0, 0.55, 0.28, 1); + colors["text_editor/theme/highlighting/function_color"] = p_config.dark_theme ? Color(0.34, 0.7, 1.0) : Color(0, 0.225, 0.9, 1); + colors["text_editor/theme/highlighting/member_variable_color"] = p_config.dark_theme ? Color(0.34, 0.7, 1.0).lerp(p_config.mono_color, 0.6) : Color(0, 0.4, 0.68, 1); + colors["text_editor/theme/highlighting/mark_color"] = Color(p_config.error_color.r, p_config.error_color.g, p_config.error_color.b, 0.3); + colors["text_editor/theme/highlighting/warning_color"] = Color(p_config.warning_color.r, p_config.warning_color.g, p_config.warning_color.b, 0.15); + colors["text_editor/theme/highlighting/bookmark_color"] = Color(0.08, 0.49, 0.98); + colors["text_editor/theme/highlighting/breakpoint_color"] = p_config.dark_theme ? p_config.error_color : Color(1, 0.27, 0.2, 1); + colors["text_editor/theme/highlighting/executing_line_color"] = Color(0.98, 0.89, 0.27); + colors["text_editor/theme/highlighting/code_folding_color"] = alpha3; + colors["text_editor/theme/highlighting/folded_code_region_color"] = Color(0.68, 0.46, 0.77, 0.2); + colors["text_editor/theme/highlighting/search_result_color"] = alpha1; + colors["text_editor/theme/highlighting/search_result_border_color"] = p_config.dark_theme ? Color(0.41, 0.61, 0.91, 0.38) : Color(0, 0.4, 1, 0.38); + + if (p_config.dark_theme) { + colors["text_editor/theme/highlighting/gdscript/function_definition_color"] = Color(0.4, 0.9, 1.0); + colors["text_editor/theme/highlighting/gdscript/global_function_color"] = Color(0.64, 0.64, 0.96); + colors["text_editor/theme/highlighting/gdscript/node_path_color"] = Color(0.72, 0.77, 0.49); + colors["text_editor/theme/highlighting/gdscript/node_reference_color"] = Color(0.39, 0.76, 0.35); + colors["text_editor/theme/highlighting/gdscript/annotation_color"] = Color(1.0, 0.7, 0.45); + colors["text_editor/theme/highlighting/gdscript/string_name_color"] = Color(1.0, 0.76, 0.65); + colors["text_editor/theme/highlighting/comment_markers/critical_color"] = Color(0.77, 0.35, 0.35); + colors["text_editor/theme/highlighting/comment_markers/warning_color"] = Color(0.72, 0.61, 0.48); + colors["text_editor/theme/highlighting/comment_markers/notice_color"] = Color(0.56, 0.67, 0.51); + } else { + colors["text_editor/theme/highlighting/gdscript/function_definition_color"] = Color(0, 0.6, 0.6); + colors["text_editor/theme/highlighting/gdscript/global_function_color"] = Color(0.36, 0.18, 0.72); + colors["text_editor/theme/highlighting/gdscript/node_path_color"] = Color(0.18, 0.55, 0); + colors["text_editor/theme/highlighting/gdscript/node_reference_color"] = Color(0.0, 0.5, 0); + colors["text_editor/theme/highlighting/gdscript/annotation_color"] = Color(0.8, 0.37, 0); + colors["text_editor/theme/highlighting/gdscript/string_name_color"] = Color(0.8, 0.56, 0.45); + colors["text_editor/theme/highlighting/comment_markers/critical_color"] = Color(0.8, 0.14, 0.14); + colors["text_editor/theme/highlighting/comment_markers/warning_color"] = Color(0.75, 0.39, 0.03); + colors["text_editor/theme/highlighting/comment_markers/notice_color"] = Color(0.24, 0.54, 0.09); + } + } else if (is_godot2_theme) { + colors = EditorSettings::get_godot2_text_editor_theme(); + } + EditorSettings *settings = EditorSettings::get_singleton(); for (const KeyValue &setting : colors) { - EditorSettings::get_singleton()->set_initial_value(setting.key, setting.value); - if (text_editor_color_theme == "Default") { - EditorSettings::get_singleton()->set_manually(setting.key, setting.value); + settings->set_initial_value(setting.key, setting.value); + if (is_default_theme || is_godot2_theme) { + settings->set_manually(setting.key, setting.value); } } - } else if (text_editor_color_theme == "Godot 2") { - EditorSettings::get_singleton()->load_text_editor_theme(); + } else { + // Custom user theme. + _load_text_editor_theme(); } // Now theme is loaded, apply it to CodeEdit. diff --git a/modules/gdscript/editor/gdscript_highlighter.cpp b/modules/gdscript/editor/gdscript_highlighter.cpp index 60e0aa21a39..a0fadc3290d 100644 --- a/modules/gdscript/editor/gdscript_highlighter.cpp +++ b/modules/gdscript/editor/gdscript_highlighter.cpp @@ -901,85 +901,6 @@ void GDScriptSyntaxHighlighter::_update_cache() { } } - const String text_edit_color_theme = EDITOR_GET("text_editor/theme/color_theme"); - const bool godot_2_theme = text_edit_color_theme == "Godot 2"; - - if (godot_2_theme || EditorThemeManager::is_dark_theme()) { - function_definition_color = Color(0.4, 0.9, 1.0); - global_function_color = Color(0.64, 0.64, 0.96); - node_path_color = Color(0.72, 0.77, 0.49); - node_ref_color = Color(0.39, 0.76, 0.35); - annotation_color = Color(1.0, 0.7, 0.45); - string_name_color = Color(1.0, 0.76, 0.65); - comment_marker_colors[COMMENT_MARKER_CRITICAL] = Color(0.77, 0.35, 0.35); - comment_marker_colors[COMMENT_MARKER_WARNING] = Color(0.72, 0.61, 0.48); - comment_marker_colors[COMMENT_MARKER_NOTICE] = Color(0.56, 0.67, 0.51); - } else { - function_definition_color = Color(0, 0.6, 0.6); - global_function_color = Color(0.36, 0.18, 0.72); - node_path_color = Color(0.18, 0.55, 0); - node_ref_color = Color(0.0, 0.5, 0); - annotation_color = Color(0.8, 0.37, 0); - string_name_color = Color(0.8, 0.56, 0.45); - comment_marker_colors[COMMENT_MARKER_CRITICAL] = Color(0.8, 0.14, 0.14); - comment_marker_colors[COMMENT_MARKER_WARNING] = Color(0.75, 0.39, 0.03); - comment_marker_colors[COMMENT_MARKER_NOTICE] = Color(0.24, 0.54, 0.09); - } - - // TODO: Move to editor_settings.cpp - EDITOR_DEF("text_editor/theme/highlighting/gdscript/function_definition_color", function_definition_color); - EDITOR_DEF("text_editor/theme/highlighting/gdscript/global_function_color", global_function_color); - EDITOR_DEF("text_editor/theme/highlighting/gdscript/node_path_color", node_path_color); - EDITOR_DEF("text_editor/theme/highlighting/gdscript/node_reference_color", node_ref_color); - EDITOR_DEF("text_editor/theme/highlighting/gdscript/annotation_color", annotation_color); - EDITOR_DEF("text_editor/theme/highlighting/gdscript/string_name_color", string_name_color); - EDITOR_DEF("text_editor/theme/highlighting/comment_markers/critical_color", comment_marker_colors[COMMENT_MARKER_CRITICAL]); - EDITOR_DEF("text_editor/theme/highlighting/comment_markers/warning_color", comment_marker_colors[COMMENT_MARKER_WARNING]); - EDITOR_DEF("text_editor/theme/highlighting/comment_markers/notice_color", comment_marker_colors[COMMENT_MARKER_NOTICE]); - // The list is based on . - EDITOR_DEF("text_editor/theme/highlighting/comment_markers/critical_list", "ALERT,ATTENTION,CAUTION,CRITICAL,DANGER,SECURITY"); - EDITOR_DEF("text_editor/theme/highlighting/comment_markers/warning_list", "BUG,DEPRECATED,FIXME,HACK,TASK,TBD,TODO,WARNING"); - EDITOR_DEF("text_editor/theme/highlighting/comment_markers/notice_list", "INFO,NOTE,NOTICE,TEST,TESTING"); - - if (text_edit_color_theme == "Default" || godot_2_theme) { - EditorSettings::get_singleton()->set_initial_value( - "text_editor/theme/highlighting/gdscript/function_definition_color", - function_definition_color, - true); - EditorSettings::get_singleton()->set_initial_value( - "text_editor/theme/highlighting/gdscript/global_function_color", - global_function_color, - true); - EditorSettings::get_singleton()->set_initial_value( - "text_editor/theme/highlighting/gdscript/node_path_color", - node_path_color, - true); - EditorSettings::get_singleton()->set_initial_value( - "text_editor/theme/highlighting/gdscript/node_reference_color", - node_ref_color, - true); - EditorSettings::get_singleton()->set_initial_value( - "text_editor/theme/highlighting/gdscript/annotation_color", - annotation_color, - true); - EditorSettings::get_singleton()->set_initial_value( - "text_editor/theme/highlighting/gdscript/string_name_color", - string_name_color, - true); - EditorSettings::get_singleton()->set_initial_value( - "text_editor/theme/highlighting/comment_markers/critical_color", - comment_marker_colors[COMMENT_MARKER_CRITICAL], - true); - EditorSettings::get_singleton()->set_initial_value( - "text_editor/theme/highlighting/comment_markers/warning_color", - comment_marker_colors[COMMENT_MARKER_WARNING], - true); - EditorSettings::get_singleton()->set_initial_value( - "text_editor/theme/highlighting/comment_markers/notice_color", - comment_marker_colors[COMMENT_MARKER_NOTICE], - true); - } - function_definition_color = EDITOR_GET("text_editor/theme/highlighting/gdscript/function_definition_color"); global_function_color = EDITOR_GET("text_editor/theme/highlighting/gdscript/global_function_color"); node_path_color = EDITOR_GET("text_editor/theme/highlighting/gdscript/node_path_color");