add restart required because of settings to moditem and modpopup

This commit is contained in:
HJfod 2024-08-31 22:00:01 +03:00
parent 6eb079735f
commit 8a826065a1
5 changed files with 36 additions and 3 deletions

View file

@ -283,6 +283,11 @@ bool ModItem::init(ModSource&& source) {
m_downloadListener.bind([this](auto) { this->updateState(); });
m_downloadListener.setFilter(server::ModDownloadFilter(m_source.getID()));
m_settingNodeListener.bind([this](SettingNodeValueChangeEventV3*) {
this->updateState();
return ListenerResult::Propagate;
});
return true;
}

View file

@ -35,6 +35,7 @@ protected:
EventListener<server::ServerRequest<std::optional<server::ServerModUpdate>>> m_checkUpdateListener;
EventListener<server::ModDownloadFilter> m_downloadListener;
std::optional<server::ServerModUpdate> m_availableUpdate;
EventListener<EventFilter<SettingNodeValueChangeEventV3>> m_settingNodeListener;
/**
* @warning Make sure `getMetadata` and `createModLogo` are callable

View file

@ -3,6 +3,7 @@
#include <Geode/ui/MDTextArea.hpp>
#include <Geode/utils/web.hpp>
#include <Geode/loader/Loader.hpp>
#include <Geode/loader/ModSettingsManager.hpp>
#include <Geode/ui/GeodeUI.hpp>
#include <Geode/utils/ColorProvider.hpp>
#include "ConfirmUninstallPopup.hpp"
@ -557,6 +558,13 @@ bool ModPopup::setup(ModSource&& src) {
mainContainer->updateLayout();
m_mainLayer->addChildAtPosition(mainContainer, Anchor::Center);
m_settingsBG = CCScale9Sprite::create("square02b_001.png");
m_settingsBG->setColor({ 0, 0, 0 });
m_settingsBG->setOpacity(75);
m_settingsBG->setScale(.3f);
m_settingsBG->setContentSize(ccp(35, 30) / linksBG->getScale());
m_buttonMenu->addChildAtPosition(m_settingsBG, Anchor::BottomLeft, ccp(28, 25));
auto settingsSpr = createGeodeCircleButton(CCSprite::createWithSpriteFrameName("settings.png"_spr));
settingsSpr->setScale(.6f);
auto settingsBtn = CCMenuItemSpriteExtra::create(
@ -601,15 +609,30 @@ bool ModPopup::setup(ModSource&& src) {
m_downloadListener.bind([this](auto) { this->updateState(); });
m_downloadListener.setFilter(m_source.getID());
m_settingNodeListener.bind([this](SettingNodeValueChangeEventV3*) {
this->updateState();
return ListenerResult::Propagate;
});
return true;
}
void ModPopup::updateState() {
auto asMod = m_source.asMod();
auto wantsRestart = m_source.wantsRestart();
auto wantsRestartBecauseOfSettings = asMod && ModSettingsManager::from(asMod)->restartRequired();
m_installBG->setColor(wantsRestart ? to3B(ColorProvider::get()->color("mod-list-restart-required-label"_spr)) : ccc3(0, 0, 0));
m_installBG->setOpacity(wantsRestart ? 40 : 75);
m_installBG->setColor((wantsRestart && !wantsRestartBecauseOfSettings) ?
to3B(ColorProvider::get()->color("mod-list-restart-required-label"_spr)) :
ccBLACK
);
m_installBG->setOpacity((wantsRestart && !wantsRestartBecauseOfSettings) ? 40 : 75);
m_settingsBG->setColor(wantsRestartBecauseOfSettings ?
to3B(ColorProvider::get()->color("mod-list-restart-required-label"_spr)) :
ccBLACK
);
m_settingsBG->setOpacity(wantsRestartBecauseOfSettings ? 40 : 75);
m_settingsBG->setVisible(wantsRestartBecauseOfSettings);
m_restartRequiredLabel->setVisible(wantsRestart);
if (!wantsRestart && asMod) {

View file

@ -30,6 +30,7 @@ protected:
CCMenuItemSpriteExtra* m_cancelBtn;
CCLabelBMFont* m_installStatusLabel;
CCScale9Sprite* m_installBG;
CCScale9Sprite* m_settingsBG;
CCLabelBMFont* m_enabledStatusLabel;
ButtonSprite* m_restartRequiredLabel;
CCNode* m_rightColumn;
@ -40,6 +41,7 @@ protected:
EventListener<server::ServerRequest<std::optional<server::ServerModUpdate>>> m_checkUpdateListener;
EventListener<UpdateModListStateFilter> m_updateStateListener;
EventListener<server::ModDownloadFilter> m_downloadListener;
EventListener<EventFilter<SettingNodeValueChangeEventV3>> m_settingNodeListener;
bool setup(ModSource&& src) override;
void updateState();

View file

@ -1,6 +1,7 @@
#include "ModSource.hpp"
#include <Geode/loader/ModMetadata.hpp>
#include <Geode/loader/ModSettingsManager.hpp>
#include <Geode/ui/GeodeUI.hpp>
#include <server/DownloadManager.hpp>
#include <Geode/binding/GameObject.hpp>
@ -106,7 +107,8 @@ bool ModSource::wantsRestart() const {
}
return std::visit(makeVisitor {
[](Mod* mod) {
return mod->getRequestedAction() != ModRequestedAction::None;
return mod->getRequestedAction() != ModRequestedAction::None ||
ModSettingsManager::from(mod)->restartRequired();
},
[](server::ServerModMetadata const& metdata) {
return false;