Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2963 for code/trunk


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

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

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

Legend:

Unmodified
Added
Removed
  • code/trunk/src/orxonox/CMakeLists.txt

    r2896 r2963  
    3535
    3636GENERATE_SOURCE_GROUPS(${ORXONOX_FILES})
    37 GENERATE_TOLUA_BINDINGS(Orxonox ORXONOX_FILES INPUTFILES gui/GUIManager.h)
     37GENERATE_TOLUA_BINDINGS(Orxonox ORXONOX_FILES INPUTFILES gui/GUIManager.h objects/quest/QuestManager.h objects/quest/QuestDescription.h)
    3838
    3939# Not using precompiled header files: Avoid dependencies
  • code/trunk/src/orxonox/gui/GUIManager.cc

    r2957 r2963  
    242242    /**
    243243    @brief
     244        Registers a GUIOverlay with the GUIManager so that the GUIOverlay can be accessed by it's name through the GUIManager.
     245    @param name
     246        The name of the GUI.
     247    @param overlay
     248        A pointer to the GUIOverlay of the GUI.
     249    @return
     250        Returns false if the Overlay was already present.
     251    */
     252    bool GUIManager::registerOverlay(std::string name, GUIOverlay* overlay)
     253    {
     254        return (this->guiOverlays_.insert(std::pair<std::string, GUIOverlay*>(name, overlay))).second;
     255    }
     256
     257    /**
     258    @brief
     259        Get the GUIOverlay of the GUI with the given name.
     260    @param name
     261        The name of the GUI.
     262    @return
     263        Returns a pointer to the GUIOverlay.
     264    */
     265    GUIOverlay* GUIManager::getOverlay(std::string name)
     266    {
     267        return (this->guiOverlays_.find(name))->second;
     268    }
     269
     270    /**
     271    @brief
    244272        Tells the GUIManager which SceneManager to use
    245273    @param camera
  • code/trunk/src/orxonox/objects/quest/Quest.cc

    r2911 r2963  
    197197    /**
    198198    @brief
    199         Returns the parentquest of the Quest.
    200     @return
    201         Returns a pointer to the parentquest of the Quest.
    202     */
    203     const Quest* Quest::getParentQuest(void)
    204     {
    205         return this->parentQuest_;
    206     }
    207 
    208     /**
    209     @brief
    210199        Returns the subquest at the given index.
    211200    @param
  • code/trunk/src/orxonox/objects/quest/Quest.h

    r2911 r2963  
    118118            virtual bool isCompletable(const PlayerInfo* player) const = 0; //!< Checks whether the Quest can be completed.
    119119
    120             const Quest* getParentQuest(void); //!< Returns the parentquest of the Quest.
    121120            const Quest* getSubQuest(unsigned int index) const; //!<Returns the subquest at the given index.
    122121            const QuestHint* getHint(unsigned int index) const; //!< Returns the QuestHint at the given index.
  • code/trunk/src/orxonox/objects/quest/QuestDescription.h

    r2911 r2963  
    4242#include "core/XMLPort.h"
    4343
     44// tolua_begin
    4445namespace orxonox
    4546{
     
    5556        Damian 'Mozork' Frick
    5657    */
    57     class _OrxonoxExport QuestDescription : public BaseObject
    58     {
     58    class _OrxonoxExport QuestDescription
     59// tolua_end
     60        : public BaseObject
     61    { // tolua_export
    5962        public:
    6063            QuestDescription(BaseObject* creator);
     
    6366            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a QuestDescription object through XML.
    6467
     68// tolua_begin
    6569            /**
    6670            @brief Returns the title.
     
    7680            inline const std::string & getDescription(void) const
    7781                { return this->description_; }
     82// tolua_end
    7883       
    7984            /**
     
    155160                { this->completeMessage_ = message; }
    156161
    157     };
     162    }; // tolua_export
    158163
    159 }
     164} // tolua_export
    160165
    161166#endif /* _QuestDescription_H__ */
  • 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}
  • code/trunk/src/orxonox/objects/quest/QuestManager.h

    r2960 r2963  
    3838
    3939#include <map>
     40#include <list>
    4041#include <string>
    4142
    4243#include "core/OrxonoxClass.h"
    4344#include "orxonox/objects/infos/PlayerInfo.h"
     45#include "overlays/GUIOverlay.h"
    4446
    4547// tolua_begin
    4648namespace orxonox
    4749{
    48 // tolua_end
    4950
    50     struct RootQuest
     51    struct QuestContainer;
     52    struct HintContainer;
     53
     54    struct QuestContainer
    5155    {
    52         Quest* quest;
    53         RootQuest* next;
     56        const QuestDescription* description;
     57        HintContainer* hint;
     58        QuestContainer* subQuests;
     59        QuestContainer* next;
    5460    };
    5561
    56 // tolua_begin
     62    struct HintContainer
     63    {
     64        const QuestDescription* description;
     65        HintContainer* next;
     66    };
     67
    5768    /**
    5869    @brief
     
    8091            QuestHint* findHint(const std::string & hintId); //!< Returns the QuestHint with the input id.
    8192
    82             RootQuest* getQuests(const PlayerInfo & player);
     93            QuestContainer* getQuestTree(std::string & name); // tolua_export
    8394
    8495            static void toggleQuestGUI(void); //!< Opens the GUI.
     
    91102            std::map<std::string, QuestHint*> hintMap_; //!< All QuestHints registered by their id's.
    92103
     104            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);
     107
    93108    }; // tolua_export
    94109
  • code/trunk/src/orxonox/overlays/GUIOverlay.cc

    r2959 r2963  
    5353
    5454        XMLPortParam(GUIOverlay, "guiname", setGUIName, getGUIName, xmlElement, mode);
     55       
     56        GUIManager::getInstancePtr()->registerOverlay(this->guiName_, this);
    5557    }
    5658
Note: See TracChangeset for help on using the changeset viewer.