add download counts to ModItem

This commit is contained in:
HJfod 2024-05-04 23:01:07 +03:00
parent 52de5912e4
commit 03385d07e1
2 changed files with 31 additions and 0 deletions
loader
include/Geode/utils
src/ui/mods/list

View file

@ -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

View file

@ -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();