diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2021-04-23 23:12:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-23 23:12:25 +0200 |
commit | 759b876b8ad93651f000cb6ff03a26ac7748a25f (patch) | |
tree | 68efd17b710c9359041d2cd645c4bffe7d90f177 /scene | |
parent | 473a6602413d2a1808201fa5c1a265c2f0f13255 (diff) | |
parent | 2524238bb3d338c13ded86e148a149aeb0124b76 (diff) |
Merge pull request #46593 from pycbouh/theme-editor-better-edit-ui
Refactor Edit Theme menu in Theme Editor
Diffstat (limited to 'scene')
-rw-r--r-- | scene/resources/theme.cpp | 45 | ||||
-rw-r--r-- | scene/resources/theme.h | 7 |
2 files changed, 52 insertions, 0 deletions
diff --git a/scene/resources/theme.cpp b/scene/resources/theme.cpp index 036d11574c..e8b203417e 100644 --- a/scene/resources/theme.cpp +++ b/scene/resources/theme.cpp @@ -508,6 +508,10 @@ bool Theme::has_icon(const StringName &p_name, const StringName &p_node_type) co return (icon_map.has(p_node_type) && icon_map[p_node_type].has(p_name) && icon_map[p_node_type][p_name].is_valid()); } +bool Theme::has_icon_nocheck(const StringName &p_name, const StringName &p_node_type) const { + return (icon_map.has(p_node_type) && icon_map[p_node_type].has(p_name)); +} + void Theme::rename_icon(const StringName &p_old_name, const StringName &p_name, const StringName &p_node_type) { ERR_FAIL_COND_MSG(!icon_map.has(p_node_type), "Cannot rename the icon '" + String(p_old_name) + "' because the node type '" + String(p_node_type) + "' does not exist."); ERR_FAIL_COND_MSG(icon_map[p_node_type].has(p_name), "Cannot rename the icon '" + String(p_old_name) + "' because the new name '" + String(p_name) + "' already exists."); @@ -592,6 +596,10 @@ bool Theme::has_stylebox(const StringName &p_name, const StringName &p_node_type return (style_map.has(p_node_type) && style_map[p_node_type].has(p_name) && style_map[p_node_type][p_name].is_valid()); } +bool Theme::has_stylebox_nocheck(const StringName &p_name, const StringName &p_node_type) const { + return (style_map.has(p_node_type) && style_map[p_node_type].has(p_name)); +} + void Theme::rename_stylebox(const StringName &p_old_name, const StringName &p_name, const StringName &p_node_type) { ERR_FAIL_COND_MSG(!style_map.has(p_node_type), "Cannot rename the stylebox '" + String(p_old_name) + "' because the node type '" + String(p_node_type) + "' does not exist."); ERR_FAIL_COND_MSG(style_map[p_node_type].has(p_name), "Cannot rename the stylebox '" + String(p_old_name) + "' because the new name '" + String(p_name) + "' already exists."); @@ -678,6 +686,10 @@ bool Theme::has_font(const StringName &p_name, const StringName &p_node_type) co return ((font_map.has(p_node_type) && font_map[p_node_type].has(p_name) && font_map[p_node_type][p_name].is_valid()) || default_theme_font.is_valid()); } +bool Theme::has_font_nocheck(const StringName &p_name, const StringName &p_node_type) const { + return (font_map.has(p_node_type) && font_map[p_node_type].has(p_name)); +} + void Theme::rename_font(const StringName &p_old_name, const StringName &p_name, const StringName &p_node_type) { ERR_FAIL_COND_MSG(!font_map.has(p_node_type), "Cannot rename the font '" + String(p_old_name) + "' because the node type '" + String(p_node_type) + "' does not exist."); ERR_FAIL_COND_MSG(font_map[p_node_type].has(p_name), "Cannot rename the font '" + String(p_old_name) + "' because the new name '" + String(p_name) + "' already exists."); @@ -755,6 +767,10 @@ bool Theme::has_font_size(const StringName &p_name, const StringName &p_node_typ return ((font_size_map.has(p_node_type) && font_size_map[p_node_type].has(p_name) && (font_size_map[p_node_type][p_name] > 0)) || (default_theme_font_size > 0)); } +bool Theme::has_font_size_nocheck(const StringName &p_name, const StringName &p_node_type) const { + return (font_size_map.has(p_node_type) && font_size_map[p_node_type].has(p_name)); +} + void Theme::rename_font_size(const StringName &p_old_name, const StringName &p_name, const StringName &p_node_type) { ERR_FAIL_COND_MSG(!font_size_map.has(p_node_type), "Cannot rename the font size '" + String(p_old_name) + "' because the node type '" + String(p_node_type) + "' does not exist."); ERR_FAIL_COND_MSG(font_size_map[p_node_type].has(p_name), "Cannot rename the font size '" + String(p_old_name) + "' because the new name '" + String(p_name) + "' already exists."); @@ -826,6 +842,10 @@ bool Theme::has_color(const StringName &p_name, const StringName &p_node_type) c return (color_map.has(p_node_type) && color_map[p_node_type].has(p_name)); } +bool Theme::has_color_nocheck(const StringName &p_name, const StringName &p_node_type) const { + return (color_map.has(p_node_type) && color_map[p_node_type].has(p_name)); +} + void Theme::rename_color(const StringName &p_old_name, const StringName &p_name, const StringName &p_node_type) { ERR_FAIL_COND_MSG(!color_map.has(p_node_type), "Cannot rename the color '" + String(p_old_name) + "' because the node type '" + String(p_node_type) + "' does not exist."); ERR_FAIL_COND_MSG(color_map[p_node_type].has(p_name), "Cannot rename the color '" + String(p_old_name) + "' because the new name '" + String(p_name) + "' already exists."); @@ -896,6 +916,10 @@ bool Theme::has_constant(const StringName &p_name, const StringName &p_node_type return (constant_map.has(p_node_type) && constant_map[p_node_type].has(p_name)); } +bool Theme::has_constant_nocheck(const StringName &p_name, const StringName &p_node_type) const { + return (constant_map.has(p_node_type) && constant_map[p_node_type].has(p_name)); +} + void Theme::rename_constant(const StringName &p_old_name, const StringName &p_name, const StringName &p_node_type) { ERR_FAIL_COND_MSG(!constant_map.has(p_node_type), "Cannot rename the constant '" + String(p_old_name) + "' because the node type '" + String(p_node_type) + "' does not exist."); ERR_FAIL_COND_MSG(constant_map[p_node_type].has(p_name), "Cannot rename the constant '" + String(p_old_name) + "' because the new name '" + String(p_name) + "' already exists."); @@ -1029,6 +1053,27 @@ bool Theme::has_theme_item(DataType p_data_type, const StringName &p_name, const return false; } +bool Theme::has_theme_item_nocheck(DataType p_data_type, const StringName &p_name, const StringName &p_node_type) const { + switch (p_data_type) { + case DATA_TYPE_COLOR: + return has_color_nocheck(p_name, p_node_type); + case DATA_TYPE_CONSTANT: + return has_constant_nocheck(p_name, p_node_type); + case DATA_TYPE_FONT: + return has_font_nocheck(p_name, p_node_type); + case DATA_TYPE_FONT_SIZE: + return has_font_size_nocheck(p_name, p_node_type); + case DATA_TYPE_ICON: + return has_icon_nocheck(p_name, p_node_type); + case DATA_TYPE_STYLEBOX: + return has_stylebox_nocheck(p_name, p_node_type); + case DATA_TYPE_MAX: + break; // Can't happen, but silences warning. + } + + return false; +} + void Theme::rename_theme_item(DataType p_data_type, const StringName &p_old_name, const StringName &p_name, const StringName &p_node_type) { switch (p_data_type) { case DATA_TYPE_COLOR: diff --git a/scene/resources/theme.h b/scene/resources/theme.h index eb918fac69..7e887b6343 100644 --- a/scene/resources/theme.h +++ b/scene/resources/theme.h @@ -119,6 +119,7 @@ public: void set_icon(const StringName &p_name, const StringName &p_node_type, const Ref<Texture2D> &p_icon); Ref<Texture2D> get_icon(const StringName &p_name, const StringName &p_node_type) const; bool has_icon(const StringName &p_name, const StringName &p_node_type) const; + bool has_icon_nocheck(const StringName &p_name, const StringName &p_node_type) const; void rename_icon(const StringName &p_old_name, const StringName &p_name, const StringName &p_node_type); void clear_icon(const StringName &p_name, const StringName &p_node_type); void get_icon_list(StringName p_node_type, List<StringName> *p_list) const; @@ -128,6 +129,7 @@ public: void set_stylebox(const StringName &p_name, const StringName &p_node_type, const Ref<StyleBox> &p_style); Ref<StyleBox> get_stylebox(const StringName &p_name, const StringName &p_node_type) const; bool has_stylebox(const StringName &p_name, const StringName &p_node_type) const; + bool has_stylebox_nocheck(const StringName &p_name, const StringName &p_node_type) const; void rename_stylebox(const StringName &p_old_name, const StringName &p_name, const StringName &p_node_type); void clear_stylebox(const StringName &p_name, const StringName &p_node_type); void get_stylebox_list(StringName p_node_type, List<StringName> *p_list) const; @@ -137,6 +139,7 @@ public: void set_font(const StringName &p_name, const StringName &p_node_type, const Ref<Font> &p_font); Ref<Font> get_font(const StringName &p_name, const StringName &p_node_type) const; bool has_font(const StringName &p_name, const StringName &p_node_type) const; + bool has_font_nocheck(const StringName &p_name, const StringName &p_node_type) const; void rename_font(const StringName &p_old_name, const StringName &p_name, const StringName &p_node_type); void clear_font(const StringName &p_name, const StringName &p_node_type); void get_font_list(StringName p_node_type, List<StringName> *p_list) const; @@ -146,6 +149,7 @@ public: void set_font_size(const StringName &p_name, const StringName &p_node_type, int p_font_size); int get_font_size(const StringName &p_name, const StringName &p_node_type) const; bool has_font_size(const StringName &p_name, const StringName &p_node_type) const; + bool has_font_size_nocheck(const StringName &p_name, const StringName &p_node_type) const; void rename_font_size(const StringName &p_old_name, const StringName &p_name, const StringName &p_node_type); void clear_font_size(const StringName &p_name, const StringName &p_node_type); void get_font_size_list(StringName p_node_type, List<StringName> *p_list) const; @@ -155,6 +159,7 @@ public: void set_color(const StringName &p_name, const StringName &p_node_type, const Color &p_color); Color get_color(const StringName &p_name, const StringName &p_node_type) const; bool has_color(const StringName &p_name, const StringName &p_node_type) const; + bool has_color_nocheck(const StringName &p_name, const StringName &p_node_type) const; void rename_color(const StringName &p_old_name, const StringName &p_name, const StringName &p_node_type); void clear_color(const StringName &p_name, const StringName &p_node_type); void get_color_list(StringName p_node_type, List<StringName> *p_list) const; @@ -164,6 +169,7 @@ public: void set_constant(const StringName &p_name, const StringName &p_node_type, int p_constant); int get_constant(const StringName &p_name, const StringName &p_node_type) const; bool has_constant(const StringName &p_name, const StringName &p_node_type) const; + bool has_constant_nocheck(const StringName &p_name, const StringName &p_node_type) const; void rename_constant(const StringName &p_old_name, const StringName &p_name, const StringName &p_node_type); void clear_constant(const StringName &p_name, const StringName &p_node_type); void get_constant_list(StringName p_node_type, List<StringName> *p_list) const; @@ -173,6 +179,7 @@ public: void set_theme_item(DataType p_data_type, const StringName &p_name, const StringName &p_node_type, const Variant &p_value); Variant get_theme_item(DataType p_data_type, const StringName &p_name, const StringName &p_node_type) const; bool has_theme_item(DataType p_data_type, const StringName &p_name, const StringName &p_node_type) const; + bool has_theme_item_nocheck(DataType p_data_type, const StringName &p_name, const StringName &p_node_type) const; void rename_theme_item(DataType p_data_type, const StringName &p_old_name, const StringName &p_name, const StringName &p_node_type); void clear_theme_item(DataType p_data_type, const StringName &p_name, const StringName &p_node_type); void get_theme_item_list(DataType p_data_type, StringName p_node_type, List<StringName> *p_list) const; |