Skip to content

Commit 0ca19d3

Browse files
committed
sort category names
1 parent 2be3cfc commit 0ca19d3

7 files changed

Lines changed: 69 additions & 37 deletions

File tree

mod.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"name": "Interface",
6363
"description": "Appearance and functionality of the interface."
6464
},
65-
"theme":{
65+
"theme": {
6666
"type": "string",
6767
"name": "Menu Theme",
6868
"description": "Theme to use for the <cg>Horrible Options</c> menu. <co>Re-open the menu for changes to take effect.</c>",

src/Utils.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ namespace horrible {
7777
inline geode::CircleBaseColor getCircleBaseColor(std::string_view theme) {
7878
if (theme == enums::Blue) return geode::CircleBaseColor::Blue;
7979
if (theme == enums::Green) return geode::CircleBaseColor::Green;
80-
if (theme == enums::Dark) return geode::CircleBaseColor::DarkAqua;
80+
if (theme == enums::Dark) return geode::CircleBaseColor::Gray;
8181
if (theme == enums::Light) return geode::CircleBaseColor::Gray;
8282
if (theme == enums::Dim) return geode::CircleBaseColor::Gray;
8383
if (theme == enums::Girlypop) return geode::CircleBaseColor::Pink;
@@ -91,9 +91,9 @@ namespace horrible {
9191
inline const char* getButtonSquareSprite(std::string_view theme) {
9292
if (theme == enums::Blue) return "GJ_button_02.png";
9393
if (theme == enums::Green) return "GJ_button_01.png";
94-
if (theme == enums::Dark) return "geode.loader/GE_button_05.png";
94+
if (theme == enums::Dark) return "GJ_button_05.png";
9595
if (theme == enums::Light) return "GJ_button_04.png";
96-
if (theme == enums::Dim) return "GJ_button_05.png";
96+
if (theme == enums::Dim) return "GJ_button_04.png";
9797
if (theme == enums::Girlypop) return "GJ_button_03.png";
9898
if (theme == enums::Aqua) return "geode.loader/GE_button_05.png";
9999
if (theme == enums::Geode) return "geode.loader/GE_button_05.png";

src/menu/OptionCategoryItem.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,4 @@ class OptionCategoryItem final : public CCMenu {
2424

2525
public:
2626
static OptionCategoryItem* create(CCSize const& size, std::string category);
27-
28-
ZStringView getCategory() const noexcept;
2927
};

src/menu/src/OptionCategoryItem.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ bool OptionCategoryItem::init(CCSize const& size, std::string category) {
7272
addEventListener(
7373
CategoryEvent(),
7474
[this](std::string_view category, bool enabled) {
75-
if (m_impl->toggler) if (category != m_impl->category) m_impl->toggler->toggle(false);
76-
}
75+
if (m_impl->toggler) if (category != m_impl->category) m_impl->toggler->toggle(false);
76+
}
7777
);
7878

7979
return true;
@@ -83,10 +83,6 @@ void OptionCategoryItem::onToggle(CCObject* sender) {
8383
if (m_impl->toggler) CategoryEvent().send(m_impl->category, !m_impl->toggler->isOn());
8484
};
8585

86-
ZStringView OptionCategoryItem::getCategory() const noexcept {
87-
return m_impl->category;
88-
};
89-
9086
OptionCategoryItem* OptionCategoryItem::create(CCSize const& size, std::string category) {
9187
auto ret = new OptionCategoryItem();
9288
if (ret->init(size, std::move(category))) {

src/menu/src/OptionItem.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ class OptionItem::Impl final {
2525
void saveTogglerState() {
2626
if (toggler) (void)options::set(option.id, toggler->isToggled());
2727
};
28+
29+
// Notify the user if this option is not compatible for their current platform
30+
void notifyIncompat() {
31+
if (!compatible) if (auto notif = Notification::create(fmt::format("{} is unavailable for {}", option.name, GEODE_PLATFORM_NAME), NotificationIcon::Error, 1.25f)) notif->show();
32+
};
2833
};
2934

3035
OptionItem::OptionItem() : m_impl(std::make_unique<Impl>()) {};
@@ -52,7 +57,7 @@ bool OptionItem::init(CCSize const& size, Option option) {
5257
bg->setAnchorPoint({ 0, 0 });
5358
bg->setContentSize(getScaledContentSize());
5459
bg->setScaleMultiplier(0.5f);
55-
bg->setOpacity(40);
60+
bg->setOpacity(50);
5661

5762
addChild(bg, -1);
5863

@@ -183,7 +188,6 @@ bool OptionItem::init(CCSize const& size, Option option) {
183188
nameLabel->setColor(colors::gray);
184189
categoryLabel->setColor(colors::gray);
185190

186-
// @geode-ignore(unknown-resource)
187191
auto newHelpBtnSprite = CCSprite::createWithSpriteFrameName("geode.loader/info-alert.png");
188192
newHelpBtnSprite->setScale(0.75f);
189193

@@ -208,14 +212,15 @@ void OptionItem::onToggle(CCObject*) {
208212

209213
log::info("Option {} now set to {}", m_impl->option.name, now ? "enabled" : "disabled");
210214
} else if (m_impl->toggler) {
211-
Notification::create(fmt::format("{} is unavailable for {}", m_impl->option.name, GEODE_PLATFORM_NAME), NotificationIcon::Error, 1.25f)->show();
215+
m_impl->notifyIncompat();
212216
log::error("Option {} is not available for platform {}", m_impl->option.id, GEODE_PLATFORM_SHORT_IDENTIFIER);
213217

214218
m_impl->toggler->toggle(false);
215219
};
216220
};
217221

218222
void OptionItem::onDescription(CCObject*) {
223+
m_impl->notifyIncompat();
219224
if (auto popup = FLAlertLayer::create(
220225
m_impl->option.name.c_str(),
221226
m_impl->option.description.c_str(),

src/menu/src/OptionMenu.cpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
#include <Geode/utils/terminate.hpp>
1313

14+
#include <algorithm>
15+
#include <vector>
16+
1417
using namespace geode::prelude;
1518
using namespace horrible::prelude;
1619

@@ -115,7 +118,25 @@ bool OptionMenu::init() {
115118
m_impl->categoryList->setPosition(categoryListBg->getPosition());
116119
m_impl->categoryList->m_contentLayer->setLayout(layoutCategories);
117120

118-
for (auto const& category : options::getAllCategories()) {
121+
auto cats = options::getAllCategories(); // mrrp meow
122+
std::vector<std::string> sortedCats(cats.begin(), cats.end());
123+
124+
std::sort(sortedCats.begin(), sortedCats.end(), [](auto const& a, auto const& b) {
125+
return str::toLower(a) < str::toLower(b);
126+
});
127+
128+
auto misc = std::find_if(sortedCats.begin(), sortedCats.end(), [](auto const& s) {
129+
return s == category::misc;
130+
});
131+
132+
if (misc != sortedCats.end()) {
133+
auto miscCat = *misc;
134+
135+
sortedCats.erase(misc);
136+
sortedCats.push_back(miscCat);
137+
};
138+
139+
for (auto const& category : sortedCats) {
119140
if (auto categoryItem = OptionCategoryItem::create({ m_impl->categoryList->getScaledContentWidth(), 20.f }, category)) m_impl->categoryList->m_contentLayer->addChild(categoryItem);
120141
};
121142

@@ -235,7 +256,6 @@ bool OptionMenu::init() {
235256
// get all the options data
236257
m_impl->filterOptions(options::getAll());
237258

238-
// @geode-ignore(unknown-resource)
239259
auto settingsBtnSprite = CircleButtonSprite::createWithSpriteFrameName(
240260
"geode.loader/settings.png",
241261
1.f,
@@ -325,7 +345,6 @@ bool OptionMenu::init() {
325345
}
326346
},
327347
{
328-
// @geode-ignore(unknown-resource)
329348
"geode.loader/gift.png",
330349
"support-btn",
331350
[](auto) {

src/menu/src/SettingV3.cpp

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ SettingNodeV3* HorribleSettingV3::createNode(float width) {
4242

4343
class HorribleSettingNodeV3::Impl final {
4444
public:
45-
Ref<ButtonSprite> buttonSprite = nullptr;
46-
Button* button = nullptr;
45+
CCMenuItemSpriteExtra* button = nullptr;
46+
47+
std::string theme = horribleMod->getSettingValue<std::string>("theme");
4748
};
4849

4950
HorribleSettingNodeV3::HorribleSettingNodeV3() : m_impl(std::make_unique<Impl>()) {};
@@ -52,20 +53,19 @@ HorribleSettingNodeV3::~HorribleSettingNodeV3() {};
5253
bool HorribleSettingNodeV3::init(std::shared_ptr<HorribleSettingV3> setting, float width) {
5354
if (!SettingNodeV3::init(setting, width)) return false;
5455

55-
m_impl->buttonSprite = ButtonSprite::create(
56+
auto buttonSprite = ButtonSprite::create(
5657
"Horrible Options Menu",
5758
"bigFont.fnt",
58-
"GJ_button_01.png",
59+
theme::getButtonSquareSprite(m_impl->theme),
5960
0.875f
6061
);
61-
m_impl->buttonSprite->setScale(.5f);
62+
buttonSprite->setScale(0.5f);
6263

63-
m_impl->button = Button::createWithNode(
64-
m_impl->buttonSprite,
65-
[](auto) {
66-
menu::open();
67-
}
64+
m_impl->button = CCMenuItemExt::createSpriteExtra(
65+
buttonSprite,
66+
[](auto) { menu::open(); }
6867
);
68+
m_impl->button->setID("horrible-options-btn");
6969

7070
if (auto menu = getButtonMenu()) {
7171
menu->setAnchorPoint({ 0.5, 0.5 });
@@ -78,22 +78,36 @@ bool HorribleSettingNodeV3::init(std::shared_ptr<HorribleSettingV3> setting, flo
7878
log::error("Couldn't find button menu in settings");
7979
};
8080

81+
addEventListener(
82+
SettingChangedEvent(horribleMod, "theme"),
83+
[this](std::shared_ptr<SettingV3> setting) {
84+
auto strSetting = std::static_pointer_cast<StringSettingV3>(setting);
85+
m_impl->theme = strSetting->getValue();
86+
87+
if (m_impl->button) {
88+
auto buttonSprite = ButtonSprite::create(
89+
"Horrible Options Menu",
90+
"bigFont.fnt",
91+
theme::getButtonSquareSprite(m_impl->theme),
92+
0.875f
93+
);
94+
buttonSprite->setScale(0.5f);
95+
96+
m_impl->button->setNormalImage(buttonSprite);
97+
m_impl->button->updateSprite();
98+
} else {
99+
log::error("Setting button not found");
100+
};
101+
}
102+
);
103+
81104
updateState(nullptr);
82105

83106
return true;
84107
};
85108

86109
void HorribleSettingNodeV3::updateState(CCNode* invoker) {
87110
SettingNodeV3::updateState(invoker);
88-
89-
auto shouldEnable = getSetting()->shouldEnable();
90-
91-
m_impl->button->setEnabled(shouldEnable);
92-
93-
m_impl->buttonSprite->setCascadeColorEnabled(true);
94-
m_impl->buttonSprite->setCascadeOpacityEnabled(true);
95-
m_impl->buttonSprite->setOpacity(shouldEnable ? 255 : 155);
96-
m_impl->buttonSprite->setColor(shouldEnable ? ccWHITE : ccGRAY);
97111
};
98112

99113
void HorribleSettingNodeV3::onCommit() {};

0 commit comments

Comments
 (0)