Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5745 for code/trunk/src


Ignore:
Timestamp:
Sep 13, 2009, 3:04:02 PM (15 years ago)
Author:
dafrick
Message:

QuestGUI almost working…

Location:
code/trunk/src/modules/questsystem
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/modules/questsystem/CMakeLists.txt

    r5738 r5745  
    1212  QuestEffect.cc
    1313  QuestEffectBeacon.cc
     14  QuestGUINode.cc
     15  QuestGUI.cc
    1416  QuestHint.cc
    1517  QuestItem.cc
  • code/trunk/src/modules/questsystem/QuestManager.cc

    r5738 r5745  
    3737#include "core/CoreIncludes.h"
    3838#include "core/GUIManager.h"
     39#include "core/ConsoleCommand.h"
     40#include "core/input/InputManager.h" //TDO: Necessary?
     41#include <CEGUIWindow.h>
     42#include "overlays/GUIOverlay.h"
    3943
    4044#include "infos/PlayerInfo.h"
    4145#include "Quest.h"
    4246#include "QuestHint.h"
    43 #include "QuestItem.h"
     47#include "QuestItem.h" //TDO: Necessary?
    4448
    4549namespace orxonox
     
    6569    QuestManager::~QuestManager()
    6670    {
     71        for(std::map<PlayerInfo*, QuestGUI*>::iterator it = this->questGUIs_.begin(); it != this->questGUIs_.end(); it++)
     72        {
     73            delete (*it).second;
     74        }
     75        this->questGUIs_.clear();
     76    }
     77
     78    /**
     79    @brief
     80        Retreive all Quests.
     81    @return
     82        Returns a map with all Quests indexed by their id's.
     83    */
     84    std::map<std::string, Quest*> & QuestManager::getQuests(void)
     85    {
     86        return this->questMap_;
    6787    }
    6888
     
    201221    /**
    202222    @brief
    203 
    204     @param name
    205     @return
    206     */
    207     QuestContainer* QuestManager::getQuestTree(std::string & name)
    208     {
    209         PlayerInfo* player = GUIManager::getInstance().getPlayer(name);
     223        Retreive the main window for the GUI.
     224        This is for the use in the lua script tu start the QuestGUI.
     225    @param guiName
     226        The name of the GUI.
     227    @return
     228        Returns a CEGUI Window.
     229    */
     230    CEGUI::Window* QuestManager::getQuestGUI(const std::string & guiName)
     231    {
     232        PlayerInfo* player = this->retreivePlayer(guiName);
     233
     234        if(this->questGUIs_.find(player) == this->questGUIs_.end()) //!< Create a new GUI, if there is none, yet.
     235            this->questGUIs_[player] = new QuestGUI(player);
     236
     237        return this->questGUIs_[player]->getGUI();
     238    }
     239
     240    /**
     241    @brief
     242        Retrieve the player for a certain GUI.
     243    @param guiName
     244        The name of the GUI the player is retrieved for.
     245    @return
     246        Returns the player.
     247    @todo
     248        This very well might be outdated. So: Check if still needed, and update if necessary.
     249    */
     250    PlayerInfo* QuestManager::retreivePlayer(const std::string & guiName)
     251    {
     252        PlayerInfo* player = GUIManager::getInstance().getPlayer(guiName);
    210253        if(player == NULL)
    211254        {
    212             COUT(1) << "Error: GUIOverlay with name '" << name << "' has no player." << std::endl;
     255            COUT(1) << "Error: GUIOverlay with name '" << guiName << "' has no player." << std::endl;
    213256            return NULL;
    214257        }
    215258
    216         QuestContainer* root = NULL;
    217         QuestContainer* current = NULL;
    218 
    219         std::list<Quest*>* rootQuests = new std::list<Quest*>();
    220         getRootQuests(player, *rootQuests);
    221 
    222         for(std::list<Quest*>::iterator it = rootQuests->begin(); it != rootQuests->end(); it++)
    223         {
    224             QuestContainer* container = addSubQuest(*it, player);
    225 
    226             if(root == NULL)
    227             {
    228                 root = container;
    229             }
    230             else
    231             {
    232                 current->next = container;
    233             }
    234 
    235             current = container;
    236 
    237         }
    238         if(current != NULL)
    239             current->next = NULL;
    240 
    241         delete rootQuests;
    242 
    243         return root;
    244     }
    245 
    246     /**
    247     @brief
    248 
    249     @param player
    250     @param list
    251     @return
    252     */
    253     void QuestManager::getRootQuests(const PlayerInfo* player, std::list<Quest*> & list)
    254     {
    255         for(std::map<std::string, Quest*>::iterator it=this->questMap_.begin(); it!=this->questMap_.end(); it++)
    256         {
    257             Quest* quest = (*it).second;
    258             if(quest->getParentQuest() == NULL && !quest->isInactive(player))
    259             {
    260                 list.push_back(quest);
    261             }
    262         }
    263     }
    264 
    265     /**
    266     @brief
    267 
    268     @param quest
    269     @param player
    270     @return
    271     */
    272     QuestContainer* QuestManager::addSubQuest(Quest* quest, const PlayerInfo* player)
    273     {
    274         if(quest == NULL)
    275             return NULL;
    276 
    277         QuestContainer* container = new QuestContainer;
    278         container->description = quest->getDescription();
    279         container->hint = addHints(quest, player);
    280 
    281         if(quest->isActive(player))
    282         {
    283             container->status = "active";
    284         }
    285         else if(quest->isCompleted(player))
    286         {
    287             container->status = "completed";
    288         }
    289         else if(quest->isFailed(player))
    290         {
    291             container->status = "failed";
    292         }
    293         else
    294         {
    295             container->status = "";
    296             COUT(1) << "An error occurred. A Quest of un-specified status wanted to be displayed." << std::endl;
    297         }
    298 
    299         std::list<Quest*> quests = quest->getSubQuestList();
    300         QuestContainer* current = NULL;
    301         QuestContainer* first = NULL;
    302         for(std::list<Quest*>::iterator it = quests.begin(); it != quests.end(); it++)
    303         {
    304             Quest* subQuest = *it;
    305             if(!subQuest->isInactive(player))
    306             {
    307                 QuestContainer* subContainer = addSubQuest(subQuest, player);
    308 
    309                 if(first == NULL)
    310                 {
    311                     first = subContainer;
    312                 }
    313                 else
    314                 {
    315                     current->next = subContainer;
    316                 }
    317 
    318                 current = subContainer;
    319             }
    320         }
    321         if(current != NULL)
    322             current->next = NULL;
    323         container->subQuests = first;
    324 
    325         return container;
    326     }
    327 
    328     /**
    329     @brief
    330 
    331     @param quest
    332     @param player
    333     @return
    334     */
    335     HintContainer* QuestManager::addHints(Quest* quest, const PlayerInfo* player)
    336     {
    337         HintContainer* current = NULL;
    338         HintContainer* first = NULL;
    339 
    340         std::list<QuestHint*> hints = quest->getHintsList();
    341         for(std::list<QuestHint*>::iterator it = hints.begin(); it != hints.end(); it++)
    342         {
    343             if((*it)->isActive(player))
    344             {
    345                 HintContainer* hint = new HintContainer;
    346                 hint->description = (*it)->getDescription();
    347 
    348                 if(first == NULL)
    349                 {
    350                     first = hint;
    351                 }
    352                 else
    353                 {
    354                     current->next = hint;
    355                 }
    356 
    357                 current = hint;
    358             }
    359         }
    360 
    361         if(current != NULL)
    362             current->next = NULL;
    363         return first;
    364     }
    365 
     259        return player;
     260    }
    366261
    367262}
  • code/trunk/src/modules/questsystem/QuestManager.h

    r5738 r5745  
    3636
    3737#include "questsystem/QuestsystemPrereqs.h"
     38#include <CEGUIForwardRefs.h>
    3839
    3940#include <list>
     
    4445#include "core/OrxonoxClass.h"
    4546
     47#include "QuestGUI.h"
     48
    4649// tolua_begin
    4750namespace orxonox
    4851{
    49 
    50     struct QuestContainer;
    51     struct HintContainer;
    52 
    53     struct QuestContainer
    54     {
    55         const QuestDescription* description;
    56         std::string status;
    57         HintContainer* hint;
    58         QuestContainer* subQuests;
    59         QuestContainer* next;
    60     };
    61 
    62     struct HintContainer
    63     {
    64         const QuestDescription* description;
    65         HintContainer* next;
    66     };
    6752
    6853    typedef ScopedSingleton<QuestManager, ScopeID::GSLevel> ScopedSingletonQuestManagerGSLevel; // workaround for tolua
     
    7863    {
    7964// tolua_end
     65
    8066            friend class ScopedSingleton<QuestManager, ScopeID::GSLevel>;
     67            friend class QuestGUI; //TDO: better solution.
     68            //friend std::map<std::string, Quest*> & QuestGUI::getQuests(void);
     69
    8170        public:
    8271            QuestManager();
     
    8675            static QuestManager& getInstance() { return ScopedSingleton<QuestManager, ScopeID::GSLevel>::getInstance(); } // tolua_export
    8776
     77            //! Retreive the main window for the GUI.
     78            CEGUI::Window* getQuestGUI(const std::string & guiName); // tolua_export
     79
    8880            bool registerQuest(Quest* quest); //!< Registers a Quest in the QuestManager.
    8981            bool registerHint(QuestHint* quest); //!< Registers a QuestHint in the QuestManager.
     
    9284            QuestHint* findHint(const std::string & hintId); //!< Returns the QuestHint with the input id.
    9385
    94             QuestContainer* getQuestTree(std::string & name); // tolua_export
     86        protected:
     87            std::map<std::string, Quest*> & getQuests(void); //!< Retreive all Quests.
    9588
    9689        private:
    9790            static QuestManager* singletonPtr_s;
     91            PlayerInfo* retreivePlayer(const std::string & guiName); //!< Retrieve the player for a certain GUI.
    9892
    9993            std::map<std::string, Quest*> questMap_; //!< All Quests registered by their id's.
    10094            std::map<std::string, QuestHint*> hintMap_; //!< All QuestHints registered by their id's.
    10195
    102             void getRootQuests(const PlayerInfo* player, std::list<Quest*> & list);
    103             HintContainer* addHints(Quest* quest, const PlayerInfo* player);
    104             QuestContainer* addSubQuest(Quest* quest, const PlayerInfo* player);
     96            //TDO: Call destructor of QuestGUI's on destruction of QuestManager?
     97            std::map<PlayerInfo*, QuestGUI*> questGUIs_; //!< All GUI's registered by the players.
    10598
    10699    }; // tolua_export
  • code/trunk/src/modules/questsystem/QuestsystemPrereqs.h

    r5738 r5745  
    7676    class QuestEffect;
    7777    class QuestEffectBeacon;
     78    class QuestGUINode;
     79    class QuestGUI;
    7880    class QuestHint;
    7981    class QuestItem;
Note: See TracChangeset for help on using the changeset viewer.