diff --git a/core/config/project_settings.cpp b/core/config/project_settings.cpp index 8f5a61e7a8..06eea7c848 100644 --- a/core/config/project_settings.cpp +++ b/core/config/project_settings.cpp @@ -1578,6 +1578,8 @@ ProjectSettings::ProjectSettings() { GLOBAL_DEF("application/config/auto_accept_quit", true); GLOBAL_DEF("application/config/quit_on_go_back", true); + GLOBAL_DEF_BASIC("application/boot_splash/bg_color", Color(0.14, 0.14, 0.14)); + GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "accessibility/general/accessibility_support", PROPERTY_HINT_ENUM, "Auto (When Screen Reader is Running),Always Active,Disabled"), 0); GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "accessibility/general/updates_per_second", PROPERTY_HINT_RANGE, "1,100,1"), 60); diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml index 1397d97536..628e7e9344 100644 --- a/doc/classes/ProjectSettings.xml +++ b/doc/classes/ProjectSettings.xml @@ -276,7 +276,6 @@ If [code]true[/code], [AnimationMixer] prints the warning of no matching object of the track path in the scene. - Background color for the boot splash. If [code]true[/code], scale the boot splash image to the full window size (preserving the aspect ratio) when the engine starts. If [code]false[/code], the engine will leave it at the default pixel size. @@ -2800,7 +2799,7 @@ The thread model to use for rendering. Rendering on a thread may improve performance, but synchronizing to the main thread can cause a bit more jitter. - + Default background clear color. Overridable per [Viewport] using its [Environment]. See [member Environment.background_mode] and [member Environment.background_color] in particular. To change this default color programmatically, use [method RenderingServer.set_default_clear_color]. diff --git a/editor/settings/editor_settings.cpp b/editor/settings/editor_settings.cpp index 3b7460d689..0adf9aa97f 100644 --- a/editor/settings/editor_settings.cpp +++ b/editor/settings/editor_settings.cpp @@ -46,6 +46,7 @@ #include "core/os/keyboard.h" #include "core/os/os.h" #include "core/string/translation_server.h" +#include "core/variant/variant_parser.h" #include "core/version.h" #include "editor/editor_node.h" #include "editor/file_system/editor_paths.h" @@ -582,7 +583,7 @@ void EditorSettings::_load_defaults(Ref p_extra_config) { EDITOR_SETTING_BASIC(Variant::STRING, PROPERTY_HINT_ENUM, "interface/theme/preset", "Default", "Default,Breeze Dark,Godot,Godot 2,Gray,Light,Solarized (Dark),Solarized (Light),Black (OLED),Indigo,Custom") EDITOR_SETTING_BASIC(Variant::STRING, PROPERTY_HINT_ENUM, "interface/theme/spacing_preset", "Default", "Compact,Default,Spacious,Custom") EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/theme/icon_and_font_color", 0, "Auto,Dark,Light") - EDITOR_SETTING_BASIC(Variant::COLOR, PROPERTY_HINT_NONE, "interface/theme/base_color", Color(0.2, 0.23, 0.31), "") + EDITOR_SETTING_BASIC(Variant::COLOR, PROPERTY_HINT_NONE, "interface/theme/base_color", get_default_base_color(), "") EDITOR_SETTING_BASIC(Variant::COLOR, PROPERTY_HINT_NONE, "interface/theme/accent_color", Color(0.41, 0.61, 0.91), "") EDITOR_SETTING_BASIC(Variant::BOOL, PROPERTY_HINT_NONE, "interface/theme/use_system_accent_color", false, "") EDITOR_SETTING_BASIC(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/theme/contrast", 0.3, "-1,1,0.01") @@ -1239,6 +1240,56 @@ String EditorSettings::get_existing_settings_path() { return config_dir.path_join(filename); } +static Error _parse_direct_resource_dummy(void *p_data, VariantParser::Stream *p_stream, Ref &r_res, int &line, String &r_err_str) { + return OK; +} + +Variant EditorSettings::get_setting_directly(const String &p_setting, const Variant &p_default) { + if (!EditorPaths::get_singleton() || !EditorPaths::get_singleton()->are_paths_valid()) { + return p_default; + } + + String config_file_path = get_existing_settings_path(); + if (config_file_path.is_empty() || !FileAccess::exists(config_file_path)) { + return p_default; + } + + Ref f = FileAccess::open(config_file_path, FileAccess::READ); + if (f.is_null()) { + return p_default; + } + + VariantParser::StreamFile stream; + stream.f = f; + String assign; + Variant value; + VariantParser::Tag next_tag; + int lines = 0; + String error_text; + VariantParser::ResourceParser rp_new; + rp_new.ext_func = _parse_direct_resource_dummy; + rp_new.sub_func = _parse_direct_resource_dummy; + + while (true) { + assign = Variant(); + next_tag.fields.clear(); + next_tag.name = String(); + Error err = VariantParser::parse_tag_assign_eof(&stream, lines, error_text, next_tag, assign, value, &rp_new, true, true); + if (err == ERR_FILE_EOF) { + break; + } + if (err == OK && !assign.is_empty() && assign == p_setting) { + return value; + } + } + + return p_default; +} + +Color EditorSettings::get_default_base_color() { + return Color(0.06, 0.09, 0.14); +} + String EditorSettings::get_newest_settings_path() { const String config_file_name = vformat("editor_settings-%d.%d.tres", REDOT_VERSION_MAJOR, REDOT_VERSION_MINOR); return EditorPaths::get_singleton()->get_config_dir().path_join(config_file_name); diff --git a/editor/settings/editor_settings.h b/editor/settings/editor_settings.h index ce6c4bdbab..5c060db037 100644 --- a/editor/settings/editor_settings.h +++ b/editor/settings/editor_settings.h @@ -138,6 +138,8 @@ class EditorSettings : public Resource { static EditorSettings *get_singleton(); static String get_existing_settings_path(); static String get_newest_settings_path(); + static Variant get_setting_directly(const String &p_setting, const Variant &p_default = Variant()); + static Color get_default_base_color(); static void create(); void setup_language(); diff --git a/main/main.cpp b/main/main.cpp index d21510bf4f..caf486868d 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -135,11 +135,6 @@ #include "modules/modules_enabled.gen.h" // For mono. -// Fallback definition for missing editor splash color -#if defined(TOOLS_ENABLED) && !defined(NO_EDITOR_SPLASH) -static const Color boot_splash_editor_bg_color = Color(0.06, 0.09, 0.14); -#endif - #if defined(MODULE_MONO_ENABLED) && defined(TOOLS_ENABLED) #include "modules/mono/editor/bindings_generator.h" #endif @@ -3170,48 +3165,8 @@ Error Main::setup2(bool p_show_boot_logo) { window_position = &position; } - Color boot_bg_color; -#ifdef TOOLS_ENABLED - if (editor) { - // Read base color directly from settings file since EditorSettings isn't available yet - boot_bg_color = Color(0.06, 0.09, 0.14); // Default fallback - if (EditorPaths::get_singleton() && EditorPaths::get_singleton()->are_paths_valid()) { - String config_file_path = EditorSettings::get_existing_settings_path(); - if (FileAccess::exists(config_file_path)) { - Ref f = FileAccess::open(config_file_path, FileAccess::READ); - if (f.is_valid()) { - VariantParser::StreamFile stream; - stream.f = f; - String assign; - Variant value; - VariantParser::Tag next_tag; - int lines = 0; - String error_text; - VariantParser::ResourceParser rp_new; - rp_new.ext_func = _parse_resource_dummy; - rp_new.sub_func = _parse_resource_dummy; - while (true) { - assign = Variant(); - next_tag.fields.clear(); - next_tag.name = String(); - Error err = VariantParser::parse_tag_assign_eof(&stream, lines, error_text, next_tag, assign, value, &rp_new, true); - if (err == ERR_FILE_EOF) { - break; - } - if (err == OK && !assign.is_empty() && assign == "interface/theme/base_color") { - boot_bg_color = value; - break; - } - } - } - } - } - } else { - boot_bg_color = GLOBAL_DEF_BASIC("application/boot_splash/bg_color", boot_splash_bg_color); - } -#else - boot_bg_color = GLOBAL_DEF_BASIC("application/boot_splash/bg_color", boot_splash_bg_color); -#endif + GLOBAL_DEF(PropertyInfo(Variant::COLOR, "application/boot_splash/bg_color"), Color(0.14, 0.14, 0.14)); + Color boot_bg_color = get_boot_splash_bg_color(); DisplayServer::set_early_window_clear_color_override(true, boot_bg_color); DisplayServer::Context context; @@ -3526,7 +3481,7 @@ Error Main::setup2(bool p_show_boot_logo) { } } - Color clear = GLOBAL_DEF_BASIC("rendering/environment/defaults/default_clear_color", Color(0.128, 0.128, 0.128)); + Color clear = GLOBAL_DEF_BASIC("rendering/environment/defaults/default_clear_color", get_boot_splash_bg_color()); RenderingServer::get_singleton()->set_default_clear_color(clear); if (p_show_boot_logo) { @@ -3807,6 +3762,19 @@ Error Main::setup2(bool p_show_boot_logo) { return OK; } +Color Main::get_boot_splash_bg_color() { +#if defined(TOOLS_ENABLED) + if (editor || project_manager) { + if (EditorSettings::get_singleton()) { + return EditorSettings::get_singleton()->get_setting("interface/theme/base_color"); + } + return EditorSettings::get_setting_directly("interface/theme/base_color", EditorSettings::get_default_base_color()); + } +#endif + + return GLOBAL_GET("application/boot_splash/bg_color"); +} + void Main::setup_boot_logo() { MAIN_PRINT("Main: Load Boot Image"); @@ -3852,49 +3820,8 @@ void Main::setup_boot_logo() { boot_logo->set_pixel(0, 0, Color(0, 0, 0, 0)); } - Color boot_bg_color; -#ifdef TOOLS_ENABLED - if (editor) { - // Read base color directly from settings file since EditorSettings isn't available yet - boot_bg_color = Color(0.06, 0.09, 0.14); // Default fallback - if (EditorPaths::get_singleton() && EditorPaths::get_singleton()->are_paths_valid()) { - String config_file_path = EditorSettings::get_existing_settings_path(); - if (FileAccess::exists(config_file_path)) { - Ref f = FileAccess::open(config_file_path, FileAccess::READ); - if (f.is_valid()) { - VariantParser::StreamFile stream; - stream.f = f; - String assign; - Variant value; - VariantParser::Tag next_tag; - int lines = 0; - String error_text; - VariantParser::ResourceParser rp_new; - rp_new.ext_func = _parse_resource_dummy; - rp_new.sub_func = _parse_resource_dummy; - while (true) { - assign = Variant(); - next_tag.fields.clear(); - next_tag.name = String(); - Error err = VariantParser::parse_tag_assign_eof(&stream, lines, error_text, next_tag, assign, value, &rp_new, true); - if (err == ERR_FILE_EOF) { - break; - } - if (err == OK && !assign.is_empty() && assign == "interface/theme/base_color") { - boot_bg_color = value; - break; - } - } - } - } - } - } else { - boot_bg_color = GLOBAL_DEF_BASIC("application/boot_splash/bg_color", boot_splash_bg_color); - } -#else - boot_bg_color = GLOBAL_DEF_BASIC("application/boot_splash/bg_color", boot_splash_bg_color); -#endif if (boot_logo.is_valid()) { + Color boot_bg_color = get_boot_splash_bg_color(); RenderingServer::get_singleton()->set_boot_image(boot_logo, boot_bg_color, boot_logo_scale, boot_logo_filter); } else { @@ -3907,6 +3834,7 @@ void Main::setup_boot_logo() { #endif MAIN_PRINT("Main: ClearColor"); + Color boot_bg_color = get_boot_splash_bg_color(); RenderingServer::get_singleton()->set_default_clear_color(boot_bg_color); MAIN_PRINT("Main: Image"); RenderingServer::get_singleton()->set_boot_image(splash, boot_bg_color, false); @@ -3920,8 +3848,10 @@ void Main::setup_boot_logo() { } #endif } - RenderingServer::get_singleton()->set_default_clear_color( - GLOBAL_GET("rendering/environment/defaults/default_clear_color")); + if (!editor && !project_manager) { + RenderingServer::get_singleton()->set_default_clear_color( + GLOBAL_GET("rendering/environment/defaults/default_clear_color")); + } } String Main::get_rendering_driver_name() { diff --git a/main/main.h b/main/main.h index 369f02636a..ac49a7d4d7 100644 --- a/main/main.h +++ b/main/main.h @@ -37,6 +37,7 @@ template class Vector; +struct Color; class Main { enum CLIOptionAvailability { @@ -74,6 +75,7 @@ class Main { static Error setup2(bool p_show_boot_logo = true); // The thread calling setup2() will effectively become the main thread. static String get_rendering_driver_name(); static void setup_boot_logo(); + static Color get_boot_splash_bg_color(); #ifdef TESTS_ENABLED static Error test_setup(); static void test_cleanup(); diff --git a/servers/rendering/renderer_viewport.cpp b/servers/rendering/renderer_viewport.cpp index 27f955f36d..975ee30520 100644 --- a/servers/rendering/renderer_viewport.cpp +++ b/servers/rendering/renderer_viewport.cpp @@ -35,6 +35,7 @@ #include "core/config/project_settings.h" #include "core/math/transform_interpolator.h" #include "core/object/worker_thread_pool.h" +#include "main/main.h" #include "renderer_canvas_cull.h" #include "renderer_scene_cull.h" #include "rendering_server_globals.h" @@ -746,7 +747,7 @@ void RendererViewport::draw_viewports(bool p_swap_buffers) { #endif // XR_DISABLED if (Engine::get_singleton()->is_editor_hint()) { - RSG::texture_storage->set_default_clear_color(GLOBAL_GET_CACHED(Color, "rendering/environment/defaults/default_clear_color")); + RSG::texture_storage->set_default_clear_color(Main::get_boot_splash_bg_color()); } if (sorted_active_viewports_dirty) {