Sort karts by locked/unlocked state (and then alphabetically).

This commit is contained in:
hiker
2014-06-03 13:50:28 +10:00
parent 3d88bfa297
commit 663287930f
5 changed files with 64 additions and 66 deletions

View File

@@ -78,7 +78,7 @@ void AbstractKart::reset()
// ----------------------------------------------------------------------------
/** Returns a name to be displayed for this kart. */
const wchar_t* AbstractKart::getName() const
core::stringw AbstractKart::getName() const
{
return m_kart_properties->getName();
} // getName;

View File

@@ -83,6 +83,7 @@ public:
int world_kart_id,
int position, const btTransform& init_transform);
virtual ~AbstractKart();
virtual core::stringw getName() const;
virtual void reset();
virtual void init(RaceManager::KartType type) = 0;
// ========================================================================
@@ -109,8 +110,7 @@ public:
// ------------------------------------------------------------------------
/** Sets the kart properties. */
void setKartProperties(const KartProperties *kp) { m_kart_properties=kp; }
// ------------------------------------------------------------------------
virtual const wchar_t* getName() const;
// ------------------------------------------------------------------------
/** Returns a unique identifier for this kart (name of the directory the
* kart was loaded from). */

View File

@@ -20,6 +20,7 @@
#include "addons/addon.hpp"
#include "config/stk_config.hpp"
#include "config/player_manager.hpp"
#include "graphics/irr_driver.hpp"
#include "graphics/material_manager.hpp"
#include "io/file_manager.hpp"
@@ -732,6 +733,28 @@ void KartProperties::checkAllSet(const std::string &filename)
m_ai_properties[i]->checkAllSet(filename);
} // checkAllSet
// ----------------------------------------------------------------------------
bool KartProperties::operator<(const KartProperties &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 getName() < other.getName();
}
else
return other_is_locked;
return true;
} // operator<
// ----------------------------------------------------------------------------
bool KartProperties::isInGroup(const std::string &group) const
{
return std::find(m_groups.begin(), m_groups.end(), group) != m_groups.end();
} // isInGroups
// ----------------------------------------------------------------------------
/** Called the first time a kart accelerates after 'ready-set-go'. It searches
* through m_startup_times to find the appropriate slot, and returns the

View File

@@ -387,6 +387,8 @@ public:
void getAllData (const XMLNode * root);
void checkAllSet (const std::string &filename);
float getStartupBoost () const;
bool isInGroup (const std::string &group) const;
bool operator<(const KartProperties &other) const;
// ------------------------------------------------------------------------
/** Returns the (maximum) speed for a given turn radius.
@@ -431,9 +433,9 @@ public:
/** Returns the name of this kart.
\note Pass it through fridibi as needed, this is the LTR name
*/
const wchar_t* getName() const
core::stringw getName() const
{
return translations->w_gettext(m_name.c_str());
return core::stringw(translations->w_gettext(m_name.c_str()));
}
// ------------------------------------------------------------------------

View File

