diff --git a/loader/include/Geode/utils/general.hpp b/loader/include/Geode/utils/general.hpp index a151ae9d..9fcfa284 100644 --- a/loader/include/Geode/utils/general.hpp +++ b/loader/include/Geode/utils/general.hpp @@ -101,6 +101,17 @@ namespace geode { return ss.str(); } + /** + * Turn a number into an abbreviated string, like `1253` to `1.25K` + */ + template <std::integral Num> + std::string numToAbbreviatedString(Num num) { + if (num >= 1'000'000'000) return fmt::format("{:0.3}B", num / 1'000'000'000.f); + if (num >= 1'000'000) return fmt::format("{:0.3}M", num / 1'000'000.f); + if (num >= 1'000) return fmt::format("{:0.3}K", num / 1'000.f); + return numToString(num); + } + /** * Parse a number from a string * @param str The string to parse diff --git a/loader/src/ui/mods/list/ModItem.cpp b/loader/src/ui/mods/list/ModItem.cpp index b5f678d0..aca1caa2 100644 --- a/loader/src/ui/mods/list/ModItem.cpp +++ b/loader/src/ui/mods/list/ModItem.cpp @@ -161,6 +161,26 @@ bool ModItem::init(ModSource&& source) { m_titleContainer->addChild(starBG); } + + // Show mod download count here already so people can make informed decisions + // on which mods to install + auto downloadsContainer = CCNode::create(); + + auto downloads = CCLabelBMFont::create(numToAbbreviatedString(metadata.downloadCount).c_str(), "bigFont.fnt"); + downloads->setColor("mod-list-version-label"_cc3b); + downloads->limitLabelWidth(80, .5f, .1f); + downloadsContainer->addChildAtPosition(downloads, Anchor::Right, ccp(-0, 0), ccp(1, .5f)); + + auto downloadsIcon = CCSprite::createWithSpriteFrameName("GJ_downloadsIcon_001.png"); + downloadsIcon->setScale(.75f); + downloadsContainer->addChildAtPosition(downloadsIcon, Anchor::Right, ccp(-downloads->getScaledContentWidth() - 10, 0)); + + downloadsContainer->setContentSize({ + downloads->getScaledContentWidth() + 10 + downloadsIcon->getScaledContentWidth() + 10, + 25 + }); + downloadsContainer->updateLayout(); + m_viewMenu->addChild(downloadsContainer); }, [this](ModSuggestion const& suggestion) { m_recommendedBy = CCNode::create();