Skip to content

Commit

Permalink
add ability to favorite charts, sort by favorites coming soon
Browse files Browse the repository at this point in the history
  • Loading branch information
MinaciousGrace committed Dec 9, 2016
1 parent 807f14c commit 7f6f053
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/MusicWheelItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,8 @@ void MusicWheelItem::RefreshGrades()
msg.SetParam( "PlayerNumber", p );
if( BestpHSL )
{
if(pWID->m_pSong->IsFavorited())
msg.SetParam( "Favorited", 1);
msg.SetParam( "Grade", BestpHSL->HighGrade);
msg.SetParam( "Difficulty", DifficultyToString(dcBest));
msg.SetParam( "NumTimesPlayed", BestpHSL->GetNumTimesPlayed() );
Expand Down
24 changes: 24 additions & 0 deletions src/Profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1509,6 +1509,12 @@ XNode* Profile::SaveGeneralDataCreateNode() const
pDefaultModifiers->AppendChild( it->first, it->second );
}

{
XNode* Favorites = pGeneralDataNode->AppendChild("Favorites");
FOREACH_CONST(RString, FavoritedCharts, it)
Favorites->AppendChild(*it);
}

{
XNode* pUnlocks = pGeneralDataNode->AppendChild("Unlocks");
FOREACHS_CONST( RString, m_UnlockedEntryIDs, it )
Expand Down Expand Up @@ -1703,6 +1709,15 @@ void Profile::LoadGeneralDataFromNode( const XNode* pNode )
}
}

{
const XNode* Favorites = pNode->GetChild("Favorites");
if (Favorites) {
FOREACH_CONST_Child(Favorites, ck)
FavoritedCharts.push_back(ck->GetName());
SONGMAN->SetFavoritedStatus(FavoritedCharts);
}
}

{
const XNode* pUnlocks = pNode->GetChild("Unlocks");
if( pUnlocks )
Expand Down Expand Up @@ -1950,6 +1965,15 @@ XNode* Profile::SaveSongScoresCreateNode() const
return pNode;
}

void Profile::RemoveFromFavorites(RString ck) {
LOG->Trace("b4 %i", FavoritedCharts.size());
for (size_t i = 0; i < FavoritedCharts.size(); ++i) {
if (FavoritedCharts[i] == ck)
FavoritedCharts.erase(FavoritedCharts.begin() + i);
}
LOG->Trace("afta %i", FavoritedCharts.size());
}

