diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 26be17f6c19..1d6f3dc7821 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -850,6 +850,12 @@ Ref Control::get_icon(const StringName &p_name, const StringName &p_typ theme_owner = NULL; } + if (Theme::get_project_default().is_valid()) { + if (Theme::get_project_default()->has_icon(p_name, type)) { + return Theme::get_project_default()->get_icon(p_name, type); + } + } + return Theme::get_default()->get_icon(p_name, type); } @@ -886,6 +892,12 @@ Ref Control::get_shader(const StringName &p_name, const StringName &p_ty theme_owner = NULL; } + if (Theme::get_project_default().is_valid()) { + if (Theme::get_project_default()->has_shader(p_name, type)) { + return Theme::get_project_default()->get_shader(p_name, type); + } + } + return Theme::get_default()->get_shader(p_name, type); } @@ -925,6 +937,9 @@ Ref Control::get_stylebox(const StringName &p_name, const StringName & } while (class_name != StringName()) { + if (Theme::get_project_default().is_valid() && Theme::get_project_default()->has_stylebox(p_name, type)) + return Theme::get_project_default()->get_stylebox(p_name, type); + if (Theme::get_default()->has_stylebox(p_name, class_name)) return Theme::get_default()->get_stylebox(p_name, class_name); @@ -1001,6 +1016,11 @@ Color Control::get_color(const StringName &p_name, const StringName &p_type) con theme_owner = NULL; } + if (Theme::get_project_default().is_valid()) { + if (Theme::get_project_default()->has_color(p_name, type)) { + return Theme::get_project_default()->get_color(p_name, type); + } + } return Theme::get_default()->get_color(p_name, type); } @@ -1036,6 +1056,11 @@ int Control::get_constant(const StringName &p_name, const StringName &p_type) co theme_owner = NULL; } + if (Theme::get_project_default().is_valid()) { + if (Theme::get_project_default()->has_constant(p_name, type)) { + return Theme::get_project_default()->get_constant(p_name, type); + } + } return Theme::get_default()->get_constant(p_name, type); } @@ -1106,6 +1131,11 @@ bool Control::has_icon(const StringName &p_name, const StringName &p_type) const theme_owner = NULL; } + if (Theme::get_project_default().is_valid()) { + if (Theme::get_project_default()->has_color(p_name, type)) { + return true; + } + } return Theme::get_default()->has_icon(p_name, type); } @@ -1140,6 +1170,11 @@ bool Control::has_shader(const StringName &p_name, const StringName &p_type) con theme_owner = NULL; } + if (Theme::get_project_default().is_valid()) { + if (Theme::get_project_default()->has_shader(p_name, type)) { + return true; + } + } return Theme::get_default()->has_shader(p_name, type); } bool Control::has_stylebox(const StringName &p_name, const StringName &p_type) const { @@ -1173,6 +1208,11 @@ bool Control::has_stylebox(const StringName &p_name, const StringName &p_type) c theme_owner = NULL; } + if (Theme::get_project_default().is_valid()) { + if (Theme::get_project_default()->has_stylebox(p_name, type)) { + return true; + } + } return Theme::get_default()->has_stylebox(p_name, type); } bool Control::has_font(const StringName &p_name, const StringName &p_type) const { @@ -1206,6 +1246,11 @@ bool Control::has_font(const StringName &p_name, const StringName &p_type) const theme_owner = NULL; } + if (Theme::get_project_default().is_valid()) { + if (Theme::get_project_default()->has_font(p_name, type)) { + return true; + } + } return Theme::get_default()->has_font(p_name, type); } @@ -1240,6 +1285,11 @@ bool Control::has_color(const StringName &p_name, const StringName &p_type) cons theme_owner = NULL; } + if (Theme::get_project_default().is_valid()) { + if (Theme::get_project_default()->has_color(p_name, type)) { + return true; + } + } return Theme::get_default()->has_color(p_name, type); } @@ -1274,6 +1324,11 @@ bool Control::has_constant(const StringName &p_name, const StringName &p_type) c theme_owner = NULL; } + if (Theme::get_project_default().is_valid()) { + if (Theme::get_project_default()->has_constant(p_name, type)) { + return true; + } + } return Theme::get_default()->has_constant(p_name, type); } diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp index 245fe3856a0..974c9771e08 100644 --- a/scene/register_scene_types.cpp +++ b/scene/register_scene_types.cpp @@ -752,7 +752,7 @@ void register_scene_types() { if (theme_path != String()) { Ref theme = ResourceLoader::load(theme_path); if (theme.is_valid()) { - Theme::set_default(theme); + Theme::set_project_default(theme); if (font.is_valid()) { Theme::set_default_font(font); } diff --git a/scene/resources/theme.cpp b/scene/resources/theme.cpp index 69258bc8349..ae18be1695f 100644 --- a/scene/resources/theme.cpp +++ b/scene/resources/theme.cpp @@ -32,8 +32,6 @@ #include "core/os/file_access.h" #include "core/print_string.h" -Ref Theme::default_theme; - void Theme::_emit_theme_changed() { emit_changed(); @@ -186,11 +184,6 @@ void Theme::_get_property_list(List *p_list) const { } } -Ref Theme::get_default() { - - return default_theme; -} - void Theme::set_default_theme_font(const Ref &p_default_font) { if (default_theme_font == p_default_font) @@ -215,14 +208,31 @@ Ref Theme::get_default_theme_font() const { return default_theme_font; } +Ref Theme::project_default_theme; +Ref Theme::default_theme; +Ref Theme::default_icon; +Ref Theme::default_style; +Ref Theme::default_font; + +Ref Theme::get_default() { + + return default_theme; +} + void Theme::set_default(const Ref &p_default) { default_theme = p_default; } -Ref Theme::default_icon; -Ref Theme::default_style; -Ref Theme::default_font; +Ref Theme::get_project_default() { + + return project_default_theme; +} + +void Theme::set_project_default(const Ref &p_project_default) { + + project_default_theme = p_project_default; +} void Theme::set_default_icon(const Ref &p_icon) { diff --git a/scene/resources/theme.h b/scene/resources/theme.h index fb59073cbe8..4c4f9b5abab 100644 --- a/scene/resources/theme.h +++ b/scene/resources/theme.h @@ -46,7 +46,6 @@ class Theme : public Resource { GDCLASS(Theme, Resource); RES_BASE_EXTENSION("theme"); - static Ref default_theme; void _emit_theme_changed(); HashMap > > icon_map; @@ -61,6 +60,8 @@ protected: bool _get(const StringName &p_name, Variant &r_ret) const; void _get_property_list(List *p_list) const; + static Ref project_default_theme; + static Ref default_theme; static Ref default_icon; static Ref default_style; static Ref default_font; @@ -137,6 +138,9 @@ public: static Ref get_default(); static void set_default(const Ref &p_default); + static Ref get_project_default(); + static void set_project_default(const Ref &p_default); + static void set_default_icon(const Ref &p_icon); static void set_default_style(const Ref &p_style); static void set_default_font(const Ref &p_font);