[Orxonox-commit 4486] r9157 - in code/branches/shipSelection: data/gui/scripts data/levels src/orxonox
huttemat at orxonox.net
huttemat at orxonox.net
Fri May 4 16:05:53 CEST 2012
Author: huttemat
Date: 2012-05-04 16:05:53 +0200 (Fri, 04 May 2012)
New Revision: 9157
Added:
code/branches/shipSelection/src/orxonox/ShipManager.cc
code/branches/shipSelection/src/orxonox/ShipManager.h
Modified:
code/branches/shipSelection/data/gui/scripts/ShipSelectionMenu.lua
code/branches/shipSelection/data/levels/tutorial.oxw
code/branches/shipSelection/src/orxonox/LevelInfo.cc
Log:
ShipSelecting working, still hackish and featureless though
Modified: code/branches/shipSelection/data/gui/scripts/ShipSelectionMenu.lua
===================================================================
--- code/branches/shipSelection/data/gui/scripts/ShipSelectionMenu.lua 2012-05-04 14:05:49 UTC (rev 9156)
+++ code/branches/shipSelection/data/gui/scripts/ShipSelectionMenu.lua 2012-05-04 14:05:53 UTC (rev 9157)
@@ -5,7 +5,7 @@
P.scrollbarWidth = 13
P.shipList = {}
function P.onLoad()
- --orxonox.execute("orxout internal_warning Ships= " .. selectedlevel:hasShip("abcdef"))
+ --orxonox.execute("orxout user_warning Ships= " .. selectedlevel:hasShip("abcdef"))
local dircmd = "ls ../levels/templates/ -l | awk '{print $9}' | grep \"spaceship\" | sed -e 's/\\.[a-zA-Z]*$//'" -- go to spaceships folder and generate a list of installed shipmodels.
os.execute(dircmd .. " > ../levels/templates/.shipmodels") --saves output in a textfile
--[[ Program a Windows Version here:
@@ -15,25 +15,13 @@
end]]
P.shipList = {}
+ for line in io.lines("../levels/templates/.shipmodels") do
+ if selectedlevel:hasShip(string.lower(line)) then
+ P.shipList[#P.shipList+1] = string.lower(line)
+ end
+ end
+ P.createFilterTab("Show All")
- --for line in io.lines("../levels/templates/.shipmodels") do orxonox.execute("orxout user_warning " .. line) end
- for line in io.lines("../levels/templates/.shipmodels") do
- P.shipList[#P.shipList+1] = string.lower(line)
- end
- --[[for f in io.lines("../levels/templates/.shipmodels") do
- if selectedlevel:hasShip(f) then
- P.shipList[#P.shipList+1] = f
- table.insert(P.shipList, f)
- end
- end--]]
- P.shipList[1]="spaceshipAssff"
- P.shipList[2]="spaceshipGhost"
- P.shipList[3]="spaceshipPirate"
- P.createFilterTab("Show All")
- --[[list = winMgr:createWindow("MenuWidgets/Listbox", "listbox")
- item = CEGUI.createListboxTextItem("Text")
- CEGUI.toListbox(list):addItem(item)
- list:enable()--]]
end
function P.createShipList()
@@ -45,43 +33,6 @@
function P.createFilterTab(name)
- --[[-- create unique tab window name
- orxonox.execute("orxout user_warning test")
- local tabName = "orxonox/SchipSelectionLevelTab"
- -- create new tab window with desired name
- local listbox = CEGUI.toListbox(winMgr:createWindow("MenuWidgets/Listbox", tabName))
- listbox:setText(name)
- listbox:setProperty("UnifiedMaxSize", "{{1,0},{1,0}}")
- listbox:setProperty("UnifiedAreaRect", "{{0.05,0},{0.1,0},{0.5,0},{0.675,0}}")
- -- fill listbox with items
- listbox:resetList()
- orxonox.GUIManager:setItemTooltipsEnabledHelper(listbox, true)
- local preselect = "spaceshipAssff"
- local tabIndexes = {}
- for k,v in pairs(P.shipList) do
- --for i = 1 ,#P.shipList,1 do
- -- only add level if it has desired tag
- --if v:hasShip(Ship) then
- local item = CEGUI.createListboxTextItem("asbsergse")
- item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
- listbox:addItem(item)
- table.insert(tabIndexes, k)
- if v:getXMLFilename() == preselect then
- listbox:setItemSelectState(item, true)
- end
- --orxonox.GUIManager:setTooltipTextHelper(item, v:getDescription())
- -- end
- end
- table.insert(P.activeTabIndexes, tabIndexes)
- -- listen to selection changes
- orxonox.GUIManager:subscribeEventHelper(listbox, "ItemSelectionChanged", P.name..".SingleplayerSelectionChanged")
- local tabControl = winMgr:getWindow("orxonox/SingleplayerTabControl")
- orxonox.GUIManager:subscribeEventHelper(tabControl, "TabSelectionChanged", P.name..".SingleplayerSelectionChanged")
- if listbox:getItemCount() > 0 then
- tabControl:addChildWindow(tabName)
- end--]]
- -- create unique tab window name
-
local tabName = "orxonox/ShipSelectionLevelTab"
-- create new tab window with desired name
local listbox = CEGUI.toListbox(winMgr:createWindow("MenuWidgets/Listbox", tabName))
@@ -116,7 +67,7 @@
end
end
-function P.ShipSelectionGetSelectedLevel()
+function P.ShipSelectionGetSelectedModel()
-- choose the active listbox
local tabControl = CEGUI.toTabControl(winMgr:getWindow("orxonox/ShipSelectionTabControl"))
local listbox = CEGUI.toListbox(tabControl:getTabContentsAtIndex(tabControl:getSelectedTabIndex()))
@@ -125,7 +76,7 @@
-- get the right tab and the right index
local tabIndexes = P.activeTabIndexes[tabControl:getSelectedTabIndex()+1]
local index = tabIndexes[listbox:getItemIndex(choice)+1]
- --return P.levelList[index]
+ return P.shipList[index]
else
return nil
end
@@ -135,19 +86,19 @@
local levelImage = winMgr:getWindow("orxonox/ShipSelectionLevelImage")
local levelDescription = winMgr:getWindow("orxonox/ShipSelectionLevelDescription")
local configButton = winMgr:getWindow("orxonox/ShipSelectionConfigButton")
- local level = P.ShipSelectionGetSelectedLevel()
+ local level = P.ShipSelectionGetSelectedModel()
if level ~= nil then
- local levelXMLFilename = level:getXMLFilename()
- local imageName = level:getScreenshot()
+ --local levelXMLFilename = selectedlevel:getXMLFilename()
+ --local imageName = selectedlevel:getScreenshot()
-- set the screenshot and the description for the selected level
- levelImage:setProperty("Image", "set:"..levelXMLFilename..imageName.." image:full_image")
- levelDescription:setText(level:getDescription())
+ --levelImage:setProperty("Image", "set:"..levelXMLFilename..imageName.." image:full_image")
+ --levelDescription:setText(level:getDescription())
-- only enable config button for "gametype" levels
- if level:hasTag("gametype") then
- configButton:setProperty("Disabled", "False")
- else
- configButton:setProperty("Disabled", "True")
- end
+ --if level:hasTag("gametype") then
+ -- configButton:setProperty("Disabled", "False")
+ --else
+ -- configButton:setProperty("Disabled", "True")
+ --end
else
-- also take care of "no level selected"
levelImage:setProperty("Image", nil)
@@ -159,7 +110,7 @@
function P.ShipSelectionStartButton_clicked(e)
if selectedlevel ~= nil then
- selectedlevel:selectShip(P.ShipSelectionGetSelectedLevel())
+ selectedlevel:selectShip(P.ShipSelectionGetSelectedModel())
orxonox.execute("startGame " .. "_temp.oxw")
hideAllMenuSheets()
else
@@ -169,7 +120,7 @@
function P.ShipSelectionConfigButton_clicked(e)
--[[
- local level = P.ShipSelectionGetSelectedLevel()
+ local level = P.ShipSelectionGetSelectedModel()
if level ~= nil then
local configMenu = showMenuSheet("ShipSelectionConfigMenu")
configMenu:loadConfig(level)
Modified: code/branches/shipSelection/data/levels/tutorial.oxw
===================================================================
--- code/branches/shipSelection/data/levels/tutorial.oxw 2012-05-04 14:05:49 UTC (rev 9156)
+++ code/branches/shipSelection/data/levels/tutorial.oxw 2012-05-04 14:05:53 UTC (rev 9157)
@@ -3,7 +3,7 @@
description = "Level for the coding tutorial."
tags = "tutorial, shipselection"
screenshot = "codingtutorial.png"
- startingships = "spaceshipAssff, spaceshipGhost, spaceshipSpacecruiser"
+ startingships = "spaceshipassff, spaceshipghost, spaceshipspacecruiser"
/>
<?lua
Modified: code/branches/shipSelection/src/orxonox/LevelInfo.cc
===================================================================
--- code/branches/shipSelection/src/orxonox/LevelInfo.cc 2012-05-04 14:05:49 UTC (rev 9156)
+++ code/branches/shipSelection/src/orxonox/LevelInfo.cc 2012-05-04 14:05:53 UTC (rev 9157)
@@ -162,9 +162,10 @@
*/
bool LevelInfoItem::addShip(const std::string& ship, bool update)
{
- bool success = this->tags_.insert(ship).second;
+ bool success = this->ships_.insert(ship).second;
if(update && success)
- this->tagsUpdated();
+ this->shipsUpdated();
+
return success;
}
Added: code/branches/shipSelection/src/orxonox/ShipManager.cc
===================================================================
--- code/branches/shipSelection/src/orxonox/ShipManager.cc (rev 0)
+++ code/branches/shipSelection/src/orxonox/ShipManager.cc 2012-05-04 14:05:53 UTC (rev 9157)
@@ -0,0 +1,202 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Fabian 'x3n' Landau
+ * Co-authors:
+ * Damian 'Mozork' Frick
+ *
+ */
+
+/**
+ @file LevelManager.cc
+ @brief Implementation of the LevelManager singleton.
+*/
+
+#include "LevelManager.h"
+
+#include <map>
+
+#include "util/ScopedSingletonManager.h"
+#include "core/ClassTreeMask.h"
+#include "core/CommandLineParser.h"
+#include "core/ConfigValueIncludes.h"
+#include "core/CoreIncludes.h"
+#include "core/Loader.h"
+#include "core/Resource.h"
+#include "core/XMLFile.h"
+#include "Level.h"
+#include "PlayerManager.h"
+
+namespace orxonox
+{
+ SetCommandLineArgument(level, "").shortcut("l").information("Default level file (overrides LevelManager::defaultLevelName_ configValue)");
+
+ ManageScopedSingleton(LevelManager, ScopeID::Root, false);
+
+ /**
+ @brief
+ Constructor.
+ */
+ ShipManager::ShipManager()
+ {
+ RegisterRootObject(LevelManager);
+ this->compileAvailableLevelList();
+ this->nextIndex_ = 0;
+ this->nextLevel_ = this->availableLevels_.begin();
+ }
+
+ ShipManager::~ShipManager()
+ {
+ // Delete all the Ship objects because the LevelManager created them
+ std::set<SpaceShip*, LevelInfoCompare>::iterator it = availableLevels_.begin();
+ for (; it != availableLevels_.end(); ++it)
+ delete *it;
+ }
+
+
+ /**
+ @brief
+ Get the number of available Ships.
+ @return
+ Returns the number of available Ships.
+ */
+ unsigned int LevelManager::getNumberOfLevels(){ return this->availableLevels_.size(); }
+
+ /**
+ @brief
+ Get the SpaceShip at the given index in the list of available Ships.
+ The SpaceShips are sorted in alphabetical order accoridng to the name of the Ship.
+ This method is most efficiently called with consecutive indices (or at least ascending indices).
+ @param index
+ The index of the item that should be returned.
+ @return
+ Returns a pointer to the SpaceShip at the given index.
+ */
+ SpaceShip* ShipManager::getAvailableShipListItem(unsigned int index)
+ {
+ if(index >= this->availableShips_.size())
+ return NULL;
+
+ // If this index directly follows the last we can optimize a lot.
+ if(index == this->nextIndex_)
+ {
+ this->nextIndex_++;
+ std::set<SpaceShip*, SpaceShipCompare>::iterator it = this->nextShip_;
+ this->nextLevel_++;
+ return *it;
+ }
+ else
+ {
+ // If this index is bigger than the last, we can optimize a little.
+ if(index < this->nextIndex_)
+ {
+ this->nextIndex_ = 0;
+ this->nextShip_ = this->availableShips_.begin();
+ }
+
+ while(this->nextIndex_ != index)
+ {
+ this->nextIndex_++;
+ this->nextShip_++;
+ }
+ this->nextIndex_++;
+ std::set<SpaceShip*, SpaceShipCompare>::iterator it = this->nextLevel_;
+ this->nextLevel_++;
+ return *it;
+ }
+ }
+
+ /**
+ @brief
+ Compile the list of available Levels.
+ Iterates over all *.oxw files, loads the LevelInfo objects in them and from that it creates the LevelInfoItems which are inserted in a list.
+ */
+ void ShipManager::compileAvailableShipList()
+ {
+ /*
+ // We only want to load as little as possible
+ ClassTreeMask mask;
+ mask.exclude(Class(BaseObject));
+ mask.include(Class(SpaceShip));
+ SpaceShip* info = NULL;
+ XMLFile file = XMLFile(ship);
+ Loader::load(&file, mask, false, true);
+ for(ObjectList<SpaceShip>::iterator item = ObjectList<SpaceShip>::begin(); item != ObjectList<SpaceShip>::end(); ++item)
+ if(item->getXMLFilename() == *it)
+ info = item->copy();
+ Loader::unload(&file);
+ */
+
+ // Get all files matching the level criteria
+ Ogre::StringVectorPtr levels = Resource::findResourceNames("*.oxw");
+
+ // We only want to load as little as possible
+ ClassTreeMask mask;
+ mask.exclude(Class(BaseObject));
+ mask.include(Class(LevelInfo));
+
+ // Iterate over all the found *.oxw files
+ orxout(internal_info) << "Loading LevelInfos..." << endl;
+ std::set<std::string> names;
+ for (Ogre::StringVector::const_iterator it = levels->begin(); it != levels->end(); ++it)
+ {
+ // TODO: Replace with tag?
+ if (it->find("old/") != 0 )
+ {
+ LevelInfoItem* info = NULL;
+
+ // Load the LevelInfo object from the level file.
+ XMLFile file = XMLFile(*it);
+ Loader::load(&file, mask, false, true);
+
+ // Find the LevelInfo object we've just loaded (if there was one)
+ for(ObjectList<LevelInfo>::iterator item = ObjectList<LevelInfo>::begin(); item != ObjectList<LevelInfo>::end(); ++item)
+ if(item->getXMLFilename() == *it)
+ info = item->copy();
+
+ // We don't need the loaded stuff anymore
+ Loader::unload(&file);
+
+ if(info == NULL)
+ {
+ // Create a default LevelInfoItem object that merely contains the name
+ std::string filenameWOExtension = it->substr(0, it->find(".oxw"));
+ info = new LevelInfoItem(filenameWOExtension, *it);
+ }
+
+ // Warn about levels with the same name.
+ if(!names.insert(info->getName()).second)
+ orxout(internal_warning) << "Multiple levels (" << info->getXMLFilename() << ") with name '" << info->getName() << "' found!" << endl;
+
+ // Warn about multiple items so that it gets fixed quickly
+ if(availableLevels_.find(info) != availableLevels_.end())
+ {
+ orxout(internal_warning) << "Multiple levels (" << info->getXMLFilename() << ") with same name '" << info->getName() << "' and filename found! Exluding..." << endl;
+ // Delete LevelInfoItem to avoid a dangling pointer
+ delete info;
+ }
+ else
+ this->availableLevels_.insert(info);
+ }
+ }
+ }
+}
Added: code/branches/shipSelection/src/orxonox/ShipManager.h
===================================================================
--- code/branches/shipSelection/src/orxonox/ShipManager.h (rev 0)
+++ code/branches/shipSelection/src/orxonox/ShipManager.h 2012-05-04 14:05:53 UTC (rev 9157)
@@ -0,0 +1,93 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Matthias Hutter
+ */
+
+/**
+ @file ShipManager.h
+ @brief Definition of the ShipManager singleton.
+ @ingroup Orxonox
+*/
+
+#ifndef _ShipManager_H__
+#define _ShipManager_H__
+
+#include "OrxonoxPrereqs.h"
+
+#include <cassert>
+#include <list>
+#include <map>
+#include <string>
+#include "worldentities/pawns/SpaceShip.h"
+
+#include "util/Singleton.h"
+#include "core/OrxonoxClass.h"
+
+// tolua_begin
+namespace orxonox
+{
+
+ /**
+ @author
+ Matthias Hutter
+
+ @ingroup Orxonox
+ */
+ class _OrxonoxExport ShipManager
+ // tolua_end
+ : public Singleton<ShipManager>, public OrxonoxClass
+ { // tolua_export
+ friend class Singleton<LevelManager>;
+ public:
+ ShipManager();
+ virtual ~ShipManager();
+
+ void setConfigValues(); //!< Set the config values for this object.
+ // tolua_begin
+ /**
+ @brief Get the instance of the LevelManager.
+ @return Returns the instance of the LevelManager.
+ */
+ static ShipManager& getInstance()
+ { return Singleton<ShipManager>::getInstance(); }
+ // tolua_end
+
+ private:
+ ShipManager(const ShipManager&);
+
+
+ void compileAvailableLevelList(void); //!< Compile the list of available Levels.
+ void updateAvailableLevelList(void); //!< Update the list of available Levels.
+
+ std::list<Level*> levels_; //!< A list of all the Levels whose activity has been requested, in the order in which they will become active.
+ std::set<LevelInfoItem*, LevelInfoCompare> availableLevels_; //!< The set of available Levels sorted alphabetically according to the name of the Level.
+
+ // Helpers to allow fast access to the availableLevels list.
+ unsigned int nextIndex_; //! The next expected index to be accessed.
+ std::set<LevelInfoItem*, LevelInfoCompare>::iterator nextLevel_; //! The next expected Level to be accessed.
+
+ static LevelManager* singletonPtr_s;
+ }; // tolua_export
+} // tolua_export
+
+#endif /* _LevelManager_H__ */
More information about the Orxonox-commit
mailing list