Skip to content

Commit 5c2ffaf

Browse files
committed
redo UI a bit
1 parent 8468be6 commit 5c2ffaf

File tree

3 files changed

+31
-36
lines changed

3 files changed

+31
-36
lines changed

src/Utils.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -585,26 +585,20 @@ void Utils::queueUpdateSCMLabel() {
585585
void Utils::addButton(const std::string& name, const cocos2d::SEL_MenuHandler function, cocos2d::CCMenu* menu, cocos2d::CCNode* target) {
586586
if (!menu || !target || name.empty()) return;
587587

588-
geode::CircleButtonSprite* visualSprite = geode::CircleButtonSprite::create(cocos2d::CCSprite::create(fmt::format("{}-btn-sprite.png"_spr, name).c_str()));
589-
if (name == "controls" && menu->getTag() == 7212025) {
590-
visualSprite->setScale(.5f);
591-
}
592-
593-
CCMenuItemSpriteExtra* btn = CCMenuItemSpriteExtra::create(visualSprite, target, function);
588+
CCMenuItemSpriteExtra* btn = CCMenuItemSpriteExtra::create(
589+
geode::CircleButtonSprite::create(cocos2d::CCSprite::create(fmt::format("{}-btn-sprite.png"_spr, name).c_str())),
590+
target, function
591+
);
594592
btn->setID(fmt::format("{}-button"_spr, name));
595593

596594
if (cocos2d::CCSprite* cocosSprite = btn->getChildByType<geode::CircleButtonSprite>(0)->getChildByType<cocos2d::CCSprite>(0)) {
597-
if (name == "favorite" || name == "prev") {
598-
cocosSprite->setScale(.5f);
599-
} else if (name == "controls" || name == "blacklist") {
600-
cocosSprite->setScale(.4f);
601-
} else if (name == "playlist" || name == "add") {
602-
cocosSprite->setScale(.5f);
603-
}
595+
if (name == "favorite" || name == "prev") cocosSprite->setScale(.5f);
596+
else if (name == "controls" || name == "blacklist") cocosSprite->setScale(.4f);
597+
else if (name == "playlist" || name == "add") cocosSprite->setScale(.5f);
604598
}
605599

606600
menu->addChild(btn);
607-
menu->updateLayout();
601+
if (menu->getLayout()) menu->updateLayout();
608602
}
609603

610604
bool Utils::notFavoritesNorBlacklist(std::filesystem::path filePath) {

src/ui/SongControlMenu.cpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
#include <Geode/ui/GeodeUI.hpp>
66

77
#define REST_OF_THE_OWL this->m_songControlsMenu, this
8-
#define REST_OF_THE_CAT this->m_theTimeoutCorner, this
9-
#define REST_OF_THE_DOG this->m_buttonMenu, this
108

119
bool SongControlMenu::setup(const std::string&) {
1210
this->setTitle("Menu Loop Randomizer - Control Panel");
@@ -44,23 +42,24 @@ bool SongControlMenu::setup(const std::string&) {
4442
this->m_songControlsMenu->setContentSize({idealWidth, 32.f});
4543
this->m_songControlsMenu->setLayout(layout);
4644

47-
this->m_buttonMenu->setTag(7212025);
4845
this->m_theTimeoutCorner = cocos2d::CCMenu::create();
46+
Utils::addButton("controls", menu_selector(SongControlMenu::onSettingsButton), this->m_theTimeoutCorner, this);
47+
geode::AxisLayout* layoutTimeout = geode::ColumnLayout::create()->setGap(0.f)->setDefaultScaleLimits(.0001f, 1.0f)->setAutoScale(true);
4948

50-
Utils::addButton("playlist", menu_selector(SongControlMenu::onPlaylistButton), REST_OF_THE_CAT);
51-
Utils::addButton("controls", menu_selector(SongControlMenu::onSettingsButton), REST_OF_THE_DOG);
49+
this->m_openSongListMenu = cocos2d::CCMenu::create();
50+
Utils::addButton("playlist", menu_selector(SongControlMenu::onPlaylistButton), this->m_openSongListMenu, this);
51+
geode::AxisLayout* layoutSongList = geode::RowLayout::create()->setGap(0.f)->setDefaultScaleLimits(.0001f, 1.0f)->setAutoScale(true);
5252

53-
geode::AxisLayout* layoutTimeout = geode::ColumnLayout::create()->setGap(0.f)->setDefaultScaleLimits(.0001f, .65f)->setAutoScale(true);
54-
55-
if (CCNode* controlsButton = this->m_buttonMenu->getChildByID("controls-button"_spr)) {
56-
controlsButton->setPosition({m_mainLayer->getContentSize() - 3.f});
57-
}
58-
59-
this->m_theTimeoutCorner->setPosition({280.f, this->m_title->getPositionY() - 8.5f});
53+
this->m_theTimeoutCorner->setPosition({280.f, this->m_title->getPositionY() - 2.5f});
6054
this->m_theTimeoutCorner->ignoreAnchorPointForPosition(false);
61-
this->m_theTimeoutCorner->setContentSize({24.f, 36.f});
55+
this->m_theTimeoutCorner->setContentSize({24.f, 24.f});
6256
this->m_theTimeoutCorner->setLayout(layoutTimeout);
6357

58+
this->m_openSongListMenu->setPosition({280.f, this->m_title->getPositionY() - 51.5f});
59+
this->m_openSongListMenu->ignoreAnchorPointForPosition(false);
60+
this->m_openSongListMenu->setContentSize({27.f, 27.f});
61+
this->m_openSongListMenu->setLayout(layoutSongList);
62+
6463
this->m_otherLabel = cocos2d::CCLabelBMFont::create("Hi! Menu Loop Randomizer will never resemble Spotify or its distant cousin EditorMusic. Please respect that. :)", "chatFont.fnt");
6564
this->m_otherLabel->setBlendFunc({GL_ONE_MINUS_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA});
6665
this->m_otherLabel->limitLabelWidth(idealWidth * .95f, 1.0f, .0001f);
@@ -70,21 +69,22 @@ bool SongControlMenu::setup(const std::string&) {
7069
this->m_headerLabl->setBlendFunc({GL_ONE_MINUS_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA});
7170
this->m_headerLabl->setPosition({centerStage, 107.5f});
7271

73-
SongControlMenu::updateCurrentLabel();
74-
7572
this->b = cocos2d::extension::CCScale9Sprite::create("square02b_001.png");
7673
this->b->ignoreAnchorPointForPosition(false);
77-
this->b->setPosition({centerStage, 80.f});
78-
this->b->setContentSize({275.f, 30.f});
74+
this->b->setContentSize({250.f, 30.f});
75+
this->b->setAnchorPoint({0.f, .5f});
76+
this->b->setPosition({12.5f, 80.f});
7977
this->b->setColor({0, 0, 0});
8078
this->b->setOpacity(128);
8179

80+
SongControlMenu::updateCurrentLabel();
81+
8282
this->setID("SongControlMenu"_spr);
8383
mainLayer->addChild(this->b);
8484
mainLayer->addChild(this->m_otherLabel);
85-
mainLayer->addChild(this->m_smallLabel);
8685
mainLayer->addChild(this->m_headerLabl);
8786
mainLayer->addChild(this->m_songControlsMenu);
87+
mainLayer->addChild(this->m_openSongListMenu);
8888
mainLayer->addChild(this->m_theTimeoutCorner);
8989

9090
this->b->setID("trans-bg"_spr);
@@ -95,6 +95,7 @@ bool SongControlMenu::setup(const std::string&) {
9595
this->m_smallLabel->setID("current-song-label"_spr);
9696
this->m_headerLabl->setID("current-song-header"_spr);
9797
this->m_theTimeoutCorner->setID("timeout-corner"_spr);
98+
this->m_openSongListMenu->setID("song-list-menu"_spr);
9899
this->m_songControlsMenu->setID("song-controls-menu"_spr);
99100

100101
return true;
@@ -157,13 +158,12 @@ void SongControlMenu::onSettingsButton(CCObject*) {
157158
void SongControlMenu::updateCurrentLabel() {
158159
SongManager& songManager = SongManager::get();
159160
const std::string& currentSong = songManager.getCurrentSongDisplayName();
160-
const cocos2d::CCSize layerSize = this->m_mainLayer->getContentSize();
161-
if (!this->m_smallLabel || !this->m_smallLabel->getParent() || this->m_smallLabel->getParent() != this->m_mainLayer) {
161+
if (!this->m_smallLabel || !this->m_smallLabel->getParent() || this->m_smallLabel->getParent() != this->b) {
162162
this->m_smallLabel = cocos2d::CCLabelBMFont::create(currentSong.c_str(), "chatFont.fnt");
163+
this->b->addChildAtPosition(this->m_smallLabel, geode::Anchor::Center);
163164
} else this->m_smallLabel->setString(currentSong.c_str(), "chatFont.fnt");
165+
this->m_smallLabel->limitLabelWidth(this->b->getContentWidth() - 20.f, 1.0f, .0001f);
164166
this->m_smallLabel->setBlendFunc({GL_ONE_MINUS_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA});
165-
this->m_smallLabel->limitLabelWidth(layerSize.width * 0.95f * .9f, 1.0f, .0001f);
166-
this->m_smallLabel->setPosition({layerSize.width / 2.f, 80.f});
167167
if (!this->m_headerLabl) return;
168168
if (songManager.isOverride()) this->m_headerLabl->setString("Current Song (Custom Override):");
169169
else if (songManager.getConstantShuffleMode()) this->m_headerLabl->setString("Current Song (Constant Shuffle Mode):");

src/ui/SongControlMenu.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class SongControlMenu final : public geode::Popup<const std::string&> {
77
cocos2d::CCLabelBMFont* m_headerLabl{};
88
cocos2d::CCMenu* m_songControlsMenu {};
99
cocos2d::CCMenu* m_theTimeoutCorner {};
10+
cocos2d::CCMenu* m_openSongListMenu {};
1011
cocos2d::extension::CCScale9Sprite*b{};
1112
bool setup(std::string const& id) override;
1213
void onShuffleButton(CCObject*);

0 commit comments

Comments
 (0)