diff --git a/data/gui/screens/arenas.stkgui b/data/gui/screens/arenas.stkgui
index 9746e93081..6c71e81cf7 100644
--- a/data/gui/screens/arenas.stkgui
+++ b/data/gui/screens/arenas.stkgui
@@ -3,9 +3,16 @@
-
-
+
+
+
+
+
+
+
+
+
-
+
-
+
diff --git a/src/config/player_manager.cpp b/src/config/player_manager.cpp
index 55e061b012..f3637e49fd 100644
--- a/src/config/player_manager.cpp
+++ b/src/config/player_manager.cpp
@@ -241,10 +241,6 @@ void PlayerManager::initRemainingData()
// Sort player by frequency
m_all_players.insertionSort(/*start*/0, /*desc*/true);
-
- // Load favorite tracks for the current player
- if (m_current_player)
- m_current_player->setFavoriteTracks();
} // initRemainingData
// ----------------------------------------------------------------------------
@@ -486,7 +482,6 @@ void PlayerManager::setCurrentPlayer(PlayerProfile *player)
if(m_current_player)
{
m_current_player->computeActive();
- m_current_player->setFavoriteTracks();
}
if (player_has_changed)
diff --git a/src/config/player_profile.cpp b/src/config/player_profile.cpp
index 729450657e..414338a21a 100644
--- a/src/config/player_profile.cpp
+++ b/src/config/player_profile.cpp
@@ -79,7 +79,7 @@ PlayerProfile::PlayerProfile(const XMLNode* node)
m_remember_password = false;
m_story_mode_status = NULL;
m_achievements_status = NULL;
- m_favorite_tracks.clear();
+ m_favorite_track_status = NULL;
m_default_kart_color = 0.0f;
m_icon_filename = "";
@@ -106,6 +106,7 @@ PlayerProfile::~PlayerProfile()
{
delete m_story_mode_status;
delete m_achievements_status;
+ delete m_favorite_track_status;
#ifdef DEBUG
m_magic_number = 0xDEADBEEF;
#endif
@@ -118,29 +119,20 @@ PlayerProfile::~PlayerProfile()
*/
void PlayerProfile::loadRemainingData(const XMLNode *node)
{
+ assert(m_story_mode_status == NULL);
const XMLNode *xml_story_mode = node->getNode("story-mode");
- m_story_mode_status =
- unlock_manager->createStoryModeStatus(xml_story_mode);
+ m_story_mode_status = unlock_manager->createStoryModeStatus(xml_story_mode);
+
+ assert(m_achievements_status == NULL);
const XMLNode *xml_achievements = node->getNode("achievements");
m_achievements_status = AchievementsManager::get()
- ->createAchievementsStatus(xml_achievements, m_unique_id == 1);
+ ->createAchievementsStatus(xml_achievements, m_unique_id == 1);
// We first load the list of all favorite tracks
// Some favorites may correspond to uninstalled addons, so we do not sanitize the strings
- // TODO : handle Arena and Soccer fields
+ assert(m_favorite_track_statuss == NULL);
const XMLNode *xml_favorites = node->getNode("favorites");
- std::vector xml_favorite_tracks;
- xml_favorites->getNodes("track", xml_favorite_tracks);
- for (unsigned int i = 0; i < xml_favorite_tracks.size(); i++)
- {
- std::string temp_string;
- xml_favorite_tracks[i]->get("ident", &temp_string);
- m_favorite_tracks.push_back(temp_string);
- }
- // Deduplicate the list just in case.
- std::sort(m_favorite_tracks.begin(), m_favorite_tracks.end());
- auto it = std::unique(m_favorite_tracks.begin(), m_favorite_tracks.end());
- m_favorite_tracks.erase(it, m_favorite_tracks.end());
+ m_favorite_track_status = new FavoriteTrackStatus(xml_favorites);
// Fix up any potentially missing icons.
addIcon();
@@ -155,49 +147,10 @@ void PlayerProfile::initRemainingData()
m_story_mode_status = unlock_manager->createStoryModeStatus();
m_achievements_status =
AchievementsManager::get()->createAchievementsStatus();
+ m_favorite_track_status = new FavoriteTrackStatus(NULL);
addIcon();
} // initRemainingData
-//------------------------------------------------------------------------------
-/** Update the group of favorite tracks handled by the Track Manager.
- * To be used only if this player profile is the current player.
- */
-void PlayerProfile::setFavoriteTracks()
-{
- // Update the group data from the Track Manager
- track_manager->clearFavoriteTracks();
- for (unsigned int i = 0; i < m_favorite_tracks.size(); i++)
- {
- track_manager->addFavoriteTrack(m_favorite_tracks[i]);
- }
-} // setFavoriteTracks
-
-//------------------------------------------------------------------------------
-/** Adds a new favorite track to this player profile and to the group
- * of favorite tracks of the Track Manager.
- * To be used only if this player profile is the current player.
- */
-void PlayerProfile::addFavoriteTrack(std::string ident)
-{
- m_favorite_tracks.push_back(ident);
- track_manager->addFavoriteTrack(ident);
-} // addFavoriteTrack
-
-//------------------------------------------------------------------------------
-/** Removes a favorite track from this player profile and from the group
- * of favorite tracks of the Track Manager.
- * To be used only if this player profile is the current player.
- */
-void PlayerProfile::removeFavoriteTrack(std::string ident)
-{
- auto it = std::find(m_favorite_tracks.begin(), m_favorite_tracks.end(), ident);
- if (it != m_favorite_tracks.end()) // the track to remove has been found
- {
- m_favorite_tracks.erase(it);
- setFavoriteTracks();
- }
-} // removeFavoriteTrack
-
//------------------------------------------------------------------------------
/** Creates an icon for a player if non exist so far. It takes the unique
* player id modulo the number of karts to pick an icon from the karts. It
@@ -282,18 +235,14 @@ void PlayerProfile::save(UTFWriter &out)
if (player != NULL && (getName() == player->getName()))
is_current_player = true;
- if(m_story_mode_status)
+ if (m_story_mode_status)
m_story_mode_status->save(out, is_current_player);
- if(m_achievements_status)
+ if (m_achievements_status)
m_achievements_status->save(out);
-
- out << " \n";
- for (unsigned int i=0; i < m_favorite_tracks.size(); i++)
- {
- out << " \n";
- }
- out << " \n";
+
+ if (m_favorite_track_status)
+ m_favorite_track_status->save(out);
}
out << " \n";
} // save
diff --git a/src/config/player_profile.hpp b/src/config/player_profile.hpp
index 04fcd1f76a..d0ecf5c981 100644
--- a/src/config/player_profile.hpp
+++ b/src/config/player_profile.hpp
@@ -20,6 +20,7 @@
#define HEADER_PLAYER_PROFILE_HPP
#include "challenges/story_mode_status.hpp"
+#include "config/favorite_track_status.hpp"
#include "network/remote_kart_info.hpp"
#include "utils/leak_check.hpp"
#include "utils/no_copy.hpp"
@@ -114,8 +115,8 @@ class PlayerProfile : public NoCopy
/** The complete achievement data. */
AchievementsStatus *m_achievements_status;
- /** The list of identifiers of favorite tracks .*/
- std::vector m_favorite_tracks;
+ /** The favorite tracks selected by this player. */
+ FavoriteTrackStatus *m_favorite_track_status;
public:
@@ -125,9 +126,6 @@ class PlayerProfile : public NoCopy
void save(UTFWriter &out);
void loadRemainingData(const XMLNode *node);
void initRemainingData();
- void setFavoriteTracks();
- void addFavoriteTrack(std::string ident);
- void removeFavoriteTrack(std::string ident);
void incrementUseFrequency();
int getUseFrequency() const { return m_use_frequency; }
bool operator<(const PlayerProfile &other);
@@ -204,13 +202,6 @@ 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(); }
// ----------------------------------------------------------------------------------------
@@ -303,6 +294,23 @@ class PlayerProfile : public NoCopy
// ----------------------------------------------------------------------------------------
StoryModeStatus* getStoryModeStatus() { return m_story_mode_status; }
// ----------------------------------------------------------------------------------------
+ FavoriteTrackStatus* getFavoriteTrackStatus() { return m_favorite_track_status; }
+ // ----------------------------------------------------------------------------------------
+ bool isFavoriteTrack(std::string ident)
+ {
+ return m_favorite_track_status->isFavoriteTrack(ident);
+ } // getNumBestTrophies
+ void addFavoriteTrack(std::string ident, std::string group =
+ FavoriteTrackStatus::DEFAULT_FAVORITE_GROUP_NAME)
+ {
+ m_favorite_track_status->addFavoriteTrack(ident, group);
+ } // getNumBestTrophies
+ void removeFavoriteTrack(std::string ident, std::string group =
+ FavoriteTrackStatus::DEFAULT_FAVORITE_GROUP_NAME)
+ {
+ m_favorite_track_status->removeFavoriteTrack(ident, group);
+ } // getNumBestTrophies
+ // ----------------------------------------------------------------------------------------
/** If a session was saved, return the id of the saved user. */
int getSavedUserId() const
{
diff --git a/src/states_screens/arenas_screen.cpp b/src/states_screens/arenas_screen.cpp
index fff9cc6e05..7cb828c237 100644
--- a/src/states_screens/arenas_screen.cpp
+++ b/src/states_screens/arenas_screen.cpp
@@ -20,6 +20,7 @@
#include "config/user_config.hpp"
#include "graphics/irr_driver.hpp"
#include "guiengine/widget.hpp"
+#include "guiengine/widgets/check_box_widget.hpp"
#include "guiengine/widgets/dynamic_ribbon_widget.hpp"
#include "guiengine/widgets/icon_button_widget.hpp"
#include "io/file_manager.hpp"
@@ -57,6 +58,11 @@ void ArenasScreen::loadedFromFile()
void ArenasScreen::beforeAddingWidget()
{
+ track_manager->setFavoriteTrackStatus(PlayerManager::getCurrentPlayer()->getFavoriteTrackStatus());
+
+ CheckBoxWidget* favorite_cb = getWidget("favorite");
+ assert( favorite_cb != NULL );
+ favorite_cb->setState(false);
// Dynamically add tabs
RibbonWidget* tabs = this->getWidget("trackgroups");
@@ -79,6 +85,8 @@ void ArenasScreen::beforeAddingWidget()
//I18N: track group name
FOR_GETTEXT_ONLY( _("All") )
//I18N: track group name
+ FOR_GETTEXT_ONLY( _("Favorites") )
+ //I18N: track group name
FOR_GETTEXT_ONLY( _("Standard") )
//I18N: track group name
FOR_GETTEXT_ONLY( _("Add-Ons") )
@@ -204,8 +212,20 @@ void ArenasScreen::eventCallback(Widget* widget, const std::string& name, const
Track* clicked_track = track_manager->getTrack(selection);
if (clicked_track != NULL)
{
- TrackInfoScreen::getInstance()->setTrack(clicked_track);
- TrackInfoScreen::getInstance()->push();
+ if (getWidget("favorite")->getState())
+ {
+ if(PlayerManager::getCurrentPlayer()->isFavoriteTrack(clicked_track->getIdent()))
+ PlayerManager::getCurrentPlayer()->removeFavoriteTrack(clicked_track->getIdent());
+ else
+ PlayerManager::getCurrentPlayer()->addFavoriteTrack(clicked_track->getIdent());
+
+ buildTrackList();
+ }
+ else
+ {
+ TrackInfoScreen::getInstance()->setTrack(clicked_track);
+ TrackInfoScreen::getInstance()->push();
+ }
} // clickedTrack != NULL
} // if random_track
@@ -225,6 +245,8 @@ void ArenasScreen::eventCallback(Widget* widget, const std::string& name, const
void ArenasScreen::buildTrackList()
{
+ track_manager->setFavoriteTrackStatus(PlayerManager::getCurrentPlayer()->getFavoriteTrackStatus());
+
DynamicRibbonWidget* w = this->getWidget("tracks");
assert( w != NULL );
@@ -237,6 +259,7 @@ void ArenasScreen::buildTrackList()
bool soccer_mode = RaceManager::get()->getMinorMode() == RaceManager::MINOR_MODE_SOCCER;
bool arenas_have_navmesh = false;
+ PtrVector