Skip to content

Commit

Permalink
add unavailable button to mod popup
Browse files Browse the repository at this point in the history
  • Loading branch information
altalk23 committed Dec 13, 2024
1 parent 695f39f commit fdf4348
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
34 changes: 33 additions & 1 deletion loader/src/ui/mods/popups/ModPopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,20 @@ bool ModPopup::setup(ModSource&& src) {
m_reenableBtn->m_notClickable = true;
m_installMenu->addChild(m_reenableBtn);

auto unavailableSpr = createGeodeButton(
CCSprite::createWithSpriteFrameName("exclamation.png"_spr),
"Unavailable",
GeodeButtonSprite::Gray,
m_forceDisableTheme
);
unavailableSpr->setColor({ 155, 155, 155 });
unavailableSpr->setScale(.5f);
m_unavailableBtn = CCMenuItemSpriteExtra::create(
unavailableSpr, this, nullptr
);
m_unavailableBtn->setEnabled(false);
m_installMenu->addChild(m_unavailableBtn);

auto installModSpr = createGeodeButton(
CCSprite::createWithSpriteFrameName("GJ_downloadsIcon_001.png"),
"Install",
Expand Down Expand Up @@ -681,7 +695,8 @@ void ModPopup::updateState() {
m_reenableBtn->setVisible(asMod && modRequestedActionIsToggle(asMod->getRequestedAction()));

m_updateBtn->setVisible(m_source.hasUpdates().has_value() && asMod->getRequestedAction() == ModRequestedAction::None);
m_installBtn->setVisible(m_source.asServer());
m_installBtn->setVisible(this->availableForInstall());
m_unavailableBtn->setVisible(m_source.asServer() && this->availableForInstall());
m_uninstallBtn->setVisible(asMod && asMod->getRequestedAction() == ModRequestedAction::None);

if (asMod && modRequestedActionIsUninstall(asMod->getRequestedAction())) {
Expand Down Expand Up @@ -1126,3 +1141,20 @@ ModPopup* ModPopup::create(ModSource&& src) {
ModSource& ModPopup::getSource() & {
return m_source;
}

bool ModPopup::availableForInstall() const {
// Adapted from ModItem.cpp ModItem::onView
if (auto serverSource = m_source.asServer()) {
auto version = serverSource->latestVersion();
auto gameVersion = version.getGameVersion();

if (
(gameVersion == "0.000") ||
(gameVersion && gameVersion != "*" && gameVersion != GEODE_STR(GEODE_GD_VERSION)) ||
(!Loader::get()->isModVersionSupported(version.getGeodeVersion()))) {
return false;
}
return true;
}
return false;
}
3 changes: 3 additions & 0 deletions loader/src/ui/mods/popups/ModPopup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class ModPopup : public GeodePopup<ModSource&&> {
CCMenuItemToggler* m_reenableBtn;
CCMenuItemSpriteExtra* m_uninstallBtn;
CCMenuItemSpriteExtra* m_installBtn;
CCMenuItemSpriteExtra* m_unavailableBtn;
CCMenuItemSpriteExtra* m_updateBtn;
CCMenuItemSpriteExtra* m_cancelBtn;
CCLabelBMFont* m_installStatusLabel;
Expand Down Expand Up @@ -66,6 +67,8 @@ class ModPopup : public GeodePopup<ModSource&&> {
void onSupport(CCObject*);
void onModtoberInfo(CCObject*);

bool availableForInstall() const;

public:
void loadTab(Tab tab);
static ModPopup* create(ModSource&& src);
Expand Down

0 comments on commit fdf4348

Please sign in to comment.