Tutorial incremental commit. Add main loading and improving xml loading

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@7150 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
aeonphyxius 2010-12-23 13:38:38 +00:00
parent d8afbe9750
commit 86ba25bc59
7 changed files with 48 additions and 292 deletions

View File

@ -43,6 +43,7 @@
#include "audio/music_manager.hpp"
#include "audio/sfx_manager.hpp"
#include "challenges/unlock_manager.hpp"
#include "tutorial/tutorial_manager.hpp"
#include "config/stk_config.hpp"
#include "config/user_config.hpp"
#include "config/player.hpp"
@ -679,6 +680,7 @@ int main(int argc, char *argv[] )
GUIEngine::addLoadingIcon( irr_driver->getTexture(file_manager->getGUIDir() + "/options_video.png") );
kart_properties_manager -> loadAllKarts ();
unlock_manager = new UnlockManager();
//m_tutorial_manager = new TutorialManager();
GUIEngine::addLoadingIcon( irr_driver->getTexture(file_manager->getTextureFile("gui_lock.png")) );
projectile_manager -> loadData ();

View File

@ -140,14 +140,10 @@ void TutorialScreen::eventCallback(GUIEngine::Widget* widget, const std::string&
const std::string& selection = tutorials->getSelectionInternalName();
if (selection == BASIC_DRIVING)
{
//FIXME: simplify and centralize race start sequence!!
// Verify the kart in the config exists
if (kart_properties_manager->getKart(UserConfigParams::m_default_kart) == NULL)
{
UserConfigParams::m_default_kart.revertToDefaults();
}
// Use latest used device
InputDevice* device = input_manager->getDeviceList()->getLatestUsedDevice();
@ -170,8 +166,9 @@ void TutorialScreen::eventCallback(GUIEngine::Widget* widget, const std::string&
network_manager->initCharacterDataStructures();
// Launch tutorial
//tutorial_manager->getTutorial(selection)->setRace();
//m_tutorial_manager->getTutorial(selection)->setRace();
// FIXME this code have to be in Tutorial class (and loaded from file xD)
RaceManager::MajorRaceModeType m_major;
RaceManager::MinorRaceModeType m_minor;
@ -189,9 +186,8 @@ void TutorialScreen::eventCallback(GUIEngine::Widget* widget, const std::string&
race_manager->setNumLaps(1);
race_manager->setNumKarts(1);
race_manager->setNumPlayers(1);
race_manager->setNumLocalPlayers(1);
//race_manager->setCoinTarget(m_energy);
race_manager->setNumLocalPlayers(1);
//race_manager->setCoinTarget(m_energy);*/
// Sets up kart info, including random list of kart for AI
network_manager->setupPlayerKartInfo();

View File

@ -32,9 +32,8 @@ const std::string COLLECTIBLE_WEAPONS = "cw";
const std::string SHOOTING_BACKWARDS = "sb";
class TutorialScreen : public GUIEngine::Screen, public GUIEngine::ScreenSingleton<TutorialScreen>
{
{
friend class GUIEngine::ScreenSingleton<TutorialScreen>;
TutorialScreen();
@ -42,7 +41,6 @@ class TutorialScreen : public GUIEngine::Screen, public GUIEngine::ScreenSinglet
public:
/** \brief implement callback from parent class GUIEngine::Screen */
virtual void loadedFromFile();

View File

@ -35,7 +35,7 @@ using namespace std; // To avoid using std:: all the time
using namespace irr::core;
class XMLNode;
enum REWARD_TYPE
/*enum REWARD_TYPE
{UNLOCK_TRACK,
UNLOCK_GP,
UNLOCK_MODE,

View File

@ -44,7 +44,7 @@ private:
int m_energy;
std::string m_filename;
void getUnlocks(const XMLNode *root, const std:: string type, REWARD_TYPE reward);
// void getUnlocks(const XMLNode *root, const std:: string type, REWARD_TYPE reward);
void error(const char *id) const;
public:

View File

@ -31,7 +31,7 @@
#include "tracks/track_manager.hpp"
#include "utils/string_utils.hpp"
TutorialManager* tutorial_manager=0;
TutorialManager * m_tutorial_manager=0;
//-----------------------------------------------------------------------------
TutorialManager::TutorialManager()
@ -39,105 +39,20 @@ TutorialManager::TutorialManager()
// The global variable 'tutorial_manager' is needed in the tutorials,
// but it's not set yet - so we define it here (and it gets re-assign
// in main).
tutorial_manager=this;
m_locked_sound = sfx_manager->createSoundSource("locked");
m_tutorial_manager = this;
// FIXME : Read tutorials from .../data
// -----------------------------
//std::set<std::string> result;
//file_manager->listFiles(result, "data");
//for(std::set<std::string>::iterator i = result.begin();
// i != result.end() ; i++)
//{
// if (StringUtils::hasSuffix(*i, ".challenge"))
// addChallenge(file_manager->getDataFile(*i));
//} // for i
std::set<std::string> result;
file_manager->listFiles(result, "data/grandprix");
for(std::set<std::string>::iterator i = result.begin();
i != result.end() ; i++)
{
if (StringUtils::hasSuffix(*i, ".tutorial"))
addTutorial(file_manager->getDataFile("grandprix/"+*i));
}
//// Read tutorials from .../data/tracks/*
//// --------------------------------------
//const std::vector<std::string> *all_track_dirs = track_manager->getAllTrackDirs();
//for(std::vector<std::string>::const_iterator dir=all_track_dirs->begin();
// dir!=all_track_dirs->end(); dir++)
//{
// std::set<std::string> all_files;
// file_manager->listFiles(all_files, *dir, /*is_full_path*/ true);
// for(std::set<std::string>::iterator file=all_files.begin();
// file!=all_files.end(); file++)
// {
// if(!StringUtils::hasSuffix(*file,".challenge")) continue;
// std::string filename=*dir+"/"+*file;
// FILE *f=fopen(filename.c_str(), "r");
// if(f)
// {
// fclose(f);
// ChallengeData* newChallenge = NULL;
// try
// {
// newChallenge = new ChallengeData(filename);
// }
// catch (std::runtime_error& ex)
// {
// std::cerr << "\n/!\\ An error occurred while loading challenge file '" << filename << "' : "
// << ex.what() << " : challenge will be ignored.\n\n";
// continue;
// }
// addChallenge(newChallenge);
// } // if file
// } // for file in files
//} // for dir in all_track_dirs
//// Load challenges from .../data/karts (FIXME: the code below is just copied and pasted from above xD)
//// -----------------------------------
//const std::vector<std::string> *all_kart_dirs =
// kart_properties_manager->getAllKartDirs();
//// Find out which characters are available and load them
//for(std::vector<std::string>::const_iterator dir = all_kart_dirs->begin();
// dir != all_kart_dirs->end(); dir++)
//{
// std::set<std::string> all_files;
// file_manager->listFiles(all_files, *dir, /*is_full_path*/ true);
// for(std::set<std::string>::iterator file=all_files.begin();
// file!=all_files.end(); file++)
// {
// if(!StringUtils::hasSuffix(*file,".challenge")) continue;
// std::string filename=*dir+"/"+*file;
// FILE *f=fopen(filename.c_str(), "r");
// if(f)
// {
// fclose(f);
//
// ChallengeData* newChallenge = NULL;
// try
// {
// newChallenge = new ChallengeData(filename);
// }
// catch (std::runtime_error& ex)
// {
// std::cerr << "\n/!\\ An error occurred while loading challenge file '" << filename << "' : "
// << ex.what() << " : challenge will be ignored.\n\n";
// continue;
// }
// addChallenge(newChallenge);
// } // if file
// } // for file in files
//} // for dir in all_karts_dirs
//// Challenges from .../data/grandprix
//// ----------------------------------
//file_manager->listFiles(result, "data/grandprix");
//for(std::set<std::string>::iterator i = result.begin();
// i != result.end() ; i++)
//{
// if (StringUtils::hasSuffix(*i, ".challenge"))
// addChallenge(file_manager->getDataFile("grandprix/"+*i));
//} // for i
//// Hard coded challenges can be added here.
//computeActive(); //FIXME: 'load' calls 'computeActive', not sure this call here is needed
// Hard coded challenges can be added here.
load();
} // UnlockManager
@ -156,27 +71,27 @@ TutorialManager::~TutorialManager()
//-----------------------------------------------------------------------------
void TutorialManager::addTutorial(Tutorial * m_tutorial)
{
m_all_tutorials[m_tutorial->getId()]=m_tutorial;
m_tutorials_list[m_tutorial->getId()]=m_tutorial;
} // addTutorial
//-----------------------------------------------------------------------------
void TutorialManager::addTutorial(const std::string& filename)
{
/* ChallengeData* newChallenge = NULL;
TutorialData* m_tutorial = NULL;
try
{
newChallenge = new ChallengeData(filename);
newChallenge->check();
m_tutorial = new TutorialData(filename);
m_tutorial->check();
}
catch (std::runtime_error& ex)
{
std::cerr << "\n/!\\ An error occurred while loading challenge file '" << filename << "' : "
<< ex.what() << " : challenge will be ignored.\n\n";
if (newChallenge != NULL) delete newChallenge;
std::cerr << "\n/!\\ An error occurred while loading tutorial file '" << filename << "' : "
<< ex.what() << " : tutorial will be ignored.\n\n";
if (m_tutorial != NULL) delete m_tutorial;
return;
}
addChallenge(newChallenge);*/
addTutorial(m_tutorial);
} // addChallenge
@ -184,19 +99,19 @@ void TutorialManager::addTutorial(const std::string& filename)
std::vector<const Tutorial*> TutorialManager::getTutorialsList()
{
std::vector<const Tutorial*> all_active;
//for(AllChallengesType::iterator i =m_all_challenges.begin();
// i!=m_all_challenges.end(); i++)
//{
// if(i->second->isActive()) all_active.push_back(i->second);
//}
for(TutorialsList::iterator i = m_tutorials_list.begin();
i!=m_tutorials_list.end(); i++)
{
if(i->second->isActive()) all_active.push_back(i->second);
}
return all_active;
} // getActiveChallenges
//-----------------------------------------------------------------------------
const Tutorial* TutorialManager::getTutorial(const std::string& id)
{
if(m_all_tutorials.find(id) == m_all_tutorials.end()) return NULL;
return m_all_tutorials[id];
if(m_tutorials_list.find(id) == m_tutorials_list.end()) return NULL;
return m_tutorials_list[id];
} // getTutorial
/*-----------------------------------------------------------------------------
@ -216,13 +131,11 @@ void TutorialManager::load()
return;
}
for(AllTutorialsType::iterator i = m_all_tutorials.begin();
i!= m_all_tutorials.end(); i++)
for(TutorialsList::iterator i = m_tutorials_list.begin();
i!= m_tutorials_list.end(); i++)
{
// i->second->load(root);
}
computeActive();
delete root;
} // load
@ -253,149 +166,3 @@ void TutorialManager::save()
} // save
//-----------------------------------------------------------------------------
void TutorialManager::computeActive()
{
// for(AllChallengesType::iterator i =m_all_challenges.begin();
// i!=m_all_challenges.end(); i++)
// {
// // Changed challenge
// // -----------------
// if((i->second)->isSolved())
// {
// // The constructor calls computeActive, which actually locks
// // all features, so unlock the solved ones (and don't try to
// // save the state, since we are currently reading it)
//
// unlockFeature(i->second, /*save*/ false);
// continue;
// }
//
// // Otherwise lock the feature, and check if the challenge is active
// // ----------------------------------------------------------------
// lockFeature(i->second);
// std::vector<std::string> pre_req=(i->second)->getPrerequisites();
// bool allSolved=true;
// for(std::vector<std::string>::iterator pre =pre_req.begin();
// pre!=pre_req.end(); pre++)
// {
// const Challenge*p = getChallenge(*pre);
// if(!p)
// {
// fprintf(stderr,"Challenge prerequisite '%s' of '%s' not found - ignored\n",
// pre->c_str(), i->first.c_str());
// //continue;
// allSolved=false;
// break;
// }
// else if(!p->isSolved())
// {
// allSolved=false;
// break;
// }
// } // for all pre in pre_req
// if(allSolved)
// {
// i->second->setActive();
// } // if solved
// } // for i
// clearUnlocked();
//
} // computeActive
/*-----------------------------------------------------------------------------
** This is called when a race is finished. Call all active challenges
*/
//void TutorialManager::raceFinished()
//{
// //for(AllChallengesType::iterator i =m_all_challenges.begin();
// // i!=m_all_challenges.end(); i++)
// //{
// // if(i->second->isActive() && i->second->raceFinished())
// // {
// // unlockFeature(i->second);
// // } // if isActive && challenge solved
// //}
// //race_manager->setCoinTarget(0); //reset
//} // raceFinished
////-----------------------------------------------------------------------------
//void UnlockManager::grandPrixFinished()
//{
// for(AllChallengesType::iterator i =m_all_challenges.begin();
// i!=m_all_challenges.end(); i++)
// {
// if(i->second->isActive() && i->second->grandPrixFinished())
// {
// std::cout << "===== A FEATURE WAS UNLOCKED BECAUSE YOU WON THE GP!! ==\n";
// unlockFeature(i->second);
// }
// }
// race_manager->setCoinTarget(0);
//} // grandPrixFinished
////-----------------------------------------------------------------------------
//void UnlockManager::lockFeature(Challenge* 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;
//} // lockFeature
//
////-----------------------------------------------------------------------------
//void UnlockManager::unlockFeature(Challenge* 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::map<std::string,bool>::iterator p=m_locked_features.find(feature);
// if(p==m_locked_features.end())
// {
// //fprintf(stderr,"Unlocking feature '%s' failed: feature is not locked.\n",
// // (feature).c_str());
// return;
// }
// m_locked_features.erase(p);
// }
//
// // Add to list of recently unlocked features
// m_unlocked_features.push_back(c);
// c->setSolved(); // reset isActive flag
//
// // Save the new unlock information
// if(do_save) save();
//} // unlockFeature
//
////-----------------------------------------------------------------------------
//bool UnlockManager::isLocked(const std::string& feature)
//{
// return m_locked_features.find(feature)!=m_locked_features.end();
//} // featureIsLocked
////-----------------------------------------------------------------------------
//const std::vector<const Challenge*> UnlockManager::getUnlockedFeatures()
//{
// std::vector<const Challenge*> out;
//
// for(AllChallengesType::const_iterator i =m_all_challenges.begin();
// i!=m_all_challenges.end(); i++)
// {
// if (i->second->isSolved()) out.push_back(i->second);
// }
//
// return out;
//}
////-----------------------------------------------------------------------------
//const std::vector<const Challenge*> UnlockManager::getLockedChallenges()
//{
// std::vector<const Challenge*> out;
//
// for(AllChallengesType::const_iterator i =m_all_challenges.begin();
// i!=m_all_challenges.end(); i++)
// {
// if (!i->second->isSolved() && !i->second->isActive()) out.push_back(i->second);
// }
//
// return out;
//}

View File

@ -21,12 +21,13 @@
#include <map>
#include "tutorial/tutorial.hpp"
#include "tutorial/tutorial_data.hpp"
#include "utils/no_copy.hpp"
#include <fstream>
class XMLNode;
class SFXBase;
/**
* \brief main class to handle the tutorials list
@ -36,34 +37,26 @@ class TutorialManager : public NoCopy
{
private:
typedef std::map<std::string, Tutorial*> AllTutorialsType;
typedef std::map<std::string, Tutorial*> TutorialsList;
TutorialsList m_tutorials_list;
SFXBase *m_locked_sound;
AllTutorialsType m_all_tutorials;
std::map<std::string, bool> m_locked_tutorials;
void computeActive ();
void load ();
void unlockFeature (Tutorial* t, bool do_save=true);
public:
TutorialManager ();
~TutorialManager ();
void addTutorial (Tutorial * m_tutorial);
void addTutorial (const std::string& filename);
void save ();
vector <const Tutorial*> getTutorialsList();
/** Returns a complete list of all solved challenges */
const vector<const Tutorial*> getUnlockedTutorials();
const Tutorial *getTutorial (const std::string& id);
void raceFinished ();
void raceFinished ();
}; // UnlockManager
}; // TutorialManager
//extern UnlockManager* unlock_manager;
extern TutorialManager * m_tutorial_manager;
#endif // TUTORIALMANAGER_H