Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7625


Ignore:
Timestamp:
Nov 6, 2010, 8:17:20 PM (13 years ago)
Author:
dafrick
Message:

Introducing LevelInfo class, which can be used to specify things about a Level and which is used to provide more flexibility in displaying a list of levels.
Basic functionality works, now all that needs to be dones is to exploit the new functionality.

Location:
code/branches/releasetodo
Files:
1 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • code/branches/releasetodo/data/gui/scripts/SingleplayerMenu.lua

    r7163 r7625  
    66    listbox = winMgr:getWindow("orxonox/SingleplayerLevelListbox")
    77    preselect = orxonox.LevelManager:getInstance():getDefaultLevel()
    8     orxonox.LevelManager:getInstance():compileAvailableLevelList()
     8    size = orxonox.LevelManager:getInstance():getNumberOfLevels()
    99    local levelList = {}
    1010    local index = 0
    1111    local level = ""
    12     while true do
     12    while index < size do
    1313      level = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index)
    14       if level == "" then
    15         break
    16       end
    1714      table.insert(levelList, level)
    1815      index = index + 1
  • code/branches/releasetodo/data/levels/empty_level.oxw

    r7163 r7625  
     1<LevelInfo
     2 name = "Empty level"
     3 description = "A level with absolutely nothing in it."
     4 tags = "test, empty"
     5/>
     6
    17<?lua
    28  include("stats.oxo")
  • code/branches/releasetodo/data/levels/notifications.oxw

    r7614 r7625  
     1<LevelInfo
     2 name = "Notifications showcase"
     3 description = "Level to test and showcase notifications."
     4 tags = "test, showcase, notifications"
     5/>
     6
    17<?lua
    28  include("hudtemplates3.oxo")
     
    511  include("templates/lodinformation.oxt")
    612?>
    7 
    8 <LevelInfo
    9  name = "Notifications showcase"
    10  description = "Level to test and showcase notifications."
    11  tags = "test, showcase, notifications"
    12 />
    1313
    1414<Level
  • code/branches/releasetodo/src/orxonox/LevelInfo.h

    r7614 r7625  
    2727 */
    2828
     29/**
     30    @file LevelInfo.h
     31    @brief Definition of the LevelInfo and LevelInfoItem class.
     32    @ingroup Orxonox
     33*/
     34
    2935#ifndef _LevelInfo_H__
    3036#define _LevelInfo_H__
     
    3440#include <set>
    3541#include <string>
     42
    3643#include "core/BaseObject.h"
     44#include "core/OrxonoxClass.h"
    3745
    38 namespace orxonox // tolua_export
    39 {  // tolua_export
    40     class _OrxonoxExport LevelInfo  // tolua_export
    41         : public BaseObject
    42     { // tolua_export
    43    
     46namespace orxonox
     47{
     48
     49    /**
     50    @brief
     51        The LevelInfoItem class stores information regarding a @ref orxonox::Level "Level" and makes that information it accessible trough the @ref orxonox::LevelManager "LevelManager".
     52        A LevelInfoItem object is commonly created from a @ref orxonox::LevelInfo "LevelInfo" object, using its <code>copy()</code> method.
     53
     54    @author
     55        Damian 'Mozork' Frick
     56    */
     57    class _OrxonoxExport LevelInfoItem : virtual public OrxonoxClass
     58    {
     59        public:
     60            LevelInfoItem(); //!< Default constructor.
     61            LevelInfoItem(const std::string& name, const std::string filename); //!< Constructor. Initializes the object.
     62            virtual ~LevelInfoItem(); //!< Destructor.
     63
     64            /**
     65            @brief Set the name of the Level.
     66            @param name The name to be set.
     67            */
     68            inline void setName(const std::string& name)
     69                { this->name_ = std::string(name); }
     70            /**
     71            @brief Get the name of the Level.
     72            @return Returns the name of the Level.
     73            */
     74            inline const std::string& getName(void)
     75                { return this->name_; }
     76
     77            /**
     78            @brief Set the description of the Level.
     79            @param description The description to be set.
     80            */
     81            inline void setDescription(const std::string& description)
     82                { this->description_ = std::string(description); }
     83            /**
     84            @brief Get the description of the Level.
     85            @return Returns the description of the Level.
     86            */
     87            inline const std::string& getDescription() const
     88                { return this->description_; }
     89
     90            void setTags(const std::string& tags); //!< Set the tags the Level is tagged with.
     91            bool addTag(const std::string& tag, bool update = true); //!< Add a tag to the set of tags the Level is tagged with.
     92            /**
     93            @brief Get the lis of the tags the Level is tagged with.
     94            @return Returns a comma-seperated string of all the tags the Level is tagged with.
     95            */
     96            inline const std::string& getTags(void) const
     97                { return this->tagsString_; }
     98            /**
     99            @brief Get whether the Level has a specific tag.
     100            @param tag The tag for which is checked.
     101            @return Returns true if the Level is tagged with the input tag.
     102            */
     103            bool hasTag(const std::string& tag) const
     104                { return this->tags_.find(tag) != this->tags_.end(); }
     105
     106            /**
     107            @brief Get the XML-filename of the Level.
     108            @return Returns the XML-filename (including *.oxw extension) of the Level.
     109            */
     110            inline const std::string& getXMLFilename(void)
     111                { return this->xmlfilename_; }
     112
     113        protected:
     114            /**
     115            @brief Set the XML-filename of the Level.
     116            @param filename The XML-filename to be set.
     117            */
     118            inline void setXMLFilename(const std::string& filename)
     119                { this->xmlfilename_ = std::string(filename); }
     120
     121            std::string xmlfilename_; //!< The XML-filename of the Level.
     122
     123        private:
     124            void tagsUpdated(void); //!< Updates the comma-seperated string of all tags, if the set of tags has changed.
     125
     126            std::string name_; //!< The name of the Level.
     127            std::string description_; //!< The description of the Level.
     128            std::set<std::string> tags_; //!< The set of tags the Level is tagged with.
     129            std::string tagsString_; //!< The comma-seperated string of all the tags the Level is tagged with.
     130    };
     131
     132    /**
     133    @brief
     134        The LevelInfo class can be used to store information regarding a @ref orxonox::Level "Level" in its level file.
     135        The following parameters can be specified:
     136        - @b name The name of the level.
     137        - @b description The description of the level.
     138        - @b tags A comma-seperated string of tags.
     139
     140        An example would be:
     141        @code
     142        <LevelInfo
     143            name = "Levelname"
     144            description = "This is just some awesome level."
     145            tags = "test, awesome"
     146        />
     147        @endcode
     148        The LevelInfo is best located at the top of the level file.
     149
     150    @author
     151        Damian 'Mozork' Frick
     152    */
     153    class _OrxonoxExport LevelInfo : public BaseObject, public LevelInfoItem
     154    {
    44155        public:
    45156            LevelInfo(BaseObject* creator);
    46157            virtual ~LevelInfo();
    47            
    48             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    49158
     159            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Creates a LevelInfo object through XML.
     160
     161            /**
     162            @brief Set the description of the Level.
     163            @param description The description to be set.
     164            */
    50165            inline void setDescription(const std::string& description)
    51                 { this->description_ = description; }
    52             inline const std::string& getDescription() const // tolua_export
    53                 { return this->description_; }
    54                
    55             void setTags(const std::string& tags);
    56             inline bool addTag(const std::string& tag)
    57                 { bool success = this->tags_.insert(tag).second; if(success) this->tagsUpdated(); return success; }
     166                { this->LevelInfoItem::setDescription(description); }
     167            /**
     168            @brief Get the description of the Level.
     169            @return Returns the description of the Level.
     170            */
     171            inline const std::string& getDescription() const
     172                { return this->LevelInfoItem::getDescription(); }
     173
     174            /**
     175            @brief Set the tags the Level is tagged with.
     176            @param tags A comma-seperated string of all the tags to be set.
     177            */
     178            inline void setTags(const std::string& tags)
     179                { this->LevelInfoItem::setTags(tags); }
     180            /**
     181            @brief Get the lis of the tags the Level is tagged with.
     182            @return Returns a comma-seperated string of all the tags the Level is tagged with.
     183            */
    58184            inline const std::string& getTags(void) const
    59                 { return this->tagsString_; }
    60             bool hasTag(const std::string& tag) { return this->tags_.find(tag) != this->tags_.end(); } // tolua_export
    61            
    62         private:
    63             void tagsUpdated(void);
    64        
    65             std::string description_;
    66             std::set<std::string> tags_;
    67             std::string tagsString_;
    68            
    69     }; // tolua_export
    70 } // tolua_export
     185                { return this->LevelInfoItem::getTags(); }
    71186
    72 #endif /* _Level_H__ */
     187            LevelInfoItem* copy(void); //!< Copies the contents of this LevelInfo object to a new LevelInfoItem object.
     188
     189    };
     190}
     191
     192#endif /* _LevelInfo_H__ */
  • code/branches/releasetodo/src/orxonox/LevelManager.cc

    r7614 r7625  
    5959            ModifyConfigValue(defaultLevelName_, tset, CommandLineParser::getValue("level").getString());
    6060        }
     61
     62        this->compileAvailableLevelList();
    6163    }
    6264
     
    128130    }
    129131
     132    unsigned int LevelManager::getNumberOfLevels()
     133    {
     134        this->updateAvailableLevelList();
     135
     136        COUT(0) << "Number of Levels: " << this->infos_.size() << std::endl;
     137
     138        return this->availableLevels_.size();
     139    }
     140
    130141    const std::string& LevelManager::getAvailableLevelListItem(unsigned int index) const
    131142    {
    132         if (index >= availableLevels_.size())
     143        if (index >= this->availableLevels_.size())
    133144            return BLANKSTRING;
    134145        else
    135             return availableLevels_[index];
     146        {
     147            std::map<std::string, LevelInfoItem*>::const_iterator it = this->infos_.find(this->availableLevels_[index]);
     148            assert(it->second);
     149            return it->second->getName();
     150        }
    136151    }
    137152
    138153    void LevelManager::compileAvailableLevelList()
    139154    {
    140         this->availableLevels_.clear();
    141155        Ogre::StringVectorPtr levels = Resource::findResourceNames("*.oxw");
     156        // Iterate over all *.oxw level files.
    142157        for (Ogre::StringVector::const_iterator it = levels->begin(); it != levels->end(); ++it)
    143158        {
     159            //TODO: Replace with tag,
    144160            if (it->find("old/") != 0)
    145161            {
    146162                size_t pos = it->find(".oxw");
    147                 COUT(0) << *it << std::endl;
     163
     164                bool infoExists = false;
     165                // Load the LevelInfo object from the level file.
    148166                XMLFile file = XMLFile(*it);
    149167                ClassTreeMask mask = ClassTreeMask();
     
    151169                mask.include(ClassIdentifier<LevelInfo>::getIdentifier());
    152170                Loader::load(&file, mask);
    153                
     171                for(ObjectList<LevelInfo>::iterator item = ObjectList<LevelInfo>::begin(); item != ObjectList<LevelInfo>::end(); ++item)
     172                {
     173                    LevelInfoItem* info = item->copy();
     174                    COUT(0) << "BUUUUUUUUUH: " << info->getName() << " | " << info->getXMLFilename() << " | " << it->substr(0, pos) << std::endl;
     175                    if(info->getXMLFilename() == *it)
     176                    {
     177                        this->infos_.insert(std::pair<std::string, LevelInfoItem*>(it->substr(0, pos),info));
     178                        infoExists = true;
     179                    }
     180                }
     181                Loader::unload(&file, mask);
     182                if(!infoExists)
     183                {
     184                    this->infos_.insert(std::pair<std::string, LevelInfoItem*>(it->substr(0, pos), new LevelInfoItem(it->substr(0, pos), *it)));
     185                }
     186
    154187                this->availableLevels_.push_back(it->substr(0, pos));
    155188            }
    156189        }
     190    }
    157191
     192    void LevelManager::updateAvailableLevelList(void)
     193    {
     194        //TODO: Implement some kind of update?
    158195    }
    159196}
  • code/branches/releasetodo/src/orxonox/LevelManager.h

    r6746 r7625  
    3434#include <cassert>
    3535#include <list>
     36#include <map>
    3637#include <string>
    3738
     
    5960            void setDefaultLevel(const std::string& levelName); //tolua_export
    6061            const std::string& getDefaultLevel() const; //tolua_export
    61             void compileAvailableLevelList(); //tolua_export
     62            unsigned int getNumberOfLevels(void); //tolua_export
    6263            const std::string& getAvailableLevelListItem(unsigned int index) const; //tolua_export
    6364
     
    6970            void activateNextLevel();
    7071
     72            void compileAvailableLevelList(void);
     73            void updateAvailableLevelList(void);
     74
    7175            std::list<Level*> levels_s;
    7276            std::vector<std::string> availableLevels_;
     77            std::map<std::string, LevelInfoItem*> infos_;
    7378
    7479            // config values
  • code/branches/releasetodo/src/orxonox/OrxonoxPrereqs.h

    r7614 r7625  
    6868    class Level;
    6969    class LevelInfo;
     70    class LevelInfoItem;
    7071    class LevelManager;
    7172    class PawnManager;
Note: See TracChangeset for help on using the changeset viewer.