From 0248ef664ec2c0cc3d12b83ca157cb4bde2c5d41 Mon Sep 17 00:00:00 2001 From: Skyth <19259897+blueskythlikesclouds@users.noreply.github.com> Date: Thu, 5 Dec 2024 00:44:07 +0300 Subject: [PATCH] Implement ImGui font atlas caching. --- UnleashedRecomp/CMakeLists.txt | 2 + UnleashedRecomp/gpu/imgui_snapshot.cpp | 214 +++++++++++++++++++++ UnleashedRecomp/gpu/imgui_snapshot.h | 31 +++ UnleashedRecomp/gpu/video.cpp | 56 +++++- UnleashedRecomp/gpu/video.h | 2 +- UnleashedRecomp/stdafx.h | 1 + UnleashedRecomp/ui/achievement_menu.cpp | 7 +- UnleashedRecomp/ui/achievement_overlay.cpp | 3 +- UnleashedRecomp/ui/message_window.cpp | 3 +- UnleashedRecomp/ui/options_menu.cpp | 7 +- UnleashedRecomp/user/config_detail.cpp | 25 +++ UnleashedRecomp/user/config_detail.h | 7 +- UnleashedRecompResources | 2 +- 13 files changed, 343 insertions(+), 17 deletions(-) diff --git a/UnleashedRecomp/CMakeLists.txt b/UnleashedRecomp/CMakeLists.txt index 35c25709..17c1b2ea 100644 --- a/UnleashedRecomp/CMakeLists.txt +++ b/UnleashedRecomp/CMakeLists.txt @@ -323,3 +323,5 @@ BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/images/co BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/images/common/select_fill.dds" DEST_FILE "${RESOURCES_OUTPUT_PATH}/images/common/select_fill.dds" ARRAY_NAME "g_select_fill" COMPRESSION_TYPE "zstd") BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/images/game_icon.bmp" DEST_FILE "${RESOURCES_OUTPUT_PATH}/images/game_icon.bmp" ARRAY_NAME "g_game_icon") BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/images/game_icon_night.bmp" DEST_FILE "${RESOURCES_OUTPUT_PATH}/images/game_icon_night.bmp" ARRAY_NAME "g_game_icon_night") +BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/font/im_font_atlas.bin" DEST_FILE "${RESOURCES_OUTPUT_PATH}/font/im_font_atlas.bin" ARRAY_NAME "g_im_font_atlas" COMPRESSION_TYPE "zstd") +BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/font/im_font_atlas.dds" DEST_FILE "${RESOURCES_OUTPUT_PATH}/font/im_font_atlas.dds" ARRAY_NAME "g_im_font_atlas_texture" COMPRESSION_TYPE "zstd") diff --git a/UnleashedRecomp/gpu/imgui_snapshot.cpp b/UnleashedRecomp/gpu/imgui_snapshot.cpp index 492b61f8..e6107f7b 100644 --- a/UnleashedRecomp/gpu/imgui_snapshot.cpp +++ b/UnleashedRecomp/gpu/imgui_snapshot.cpp @@ -1,5 +1,11 @@ #include "imgui_snapshot.h" +#include +#include +#include +#include +#include + void ImDrawDataSnapshot::Clear() { for (int n = 0; n < Cache.GetMapSize(); n++) @@ -52,3 +58,211 @@ void ImDrawDataSnapshot::SnapUsingSwap(ImDrawData* src, double current_time) Cache.Remove(GetDrawListID(entry->SrcCopy), entry); } }; + +template +void ImFontAtlasSnapshot::SnapPointer(size_t offset, const T1& value, const T2& ptr, size_t count) +{ + if (ptr != nullptr && count != 0) + { + if (!objects.contains(ptr)) + { + constexpr size_t ALIGN = alignof(std::remove_pointer_t); + constexpr size_t SIZE = sizeof(std::remove_pointer_t); + + size_t ptrOffset = (data.size() + ALIGN - 1) & ~(ALIGN - 1); + data.resize(ptrOffset + SIZE * count); + memcpy(&data[ptrOffset], ptr, SIZE * count); + + for (size_t i = 0; i < count; i++) + { + size_t curPtrOffset = ptrOffset + SIZE * i; + objects[&ptr[i]] = curPtrOffset; + Traverse(curPtrOffset, ptr[i]); + } + } + + size_t fieldOffset = offset + (reinterpret_cast(&ptr) - reinterpret_cast(&value)); + *reinterpret_cast(&data[fieldOffset]) = objects[ptr]; + offsets.push_back(fieldOffset); + } +} + +template +void ImFontAtlasSnapshot::Traverse(size_t offset, const T& value) +{ + if constexpr (std::is_pointer_v) + { + SnapPointer(offset, value, value, 1); + } + else if constexpr (std::is_same_v) + { + SnapPointer(offset, value, value.ConfigData.Data, value.ConfigData.Size); + SnapPointer(offset, value, value.CustomRects.Data, value.CustomRects.Size); + SnapPointer(offset, value, value.Fonts.Data, value.Fonts.Size); + } + else if constexpr (std::is_same_v) + { + SnapPointer(offset, value, value.IndexAdvanceX.Data, value.IndexAdvanceX.Size); + SnapPointer(offset, value, value.IndexLookup.Data, value.IndexLookup.Size); + SnapPointer(offset, value, value.Glyphs.Data, value.Glyphs.Size); + SnapPointer(offset, value, value.FallbackGlyph, 1); + SnapPointer(offset, value, value.ContainerAtlas, 1); + SnapPointer(offset, value, value.ConfigData, value.ConfigDataCount); + } + else if constexpr (std::is_same_v) + { + SnapPointer(offset, value, value.Font, 1); + } + else if constexpr (std::is_same_v) + { + SnapPointer(offset, value, value.GlyphRanges, value.GlyphRanges != nullptr ? wcslen(reinterpret_cast(value.GlyphRanges)) + 1 : 0); + SnapPointer(offset, value, value.DstFont, 1); + } +} + +template +size_t ImFontAtlasSnapshot::Snap(const T& value) +{ + size_t offset = (data.size() + alignof(T) - 1) & ~(alignof(T) - 1); + data.resize(offset + sizeof(T)); + memcpy(&data[offset], &value, sizeof(T)); + objects[&value] = offset; + Traverse(offset, value); + return offset; +} + +struct ImFontAtlasSnapshotHeader +{ + uint32_t imguiVersion; + uint32_t dataOffset; + uint32_t offsetCount; + uint32_t offsetsOffset; +}; + +void ImFontAtlasSnapshot::Snap() +{ + data.resize(sizeof(ImFontAtlasSnapshotHeader)); + size_t dataOffset = Snap(*ImGui::GetIO().Fonts); + + size_t offsetsOffset = data.size(); + std::sort(offsets.begin(), offsets.end()); + + data.insert(data.end(), + reinterpret_cast(offsets.data()), + reinterpret_cast(offsets.data() + offsets.size())); + + auto header = reinterpret_cast(data.data()); + header->imguiVersion = IMGUI_VERSION_NUM; + header->dataOffset = dataOffset; + header->offsetCount = offsets.size(); + header->offsetsOffset = offsetsOffset; +} + +static std::unique_ptr g_imFontAtlas; + +ImFontAtlas* ImFontAtlasSnapshot::Load() +{ + g_imFontAtlas = decompressZstd(g_im_font_atlas, g_im_font_atlas_uncompressed_size); + + auto header = reinterpret_cast(g_imFontAtlas.get()); + assert(header->imguiVersion == IMGUI_VERSION_NUM && "ImGui version mismatch, the font atlas needs to be regenerated!"); + + auto offsetTable = reinterpret_cast(g_imFontAtlas.get() + header->offsetsOffset); + for (size_t i = 0; i < header->offsetCount; i++) + { + *reinterpret_cast(g_imFontAtlas.get() + (*offsetTable)) += reinterpret_cast(g_imFontAtlas.get()); + ++offsetTable; + } + + return reinterpret_cast(g_imFontAtlas.get() + header->dataOffset); +} + + +static void GetGlyphs(std::set& glyphs, const std::string_view& value) +{ + const char* cur = value.data(); + while (cur < value.data() + value.size()) + { + unsigned int c; + cur += ImTextCharFromUtf8(&c, cur, value.data() + value.size()); + glyphs.emplace(c); + } +} + +static std::vector g_glyphRanges; + +void ImFontAtlasSnapshot::GenerateGlyphRanges() +{ + std::vector localeStrings; + + for (auto& config : Config::Definitions) + config->GetLocaleStrings(localeStrings); + + std::set glyphs; + + for (size_t i = 0x20; i <= 0xFF; i++) + glyphs.emplace(i); + + for (auto& localeString : localeStrings) + GetGlyphs(glyphs, localeString); + + for (auto& [name, locale] : g_locale) + { + for (auto& [language, value] : locale) + GetGlyphs(glyphs, value); + } + + for (auto& [language, locale] : g_bool_locale) + { + for (auto& [value, nameAndDesc] : locale) + { + GetGlyphs(glyphs, std::get<0>(nameAndDesc)); + GetGlyphs(glyphs, std::get<1>(nameAndDesc)); + } + } + + for (size_t i = XDBF_LANGUAGE_ENGLISH; i <= XDBF_LANGUAGE_ITALIAN; i++) + { + auto achievements = g_xdbfWrapper.GetAchievements(static_cast(i)); + for (auto& achievement : achievements) + { + GetGlyphs(glyphs, achievement.Name); + GetGlyphs(glyphs, achievement.UnlockedDesc); + GetGlyphs(glyphs, achievement.LockedDesc); + } + } + + for (auto glyph : glyphs) + { + if (g_glyphRanges.empty() || (g_glyphRanges.back() + 1) != glyph) + { + g_glyphRanges.push_back(glyph); + g_glyphRanges.push_back(glyph); + } + else + { + g_glyphRanges.back() = glyph; + } + } + + g_glyphRanges.push_back(0); +} + +ImFont* ImFontAtlasSnapshot::GetFont(const char* name, float size) +{ + auto fontAtlas = ImGui::GetIO().Fonts; + for (auto& configData : fontAtlas->ConfigData) + { + if (strstr(configData.Name, name) != nullptr && abs(configData.SizePixels - size) < 0.001f) + { + assert(configData.DstFont != nullptr); + return configData.DstFont; + } + } + +#ifdef ENABLE_IM_FONT_ATLAS_SNAPSHOT + assert(false && "Unable to locate equivalent font in the atlas file."); +#endif + + return fontAtlas->AddFontFromFileTTF(name, size, nullptr, g_glyphRanges.data()); +} diff --git a/UnleashedRecomp/gpu/imgui_snapshot.h b/UnleashedRecomp/gpu/imgui_snapshot.h index f08393be..26b60d0e 100644 --- a/UnleashedRecomp/gpu/imgui_snapshot.h +++ b/UnleashedRecomp/gpu/imgui_snapshot.h @@ -30,3 +30,34 @@ struct ImDrawDataSnapshot ImGuiID GetDrawListID(ImDrawList* src_list) { return ImHashData(&src_list, sizeof(src_list)); } // Hash pointer ImDrawDataSnapshotEntry* GetOrAddEntry(ImDrawList* src_list) { return Cache.GetOrAddByKey(GetDrawListID(src_list)); } }; + +// Undefine this to generate a font atlas file in working directory. +// You also need to do this if you are testing localization, as only +// characters in the locale get added to the atlas. +// Don't forget to compress the generated atlas texture to BC4 with no mips! +#define ENABLE_IM_FONT_ATLAS_SNAPSHOT + +struct ImFontAtlasSnapshot +{ + std::vector data; + ankerl::unordered_dense::map objects; + std::vector offsets; + + template + void SnapPointer(size_t offset, const T1& value, const T2& ptr, size_t count); + + template + void Traverse(size_t offset, const T& value); + + template + size_t Snap(const T& value); + + void Snap(); + + static ImFontAtlas* Load(); + + static void GenerateGlyphRanges(); + + // When ENABLE_IM_FONT_ATLAS_SNAPSHOT is undefined, this creates the font runtime instead. + static ImFont* GetFont(const char* name, float size); +}; diff --git a/UnleashedRecomp/gpu/video.cpp b/UnleashedRecomp/gpu/video.cpp index 29c09e96..5dbd5dfc 100644 --- a/UnleashedRecomp/gpu/video.cpp +++ b/UnleashedRecomp/gpu/video.cpp @@ -21,6 +21,9 @@ #include #include +#include +#include + #include #include "../../thirdparty/ShaderRecomp/ShaderRecomp/shader_common.h" @@ -1064,6 +1067,15 @@ static void CreateImGuiBackend() io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange; +#ifdef ENABLE_IM_FONT_ATLAS_SNAPSHOT + delete io.Fonts; + io.Fonts = ImFontAtlasSnapshot::Load(); +#else + io.Fonts->TexDesiredWidth = 4096; + io.Fonts->AddFontDefault(); + ImFontAtlasSnapshot::GenerateGlyphRanges(); +#endif + AchievementMenu::Init(); AchievementOverlay::Init(); MessageWindow::Init(); @@ -1071,6 +1083,12 @@ static void CreateImGuiBackend() ImGui_ImplSDL2_InitForOther(Window::s_pWindow); + RenderComponentMapping componentMapping(RenderSwizzle::ONE, RenderSwizzle::ONE, RenderSwizzle::ONE, RenderSwizzle::R); + +#ifdef ENABLE_IM_FONT_ATLAS_SNAPSHOT + g_imFontTexture = LoadTexture(decompressZstd(g_im_font_atlas_texture, g_im_font_atlas_texture_uncompressed_size).get(), + g_im_font_atlas_texture_uncompressed_size, componentMapping); +#else g_imFontTexture = std::make_unique(ResourceType::Texture); uint8_t* pixels; @@ -1125,11 +1143,12 @@ static void CreateImGuiBackend() textureViewDesc.format = textureDesc.format; textureViewDesc.dimension = RenderTextureViewDimension::TEXTURE_2D; textureViewDesc.mipLevels = 1; - textureViewDesc.componentMapping = RenderComponentMapping(RenderSwizzle::ONE, RenderSwizzle::ONE, RenderSwizzle::ONE, RenderSwizzle::R); + textureViewDesc.componentMapping = componentMapping; g_imFontTexture->textureView = g_imFontTexture->texture->createTextureView(textureViewDesc); g_imFontTexture->descriptorIndex = g_textureDescriptorAllocator.allocate(); g_textureDescriptorSet->setTexture(g_imFontTexture->descriptorIndex, g_imFontTexture->texture, RenderTextureLayout::SHADER_READ, g_imFontTexture->textureView.get()); +#endif io.Fonts->SetTexID(g_imFontTexture.get()); @@ -1174,6 +1193,32 @@ static void CreateImGuiBackend() pipelineDesc.inputSlots = &inputSlot; pipelineDesc.inputSlotsCount = 1; g_imPipeline = g_device->createGraphicsPipeline(pipelineDesc); + +#ifndef ENABLE_IM_FONT_ATLAS_SNAPSHOT + ImFontAtlasSnapshot snapshot; + snapshot.Snap(); + + FILE* file = fopen("im_font_atlas.bin", "wb"); + if (file) + { + fwrite(snapshot.data.data(), 1, snapshot.data.size(), file); + fclose(file); + } + + ddspp::Header header; + ddspp::HeaderDXT10 headerDX10; + ddspp::encode_header(ddspp::R8_UNORM, width, height, 1, ddspp::Texture2D, 1, 1, header, headerDX10); + + file = fopen("im_font_atlas.dds", "wb"); + if (file) + { + fwrite(&ddspp::DDS_MAGIC, 4, 1, file); + fwrite(&header, sizeof(header), 1, file); + fwrite(&headerDX10, sizeof(headerDX10), 1, file); + fwrite(pixels, 1, width * height, file); + fclose(file); + } +#endif } static void CreateHostDevice() @@ -4123,7 +4168,7 @@ static RenderFormat ConvertDXGIFormat(ddspp::DXGIFormat format) } } -static bool LoadTexture(GuestTexture& texture, uint8_t* data, size_t dataSize) +static bool LoadTexture(GuestTexture& texture, uint8_t* data, size_t dataSize, RenderComponentMapping componentMapping) { ddspp::Descriptor ddsDesc; if (ddspp::decode_header(data, ddsDesc) != ddspp::Error) @@ -4146,6 +4191,7 @@ static bool LoadTexture(GuestTexture& texture, uint8_t* data, size_t dataSize) viewDesc.format = desc.format; viewDesc.dimension = ConvertTextureViewDimension(ddsDesc.type); viewDesc.mipLevels = ddsDesc.numMips; + viewDesc.componentMapping = componentMapping; texture.textureView = texture.texture->createTextureView(viewDesc); texture.descriptorIndex = g_textureDescriptorAllocator.allocate(); g_textureDescriptorSet->setTexture(texture.descriptorIndex, texture.texture, RenderTextureLayout::SHADER_READ, texture.textureView.get()); @@ -4287,11 +4333,11 @@ static bool LoadTexture(GuestTexture& texture, uint8_t* data, size_t dataSize) return false; } -std::unique_ptr LoadTexture(uint8_t* data, size_t dataSize) +std::unique_ptr LoadTexture(uint8_t* data, size_t dataSize, RenderComponentMapping componentMapping) { GuestTexture texture(ResourceType::Texture); - if (LoadTexture(texture, data, dataSize)) + if (LoadTexture(texture, data, dataSize, componentMapping)) return std::make_unique(std::move(texture)); return nullptr; @@ -4303,7 +4349,7 @@ static void MakePictureData(GuestPictureData* pictureData, uint8_t* data, uint32 { GuestTexture texture(ResourceType::Texture); - if (LoadTexture(texture, data, dataSize)) + if (LoadTexture(texture, data, dataSize, {})) { #ifdef _DEBUG texture.texture->setName(reinterpret_cast(g_memory.Translate(pictureData->name + 2))); diff --git a/UnleashedRecomp/gpu/video.h b/UnleashedRecomp/gpu/video.h index 2c237e6c..102f88b9 100644 --- a/UnleashedRecomp/gpu/video.h +++ b/UnleashedRecomp/gpu/video.h @@ -379,6 +379,6 @@ enum GuestTextureAddress D3DTADDRESS_BORDER = 6 }; -extern std::unique_ptr LoadTexture(uint8_t* data, size_t dataSize); +extern std::unique_ptr LoadTexture(uint8_t* data, size_t dataSize, RenderComponentMapping componentMapping = RenderComponentMapping()); extern void VideoConfigValueChangedCallback(class IConfigDef* config); diff --git a/UnleashedRecomp/stdafx.h b/UnleashedRecomp/stdafx.h index d8769c36..011046d1 100644 --- a/UnleashedRecomp/stdafx.h +++ b/UnleashedRecomp/stdafx.h @@ -33,6 +33,7 @@ #include #include #include +#include using Microsoft::WRL::ComPtr; diff --git a/UnleashedRecomp/ui/achievement_menu.cpp b/UnleashedRecomp/ui/achievement_menu.cpp index b842ff5a..509553c6 100644 --- a/UnleashedRecomp/ui/achievement_menu.cpp +++ b/UnleashedRecomp/ui/achievement_menu.cpp @@ -12,6 +12,7 @@ #include #include #include +#include constexpr double HEADER_CONTAINER_INTRO_MOTION_START = 0; constexpr double HEADER_CONTAINER_INTRO_MOTION_END = 15; @@ -621,9 +622,9 @@ void AchievementMenu::Init() constexpr float FONT_SCALE = 2.0f; - g_fntSeurat = io.Fonts->AddFontFromFileTTF("FOT-SeuratPro-M.otf", 24.0f * FONT_SCALE); - g_fntNewRodinDB = io.Fonts->AddFontFromFileTTF("FOT-NewRodinPro-DB.otf", 20.0f * FONT_SCALE); - g_fntNewRodinUB = io.Fonts->AddFontFromFileTTF("FOT-NewRodinPro-UB.otf", 20.0f * FONT_SCALE); + g_fntSeurat = ImFontAtlasSnapshot::GetFont("FOT-SeuratPro-M.otf", 24.0f * FONT_SCALE); + g_fntNewRodinDB = ImFontAtlasSnapshot::GetFont("FOT-NewRodinPro-DB.otf", 20.0f * FONT_SCALE); + g_fntNewRodinUB = ImFontAtlasSnapshot::GetFont("FOT-NewRodinPro-UB.otf", 20.0f * FONT_SCALE); g_upTrophyIcon = LoadTexture(decompressZstd(g_trophy, g_trophy_uncompressed_size).get(), g_trophy_uncompressed_size); g_upSelectionCursor = LoadTexture(decompressZstd(g_select_fill, g_select_fill_uncompressed_size).get(), g_select_fill_uncompressed_size); diff --git a/UnleashedRecomp/ui/achievement_overlay.cpp b/UnleashedRecomp/ui/achievement_overlay.cpp index fe88c962..f6a4087c 100644 --- a/UnleashedRecomp/ui/achievement_overlay.cpp +++ b/UnleashedRecomp/ui/achievement_overlay.cpp @@ -10,6 +10,7 @@ #include #include #include +#include constexpr double OVERLAY_CONTAINER_COMMON_MOTION_START = 0; constexpr double OVERLAY_CONTAINER_COMMON_MOTION_END = 11; @@ -77,7 +78,7 @@ void AchievementOverlay::Init() constexpr float FONT_SCALE = 2.0f; - g_fntSeurat = io.Fonts->AddFontFromFileTTF("FOT-SeuratPro-M.otf", 24.0f * FONT_SCALE); + g_fntSeurat = ImFontAtlasSnapshot::GetFont("FOT-SeuratPro-M.otf", 24.0f * FONT_SCALE); g_upWindow = LoadTexture(decompressZstd(g_general_window, g_general_window_uncompressed_size).get(), g_general_window_uncompressed_size); } diff --git a/UnleashedRecomp/ui/message_window.cpp b/UnleashedRecomp/ui/message_window.cpp index 8142c8f8..6011df4a 100644 --- a/UnleashedRecomp/ui/message_window.cpp +++ b/UnleashedRecomp/ui/message_window.cpp @@ -5,6 +5,7 @@ #include #include #include +#include constexpr double OVERLAY_CONTAINER_COMMON_MOTION_START = 0; constexpr double OVERLAY_CONTAINER_COMMON_MOTION_END = 11; @@ -175,7 +176,7 @@ void MessageWindow::Init() constexpr float FONT_SCALE = 2.0f; - g_fntSeurat = io.Fonts->AddFontFromFileTTF("FOT-SeuratPro-M.otf", 28.0f * FONT_SCALE); + g_fntSeurat = ImFontAtlasSnapshot::GetFont("FOT-SeuratPro-M.otf", 24.0f * FONT_SCALE); g_upSelectionCursor = LoadTexture(decompressZstd(g_select_fade, g_select_fade_uncompressed_size).get(), g_select_fade_uncompressed_size); } diff --git a/UnleashedRecomp/ui/options_menu.cpp b/UnleashedRecomp/ui/options_menu.cpp index 88f5ae1f..4c3625f1 100644 --- a/UnleashedRecomp/ui/options_menu.cpp +++ b/UnleashedRecomp/ui/options_menu.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -975,9 +976,9 @@ void OptionsMenu::Init() constexpr float FONT_SCALE = 2.0f; - g_seuratFont = io.Fonts->AddFontFromFileTTF("FOT-SeuratPro-M.otf", 26.0f * FONT_SCALE); - g_dfsogeistdFont = io.Fonts->AddFontFromFileTTF("DFSoGeiStd-W7.otf", 48.0f * FONT_SCALE); - g_newRodinFont = io.Fonts->AddFontFromFileTTF("FOT-NewRodinPro-DB.otf", 20.0f * FONT_SCALE); + g_seuratFont = ImFontAtlasSnapshot::GetFont("FOT-SeuratPro-M.otf", 24.0f * FONT_SCALE); + g_dfsogeistdFont = ImFontAtlasSnapshot::GetFont("DFSoGeiStd-W7.otf", 48.0f * FONT_SCALE); + g_newRodinFont = ImFontAtlasSnapshot::GetFont("FOT-NewRodinPro-DB.otf", 20.0f * FONT_SCALE); } void OptionsMenu::Draw() diff --git a/UnleashedRecomp/user/config_detail.cpp b/UnleashedRecomp/user/config_detail.cpp index 084ca684..31492253 100644 --- a/UnleashedRecomp/user/config_detail.cpp +++ b/UnleashedRecomp/user/config_detail.cpp @@ -163,3 +163,28 @@ std::string ConfigDef::GetValueDescription() const return std::get<1>(strings.at(Value)); } + +template +inline void ConfigDef::GetLocaleStrings(std::vector& localeStrings) const +{ + if (Locale != nullptr) + { + for (auto& [language, nameAndDesc] : *Locale) + { + localeStrings.push_back(std::get<0>(nameAndDesc)); + localeStrings.push_back(std::get<1>(nameAndDesc)); + } + } + + if (EnumLocale != nullptr) + { + for (auto& [language, locale] : *EnumLocale) + { + for (auto& [value, nameAndDesc] : locale) + { + localeStrings.push_back(std::get<0>(nameAndDesc)); + localeStrings.push_back(std::get<1>(nameAndDesc)); + } + } + } +} diff --git a/UnleashedRecomp/user/config_detail.h b/UnleashedRecomp/user/config_detail.h index 25c1ccba..2571e219 100644 --- a/UnleashedRecomp/user/config_detail.h +++ b/UnleashedRecomp/user/config_detail.h @@ -224,6 +224,7 @@ public: virtual std::string GetValueDescription() const = 0; virtual std::string GetDefinition(bool withSection = false) const = 0; virtual std::string ToString(bool strWithQuotes = true) const = 0; + virtual void GetLocaleStrings(std::vector& localeStrings) const = 0; }; template @@ -232,12 +233,12 @@ class ConfigDef : public IConfigDef public: std::string Section{}; std::string Name{}; - CONFIG_LOCALE* Locale; + CONFIG_LOCALE* Locale{}; T DefaultValue{}; T Value{ DefaultValue }; std::unordered_map* EnumTemplate; std::map EnumTemplateReverse{}; - CONFIG_ENUM_LOCALE(T)* EnumLocale; + CONFIG_ENUM_LOCALE(T)* EnumLocale{}; std::function*)> Callback; // CONFIG_DEFINE @@ -350,6 +351,8 @@ public: return result; } + void GetLocaleStrings(std::vector& localeStrings) const override; + ConfigDef& operator=(const ConfigDef& other) { if (this != &other) diff --git a/UnleashedRecompResources b/UnleashedRecompResources index 5b5ad279..96cbb00e 160000 --- a/UnleashedRecompResources +++ b/UnleashedRecompResources @@ -1 +1 @@ -Subproject commit 5b5ad2794a2c78d50dc6a85e71954fb6b9e80ae2 +Subproject commit 96cbb00e929c3731e01685a7352f59a417d606a4