Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 23, 2009, 8:04:51 PM (15 years ago)
Author:
rgrieder
Message:

Moved GUIManager::getLevelList to LevelManager because the GUIManager has nothing to do with levels.
I also had to change the way the information flows: Instead of operation on the Lua state, you tell the LevelManager to compile the list and then get the elements one by one.
The reason for this change is simple: There is no way to know from which LuaState the call came (without making an ugly hack in Tolua itself).

Location:
code/branches/resource/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • code/branches/resource/src/core/Loader.cc

    r3196 r3339  
    3030
    3131#include <tinyxml/ticpp.h>
    32 #include <boost/filesystem.hpp>
    3332
    3433#include "util/Debug.h"
    3534#include "util/Exception.h"
    3635#include "BaseObject.h"
    37 #include "Core.h"
    3836#include "Iterator.h"
    3937#include "ObjectList.h"
     
    210208        return Loader::load(file, mask);
    211209    }
    212 
    213     std::vector<std::string> Loader::getLevelList()
    214     {
    215         std::vector<std::string> levelList;
    216 
    217         boost::filesystem::directory_iterator file(Core::getMediaPathString() + "levels");
    218         boost::filesystem::directory_iterator end;
    219 
    220         while (file != end)
    221         {
    222             if (!boost::filesystem::is_directory(*file) && file->string()[file->string().length()-1] != '~')
    223             {
    224                 std::string filename = file->path().leaf();
    225                 if (filename.length() > 4)
    226                     levelList.push_back(filename.substr(0,filename.length()-4));
    227             }
    228             ++file;
    229         }
    230         return levelList;
    231     }
    232210}
  • code/branches/resource/src/core/Loader.h

    r3196 r3339  
    5656
    5757            static ClassTreeMask currentMask_s;
    58             static std::vector<std::string> getLevelList();
    5958
    6059        private:
  • code/branches/resource/src/orxonox/LevelManager.cc

    r3280 r3339  
    3030
    3131#include <map>
     32#include <boost/filesystem.hpp>
    3233
    3334#include "core/CommandLine.h"
    3435#include "core/ConfigValueIncludes.h"
    3536#include "core/CoreIncludes.h"
     37#include "core/Loader.h"
    3638#include "PlayerManager.h"
    3739#include "objects/Level.h"
     
    120122    }
    121123
    122     const std::string& LevelManager::getDefaultLevel()
     124    const std::string& LevelManager::getDefaultLevel() const
    123125    {
    124126        return defaultLevelName_;
    125127    }
     128
     129    std::string LevelManager::getAvailableLevelListItem(unsigned int index) const
     130    {
     131        if (index >= availableLevels_.size())
     132            return std::string();
     133        else
     134            return availableLevels_[index];
     135    }
     136
     137    void LevelManager::compileAvailableLevelList()
     138    {
     139        availableLevels_.clear();
     140
     141        boost::filesystem::directory_iterator file(Core::getMediaPathString() + "levels");
     142        boost::filesystem::directory_iterator end;
     143
     144        while (file != end)
     145        {
     146            if (!boost::filesystem::is_directory(*file) && file->string()[file->string().length()-1] != '~')
     147            {
     148                std::string filename = file->path().leaf();
     149                if (filename.length() > 4)
     150                    availableLevels_.push_back(filename.substr(0,filename.length()-4));
     151            }
     152            ++file;
     153        }
     154    }
    126155}
  • code/branches/resource/src/orxonox/LevelManager.h

    r3304 r3339  
    5555
    5656            void setDefaultLevel(const std::string& levelName); //tolua_export
    57             const std::string& getDefaultLevel(); //tolua_export
     57            const std::string& getDefaultLevel() const; //tolua_export
     58            void compileAvailableLevelList(); //tolua_export
     59            std::string getAvailableLevelListItem(unsigned int index) const; //tolua_export
    5860
    5961            static LevelManager* getInstancePtr() { return singletonRef_s; }
     
    6668
    6769            std::list<Level*> levels_s;
     70            std::vector<std::string> availableLevels_;
    6871
    6972            // config values
  • code/branches/resource/src/orxonox/gamestates/GSMainMenu.cc

    r3327 r3339  
    6767
    6868        // show main menu
    69         GUIManager::getInstance().showGUI("mainmenu_3");
     69        GUIManager::getInstance().showGUI("mainmenu_4");
    7070        GUIManager::getInstance().setCamera(this->camera_);
    7171        GraphicsManager::getInstance().setCamera(this->camera_);
  • code/branches/resource/src/orxonox/gui/GUIManager.cc

    r3338 r3339  
    6161#include "ToluaBindCore.h"
    6262#include "ToluaBindOrxonox.h"
    63 #include "core/Loader.h"
    6463
    6564namespace orxonox
     
    8887
    8988    static CEGUI::MouseButton convertButton(MouseButtonCode::ByEnum button);
     89
    9090    GUIManager* GUIManager::singletonRef_s = 0;
    9191
     
    157157        Destructor of the GUIManager
    158158
    159         Basically shuts down CEGUI and destroys the Lua engine and afterwards the interface to the Ogre engine.
     159        Basically shuts down CEGUI (member smart pointers) but first unloads our Tolua modules.
    160160    */
    161161    GUIManager::~GUIManager()
     
    174174        Calls main Lua script
    175175    @todo
    176         Replace loadGUI.lua with loadGUI_2.lua after merging this back to trunk.
    177         However CEGUI is able to execute a startup script. We could maybe put this call in this startup code.
    178 
    179176        This function calls the main Lua script for our GUI.
    180177
     
    183180    void GUIManager::loadLuaCode()
    184181    {
    185         try
    186         {
    187             // set datapath for GUI data
    188             lua_pushfstring(this->scriptModule_->getLuaState(), Core::getMediaPathString().c_str());
    189             lua_setglobal(this->scriptModule_->getLuaState(), "datapath");
    190             // call main Lua script
    191             this->scriptModule_->executeScriptFile("loadGUI_3.lua", "GUI");
    192         }
    193         catch (CEGUI::Exception& ex)
    194         {
    195 #if CEGUI_VERSION_MINOR < 6
    196             throw GeneralException(ex.getMessage().c_str());
    197 #else
    198             throw GeneralException(ex.getMessage().c_str(), ex.getLine(),
    199                 ex.getFileName().c_str(), ex.getName().c_str());
    200 #endif
    201         }
     182        // set datapath for GUI data
     183        lua_pushfstring(this->scriptModule_->getLuaState(), Core::getMediaPathString().c_str());
     184        lua_setglobal(this->scriptModule_->getLuaState(), "datapath");
     185        // call main Lua script
     186        this->scriptModule_->executeScriptFile("loadGUI_3.lua", "GUI");
    202187    }
    203188
     
    216201        assert(guiSystem_);
    217202        guiSystem_->injectTimePulse(time.getDeltaTime());
    218     }
    219 
    220     /**
    221 
    222     */
    223     void GUIManager::getLevelList()
    224     {
    225         lua_State* L = this->scriptModule_->getLuaState();
    226         lua_newtable(L);
    227 
    228         std::vector<std::string> list = Loader::getLevelList();
    229 
    230         int j = 1;
    231         for (std::vector<std::string>::iterator i = list.begin(); i != list.end(); i++)
    232         {
    233             lua_pushnumber(L,j);
    234             lua_pushstring(L,i->c_str());
    235             lua_settable(L,-3);
    236             j++;
    237         }
    238         lua_setglobal(L, "levellist");
    239203    }
    240204
  • code/branches/resource/src/orxonox/gui/GUIManager.h

    r3338 r3339  
    4747#include "core/input/InputHandler.h"
    4848
    49 // tolua_begin
    5049namespace orxonox
    5150{
     
    6160        Those input events are then injected into CEGUI in Lua.
    6261    */
    63     class _OrxonoxExport GUIManager
    64 // tolua_end
    65         : public InputHandler
    66 // tolua_begin
     62    class _OrxonoxExport GUIManager : public InputHandler
    6763    {
    68 // tolua_end
    6964    public:
    7065        GUIManager(Ogre::RenderWindow* renderWindow);
     
    7873        void setCamera(Ogre::Camera* camera);
    7974
    80         static GUIManager& getInstance()    { assert(singletonRef_s); return *singletonRef_s; } // tolua_export
     75        static GUIManager& getInstance()    { assert(singletonRef_s); return *singletonRef_s; }
    8176        static GUIManager* getInstancePtr() { return singletonRef_s; }
    8277
    83         void getLevelList(); //tolua_export
    84 
    8578    private:
    86         GUIManager(const GUIManager& instance);                 //!< private constructor (this is a singleton class)
     79        GUIManager(const GUIManager& instance); //!< private and undefined copy c'tor (this is a singleton class)
    8780
    8881        void loadLuaCode();
     
    108101        static GUIManager*       singletonRef_s;    //!< Singleton reference to GUIManager
    109102
    110     }; // tolua_export
    111 } // tolua_export
     103    };
     104}
    112105
    113106#endif /* _GUIManager_H__ */
Note: See TracChangeset for help on using the changeset viewer.