Sort tracks first by locked/unlocked status, then alphabetically.
Added support for special sort names for each track (e.g. 'The Island' can be sorted as 'Island' etc).
This commit is contained in:
@@ -135,7 +135,8 @@ SelectChallengeDialog::SelectChallengeDialog(const float percentWidth,
|
||||
}
|
||||
else
|
||||
{
|
||||
const wchar_t* track_name = track_manager->getTrack(c->getData()->getTrackId())->getName();
|
||||
const core::stringw track_name =
|
||||
track_manager->getTrack(c->getData()->getTrackId())->getName();
|
||||
getWidget<LabelWidget>("title")->setText( track_name, true );
|
||||
}
|
||||
|
||||
|
||||
@@ -282,7 +282,9 @@ void TracksScreen::init()
|
||||
} // init
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
/** Rebuild the list of tracks and GPs. This need to be recomputed e.g. to
|
||||
* take unlocked tracks into account.
|
||||
*/
|
||||
void TracksScreen::buildTrackList()
|
||||
{
|
||||
DynamicRibbonWidget* tracks_widget = getWidget<DynamicRibbonWidget>("tracks");
|
||||
@@ -295,71 +297,44 @@ void TracksScreen::buildTrackList()
|
||||
tracks_widget->clearItems();
|
||||
m_random_track_list.clear();
|
||||
|
||||
const std::string curr_group_name = tabs->getSelectionIDString(0);
|
||||
const std::string& curr_group_name = tabs->getSelectionIDString(0);
|
||||
|
||||
// Build track list
|
||||
if (curr_group_name == ALL_TRACK_GROUPS_ID)
|
||||
const int track_amount = track_manager->getNumberOfTracks();
|
||||
|
||||
// First build a list of all tracks to be displayed
|
||||
// (e.g. exclude arenas, ...)
|
||||
PtrVector<Track, REF> tracks;
|
||||
for (int n = 0; n < track_amount; n++)
|
||||
{
|
||||
const int trackAmount = track_manager->getNumberOfTracks();
|
||||
Track* curr = track_manager->getTrack(n);
|
||||
if (race_manager->getMinorMode() == RaceManager::MINOR_MODE_EASTER_EGG
|
||||
&& !curr->hasEasterEggs())
|
||||
continue;
|
||||
if (curr->isArena() || curr->isSoccer()||curr->isInternal()) continue;
|
||||
if (curr_group_name != ALL_TRACK_GROUPS_ID &&
|
||||
!curr->isInGroup(curr_group_name)) continue;
|
||||
|
||||
for (int n=0; n<trackAmount; n++)
|
||||
tracks.push_back(curr);
|
||||
} // for n<track_amount
|
||||
|
||||
tracks.insertionSort();
|
||||
for (unsigned int i = 0; i < tracks.size(); i++)
|
||||
{
|
||||
Track *curr = tracks.get(i);
|
||||
if (PlayerManager::getCurrentPlayer()->isLocked(curr->getIdent()))
|
||||
{
|
||||
Track* curr = track_manager->getTrack( n );
|
||||
if(race_manager->getMinorMode()==RaceManager::MINOR_MODE_EASTER_EGG
|
||||
&& !curr->hasEasterEggs())
|
||||
continue;
|
||||
if (curr->isArena() || curr->isSoccer()) continue;
|
||||
if (curr->isInternal()) continue;
|
||||
|
||||
if(PlayerManager::getCurrentPlayer()->isLocked(curr->getIdent()))
|
||||
{
|
||||
tracks_widget->addItem(
|
||||
_("Locked : solve active challenges to gain access to more!"),
|
||||
"locked", curr->getScreenshotFile(), LOCKED_BADGE,
|
||||
IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE);
|
||||
}
|
||||
else
|
||||
{
|
||||
tracks_widget->addItem(translations->fribidize(curr->getName()),
|
||||
curr->getIdent(),
|
||||
curr->getScreenshotFile(), 0,
|
||||
IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE );
|
||||
m_random_track_list.push_back(curr->getIdent());
|
||||
}
|
||||
tracks_widget->addItem(
|
||||
_("Locked : solve active challenges to gain access to more!"),
|
||||
"locked", curr->getScreenshotFile(), LOCKED_BADGE,
|
||||
IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
const std::vector<int>& curr_group =
|
||||
track_manager->getTracksInGroup( curr_group_name );
|
||||
const int trackAmount = curr_group.size();
|
||||
|
||||
for (int n=0; n<trackAmount; n++)
|
||||
else
|
||||
{
|
||||
Track* curr = track_manager->getTrack( curr_group[n] );
|
||||
if(race_manager->getMinorMode()==RaceManager::MINOR_MODE_EASTER_EGG
|
||||
&& !curr->hasEasterEggs())
|
||||
continue;
|
||||
if (curr->isArena()) continue;
|
||||
if (curr->isSoccer()) continue;
|
||||
if (curr->isInternal()) continue;
|
||||
|
||||
if (PlayerManager::getCurrentPlayer()->isLocked(curr->getIdent()))
|
||||
{
|
||||
tracks_widget->addItem(
|
||||
_("Locked : solve active challenges to gain access to more!"),
|
||||
"locked", curr->getScreenshotFile(), LOCKED_BADGE,
|
||||
IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE);
|
||||
}
|
||||
else
|
||||
{
|
||||
tracks_widget->addItem(translations->fribidize(curr->getName()),
|
||||
curr->getIdent(),
|
||||
curr->getScreenshotFile(), 0 /* no badge */,
|
||||
IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE );
|
||||
m_random_track_list.push_back(curr->getIdent());
|
||||
}
|
||||
tracks_widget->addItem(translations->fribidize(curr->getName()),
|
||||
curr->getIdent(),
|
||||
curr->getScreenshotFile(), 0,
|
||||
IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE);
|
||||
m_random_track_list.push_back(curr->getIdent());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -73,6 +73,7 @@
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <sstream>
|
||||
#include <wchar.h>
|
||||
|
||||
using namespace irr;
|
||||
|
||||
@@ -152,6 +153,82 @@ Track::~Track()
|
||||
#endif
|
||||
} // ~Track
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** A < comparison of tracks. This is used to sort the tracks when displaying
|
||||
* them in the gui.
|
||||
*/
|
||||
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
|
||||
return other_is_locked;
|
||||
} // operator<
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
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
|
||||
return this_is_locked;
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Returns the name of the track, which is e.g. displayed on the screen.
|
||||
\note this is the LTR name, invoke fribidi as needed. */
|
||||
core::stringw Track::getName() const
|
||||
{
|
||||
core::stringw translated = translations->w_gettext(m_name.c_str());
|
||||
int index = translated.find("|");
|
||||
if(index>-1)
|
||||
{
|
||||
translated = translated.subString(0, index);
|
||||
}
|
||||
return translated;
|
||||
} // getName
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Returns the name of the track used to sort the tracks alphabetically.
|
||||
* This can be used to e.g. sort 'The Island' as 'Island,The'; or
|
||||
* to replace certain language-specific characters (e.g. German 'ae' with 'a')
|
||||
* The sort name can be specified by setting the name of a track to:
|
||||
* "normal name|sort name"
|
||||
*/
|
||||
core::stringw Track::getSortName() const
|
||||
{
|
||||
core::stringw translated = translations->w_gettext(m_name.c_str());
|
||||
translated.make_lower();
|
||||
int index = translated.find("|");
|
||||
if(index>-1)
|
||||
{
|
||||
translated = translated.subString(index+1, translated.size());
|
||||
}
|
||||
return translated;
|
||||
} // getSortName
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Returns true if this track belongs to the specified track group.
|
||||
* \param group_name Group name to test for.
|
||||
*/
|
||||
bool Track::isInGroup(const std::string &group_name)
|
||||
{
|
||||
for(unsigned int i=0; i<m_groups.size(); i++)
|
||||
{
|
||||
if(m_groups[i]==group_name) return true;
|
||||
}
|
||||
return false;
|
||||
} // isInGroup
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Returns number of completed challenges */
|
||||
unsigned int Track::getNumOfCompletedChallenges()
|
||||
|
||||
@@ -350,6 +350,9 @@ private:
|
||||
/** Name of the track to display. */
|
||||
std::string m_name;
|
||||
|
||||
/** The name used in sorting the track. */
|
||||
core::stringw m_sort_name;
|
||||
|
||||
bool m_use_fog;
|
||||
/** True if this track supports using smoothed normals. */
|
||||
bool m_smooth_normals;
|
||||
@@ -428,6 +431,11 @@ public:
|
||||
void adjustForFog(scene::IMesh* mesh,
|
||||
scene::ISceneNode* parent_scene_node);
|
||||
void itemCommand(const XMLNode *node);
|
||||
core::stringw getName() const;
|
||||
core::stringw getSortName() const;
|
||||
// ------------------------------------------------------------------------
|
||||
bool isInGroup(const std::string &group_name);
|
||||
// ------------------------------------------------------------------------
|
||||
const core::vector3df& getSunRotation();
|
||||
/** Sets the current ambient color for a kart with index k. */
|
||||
void setAmbientColor(const video::SColor &color,
|
||||
@@ -472,11 +480,6 @@ public:
|
||||
/** Returns a unique identifier for this track (the directory name). */
|
||||
const std::string& getIdent () const {return m_ident; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the name of the track, which is e.g. displayed on the screen.
|
||||
\note this is the LTR name, invoke fribidi as needed. */
|
||||
const wchar_t* getName () const
|
||||
{return translations->w_gettext(m_name.c_str()); }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns all groups this track belongs to. */
|
||||
const std::vector<std::string>&
|
||||
getGroups () const {return m_groups; }
|
||||
@@ -612,6 +615,8 @@ public:
|
||||
|
||||
float getDisplacementSpeed() const { return m_displacement_speed; }
|
||||
float getCausticsSpeed() const { return m_caustics_speed; }
|
||||
bool operator<(const Track &other) const;
|
||||
bool operator>(const Track &other) const;
|
||||
}; // class Track
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user