From efb1fbf72947d26ed71541795211339f4802de0f Mon Sep 17 00:00:00 2001 From: HJfod <60038575+HJfod@users.noreply.github.com> Date: Sun, 10 Nov 2024 12:17:14 +0200 Subject: [PATCH] add option for single-page local mods list --- loader/resources/mod.json.in | 6 ++++++ .../mods/sources/InstalledModListSource.cpp | 19 +++++++++++++++++-- loader/src/ui/mods/sources/ModListSource.cpp | 10 ++++++---- loader/src/ui/mods/sources/ModListSource.hpp | 10 ++++++---- .../src/ui/mods/sources/ModPackListSource.cpp | 2 +- .../ui/mods/sources/ServerModListSource.cpp | 4 ++-- 6 files changed, 38 insertions(+), 13 deletions(-) diff --git a/loader/resources/mod.json.in b/loader/resources/mod.json.in index 0e7ef08d..ea3f2df8 100644 --- a/loader/resources/mod.json.in +++ b/loader/resources/mod.json.in @@ -85,6 +85,12 @@ "name": "Enable Geode-Themed Colors", "description": "When enabled, the Geode menu has a Geode-themed color scheme. This does not affect any other menus!" }, + "infinite-local-mods-list": { + "type": "bool", + "default": false, + "name": "Expand Installed Mods List", + "description": "Make the installed mods list a single infinite scrollable list instead of having pages" + }, "developer-title": { "type": "title", "name": "Developer Settings" diff --git a/loader/src/ui/mods/sources/InstalledModListSource.cpp b/loader/src/ui/mods/sources/InstalledModListSource.cpp index 0aea81f0..5ed9c097 100644 --- a/loader/src/ui/mods/sources/InstalledModListSource.cpp +++ b/loader/src/ui/mods/sources/InstalledModListSource.cpp @@ -68,9 +68,15 @@ void InstalledModListSource::resetQuery() { }; } -InstalledModListSource::ProviderTask InstalledModListSource::fetchPage(size_t page, size_t pageSize, bool forceUpdate) { +InstalledModListSource::ProviderTask InstalledModListSource::fetchPage(size_t page, bool forceUpdate) { m_query.page = page; - m_query.pageSize = pageSize; + m_query.pageSize = m_pageSize; + + // Infinite mods list option + if (Mod::get()->template getSettingValue("infinite-local-mods-list")) { + m_query.page = 0; + m_query.pageSize = Loader::get()->getAllMods().size(); + } auto content = ModListSource::ProvidedMods(); for (auto& mod : Loader::get()->getAllMods()) { @@ -122,3 +128,12 @@ InvalidateQueryAfter InstalledModListSource::getQueryMut() { bool InstalledModListSource::isDefaultQuery() const { return m_query.isDefault(); } + +$execute { + listenForSettingChanges("infinite-local-mods-list", [](bool value) { + auto size = value ? std::numeric_limits::max() : 10; + InstalledModListSource::get(InstalledModListType::All)->setPageSize(size); + InstalledModListSource::get(InstalledModListType::OnlyErrors)->setPageSize(size); + // Updates is technically a server mod list :-) So I left it out here + }); +} diff --git a/loader/src/ui/mods/sources/ModListSource.cpp b/loader/src/ui/mods/sources/ModListSource.cpp index c7b301a0..1c6f57b2 100644 --- a/loader/src/ui/mods/sources/ModListSource.cpp +++ b/loader/src/ui/mods/sources/ModListSource.cpp @@ -5,7 +5,6 @@ #define FTS_FUZZY_MATCH_IMPLEMENTATION #include -static constexpr size_t PER_PAGE = 10; static std::vector ALL_EXTANT_SOURCES {}; static size_t ceildiv(size_t a, size_t b) { @@ -33,7 +32,7 @@ typename ModListSource::PageLoadTask ModListSource::loadPage(size_t page, bool f return PageLoadTask::immediate(Ok(m_cachedPages.at(page))); } m_cachedPages.erase(page); - return this->fetchPage(page, PER_PAGE, forceUpdate).map( + return this->fetchPage(page, forceUpdate).map( [this, page](Result* result) -> Result { if (result->isOk()) { auto data = result->unwrap(); @@ -56,12 +55,15 @@ typename ModListSource::PageLoadTask ModListSource::loadPage(size_t page, bool f } std::optional ModListSource::getPageCount() const { - return m_cachedItemCount ? std::optional(ceildiv(m_cachedItemCount.value(), PER_PAGE)) : std::nullopt; + return m_cachedItemCount ? std::optional(ceildiv(m_cachedItemCount.value(), m_pageSize)) : std::nullopt; } - std::optional ModListSource::getItemCount() const { return m_cachedItemCount; } +void ModListSource::setPageSize(size_t size) { + m_pageSize = size; + this->reset(); +} void ModListSource::reset() { this->resetQuery(); diff --git a/loader/src/ui/mods/sources/ModListSource.hpp b/loader/src/ui/mods/sources/ModListSource.hpp index 5b61d22a..862bec52 100644 --- a/loader/src/ui/mods/sources/ModListSource.hpp +++ b/loader/src/ui/mods/sources/ModListSource.hpp @@ -51,9 +51,10 @@ public: protected: std::unordered_map m_cachedPages; std::optional m_cachedItemCount; + size_t m_pageSize = 10; virtual void resetQuery() = 0; - virtual ProviderTask fetchPage(size_t page, size_t pageSize, bool forceUpdate) = 0; + virtual ProviderTask fetchPage(size_t page, bool forceUpdate) = 0; virtual void setSearchQuery(std::string const& query) = 0; ModListSource(); @@ -75,6 +76,7 @@ public: PageLoadTask loadPage(size_t page, bool forceUpdate = false); std::optional getPageCount() const; std::optional getItemCount() const; + void setPageSize(size_t size); static void clearAllCaches(); static bool isRestartRequired(); @@ -123,7 +125,7 @@ protected: InstalledModsQuery m_query; void resetQuery() override; - ProviderTask fetchPage(size_t page, size_t pageSize, bool forceUpdate) override; + ProviderTask fetchPage(size_t page, bool forceUpdate) override; void setSearchQuery(std::string const& query) override; InstalledModListSource(InstalledModListType type); @@ -153,7 +155,7 @@ protected: server::ModsQuery m_query; void resetQuery() override; - ProviderTask fetchPage(size_t page, size_t pageSize, bool forceUpdate) override; + ProviderTask fetchPage(size_t page, bool forceUpdate) override; void setSearchQuery(std::string const& query) override; ServerModListSource(ServerModListType type); @@ -174,7 +176,7 @@ public: class ModPackListSource : public ModListSource { protected: void resetQuery() override; - ProviderTask fetchPage(size_t page, size_t pageSize, bool forceUpdate) override; + ProviderTask fetchPage(size_t page, bool forceUpdate) override; void setSearchQuery(std::string const& query) override; ModPackListSource(); diff --git a/loader/src/ui/mods/sources/ModPackListSource.cpp b/loader/src/ui/mods/sources/ModPackListSource.cpp index 6063d4c7..d2d536ab 100644 --- a/loader/src/ui/mods/sources/ModPackListSource.cpp +++ b/loader/src/ui/mods/sources/ModPackListSource.cpp @@ -1,7 +1,7 @@ #include "ModListSource.hpp" void ModPackListSource::resetQuery() {} -ModPackListSource::ProviderTask ModPackListSource::fetchPage(size_t page, size_t pageSize, bool forceUpdate) { +ModPackListSource::ProviderTask ModPackListSource::fetchPage(size_t page, bool forceUpdate) { return ProviderTask::immediate(Err(LoadPageError("Coming soon ;)"))); } diff --git a/loader/src/ui/mods/sources/ServerModListSource.cpp b/loader/src/ui/mods/sources/ServerModListSource.cpp index cc43e495..3dc54f83 100644 --- a/loader/src/ui/mods/sources/ServerModListSource.cpp +++ b/loader/src/ui/mods/sources/ServerModListSource.cpp @@ -4,9 +4,9 @@ void ServerModListSource::resetQuery() { m_query = this->createDefaultQuery(); } -ServerModListSource::ProviderTask ServerModListSource::fetchPage(size_t page, size_t pageSize, bool forceUpdate) { +ServerModListSource::ProviderTask ServerModListSource::fetchPage(size_t page, bool forceUpdate) { m_query.page = page; - m_query.pageSize = pageSize; + m_query.pageSize = m_pageSize; return server::getMods(m_query, !forceUpdate).map( [](Result* result) -> ProviderTask::Value { if (result->isOk()) {