@@ -106,6 +106,10 @@ void SongListLayer::addSongsToScrollLayer(geode::ScrollLayer* scrollLayer, SongM
106106 std::sort (cellsToAdd.begin (), cellsToAdd.end (), [reverse](MLRSongCell* a, MLRSongCell* b) {
107107 return SongListLayer::fileSize (a, b, reverse);
108108 });
109+ } else if (SAVED (" songListSortFileExtension" )) {
110+ std::sort (cellsToAdd.begin (), cellsToAdd.end (), [reverse](MLRSongCell* a, MLRSongCell* b) {
111+ return SongListLayer::fileExtn (a, b, reverse);
112+ });
109113 } else if (SAVED (" songListSortDateAdded" )) {
110114 std::sort (cellsToAdd.begin (), cellsToAdd.end (), [reverse](MLRSongCell* a, MLRSongCell* b) {
111115 return SongListLayer::dateAdded (a, b, reverse);
@@ -257,6 +261,7 @@ bool SongListLayer::setup() {
257261 Utils::addViewModeToggle (SAVED (" songListSortDateAdded" ), " dates.png" _spr, " date-added" , menu_selector (SongListLayer::onSortDateToggle), viewModeMenu, this );
258262 if (Utils::getBool (" showSortSongLength" )) Utils::addViewModeToggle (SAVED (" songListSortSongLength" ), " length.png" _spr, " song-length" , menu_selector (SongListLayer::onSortLengthToggle), viewModeMenu, this );
259263 Utils::addViewModeToggle (SAVED (" songListSortFileSize" ), " size.png" _spr, " song-size" , menu_selector (SongListLayer::onSortSizeToggle), viewModeMenu, this );
264+ Utils::addViewModeToggle (SAVED (" songListSortFileExtn" ), " xtension.png" _spr, " file-extension" , menu_selector (SongListLayer::onSortExtnToggle), viewModeMenu, this );
260265
261266 viewModeMenu->setContentHeight (viewModeMenu->getChildrenCount () * 30 .f );
262267 viewModeMenu->ignoreAnchorPointForPosition (false );
@@ -495,31 +500,29 @@ void SongListLayer::onSortSizeToggle(CCObject*) {
495500 SongListLayer::disableAllSortFiltersThenToggleThenSearch (" songListSortFileSize" );
496501}
497502
503+ void SongListLayer::onSortExtnToggle (CCObject *) {
504+ if (SONG_SORTING_DISABLED) return ;
505+ SongListLayer::disableAllSortFiltersThenToggleThenSearch (" songListSortFileExtn" );
506+ }
507+
508+ void SongListLayer::handleMutuallyExclusiveSortToggle (const std::string_view savedValueKeyToMatch, const std::string_view nodeID, const std::string_view savedValueKey, cocos2d::CCNode *viewModeMenu, const bool originalSavedValue) {
509+ geode::Mod::get ()->setSavedValue <bool >(savedValueKeyToMatch, false );
510+ if (const auto toggler = static_cast <CCMenuItemToggler*>(viewModeMenu->getChildByID (nodeID)); toggler) {
511+ toggler->toggle (false );
512+ if (savedValueKey == savedValueKeyToMatch) toggler->toggle (originalSavedValue);
513+ }
514+ }
515+
498516void SongListLayer::disableAllSortFiltersThenToggleThenSearch (const std::string_view savedValueKey) {
499517 if (SONG_SORTING_DISABLED) return ;
500518 cocos2d::CCNode* viewModeMenu = this ->m_mainLayer ->getChildByID (" view-mode-menu" _spr);
501519 if (!viewModeMenu) return ;
502520 const bool originalSavedValue = SAVED (savedValueKey);
503- geode::Mod::get ()->setSavedValue <bool >(" songListSortAlphabetically" , false );
504- geode::Mod::get ()->setSavedValue <bool >(" songListSortSongLength" , false );
505- geode::Mod::get ()->setSavedValue <bool >(" songListSortDateAdded" , false );
506- geode::Mod::get ()->setSavedValue <bool >(" songListSortFileSize" , false );
507- if (const auto toggler = static_cast <CCMenuItemToggler*>(viewModeMenu->getChildByID (" alphabetical-button" _spr)); toggler) {
508- toggler->toggle (false );
509- if (savedValueKey == " songListSortAlphabetically" ) toggler->toggle (originalSavedValue);
510- }
511- if (const auto toggler = static_cast <CCMenuItemToggler*>(viewModeMenu->getChildByID (" date-added-button" _spr)); toggler) {
512- toggler->toggle (false );
513- if (savedValueKey == " songListSortDateAdded" ) toggler->toggle (originalSavedValue);
514- }
515- if (const auto toggler = static_cast <CCMenuItemToggler*>(viewModeMenu->getChildByID (" song-length-button" _spr)); toggler) {
516- toggler->toggle (false );
517- if (savedValueKey == " songListSortSongLength" ) toggler->toggle (originalSavedValue);
518- }
519- if (const auto toggler = static_cast <CCMenuItemToggler*>(viewModeMenu->getChildByID (" song-size-button" _spr)); toggler) {
520- toggler->toggle (false );
521- if (savedValueKey == " songListSortFileSize" ) toggler->toggle (originalSavedValue);
522- }
521+ SongListLayer::handleMutuallyExclusiveSortToggle (" songListSortAlphabetically" , " alphabetical-button" _spr, savedValueKey, viewModeMenu, originalSavedValue);
522+ SongListLayer::handleMutuallyExclusiveSortToggle (" songListSortDateAdded" , " date-added-button" _spr, savedValueKey, viewModeMenu, originalSavedValue);
523+ SongListLayer::handleMutuallyExclusiveSortToggle (" songListSortSongLength" , " song-length-button" _spr, savedValueKey, viewModeMenu, originalSavedValue);
524+ SongListLayer::handleMutuallyExclusiveSortToggle (" songListSortFileSize" , " song-size-button" _spr, savedValueKey, viewModeMenu, originalSavedValue);
525+ SongListLayer::handleMutuallyExclusiveSortToggle (" songListSortFileExtn" , " file-extension-button" _spr, savedValueKey, viewModeMenu, originalSavedValue);
523526 geode::Mod::get ()->setSavedValue <bool >(savedValueKey, !originalSavedValue);
524527 CCNode* searchBar = GET_SEARCH_BAR_NODE;
525528 SongListLayer::searchSongs (!searchBar ? " " : GET_SEARCH_STRING);
@@ -581,7 +584,7 @@ void SongListLayer::displayCurrentSongByLimitingPlaceholderLabelWidth(CCTextInpu
581584 placeholderLabelMaybe->setTag (12242025 );
582585}
583586
584- bool SongListLayer::caseInsensitiveAlphabetical (MLRSongCell* a, MLRSongCell* b, const bool reverse = false ) {
587+ bool SongListLayer::caseInsensitiveAlphabetical (MLRSongCell* a, MLRSongCell* b, const bool reverse) {
585588 if (SONG_SORTING_DISABLED) return false ;
586589 const std::string& cleanedUpA = SongListLayer::generateDisplayName (a->m_songData );
587590 const std::string& cleanedUpB = SongListLayer::generateDisplayName (b->m_songData );
@@ -599,7 +602,7 @@ bool SongListLayer::caseInsensitiveAlphabetical(MLRSongCell* a, MLRSongCell* b,
599602 return false ;
600603}
601604
602- bool SongListLayer::fileSize (MLRSongCell* a, MLRSongCell* b, const bool reverse = false ) {
605+ bool SongListLayer::fileSize (MLRSongCell* a, MLRSongCell* b, const bool reverse) {
603606 if (SONG_SORTING_DISABLED) return false ;
604607 std::error_code ec;
605608 std::uintmax_t fileSizeA = std::filesystem::file_size (Utils::toProblematicString (a->m_songData .actualFilePath ), ec);
@@ -611,7 +614,25 @@ bool SongListLayer::fileSize(MLRSongCell* a, MLRSongCell* b, const bool reverse
611614 return a->m_songData .actualFilePath < b->m_songData .actualFilePath ;
612615}
613616
614- bool SongListLayer::dateAdded (MLRSongCell* a, MLRSongCell* b, const bool reverse = false ) {
617+ bool SongListLayer::fileExtn (MLRSongCell* a, MLRSongCell* b, const bool reverse) {
618+ if (SONG_SORTING_DISABLED) return false ;
619+ const std::string& cleanedUpA = a->m_songData .fileExtension ;
620+ const std::string& cleanedUpB = b->m_songData .fileExtension ;
621+ auto it1 = cleanedUpA.begin (), it2 = cleanedUpB.begin ();
622+ while (it1 != cleanedUpA.end () && it2 != cleanedUpB.end ()) {
623+ unsigned char c1 = static_cast <unsigned char >(*it1++);
624+ unsigned char c2 = static_cast <unsigned char >(*it2++);
625+ char lc1 = static_cast <char >(std::tolower (c1));
626+ char lc2 = static_cast <char >(std::tolower (c2));
627+ if (lc1 < lc2) return !reverse;
628+ if (lc1 > lc2) return reverse;
629+ }
630+ if (cleanedUpA.size () < cleanedUpB.size ()) return !reverse;
631+ if (cleanedUpA.size () > cleanedUpB.size ()) return reverse;
632+ return SongListLayer::caseInsensitiveAlphabetical (a, b, reverse);
633+ }
634+
635+ bool SongListLayer::dateAdded (MLRSongCell* a, MLRSongCell* b, const bool reverse) {
615636 if (SONG_SORTING_DISABLED) return false ;
616637 std::error_code ea, eb;
617638 auto ta = std::filesystem::last_write_time (Utils::toProblematicString (a->m_songData .actualFilePath ), ea);
@@ -625,7 +646,7 @@ bool SongListLayer::dateAdded(MLRSongCell* a, MLRSongCell* b, const bool reverse
625646 return ta < tb;
626647}
627648
628- bool SongListLayer::songLength (MLRSongCell* a, MLRSongCell* b, const bool reverse = false ) {
649+ bool SongListLayer::songLength (MLRSongCell* a, MLRSongCell* b, const bool reverse) {
629650 if (SONG_SORTING_DISABLED) return false ;
630651 const unsigned int extreme = reverse ? std::numeric_limits<unsigned int >::min () : std::numeric_limits<unsigned int >::max ();
631652 if (a->m_songData .songLength == extreme || b->m_songData .songLength == extreme) {
0 commit comments