Skip to content

Commit

Permalink
Improve the UI display of favorite tracks
Browse files Browse the repository at this point in the history
- Immediately refresh the display of tracks inside group after favoriting or unfavoriting a track
- Sort tracks according to favorite status, displaying favorite tracks first
- Add heart as a badge overlay option, and use it to mark favorite tracks
- Remove debug prints
  • Loading branch information
Alayan-stk-2 committed Aug 8, 2024
1 parent ca80a1c commit c61ab02
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 15 deletions.
6 changes: 0 additions & 6 deletions src/config/player_profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ void PlayerProfile::setFavoriteTracks()
void PlayerProfile::addFavoriteTrack(std::string ident)
{
m_favorite_tracks.push_back(ident);
printf("Ident %s added to favorite tracks.\n", ident.c_str());
track_manager->addFavoriteTrack(ident);
} // addFavoriteTrack

Expand All @@ -195,13 +194,8 @@ void PlayerProfile::removeFavoriteTrack(std::string ident)
if (it != m_favorite_tracks.end()) // the track to remove has been found
{
m_favorite_tracks.erase(it);
printf("Ident %s removed from favorite tracks.\n", ident.c_str());
setFavoriteTracks();
}
else
{
printf("Favorite track to remove not found.\n");
}
} // removeFavoriteTrack

//------------------------------------------------------------------------------
Expand Down
7 changes: 7 additions & 0 deletions src/config/player_profile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,13 @@ class PlayerProfile : public NoCopy
return m_story_mode_status->isLocked(feature);
} // isLocked
// ----------------------------------------------------------------------------------------
/** Returnes if the track is favorite. */
bool isFavoriteTrack(const std::string &ident) const
{
return std::find(m_favorite_tracks.begin(), m_favorite_tracks.end(), ident)
!= m_favorite_tracks.end();
} // isFavoriteTrack
// ----------------------------------------------------------------------------------------
/** Returns all active challenges. */
void computeActive() { m_story_mode_status->computeActive(); }
// ----------------------------------------------------------------------------------------
Expand Down
7 changes: 7 additions & 0 deletions src/guiengine/skin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2577,6 +2577,13 @@ void Skin::drawBadgeOn(const Widget* widget, const core::recti& rect)
"down.png");
doDrawBadge(texture, rect, max_icon_size, false);
}
if (widget->m_badges & HEART_BADGE)
{
float max_icon_size = 0.43f;
video::ITexture* texture = irr_driver->getTexture(FileManager::GUI_ICON,
"heart.png");
doDrawBadge(texture, rect, max_icon_size, false);
}
} // drawBadgeOn

// -----------------------------------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion src/guiengine/widget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ namespace GUIEngine
/** A anchor badge to indicate that this player receives a handicap */
ANCHOR_BADGE = 256,
/** A down arrow badge to indicate new addons for downloading */
DOWN_BADGE = 512
DOWN_BADGE = 512,
/** A heart badge, to indicate e.g. a favorite track */
HEART_BADGE = 1024
};


Expand Down
14 changes: 11 additions & 3 deletions src/states_screens/tracks_and_gp_screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ void TracksAndGPScreen::eventCallback(Widget* widget, const std::string& name,
PlayerManager::getCurrentPlayer()->removeFavoriteTrack(track->getIdent());
else
PlayerManager::getCurrentPlayer()->addFavoriteTrack(track->getIdent());

buildTrackList();
}
else // Normal mode
{
Expand Down Expand Up @@ -291,6 +293,7 @@ void TracksAndGPScreen::buildTrackList()
for (int n = 0; n < track_amount; n++)
{
Track* curr = track_manager->getTrack(n);
if (curr->isArena() || curr->isSoccer() || curr->isInternal()) continue;
if (RaceManager::get()->getMinorMode() == RaceManager::MINOR_MODE_EASTER_EGG
&& !curr->hasEasterEggs())
continue;
Expand All @@ -299,7 +302,6 @@ void TracksAndGPScreen::buildTrackList()
if (!search_text.empty() &&
curr->getName().make_lower().find(search_text.c_str()) == -1)
continue;
if (curr->isArena() || curr->isSoccer()||curr->isInternal()) continue;
if (curr_group_name != ALL_TRACK_GROUPS_ID &&
!curr->isInGroup(curr_group_name)) continue;

Expand All @@ -318,10 +320,16 @@ void TracksAndGPScreen::buildTrackList()
"locked", curr->getScreenshotFile(), LOCKED_BADGE,
IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE);
}
else if (curr->isInGroup("Favorites"))
{
tracks_widget->addItem(curr->getName(), curr->getIdent(),
curr->getScreenshotFile(), HEART_BADGE,
IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE);
m_random_track_list.push_back(curr->getIdent());
}
else
{
tracks_widget->addItem(curr->getName(),
curr->getIdent(),
tracks_widget->addItem(curr->getName(), curr->getIdent(),
curr->getScreenshotFile(), 0,
IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE);
m_random_track_list.push_back(curr->getIdent());
Expand Down
13 changes: 8 additions & 5 deletions src/tracks/track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,15 @@ bool Track::operator<(const Track &other) const
PlayerProfile *p = PlayerManager::getCurrentPlayer();
bool this_is_locked = p->isLocked(getIdent());
bool other_is_locked = p->isLocked(other.getIdent());
if(this_is_locked == other_is_locked)
{
return getSortName() < other.getSortName();
}
else
bool this_is_favorite = p->isFavoriteTrack(getIdent());
bool other_is_favorite = p->isFavoriteTrack(other.getIdent());
// Locked tracks cannot be favorite, so favorites < normal < locked
if (this_is_favorite != other_is_favorite)
return this_is_favorite;
else if(this_is_locked != other_is_locked)
return other_is_locked;
else
return getSortName() < other.getSortName();
} // operator<

//-----------------------------------------------------------------------------
Expand Down

0 comments on commit c61ab02

Please sign in to comment.