Cosmetic changes: moved minor structs into a class, added &,

renamed members to use m_ etc.


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@7713 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2011-02-16 08:45:26 +00:00
parent 745bea6285
commit ac956fdcb1
8 changed files with 107 additions and 88 deletions

View File

@ -31,13 +31,13 @@
#include "utils/translation.hpp"
#include "utils/string_utils.hpp"
const irr::core::stringw UnlockableFeature::getUnlockedMessage() const
const irr::core::stringw Challenge::UnlockableFeature::getUnlockedMessage() const
{
switch (type)
switch (m_type)
{
case UNLOCK_TRACK:
{ // {} avoids compiler warning
const Track* track = track_manager->getTrack( name );
const Track* track = track_manager->getTrack(m_name);
// shouldn't happen but let's avoid crashes as much as possible...
if (track == NULL) return irr::core::stringw( L"????" );
@ -47,11 +47,11 @@ const irr::core::stringw UnlockableFeature::getUnlockedMessage() const
}
case UNLOCK_MODE:
{
return _("New game mode '%s' now available", user_name);
return _("New game mode '%s' now available", m_user_name);
}
case UNLOCK_GP:
{
const GrandPrixData* gp = grand_prix_manager->getGrandPrix(name);
const GrandPrixData* gp = grand_prix_manager->getGrandPrix(m_name);
// shouldn't happen but let's avoid crashes as much as possible...
if (gp == NULL) return irr::core::stringw( L"????" );
@ -61,11 +61,12 @@ const irr::core::stringw UnlockableFeature::getUnlockedMessage() const
}
case UNLOCK_DIFFICULTY:
{
return _("New difficulty '%s' now available", user_name);
return _("New difficulty '%s' now available", m_user_name);
}
case UNLOCK_KART:
{
const KartProperties* kp = kart_properties_manager->getKart( name );
const KartProperties* kp =
kart_properties_manager->getKart(m_name);
// shouldn't happen but let's avoid crashes as much as possible...
if (kp == NULL) return irr::core::stringw( L"????" );
@ -76,7 +77,7 @@ const irr::core::stringw UnlockableFeature::getUnlockedMessage() const
assert(false);
return L"";
} // switch
}
} // UnlockableFeature::getUnlockedMessage
//-----------------------------------------------------------------------------
/** Sets that the given track will be unlocked if this challenge
@ -92,10 +93,10 @@ void Challenge::addUnlockTrackReward(const std::string &track_name)
}
UnlockableFeature feature;
feature.name = track_name;
feature.type = UNLOCK_TRACK;
feature.m_name = track_name;
feature.m_type = UNLOCK_TRACK;
m_feature.push_back(feature);
}
} // addUnlockTrackReward
//-----------------------------------------------------------------------------
@ -103,11 +104,11 @@ void Challenge::addUnlockModeReward(const std::string &internal_mode_name,
const irr::core::stringw &user_mode_name)
{
UnlockableFeature feature;
feature.name = internal_mode_name;
feature.type = UNLOCK_MODE;
feature.user_name = user_mode_name;
feature.m_name = internal_mode_name;
feature.m_type = UNLOCK_MODE;
feature.m_user_name = user_mode_name;
m_feature.push_back(feature);
}
} // addUnlockModeReward
//-----------------------------------------------------------------------------
void Challenge::addUnlockGPReward(const std::string &gp_name)
@ -119,11 +120,11 @@ void Challenge::addUnlockGPReward(const std::string &gp_name)
UnlockableFeature feature;
feature.name = gp_name.c_str();
feature.m_name = gp_name.c_str();
feature.type = UNLOCK_GP;
feature.m_type = UNLOCK_GP;
m_feature.push_back(feature);
}
} // addUnlockGPReward
//-----------------------------------------------------------------------------
@ -131,11 +132,11 @@ void Challenge::addUnlockDifficultyReward(const std::string &internal_name,
const irr::core::stringw &user_name)
{
UnlockableFeature feature;
feature.name = internal_name;
feature.type = UNLOCK_DIFFICULTY;
feature.user_name = user_name;
feature.m_name = internal_name;
feature.m_type = UNLOCK_DIFFICULTY;
feature.m_user_name = user_name;
m_feature.push_back(feature);
}
} // addUnlockDifficultyReward
//-----------------------------------------------------------------------------
void Challenge::addUnlockKartReward(const std::string &internal_name,
@ -152,11 +153,11 @@ void Challenge::addUnlockKartReward(const std::string &internal_name,
}
UnlockableFeature feature;
feature.name = internal_name;
feature.type = UNLOCK_KART;
feature.user_name = user_name;
feature.m_name = internal_name;
feature.m_type = UNLOCK_KART;
feature.m_user_name = user_name;
m_feature.push_back(feature);
}
} // addUnlockKartReward
//-----------------------------------------------------------------------------
/** Loads the state for a challenge object (esp. m_state), and calls the

View File

@ -33,21 +33,6 @@
class XMLNode;
enum REWARD_TYPE
{UNLOCK_TRACK,
UNLOCK_GP,
UNLOCK_MODE,
UNLOCK_KART,
UNLOCK_DIFFICULTY};
struct UnlockableFeature
{
std::string name; // internal name
irr::core::stringw user_name; // not all types of feature have one
REWARD_TYPE type;
const irr::core::stringw getUnlockedMessage() const;
};
/**
* \brief A class for all challenges
@ -55,6 +40,25 @@ struct UnlockableFeature
*/
class Challenge : public NoCopy
{
public:
enum REWARD_TYPE {UNLOCK_TRACK,
UNLOCK_GP,
UNLOCK_MODE,
UNLOCK_KART,
UNLOCK_DIFFICULTY};
// ------------------------------------------------------------------------
class UnlockableFeature
{
public:
std::string m_name; // internal name
irr::core::stringw m_user_name; // not all types of feature have one
REWARD_TYPE m_type;
const irr::core::stringw getUnlockedMessage() const;
}; // UnlockableFeature
// ------------------------------------------------------------------------
private:
enum {CH_INACTIVE, // challenge not yet possible
CH_ACTIVE, // challenge possible, but not yet solved
@ -70,6 +74,12 @@ private:
/** What needs to be done before accessing this challenge. */
std::vector<std::string> m_prerequisites;
/** Version of the challenge. This way incorrect challenges
* (e.g. if a newer version of STK is installed on top of an
* existing installation, and the older challenges refer to
* a track that does not exist/does not work anymore) can be
* avoided. */
unsigned int m_version;
public:
Challenge(const std::string &id, const std::string &name);
Challenge() {m_Id=""; m_Name="";m_state=CH_INACTIVE;}

View File

@ -146,11 +146,11 @@ ChallengeData::ChallengeData(const std::string& filename)
if (grand_prix_manager->getGrandPrix(m_gp_id) == NULL) error("gp");
}
getUnlocks(root, "unlock-track", UNLOCK_TRACK);
getUnlocks(root, "unlock-gp", UNLOCK_GP );
getUnlocks(root, "unlock-mode", UNLOCK_MODE );
getUnlocks(root, "unlock-difficulty", UNLOCK_DIFFICULTY);
getUnlocks(root, "unlock-kart", UNLOCK_KART);
getUnlocks(root, "unlock-track", Challenge::UNLOCK_TRACK);
getUnlocks(root, "unlock-gp", Challenge::UNLOCK_GP );
getUnlocks(root, "unlock-mode", Challenge::UNLOCK_MODE );
getUnlocks(root, "unlock-difficulty", Challenge::UNLOCK_DIFFICULTY);
getUnlocks(root, "unlock-kart", Challenge::UNLOCK_KART);
if (getFeatures().size() == 0)
{
@ -215,7 +215,7 @@ void ChallengeData::check() const
// ----------------------------------------------------------------------------
void ChallengeData::getUnlocks(const XMLNode *root, const std:: string type,
void ChallengeData::getUnlocks(const XMLNode *root, const std:: string &type,
REWARD_TYPE reward)
{
std:: string attrib;
@ -241,7 +241,7 @@ void ChallengeData::getUnlocks(const XMLNode *root, const std:: string type,
case UNLOCK_MODE: {
const RaceManager::MinorRaceModeType mode =
RaceManager::getModeIDFromInternalName(attrib.c_str());
RaceManager::getModeIDFromInternalName(attrib);
addUnlockModeReward (attrib, RaceManager::getNameOf(mode));
break;
}

View File

@ -48,7 +48,8 @@ private:
/** Version number of the challenge. */
int m_version;
void getUnlocks(const XMLNode *root, const std:: string type, REWARD_TYPE reward);
void getUnlocks(const XMLNode *root, const std::string &type,
Challenge::REWARD_TYPE reward);
void error(const char *id) const;
public:

View File

@ -341,7 +341,7 @@ void UnlockManager::lockFeature(const ChallengeData *challenge)
{
const unsigned int amount = (unsigned int)challenge->getFeatures().size();
for(unsigned int n=0; n<amount; n++)
m_locked_features[challenge->getFeatures()[n].name]=true;
m_locked_features[challenge->getFeatures()[n].m_name]=true;
} // lockFeature
//-----------------------------------------------------------------------------
@ -351,7 +351,7 @@ void UnlockManager::unlockFeature(ChallengeData* c, bool do_save)
const unsigned int amount = (unsigned int)c->getFeatures().size();
for(unsigned int n=0; n<amount; n++)
{
std::string feature = c->getFeatures()[n].name;
std::string feature = c->getFeatures()[n].m_name;
std::map<std::string,bool>::iterator p=m_locked_features.find(feature);
if(p==m_locked_features.end())
{

View File

@ -169,12 +169,12 @@ public:
* used from challenge_data, which reads the mode from a challenge file.
* \param name The name of the minor mode.
*/
static const MinorRaceModeType getModeIDFromInternalName(const char* name)
static const MinorRaceModeType getModeIDFromInternalName(const std::string &name)
{
if (strcmp(name, IDENT_STD) == 0) return MINOR_MODE_NORMAL_RACE;
else if (strcmp(name, IDENT_TTRIAL) == 0) return MINOR_MODE_TIME_TRIAL;
else if (strcmp(name, FTL_IDENT) == 0) return MINOR_MODE_FOLLOW_LEADER;
else if (strcmp(name, STRIKES_IDENT) == 0) return MINOR_MODE_3_STRIKES;
if (name==IDENT_STD ) return MINOR_MODE_NORMAL_RACE;
else if (name==IDENT_TTRIAL ) return MINOR_MODE_TIME_TRIAL;
else if (name==FTL_IDENT ) return MINOR_MODE_FOLLOW_LEADER;
else if (name==STRIKES_IDENT) return MINOR_MODE_3_STRIKES;
assert(0);
return MINOR_MODE_NONE;

View File

@ -488,27 +488,29 @@ void FeatureUnlockedCutScene::addUnlockedThings(const std::vector<const Challeng
{
for (unsigned int n=0; n<unlocked.size(); n++)
{
const std::vector<UnlockableFeature>& unlockedFeatures = unlocked[n]->getFeatures();
const std::vector<Challenge::UnlockableFeature>&
unlockedFeatures = unlocked[n]->getFeatures();
assert(unlockedFeatures.size() > 0);
for (unsigned int i=0; i<unlockedFeatures.size(); i++)
{
switch (unlockedFeatures[i].type)
switch (unlockedFeatures[i].m_type)
{
case UNLOCK_TRACK:
case Challenge::UNLOCK_TRACK:
{
Track* track = track_manager->getTrack(unlockedFeatures[i].name);
Track* track =
track_manager->getTrack(unlockedFeatures[i].m_name);
assert(track != NULL);
const std::string sshot = track->getScreenshotFile();
addUnlockedPicture( irr_driver->getTexture(sshot.c_str()), 1.0f, 0.75f,
unlockedFeatures[i].getUnlockedMessage() );
unlockedFeatures[i].getUnlockedMessage() );
break;
}
case UNLOCK_GP:
case Challenge::UNLOCK_GP:
{
std::vector<ITexture*> images;
const GrandPrixData* gp = grand_prix_manager->getGrandPrix(unlockedFeatures[i].name);
const GrandPrixData* gp =
grand_prix_manager->getGrandPrix(unlockedFeatures[i].m_name);
if (gp == NULL)
{
std::cerr << "ERROR: Unlocked GP does not exist???\n";
@ -532,62 +534,66 @@ void FeatureUnlockedCutScene::addUnlockedThings(const std::vector<const Challeng
Track* track = track_manager->getTrack(gptracks[t]);
ITexture* tex = irr_driver->getTexture(track != NULL ?
track->getScreenshotFile().c_str() :
file_manager->getDataDir() + "gui/main_help.png");
track->getScreenshotFile().c_str() :
file_manager->getDataDir() + "gui/main_help.png");
images.push_back(tex);
}
}
addUnlockedPictures(images, 1.0f, 0.75f,
unlockedFeatures[i].getUnlockedMessage() );
unlockedFeatures[i].getUnlockedMessage() );
break;
}
case UNLOCK_MODE:
case Challenge::UNLOCK_MODE:
{
const RaceManager::MinorRaceModeType mode =
RaceManager::getModeIDFromInternalName(unlockedFeatures[i].name.c_str());
RaceManager::getModeIDFromInternalName(unlockedFeatures[i].m_name);
const std::string icon = file_manager->getDataDir() + "/" + RaceManager::getIconOf(mode);
addUnlockedPicture( irr_driver->getTexture(icon.c_str()), 0.8f, 0.8f,
unlockedFeatures[i].getUnlockedMessage() );
unlockedFeatures[i].getUnlockedMessage() );
break;
}
case UNLOCK_KART:
case Challenge::UNLOCK_KART:
{
const KartProperties* kart = kart_properties_manager->getKart(unlockedFeatures[i].name);
const KartProperties* kart =
kart_properties_manager->getKart(unlockedFeatures[i].m_name);
if (kart == NULL)
{
fprintf(stderr, "[KartSelectionScreen] WARNING: could not find a kart named '%s'\n",
unlockedFeatures[i].name.c_str());
unlockedFeatures[i].m_name.c_str());
video::ITexture* tex = irr_driver->getTexture(file_manager->getGUIDir() + "/main_help.png");
video::ITexture* tex =
irr_driver->getTexture(file_manager->getGUIDir() +
"/main_help.png" );
addUnlockedPicture(tex, 1.0f, 0.75f,
L"???" );
L"???" );
}
else
{
// the passed kart will not be modified, that's why I allow myself to use const_cast
// the passed kart will not be modified,
// that's why I allow myself to use const_cast
addUnlockedKart(const_cast<KartProperties*>(kart),
unlockedFeatures[i].getUnlockedMessage() );
}
break;
}
case UNLOCK_DIFFICULTY:
case Challenge::UNLOCK_DIFFICULTY:
{
//TODO : implement difficulty reward
std::cerr << "OK, I see you unlocked a difficulty, but this is not supported yet\n";
video::ITexture* tex = irr_driver->getTexture( file_manager->getGUIDir() + "/main_help.png");
addUnlockedPicture( tex, 1.0f, 0.75f,
unlockedFeatures[i].getUnlockedMessage() );
unlockedFeatures[i].getUnlockedMessage() );
break;
}
default:
{
assert(false);
}
}
} // default
} // switch
} // next feature
} // next challenge

View File

@ -148,7 +148,8 @@ void RaceSetupScreen::onGameModeChanged()
assert( w2 != NULL );
std::string gamemode_str = w2->getSelectionIDString(PLAYER_ID_GAME_MASTER);
RaceManager::MinorRaceModeType gamemode = RaceManager::getModeIDFromInternalName(gamemode_str.c_str());
RaceManager::MinorRaceModeType gamemode =
RaceManager::getModeIDFromInternalName(gamemode_str);
// deactivate the AI karts count widget for modes for which we have no AI
SpinnerWidget* kartamount = getWidget<SpinnerWidget>("aikartamount");