This commit is contained in:
Justin 2024-09-05 10:51:52 -07:00 committed by GitHub
commit 84d9975c87
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 46 additions and 0 deletions

BIN
loader/resources/copy.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

View file

@ -375,6 +375,17 @@ bool ModsLayer::init() {
folderBtn->setID("mods-folder-button");
actionsMenu->addChild(folderBtn);
auto copySpr = createGeodeCircleButton(
CCSprite::createWithSpriteFrameName("copy.png"_spr), 1.f,
CircleBaseSize::Medium
);
copySpr->setScale(.8f);
auto copyBtn = CCMenuItemSpriteExtra::create(
copySpr, this, menu_selector(ModsLayer::onCopy)
);
copyBtn->setID("copy-button");
actionsMenu->addChild(copyBtn);
actionsMenu->setLayout(
ColumnLayout::create()
->setAxisAlignment(AxisAlignment::Start)
@ -702,6 +713,40 @@ void ModsLayer::onSettings(CCObject*) {
openSettingsPopup(Mod::get());
}
void ModsLayer::onCopy(CCObject*) {
auto mods = Loader::get()->getAllMods();
if (mods.empty()) {
Notification::create("No mods installed", NotificationIcon::Info, 0.5f)->show();
return;
}
std::sort(mods.begin(), mods.end(), [](Mod* a, Mod* b) {
auto const s1 = a->getID();
auto const s2 = b->getID();
return std::lexicographical_compare(s1.begin(), s1.end(), s2.begin(), s2.end(), [](auto a, auto b) {
return std::tolower(a) < std::tolower(b);
});
});
std::stringstream ss;
using namespace std::string_view_literals;
for (int i = 0; i < mods.size(); i++) {
auto& mod = mods[i];
ss << fmt::format("{} | [{}] {}",
mod->isEnabled() ? "x"sv :
mod->hasProblems() ? "!"sv :
" "sv,
mod->getVersion().toVString(), mod->getID()
);
if (i != mods.size() - 1) {
ss << "\n";
}
}
clipboard::write(ss.str());
Notification::create("Mods list copied to clipboard", NotificationIcon::Info, 0.5f)->show();
}
ModsLayer* ModsLayer::create() {
auto ret = new ModsLayer();
if (ret->init()) {

View file

@ -80,6 +80,7 @@ protected:
void onRefreshList(CCObject*);
void onTheme(CCObject*);
void onSettings(CCObject*);
void onCopy(CCObject*);
void onBack(CCObject*);
void updateState();