Skip to content
53 changes: 52 additions & 1 deletion editor/settings/editor_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -582,7 +583,7 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> 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")
Expand Down Expand Up @@ -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<Resource> &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<FileAccess> 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);
Expand Down
2 changes: 2 additions & 0 deletions editor/settings/editor_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
113 changes: 21 additions & 92 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1941,6 +1936,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
} else {
#ifdef TOOLS_ENABLED
editor = false;
project_manager = true;
#else
const String error_msg = "Error: Couldn't load project data at path \"" + project_path + "\". Is the .pck file missing?\nIf you've renamed the executable, the associated .pck file should also be renamed to match the executable's name (without the extension).\n";
OS::get_singleton()->print("%s", error_msg.utf8().get_data());
Expand Down Expand Up @@ -3170,48 +3166,7 @@ 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<FileAccess> 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
Color boot_bg_color = get_boot_splash_bg_color();
DisplayServer::set_early_window_clear_color_override(true, boot_bg_color);

DisplayServer::Context context;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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_DEF_BASIC("application/boot_splash/bg_color", boot_splash_bg_color);
}

void Main::setup_boot_logo() {
MAIN_PRINT("Main: Load Boot Image");

Expand Down Expand Up @@ -3852,48 +3820,7 @@ 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<FileAccess> 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
Color boot_bg_color = get_boot_splash_bg_color();
if (boot_logo.is_valid()) {
RenderingServer::get_singleton()->set_boot_image(boot_logo, boot_bg_color, boot_logo_scale, boot_logo_filter);

Expand All @@ -3920,8 +3847,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() {
Expand Down
2 changes: 2 additions & 0 deletions main/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

template <typename T>
class Vector;
struct Color;

class Main {
enum CLIOptionAvailability {
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion servers/rendering/renderer_viewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down
Loading