Skip to content

Commit

Permalink
feat: Add support for main level songs
Browse files Browse the repository at this point in the history
possible because it's supported in Jukebox now
  • Loading branch information
FlafyDev committed May 29, 2024
1 parent 6a1fb12 commit 6e5f454
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 25 deletions.
8 changes: 5 additions & 3 deletions src/hooks/custom_song_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct ANCustomSongWidget : geode::Modify<ANCustomSongWidget, CustomSongWidget>
void updateSongInfo() {
CustomSongWidget::updateSongInfo();
if (!m_fields->m_showNong) {
m_fields->m_showNong = !m_isRobtopSong && GameManager::get()->m_levelEditorLayer == nullptr &&
m_fields->m_showNong = GameManager::get()->m_levelEditorLayer == nullptr &&
AutoNongManager::get()->anySongExists(getSongIds());

if (m_fields->m_showNong) {
Expand Down Expand Up @@ -80,8 +80,10 @@ struct ANCustomSongWidget : geode::Modify<ANCustomSongWidget, CustomSongWidget>
for (int songId : getSongIds()) {
auto anSongs = AutoNongManager::get()->getNongsFromSongID(songId);
if (!anSongs.empty()) {
auto layer = ANDropdownLayer::create(
songId, AutoNongManager::get()->getNongsFromSongID(songId), this, 1, 1);
// 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);
layer->m_noElasticity = true;
layer->setZOrder(106);
layer->show();
Expand Down
50 changes: 28 additions & 22 deletions src/ui/an_song_cell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,31 +109,37 @@ void ANSongCell::onDeleteSong(CCObject *target) {
}

void ANSongCell::setSong() {
// m_parentPopup's data can corrupt at this point. This is how I verify it doesn't.
if (m_parentPopup->m_uID != m_parentPopupUID) {
return;
}
try {
// m_parentPopup's data can corrupt at this point. This is how I verify it doesn't.
if (m_parentPopup->m_uID != m_parentPopupUID) {
return;
}

setButtonsVisible();
fs::path downloadPath = getFileDownloadPath(false);
const Ref<CustomSongWidget> customSongWidget = m_parentPopup->m_parentWidget;
setButtonsVisible();
fs::path downloadPath = getFileDownloadPath(false);
const Ref<CustomSongWidget> customSongWidget = m_parentPopup->m_parentWidget;

if (!fs::exists(downloadPath)) {
Notification::create("File doesn't exist", NotificationIcon::Error)->show();
return;
}
if (!fs::exists(downloadPath)) {
Notification::create("File doesn't exist", NotificationIcon::Error)->show();
return;
}

jukebox::SongInfo song = {
.path = downloadPath,
.songName = m_anSong->m_name,
.authorName = m_anSong->m_artist,
.songUrl = "local",
};
jukebox::addNong(song, m_songId);
jukebox::setActiveSong(song, m_songId);
customSongWidget->m_songInfoObject->m_artistName = m_anSong->m_artist;
customSongWidget->m_songInfoObject->m_songName = m_anSong->m_name;
customSongWidget->updateSongObject(customSongWidget->m_songInfoObject);
jukebox::SongInfo song = {
.path = downloadPath,
.songName = m_anSong->m_name,
.authorName = m_anSong->m_artist,
.songUrl = "local",
};

jukebox::addNong(song, m_songId);
jukebox::setActiveSong(song, m_songId);
customSongWidget->m_songInfoObject->m_artistName = m_anSong->m_artist;
customSongWidget->m_songInfoObject->m_songName = m_anSong->m_name;
customSongWidget->updateSongObject(customSongWidget->m_songInfoObject);
} catch (const std::exception &e) {
log::error("Failed to set song: {}", e.what());
Notification::create("Failed to set song", NotificationIcon::Error)->show();
}
}

fs::path ANSongCell::getFileDownloadPath(bool create) {
Expand Down

0 comments on commit 6e5f454

Please sign in to comment.