void Profile::LoadSongScoresFromNode( const XNode* pSongScores )
{
CHECKPOINT_M("Loading the node that contains song scores.");
Expand Down
5 changes: 5 additions & 0 deletions src/Profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,11 @@ class Profile
int m_iNumStagesPassedByPlayMode[NUM_PlayMode];
int m_iNumStagesPassedByGrade[NUM_Grade];

void AddToFavorites(RString ck) { FavoritedCharts.push_back(ck); }
void RemoveFromFavorites(RString ck);
// Vector for now, we can make this more efficient later
vector<RString> FavoritedCharts;

/* store arbitrary data for the theme within a profile */
LuaTable m_UserTable;

Expand Down
27 changes: 27 additions & 0 deletions src/ScreenSelectMusic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,32 @@ bool ScreenSelectMusic::Input( const InputEventPlus &input )
return true;
}
}
else if (bHoldingCtrl && c == 'F' && m_MusicWheel.IsSettled())
{
// Unfavorite the currently selected song. -Not Kyz
Song* unfav_me_biatch = m_MusicWheel.GetSelectedSong();
if (unfav_me_biatch) {
Profile *pProfile = PROFILEMAN->GetProfile(PLAYER_1);
if (unfav_me_biatch) {
Profile *pProfile = PROFILEMAN->GetProfile(PLAYER_1);
unfav_me_biatch->SetFavorited(false);
pProfile->RemoveFromFavorites(GAMESTATE->m_pCurSteps[PLAYER_1]->GetChartKey());
return true;
}
}
}
else if (c == 'F' && m_MusicWheel.IsSettled())
{
// Favorite the currently selected song. -Not Kyz
Song* fav_me_biatch = m_MusicWheel.GetSelectedSong();
if (fav_me_biatch) {
Profile *pProfile = PROFILEMAN->GetProfile(PLAYER_1);
fav_me_biatch->SetFavorited(true);
pProfile->AddToFavorites(GAMESTATE->m_pCurSteps[PLAYER_1]->GetChartKey());
return true;
}
}
#if 0 // This is really more annoying than useful as well as obsoleted by song search
else if( bHoldingCtrl && ( c >= 'A' ) && ( c <= 'Z' ) )
{
// Only allow changing the sort order if the wheel is not locked
Expand All @@ -493,6 +519,7 @@ bool ScreenSelectMusic::Input( const InputEventPlus &input )
return true;
}
}
#endif // 0
else if( input.DeviceI.device == DEVICE_KEYBOARD && bHoldingCtrl && input.DeviceI.button == KEY_BACK && input.type == IET_FIRST_PRESS
&& m_MusicWheel.IsSettled() )
{
Expand Down
4 changes: 3 additions & 1 deletion src/Song.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2198,6 +2198,7 @@ class LunaSong: public Luna<Song>
}
return 1;
}
static int IsFavorited(T* p, lua_State *L) { lua_pushboolean(L, p->IsFavorited()); return 1; }
// has functions
static int HasMusic( T* p, lua_State *L ) { lua_pushboolean(L, p->HasMusic()); return 1; }
static int HasBanner( T* p, lua_State *L ) { lua_pushboolean(L, p->HasBanner()); return 1; }
Expand Down Expand Up @@ -2309,7 +2310,7 @@ class LunaSong: public Luna<Song>
ADD_METHOD( GetDisplayFullTitle );
ADD_METHOD( GetTranslitFullTitle );
ADD_METHOD( GetDisplayMainTitle );
ADD_METHOD(GetMainTitle);
ADD_METHOD( GetMainTitle );
ADD_METHOD( GetTranslitMainTitle );
ADD_METHOD( GetDisplaySubTitle );
ADD_METHOD( GetTranslitSubTitle );
Expand Down Expand Up @@ -2354,6 +2355,7 @@ class LunaSong: public Luna<Song>
ADD_METHOD( HasSignificantBPMChangesOrStops );
ADD_METHOD( HasEdits );
ADD_METHOD( IsEasy );
ADD_METHOD( IsFavorited );
ADD_METHOD( GetStepsSeconds );
ADD_METHOD( NormallyDisplayed );
ADD_METHOD( GetFirstBeat );
Expand Down
4 changes: 4 additions & 0 deletions src/Song.h
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,9 @@ class Song
bool IsTutorial() const;
bool HasEdits( StepsType st ) const;

bool IsFavorited() { return isfavorited; }
void SetFavorited(bool b) { isfavorited = b; }

void SetEnabled( bool b ) { m_bEnabled = b; }
bool GetEnabled() const { return m_bEnabled; }
/**
Expand Down Expand Up @@ -458,6 +461,7 @@ class Song
void PushSelf( lua_State *L );

private:
bool isfavorited = false;
bool m_loaded_from_autosave;
/** @brief the Steps that belong to this Song. */
vector<Steps*> m_vpSteps;
Expand Down
12 changes: 12 additions & 0 deletions src/SongManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,18 @@ bool SongManager::IsGroupNeverCached(const RString& group) const
return m_GroupsToNeverCache.find(group) != m_GroupsToNeverCache.end();
}

void SongManager::SetFavoritedStatus(vector<RString>& favs) {
FOREACH(Song*, m_pSongs, song) {
FOREACH_CONST(Steps*, (*song)->GetAllSteps(), steps) {
RString sck = (*steps)->GetChartKey();
FOREACH(RString, favs, ck) {
if (sck == *ck)
(*song)->SetFavorited(true);
}
}
}
}

RString SongManager::GetSongGroupBannerPath( const RString &sSongGroup ) const
{
for( unsigned i = 0; i < m_sSongGroupNames.size(); ++i )
Expand Down
1 change: 1 addition & 0 deletions src/SongManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class SongManager
void PreloadSongImages();

bool IsGroupNeverCached(const RString& group) const;
void SetFavoritedStatus(vector<RString>& favs);

RString GetSongGroupBannerPath( const RString &sSongGroup ) const;
//RString GetSongGroupBackgroundPath( RString sSongGroup ) const;
Expand Down

0 comments on commit 7f6f053

Please sign in to comment.