From 8a826065a1c1d4f64e9b00ebf37e40564a957180 Mon Sep 17 00:00:00 2001 From: HJfod <60038575+HJfod@users.noreply.github.com> Date: Sat, 31 Aug 2024 22:00:01 +0300 Subject: [PATCH] add restart required because of settings to moditem and modpopup --- loader/src/ui/mods/list/ModItem.cpp | 5 +++++ loader/src/ui/mods/list/ModItem.hpp | 1 + loader/src/ui/mods/popups/ModPopup.cpp | 27 ++++++++++++++++++++++-- loader/src/ui/mods/popups/ModPopup.hpp | 2 ++ loader/src/ui/mods/sources/ModSource.cpp | 4 +++- 5 files changed, 36 insertions(+), 3 deletions(-) diff --git a/loader/src/ui/mods/list/ModItem.cpp b/loader/src/ui/mods/list/ModItem.cpp index ee85ab85..91e769ae 100644 --- a/loader/src/ui/mods/list/ModItem.cpp +++ b/loader/src/ui/mods/list/ModItem.cpp @@ -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; } diff --git a/loader/src/ui/mods/list/ModItem.hpp b/loader/src/ui/mods/list/ModItem.hpp index 717c030c..f5f9fc90 100644 --- a/loader/src/ui/mods/list/ModItem.hpp +++ b/loader/src/ui/mods/list/ModItem.hpp @@ -35,6 +35,7 @@ protected: EventListener>> m_checkUpdateListener; EventListener m_downloadListener; std::optional m_availableUpdate; + EventListener> m_settingNodeListener; /** * @warning Make sure `getMetadata` and `createModLogo` are callable diff --git a/loader/src/ui/mods/popups/ModPopup.cpp b/loader/src/ui/mods/popups/ModPopup.cpp index 82006b0b..03427bf3 100644 --- a/loader/src/ui/mods/popups/ModPopup.cpp +++ b/loader/src/ui/mods/popups/ModPopup.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #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) { diff --git a/loader/src/ui/mods/popups/ModPopup.hpp b/loader/src/ui/mods/popups/ModPopup.hpp index b91c5092..a6bbf789 100644 --- a/loader/src/ui/mods/popups/ModPopup.hpp +++ b/loader/src/ui/mods/popups/ModPopup.hpp @@ -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>> m_checkUpdateListener; EventListener m_updateStateListener; EventListener m_downloadListener; + EventListener> m_settingNodeListener; bool setup(ModSource&& src) override; void updateState(); diff --git a/loader/src/ui/mods/sources/ModSource.cpp b/loader/src/ui/mods/sources/ModSource.cpp index 0c5ef5d3..fe7bb2e0 100644 --- a/loader/src/ui/mods/sources/ModSource.cpp +++ b/loader/src/ui/mods/sources/ModSource.cpp @@ -1,6 +1,7 @@ #include "ModSource.hpp" #include +#include #include #include #include @@ -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;