Skip to content

Commit 6525f6d

Browse files
committed
finish ui refactor
1 parent a468ea8 commit 6525f6d

9 files changed

Lines changed: 93 additions & 54 deletions

File tree

src/ui/MenuButton.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace horrible {
3333
static MenuButton* create();
3434

3535
public:
36-
static MenuButton* get() noexcept;
36+
static MenuButton* get();
3737

3838
void setOpacity(GLubyte opacity);
3939
void setShowInLevel(bool show);

src/ui/MenuFilterCells.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ namespace horrible {
1313
CCMenuItemToggler* m_toggler = nullptr; // The toggler for the option
1414
Callback m_toggleCallback = nullptr; // Callback for when the category is toggled
1515

16+
geode::NineSlice* m_bg = nullptr;
17+
1618
protected:
1719
void onToggle(CCObject* sender);
1820

src/ui/src/Menu.cpp

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#include "../Menu.h"
22

3-
#include "../MenuCredits.h"
4-
53
#include "../MenuOption.hpp"
4+
#include "../MenuCredits.hpp"
65
#include "../MenuFilterCells.hpp"
76

87
#include <Utils.h>
@@ -117,6 +116,16 @@ class Menu::Impl final {
117116
log::error("Option list layer not found");
118117
};
119118
};
119+
120+
CCLabelBMFont* createFilterLabel(ZStringView text, std::string id, CCPoint const& pos) {
121+
auto label = CCLabelBMFont::create(text.c_str(), "bigFont.fnt");
122+
label->setID(std::move(id));
123+
label->setScale(0.375f);
124+
label->setAnchorPoint({0.5, 0.5});
125+
label->setPosition(pos);
126+
127+
return label;
128+
};
120129
};
121130

