From c61ab025780b98c1ad18a6a18b5160833277f2d3 Mon Sep 17 00:00:00 2001 From: Alayan <25536748+Alayan-stk-2@users.noreply.github.com> Date: Thu, 8 Aug 2024 18:25:58 +0200 Subject: [PATCH] Improve the UI display of favorite tracks - 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 --- src/config/player_profile.cpp | 6 ------ src/config/player_profile.hpp | 7 +++++++ src/guiengine/skin.cpp | 7 +++++++ src/guiengine/widget.hpp | 4 +++- src/states_screens/tracks_and_gp_screen.cpp | 14 +++++++++++--- src/tracks/track.cpp | 13 ++++++++----- 6 files changed, 36 insertions(+), 15 deletions(-) diff --git a/src/config/player_profile.cpp b/src/config/player_profile.cpp index d0f4a2240c8..729450657e7 100644 --- a/src/config/player_profile.cpp +++ b/src/config/player_profile.cpp @@ -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 @@ -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 //------------------------------------------------------------------------------ diff --git a/src/config/player_profile.hpp b/src/config/player_profile.hpp index 979fb8beb24..04fcd1f76af 100644 --- a/src/config/player_profile.hpp +++ b/src/config/player_profile.hpp @@ -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(); } // ---------------------------------------------------------------------------------------- diff --git a/src/guiengine/skin.cpp b/src/guiengine/skin.cpp index bd58de8a36d..be5a7a12941 100644 --- a/src/guiengine/skin.cpp +++ b/src/guiengine/skin.cpp @@ -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 // ----------------------------------------------------------------------------- diff --git a/src/guiengine/widget.hpp b/src/guiengine/widget.hpp index 1b8ce3d8364..5f61738591f 100644 --- a/src/guiengine/widget.hpp +++ b/src/guiengine/widget.hpp @@ -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 }; diff --git a/src/states_screens/tracks_and_gp_screen.cpp b/src/states_screens/tracks_and_gp_screen.cpp index 5c283c53064..b0eca47a2f6 100644 --- a/src/states_screens/tracks_and_gp_screen.cpp +++ b/src/states_screens/tracks_and_gp_screen.cpp @@ -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 { @@ -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; @@ -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; @@ -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()); diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index 86ad0e2d7e5..63e4cef4ac0 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -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< //-----------------------------------------------------------------------------