Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3008


Ignore:
Timestamp:
May 21, 2009, 5:16:29 PM (15 years ago)
Author:
bknecht
Message:

You don't need no —level or -l anymore now. You may choose your favorite level from the main menu ;-)

Location:
code/trunk/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/core/Loader.cc

    r2710 r3008  
    3030
    3131#include <tinyxml/ticpp.h>
     32#include <boost/filesystem.hpp>
    3233
    3334#include "XMLFile.h"
     
    4142#include "util/Debug.h"
    4243#include "util/Exception.h"
     44#include "Core.h"
    4345
    4446namespace orxonox
     
    210212        return Loader::load(file, mask);
    211213    }
     214
     215    std::vector<std::string> Loader::getLevelList()
     216    {
     217        std::vector<std::string> levelList;
     218
     219        boost::filesystem::directory_iterator file(Core::getMediaPathString() + "levels");
     220        boost::filesystem::directory_iterator end;
     221
     222        while (file != end)
     223        {
     224            if (!boost::filesystem::is_directory(*file) && file->string()[file->string().length()-1] != '~')
     225            {
     226                std::string filename = file->path().leaf();
     227                if (filename.length() > 4)
     228                    levelList.push_back(filename.substr(0,filename.length()-4));
     229            }
     230            ++file;
     231        }
     232        return levelList;
     233    }
    212234}
  • code/trunk/src/core/Loader.h

    r2087 r3008  
    5757
    5858            static ClassTreeMask currentMask_s;
     59            static std::vector<std::string> getLevelList();
    5960
    6061        private:
  • code/trunk/src/orxonox/gamestates/GSLevel.cc

    r2928 r3008  
    6060    SetCommandLineArgument(level, "presentation_dm.oxw").shortcut("l");
    6161    SetConsoleCommand(GSLevel, showIngameGUI, true);
     62    SetConsoleCommand(GSLevel, setLevel, true);
     63
     64    XMLFile* GSLevel::startFile_s = NULL;
    6265
    6366    GSLevel::GSLevel(const std::string& name)
     
    6871        , guiKeysOnlyInputState_(0)
    6972        , radar_(0)
    70         , startFile_(0)
    7173        , cameraManager_(0)
    7274        , levelManager_(0)
     
    252254        COUT(0) << "Loading level..." << std::endl;
    253255        std::string levelName;
    254         CommandLine::getValue("level", &levelName);
    255         startFile_ = new XMLFile(Core::getMediaPathString() + "levels" + '/' + levelName);
    256         Loader::open(startFile_);
     256        if (!startFile_s)
     257        {
     258            CommandLine::getValue("level", &levelName);
     259            startFile_s = new XMLFile(Core::getMediaPathString() + "levels" + '/' + levelName);
     260        }
     261        Loader::open(startFile_s);
     262    }
     263
     264    void GSLevel::setLevel(std::string levelName)
     265    {
     266        delete GSLevel::startFile_s;
     267        GSLevel::startFile_s = new XMLFile(Core::getMediaPathString() + "levels" + '/' + levelName);
    257268    }
    258269
     
    265276        //////////////////////////////////////////////////////////////////////////////////////////
    266277
    267         delete this->startFile_;
     278        delete startFile_s;
    268279    }
    269280
  • code/trunk/src/orxonox/gamestates/GSLevel.h

    r2911 r3008  
    4848
    4949        static void showIngameGUI(bool show);
     50        static void setLevel(std::string levelName);
     51
     52        static XMLFile* startFile_s;
    5053
    5154    protected:
     
    6366        SimpleInputState*     guiKeysOnlyInputState_;   //!< input state if we only need the keys to use the GUI
    6467        Radar*                radar_;                   //!< represents the Radar (not the HUD part)
    65         XMLFile*              startFile_;               //!< current hard coded default level
    6668        CameraManager*        cameraManager_;           //!< camera manager for this level
    6769        LevelManager*         levelManager_;            //!< global level manager
  • code/trunk/src/orxonox/gui/GUIManager.cc

    r2963 r3008  
    5555#include "ToluaBindCore.h"
    5656#include "ToluaBindOrxonox.h"
     57#include "core/Loader.h"
    5758
    5859extern "C" {
     
    238239            COUT(2) << "CEGUI Error: \"" << ex.getMessage() << "\" while executing code \"" << str << "\"" << std::endl;
    239240        }
     241    }
     242
     243    /**
     244
     245    */
     246    void GUIManager::getLevelList()
     247    {
     248        lua_State* L = this->scriptModule_->getLuaState();
     249        lua_newtable(L);
     250
     251        std::vector<std::string> list = Loader::getLevelList();
     252
     253        int j = 1;
     254        for (std::vector<std::string>::iterator i = list.begin(); i != list.end(); i++)
     255        {
     256            lua_pushnumber(L,j);
     257            lua_pushstring(L,i->c_str());
     258            lua_settable(L,-3);
     259            j++;
     260        }
     261        lua_setglobal(L, "levellist");
    240262    }
    241263
  • code/trunk/src/orxonox/gui/GUIManager.h

    r2962 r3008  
    9797        static GUIManager* getInstancePtr() { return singletonRef_s; }
    9898
     99        void getLevelList(); //tolua_export
     100
    99101    private:
    100102        GUIManager(const GUIManager& instance);                 //!< private constructor (this is a singleton class)
Note: See TracChangeset for help on using the changeset viewer.