Skip to content

Commit cdb6f45

Browse files
committed
option event
1 parent 112a253 commit cdb6f45

4 files changed

Lines changed: 42 additions & 2 deletions

File tree

include/HorribleIdeas.hpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,27 @@ namespace horribleideas {
6767
restart(restart) {};
6868
};
6969

70+
class HorribleOptionEvent : public Event {
71+
protected:
72+
std::string id;
73+
bool isToggled;
74+
75+
public:
76+
HorribleOptionEvent(std::string id, bool isToggled);
77+
78+
std::string getId() const;
79+
bool getIsToggled() const;
80+
};
81+
82+
class AWCW_HORRIBLE_API_DLL HorribleOptionEventFilter : public EventFilter<HorribleOptionEvent> {
83+
public:
84+
using Callback = ListenerResult(HorribleOptionEvent*);
85+
86+
ListenerResult handle(std::function<Callback> fn, HorribleOptionEvent* event) {
87+
return fn(event);
88+
};
89+
};
90+
7091
// All horrible mods
7192
static inline std::vector<Option> m_options = {
7293
{"oxygen",

src/include/HorribleIdeas.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ using namespace horribleideas;
66

77
static inline std::mutex s_horrible_registry_mutex;
88

9+
HorribleOptionEvent::HorribleOptionEvent(std::string id, bool isToggled)
10+
: id(id), isToggled(isToggled) {};
11+
12+
std::string HorribleOptionEvent::getId() const {
13+
return id;
14+
};
15+
16+
bool HorribleOptionEvent::getIsToggled() const {
17+
return isToggled;
18+
};
19+
920
bool horribleideas::get(std::string_view id) {
1021
return Mod::get()->getSavedValue<bool>(std::string(id), false);
1122
};

src/menu/HorribleMenuPopup.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ class HorribleMenuPopup : public Popup<> {
1313

1414
ScrollLayer* m_optionList = nullptr;
1515

16+
EventListener<HorribleOptionEventFilter> m_listener = {
17+
[=](HorribleOptionEvent* event) {
18+
log::info("Horrible option of ID {} toggled to {}", event->getId(), event->getIsToggled() ? "ON" : "OFF");
19+
return ListenerResult::Propagate;
20+
},
21+
HorribleOptionEventFilter()
22+
};
23+
1624
void filterOptionsByTier(const std::vector<Option>& allOptions, SillyTier tier);
1725

1826
void openModSettings(CCObject* sender);

src/menu/toggle/ModOption.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ void ModOption::onToggle(CCObject*) {
172172
if (m_toggler) horribleMod->setSavedValue(m_modID, m_toggler->isToggled());
173173
if (m_restartRequired) Notification::create("Restart required!", NotificationIcon::Warning, 2.5f)->show();
174174

175-
// If grief option is toggled on, call jumpscares::checkAndDownloadGriefLevel
176-
if (m_modID == "grief" && m_toggler->isToggled()) jumpscares::DownloadGriefLevel();
175+
auto event = new HorribleOptionEvent(m_modID, m_toggler->isToggled());
176+
event->postFromMod(horribleMod);
177177

178178
log::info("Option {} now set to {}", m_modName, horribleMod->getSavedValue<bool>(m_modID) ? "disabled" : "enabled"); // wtf is it other way around lmao
179179
};

0 commit comments

Comments
 (0)