Skip to content

Commit 4a74314

Browse files
committed
feat(mod): Warn when changing desired local storage mode mid-level
1 parent b98d688 commit 4a74314

2 files changed

Lines changed: 39 additions & 4 deletions

File tree

src/main.cpp

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,10 @@ class $modify(DMPlayerObject, PlayerObject) {
543543
#include <Geode/modify/PauseLayer.hpp>
544544
class $modify(DMPauseLayer, PauseLayer) {
545545

546+
struct Fields {
547+
std::optional<EventListener<geode::Popup<geode::Mod*>::CloseEventFilter>> m_listener;
548+
};
549+
546550
void customSetup() override {
547551

548552
PauseLayer::customSetup();
@@ -554,11 +558,28 @@ class $modify(DMPauseLayer, PauseLayer) {
554558
CircleBaseSize::MediumAlt
555559
);
556560
sprite->setScale(0.6f);
557-
auto button = CCMenuItemExt::createSpriteExtra(
558-
sprite, [](CCNode*){
559-
auto playLayer = static_cast<DMPlayLayer*>(PlayLayer::get());
560561

561-
geode::openSettingsPopup(Mod::get(), true);
562+
auto button = CCMenuItemExt::createSpriteExtra(
563+
sprite, [this](CCNode*){
564+
auto popup = geode::openSettingsPopup(Mod::get(), true);
565+
566+
this->m_fields->m_listener = {PopupBypass::listenForCloseOn(popup)};
567+
568+
this->m_fields->m_listener->bind([](geode::Popup<geode::Mod*>::CloseEvent* e) {
569+
auto playLayer = static_cast<DMPlayLayer*>(PlayLayer::get());
570+
auto storeLocalStr = Mod::get()->getSettingValue<std::string>("store-local-2");
571+
auto useLocal = storeLocalStr == "Always" ? true : storeLocalStr == "Never" ? false :
572+
playLayer->m_level->m_stars >= 10;
573+
574+
if (playLayer->m_fields->m_useLocal == useLocal) return;
575+
576+
constexpr auto message = "<co>\"Use Local Deats\" has changed.</c>\n"
577+
"For this change to take effect, you need to <cl>quit and rejoin "
578+
"the level</c>.";
579+
FLAlertLayer::create(
580+
"Settings changed", message, "OK"
581+
)->show();
582+
});
562583
}
563584
);
564585

src/shared.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,17 @@ namespace dm {
115115
vector<DeathLocationMin>::iterator to, float x);
116116

117117
}
118+
119+
// for whatever fucking reason, listenForClose is protected, so this is a bypass class
120+
class PopupBypass : public geode::Popup<geode::Mod*> {
121+
public:
122+
// PopupBypass() : geode::Popup<geode::Mod*>() {};
123+
124+
static geode::Popup<geode::Mod*>::CloseEventFilter listenForCloseOn(geode::Popup<geode::Mod*>* popup) {
125+
return static_cast<PopupBypass*>(popup)->listenForCloseBypass();
126+
};
127+
128+
geode::Popup<geode::Mod*>::CloseEventFilter listenForCloseBypass() {
129+
return this->listenForClose();
130+
}
131+
};

0 commit comments

Comments
 (0)