From 7f2b7e08a623cec09b17ae085f1b1b982fbf2ddf Mon Sep 17 00:00:00 2001 From: Maxime <672982+maximegmd@users.noreply.github.com> Date: Wed, 28 Jun 2023 13:09:18 +0200 Subject: [PATCH] Revert "Feature/its all about fonts" --- scripts/IconGlyphs/icons.lua | 16 +- src/CET.cpp | 10 +- src/CET.h | 3 - src/Fonts.cpp | 505 -------------------------- src/Fonts.h | 70 ---- src/Options.cpp | 11 +- src/Options.h | 4 +- src/d3d12/D3D12.cpp | 3 +- src/d3d12/D3D12.h | 5 +- src/d3d12/D3D12_Functions.cpp | 146 +++++++- src/imgui_impl/dx12.cpp | 8 - src/imgui_impl/dx12.h | 3 - src/overlay/Overlay.cpp | 17 +- src/overlay/widgets/Bindings.cpp | 2 +- src/overlay/widgets/Console.cpp | 6 +- src/overlay/widgets/GameLog.cpp | 2 +- src/overlay/widgets/ImGuiDebug.cpp | 2 +- src/overlay/widgets/LogWindow.cpp | 5 - src/overlay/widgets/Settings.cpp | 232 +++--------- src/overlay/widgets/Settings.h | 12 +- src/overlay/widgets/TweakDBEditor.cpp | 2 +- src/scripting/LuaSandbox.cpp | 29 +- src/scripting/LuaSandbox.h | 3 +- src/scripting/LuaVM.h | 2 +- src/scripting/LuaVM_Hooks.cpp | 4 +- src/scripting/Scripting.cpp | 20 +- src/scripting/Scripting.h | 3 +- src/sol_imgui/sol_imgui.h | 14 - src/stdafx.h | 4 - xmake.lua | 4 +- 30 files changed, 235 insertions(+), 912 deletions(-) delete mode 100644 src/Fonts.cpp delete mode 100644 src/Fonts.h diff --git a/scripts/IconGlyphs/icons.lua b/scripts/IconGlyphs/icons.lua index f9ea643b..14285ab1 100644 --- a/scripts/IconGlyphs/icons.lua +++ b/scripts/IconGlyphs/icons.lua @@ -1,9 +1,7 @@ -- Generated by https://github.com/Nats-ji/IconFontCppHeadersAndLuaTables for LuaJLT and Lua 5.3+ -- from https://raw.githubusercontent.com/Templarian/MaterialDesign-SVG/master/meta.json -- for use with https://github.com/Templarian/MaterialDesign-Webfont/blob/master/fonts/materialdesignicons-webfont.ttf -local IconGlyphs = {} - -IconGlyphs.icons = { +local IconGlyphs = { AbTesting = "\u{f01c9}", -- U+F01C9 ab-testing, tags: Developer / Languages Abacus = "\u{f16e0}", -- U+F16E0 abacus, tags: Math AbjadArabic = "\u{f1328}", -- U+F1328 abjad-arabic, aliases: writing-system-arabic, tags: Alpha / Numeric @@ -7101,14 +7099,4 @@ IconGlyphs.icons = { ZodiacTaurus = "\u{f0a87}", -- U+F0A87 zodiac-taurus, aliases: horoscope-taurus ZodiacVirgo = "\u{f0a88}", -- U+F0A88 zodiac-virgo, aliases: horoscope-virgo } - -IconGlyphs.metatable = { - __index = function(table, key) - AddTextGlyphs(IconGlyphs.icons[key]) - return IconGlyphs.icons[key] - end -} - -setmetatable(IconGlyphs, IconGlyphs.metatable) - -return IconGlyphs \ No newline at end of file +return IconGlyphs diff --git a/src/CET.cpp b/src/CET.cpp index 6021a138..20b9b65a 100644 --- a/src/CET.cpp +++ b/src/CET.cpp @@ -60,11 +60,6 @@ LuaVM& CET::GetVM() noexcept return m_vm; } -Fonts& CET::GetFonts() noexcept -{ - return m_fonts; -} - bool CET::IsRunning() noexcept { return s_isRunning; @@ -75,9 +70,8 @@ CET::CET() , m_persistentState(m_paths, m_options) , m_bindings(m_paths, m_options) , m_window(&m_bindings, &m_d3d12) - , m_fonts(m_options, m_paths) - , m_d3d12(m_window, m_paths, m_options, m_fonts) - , m_vm(m_paths, m_bindings, m_d3d12, m_fonts) + , m_d3d12(m_window, m_paths, m_options) + , m_vm(m_paths, m_bindings, m_d3d12) , m_overlay(m_bindings, m_options, m_persistentState, m_vm) { m_vm.Initialize(); diff --git a/src/CET.h b/src/CET.h index fa6731a5..adcae844 100644 --- a/src/CET.h +++ b/src/CET.h @@ -8,7 +8,6 @@ #include "overlay/Overlay.h" #include "scripting/LuaVM.h" #include "common/CETTasks.h" -#include "Fonts.h" struct CET { @@ -25,7 +24,6 @@ struct CET VKBindings& GetBindings() noexcept; Overlay& GetOverlay() noexcept; LuaVM& GetVM() noexcept; - Fonts& GetFonts() noexcept; static bool IsRunning() noexcept; @@ -37,7 +35,6 @@ struct CET PersistentState m_persistentState; VKBindings m_bindings; Window m_window; - Fonts m_fonts; D3D12 m_d3d12; LuaVM m_vm; Overlay m_overlay; diff --git a/src/Fonts.cpp b/src/Fonts.cpp deleted file mode 100644 index 8ef2fe04..00000000 --- a/src/Fonts.cpp +++ /dev/null @@ -1,505 +0,0 @@ -#include - -#include "Fonts.h" - -#include -#include - -GlyphRangesBuilder::GlyphRangesBuilder() -{ - const ImWchar defaultRange[] = {0x0020, 0x00FF, 0}; - m_builder.AddRanges(defaultRange); - m_builder.AddChar(0xFFFD); // FallbackChar - m_builder.AddChar(0x2026); // EllipsisChar -} - -bool GlyphRangesBuilder::NeedsRebuild() const -{ - return m_needsRebuild; -} - -void GlyphRangesBuilder::AddText(const std::string& acText) -{ - auto text = acText.c_str(); - while (*text) - { - unsigned int c = 0; - int c_len = ImTextCharFromUtf8(&c, text, NULL); - text += c_len; - if (c_len == 0) - break; - if (!m_builder.GetBit(c)) - { - m_builder.AddChar((ImWchar)c); - m_needsRebuild = true; - } - } -} - -bool GlyphRangesBuilder::AddFile(const std::filesystem::path& acPath) -{ - std::ifstream file(acPath); - if (!file) - return false; - - std::stringstream buffer; - buffer << file.rdbuf(); - - AddText(buffer.str()); - - file.close(); - - return true; -} - -void GlyphRangesBuilder::BuildRanges(ImVector* apRange) -{ - m_builder.BuildRanges(apRange); - m_needsRebuild = false; -} - -Font::Font(const std::filesystem::path& acPath) - : m_path(acPath) -{ - m_name = UTF16ToUTF8(m_path.stem().native()); -} -Font::Font(const std::string& acName, const std::filesystem::path& acPath) - : m_name(acName) - , m_path(acPath) -{ -} -std::string Font::GetName() const -{ - return m_name; -} -std::filesystem::path Font::GetPath() const -{ - return m_path; -} -bool Font::Exists() -{ - return exists(m_path); -} - -// Build Fonts -// if custom font not set: -// we merge and use all the notosans fonts -// (e.g. NotoSans-Regular.ttf + NotoSansJP-Regular.otf + ...). -// -// if custom font is set: -// we use the custom font (e.g. c:/windows/fonts/Comic.ttf). -// TODO: Refactor this -void Fonts::BuildFonts(const SIZE& acOutSize) -{ - // TODO: scale also by DPI - const auto [resx, resy] = acOutSize; - const auto scaleFromReference = std::min(static_cast(resx) / 1920.0f, static_cast(resy) / 1080.0f); - - auto& io = ImGui::GetIO(); - io.Fonts->Clear(); - - const auto& fontSettings = m_options.Font; - const float fontSize = std::floorf(fontSettings.BaseSize * scaleFromReference); - // scale emoji's fontsize by 0.8 to make the glyphs roughly the same size as the main font. not sure about other font, don't really have a good solution. - const float emojiSize = fontSize * 0.8f; - - // get fontpaths - // Get custom font paths from options - const auto customMainFontPath = GetFontPathFromOption(fontSettings.MainFont); - if (customMainFontPath.empty() && !fontSettings.MainFont.empty() && fontSettings.MainFont != "Default") - Log::Warn("Can't find custom main font at path: {}", GetAbsolutePath(fontSettings.MainFont, m_paths.Fonts(), true).string()); - - const auto customMonosFontPath = GetFontPathFromOption(fontSettings.MonoFont); - if (customMonosFontPath.empty() && !fontSettings.MonoFont.empty() && fontSettings.MonoFont != "Default") - Log::Warn("Can't find custom main font at path: {}", GetAbsolutePath(fontSettings.MonoFont, m_paths.Fonts(), true).string()); - - const bool useCustomMainFont = !customMainFontPath.empty(); - const bool useCustomMonosFont = !customMonosFontPath.empty(); - - const auto defaultMainFontPath = GetAbsolutePath(m_defaultMainFont, m_paths.Fonts(), false); - const auto defaultMonoFontPath = GetAbsolutePath(m_defaultMonoFont, m_paths.Fonts(), false); - - // Set main font path to default if customMainFontPath is empty or doesnt exist. - const auto mainFontPath = useCustomMainFont ? customMainFontPath : defaultMainFontPath; - if (mainFontPath.empty()) - Log::Warn("Can't find default main font at path: {}, will use built-in font.", GetAbsolutePath(m_defaultMainFont, m_paths.Fonts(), true).string()); - - // Set monospace font path to default if customMonosFontPath is empty or doesnt exist. - const auto monoFontPath = useCustomMonosFont ? customMonosFontPath : defaultMonoFontPath; - if (monoFontPath.empty()) - Log::Warn("Can't find default monospacee font at path: {}, will use built-in font.", GetAbsolutePath(m_defaultMonoFont, m_paths.Fonts(), true).string()); - - const auto iconFontPath = GetAbsolutePath(m_defaultIconFont, m_paths.Fonts(), false); - if (iconFontPath.empty()) - Log::Warn("Can't find icon font at path: {}", GetAbsolutePath(m_defaultIconFont, m_paths.Fonts(), true).string()); - - const auto emojiFontPath = GetAbsolutePath(m_defaultEmojiFont, m_paths.Fonts(), false); - if (emojiFontPath.empty()) - Log::Warn("Can't find emoji font at path: {}", GetAbsolutePath(m_defaultEmojiFont, m_paths.Fonts(), true).string()); - - m_useEmojiFont = !emojiFontPath.empty(); - - // create config for each font - ImFontConfig fontConfig; - fontConfig.OversampleH = fontSettings.OversampleHorizontal; - fontConfig.OversampleV = fontSettings.OversampleVertical; - - static ImVector fontRange; - fontRange.clear(); - m_glyphRangesBuilder.BuildRanges(&fontRange); - - ImFontConfig iconFontConfig; - iconFontConfig.OversampleH = iconFontConfig.OversampleV = 1; - iconFontConfig.GlyphMinAdvanceX = fontSize; - - ImFontConfig emojiFontConfig; - emojiFontConfig.OversampleH = emojiFontConfig.OversampleV = 1; - emojiFontConfig.FontBuilderFlags |= ImGuiFreeTypeBuilderFlags_LoadColor; - - // load fonts without merging first, so we can calculate the offset to align the fonts. - float mainFontBaselineOffset = 0.0f; - float monoFontBaselineOffset = 0.0f; - if (!mainFontPath.empty() && !monoFontPath.empty() && !iconFontPath.empty()) - { - static const ImWchar mainFontRange[] = {0x0041, 0x0041, 0}; - static const ImWchar iconFontRange[] = {0xF01C9, 0xF01C9, 0}; - auto mainFont = io.Fonts->AddFontFromFileTTF(UTF16ToUTF8(mainFontPath.native()).c_str(), fontSize, &fontConfig, mainFontRange); - auto monoFont = io.Fonts->AddFontFromFileTTF(UTF16ToUTF8(monoFontPath.native()).c_str(), fontSize, &fontConfig, mainFontRange); - auto iconFont = io.Fonts->AddFontFromFileTTF(UTF16ToUTF8(iconFontPath.native()).c_str(), fontSize, &iconFontConfig, iconFontRange); - - io.Fonts->Build(); // Build atlas, retrieve pixel data. - - // calculate font baseline differences - mainFontBaselineOffset = iconFont->Ascent - mainFont->Ascent; - monoFontBaselineOffset = iconFont->Ascent - monoFont->Ascent; - - // clear fonts then merge - io.Fonts->Clear(); - } - - // reconfig fonts for merge - iconFontConfig.MergeMode = true; - emojiFontConfig.MergeMode = true; - - // add main font - { - fontConfig.GlyphOffset.y = std::floorf(mainFontBaselineOffset * -0.5f); - iconFontConfig.GlyphOffset.y = std::ceilf(mainFontBaselineOffset * 0.5f); - - if (!mainFontPath.empty()) - MainFont = io.Fonts->AddFontFromFileTTF(UTF16ToUTF8(mainFontPath.native()).c_str(), fontSize, &fontConfig, fontRange.Data); - else - MainFont = io.Fonts->AddFontDefault(); - - fontConfig.MergeMode = true; - // merge NotoSans-Regular as fallback font when using custom font - if (useCustomMainFont && !defaultMainFontPath.empty()) - io.Fonts->AddFontFromFileTTF(UTF16ToUTF8(defaultMainFontPath.native()).c_str(), fontSize, &fontConfig, fontRange.Data); - - // merge the default CJK fonts - for (const auto& font : m_defaultCJKFonts) - { - const std::filesystem::path fontPath = GetAbsolutePath(font, m_paths.Fonts(), false); - if (fontPath.empty()) - { - Log::Warn("Can't find font {}.", GetAbsolutePath(font, m_paths.Fonts(), true).string()); - continue; - } - io.Fonts->AddFontFromFileTTF(UTF16ToUTF8(fontPath.native()).c_str(), fontSize, &fontConfig, fontRange.Data); - } - fontConfig.MergeMode = false; - - // merge the icon font and emoji font - if (!iconFontPath.empty()) - io.Fonts->AddFontFromFileTTF(UTF16ToUTF8(iconFontPath.native()).c_str(), fontSize, &iconFontConfig, fontRange.Data); - - if (m_useEmojiFont) - io.Fonts->AddFontFromFileTTF(UTF16ToUTF8(emojiFontPath.native()).c_str(), emojiSize, &emojiFontConfig, fontRange.Data); - } - - // add monospace font - { - fontConfig.GlyphOffset.y = std::floorf(monoFontBaselineOffset * -0.5f); - iconFontConfig.GlyphOffset.y = std::ceilf(monoFontBaselineOffset * 0.5f); - - if (!monoFontPath.empty()) - MonoFont = io.Fonts->AddFontFromFileTTF(UTF16ToUTF8(monoFontPath.native()).c_str(), fontSize, &fontConfig, fontRange.Data); - else - MonoFont = io.Fonts->AddFontDefault(); - - fontConfig.MergeMode = true; - - // merge NotoSans-Mono as fallback font when using custom monospace font - if (useCustomMonosFont && !defaultMonoFontPath.empty()) - io.Fonts->AddFontFromFileTTF(UTF16ToUTF8(defaultMonoFontPath.native()).c_str(), fontSize, &fontConfig, fontRange.Data); - - // merge main font with monospace font - if (!mainFontPath.empty()) - io.Fonts->AddFontFromFileTTF(UTF16ToUTF8(mainFontPath.native()).c_str(), fontSize, &fontConfig, fontRange.Data); - - // merge the default CJK fonts - for (const auto& font : m_defaultCJKFonts) - { - const std::filesystem::path fontPath = GetAbsolutePath(font, m_paths.Fonts(), false); - if (fontPath.empty()) - continue; - io.Fonts->AddFontFromFileTTF(UTF16ToUTF8(fontPath.native()).c_str(), fontSize, &fontConfig, fontRange.Data); - } - - if (!iconFontPath.empty()) - io.Fonts->AddFontFromFileTTF(UTF16ToUTF8(iconFontPath.native()).c_str(), fontSize, &iconFontConfig, fontRange.Data); - - if (m_useEmojiFont) - io.Fonts->AddFontFromFileTTF(UTF16ToUTF8(emojiFontPath.native()).c_str(), emojiSize, &emojiFontConfig, fontRange.Data); - } -} - -// Rebuild font texture during runtime. -// Call before ImGui_ImplXXXX_NewFrame() -void Fonts::RebuildFonts(ID3D12CommandQueue* apCommandQueue, const SIZE& acOutSize) -{ - - if (m_rebuildFonts || m_glyphRangesBuilder.NeedsRebuild()) // Rebuild when font settings changed or glyph ranges changed - { - BuildFonts(acOutSize); - ImGui_ImplDX12_RecreateFontsTexture(apCommandQueue); - - m_rebuildFonts = false; - } -} - -// Call from imgui to trgger RebuildFonts in the next frame -void Fonts::RebuildFontNextFrame() -{ - m_rebuildFonts = true; -} - -// Check if the emoji font is loaded. -const bool Fonts::UseEmojiFont() -{ - return m_useEmojiFont; -} - -// Get system fonts and their path -void Fonts::EnumerateSystemFonts() -{ - m_systemFonts.clear(); - m_systemFonts.emplace_back(Font("Default", "")); - IDWriteFactory* pDWriteFactory = NULL; - HRESULT hresult = DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory), reinterpret_cast(&pDWriteFactory)); - - IDWriteFontCollection* pFontCollection = NULL; - - // Get the system font collection. - if (SUCCEEDED(hresult)) - hresult = pDWriteFactory->GetSystemFontCollection(&pFontCollection); - - UINT32 familyCount = 0; - - // Get the number of font families in the collection. - if (SUCCEEDED(hresult)) - familyCount = pFontCollection->GetFontFamilyCount(); - - for (UINT32 i = 0; i < familyCount; ++i) - { - IDWriteFontFamily* pFontFamily = NULL; - - // Get the font family. - if (SUCCEEDED(hresult)) - hresult = pFontCollection->GetFontFamily(i, &pFontFamily); - - IDWriteLocalizedStrings* pFamilyNames = NULL; - - // Get a list of localized strings for the family name. - if (SUCCEEDED(hresult)) - hresult = pFontFamily->GetFamilyNames(&pFamilyNames); - - UINT32 index = 0; - BOOL exists = false; - - wchar_t localeName[LOCALE_NAME_MAX_LENGTH]; - - if (SUCCEEDED(hresult)) - { - // Get the default locale for this user. - int defaultLocaleSuccess = GetUserDefaultLocaleName(localeName, LOCALE_NAME_MAX_LENGTH); - - // If the default locale is returned, find that locale name, otherwise use "en-us". - if (defaultLocaleSuccess) - hresult = pFamilyNames->FindLocaleName(localeName, &index, &exists); - - if (SUCCEEDED(hresult) && !exists) // if the above find did not find a match, retry with US English - hresult = pFamilyNames->FindLocaleName(L"en-us", &index, &exists); - } - - // If the specified locale doesn't exist, select the first on the list. - if (!exists) - index = 0; - - UINT32 length = 0; - - // Get the string length. - if (SUCCEEDED(hresult)) - hresult = pFamilyNames->GetStringLength(index, &length); - - // Allocate a string big enough to hold the name. - wchar_t* name = new (std::nothrow) wchar_t[length + 1]; - if (name == NULL) - hresult = E_OUTOFMEMORY; - - // Get the family name. - if (SUCCEEDED(hresult)) - hresult = pFamilyNames->GetString(index, name, length + 1); - - // Get font - IDWriteFont* pFont = NULL; - if (SUCCEEDED(hresult)) - hresult = pFontFamily->GetFont(index, &pFont); - - // Get fontface - IDWriteFontFace* pFontFace = NULL; - if (SUCCEEDED(hresult)) - hresult = pFont->CreateFontFace(&pFontFace); - - UINT32 numberOfFiles = 0; - if (SUCCEEDED(hresult)) - hresult = pFontFace->GetFiles(&numberOfFiles, NULL); - - IDWriteFontFile* pFontFiles = NULL; - if (SUCCEEDED(hresult)) - hresult = pFontFace->GetFiles(&numberOfFiles, &pFontFiles); - - if (numberOfFiles > 0) - { - IDWriteFontFileLoader* pFileLoader = NULL; - IDWriteLocalFontFileLoader* pLocalFileLoader = NULL; - const void* pFontFileReferenceKey = NULL; - UINT32 fontFileReferenceKeySize = 0; - - if (SUCCEEDED(hresult)) - hresult = pFontFiles[0].GetLoader(&pFileLoader); - - if (SUCCEEDED(hresult)) - hresult = pFontFiles[0].GetReferenceKey(&pFontFileReferenceKey, &fontFileReferenceKeySize); - - if (SUCCEEDED(hresult)) - hresult = pFileLoader->QueryInterface(__uuidof(IDWriteLocalFontFileLoader), (void**)&pLocalFileLoader); - - UINT32 filePathLength = 0; - if (SUCCEEDED(hresult)) - hresult = pLocalFileLoader->GetFilePathLengthFromKey(pFontFileReferenceKey, fontFileReferenceKeySize, &filePathLength); - - WCHAR* fontPath = new (std::nothrow) WCHAR[filePathLength + 1]; - if (SUCCEEDED(hresult)) - hresult = pLocalFileLoader->GetFilePathFromKey(pFontFileReferenceKey, fontFileReferenceKeySize, fontPath, filePathLength + 1); - - if (SUCCEEDED(hresult)) - { - m_systemFonts.emplace_back(Font(UTF16ToUTF8(name), fontPath)); - } - } - } - - // print error message if failed - if (FAILED(hresult)) - Log::Error("Error message: {}", std::system_category().message(hresult)); -} - -const std::vector& Fonts::GetSystemFonts() -{ - return m_systemFonts; -} - -Font Fonts::GetSystemFont(const std::string& acFontName) const -{ - for (const auto& systemFont : m_systemFonts) - { - if (systemFont.GetName() == acFontName) - return systemFont; - } - return Font(""); -} - -// Returns absolute path, already checked for file existence. -std::filesystem::path Fonts::GetFontPathFromOption(const std::string& acFontOption) const -{ - if (GetSystemFont(acFontOption).Exists()) - return GetSystemFont(acFontOption).GetPath(); - - if (!GetAbsolutePath(acFontOption, m_paths.Fonts(), false).empty()) - return GetAbsolutePath(acFontOption, m_paths.Fonts(), false); - - return {}; -} - -GlyphRangesBuilder& Fonts::GetGlyphRangesBuilder() -{ - return m_glyphRangesBuilder; -} - -void Fonts::PrecacheGlyphsFromMods() -{ - const auto modsRoot = m_paths.ModsRoot(); - - int fileCount = 0; - - for (const auto& modEntry : std::filesystem::directory_iterator(modsRoot)) - { - // ignore normal files - if (!modEntry.is_directory() && !modEntry.is_symlink()) - continue; - // ignore mod using preserved name - if (modEntry.path().native().starts_with(L"cet\\")) - continue; - - const auto path = GetAbsolutePath(modEntry.path(), modsRoot, false); - // ignore invalid path - if (path.empty()) - continue; - // ignore path symlinked to file - if (!is_directory(path)) - continue; - // ignore directory doesn't contain init.lua - if (!exists(path / L"init.lua")) - continue; - - // iterate all files within each mod folder recursively - for (const auto& entry : std::filesystem::recursive_directory_iterator(modEntry, std::filesystem::directory_options::follow_directory_symlink)) - { - const auto pathStr = UTF16ToUTF8(entry.path().native()); - - // add the file path to the glyph range builder - m_glyphRangesBuilder.AddText(pathStr); - - if (!entry.is_regular_file()) - continue; - - // ignore files without the following extension names: lua, txt, json, yml, yaml, toml, ini - const std::vector extensionFilter = {".lua", ".txt", ".json", ".yml", ".yaml", ".toml", ".ini"}; - const std::string entryExtension = UTF16ToUTF8(entry.path().extension().native()); - if (std::find(extensionFilter.begin(), extensionFilter.end(), entryExtension) == extensionFilter.end()) - continue; - - // open the file and add the content to the glyph range builder - bool result = m_glyphRangesBuilder.AddFile(entry.path()); - - if (!result) - { - Log::Error("Can't read file {}.", pathStr); - continue; - } - - fileCount++; - } - } - - Log::Info("Total mod files cached into glyph ranges builder: {}.", fileCount); -} - -Fonts::Fonts(Options& aOptions, Paths& aPaths) - : m_options(aOptions) - , m_paths(aPaths) -{ - EnumerateSystemFonts(); - PrecacheGlyphsFromMods(); -} \ No newline at end of file diff --git a/src/Fonts.h b/src/Fonts.h deleted file mode 100644 index ce3a9cb3..00000000 --- a/src/Fonts.h +++ /dev/null @@ -1,70 +0,0 @@ -#pragma once - -// a wrapper for ImFontGlyphRangesBuilder -struct GlyphRangesBuilder -{ - GlyphRangesBuilder(); - bool NeedsRebuild() const; - void AddText(const std::string& acText); - bool AddFile(const std::filesystem::path& acPath); - void BuildRanges(ImVector* apRange); - -private: - bool m_needsRebuild{false}; - ImFontGlyphRangesBuilder m_builder; -}; - -struct Font -{ - Font(const std::filesystem::path& acPath); - Font(const std::string& acName, const std::filesystem::path& acPath); - std::string GetName() const; - std::filesystem::path GetPath() const; - bool Exists(); - -private: - std::string m_name; - std::filesystem::path m_path; -}; - -struct Fonts -{ - ~Fonts() = default; - - void BuildFonts(const SIZE& acOutSize); - void RebuildFonts(ID3D12CommandQueue* apCommandQueue, const SIZE& acOutSize); - void RebuildFontNextFrame(); - - const bool UseEmojiFont(); - - void EnumerateSystemFonts(); - const std::vector& GetSystemFonts(); - Font GetSystemFont(const std::string& acFontName) const; - std::filesystem::path GetFontPathFromOption(const std::string& acFontOption) const; - - GlyphRangesBuilder& GetGlyphRangesBuilder(); - void PrecacheGlyphsFromMods(); - - ImFont* MainFont; - ImFont* MonoFont; - -private: - friend struct CET; - Fonts(Options& aOptions, Paths& aPaths); - - Options& m_options; - Paths& m_paths; - - GlyphRangesBuilder m_glyphRangesBuilder; - - bool m_rebuildFonts{false}; - bool m_useEmojiFont{false}; - std::vector m_systemFonts; - - std::filesystem::path m_defaultMainFont{L"NotoSans-Regular.ttf"}; - std::vector m_defaultCJKFonts{ - L"NotoSansJP-Regular.otf", L"NotoSansKR-Regular.otf", L"NotoSansSC-Regular.otf", L"NotoSansTC-Regular.otf", L"NotoSansThai-Regular.ttf"}; - std::filesystem::path m_defaultMonoFont{L"NotoSansMono-Regular.ttf"}; - std::filesystem::path m_defaultIconFont{L"materialdesignicons.ttf"}; - std::filesystem::path m_defaultEmojiFont{L"C:\\Windows\\Fonts\\seguiemj.ttf"}; // tried to use noto color emoji but it wont render. only this one works -}; diff --git a/src/Options.cpp b/src/Options.cpp index eb9131e2..0bab15e7 100644 --- a/src/Options.cpp +++ b/src/Options.cpp @@ -40,8 +40,8 @@ void PatchesSettings::ResetToDefaults() void FontSettings::Load(const nlohmann::json& aConfig) { - MainFont = aConfig.value("main_font", MainFont); - MonoFont = aConfig.value("mono_font", MonoFont); + Path = aConfig.value("path", Path); + Language = aConfig.value("language", Language); BaseSize = aConfig.value("base_size", BaseSize); OversampleHorizontal = aConfig.value("oversample_horizontal", OversampleHorizontal); OversampleVertical = aConfig.value("oversample_vertical", OversampleVertical); @@ -49,12 +49,7 @@ void FontSettings::Load(const nlohmann::json& aConfig) nlohmann::json FontSettings::Save() const { - return { - {"main_font", MainFont}, - {"mono_font", MonoFont}, - {"base_size", BaseSize}, - {"oversample_horizontal", OversampleHorizontal}, - {"oversample_vertical", OversampleVertical}}; + return {{"path", Path}, {"language", Language}, {"base_size", BaseSize}, {"oversample_horizontal", OversampleHorizontal}, {"oversample_vertical", OversampleVertical}}; } void FontSettings::ResetToDefaults() diff --git a/src/Options.h b/src/Options.h index 6f4433c3..1f1664be 100644 --- a/src/Options.h +++ b/src/Options.h @@ -32,8 +32,8 @@ struct FontSettings [[nodiscard]] auto operator<=>(const FontSettings&) const = default; - std::string MainFont{"Default"}; - std::string MonoFont{"Default"}; + std::string Path{}; + std::string Language{"Default"}; float BaseSize{18.0f}; int32_t OversampleHorizontal{3}; int32_t OversampleVertical{1}; diff --git a/src/d3d12/D3D12.cpp b/src/d3d12/D3D12.cpp index 01e1558e..58a99bc7 100644 --- a/src/d3d12/D3D12.cpp +++ b/src/d3d12/D3D12.cpp @@ -60,11 +60,10 @@ LRESULT D3D12::OnWndProc(HWND ahWnd, UINT auMsg, WPARAM awParam, LPARAM alParam) return 0; } -D3D12::D3D12(Window& aWindow, Paths& aPaths, Options& aOptions, Fonts& aFonts) +D3D12::D3D12(Window& aWindow, Paths& aPaths, Options& aOptions) : m_paths(aPaths) , m_window(aWindow) , m_options(aOptions) - , m_fonts(aFonts) { HookGame(); diff --git a/src/d3d12/D3D12.h b/src/d3d12/D3D12.h index 0db5eba1..0c64197b 100644 --- a/src/d3d12/D3D12.h +++ b/src/d3d12/D3D12.h @@ -15,9 +15,11 @@ struct D3D12 { inline static const uint32_t g_numDownlevelBackbuffersRequired = 3; // Windows 7 only: number of buffers needed before we start rendering - D3D12(Window& aWindow, Paths& aPaths, Options& aOptions, Fonts& aFonts); + D3D12(Window& aWindow, Paths& aPaths, Options& aOptions); ~D3D12(); + void ReloadFonts(); + void SetTrapInputInImGui(const bool acEnabled); void DelayedSetTrapInputInImGui(const bool acEnabled); [[nodiscard]] bool IsTrapInputInImGui() const noexcept { return m_trapInputInImGui; } @@ -93,7 +95,6 @@ struct D3D12 Paths& m_paths; Window& m_window; Options& m_options; - Fonts& m_fonts; std::recursive_mutex m_imguiLock; std::array m_imguiDrawDataBuffers; diff --git a/src/d3d12/D3D12_Functions.cpp b/src/d3d12/D3D12_Functions.cpp index dcc2e08e..92f154fb 100644 --- a/src/d3d12/D3D12_Functions.cpp +++ b/src/d3d12/D3D12_Functions.cpp @@ -277,6 +277,148 @@ bool D3D12::InitializeDownlevel(ID3D12CommandQueue* apCommandQueue, ID3D12Resour return true; } +void D3D12::ReloadFonts() +{ + std::lock_guard _(m_imguiLock); + + // TODO - scale also by DPI + const auto [resx, resy] = m_outSize; + const auto scaleFromReference = std::min(static_cast(resx) / 1920.0f, static_cast(resy) / 1080.0f); + + auto& io = ImGui::GetIO(); + io.Fonts->Clear(); + + ImFontConfig config; + const auto& fontSettings = m_options.Font; + config.SizePixels = std::floorf(fontSettings.BaseSize * scaleFromReference); + config.OversampleH = fontSettings.OversampleHorizontal; + config.OversampleV = fontSettings.OversampleVertical; + if (config.OversampleH == 1 && config.OversampleV == 1) + config.PixelSnapH = true; + config.MergeMode = false; + + // add default font + const auto customFontPath = fontSettings.Path.empty() ? std::filesystem::path{} : GetAbsolutePath(UTF8ToUTF16(fontSettings.Path), m_paths.Fonts(), false); + auto cetFontPath = GetAbsolutePath(L"NotoSans-Regular.ttf", m_paths.Fonts(), false); + const auto* cpGlyphRanges = io.Fonts->GetGlyphRangesDefault(); + if (customFontPath.empty()) + { + if (!fontSettings.Path.empty()) + Log::Warn("D3D12::ReloadFonts() - Custom font path is invalid! Using default CET font."); + + if (cetFontPath.empty()) + { + Log::Warn("D3D12::ReloadFonts() - Missing default fonts!"); + io.Fonts->AddFontDefault(&config); + } + else + io.Fonts->AddFontFromFileTTF(UTF16ToUTF8(cetFontPath.native()).c_str(), config.SizePixels, &config, cpGlyphRanges); + } + else + io.Fonts->AddFontFromFileTTF(UTF16ToUTF8(customFontPath.native()).c_str(), config.SizePixels, &config, cpGlyphRanges); + + if (fontSettings.Language == "ChineseFull") + { + cetFontPath = GetAbsolutePath(m_paths.Fonts() / L"NotoSansTC-Regular.otf", m_paths.Fonts(), false); + cpGlyphRanges = io.Fonts->GetGlyphRangesChineseFull(); + } + else if (fontSettings.Language == "ChineseSimplifiedCommon") + { + cetFontPath = GetAbsolutePath(m_paths.Fonts() / L"NotoSansSC-Regular.otf", m_paths.Fonts(), false); + cpGlyphRanges = io.Fonts->GetGlyphRangesChineseSimplifiedCommon(); + } + else if (fontSettings.Language == "Japanese") + { + cetFontPath = GetAbsolutePath(m_paths.Fonts() / L"NotoSansJP-Regular.otf", m_paths.Fonts(), false); + cpGlyphRanges = io.Fonts->GetGlyphRangesJapanese(); + } + else if (fontSettings.Language == "Korean") + { + cetFontPath = GetAbsolutePath(m_paths.Fonts() / L"NotoSansKR-Regular.otf", m_paths.Fonts(), false); + cpGlyphRanges = io.Fonts->GetGlyphRangesKorean(); + } + else if (fontSettings.Language == "Cyrillic") + { + cetFontPath = GetAbsolutePath(m_paths.Fonts() / L"NotoSans-Regular.ttf", m_paths.Fonts(), false); + cpGlyphRanges = io.Fonts->GetGlyphRangesCyrillic(); + } + else if (fontSettings.Language == "Thai") + { + cetFontPath = GetAbsolutePath(m_paths.Fonts() / L"NotoSansThai-Regular.ttf", m_paths.Fonts(), false); + cpGlyphRanges = io.Fonts->GetGlyphRangesThai(); + } + else if (fontSettings.Language == "Vietnamese") + { + cetFontPath = GetAbsolutePath(m_paths.Fonts() / L"NotoSans-Regular.ttf", m_paths.Fonts(), false); + cpGlyphRanges = io.Fonts->GetGlyphRangesVietnamese(); + } + else + { + switch (GetSystemDefaultLangID()) + { + case MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL): + cetFontPath = GetAbsolutePath(L"NotoSansTC-Regular.otf", m_paths.Fonts(), false); + cpGlyphRanges = io.Fonts->GetGlyphRangesChineseFull(); + break; + + case MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED): + cetFontPath = GetAbsolutePath(m_paths.Fonts() / L"NotoSansSC-Regular.otf", m_paths.Fonts(), false); + cpGlyphRanges = io.Fonts->GetGlyphRangesChineseSimplifiedCommon(); + break; + + case MAKELANGID(LANG_JAPANESE, SUBLANG_DEFAULT): + cetFontPath = GetAbsolutePath(m_paths.Fonts() / L"NotoSansJP-Regular.otf", m_paths.Fonts(), false); + cpGlyphRanges = io.Fonts->GetGlyphRangesJapanese(); + break; + + case MAKELANGID(LANG_KOREAN, SUBLANG_DEFAULT): + cetFontPath = GetAbsolutePath(m_paths.Fonts() / L"NotoSansKR-Regular.otf", m_paths.Fonts(), false); + cpGlyphRanges = io.Fonts->GetGlyphRangesKorean(); + break; + + case MAKELANGID(LANG_BELARUSIAN, SUBLANG_DEFAULT): + case MAKELANGID(LANG_RUSSIAN, SUBLANG_DEFAULT): + cetFontPath = GetAbsolutePath(m_paths.Fonts() / L"NotoSans-Regular.ttf", m_paths.Fonts(), false); + cpGlyphRanges = io.Fonts->GetGlyphRangesCyrillic(); + break; + + case MAKELANGID(LANG_THAI, SUBLANG_DEFAULT): + cetFontPath = GetAbsolutePath(m_paths.Fonts() / L"NotoSansThai-Regular.ttf", m_paths.Fonts(), false); + cpGlyphRanges = io.Fonts->GetGlyphRangesThai(); + break; + + case MAKELANGID(LANG_VIETNAMESE, SUBLANG_DEFAULT): + cetFontPath = GetAbsolutePath(m_paths.Fonts() / L"NotoSans-Regular.ttf", m_paths.Fonts(), false); + cpGlyphRanges = io.Fonts->GetGlyphRangesVietnamese(); + break; + } + } + + // add extra glyphs from language font + config.MergeMode = true; + if (customFontPath.empty()) + { + if (!fontSettings.Path.empty()) + Log::Warn("D3D12::ReloadFonts() - Custom font path is invalid! Using default CET font."); + + if (cetFontPath.empty()) + { + Log::Warn("D3D12::ReloadFonts() - Missing fonts for extra language glyphs!"); + io.Fonts->AddFontDefault(&config); + } + else + io.Fonts->AddFontFromFileTTF(UTF16ToUTF8(cetFontPath.native()).c_str(), config.SizePixels, &config, cpGlyphRanges); + } + else + io.Fonts->AddFontFromFileTTF(UTF16ToUTF8(customFontPath.native()).c_str(), config.SizePixels, &config, cpGlyphRanges); + + // add icons from fontawesome4 + config.GlyphMinAdvanceX = config.SizePixels; + static const ImWchar icon_ranges[] = {ICON_MIN_MD, ICON_MAX_MD, 0}; + auto cetIconPath = GetAbsolutePath(L"materialdesignicons.ttf", m_paths.Fonts(), false); + io.Fonts->AddFontFromFileTTF(UTF16ToUTF8(cetIconPath.native()).c_str(), config.SizePixels, &config, icon_ranges); +} + bool D3D12::InitializeImGui(size_t aBuffersCounts) { std::lock_guard _(m_imguiLock); @@ -322,7 +464,7 @@ bool D3D12::InitializeImGui(size_t aBuffersCounts) return false; } - m_fonts.BuildFonts(m_outSize); + ReloadFonts(); if (!ImGui_ImplDX12_CreateDeviceObjects(m_pCommandQueue.Get())) { @@ -342,8 +484,6 @@ void D3D12::PrepareUpdate() std::lock_guard _(m_imguiLock); - m_fonts.RebuildFonts(m_pCommandQueue.Get(), m_outSize); - ImGui_ImplWin32_NewFrame(m_outSize); ImGui::NewFrame(); diff --git a/src/imgui_impl/dx12.cpp b/src/imgui_impl/dx12.cpp index 33e4f09f..394196c6 100644 --- a/src/imgui_impl/dx12.cpp +++ b/src/imgui_impl/dx12.cpp @@ -690,11 +690,3 @@ void ImGui_ImplDX12_NewFrame(ID3D12CommandQueue* apCommandQueue) if (!g_pPipelineState || !ImGui::GetIO().Fonts->IsBuilt()) ImGui_ImplDX12_CreateDeviceObjects(apCommandQueue); } - -void ImGui_ImplDX12_RecreateFontsTexture(ID3D12CommandQueue* apCommandQueue) -{ - SafeRelease(g_pFontTextureResource); - ImGuiIO& io = ImGui::GetIO(); - io.Fonts->TexID = NULL; - ImGui_ImplDX12_CreateFontsTexture(apCommandQueue); -} \ No newline at end of file diff --git a/src/imgui_impl/dx12.h b/src/imgui_impl/dx12.h index b43d44ae..899afbdc 100644 --- a/src/imgui_impl/dx12.h +++ b/src/imgui_impl/dx12.h @@ -38,6 +38,3 @@ IMGUI_IMPL_API void ImGui_ImplDX12_RenderDrawData(ImDrawData* apDrawData, ID3D12 // Use if you want to reset your rendering device without losing Dear ImGui state. IMGUI_IMPL_API void ImGui_ImplDX12_InvalidateDeviceObjects(); IMGUI_IMPL_API bool ImGui_ImplDX12_CreateDeviceObjects(ID3D12CommandQueue* apCommandQueue); - -// Use to recreate font texture during runtime. Call before NewFrame().Should switch to https://github.com/ocornut/imgui/pull/3761 once it's implemented. -IMGUI_IMPL_API void ImGui_ImplDX12_RecreateFontsTexture(ID3D12CommandQueue* apCommandQueue); \ No newline at end of file diff --git a/src/overlay/Overlay.cpp b/src/overlay/Overlay.cpp index cade5a29..aa0ac2ea 100644 --- a/src/overlay/Overlay.cpp +++ b/src/overlay/Overlay.cpp @@ -285,14 +285,11 @@ Overlay::~Overlay() void Overlay::DrawToolbar() { - // add icons to glyph builder - CET::Get().GetFonts().GetGlyphRangesBuilder().AddText(ICON_MD_CONSOLE ICON_MD_KEYBOARD_SETTINGS ICON_MD_COG ICON_MD_DATABASE_EDIT ICON_MD_FILE_DOCUMENT ICON_MD_BUG ICON_MD_RESTART); - const auto itemWidth = GetAlignedItemWidth(7); auto& persistentState = m_persistentState.Overlay; ImGui::PushStyleColor(ImGuiCol_Button, persistentState.ConsoleToggled ? ImGui::GetStyleColorVec4(ImGuiCol_ButtonActive) : ImGui::GetStyleColorVec4(ImGuiCol_Button)); - if (ImGui::Button(ICON_MD_CONSOLE " Console", ImVec2(itemWidth, 0))) + if (ImGui::Button("Console", ImVec2(itemWidth, 0))) m_console.Toggle(); if (!m_toggled) persistentState.ConsoleToggled = m_console.IsEnabled(); @@ -301,7 +298,7 @@ void Overlay::DrawToolbar() ImGui::SameLine(); ImGui::PushStyleColor(ImGuiCol_Button, persistentState.BindingsToggled ? ImGui::GetStyleColorVec4(ImGuiCol_ButtonActive) : ImGui::GetStyleColorVec4(ImGuiCol_Button)); - if (ImGui::Button(ICON_MD_KEYBOARD_SETTINGS " Bindings", ImVec2(itemWidth, 0))) + if (ImGui::Button("Bindings", ImVec2(itemWidth, 0))) m_bindings.Toggle(); if (!m_toggled) persistentState.BindingsToggled = m_bindings.IsEnabled(); @@ -310,7 +307,7 @@ void Overlay::DrawToolbar() ImGui::SameLine(); ImGui::PushStyleColor(ImGuiCol_Button, persistentState.SettingsToggled ? ImGui::GetStyleColorVec4(ImGuiCol_ButtonActive) : ImGui::GetStyleColorVec4(ImGuiCol_Button)); - if (ImGui::Button(ICON_MD_COG " Settings", ImVec2(itemWidth, 0))) + if (ImGui::Button("Settings", ImVec2(itemWidth, 0))) m_settings.Toggle(); if (!m_toggled) persistentState.SettingsToggled = m_settings.IsEnabled(); @@ -319,7 +316,7 @@ void Overlay::DrawToolbar() ImGui::SameLine(); ImGui::PushStyleColor(ImGuiCol_Button, persistentState.TweakDBEditorToggled ? ImGui::GetStyleColorVec4(ImGuiCol_ButtonActive) : ImGui::GetStyleColorVec4(ImGuiCol_Button)); - if (ImGui::Button(ICON_MD_DATABASE_EDIT " TweakDB Editor", ImVec2(itemWidth, 0))) + if (ImGui::Button("TweakDB Editor", ImVec2(itemWidth, 0))) m_tweakDBEditor.Toggle(); if (!m_toggled) persistentState.TweakDBEditorToggled = m_tweakDBEditor.IsEnabled(); @@ -328,7 +325,7 @@ void Overlay::DrawToolbar() ImGui::SameLine(); ImGui::PushStyleColor(ImGuiCol_Button, persistentState.GameLogToggled ? ImGui::GetStyleColorVec4(ImGuiCol_ButtonActive) : ImGui::GetStyleColorVec4(ImGuiCol_Button)); - if (ImGui::Button(ICON_MD_FILE_DOCUMENT " Game Log", ImVec2(itemWidth, 0))) + if (ImGui::Button("Game Log", ImVec2(itemWidth, 0))) m_gameLog.Toggle(); if (!m_toggled) persistentState.GameLogToggled = m_gameLog.IsEnabled(); @@ -337,7 +334,7 @@ void Overlay::DrawToolbar() ImGui::SameLine(); ImGui::PushStyleColor(ImGuiCol_Button, persistentState.ImGuiDebugToggled ? ImGui::GetStyleColorVec4(ImGuiCol_ButtonActive) : ImGui::GetStyleColorVec4(ImGuiCol_Button)); - if (ImGui::Button(ICON_MD_BUG " ImGui Debug", ImVec2(itemWidth, 0))) + if (ImGui::Button("ImGui Debug", ImVec2(itemWidth, 0))) m_imguiDebug.Toggle(); if (!m_toggled) persistentState.ImGuiDebugToggled = m_imguiDebug.IsEnabled(); @@ -345,6 +342,6 @@ void Overlay::DrawToolbar() ImGui::SameLine(); - if (ImGui::Button(ICON_MD_RESTART " Reload all mods", ImVec2(itemWidth, 0))) + if (ImGui::Button("Reload all mods", ImVec2(itemWidth, 0))) m_vm.ReloadAllMods(); } diff --git a/src/overlay/widgets/Bindings.cpp b/src/overlay/widgets/Bindings.cpp index b34f165d..d6ba703a 100644 --- a/src/overlay/widgets/Bindings.cpp +++ b/src/overlay/widgets/Bindings.cpp @@ -24,7 +24,7 @@ bool VKBindInfo::operator==(const std::string& id) const } Bindings::Bindings(VKBindings& aBindings, LuaVM& aVm) - : Widget(ICON_MD_KEYBOARD_SETTINGS " Bindings") + : Widget("Bindings") , m_bindings(aBindings) , m_vm(aVm) { diff --git a/src/overlay/widgets/Console.cpp b/src/overlay/widgets/Console.cpp index 6131fe80..ca61fe58 100644 --- a/src/overlay/widgets/Console.cpp +++ b/src/overlay/widgets/Console.cpp @@ -2,12 +2,11 @@ #include "Console.h" -#include #include #include Console::Console(Options& aOptions, PersistentState& aPersistentState, LuaVM& aVm) - : Widget(ICON_MD_CONSOLE " Console") + : Widget("Console") , m_options(aOptions) , m_persistentState(aPersistentState) , m_vm(aVm) @@ -91,10 +90,7 @@ void Console::OnUpdate() ImGui::SetNextItemWidth(-FLT_MIN); constexpr auto flags = ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AllowTabInput | ImGuiInputTextFlags_CallbackHistory | ImGuiInputTextFlags_CallbackResize; - ImGui::PushFont(CET::Get().GetFonts().MonoFont); - CET::Get().GetFonts().GetGlyphRangesBuilder().AddText(m_command); // Add text to glyph ranges const auto execute = ImGui::InputText("##InputCommand", m_command.data(), m_command.capacity(), flags, &HandleConsole, this); - ImGui::PopFont(); ImGui::SetItemDefaultFocus(); if (execute) { diff --git a/src/overlay/widgets/GameLog.cpp b/src/overlay/widgets/GameLog.cpp index 64961059..98e1a2a7 100644 --- a/src/overlay/widgets/GameLog.cpp +++ b/src/overlay/widgets/GameLog.cpp @@ -3,7 +3,7 @@ #include "GameLog.h" GameLog::GameLog() - : Widget(ICON_MD_FILE_DOCUMENT " Game Log") + : Widget("Game Log") , m_logWindow("gamelog") { } diff --git a/src/overlay/widgets/ImGuiDebug.cpp b/src/overlay/widgets/ImGuiDebug.cpp index d038dea9..a1ad5652 100644 --- a/src/overlay/widgets/ImGuiDebug.cpp +++ b/src/overlay/widgets/ImGuiDebug.cpp @@ -3,7 +3,7 @@ #include "ImGuiDebug.h" ImGuiDebug::ImGuiDebug() - : Widget(ICON_MD_BUG " ImGui Debug", true) + : Widget("ImGui Debug", true) { } diff --git a/src/overlay/widgets/LogWindow.cpp b/src/overlay/widgets/LogWindow.cpp index f3c0cafa..08cc098f 100644 --- a/src/overlay/widgets/LogWindow.cpp +++ b/src/overlay/widgets/LogWindow.cpp @@ -2,7 +2,6 @@ #include "LogWindow.h" -#include #include LogWindow::LogWindow(const std::string& acpLoggerName) @@ -33,7 +32,6 @@ void LogWindow::Draw(const ImVec2& size) if (ImGui::BeginChildFrame(frameId, size, ImGuiWindowFlags_HorizontalScrollbar)) { std::lock_guard _{m_lock}; - ImGui::PushFont(CET::Get().GetFonts().MonoFont); if (!m_lines.empty() && (m_normalizedWidth < 0.0f || m_nextIndexToCheck < m_lines.size())) { @@ -78,8 +76,6 @@ void LogWindow::Draw(const ImVec2& size) ImGui::SetNextItemWidth(listItemWidth); ImGui::PushID(i); - - CET::Get().GetFonts().GetGlyphRangesBuilder().AddText(item); // Add text to glyph ranges ImGui::InputText(("##" + item).c_str(), item.data(), item.size(), ImGuiInputTextFlags_ReadOnly); ImGui::PopID(); @@ -97,7 +93,6 @@ void LogWindow::Draw(const ImVec2& size) } m_scroll = false; } - ImGui::PopFont(); } ImGui::EndChildFrame(); } diff --git a/src/overlay/widgets/Settings.cpp b/src/overlay/widgets/Settings.cpp index 6572487d..3c469875 100644 --- a/src/overlay/widgets/Settings.cpp +++ b/src/overlay/widgets/Settings.cpp @@ -7,7 +7,7 @@ #include Settings::Settings(Options& aOptions, LuaVM& aVm) - : Widget(ICON_MD_COG " Settings") + : Widget("Settings") , m_options(aOptions) , m_vm(aVm) { @@ -52,101 +52,71 @@ void Settings::OnUpdate() if (ImGui::BeginChild(ImGui::GetID("Settings"), frameSize)) { m_madeChanges = false; - m_madeFontChanges = false; if (ImGui::CollapsingHeader("Patches", ImGuiTreeNodeFlags_DefaultOpen)) { ImGui::TreePush(); - if (ImGui::BeginTable("SETTINGS", 2, ImGuiTableFlags_NoSavedSettings, ImVec2(-ImGui::GetStyle().IndentSpacing, 0))) + if (ImGui::BeginTable("##SETTINGS_PATCHES", 2, ImGuiTableFlags_Sortable | ImGuiTableFlags_SizingStretchSame, ImVec2(-ImGui::GetStyle().IndentSpacing, 0))) { const auto& patchesSettings = m_options.Patches; - SettingItemCheckBox( - "🚑", "AMD SMT Patch", "For AMD CPUs that did not get a performance boost after CDPR's patch (requires restart to take effect).", m_patches.AmdSmt, - patchesSettings.AmdSmt); - SettingItemCheckBox( - "👻", "Remove Pedestrians", "Removes most of the pedestrians and traffic (requires restart to take effect).", m_patches.RemovePedestrians, + UpdateAndDrawSetting( + "AMD SMT Patch", + "For AMD CPUs that did not get a performance boost after CDPR's patch (requires restart to take " + "effect).", + m_patches.AmdSmt, patchesSettings.AmdSmt); + UpdateAndDrawSetting( + "Remove Pedestrians", "Removes most of the pedestrians and traffic (requires restart to take effect).", m_patches.RemovePedestrians, patchesSettings.RemovePedestrians); - SettingItemCheckBox( - "🐌", "Disable Async Compute", - "Disables async compute, this can give a boost on older GPUs like Nvidia 10xx series for example (requires restart to take effect).", m_patches.AsyncCompute, - patchesSettings.AsyncCompute); - SettingItemCheckBox( - "🤮", "Disable Anti-aliasing", "Completely disables anti-aliasing (requires restart to take effect).", m_patches.Antialiasing, patchesSettings.Antialiasing); - SettingItemCheckBox( - "🏄", "Skip Start Menu", "Skips the 'Breaching...' menu asking you to press space bar to continue (requires restart to take effect).", m_patches.SkipStartMenu, - patchesSettings.SkipStartMenu); - SettingItemCheckBox( - "🎞", "Suppress Intro Movies", "Disables logos played at the beginning (requires restart to take effect).", m_patches.DisableIntroMovies, + UpdateAndDrawSetting( + "Disable Async Compute", + "Disables async compute, this can give a boost on older GPUs like Nvidia 10xx series for example " + "(requires restart to take effect).", + m_patches.AsyncCompute, patchesSettings.AsyncCompute); + UpdateAndDrawSetting( + "Disable Anti-aliasing", "Completely disables anti-aliasing (requires restart to take effect).", m_patches.Antialiasing, patchesSettings.Antialiasing); + UpdateAndDrawSetting( + "Skip Start Menu", + "Skips the 'Breaching...' menu asking you to press space bar to continue (requires restart to take " + "effect).", + m_patches.SkipStartMenu, patchesSettings.SkipStartMenu); + UpdateAndDrawSetting( + "Suppress Intro Movies", "Disables logos played at the beginning (requires restart to take effect).", m_patches.DisableIntroMovies, patchesSettings.DisableIntroMovies); - SettingItemCheckBox( - "🔦", "Disable Vignette", "Disables vignetting along screen borders (requires restart to take effect).", m_patches.DisableVignette, - patchesSettings.DisableVignette); - SettingItemCheckBox( - "🗺", "Disable Boundary Teleport", "Allows players to access out-of-bounds locations (requires restart to take effect).", m_patches.DisableBoundaryTeleport, + UpdateAndDrawSetting( + "Disable Vignette", "Disables vignetting along screen borders (requires restart to take effect).", m_patches.DisableVignette, patchesSettings.DisableVignette); + UpdateAndDrawSetting( + "Disable Boundary Teleport", "Allows players to access out-of-bounds locations (requires restart to take effect).", m_patches.DisableBoundaryTeleport, patchesSettings.DisableBoundaryTeleport); - SettingItemCheckBox("💨", "Disable V-Sync (Windows 7 only)", " (requires restart to take effect).", m_patches.DisableWin7Vsync, patchesSettings.DisableWin7Vsync); - SettingItemCheckBox( - "✨", "Fix Minimap Flicker", "Disables VSync on Windows 7 to bypass the 60 FPS limit (requires restart to take effect).", m_patches.MinimapFlicker, + UpdateAndDrawSetting("Disable V-Sync (Windows 7 only)", " (requires restart to take effect).", m_patches.DisableWin7Vsync, patchesSettings.DisableWin7Vsync); + UpdateAndDrawSetting( + "Fix Minimap Flicker", "Disables VSync on Windows 7 to bypass the 60 FPS limit (requires restart to take effect).", m_patches.MinimapFlicker, patchesSettings.MinimapFlicker); ImGui::EndTable(); } ImGui::TreePop(); } - if (ImGui::CollapsingHeader("CET Font Settings", ImGuiTreeNodeFlags_DefaultOpen)) - { - ImGui::TreePush(); - if (ImGui::BeginTable("SETTINGS", 2, ImGuiTableFlags_NoSavedSettings, ImVec2(-ImGui::GetStyle().IndentSpacing, 0))) - { - const auto& fontSettings = m_options.Font; - m_madeFontChanges |= - SettingItemFontCombo("🦄", "Main Font", "Main display font for CET.", m_font.MainFont, fontSettings.MainFont, CET::Get().GetFonts().GetSystemFonts()); - m_madeFontChanges |= SettingItemFontCombo( - "🪲", "Monospaced Font", "Monospaceed font, which is used for displaying texts in Console and Game Log, for CET.", m_font.MonoFont, - fontSettings.MonoFont, CET::Get().GetFonts().GetSystemFonts()); - m_madeFontChanges |= SettingItemSliderFloat( - "📏", "Font Size", "Changees the size of the font, default value is 18px.", m_font.BaseSize, fontSettings.BaseSize, 10.0f, 72.0f, "%.0fpx"); - - ImGui::TableNextRow(); - ImGui::TableSetColumnIndex(0); - static bool openFontAdvSettings = false; - ImGui::Selectable("Advance Settings", false, ImGuiSelectableFlags_SpanAllColumns); - if (ImGui::IsItemClicked()) - openFontAdvSettings = !openFontAdvSettings; - if (openFontAdvSettings) - { - ImGui::Indent(ImGui::GetFrameHeight()); - m_madeFontChanges |= SettingItemSliderInt( - "↔", "Oversample Horizontal", "Oversamples font horizontally, default value is 3x. (May increase font clearity, at the cost of increasing memory usage.)", - m_font.OversampleHorizontal, fontSettings.OversampleHorizontal, 1, 10, "%dx"); - m_madeFontChanges |= SettingItemSliderInt( - "↕", "Oversample Vertical", "Oversamples font vertically, default value is 1x. (May increase font clearity, at the cost of increasing memory usage.)", - m_font.OversampleVertical, fontSettings.OversampleVertical, 1, 10, "%dx"); - ImGui::Unindent(ImGui::GetFrameHeight()); - } - - ImGui::EndTable(); - } - ImGui::TreePop(); - } if (ImGui::CollapsingHeader("CET Development Settings", ImGuiTreeNodeFlags_DefaultOpen)) { ImGui::TreePush(); - if (ImGui::BeginTable("SETTINGS", 2, ImGuiTableFlags_NoSavedSettings, ImVec2(-ImGui::GetStyle().IndentSpacing, 0))) + if (ImGui::BeginTable("##SETTINGS_DEV", 2, ImGuiTableFlags_Sortable | ImGuiTableFlags_SizingStretchSame, ImVec2(-ImGui::GetStyle().IndentSpacing, 0))) { const auto& developerSettings = m_options.Developer; - SettingItemCheckBox( - "🗑", "Remove Dead Bindings", "Removes all bindings which are no longer valid (disabling this could be useful when debugging mod issues).", + UpdateAndDrawSetting( + "Remove Dead Bindings", + "Removes all bindings which are no longer valid (disabling this could be useful when debugging mod " + "issues).", m_developer.RemoveDeadBindings, developerSettings.RemoveDeadBindings); - SettingItemCheckBox( - "💣", "Enable ImGui Assertions", - "Enables all ImGui assertions, assertions will get logged into log file of whoever triggered the assertion (useful when debugging ImGui issues, should also be " - "used to check mods before shipping!).", + UpdateAndDrawSetting( + "Enable ImGui Assertions", + "Enables all ImGui assertions, assertions will get logged into log file of whoever triggered the " + "assertion (useful when debugging ImGui issues, should also be used to check mods before " + "shipping!).", m_developer.EnableImGuiAssertions, developerSettings.EnableImGuiAssertions); - SettingItemCheckBox( - "🔨", "Enable Debug Build", "Sets internal flags to disguise as debug build (requires restart to take effect).", m_developer.EnableDebug, + UpdateAndDrawSetting( + "Enable Debug Build", "Sets internal flags to disguise as debug build (requires restart to take effect).", m_developer.EnableDebug, developerSettings.EnableDebug); - SettingItemCheckBox( - "🖨", "Dump Game Options", "Dumps all game options into main log file (requires restart to take effect).", m_developer.DumpGameOptions, + UpdateAndDrawSetting( + "Dump Game Options", "Dumps all game options into main log file (requires restart to take effect).", m_developer.DumpGameOptions, developerSettings.DumpGameOptions); ImGui::EndTable(); @@ -175,16 +145,12 @@ void Settings::Load() m_patches = m_options.Patches; m_developer = m_options.Developer; - m_font = m_options.Font; } void Settings::Save() const { m_options.Patches = m_patches; m_options.Developer = m_developer; - m_options.Font = m_font; - if (m_madeFontChanges) - CET::Get().GetFonts().RebuildFontNextFrame(); m_options.Save(); } @@ -195,17 +161,15 @@ void Settings::ResetToDefaults() m_patches = m_options.Patches; m_developer = m_options.Developer; - m_font = m_options.Font; - CET::Get().GetFonts().RebuildFontNextFrame(); } -void Settings::SettingItemTemplate(const std::string& acIcon, const std::string& acLabel, const std::string& acTooltip, const bool& aValueChanged, std::function& aImGuiFunction) +void Settings::UpdateAndDrawSetting(const std::string& acLabel, const std::string& acTooltip, bool& aCurrent, const bool& acSaved) { ImGui::TableNextRow(); - ImGui::TableSetColumnIndex(0); + ImGui::TableNextColumn(); ImVec4 curTextColor = ImGui::GetStyleColorVec4(ImGuiCol_Text); - if (aValueChanged) + if (aCurrent != acSaved) curTextColor = ImVec4(1.0f, 1.0f, 0.0f, 1.0f); ImGui::AlignTextToFramePadding(); @@ -213,116 +177,20 @@ void Settings::SettingItemTemplate(const std::string& acIcon, const std::string& ImGui::PushStyleColor(ImGuiCol_Text, curTextColor); ImGui::PushID(&acLabel); - if (CET::Get().GetFonts().UseEmojiFont() && !acIcon.empty()) - { - CET::Get().GetFonts().GetGlyphRangesBuilder().AddText(acIcon); - ImGui::TextUnformatted(acIcon.c_str()); - ImGui::SameLine(); - } ImGui::TextUnformatted(acLabel.c_str()); ImGui::PopID(); if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && !acTooltip.empty()) ImGui::SetTooltip("%s", acTooltip.c_str()); - ImGui::TableSetColumnIndex(1); - - ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x / 4); - ImGui::SetNextItemWidth(-FLT_MIN); - - aImGuiFunction(); + ImGui::TableNextColumn(); + ImGui::SetCursorPosX(ImGui::GetCursorPosX() + (ImGui::GetContentRegionAvail().x - ImGui::GetFrameHeight()) / 2); + ImGui::Checkbox(("##" + acLabel).c_str(), &aCurrent); if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled)) ImGui::SetTooltip("%s", acTooltip.c_str()); ImGui::PopStyleColor(); -} - -bool Settings::SettingItemCheckBox(const std::string& acIcon, const std::string& acLabel, const std::string& acTooltip, bool& aCurrent, const bool& acSaved) -{ - std::function imguiWidget = [&]() - { - // Right align checkbox - if (ImGui::BeginTable("CheckboxItem", 2, ImGuiTableFlags_NoSavedSettings)) - { - ImGui::TableSetupColumn("Col1", ImGuiTableColumnFlags_WidthStretch); - ImGui::TableSetupColumn("Col2", ImGuiTableColumnFlags_WidthFixed); - ImGui::TableNextRow(); - ImGui::TableSetColumnIndex(1); - - ImGui::Checkbox(("##" + acLabel).c_str(), &aCurrent); - - ImGui::EndTable(); - } - }; - - const bool valueChanged = aCurrent != acSaved; - - SettingItemTemplate(acIcon, acLabel, acTooltip, valueChanged, imguiWidget); - - m_madeChanges |= aCurrent != acSaved; - - return aCurrent != acSaved; -} - -bool Settings::SettingItemSliderFloat( - const std::string& acIcon, const std::string& acLabel, const std::string& acTooltip, float& aCurrent, const float& acSaved, float aValueMin, float aValueMax, const char* aFormat) -{ - std::function imguiWidget = [&]() - { - ImGui::SliderFloat(("##" + acLabel).c_str(), &aCurrent, aValueMin, aValueMax, aFormat); - }; - - const bool valueChanged = aCurrent != acSaved; - - SettingItemTemplate(acIcon, acLabel, acTooltip, valueChanged, imguiWidget); m_madeChanges |= aCurrent != acSaved; - - return aCurrent != acSaved; } - -bool Settings::SettingItemSliderInt( - const std::string& acIcon, const std::string& acLabel, const std::string& acTooltip, int& aCurrent, const int& acSaved, int aValueMin, int aValueMax, const char* aFormat) -{ - std::function imguiWidget = [&]() - { - ImGui::SliderInt(("##" + acLabel).c_str(), &aCurrent, aValueMin, aValueMax, aFormat); - }; - - const bool valueChanged = aCurrent != acSaved; - - SettingItemTemplate(acIcon, acLabel, acTooltip, valueChanged, imguiWidget); - - m_madeChanges |= aCurrent != acSaved; - - return aCurrent != acSaved; -} - -bool Settings::SettingItemFontCombo( - const std::string& acIcon, const std::string& acLabel, const std::string& acTooltip, std::string& aCurrent, const std::string& acSaved, const std::vector& acFonts) -{ - std::function imguiWidget = [&]() - { - if (ImGui::BeginCombo(("##" + acLabel).c_str(), aCurrent.c_str())) - { - for (const auto& font : acFonts) - { - const bool isSelected = aCurrent == font.GetName(); - if (ImGui::Selectable(font.GetName().c_str(), isSelected)) - aCurrent = font.GetName(); - if (isSelected) - ImGui::SetItemDefaultFocus(); - } - ImGui::EndCombo(); - } - }; - - const bool valueChanged = aCurrent != acSaved; - - SettingItemTemplate(acIcon, acLabel, acTooltip, valueChanged, imguiWidget); - - m_madeChanges |= aCurrent != acSaved; - - return aCurrent != acSaved; -} \ No newline at end of file diff --git a/src/overlay/widgets/Settings.h b/src/overlay/widgets/Settings.h index 3b7e93cd..0ef4c415 100644 --- a/src/overlay/widgets/Settings.h +++ b/src/overlay/widgets/Settings.h @@ -21,25 +21,15 @@ struct Settings : Widget WidgetResult OnPopup() override; private: - void SettingItemTemplate(const std::string& acIcon, const std::string& acLabel, const std::string& acTooltip, const bool& aValueChanged, std::function& aImGuiFunction); - bool SettingItemCheckBox(const std::string& acIcon, const std::string& acLabel, const std::string& acTooltip, bool& aCurrent, const bool& acSaved); - bool SettingItemSliderFloat( - const std::string& acIcon, const std::string& acLabel, const std::string& acTooltip, float& aCurrent, const float& acSaved, float aValueMin, float aValueMax, - const char* aFormat = "%.1f"); - bool SettingItemSliderInt( - const std::string& acIcon, const std::string& acLabel, const std::string& acTooltip, int& aCurrent, const int& acSaved, int aValueMin, int aValueMax, const char* aFormat = "%d"); - bool SettingItemFontCombo( - const std::string& acIcon, const std::string& acLabel, const std::string& acTooltip, std::string& aCurrent, const std::string& acSaved, const std::vector& acFonts); + void UpdateAndDrawSetting(const std::string& acLabel, const std::string& acTooltip, bool& aCurrent, const bool& acSaved); PatchesSettings m_patches; DeveloperSettings m_developer; - FontSettings m_font; Options& m_options; LuaVM& m_vm; TChangedCBResult m_popupResult{TChangedCBResult::APPLY}; bool m_madeChanges{false}; - bool m_madeFontChanges{false}; bool m_openChangesModal{true}; }; diff --git a/src/overlay/widgets/TweakDBEditor.cpp b/src/overlay/widgets/TweakDBEditor.cpp index c0493d4e..44af65d1 100644 --- a/src/overlay/widgets/TweakDBEditor.cpp +++ b/src/overlay/widgets/TweakDBEditor.cpp @@ -121,7 +121,7 @@ bool StringContains(const std::string_view& acString, const std::string_view& ac } TweakDBEditor::TweakDBEditor(LuaVM& aVm) - : Widget(ICON_MD_DATABASE_EDIT " TweakDB Editor") + : Widget("TweakDB Editor") , m_vm(aVm) { } diff --git a/src/scripting/LuaSandbox.cpp b/src/scripting/LuaSandbox.cpp index 1da3ab53..a215b3bc 100644 --- a/src/scripting/LuaSandbox.cpp +++ b/src/scripting/LuaSandbox.cpp @@ -46,7 +46,6 @@ static constexpr const char* s_cGlobalObjectsWhitelist[] = { "print", "GetVersion", "GetDisplayResolution", - "AddTextGlyphs", "ModArchiveExists", "ImGuiListClipper", @@ -111,10 +110,9 @@ static constexpr const char* s_cGlobalExtraLibsWhitelist[] = { "ImGui", }; -LuaSandbox::LuaSandbox(Scripting* apScripting, const VKBindings& acVKBindings, Fonts& aFonts) +LuaSandbox::LuaSandbox(Scripting* apScripting, const VKBindings& acVKBindings) : m_pScripting(apScripting) , m_vkBindings(acVKBindings) - , m_fonts(aFonts) { } @@ -519,40 +517,27 @@ void LuaSandbox::InitializeIOForSandbox(Sandbox& aSandbox, const sol::state& acp ioSB["output"] = DeepCopySolObject(cIO["output"], acpState); ioSB["type"] = DeepCopySolObject(cIO["type"], acpState); ioSB["close"] = DeepCopySolObject(cIO["close"], acpState); - ioSB["lines"] = [this, cIO, cSBRootPath](const std::string& acPath) + ioSB["lines"] = [cIO, cSBRootPath](const std::string& acPath) { const auto previousCurrentPath = std::filesystem::current_path(); current_path(cSBRootPath); - auto path = GetLuaPath(acPath, cSBRootPath, false); - path = path.empty() || acPath == "db.sqlite3" ? "" : path; - - // add the file content to the glyph range builder. - m_fonts.GetGlyphRangesBuilder().AddFile(path); + const auto path = GetLuaPath(acPath, cSBRootPath, false); - auto result = cIO["lines"](UTF16ToUTF8(path.native())); + auto result = cIO["lines"](path.empty() || acPath == "db.sqlite3" ? "" : UTF16ToUTF8(path.native())); current_path(previousCurrentPath); return result; }; - const auto cOpenWithMode = [this, cIO, cSBRootPath](const std::string& acPath, const std::string& acMode) + const auto cOpenWithMode = [cIO, cSBRootPath](const std::string& acPath, const std::string& acMode) { const auto previousCurrentPath = std::filesystem::current_path(); current_path(cSBRootPath); - auto path = GetLuaPath(acPath, cSBRootPath, true); - path = path.empty() || acPath == "db.sqlite3" ? "" : path; - - // add the file content to the glyph range builder, only in modes allow read permissions. and exclude file types not in the list - if (acMode != "w" || acMode != "a") - { - const std::vector extensionFilter = {".lua", ".txt", ".json", ".yml", ".yaml", ".toml", ".ini"}; - if (std::find(extensionFilter.begin(), extensionFilter.end(), UTF16ToUTF8(path.extension().native())) != extensionFilter.end()) - m_fonts.GetGlyphRangesBuilder().AddFile(path); - } + const auto path = GetLuaPath(acPath, cSBRootPath, true); - auto result = cIO["open"](UTF16ToUTF8(path.native()), acMode); + auto result = cIO["open"](path.empty() || acPath == "db.sqlite3" ? "" : UTF16ToUTF8(path.native()), acMode); current_path(previousCurrentPath); diff --git a/src/scripting/LuaSandbox.h b/src/scripting/LuaSandbox.h index 0de04e3b..02a1eb37 100644 --- a/src/scripting/LuaSandbox.h +++ b/src/scripting/LuaSandbox.h @@ -4,7 +4,7 @@ struct LuaSandbox { - LuaSandbox(Scripting* apScripting, const VKBindings& acVKBindings, Fonts& aFonts); + LuaSandbox(Scripting* apScripting, const VKBindings& acVKBindings); ~LuaSandbox() = default; void Initialize(); @@ -36,7 +36,6 @@ struct LuaSandbox void CloseDBForSandbox(const Sandbox& aSandbox) const; - Fonts& m_fonts; Scripting* m_pScripting; const VKBindings& m_vkBindings; sol::table m_globals{}; diff --git a/src/scripting/LuaVM.h b/src/scripting/LuaVM.h index 94960069..323d8daf 100644 --- a/src/scripting/LuaVM.h +++ b/src/scripting/LuaVM.h @@ -25,7 +25,7 @@ struct TDBIDLookupEntry struct Image; struct LuaVM { - LuaVM(const Paths& aPaths, VKBindings& aBindings, D3D12& aD3D12, Fonts& aFonts); + LuaVM(const Paths& aPaths, VKBindings& aBindings, D3D12& aD3D12); ~LuaVM() = default; [[nodiscard]] const VKBind* GetBind(const VKModBind& acModBind) const; diff --git a/src/scripting/LuaVM_Hooks.cpp b/src/scripting/LuaVM_Hooks.cpp index 2daf950d..046ffe41 100644 --- a/src/scripting/LuaVM_Hooks.cpp +++ b/src/scripting/LuaVM_Hooks.cpp @@ -258,8 +258,8 @@ void LuaVM::HookLogChannel(RED4ext::IScriptable*, RED4ext::CStackFrame* apStack, } } -LuaVM::LuaVM(const Paths& aPaths, VKBindings& aBindings, D3D12& aD3D12, Fonts& aFonts) - : m_scripting(aPaths, aBindings, aD3D12, aFonts) +LuaVM::LuaVM(const Paths& aPaths, VKBindings& aBindings, D3D12& aD3D12) + : m_scripting(aPaths, aBindings, aD3D12) , m_d3d12(aD3D12) { Hook(); diff --git a/src/scripting/Scripting.cpp b/src/scripting/Scripting.cpp index bd6662d4..1433088d 100644 --- a/src/scripting/Scripting.cpp +++ b/src/scripting/Scripting.cpp @@ -32,13 +32,12 @@ static constexpr bool s_cThrowLuaErrors = true; static RTTILocator s_stringType{RED4ext::FNV1a64("String")}; static RTTILocator s_resRefType{RED4ext::FNV1a64("redResourceReferenceScriptToken")}; -Scripting::Scripting(const Paths& aPaths, VKBindings& aBindings, D3D12& aD3D12, Fonts& aFonts) - : m_sandbox(this, aBindings, aFonts) +Scripting::Scripting(const Paths& aPaths, VKBindings& aBindings, D3D12& aD3D12) + : m_sandbox(this, aBindings) , m_mapper(m_lua.AsRef(), m_sandbox) , m_store(m_sandbox, aPaths, aBindings) , m_override(this) , m_paths(aPaths) - , m_fonts(aFonts) , m_d3d12(aD3D12) { CreateLogger(aPaths.CETRoot() / "scripting.log", "scripting"); @@ -50,9 +49,6 @@ void Scripting::Initialize() auto lua = m_lua.Lock(); auto& luaVm = lua.Get(); - // putting it here so it can be called from IconGlyphs/icons.lua - luaVm.set_function("AddTextGlyphs", [this](const std::string& acString) -> void { m_fonts.GetGlyphRangesBuilder().AddText(acString); }); - luaVm.open_libraries(sol::lib::base, sol::lib::string, sol::lib::io, sol::lib::math, sol::lib::package, sol::lib::os, sol::lib::table, sol::lib::bit32); luaVm.require("sqlite3", luaopen_lsqlite3); @@ -76,12 +72,6 @@ void Scripting::Initialize() sol_ImGui::InitBindings(luaVm, globals); sol::table imgui = globals["ImGui"]; Texture::BindTexture(imgui); - - imgui["GetMonoFont"] = [this]() -> ImFont* - { - return m_fonts.MonoFont; - }; - for (auto [key, value] : imgui) { if (value.get_type() != sol::type::function) @@ -138,11 +128,6 @@ void Scripting::Initialize() return {static_cast(resolution.cx), static_cast(resolution.cy)}; }; - globals["AddTextGlyphs"] = [this](const std::string& acString) -> void - { - m_fonts.GetGlyphRangesBuilder().AddText(acString); - }; - globals["ModArchiveExists"] = [this](const std::string& acArchiveName) -> bool { const auto resourceDepot = RED4ext::ResourceDepot::Get(); @@ -624,7 +609,6 @@ void Scripting::UnloadAllMods() void Scripting::ReloadAllMods() { UnloadAllMods(); - CET::Get().GetFonts().PrecacheGlyphsFromMods(); // recache glyphs from mods in case of changes m_store.LoadAll(); diff --git a/src/scripting/Scripting.h b/src/scripting/Scripting.h index 7853699d..95f8ab26 100644 --- a/src/scripting/Scripting.h +++ b/src/scripting/Scripting.h @@ -11,7 +11,7 @@ struct Scripting { using LockedState = TiltedPhoques::Locked; - Scripting(const Paths& aPaths, VKBindings& aBindings, D3D12& aD3D12, Fonts& aFonts); + Scripting(const Paths& aPaths, VKBindings& aBindings, D3D12& aD3D12); ~Scripting() = default; void Initialize(); @@ -60,6 +60,5 @@ struct Scripting ScriptStore m_store; FunctionOverride m_override; const Paths& m_paths; - Fonts& m_fonts; D3D12& m_d3d12; }; diff --git a/src/sol_imgui/sol_imgui.h b/src/sol_imgui/sol_imgui.h index bf9ef214..66e4dd01 100644 --- a/src/sol_imgui/sol_imgui.h +++ b/src/sol_imgui/sol_imgui.h @@ -1466,56 +1466,42 @@ inline void VSliderScalar() // Widgets: Input with Keyboard inline std::tuple InputText(const std::string& label, std::string text, unsigned int buf_size) { - CET::Get().GetFonts().GetGlyphRangesBuilder().AddText(text); // Add text to glyph ranges - text.resize(buf_size); bool selected = ImGui::InputText(label.c_str(), text.data(), buf_size); return std::make_tuple(text.c_str(), selected); } inline std::tuple InputText(const std::string& label, std::string text, unsigned int buf_size, int flags) { - CET::Get().GetFonts().GetGlyphRangesBuilder().AddText(text); // Add text to glyph ranges - text.resize(buf_size); bool selected = ImGui::InputText(label.c_str(), text.data(), buf_size, flags); return std::make_tuple(text.c_str(), selected); } inline std::tuple InputTextMultiline(const std::string& label, std::string text, unsigned int buf_size) { - CET::Get().GetFonts().GetGlyphRangesBuilder().AddText(text); // Add text to glyph ranges - text.resize(buf_size); bool selected = ImGui::InputTextMultiline(label.c_str(), text.data(), buf_size); return std::make_tuple(text.c_str(), selected); } inline std::tuple InputTextMultiline(const std::string& label, std::string text, unsigned int buf_size, float sizeX, float sizeY) { - CET::Get().GetFonts().GetGlyphRangesBuilder().AddText(text); // Add text to glyph ranges - text.resize(buf_size); bool selected = ImGui::InputTextMultiline(label.c_str(), text.data(), buf_size, {sizeX, sizeY}); return std::make_tuple(text.c_str(), selected); } inline std::tuple InputTextMultiline(const std::string& label, std::string text, unsigned int buf_size, float sizeX, float sizeY, int flags) { - CET::Get().GetFonts().GetGlyphRangesBuilder().AddText(text); // Add text to glyph ranges - text.resize(buf_size); bool selected = ImGui::InputTextMultiline(label.c_str(), text.data(), buf_size, {sizeX, sizeY}, flags); return std::make_tuple(text.c_str(), selected); } inline std::tuple InputTextWithHint(const std::string& label, const std::string& hint, std::string text, unsigned int buf_size) { - CET::Get().GetFonts().GetGlyphRangesBuilder().AddText(text); // Add text to glyph ranges - text.resize(buf_size); bool selected = ImGui::InputTextWithHint(label.c_str(), hint.c_str(), text.data(), buf_size); return std::make_tuple(text.c_str(), selected); } inline std::tuple InputTextWithHint(const std::string& label, const std::string& hint, std::string text, unsigned int buf_size, int flags) { - CET::Get().GetFonts().GetGlyphRangesBuilder().AddText(text); // Add text to glyph ranges - text.resize(buf_size); bool selected = ImGui::InputTextWithHint(label.c_str(), hint.c_str(), text.data(), buf_size, flags); return std::make_tuple(text.c_str(), selected); diff --git a/src/stdafx.h b/src/stdafx.h index ce4ea787..82100359 100644 --- a/src/stdafx.h +++ b/src/stdafx.h @@ -3,8 +3,6 @@ #include #include #include -#include -#include #include #include #include @@ -46,7 +44,6 @@ #include #include #include -#include #include #include @@ -72,7 +69,6 @@ #include "common/FontMaterialDesignIcons.h" #include "Options.h" #include "Paths.h" -#include "Fonts.h" #include "PersistentState.h" #include "reverse/Addresses.h" #include "scripting/GameHooks.h" diff --git a/xmake.lua b/xmake.lua index 26a7e95e..342e70de 100644 --- a/xmake.lua +++ b/xmake.lua @@ -66,14 +66,14 @@ target("RED4ext.SDK") on_install(function() end) target("cyber_engine_tweaks") - add_defines("WIN32_LEAN_AND_MEAN", "NOMINMAX", "WINVER=0x0601", "SOL_ALL_SAFETIES_ON", "SOL_LUAJIT=1", "SOL_EXCEPTIONS_SAFE_PROPAGATION", "SPDLOG_WCHAR_TO_UTF8_SUPPORT", "SPDLOG_WCHAR_FILENAMES", "SPDLOG_WCHAR_SUPPORT", "IMGUI_USER_CONFIG=\""..imguiUserConfig.."\"", "SOL_IMGUI_ENABLE_FONT_MANIPULATORS") -- WINVER=0x0601 == Windows 7xmake + add_defines("WIN32_LEAN_AND_MEAN", "NOMINMAX", "WINVER=0x0601", "SOL_ALL_SAFETIES_ON", "SOL_LUAJIT=1", "SOL_EXCEPTIONS_SAFE_PROPAGATION", "SPDLOG_WCHAR_TO_UTF8_SUPPORT", "SPDLOG_WCHAR_FILENAMES", "SPDLOG_WCHAR_SUPPORT", "IMGUI_USER_CONFIG=\""..imguiUserConfig.."\"") -- WINVER=0x0601 == Windows 7xmake set_pcxxheader("src/stdafx.h") set_kind("shared") set_filename("cyber_engine_tweaks.asi") add_files("src/**.cpp") add_headerfiles("src/**.h", "build/CETVersion.h") add_includedirs("src/", "build/") - add_syslinks("User32", "Version", "d3d11", "Dwrite") + add_syslinks("User32", "Version", "d3d11") add_packages("spdlog", "nlohmann_json", "minhook", "hopscotch-map", "imgui", "mem", "sol2", "tiltedcore", "sqlite3", "openrestry-luajit", "xbyak", "stb") add_deps("RED4ext.SDK") add_configfiles("src/CETVersion.h.in")