From ba867042a22710da6087b6a1742d3c7a57348850 Mon Sep 17 00:00:00 2001 From: Micky Date: Sat, 9 Mar 2024 12:48:08 +0100 Subject: [PATCH] Fix Label3D, TextMesh & Font not following project default theme in editor --- scene/3d/label_3d.cpp | 11 +++++++++-- scene/resources/3d/primitive_meshes.cpp | 9 ++++++++- scene/resources/font.cpp | 7 ++++++- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/scene/3d/label_3d.cpp b/scene/3d/label_3d.cpp index 02f40713bf11..9f71c881a9f2 100644 --- a/scene/3d/label_3d.cpp +++ b/scene/3d/label_3d.cpp @@ -782,6 +782,8 @@ Ref Label3D::get_font() const { } Ref Label3D::_get_font_or_default() const { + // Similar code taken from `FontVariation::_get_base_font_or_default`. + if (theme_font.is_valid()) { theme_font->disconnect_changed(callable_mp(const_cast(this), &Label3D::_font_changed)); theme_font.unref(); @@ -791,12 +793,17 @@ Ref Label3D::_get_font_or_default() const { return font_override; } - StringName theme_name = "font"; + const StringName theme_name = "font"; List theme_types; ThemeDB::get_singleton()->get_native_type_dependencies(get_class_name(), &theme_types); ThemeContext *global_context = ThemeDB::get_singleton()->get_default_theme_context(); - for (const Ref &theme : global_context->get_themes()) { + List> themes = global_context->get_themes(); + if (Engine::get_singleton()->is_editor_hint()) { + themes.push_front(ThemeDB::get_singleton()->get_project_theme()); + } + + for (const Ref &theme : themes) { if (theme.is_null()) { continue; } diff --git a/scene/resources/3d/primitive_meshes.cpp b/scene/resources/3d/primitive_meshes.cpp index f99e4b15f6ad..c2b2a6d68bb1 100644 --- a/scene/resources/3d/primitive_meshes.cpp +++ b/scene/resources/3d/primitive_meshes.cpp @@ -3463,6 +3463,8 @@ Ref TextMesh::get_font() const { } Ref TextMesh::_get_font_or_default() const { + // Similar code taken from `FontVariation::_get_base_font_or_default`. + if (font_override.is_valid()) { return font_override; } @@ -3472,7 +3474,12 @@ Ref TextMesh::_get_font_or_default() const { ThemeDB::get_singleton()->get_native_type_dependencies(get_class_name(), &theme_types); ThemeContext *global_context = ThemeDB::get_singleton()->get_default_theme_context(); - for (const Ref &theme : global_context->get_themes()) { + List> themes = global_context->get_themes(); + if (Engine::get_singleton()->is_editor_hint()) { + themes.push_front(ThemeDB::get_singleton()->get_project_theme()); + } + + for (const Ref &theme : themes) { if (theme.is_null()) { continue; } diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp index 7bf2d857def5..884fb7ba2bba 100644 --- a/scene/resources/font.cpp +++ b/scene/resources/font.cpp @@ -2861,7 +2861,12 @@ Ref FontVariation::_get_base_font_or_default() const { ThemeDB::get_singleton()->get_native_type_dependencies(get_class_name(), &theme_types); ThemeContext *global_context = ThemeDB::get_singleton()->get_default_theme_context(); - for (const Ref &theme : global_context->get_themes()) { + List> themes = global_context->get_themes(); + if (Engine::get_singleton()->is_editor_hint()) { + themes.push_front(ThemeDB::get_singleton()->get_project_theme()); + } + + for (const Ref &theme : themes) { if (theme.is_null()) { continue; }