122131
Menu::Menu() : m_impl(std::make_unique<Impl>()) {};
@@ -147,8 +156,8 @@ void Menu::setupSafeModeNode(bool safeMode) {
147156
void Menu::setupImageBackground(fs::path const& path) {
148157
cue::resetNode(m_impl->themeBackground);
149158

150-
if (m_impl->themeBgContainer) {
151-
if (fs::exists(path)) {
159+
if (fs::exists(path)) {
160+
if (m_impl->themeBgContainer) {
152161
m_impl->themeBackground = LazySprite::create(m_bgSprite->getScaledContentSize(), false);
153162
m_impl->themeBackground->setID("theme-bg");
154163
m_impl->themeBackground->setPosition(m_bgSprite->getScaledContentSize() / 2.f);
@@ -157,9 +166,7 @@ void Menu::setupImageBackground(fs::path const& path) {
157166
if (auto s = self.lock()) {
158167
if (auto bg = themeBg.lock()) {
159168
if (res.isOk()) {
160-
bg->setScaleX(s->m_bgSprite->getScaledContentWidth() / bg->getScaledContentWidth());
161-
bg->setScaleY(s->m_bgSprite->getScaledContentHeight() / bg->getScaledContentHeight());
162-
169+
cue::rescaleToMatch(bg, s->m_bgSprite, true);
163170
bg.take()->setOpacity(100);
164171

165172
log::debug("Successfully loaded theme background");
@@ -217,11 +224,11 @@ bool Menu::init() {
217224
m_mainLayer->addChild(border, -1);
218225

219226
// scroll layer
220-
m_impl->categoryList = ScrollLayer::create({(mainLayerSize.width / 3.f) - 20.f, 125.f});
227+
m_impl->categoryList = ScrollLayer::create({(mainLayerSize.width / 3.f) - 20.f, 100.f});
221228
m_impl->categoryList->setID("category-list");
222229
m_impl->categoryList->setAnchorPoint({0.5, 0.5});
223230
m_impl->categoryList->ignoreAnchorPointForPosition(false);
224-
m_impl->categoryList->setPosition({mainLayerSize.width - 82.5f, (mainLayerSize.height - 57.5f) - (m_impl->categoryList->getScaledContentHeight() / 2.f)});
231+
m_impl->categoryList->setPosition({mainLayerSize.width - 82.5f, (mainLayerSize.height - 70.f) - (m_impl->categoryList->getScaledContentHeight() / 2.f)});
225232

226233
m_impl->categoryList->m_contentLayer->setLayout(ScrollLayer::createDefaultListLayout());
227234

@@ -240,7 +247,7 @@ bool Menu::init() {
240247
auto miscCat = *misc;
241248

242249
sortedCats.erase(misc);
243-
sortedCats.push_back(miscCat);
250+
sortedCats.push_back(std::move(miscCat));
244251
};
245252

246253
for (auto const& category : sortedCats) {
@@ -282,6 +289,8 @@ bool Menu::init() {
282289

283290
m_mainLayer->addChild(categoryListBg);
284291

292+
m_mainLayer->addChild(m_impl->createFilterLabel("Categories", "category-list-label", {m_impl->categoryList->getPositionX(), mainLayerSize.height - 57.5f}), 1);
293+
285294
m_impl->optionList = ScrollLayer::create({(mainLayerSize.width / 1.5f) - 43.75f, mainLayerSize.height - 93.25f});
286295
m_impl->optionList->setID("options-list");
287296
m_impl->optionList->setAnchorPoint({0.5, 0.5});
@@ -338,20 +347,21 @@ bool Menu::init() {
338347

339348
auto filterContainerLabel = CCLabelBMFont::create("Filters", "goldFont.fnt");
340349
filterContainerLabel->setID("filter-container-label");
350+
filterContainerLabel->setScale(0.375f);
341351
filterContainerLabel->setAnchorPoint({0.5, 0});
342352
filterContainerLabel->setAlignment(kCCTextAlignmentCenter);
343353
filterContainerLabel->setPosition({filterContainerBg->getPositionX(), mainLayerSize.height - 50.f});
344-
filterContainerLabel->setScale(0.375f);
345354

346355
m_mainLayer->addChild(filterContainerLabel);
347356

348-
// TODO: fix the nodes on this !!!
349357
auto sillyDropdown = cue::DropdownNode::create(
350-
to4B(categoryListBg->getColor(), categoryListBg->getOpacity()),
351-
categoryListBg->getScaledContentWidth(),
352-
15.f);
358+
to4B(colors::black, 0),
359+
m_impl->categoryList->getScaledContentWidth(),
360+
17.5f,
361+
40.f);
353362
sillyDropdown->setID("silly-filter-dropdown");
354-
sillyDropdown->setPosition({filterContainerLabel->getPositionX(), 75.f});
363+
sillyDropdown->setAnchorPoint({0.5, 1});
364+
sillyDropdown->setPosition({filterContainerLabel->getPositionX(), 87.5f});
355365

356366
sillyDropdown->setCallback([this](auto, CCNode* node) {
357367
if (auto cell = typeinfo_cast<MenuSillyFilterCell*>(node)) {
@@ -368,14 +378,30 @@ bool Menu::init() {
368378
};
369379

370380
for (auto const& filterBtn : filterBtns) {
371-
if (auto cell = MenuSillyFilterCell::create({sillyDropdown->getScaledContentWidth() * 0.75f, 15.f}, filterBtn.tier, filterBtn.id, filterBtn.label, filterBtn.color)) {
381+
if (auto cell = MenuSillyFilterCell::create(
382+
{sillyDropdown->getScaledContentWidth(), 16.5f},
383+
filterBtn.tier,
384+
filterBtn.id,
385+
filterBtn.label,
386+
filterBtn.color)) {
372387
sillyDropdown->addCell(cell);
373388
} else {
374389
log::error("Failed to create filter button");
375390
};
376391
};
377392

378-
m_mainLayer->addChild(sillyDropdown);
393+
m_mainLayer->addChild(sillyDropdown, 9);
394+
395+
m_mainLayer->addChild(m_impl->createFilterLabel("Silly Tier", "silly-filter-label", {m_impl->categoryList->getPositionX(), sillyDropdown->getPositionY() + 7.5f}), 1);
396+
397+
auto filterHint = CCLabelBMFont::create("Use different filters to search for options quicker. Press the pin icon on an option cell to pin it to the top.", "chatFont.fnt", m_impl->categoryList->getScaledContentWidth());
398+
filterHint->setID("filter-hint");
399+
filterHint->setScale(0.5f);
400+
filterHint->setAnchorPoint({0.5, 0.5});
401+
filterHint->setAlignment(kCCTextAlignmentCenter);
402+
filterHint->setPosition({filterContainerBg->getPositionX(), 47.5f});
403+
404+
m_mainLayer->addChild(filterHint, 1);
379405

380406
// get all the options data
381407
m_impl->filterOptions(options::getAll());

src/ui/src/MenuButton.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ MenuButton* MenuButton::create() {
222222
return nullptr;
223223
};
224224

225-
MenuButton* MenuButton::get() noexcept {
225+
MenuButton* MenuButton::get() {
226226
static auto inst = MenuButton::create();
227227
return inst;
228228
};

src/ui/src/MenuCredits.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "../MenuCredits.h"
1+
#include "../MenuCredits.hpp"
22

33
#include <Utils.h>
44

src/ui/src/MenuFilterCells.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@ bool MenuCategoryFilterCell::init(CCSize const& size, std::string category) {
1919
setContentSize(size);
2020
setAnchorPoint({0.5, 1});
2121

22-
auto bg = cue::createBackground(
23-
getScaledContentSize(),
22+
m_bg = cue::attachBackground(
23+
this,
2424
{
25+
.opacity = 125,
26+
.sidePadding = 0.f,
27+
.verticalPadding = 0.f,
2528
.cornerRoundness = -0.25f,
29+
.texture = themes::square,
2630
});
27-
bg->setPosition(getScaledContentSize() / 2.f);
28-
29-
addChild(bg, -1);
31+
m_bg->setColor(colors::gray);
3032

3133
auto togglerOff = CCSprite::createWithSpriteFrameName("GJ_checkOff_001.png");
3234
togglerOff->setScale(0.5f);
@@ -64,8 +66,10 @@ bool MenuCategoryFilterCell::init(CCSize const& size, std::string category) {
6466
};
6567

6668
void MenuCategoryFilterCell::onToggle(CCObject* sender) {
67-
if (m_toggler) {
68-
if (m_toggleCallback) m_toggleCallback(m_category, !m_toggler->isOn());
69+
if (auto toggler = typeinfo_cast<CCMenuItemToggler*>(sender)) {
70+
auto on = !toggler->isOn();
71+
if (m_toggleCallback) m_toggleCallback(m_category, on);
72+
if (m_bg) m_bg->setColor(on ? colors::yellow : colors::gray);
6973
};
7074
};
7175

@@ -75,6 +79,7 @@ void MenuCategoryFilterCell::setToggleCallback(Callback&& callback) {
7579

7680
void MenuCategoryFilterCell::setToggled(bool on) {
7781
if (m_toggler) m_toggler->toggle(on);
82+
if (m_bg) m_bg->setColor(on ? colors::yellow : colors::gray);
7883
};
7984

8085
ZStringView MenuCategoryFilterCell::getCategory() const noexcept {
@@ -105,8 +110,10 @@ bool MenuSillyFilterCell::init(CCSize const& size, SillyTier silly, std::string
105110
auto bg = cue::attachBackground(
106111
this,
107112
{
108-
.opacity = 125,
109-
.texture = "geode.loader/white-square.png",
113+
.opacity = 175,
114+
.sidePadding = 0.f,
115+
.verticalPadding = 0.f,
116+
.texture = themes::square,
110117
});
111118
bg->setColor(color);
112119

src/ui/src/MenuOption.cpp

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,26 @@ class MenuOption::Impl final {
104104
case SillyTier::None: return "Silly Tier - UNKNOWN";
105105
};
106106
};
107+
108+
constexpr auto getTierColor(SillyTier silly) noexcept {
109+
switch (silly) {
110+
default:
111+
return colors::white;
112+
break;
113+
114+
case SillyTier::Low:
115+
return colors::green;
116+
break;
117+
118+
case SillyTier::Medium:
119+
return colors::yellow;
120+
break;
121+
122+
case SillyTier::High:
123+
return colors::red;
124+
break;
125+
};
126+
};
107127
};
108128

109129
MenuOption::MenuOption() : m_impl(std::make_unique<Impl>()) {};
@@ -129,14 +149,16 @@ bool MenuOption::init(CCSize const& size, std::weak_ptr<Option> option, ZStringV
129149
setContentSize(size);
130150
setAnchorPoint({0.5, 1});
131151

132-
auto bg = cue::createBackground(
133-
getScaledContentSize(),
152+
auto bg = cue::attachBackground(
153+
this,
134154
{
155+
.opacity = 125,
156+
.sidePadding = 0.f,
157+
.verticalPadding = 0.f,
135158
.cornerRoundness = -0.125f,
159+
.texture = themes::square,
136160
});
137-
bg->setPosition(getScaledContentSize() / 2.f);
138-
139-
addChild(bg);
161+
bg->setColor(m_impl->getTierColor(o->getSillyTier()));
140162

141163
// Horizontal layout: [toggle] [name] [info]
142164
float yCenter = getScaledContentHeight() / 2.f;
@@ -178,25 +200,6 @@ bool MenuOption::init(CCSize const& size, std::weak_ptr<Option> option, ZStringV
178200
categoryLabel->setOpacity(200);
179201
categoryLabel->setScale(0.25f);
180202

181-
// Set color based on tier
182-
switch (o->getSillyTier()) {
183-
default: // white
184-
nameLabel->setColor(colors::white);
185-
break;
186-
187-
case SillyTier::Low: // green
188-
nameLabel->setColor(colors::green);
189-
break;
190-
191-
case SillyTier::Medium: // yellow
192-
nameLabel->setColor(colors::yellow);
193-
break;
194-
195-
case SillyTier::High: // red
196-
nameLabel->setColor(colors::red);
197-
break;
198-
};
199-
200203
addChild(nameLabel);
201204
addChild(categoryLabel);
202205

src/util/Themes.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace horrible {
2222
namespace util {
2323
// Get the current theme's sprites and colors
2424
namespace themes {
25+
inline constexpr auto square = "geode.loader/white-square.png";
2526
inline constexpr auto close = "geode.loader/close.png";
2627

2728
// Theme options

0 commit comments

Comments
 (0)