Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2993


Ignore:
Timestamp:
May 20, 2009, 12:23:51 AM (16 years ago)
Author:
dafrick
Message:

Small changes in QuestManager for the GUI. Added toggleVisibility command to OrxonoxOverlay.

Location:
code/trunk/src/orxonox
Files:
4 edited

Legend:

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

    r2963 r2993  
    3838#include "core/ConsoleCommand.h"
    3939#include "core/input/InputManager.h"
    40 #include "util/Convert.h"
    4140
    4241#include "util/Exception.h"
    4342#include "gui/GUIManager.h"
     43#include "objects/infos/PlayerInfo.h"
    4444#include "Quest.h"
    4545#include "QuestHint.h"
     
    4949    //! Pointer to the current (and single) instance of this class.
    5050    /*static*/ QuestManager* QuestManager::singletonRef_s = NULL;
    51     /*static*/ bool QuestManager::GUIOpen = false;
    52 
    53     SetConsoleCommand(QuestManager, toggleQuestGUI, true);
    5451
    5552    /**
     
    220217    }
    221218
     219    /**
     220    @brief
     221       
     222    @param name
     223    @return
     224    */
    222225    QuestContainer* QuestManager::getQuestTree(std::string & name)
    223226    {
     
    227230        if(gui == NULL)
    228231        {
    229             COUT(1) << "Something BAD happened." << std::endl;
     232            COUT(1) << "Error: No GUIOverlay with the given name '" << name << "' present." << std::endl;
    230233            return NULL;
    231234        }
    232         COUT(1) << player << std::endl;
    233         ConverterExplicit<BaseObject, PlayerInfo>::convert(player, *(gui->getOwner()));
     235        BaseObject* obj = gui->getOwner();
     236        if(obj == NULL)
     237        {
     238            COUT(1) << "Error: GUIOverlay has no owner. " << std::endl;
     239            return NULL;
     240        }
     241        player = dynamic_cast<PlayerInfo*>(obj);
    234242   
    235243        QuestContainer* root = NULL;
    236244        QuestContainer* current = NULL;
    237245       
    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);
     246        std::list<Quest*>* rootQuests = new std::list<Quest*>();
     247        getRootQuests(player, *rootQuests);
     248       
     249        for(std::list<Quest*>::iterator it = rootQuests->begin(); it != rootQuests->end(); it++)
     250        {
     251            QuestContainer* container = addSubQuest(*it, player);
    251252
    252253            if(root == NULL)
     
    265266            current->next = NULL;
    266267
    267         delete pRootQuests;
     268        delete rootQuests;
    268269
    269270        return root;
    270271    }
    271272
     273    /**
     274    @brief
     275       
     276    @param player
     277    @param list
     278    @return
     279    */
    272280    void QuestManager::getRootQuests(const PlayerInfo* player, std::list<Quest*> & list)
    273281    {
     
    282290    }
    283291
    284     void QuestManager::addSubQuests(QuestContainer* container, Quest* quest, const PlayerInfo* player)
    285     {
     292    /**
     293    @brief
     294       
     295    @param quest
     296    @param player
     297    @return
     298    */
     299    QuestContainer* QuestManager::addSubQuest(Quest* quest, const PlayerInfo* player)
     300    {
     301        if(quest == NULL)
     302            return NULL;
     303
     304        QuestContainer* container = new QuestContainer;
     305        container->description = quest->getDescription();
     306        container->hint = addHints(quest, player);
     307
     308        if(quest->isActive(player))
     309        {
     310            container->status = "active";
     311        }
     312        else if(quest->isCompleted(player))
     313        {
     314            container->status = "completed";
     315        }
     316        else if(quest->isFailed(player))
     317        {
     318            container->status = "failed";
     319        }
     320        else
     321        {
     322            container->status = "";
     323            COUT(1) << "An error occured. A Quest of un-specified status wanted to be displayed." << std::endl;
     324        }
     325       
     326        std::list<Quest*> quests = quest->getSubQuestList();
    286327        QuestContainer* current = NULL;
    287328        QuestContainer* first = NULL;
    288 
    289         std::list<Quest*> quests = quest->getSubQuestList();
    290329        for(std::list<Quest*>::iterator it = quests.begin(); it != quests.end(); it++)
    291330        {
     
    293332            if(!subQuest->isInactive(player))
    294333            {
    295                 QuestContainer* subQuestContainer = new QuestContainer;
    296 
    297                 subQuestContainer->description = subQuest->getDescription();
    298                 addHints(subQuestContainer, subQuest, player);
    299                 addSubQuests(subQuestContainer, subQuest, player);
     334                QuestContainer* subContainer = addSubQuest(subQuest, player);
    300335
    301336                if(first == NULL)
    302337                {
    303                     first = subQuestContainer;
     338                    first = subContainer;
    304339                }
    305340                else
    306341                {
    307                     current->next = subQuestContainer;
     342                    current->next = subContainer;
    308343                }
    309344               
    310                 current = subQuestContainer;
    311             }
    312         }
    313 
     345                current = subContainer;
     346            }
     347        }
    314348        if(current != NULL)
    315349            current->next = NULL;
    316350        container->subQuests = first;
    317351       
    318     }
    319 
    320     void QuestManager::addHints(QuestContainer* container, Quest* quest, const PlayerInfo* player)
     352        return container;
     353    }
     354
     355    /**
     356    @brief
     357       
     358    @param quest
     359    @param player
     360    @return
     361    */
     362    HintContainer* QuestManager::addHints(Quest* quest, const PlayerInfo* player)
    321363    {
    322364        HintContainer* current = NULL;
     
    346388        if(current != NULL)
    347389            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         }
     390        return first;
    368391    }
    369392
  • code/trunk/src/orxonox/objects/quest/QuestManager.h

    r2963 r2993  
    5555    {
    5656        const QuestDescription* description;
     57        std::string status;
    5758        HintContainer* hint;
    5859        QuestContainer* subQuests;
     
    9394            QuestContainer* getQuestTree(std::string & name); // tolua_export
    9495
    95             static void toggleQuestGUI(void); //!< Opens the GUI.
    96 
    9796        private:
    9897            static QuestManager* singletonRef_s;
    99             static bool GUIOpen;
    10098
    10199            std::map<std::string, Quest*> questMap_; //!< All Quests registered by their id's.
     
    103101
    104102            void getRootQuests(const PlayerInfo* player, std::list<Quest*> & list);
    105             void addHints(QuestContainer* container, Quest* quest, const PlayerInfo* player);
    106             void addSubQuests(QuestContainer* container, Quest* quest, const PlayerInfo* player);
     103            HintContainer* addHints(Quest* quest, const PlayerInfo* player);
     104            QuestContainer* addSubQuest(Quest* quest, const PlayerInfo* player);
    107105
    108106    }; // tolua_export
  • code/trunk/src/orxonox/overlays/OrxonoxOverlay.cc

    r2896 r2993  
    5757    SetConsoleCommand(OrxonoxOverlay, scaleOverlay, false).accessLevel(AccessLevel::User);
    5858    SetConsoleCommand(OrxonoxOverlay, scrollOverlay, false).accessLevel(AccessLevel::User);
     59    SetConsoleCommand(OrxonoxOverlay, toggleVisibility, false).accessLevel(AccessLevel::User);
    5960    SetConsoleCommand(OrxonoxOverlay, rotateOverlay, false).accessLevel(AccessLevel::User);
    6061
     
    311312    /**
    312313    @brief
     314        Toggles the visibility of an Overlay by it's name.
     315    @param name
     316        The name of the overlay defined BaseObject::setName() (usually done with the "name"
     317        attribute in the xml file).
     318    */
     319    /*static*/ void OrxonoxOverlay::toggleVisibility(const std::string& name)
     320    {
     321        std::map<std::string, OrxonoxOverlay*>::const_iterator it = overlays_s.find(name);
     322        if (it != overlays_s.end())
     323        {
     324            OrxonoxOverlay* overlay= (*it).second;
     325            if(overlay->isVisible())
     326                overlay->hide();
     327            else
     328                overlay->show();
     329        }
     330    }
     331
     332    /**
     333    @brief
    313334        Scrolls an overlay by its name.
    314335    @param name
  • code/trunk/src/orxonox/overlays/OrxonoxOverlay.h

    r2896 r2993  
    149149        //! ConsoleCommand: Accesses the overlay by its name and scrolls it.
    150150        static void scrollOverlay(const std::string& name, const Vector2& scroll);
     151        static void toggleVisibility(const std::string& name);
    151152        //! ConsoleCommand: Accesses the overlay by its name and rotates it.
    152153        static void rotateOverlay(const std::string& name, const Degree& angle);
Note: See TracChangeset for help on using the changeset viewer.