tutorial incremental commit. first works on TutorialManager and Tutorial

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@7130 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
aeonphyxius
2010-12-21 08:23:08 +00:00
parent 13241636d4
commit 704ea6ac7b
4 changed files with 33 additions and 55 deletions

View File

@@ -76,45 +76,44 @@ public:
Tutorial() {m_Id=""; m_Name="";m_state=CH_INACTIVE;}
virtual ~Tutorial() {};
// Getters & Setters
const std::string &getId() const { return m_Id;}
irr::core::stringw getName() const { return m_Name;}
irr::core::stringw getName() const { return m_Name;}
const irr::core::stringw&
getTutorialDescription() const {return m_tutorial_description; }
void setName(const irr::core::stringw & s) { m_Name = s;}
void setId(const std::string& s) { m_Id = s;}
void addUnlockTrackReward(const std::string &track_name);
void addUnlockModeReward(const std::string &internal_mode_name,
const irr::core::stringw &user_mode_name);
void setSolved() { m_state = CH_SOLVED;}
void setActive() { m_state = CH_ACTIVE;}
void addUnlockTrackReward (const std::string &track_name);
void addUnlockModeReward (const std::string &internal_mode_name,
const irr::core::stringw &user_mode_name);
void setTutorialDescription(const irr::core::stringw& d)
{m_tutorial_description=d; }
/* void addUnlockGPReward(const std::string &gp_name);
{m_tutorial_description=d;}
void addUnlockGPReward(const std::string &gp_name);
void addUnlockDifficultyReward(const std::string &internal_name,
const irr::core::stringw &user_name);
void addUnlockKartReward(const std::string &internal_name,
const irr::core::stringw &user_name);
/*const vector<UnlockableFeature>&
getFeatures() const { return m_feature; }
const irr::core::stringw&
getChallengeDescription() const {return m_challenge_description; }
void addDependency(const std::string id) {m_prerequisites.push_back(id); }
bool isSolved() const {return m_state==CH_SOLVED; }
bool isActive() const {return m_state==CH_ACTIVE; }
void setSolved() {m_state = CH_SOLVED; }
void setActive() {m_state = CH_ACTIVE; }
const vector<std::string>&
getPrerequisites() const {return m_prerequisites; }
// File operations
void load(const XMLNode* config);
void save(ofstream& writer);
// These functions are meant for customisation, e.g. load/save
// additional state information specific to the tutorial
virtual void loadAdditionalInfo(const XMLNode* config) {};
virtual void saveAdditionalInfo(ofstream& writer) {};
// These functions are called when a race/gp is finished. It allows
// the challenge to unlock features (when returning true), otherwise
// the feature remains locked.
virtual bool raceFinished() {return false;} // end of a race
virtual bool raceFinished() {return false;} // end of a race
//virtual bool grandPrixFinished() {return false;} // end of a GP
/** sets the right parameters in RaceManager to try this tutorial */

View File

@@ -48,7 +48,7 @@ TutorialData::TutorialData(const std::string& filename)
XMLNode *root = new XMLNode( filename );
// Check if the file have been correctly load
// Check if the file have been load correctly
if(!root || root->getName()!="tutorial")
{
delete root;
@@ -61,8 +61,7 @@ TutorialData::TutorialData(const std::string& filename)
int i_property;
float f_property;
// Mode
// Mode
root->get("major", &s_property);
setMajor(s_property);

View File

@@ -181,9 +181,8 @@ void TutorialManager::addTutorial(const std::string& filename)
} // addChallenge
//-----------------------------------------------------------------------------
std::vector<const Tutorial*> TutorialManager::getActiveTutorials()
std::vector<const Tutorial*> TutorialManager::getTutorialsList()
{
computeActive();
std::vector<const Tutorial*> all_active;
//for(AllChallengesType::iterator i =m_all_challenges.begin();
// i!=m_all_challenges.end(); i++)
@@ -196,7 +195,7 @@ std::vector<const Tutorial*> TutorialManager::getActiveTutorials()
//-----------------------------------------------------------------------------
const Tutorial* TutorialManager::getTutorial(const std::string& id)
{
if(m_all_tutorials.find(id)==m_all_tutorials.end()) return NULL;
if(m_all_tutorials.find(id) == m_all_tutorials.end()) return NULL;
return m_all_tutorials[id];
} // getTutorial
@@ -205,11 +204,11 @@ const Tutorial* TutorialManager::getTutorial(const std::string& id)
*/
void TutorialManager::load()
{
const std::string filename=file_manager->getChallengeFile("challenges.xml");
const std::string filename=file_manager->getChallengeFile("tutorials.xml");
XMLNode* root = file_manager->createXMLTree(filename);
if(!root || root->getName() != "challenges")
if(!root || root->getName() != "tutorials")
{
std::cerr << "Challenge file '" << filename << "' will be created."
std::cerr << "Tutorial file '" << filename << "' will be created."
<< std::endl;
save();
@@ -230,8 +229,8 @@ void TutorialManager::load()
//-----------------------------------------------------------------------------
void TutorialManager::save()
{
//std::ofstream challenge_file;
//std::string filename = file_manager->getChallengeFile("challenges.xml");
std::ofstream tutorial_file;
//std::string filename = file_manager->getChallengeFile("tutorial.xml");
//challenge_file.open(filename.c_str());
//if(!challenge_file.is_open())
@@ -253,10 +252,6 @@ void TutorialManager::save()
//challenge_file.close();
} // save
void TutorialManager::playLockSound() const
{
m_locked_sound->play();
}
//-----------------------------------------------------------------------------
void TutorialManager::computeActive()

View File

@@ -34,13 +34,13 @@ class SFXBase;
*/
class TutorialManager : public NoCopy
{
private:
typedef std::map<std::string, Tutorial*> AllTutorialsType;
SFXBase *m_locked_sound;
AllTutorialsType m_all_tutorials;
std::map<std::string, bool> m_locked_tutorials;
std::vector<const Tutorial*> m_unlocked_tutorials;
void computeActive ();
void load ();
@@ -53,31 +53,16 @@ public:
void addTutorial (Tutorial * m_tutorial);
void addTutorial (const std::string& filename);
void save ();
vector<const Tutorial*> getActiveTutorials();
/** Returns the list of recently unlocked features (e.g. call at the end of a
race to know if any features were unlocked) */
const vector<const Tutorial*> getRecentlyUnlockedFeatures() {return m_unlocked_tutorials;}
/** Clear the list of recently unlocked challenges */
void clearUnlocked () {m_unlocked_tutorials.clear(); }
vector <const Tutorial*> getTutorialsList();
/** Returns a complete list of all solved challenges */
const vector<const Tutorial*> getUnlockedTutorials();
/** Returns the list of currently inaccessible (locked) challenges */
const vector<const Tutorial*> getLockedTutorials();
const Tutorial *getTutorial (const std::string& id);
/*void raceFinished ();
void grandPrixFinished ();
void lockFeature (Tutorial* tutorial);
bool isLocked (const string& feature);*/
/** Eye- (or rather ear-) candy. Play a sound when user tries to access a locked area */
void playLockSound() const;
void raceFinished ();
}; // UnlockManager
//extern UnlockManager* unlock_manager;