[Orxonox-commit 426] r3008 - in trunk/src: core orxonox/gamestates orxonox/gui
bknecht at orxonox.net
bknecht at orxonox.net
Thu May 21 17:16:30 CEST 2009
Author: bknecht
Date: 2009-05-21 17:16:29 +0200 (Thu, 21 May 2009)
New Revision: 3008
Modified:
trunk/src/core/Loader.cc
trunk/src/core/Loader.h
trunk/src/orxonox/gamestates/GSLevel.cc
trunk/src/orxonox/gamestates/GSLevel.h
trunk/src/orxonox/gui/GUIManager.cc
trunk/src/orxonox/gui/GUIManager.h
Log:
You don't need no --level or -l anymore now. You may choose your favorite level from the main menu ;-)
Modified: trunk/src/core/Loader.cc
===================================================================
--- trunk/src/core/Loader.cc 2009-05-21 10:12:33 UTC (rev 3007)
+++ trunk/src/core/Loader.cc 2009-05-21 15:16:29 UTC (rev 3008)
@@ -29,6 +29,7 @@
#include "Loader.h"
#include <tinyxml/ticpp.h>
+#include <boost/filesystem.hpp>
#include "XMLFile.h"
#include "BaseObject.h"
@@ -40,6 +41,7 @@
#include "Namespace.h"
#include "util/Debug.h"
#include "util/Exception.h"
+#include "Core.h"
namespace orxonox
{
@@ -209,4 +211,24 @@
Loader::unload(file, mask);
return Loader::load(file, mask);
}
+
+ std::vector<std::string> Loader::getLevelList()
+ {
+ std::vector<std::string> levelList;
+
+ boost::filesystem::directory_iterator file(Core::getMediaPathString() + "levels");
+ boost::filesystem::directory_iterator end;
+
+ while (file != end)
+ {
+ if (!boost::filesystem::is_directory(*file) && file->string()[file->string().length()-1] != '~')
+ {
+ std::string filename = file->path().leaf();
+ if (filename.length() > 4)
+ levelList.push_back(filename.substr(0,filename.length()-4));
+ }
+ ++file;
+ }
+ return levelList;
+ }
}
Modified: trunk/src/core/Loader.h
===================================================================
--- trunk/src/core/Loader.h 2009-05-21 10:12:33 UTC (rev 3007)
+++ trunk/src/core/Loader.h 2009-05-21 15:16:29 UTC (rev 3008)
@@ -56,6 +56,7 @@
static bool reload(const XMLFile* file, const ClassTreeMask& mask = ClassTreeMask());
static ClassTreeMask currentMask_s;
+ static std::vector<std::string> getLevelList();
private:
static std::vector<std::pair<const XMLFile*, ClassTreeMask> > files_s;
Modified: trunk/src/orxonox/gamestates/GSLevel.cc
===================================================================
--- trunk/src/orxonox/gamestates/GSLevel.cc 2009-05-21 10:12:33 UTC (rev 3007)
+++ trunk/src/orxonox/gamestates/GSLevel.cc 2009-05-21 15:16:29 UTC (rev 3008)
@@ -59,7 +59,10 @@
SetCommandLineArgument(level, "presentation_dm.oxw").shortcut("l");
SetConsoleCommand(GSLevel, showIngameGUI, true);
+ SetConsoleCommand(GSLevel, setLevel, true);
+ XMLFile* GSLevel::startFile_s = NULL;
+
GSLevel::GSLevel(const std::string& name)
: GameState(name)
, keyBinder_(0)
@@ -67,7 +70,6 @@
, guiMouseOnlyInputState_(0)
, guiKeysOnlyInputState_(0)
, radar_(0)
- , startFile_(0)
, cameraManager_(0)
, levelManager_(0)
{
@@ -251,11 +253,20 @@
// call the loader
COUT(0) << "Loading level..." << std::endl;
std::string levelName;
- CommandLine::getValue("level", &levelName);
- startFile_ = new XMLFile(Core::getMediaPathString() + "levels" + '/' + levelName);
- Loader::open(startFile_);
+ if (!startFile_s)
+ {
+ CommandLine::getValue("level", &levelName);
+ startFile_s = new XMLFile(Core::getMediaPathString() + "levels" + '/' + levelName);
+ }
+ Loader::open(startFile_s);
}
+ void GSLevel::setLevel(std::string levelName)
+ {
+ delete GSLevel::startFile_s;
+ GSLevel::startFile_s = new XMLFile(Core::getMediaPathString() + "levels" + '/' + levelName);
+ }
+
void GSLevel::unloadLevel()
{
//////////////////////////////////////////////////////////////////////////////////////////
@@ -264,7 +275,7 @@
// Loader::unload(startFile_); // TODO: REACTIVATE THIS IF LOADER::UNLOAD WORKS PROPERLY /
//////////////////////////////////////////////////////////////////////////////////////////
- delete this->startFile_;
+ delete startFile_s;
}
void GSLevel::keybind(const std::string &command)
Modified: trunk/src/orxonox/gamestates/GSLevel.h
===================================================================
--- trunk/src/orxonox/gamestates/GSLevel.h 2009-05-21 10:12:33 UTC (rev 3007)
+++ trunk/src/orxonox/gamestates/GSLevel.h 2009-05-21 15:16:29 UTC (rev 3008)
@@ -47,7 +47,10 @@
void update(const Clock& time);
static void showIngameGUI(bool show);
+ static void setLevel(std::string levelName);
+ static XMLFile* startFile_s;
+
protected:
void loadLevel();
void unloadLevel();
@@ -62,7 +65,6 @@
SimpleInputState* guiMouseOnlyInputState_; //!< input state if we only need the mouse to use the GUI
SimpleInputState* guiKeysOnlyInputState_; //!< input state if we only need the keys to use the GUI
Radar* radar_; //!< represents the Radar (not the HUD part)
- XMLFile* startFile_; //!< current hard coded default level
CameraManager* cameraManager_; //!< camera manager for this level
LevelManager* levelManager_; //!< global level manager
PlayerManager* playerManager_; //!< player manager for this level
Modified: trunk/src/orxonox/gui/GUIManager.cc
===================================================================
--- trunk/src/orxonox/gui/GUIManager.cc 2009-05-21 10:12:33 UTC (rev 3007)
+++ trunk/src/orxonox/gui/GUIManager.cc 2009-05-21 15:16:29 UTC (rev 3008)
@@ -54,6 +54,7 @@
#include "core/Clock.h"
#include "ToluaBindCore.h"
#include "ToluaBindOrxonox.h"
+#include "core/Loader.h"
extern "C" {
#include <lua.h>
@@ -240,6 +241,27 @@
}
/**
+
+ */
+ void GUIManager::getLevelList()
+ {
+ lua_State* L = this->scriptModule_->getLuaState();
+ lua_newtable(L);
+
+ std::vector<std::string> list = Loader::getLevelList();
+
+ int j = 1;
+ for (std::vector<std::string>::iterator i = list.begin(); i != list.end(); i++)
+ {
+ lua_pushnumber(L,j);
+ lua_pushstring(L,i->c_str());
+ lua_settable(L,-3);
+ j++;
+ }
+ lua_setglobal(L, "levellist");
+ }
+
+ /**
@brief
Registers a GUIOverlay with the GUIManager so that the GUIOverlay can be accessed by it's name through the GUIManager.
@param name
Modified: trunk/src/orxonox/gui/GUIManager.h
===================================================================
--- trunk/src/orxonox/gui/GUIManager.h 2009-05-21 10:12:33 UTC (rev 3007)
+++ trunk/src/orxonox/gui/GUIManager.h 2009-05-21 15:16:29 UTC (rev 3008)
@@ -96,6 +96,8 @@
static GUIManager& getInstance() { assert(singletonRef_s); return *singletonRef_s; } // tolua_export
static GUIManager* getInstancePtr() { return singletonRef_s; }
+ void getLevelList(); //tolua_export
+
private:
GUIManager(const GUIManager& instance); //!< private constructor (this is a singleton class)
More information about the Orxonox-commit
mailing list