Skip to content

Commit eb13791

Browse files
committed
more refactors
1 parent 30d9701 commit eb13791

11 files changed

Lines changed: 203 additions & 221 deletions

File tree

.github/workflows/multi-platform.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ jobs:
7676

7777
- name: Publish Nightly release
7878
uses: andelf/nightly-release@main
79+
if: ${{ github.ref_name == github.event.repository.default_branch }}
7980
env:
8081
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8182
with:

mod.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"name": "Options Menu",
5757
"description": "Key to open the Horrible Options menu.",
5858
"default": [
59-
"Backslash"
59+
"\\"
6060
],
6161
"category": "universal"
6262
},

src/classes/ui/src/MathQuiz.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ class MathQuiz::Impl final {
3131
};
3232

3333
MathQuiz::MathQuiz() : m_impl(std::make_unique<Impl>()) {};
34-
3534
MathQuiz::~MathQuiz() {};
3635

3736
bool MathQuiz::init() {

src/classes/ui/src/SpamChallenge.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ class SpamChallenge::Impl final {
2424
};
2525

2626
SpamChallenge::SpamChallenge() : m_impl(std::make_unique<Impl>()) {};
27-
2827
SpamChallenge::~SpamChallenge() {};
2928

3029
bool SpamChallenge::init() {

src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ using namespace horrible::prelude;
1313

1414
$on_game(Loaded) {
1515
listenForKeybindSettingPresses(
16-
"keybind-example",
16+
"key-popup",
1717
[](Keybind const&, bool down, bool repeat, double) {
1818
if (down && !repeat) menu::open();
1919
}

src/menu/OptionCategoryItem.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using namespace geode::prelude;
66

77
// Event for option toggles
8-
struct CategoryEvent final : Event<CategoryEvent, bool(std::string, bool)> {
8+
struct CategoryEvent final : Event<CategoryEvent, bool(std::string_view, bool)> {
99
using Event::Event;
1010
};
1111

@@ -18,8 +18,6 @@ class OptionCategoryItem final : public CCMenu {
1818
OptionCategoryItem();
1919
~OptionCategoryItem();
2020

21-
ListenerResult OnCategory(std::string_view category, bool enabled = false);
22-
2321
void onToggle(CCObject* sender);
2422

2523
bool init(CCSize const& size, std::string category);

src/menu/OptionMenuPopup.hpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,9 @@ class OptionMenuPopup final : public Popup {
2323
protected:
2424
static OptionMenuPopup* s_inst;
2525

26-
// EventListener<CategoryEventFilter> m_catListener = {
27-
// [this](CategoryEvent* event) {
28-
// return OnCategory(event->getId(), event->isEnabled());
29-
// },
30-
// CategoryEventFilter()
31-
// };
32-
3326
OptionMenuPopup();
3427
~OptionMenuPopup();
3528

36-
void filterOptions(std::span<const Option> optList, SillyTier tier = SillyTier::None, ZStringView category = "");
3729
void filterTierCallback(CCObject*);
3830

3931
void resetFilters(CCObject*);

src/menu/src/OptionCategoryItem.cpp

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,20 @@ using namespace horrible::prelude;
99

1010
class OptionCategoryItem::Impl final {
1111
public:
12-
std::string m_category = ""; // The category name
12+
std::string category = ""; // The category name
1313

14-
CCMenuItemToggler* m_toggler = nullptr; // The toggler for the option
15-
};
16-
17-
OptionCategoryItem::OptionCategoryItem() {
18-
m_impl = std::make_unique<Impl>();
14+
CCMenuItemToggler* toggler = nullptr; // The toggler for the option
1915
};
2016

17+
OptionCategoryItem::OptionCategoryItem() : m_impl(std::make_unique<Impl>()) {};
2118
OptionCategoryItem::~OptionCategoryItem() {};
2219

2320
bool OptionCategoryItem::init(CCSize const& size, std::string category) {
24-
m_impl->m_category = std::move(category);
21+
m_impl->category = std::move(category);
2522

2623
if (!CCMenu::init()) return false;
2724

28-
setID(str::join(str::split(str::filter(str::toLower(m_impl->m_category), "abcdefghijklmnopqrstuvwxyz0123456789-_./ "), " "), "-"));
25+
setID(str::join(str::split(str::filter(str::toLower(m_impl->category), "abcdefghijklmnopqrstuvwxyz0123456789-_./ "), " "), "-"));
2926
setContentSize(size);
3027
setAnchorPoint({ 0.5, 1 });
3128

@@ -44,22 +41,22 @@ bool OptionCategoryItem::init(CCSize const& size, std::string category) {
4441
togglerOn->setScale(0.5f);
4542

4643
// toggler for the category
47-
m_impl->m_toggler = CCMenuItemToggler::create(
44+
m_impl->toggler = CCMenuItemToggler::create(
4845
togglerOff,
4946
togglerOn,
5047
this,
5148
menu_selector(OptionCategoryItem::onToggle)
5249
);
53-
m_impl->m_toggler->setID("toggler");
54-
m_impl->m_toggler->setAnchorPoint({ 0.5f, 0.5f });
55-
m_impl->m_toggler->setPosition({ 10.f, getScaledContentHeight() / 2.f });
56-
m_impl->m_toggler->setScale(0.875f);
50+
m_impl->toggler->setID("toggler");
51+
m_impl->toggler->setAnchorPoint({ 0.5f, 0.5f });
52+
m_impl->toggler->setPosition({ 10.f, getScaledContentHeight() / 2.f });
53+
m_impl->toggler->setScale(0.875f);
5754

58-
addChild(m_impl->m_toggler);
55+
addChild(m_impl->toggler);
5956

6057
// name of the joke
6158
auto nameLabel = CCLabelBMFont::create(
62-
m_impl->m_category.c_str(),
59+
m_impl->category.c_str(),
6360
"goldFont.fnt",
6461
getScaledContentWidth() - 35.f,
6562
kCCTextAlignmentLeft
@@ -72,16 +69,18 @@ bool OptionCategoryItem::init(CCSize const& size, std::string category) {
7269

7370
addChild(nameLabel);
7471

75-
return true;
76-
};
72+
addEventListener(
73+
CategoryEvent(),
74+
[this](std::string_view category, bool enabled) {
75+
if (m_impl->toggler) if (category != m_impl->category) m_impl->toggler->toggle(false);
76+
}
77+
);
7778

78-
ListenerResult OptionCategoryItem::OnCategory(std::string_view category, bool enabled) {
79-
if (m_impl->m_toggler) if (category != m_impl->m_category) m_impl->m_toggler->toggle(false);
80-
return ListenerResult::Propagate;
79+
return true;
8180
};
8281

8382
void OptionCategoryItem::onToggle(CCObject* sender) {
84-
if (m_impl->m_toggler) CategoryEvent().send(m_impl->m_category, !m_impl->m_toggler->isOn());
83+
if (m_impl->toggler) CategoryEvent().send(m_impl->category, !m_impl->toggler->isOn());
8584
};
8685

8786
OptionCategoryItem* OptionCategoryItem::create(CCSize const& size, std::string category) {

src/menu/src/OptionItem.cpp

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,36 @@ using namespace horrible::prelude;
99

1010
class OptionItem::Impl final {
1111
public:
12-
bool s_compatible = false; // If this option is compatible with the current platform
12+
bool compatible = false; // If this option is compatible with the current platform
1313

1414
// The option
15-
Option m_option = {
15+
Option option = {
1616
"unk"_spr,
1717
"Unknown Option",
1818
"No description provided.",
1919
"General"
2020
};
2121

22-
CCMenuItemToggler* m_toggler = nullptr; // The toggler for the option
23-
};
24-
25-
OptionItem::OptionItem() {
26-
m_impl = std::make_unique<Impl>();
22+
CCMenuItemToggler* toggler = nullptr; // The toggler for the option
2723
};
2824

25+
OptionItem::OptionItem() : m_impl(std::make_unique<Impl>()) {};
2926
OptionItem::~OptionItem() {};
3027

3128
bool OptionItem::init(CCSize const& size, Option option) {
32-
m_impl->m_option = std::move(option);
29+
m_impl->option = std::move(option);
3330

3431
// check for compatibility
35-
for (auto const& p : m_impl->m_option.platforms) {
32+
for (auto const& p : m_impl->option.platforms) {
3633
if (p & GEODE_PLATFORM_TARGET) {
37-
m_impl->s_compatible = true;
34+
m_impl->compatible = true;
3835
break;
3936
};
4037
};
4138

4239
if (!CCMenu::init()) return false;
4340

44-
setID(m_impl->m_option.id);
41+
setID(m_impl->option.id);
4542
setContentSize(size);
4643
setAnchorPoint({ 0.5, 1 });
4744

@@ -66,27 +63,27 @@ bool OptionItem::init(CCSize const& size, Option option) {
6663
togglerOn->setScale(0.875f);
6764

6865
// toggler for the option
69-
m_impl->m_toggler = CCMenuItemToggler::create(
66+
m_impl->toggler = CCMenuItemToggler::create(
7067
togglerOff,
7168
togglerOn,
7269
this,
7370
menu_selector(OptionItem::onToggle)
7471
);
75-
m_impl->m_toggler->setID("toggler");
76-
m_impl->m_toggler->setAnchorPoint({ 0.5f, 0.5f });
77-
m_impl->m_toggler->setPosition({ x + 12.f, yCenter });
78-
m_impl->m_toggler->setScale(0.875f);
72+
m_impl->toggler->setID("toggler");
73+
m_impl->toggler->setAnchorPoint({ 0.5f, 0.5f });
74+
m_impl->toggler->setPosition({ x + 12.f, yCenter });
75+
m_impl->toggler->setScale(0.875f);
7976

8077
// Set toggler state based on saved mod option value
81-
if (horribleMod) m_impl->m_toggler->toggle(horribleMod->getSavedValue<bool>(m_impl->m_option.id));
78+
if (horribleMod) m_impl->toggler->toggle(horribleMod->getSavedValue<bool>(m_impl->option.id));
8279

83-
addChild(m_impl->m_toggler);
80+
addChild(m_impl->toggler);
8481

8582
x += 30.f;
8683

8784
// name of the joke
8885
auto nameLabel = CCLabelBMFont::create(
89-
m_impl->m_option.name.c_str(),
86+
m_impl->option.name.c_str(),
9087
"bigFont.fnt",
9188
getScaledContentWidth() - 40.f,
9289
kCCTextAlignmentLeft
@@ -98,7 +95,7 @@ bool OptionItem::init(CCSize const& size, Option option) {
9895
nameLabel->setScale(0.4f);
9996

10097
auto categoryLabel = CCLabelBMFont::create(
101-
m_impl->m_option.category.c_str(),
98+
m_impl->option.category.c_str(),
10299
"goldFont.fnt",
103100
getScaledContentWidth() - 60.f,
104101
kCCTextAlignmentLeft
@@ -110,8 +107,8 @@ bool OptionItem::init(CCSize const& size, Option option) {
110107
categoryLabel->setOpacity(200);
111108
categoryLabel->setScale(0.25f);
112109

113-
// Set color based on m_impl->m_option.Tier
114-
switch (m_impl->m_option.silly) {
110+
// Set color based on m_impl->option.Tier
111+
switch (m_impl->option.silly) {
115112
case SillyTier::Low: // green
116113
nameLabel->setColor(colors::green);
117114
break;
@@ -134,7 +131,7 @@ bool OptionItem::init(CCSize const& size, Option option) {
134131

135132
if (horribleMod->getSettingValue<bool>("dev-mode")) {
136133
auto idLabel = CCLabelBMFont::create(
137-
m_impl->m_option.id.c_str(),
134+
m_impl->option.id.c_str(),
138135
"chatFont.fnt",
139136
getScaledContentWidth() - 20.f,
140137
kCCTextAlignmentLeft
@@ -167,8 +164,8 @@ bool OptionItem::init(CCSize const& size, Option option) {
167164

168165
addChild(helpBtn);
169166

170-
if (!m_impl->s_compatible) {
171-
m_impl->m_toggler->toggle(false);
167+
if (!m_impl->compatible) {
168+
m_impl->toggler->toggle(false);
172169

173170
togglerOn->setDisplayFrame(togglerOff->displayFrame());
174171

@@ -192,34 +189,34 @@ bool OptionItem::init(CCSize const& size, Option option) {
192189
};
193190

194191
void OptionItem::saveTogglerState() {
195-
if (m_impl->m_toggler) options::set(m_impl->m_option.id, m_impl->m_toggler->isToggled());
192+
if (m_impl->toggler) options::set(m_impl->option.id, m_impl->toggler->isToggled());
196193
};
197194

198195
void OptionItem::onToggle(CCObject*) {
199-
if (m_impl->s_compatible) {
196+
if (m_impl->compatible) {
200197
saveTogglerState();
201-
if (m_impl->m_option.restart) {
198+
if (m_impl->option.restart) {
202199
Notification::create("Restart required!", NotificationIcon::Warning, 2.5f)->show();
203-
log::warn("Restart required to apply option {}", m_impl->m_option.id);
200+
log::warn("Restart required to apply option {}", m_impl->option.id);
204201
};
205202

206-
auto now = options::get(m_impl->m_option.id);
203+
auto now = options::get(m_impl->option.id);
207204

208-
OptionEvent(m_impl->m_option.id).send(m_impl->m_option.id, now);
205+
OptionEvent(m_impl->option.id).send(m_impl->option.id, now);
209206

210-
log::info("Option {} now set to {}", m_impl->m_option.name, now ? "disabled" : "enabled"); // wtf is it other way around lmao
211-
} else if (m_impl->m_toggler) {
212-
Notification::create(fmt::format("{} is unavailable for {}", m_impl->m_option.name, GEODE_PLATFORM_NAME), NotificationIcon::Error, 1.25f)->show();
213-
log::error("Option {} is not available for platform {}", m_impl->m_option.id, GEODE_PLATFORM_SHORT_IDENTIFIER);
207+
log::info("Option {} now set to {}", m_impl->option.name, now ? "disabled" : "enabled"); // wtf is it other way around lmao
208+
} else if (m_impl->toggler) {
209+
Notification::create(fmt::format("{} is unavailable for {}", m_impl->option.name, GEODE_PLATFORM_NAME), NotificationIcon::Error, 1.25f)->show();
210+
log::error("Option {} is not available for platform {}", m_impl->option.id, GEODE_PLATFORM_SHORT_IDENTIFIER);
214211

215-
m_impl->m_toggler->toggle(false);
212+
m_impl->toggler->toggle(false);
216213
};
217214
};
218215

219216
void OptionItem::onDescription(CCObject*) {
220217
if (auto popup = FLAlertLayer::create(
221-
m_impl->m_option.name.c_str(),
222-
m_impl->m_option.description.c_str(),
218+
m_impl->option.name.c_str(),
219+
m_impl->option.description.c_str(),
223220
"OK"
224221
)) popup->show();
225222
};
@@ -230,11 +227,11 @@ void OptionItem::onExit() {
230227
};
231228

232229
Option OptionItem::getOption() const noexcept {
233-
return m_impl->m_option;
230+
return m_impl->option;
234231
};
235232

236233
bool OptionItem::isCompatible() const noexcept {
237-
return m_impl->s_compatible;
234+
return m_impl->compatible;
238235
};
239236

240237
OptionItem* OptionItem::create(CCSize const& size, Option option) {

0 commit comments

Comments
 (0)