Merge pull request #30351 from bojidar-bg/30288-override-global-theme

Keep track of default theme and project custom default theme seperatelly
This commit is contained in:
Rémi Verschelde 2019-07-25 14:54:27 +02:00 committed by GitHub
commit 4c74f50d1a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 81 additions and 12 deletions

View file

@ -850,6 +850,12 @@ Ref<Texture> 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<Shader> 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<StyleBox> 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);
}

View file

@ -752,7 +752,7 @@ void register_scene_types() {
if (theme_path != String()) {
Ref<Theme> 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);
}

View file

@ -32,8 +32,6 @@
#include "core/os/file_access.h"
#include "core/print_string.h"
Ref<Theme> Theme::default_theme;
void Theme::_emit_theme_changed() {
emit_changed();
@ -186,11 +184,6 @@ void Theme::_get_property_list(List<PropertyInfo> *p_list) const {
}
}
Ref<Theme> Theme::get_default() {
return default_theme;
}
void Theme::set_default_theme_font(const Ref<Font> &p_default_font) {
if (default_theme_font == p_default_font)
@ -215,14 +208,31 @@ Ref<Font> Theme::get_default_theme_font() const {
return default_theme_font;
}
Ref<Theme> Theme::project_default_theme;
Ref<Theme> Theme::default_theme;
Ref<Texture> Theme::default_icon;
Ref<StyleBox> Theme::default_style;
Ref<Font> Theme::default_font;
Ref<Theme> Theme::get_default() {
return default_theme;
}
void Theme::set_default(const Ref<Theme> &p_default) {
default_theme = p_default;
}
Ref<Texture> Theme::default_icon;
Ref<StyleBox> Theme::default_style;
Ref<Font> Theme::default_font;
Ref<Theme> Theme::get_project_default() {
return project_default_theme;
}
void Theme::set_project_default(const Ref<Theme> &p_project_default) {
project_default_theme = p_project_default;
}
void Theme::set_default_icon(const Ref<Texture> &p_icon) {

View file

@ -46,7 +46,6 @@ class Theme : public Resource {
GDCLASS(Theme, Resource);
RES_BASE_EXTENSION("theme");
static Ref<Theme> default_theme;
void _emit_theme_changed();
HashMap<StringName, HashMap<StringName, Ref<Texture> > > icon_map;
@ -61,6 +60,8 @@ protected:
bool _get(const StringName &p_name, Variant &r_ret) const;
void _get_property_list(List<PropertyInfo> *p_list) const;
static Ref<Theme> project_default_theme;
static Ref<Theme> default_theme;
static Ref<Texture> default_icon;
static Ref<StyleBox> default_style;
static Ref<Font> default_font;
@ -137,6 +138,9 @@ public:
static Ref<Theme> get_default();
static void set_default(const Ref<Theme> &p_default);
static Ref<Theme> get_project_default();
static void set_project_default(const Ref<Theme> &p_default);
static void set_default_icon(const Ref<Texture> &p_icon);
static void set_default_style(const Ref<StyleBox> &p_style);
static void set_default_font(const Ref<Font> &p_font);