diff --git a/source/code/main.cpp b/source/code/main.cpp index 257a456..e84e70e 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp @@ -1196,7 +1196,8 @@ int main(int argc, char* argv[]) { std::cout << "Renderer: " << info.name << "\n"; } globalData.screen = renderer; - globalData.theme = ThemesGet(0); + globalData.theme= ThemesGet(ThemesGetNumber(Config::getInstance()->getString("theme"))); + ResetFullscreen(); SetSDLIcon(sdlWindow); diff --git a/source/code/menudef_themes.cpp b/source/code/menudef_themes.cpp index 50c05e4..e1833a1 100644 --- a/source/code/menudef_themes.cpp +++ b/source/code/menudef_themes.cpp @@ -28,6 +28,7 @@ http://blockattack.net static void switchTheme() { globalData.theme = ThemesGetNext(); + Config::getInstance()->setString("theme", globalData.theme.theme_name); } @@ -97,7 +98,7 @@ static void themesEditSwitchBorder() { static void themesEditSlot(int slot) { ThemesMenu tem(globalData.screen, fmt::format(_("Edit custom theme {}"), slot), true); - size_t theme_index = ThemeGetNumber(fmt::format("custom_slot_{}", slot)); + size_t theme_index = ThemesGetNumber(fmt::format("custom_slot_{}", slot)); if (theme_index == 0) { // Theme not found return; diff --git a/source/code/themes.cpp b/source/code/themes.cpp index 7358bdc..4f7f8a9 100644 --- a/source/code/themes.cpp +++ b/source/code/themes.cpp @@ -279,7 +279,7 @@ Theme& ThemesGet(size_t theme_number) { return themes.at(theme_number % themes.size()); } -size_t ThemeGetNumber(const std::string& name) { +size_t ThemesGetNumber(const std::string& name) { size_t ret = 0; // Default to 0 ThemesInit(); for (size_t i = 0; i < themes.size(); ++i) { @@ -357,6 +357,13 @@ ThemeBorderData ThemesGetNextBorder(const std::string& current) { return ret; } +void ThemesValidateAndFix(Theme& theme) { + ThemesInit(); + if (!sago::FileExists(fmt::format("textures/backgrounds/{}.jpg", theme.background.name).c_str()) && !sago::FileExists(fmt::format("textures/backgrounds/{}.png", theme.background.name).c_str())) { + theme.background.name = "standard"; + } + ThemesFillMissingFields(theme); +} void ThemesInitCustomBackgrounds() { std::vector custom_backgrounds = sago::GetFileList("textures/backgrounds"); diff --git a/source/code/themes.hpp b/source/code/themes.hpp index 144ece4..da7c6c9 100644 --- a/source/code/themes.hpp +++ b/source/code/themes.hpp @@ -77,6 +77,8 @@ void ThemesFillMissingFields(Theme& theme); void ThemesAddOrReplace(const Theme& theme); +void ThemesValidateAndFix(Theme& theme); + /** * @brief returns a theme from a list @@ -101,7 +103,7 @@ void ThemesSaveCustomSlots(); * Returns the index of a given file. * Returns 0 if it does not exist or is the standard theme. */ -size_t ThemeGetNumber(const std::string& name); +size_t ThemesGetNumber(const std::string& name); BackGroundData ThemesGetNextBackground(const std::string& current);