Skip to content

Commit

Permalink
fix: negative visual song id for ropbtop songs
Browse files Browse the repository at this point in the history
fixes: #15
  • Loading branch information
FlafyDev committed May 30, 2024
1 parent b273d3e commit 3d974aa
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 16 deletions.
5 changes: 2 additions & 3 deletions src/hooks/custom_song_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,8 @@ struct ANCustomSongWidget : geode::Modify<ANCustomSongWidget, CustomSongWidget>
auto anSongs = AutoNongManager::get()->getNongsFromSongID(songId);
if (!anSongs.empty()) {
// Would be better to handle m_isRobtopSong later in the code.
auto layer =
ANDropdownLayer::create(m_isRobtopSong ? -songId - 1 : songId,
AutoNongManager::get()->getNongsFromSongID(songId), this, 1, 1);
auto layer = ANDropdownLayer::create(
songId, AutoNongManager::get()->getNongsFromSongID(songId), this, 1, 1, m_isRobtopSong);
layer->m_noElasticity = true;
layer->setZOrder(106);
layer->show();
Expand Down
6 changes: 4 additions & 2 deletions src/ui/an_dropdown_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
#include "an_song_cell.hpp"

bool ANDropdownLayer::setup(int songId, std::vector<std::shared_ptr<ANSong>> songCandidates,
CustomSongWidget *parent, int popupNumber, int totalPopups) {
CustomSongWidget *parent, int popupNumber, int totalPopups,
bool isRobtopSong) {
m_songID = songId;
m_songCandidates = songCandidates;
m_parentWidget = parent;
m_popupNumber = popupNumber;
m_totalPopups = totalPopups;
m_isRobtopSong = isRobtopSong;

auto contentSize = m_mainLayer->getContentSize();

Expand All @@ -29,7 +31,7 @@ bool ANDropdownLayer::setup(int songId, std::vector<std::shared_ptr<ANSong>> son
auto songs = CCArray::create();

for (auto song : m_songCandidates) {
songs->addObject(ANSongCell::create(songId, song.get(), this, m_cellSize));
songs->addObject(ANSongCell::create(songId, song.get(), this, m_cellSize, isRobtopSong));
}

auto list = ListView::create(songs, m_cellSize.height, m_cellSize.width, 200.f);
Expand Down
11 changes: 7 additions & 4 deletions src/ui/an_dropdown_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,29 @@
#include "../types/an_song.hpp"

class ANDropdownLayer
: public Popup<int, std::vector<std::shared_ptr<ANSong>>, CustomSongWidget *, int, int> {
: public Popup<int, std::vector<std::shared_ptr<ANSong>>, CustomSongWidget *, int, int, bool> {
protected:
int m_songID;
std::vector<std::shared_ptr<ANSong>> m_songCandidates;
int m_popupNumber;
int m_totalPopups;
bool m_isRobtopSong;
ListView *m_listView = nullptr;
CCSize m_cellSize = {320.f, 60.f};

bool setup(int songId, std::vector<std::shared_ptr<ANSong>> songCandidates,
CustomSongWidget *parent, int popupNumber, int totalPopups) override;
CustomSongWidget *parent, int popupNumber, int totalPopups,
bool isRoptopSong) override;

public:
Ref<CustomSongWidget> m_parentWidget;

static ANDropdownLayer *create(int songId, std::vector<std::shared_ptr<ANSong>> songCandidates,
CustomSongWidget *parent, int popupNumber, int totalPopups) {
CustomSongWidget *parent, int popupNumber, int totalPopups,
bool isRobtopSong) {
auto ret = new ANDropdownLayer;
if (ret && ret->initAnchored(420.f, 280.f, songId, songCandidates, parent, popupNumber,
totalPopups, "GJ_square02.png")) {
totalPopups, isRobtopSong, "GJ_square02.png")) {
ret->autorelease();
return ret;
}
Expand Down
13 changes: 8 additions & 5 deletions src/ui/an_song_cell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
#include "../utils/utils.hpp"
#include "list_cell.hpp"

bool ANSongCell::init(int songId, ANSong *song, ANDropdownLayer *parentPopup, CCSize const &size) {
bool ANSongCell::init(int songId, ANSong *song, ANDropdownLayer *parentPopup, CCSize const &size,
bool isRobtopSong) {
if (!JBListCell::init(size))
return false;

m_songId = songId;
m_anSong = song;
m_parentPopup = parentPopup;
m_parentPopupUID = parentPopup->m_uID;
m_isRobtopSong = isRobtopSong;

CCMenuItemSpriteExtra *button;
CCSprite *spr;
Expand Down Expand Up @@ -131,8 +133,9 @@ void ANSongCell::setSong() {
.songUrl = "local",
};

jukebox::addNong(song, m_songId);
jukebox::setActiveSong(song, m_songId);
int jukeboxSongId = m_isRobtopSong ? -m_songId - 1 : m_songId;
jukebox::addNong(song, jukeboxSongId);
jukebox::setActiveSong(song, jukeboxSongId);
customSongWidget->m_songInfoObject->m_artistName = m_anSong->m_artist;
customSongWidget->m_songInfoObject->m_songName = m_anSong->m_name;
customSongWidget->updateSongObject(customSongWidget->m_songInfoObject);
Expand Down Expand Up @@ -325,9 +328,9 @@ void ANSongCell::onDownload(CCObject *target) {
}

ANSongCell *ANSongCell::create(int songId, ANSong *song, ANDropdownLayer *parentPopup,
CCSize const &size) {
CCSize const &size, bool isRobtopSong) {
auto ret = new ANSongCell();
if (ret && ret->init(songId, song, parentPopup, size)) {
if (ret && ret->init(songId, song, parentPopup, size, isRobtopSong)) {
return ret;
}
CC_SAFE_DELETE(ret);
Expand Down
6 changes: 4 additions & 2 deletions src/ui/an_song_cell.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ class ANSongCell : public JBListCell {
CCLayer *m_songInfoLayer;
CCMenuItemSpriteExtra *m_trashButton;
bool m_currentlyDownloading = false;
bool m_isRobtopSong = false;

bool init(int songId, ANSong *song, ANDropdownLayer *parentPopup, CCSize const &size);
bool init(int songId, ANSong *song, ANDropdownLayer *parentPopup, CCSize const &size,
bool isRobtopSong);

public:
void downloadFromYtDlp();
Expand All @@ -34,5 +36,5 @@ class ANSongCell : public JBListCell {
void onSetSong(CCObject *);
void onDownload(CCObject *);
static ANSongCell *create(int songId, ANSong *song, ANDropdownLayer *parentPopup,
CCSize const &size);
CCSize const &size, bool isRobtopSong);
};

0 comments on commit 3d974aa

Please sign in to comment.