Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 10, 2009, 11:41:48 PM (15 years ago)
Author:
dafrick
Message:

Some Quest stuff, and the rest for the GUIOverlay I failed to commit before.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/orxonox/objects/quest/QuestManager.cc

    r2911 r2963  
    3636
    3737#include "core/CoreIncludes.h"
     38#include "core/ConsoleCommand.h"
     39#include "core/input/InputManager.h"
     40#include "util/Convert.h"
    3841
    3942#include "util/Exception.h"
     43#include "gui/GUIManager.h"
    4044#include "Quest.h"
    4145#include "QuestHint.h"
     
    4448{
    4549    //! Pointer to the current (and single) instance of this class.
    46     QuestManager* QuestManager::singletonRef_s = NULL;
     50    /*static*/ QuestManager* QuestManager::singletonRef_s = NULL;
     51    /*static*/ bool QuestManager::GUIOpen = false;
     52
     53    SetConsoleCommand(QuestManager, toggleQuestGUI, true);
    4754
    4855    /**
     
    213220    }
    214221
     222    QuestContainer* QuestManager::getQuestTree(std::string & name)
     223    {
     224        GUIOverlay* gui = GUIManager::getInstance().getOverlay(name);
     225
     226        PlayerInfo* player;
     227        if(gui == NULL)
     228        {
     229            COUT(1) << "Something BAD happened." << std::endl;
     230            return NULL;
     231        }
     232        COUT(1) << player << std::endl;
     233        ConverterExplicit<BaseObject, PlayerInfo>::convert(player, *(gui->getOwner()));
     234   
     235        QuestContainer* root = NULL;
     236        QuestContainer* current = NULL;
     237       
     238        std::list<Quest*>* pRootQuests = new std::list<Quest*>();
     239        std::list<Quest*> rootQuests = *pRootQuests;
     240        getRootQuests(player, rootQuests);
     241       
     242        for(std::list<Quest*>::iterator it = rootQuests.begin(); it != rootQuests.end(); it++)
     243        {
     244            Quest* quest = *it;
     245           
     246            QuestContainer* container = new QuestContainer;
     247
     248            container->description = quest->getDescription();
     249            addHints(container, quest, player);
     250            addSubQuests(container, quest, player);
     251
     252            if(root == NULL)
     253            {
     254                root = container;
     255            }
     256            else
     257            {
     258                current->next = container;
     259            }
     260           
     261            current = container;
     262
     263        }
     264        if(current != NULL)
     265            current->next = NULL;
     266
     267        delete pRootQuests;
     268
     269        return root;
     270    }
     271
     272    void QuestManager::getRootQuests(const PlayerInfo* player, std::list<Quest*> & list)
     273    {
     274        for(std::map<std::string, Quest*>::iterator it=this->questMap_.begin(); it!=this->questMap_.end(); it++)
     275        {
     276            Quest* quest = (*it).second;
     277            if(quest->getParentQuest() == NULL && !quest->isInactive(player))
     278            {
     279                list.push_back(quest);
     280            }
     281        }
     282    }
     283
     284    void QuestManager::addSubQuests(QuestContainer* container, Quest* quest, const PlayerInfo* player)
     285    {
     286        QuestContainer* current = NULL;
     287        QuestContainer* first = NULL;
     288
     289        std::list<Quest*> quests = quest->getSubQuestList();
     290        for(std::list<Quest*>::iterator it = quests.begin(); it != quests.end(); it++)
     291        {
     292            Quest* subQuest = *it;
     293            if(!subQuest->isInactive(player))
     294            {
     295                QuestContainer* subQuestContainer = new QuestContainer;
     296
     297                subQuestContainer->description = subQuest->getDescription();
     298                addHints(subQuestContainer, subQuest, player);
     299                addSubQuests(subQuestContainer, subQuest, player);
     300
     301                if(first == NULL)
     302                {
     303                    first = subQuestContainer;
     304                }
     305                else
     306                {
     307                    current->next = subQuestContainer;
     308                }
     309               
     310                current = subQuestContainer;
     311            }
     312        }
     313
     314        if(current != NULL)
     315            current->next = NULL;
     316        container->subQuests = first;
     317       
     318    }
     319
     320    void QuestManager::addHints(QuestContainer* container, Quest* quest, const PlayerInfo* player)
     321    {
     322        HintContainer* current = NULL;
     323        HintContainer* first = NULL;
     324
     325        std::list<QuestHint*> hints = quest->getHintsList();
     326        for(std::list<QuestHint*>::iterator it = hints.begin(); it != hints.end(); it++)
     327        {
     328            if((*it)->isActive(player))
     329            {
     330                HintContainer* hint = new HintContainer;
     331                hint->description = (*it)->getDescription();
     332
     333                if(first == NULL)
     334                {
     335                    first = hint;
     336                }
     337                else
     338                {
     339                    current->next = hint;
     340                }
     341               
     342                current = hint;
     343            }
     344        }
     345
     346        if(current != NULL)
     347            current->next = NULL;
     348        container->hint = first;
     349    }
     350
     351    /*static*/ void QuestManager::toggleQuestGUI(void)
     352    {
     353        if (!QuestManager::GUIOpen)
     354        {
     355            GUIManager::getInstancePtr()->showGUI("QuestGUI");
     356            GUIManager::getInstancePtr()->executeCode("showCursor()");
     357            InputManager::getInstance().requestEnterState("guiMouseOnly");
     358            GUIManager::getInstancePtr()->executeCode("loadQuestsList()");
     359            GUIOpen = true;
     360        }
     361        else
     362        {
     363            GUIManager::getInstancePtr()->executeCode("hideGUI(\"QuestGUI\")");
     364            GUIManager::getInstancePtr()->executeCode("hideCursor()");
     365            InputManager::getInstance().requestLeaveState("guiMouseOnly");
     366            GUIOpen = false;
     367        }
     368    }
     369
    215370
    216371}
Note: See TracChangeset for help on using the changeset viewer.