@@ -675,10 +675,9 @@ void PlayerKartWidget::onUpdate(float delta)
// -------------------------------------------------------------------------
/** Event callback */
GUIEngine::EventPropagation PlayerKartWidget::transmitEvent(
Widget* w,
const std::string& originator,
const int m_player_id)
GUIEngine::EventPropagation PlayerKartWidget::transmitEvent(Widget* w,
const std::string& originator,
const int m_player_id )
{
assert(m_magic_number == 0x33445566);
// if it's declared ready, there is really nothing to process
@@ -1050,7 +1049,7 @@ void KartSelectionScreen::tearDown()
m_kart_widgets.clearAndDeleteAll();
if (m_must_delete_on_back)
GUIEngine::removeScreen(this->getName().c_str());
GUIEngine::removeScreen(getName().c_str());
} // tearDown
// ----------------------------------------------------------------------------
@@ -1542,7 +1541,7 @@ void KartSelectionScreen::eventCallback(Widget* widget,
setKartsFromCurrentGroup();
const std::string selected_kart_group =
const std::string &selected_kart_group =
tabs->getSelectionIDString(PLAYER_ID_GAME_MASTER);
UserConfigParams::m_last_used_kart_group = selected_kart_group;
@@ -1992,7 +1991,7 @@ void KartSelectionScreen::setKartsFromCurrentGroup()
// selected kart group is removed. In this case, select the
// 'standard' group
if (selected_kart_group != ALL_KART_GROUPS_ID &&
!kart_properties_manager->getKartsInGroup(selected_kart_group).size())
!kart_properties_manager->getKartsInGroup(selected_kart_group).size())
{
selected_kart_group = DEFAULT_GROUP_NAME;
}
@@ -2000,69 +1999,43 @@ void KartSelectionScreen::setKartsFromCurrentGroup()
DynamicRibbonWidget* w = getWidget<DynamicRibbonWidget>("karts");
w->clearItems();
int usableKartCount = 0;
int usable_kart_count = 0;
PtrVector<const KartProperties, REF> karts;
if (selected_kart_group == ALL_KART_GROUPS_ID)
for(unsigned int i=0; i<kart_properties_manager->getNumberOfKarts(); i++)
{
const int kart_amount = kart_properties_manager->getNumberOfKarts();
for (int n=0; n<kart_amount; n++)
{
const KartProperties* prop =
kart_properties_manager->getKartById(n);
if (PlayerManager::getCurrentPlayer()->isLocked(prop->getIdent()))
{
w->addItem(
_("Locked : solve active challenges to gain access "
"to more!"),
ID_LOCKED+prop->getIdent(),
prop->getAbsoluteIconFile(), LOCKED_BADGE,
IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE);
}
else
{
w->addItem(translations->fribidize(prop->getName()),
prop->getIdent(),
prop->getAbsoluteIconFile(), 0,
IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE);
usableKartCount++;
}
}
const KartProperties* prop = kart_properties_manager->getKartById(i);
// Ignore karts that are not in the selected group
if(selected_kart_group != ALL_KART_GROUPS_ID &&
!prop->isInGroup(selected_kart_group))
continue;
karts.push_back(prop);
}
else if (selected_kart_group != RibbonWidget::NO_ITEM_ID)
karts.insertionSort();
for(unsigned int i=0; i<karts.size(); i++)
{
std::vector<int> group =
kart_properties_manager->getKartsInGroup(selected_kart_group);
const int kart_amount = group.size();
for (int n=0; n<kart_amount; n++)
const KartProperties* prop = karts.get(i);
if (PlayerManager::getCurrentPlayer()->isLocked(prop->getIdent()))
{
const KartProperties* prop =
kart_properties_manager->getKartById(group[n]);
const std::string &icon_path = prop->getAbsoluteIconFile();
if (PlayerManager::getCurrentPlayer()->isLocked(prop->getIdent()))
{
w->addItem(
_("Locked : solve active challenges to gain access "
"to more!"),
ID_LOCKED+prop->getIdent(), icon_path, LOCKED_BADGE,
IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE);
}
else
{
w->addItem(translations->fribidize(prop->getName()),
prop->getIdent(),
icon_path, 0,
IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE);
usableKartCount++;
}
w->addItem(_("Locked : solve active challenges to gain access "
"to more!"),
ID_LOCKED + prop->getIdent(),
prop->getAbsoluteIconFile(), LOCKED_BADGE,
IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE);
}
else
{
w->addItem(translations->fribidize(prop->getName()),
prop->getIdent(),
prop->getAbsoluteIconFile(), 0,
IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE);
usable_kart_count++;
}
}
// add random
if (usableKartCount > 1)
if (usable_kart_count > 1)
{
w->addItem(_("Random Kart"), RANDOM_KART_ID, "/gui/random_kart.png");
}