Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add conversion for common Theme Overrides #74624

Merged
merged 1 commit into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions editor/project_converter_3_to_4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ class ProjectConverter3To4::RegExContainer {
LocalVector<RegEx *> gdscript_signals_regexes;
LocalVector<RegEx *> shaders_regexes;
LocalVector<RegEx *> builtin_types_regexes;
LocalVector<RegEx *> theme_override_regexes;
LocalVector<RegEx *> csharp_function_regexes;
LocalVector<RegEx *> csharp_properties_regexes;
LocalVector<RegEx *> csharp_signal_regexes;
Expand Down Expand Up @@ -208,6 +209,10 @@ class ProjectConverter3To4::RegExContainer {
for (unsigned int current_index = 0; RenamesMap3To4::builtin_types_renames[current_index][0]; current_index++) {
builtin_types_regexes.push_back(memnew(RegEx(String("\\b") + RenamesMap3To4::builtin_types_renames[current_index][0] + "\\b")));
}
// Theme overrides.
for (unsigned int current_index = 0; RenamesMap3To4::theme_override_renames[current_index][0]; current_index++) {
theme_override_regexes.push_back(memnew(RegEx(String("\\b") + RenamesMap3To4::theme_override_renames[current_index][0] + "\\b")));
}
// CSharp function renames.
for (unsigned int current_index = 0; RenamesMap3To4::csharp_function_renames[current_index][0]; current_index++) {
csharp_function_regexes.push_back(memnew(RegEx(String("\\b") + RenamesMap3To4::csharp_function_renames[current_index][0] + "\\b")));
Expand Down Expand Up @@ -282,6 +287,9 @@ class ProjectConverter3To4::RegExContainer {
for (RegEx *regex : builtin_types_regexes) {
memdelete(regex);
}
for (RegEx *regex : theme_override_regexes) {
memdelete(regex);
}
for (RegEx *regex : csharp_function_regexes) {
memdelete(regex);
}
Expand Down Expand Up @@ -387,6 +395,7 @@ bool ProjectConverter3To4::convert() {
rename_common(RenamesMap3To4::gdscript_signals_renames, reg_container.gdscript_signals_regexes, source_lines);
rename_common(RenamesMap3To4::shaders_renames, reg_container.shaders_regexes, source_lines);
rename_common(RenamesMap3To4::builtin_types_renames, reg_container.builtin_types_regexes, source_lines);
rename_common(RenamesMap3To4::theme_override_renames, reg_container.theme_override_regexes, source_lines);

custom_rename(source_lines, "\\.shader", ".gdshader");
} else if (file_name.ends_with(".tscn")) {
Expand All @@ -404,6 +413,7 @@ bool ProjectConverter3To4::convert() {
rename_common(RenamesMap3To4::gdscript_signals_renames, reg_container.gdscript_signals_regexes, source_lines);
rename_common(RenamesMap3To4::shaders_renames, reg_container.shaders_regexes, source_lines);
rename_common(RenamesMap3To4::builtin_types_renames, reg_container.builtin_types_regexes, source_lines);
rename_common(RenamesMap3To4::theme_override_renames, reg_container.theme_override_regexes, source_lines);

custom_rename(source_lines, "\\.shader", ".gdshader");
} else if (file_name.ends_with(".cs")) { // TODO, C# should use different methods.
Expand Down Expand Up @@ -566,6 +576,7 @@ bool ProjectConverter3To4::validate_conversion() {
changed_elements.append_array(check_for_rename_common(RenamesMap3To4::gdscript_signals_renames, reg_container.gdscript_signals_regexes, lines));
changed_elements.append_array(check_for_rename_common(RenamesMap3To4::shaders_renames, reg_container.shaders_regexes, lines));
changed_elements.append_array(check_for_rename_common(RenamesMap3To4::builtin_types_renames, reg_container.builtin_types_regexes, lines));
changed_elements.append_array(check_for_rename_common(RenamesMap3To4::theme_override_renames, reg_container.theme_override_regexes, lines));

changed_elements.append_array(check_for_custom_rename(lines, "\\.shader", ".gdshader"));
} else if (file_name.ends_with(".tscn")) {
Expand All @@ -583,6 +594,7 @@ bool ProjectConverter3To4::validate_conversion() {
changed_elements.append_array(check_for_rename_common(RenamesMap3To4::gdscript_signals_renames, reg_container.gdscript_signals_regexes, lines));
changed_elements.append_array(check_for_rename_common(RenamesMap3To4::shaders_renames, reg_container.shaders_regexes, lines));
changed_elements.append_array(check_for_rename_common(RenamesMap3To4::builtin_types_renames, reg_container.builtin_types_regexes, lines));
changed_elements.append_array(check_for_rename_common(RenamesMap3To4::theme_override_renames, reg_container.theme_override_regexes, lines));

changed_elements.append_array(check_for_custom_rename(lines, "\\.shader", ".gdshader"));
} else if (file_name.ends_with(".cs")) {
Expand Down Expand Up @@ -768,6 +780,8 @@ bool ProjectConverter3To4::test_conversion(RegExContainer &reg_container) {

valid = valid && test_conversion_basic("Transform", "Transform3D", RenamesMap3To4::builtin_types_renames, reg_container.builtin_types_regexes, "builtin type");

valid = valid && test_conversion_basic("custom_constants/margin_right", "theme_override_constants/margin_right", RenamesMap3To4::theme_override_renames, reg_container.theme_override_regexes, "theme overrides");

// Custom Renames.

valid = valid && test_conversion_with_regex("(Connect(A,B,C,D,E,F,G) != OK):", "(Connect(A, new Callable(B, C), D, E, F, G) != OK):", &ProjectConverter3To4::rename_csharp_functions, "custom rename csharp", reg_container);
Expand Down
45 changes: 45 additions & 0 deletions editor/renames_map_3_to_4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1791,4 +1791,49 @@ const char *RenamesMap3To4::color_renames[][2] = {
{ nullptr, nullptr },
};

const char *RenamesMap3To4::theme_override_renames[][2] = {
// First rename the generic prefixes.
{ "custom_colors/", "theme_override_colors/" },
{ "custom_constants/", "theme_override_constants/" },
{ "custom_fonts/", "theme_override_fonts/" },
{ "custom_icons/", "theme_override_icons/" },
{ "custom_styles/", "theme_override_styles/" },

// MarginContainer
// The margin_* properties are renamed to offset_* in a previous conversion step.
// This is fine everywhere except for the MarginContainer theme_override_constants.
{ "theme_override_constants/offset_right", "theme_override_constants/margin_right" },
{ "theme_override_constants/offset_top", "theme_override_constants/margin_top" },
{ "theme_override_constants/offset_left", "theme_override_constants/margin_left" },
{ "theme_override_constants/offset_bottom", "theme_override_constants/margin_bottom" },

// Panel/PanelContainer/TabContainer/PopupPanel/PopupMenu
{ "theme_override_styles/panel", "theme_override_styles/panel" },

// TabContainer/Tabs(TabBar)
{ "theme_override_styles/tab_bg", "theme_override_styles/tab_unselected" },
{ "theme_override_styles/tab_fg", "theme_override_styles/tab_selected" },

// { "theme_override_styles/bg", "theme_override_styles/bg" }, // GraphEdit
// { "theme_override_styles/bg", "theme_override_styles/panel" }, // ScrollContainer
// { "theme_override_styles/bg", "theme_override_styles/background" }, // ProgressBar
// { "theme_override_styles/fg", "theme_override_styles/fill" }, // ProgressBar

{ "theme_override_colors/font_color_hover", "theme_override_colors/font_hover_color" },
{ "theme_override_colors/font_color_pressed", "theme_override_colors/font_pressed_color" },
{ "theme_override_colors/font_color_disabled", "theme_override_colors/font_disabled_color" },
{ "theme_override_colors/font_color_focus", "theme_override_colors/font_focus_color" },
{ "theme_override_colors/font_color_hover_pressed", "theme_override_colors/font_hover_pressed_color" },

{ "theme_override_colors/font_outline_modulate", "theme_override_colors/font_outline_color" },
{ "theme_override_colors/font_color_shadow", "theme_override_colors/font_shadow_color" },

{ "theme_override_constants/shadow_as_outline", "theme_override_constants/shadow_outline_size" }, // 0 or 1

{ "theme_override_constants/table_vseparation", "theme_override_constants/table_v_separation" },
{ "theme_override_constants/table_hseparation", "theme_override_constants/table_h_separation" },

{ nullptr, nullptr },
};

#endif // DISABLE_DEPRECATED
1 change: 1 addition & 0 deletions editor/renames_map_3_to_4.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ struct RenamesMap3To4 {
static const char *shaders_renames[][2];
static const char *class_renames[][2];
static const char *color_renames[][2];
static const char *theme_override_renames[][2];
};

#endif // DISABLE_DEPRECATED
Expand Down