Skip to content

Commit d4ec4d7

Browse files
committed
use layouts in optionmenu
1 parent 24fefc6 commit d4ec4d7

7 files changed

Lines changed: 100 additions & 125 deletions

File tree

mod.json

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -308,23 +308,6 @@
308308
"big-arrow-step": 20
309309
}
310310
},
311-
"upside_down-chance": {
312-
"type": "int",
313-
"name": "Upside-Down Scene Chance",
314-
"description": "<cj>Upside-Down Chance</c> - Chance of your game's UI turning upside down.",
315-
"default": 50,
316-
"min": 0,
317-
"max": 100,
318-
"control": {
319-
"input": true,
320-
"slider": true,
321-
"slider-step": 1,
322-
"arrows": true,
323-
"arrow-step": 10,
324-
"big-arrows": true,
325-
"big-arrow-step": 20
326-
}
327-
},
328311
"pauses-chance": {
329312
"type": "int",
330313
"name": "Pause Chance",

src/hooks/PlayLayer/UpsideDown.cpp

Lines changed: 0 additions & 41 deletions
This file was deleted.

src/include/Horrible.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ void horrible::delegateHooks(ZStringView id, utils::StringMap<std::shared_ptr<Ho
9292
allHooks.push_back(hook.get());
9393
};
9494

95-
log::debug("Delegating {} hooks for {}", allHooks.size(), id);
96-
9795
om->addDelegate(
9896
id,
9997
[allHooks = std::move(allHooks)](bool value) {

src/menu/OptionItem.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ class OptionItem final : public CCMenu {
2424
public:
2525
static OptionItem* create(CCSize const& size, Option option);
2626

27-
Option getOption() const noexcept;
27+
Option const& getOption() const noexcept;
2828
bool isCompatible() const noexcept;
2929
};

src/menu/OptionMenu.hpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,21 @@ class OptionMenu final : public Popup {
1414
class Impl;
1515
std::unique_ptr<Impl> m_impl;
1616

17-
struct SillyFilter final {
17+
struct SillyFilterBtnData final {
1818
SillyTier tier;
1919
const char* label;
20+
const char* id;
2021
ccColor3B color;
2122
};
2223

24+
using Callback = void(*)(CCMenuItem*);
25+
26+
struct SocialBtnData final {
27+
const char* sprite;
28+
const char* id;
29+
Callback callback;
30+
};
31+
2332
protected:
2433
static OptionMenu* s_inst;
2534

src/menu/src/OptionItem.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ bool OptionItem::init(CCSize const& size, Option option) {
183183
nameLabel->setColor(colors::gray);
184184
categoryLabel->setColor(colors::gray);
185185

186+
// @geode-ignore(unknown-resource)
186187
auto newHelpBtnSprite = CCSprite::createWithSpriteFrameName("geode.loader/info-alert.png");
187188
newHelpBtnSprite->setScale(0.75f);
188189

@@ -222,7 +223,7 @@ void OptionItem::onDescription(CCObject*) {
222223
)) popup->show();
223224
};
224225

225-
Option OptionItem::getOption() const noexcept {
226+
Option const& OptionItem::getOption() const noexcept {
226227
return m_impl->option;
227228
};
228229

src/menu/src/OptionMenu.cpp

Lines changed: 87 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -178,19 +178,26 @@ bool OptionMenu::init() {
178178

179179
m_mainLayer->addChild(filtersLabel);
180180

181+
auto filterMenuLayout = ColumnLayout::create()
182+
->setGap(2.5f)
183+
->setAxisReverse(true) // Top to bottom
184+
->setAxisAlignment(AxisAlignment::End)
185+
->setAutoGrowAxis(0.f);
186+
181187
// filter buttons :o
182188
auto filterMenu = CCMenu::create();
183189
filterMenu->setID("filter-menu");
184190
filterMenu->setAnchorPoint({ 0.5, 1 });
185-
filterMenu->setPosition({ filterMenuBg->getPositionX(), mainLayerSize.height - 65.f });
186-
187-
constexpr SillyFilter filterBtns[] = {
188-
{ SillyTier::Low, "Low", colors::green },
189-
{ SillyTier::Medium, "Medium", colors::yellow },
190-
{ SillyTier::High, "High", colors::red },
191+
filterMenu->setPosition({ filterMenuBg->getPositionX(), mainLayerSize.height - 55.f });
192+
filterMenu->setContentHeight(0.f);
193+
filterMenu->setLayout(filterMenuLayout);
194+
195+
constexpr SillyFilterBtnData filterBtns[] = {
196+
{ SillyTier::Low, "Low", "filter-low-btn", colors::green },
197+
{ SillyTier::Medium, "Medium", "filter-medium-btn", colors::yellow },
198+
{ SillyTier::High, "High", "filter-high-btn", colors::red },
191199
};
192200

193-
auto fBtnY = 0.f;
194201
for (auto const& filterBtn : filterBtns) {
195202
if (auto btnSprite = ButtonSprite::create(filterBtn.label, 150, true, "bigFont.fnt", "GJ_button_01.png", 0.f, 0.8f)) {
196203
btnSprite->m_label->setColor(filterBtn.color);
@@ -205,11 +212,9 @@ bool OptionMenu::init() {
205212
m_impl->filterOptions(options::getAll(), m_impl->selectedTier, m_impl->selectedCategory);
206213
}
207214
)) {
208-
btn->setPosition({ 0.f, fBtnY });
215+
btn->setID(filterBtn.id);
209216

210217
filterMenu->addChild(btn);
211-
212-
fBtnY -= 35.f;
213218
} else {
214219
log::error("Failed to create filter button");
215220
};
@@ -218,11 +223,13 @@ bool OptionMenu::init() {
218223
};
219224
};
220225

221-
// get the options data
222-
m_impl->filterOptions(options::getAll());
226+
filterMenu->updateLayout();
223227

224228
m_mainLayer->addChild(filterMenu);
225229

230+
// get the options data
231+
m_impl->filterOptions(options::getAll());
232+
226233
// add a mod settings at the bottom left
227234
// @geode-ignore(unknown-resource)
228235
auto settingsBtnSprite = CircleButtonSprite::createWithSpriteFrameName("geode.loader/settings.png");
@@ -262,62 +269,80 @@ bool OptionMenu::init() {
262269

263270
m_buttonMenu->addChild(resetFiltersBtn);
264271

265-
auto seriesBtnSprite = CCSprite::createWithSpriteFrameName("gj_ytIcon_001.png");
266-
seriesBtnSprite->setScale(0.75f);
267-
268-
auto seriesBtn = CCMenuItemExt::createSpriteExtra(
269-
seriesBtnSprite,
270-
[](auto) {
271-
createQuickPopup(
272-
"Horrible Mods",
273-
"Watch the series '<cr>Horrible Mods</c>' on <cl>Avalanche</c>'s YouTube channel?",
274-
"Cancel", "OK",
275-
[](bool, bool ok) {
276-
if (ok) web::openLinkInBrowser("https://www.youtube.com/watch?v=Ssl49pNmW_0&list=PL0dsSu2pR5cERnq7gojZTKVRvUwWo2Ohu");
277-
}
278-
);
272+
auto socialMenuLayout = RowLayout::create()
273+
->setGap(1.25f)
274+
->setAxisReverse(true)
275+
->setAxisAlignment(AxisAlignment::End)
276+
->setAutoGrowAxis(0.f);
277+
278+
auto socialMenu = CCMenu::create();
279+
socialMenu->setID("social-menu");
280+
socialMenu->setAnchorPoint({ 1, 0.5 });
281+
socialMenu->setPosition({ mainLayerSize.width - 7.5f, mainLayerSize.height - 20.f });
282+
socialMenu->setContentWidth(0.f);
283+
socialMenu->setLayout(socialMenuLayout);
284+
285+
constexpr SocialBtnData socialBtns[] = {
286+
{
287+
"gj_ytIcon_001.png",
288+
"horrible-mods-series-btn",
289+
[](auto) {
290+
createQuickPopup(
291+
"Horrible Mods",
292+
"Watch the series '<cr>Horrible Mods</c>' on <cl>Avalanche</c>'s YouTube channel?",
293+
"Cancel", "OK",
294+
[](bool, bool ok) {
295+
if (ok) web::openLinkInBrowser("https://www.youtube.com/watch?v=Ssl49pNmW_0&list=PL0dsSu2pR5cERnq7gojZTKVRvUwWo2Ohu");
296+
}
297+
);
298+
}
299+
},
300+
{
301+
"gj_discordIcon_001.png",
302+
"discord-btn",
303+
[](auto) {
304+
createQuickPopup(
305+
"Discord",
306+
"Join the <cj>Cubic Studios</c> Discord community server?",
307+
"Cancel", "OK",
308+
[](bool, bool ok) {
309+
if (ok) web::openLinkInBrowser("https://www.dsc.gg/cubic");
310+
}
311+
);
312+
}
313+
},
314+
{
315+
// @geode-ignore(unknown-resource)
316+
"geode.loader/gift.png",
317+
"support-btn",
318+
[](auto) {
319+
openSupportPopup(horribleMod);
320+
}
279321
}
280-
);
281-
seriesBtn->setID("horrible-mods-series-btn");
282-
seriesBtn->setPosition(mainLayerSize - 20.f);
283-
284-
m_buttonMenu->addChild(seriesBtn);
285-
286-
auto discordBtnSprite = CCSprite::createWithSpriteFrameName("gj_discordIcon_001.png");
287-
discordBtnSprite->setScale(0.75f);
322+
};
288323

289-
auto discordBtn = CCMenuItemExt::createSpriteExtra(
290-
discordBtnSprite,
291-
[](auto) {
292-
createQuickPopup(
293-
"Discord",
294-
"Join the <cj>Cubic Studios</c> official Discord community server?",
295-
"Cancel", "OK",
296-
[](bool, bool ok) {
297-
if (ok) web::openLinkInBrowser("https://www.dsc.gg/cubic");
298-
}
299-
);
300-
}
301-
);
302-
discordBtn->setID("discord-btn");
303-
discordBtn->setPosition({ mainLayerSize.width - 45.f, mainLayerSize.height - 20.f });
324+
for (auto const& socialBtn : socialBtns) {
325+
if (auto sprite = CCSprite::createWithSpriteFrameName(socialBtn.sprite)) {
326+
sprite->setScale(0.75f);
304327

305-
m_buttonMenu->addChild(discordBtn);
328+
if (auto btn = CCMenuItemExt::createSpriteExtra(
329+
sprite,
330+
socialBtn.callback
331+
)) {
332+
btn->setID(socialBtn.id);
306333

307-
// @geode-ignore(unknown-resource)
308-
auto supporterBtnSprite = CCSprite::createWithSpriteFrameName("geode.loader/gift.png");
309-
supporterBtnSprite->setScale(0.75f);
334+
socialMenu->addChild(btn);
335+
} else {
336+
log::error("Failed to create social button");
337+
};
338+
} else {
339+
log::error("Failed to create social button sprite");
340+
};
341+
};
310342

311-
auto supporterBtn = CCMenuItemExt::createSpriteExtra(
312-
supporterBtnSprite,
313-
[](auto) {
314-
openSupportPopup(horribleMod);
315-
}
316-
);
317-
supporterBtn->setID("support-btn");
318-
supporterBtn->setPosition({ mainLayerSize.width - 70.f, mainLayerSize.height - 20.f });
343+
socialMenu->updateLayout();
319344

320-
m_buttonMenu->addChild(supporterBtn);
345+
m_mainLayer->addChild(socialMenu);
321346

322347
auto safeModeLabel = CCLabelBMFont::create("Safe Mode OFF", "bigFont.fnt");
323348
safeModeLabel->setID("safe-mode-label");

0 commit comments

Comments
 (0)