[Orxonox-commit 2923] r7626 - in code/branches/releasetodo: data/gui/layouts data/gui/scripts src/orxonox
dafrick at orxonox.net
dafrick at orxonox.net
Sat Nov 6 21:52:48 CET 2010
Author: dafrick
Date: 2010-11-06 21:52:48 +0100 (Sat, 06 Nov 2010)
New Revision: 7626
Added:
code/branches/releasetodo/src/orxonox/LevelInfo.cc
Modified:
code/branches/releasetodo/data/gui/layouts/SingleplayerMenu.layout
code/branches/releasetodo/data/gui/scripts/MultiplayerMenu.lua
code/branches/releasetodo/data/gui/scripts/SingleplayerMenu.lua
code/branches/releasetodo/src/orxonox/LevelInfo.h
code/branches/releasetodo/src/orxonox/LevelManager.cc
code/branches/releasetodo/src/orxonox/LevelManager.h
Log:
Accidentally removed a file. Re-adding it.
Levels that are tagged with "test" are now not displayed by default, but can be displayed by choosing show all.
Modified: code/branches/releasetodo/data/gui/layouts/SingleplayerMenu.layout
===================================================================
--- code/branches/releasetodo/data/gui/layouts/SingleplayerMenu.layout 2010-11-06 19:17:20 UTC (rev 7625)
+++ code/branches/releasetodo/data/gui/layouts/SingleplayerMenu.layout 2010-11-06 20:52:48 UTC (rev 7626)
@@ -14,22 +14,34 @@
<Property Name="HorzFormatting" Value="HorzCentred" />
<Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
<Property Name="VertFormatting" Value="TopAligned" />
- <Property Name="UnifiedAreaRect" Value="{{0.25,0},{0.2875,0},{0.75,0},{0.6375,0}}" />
+ <Property Name="UnifiedAreaRect" Value="{{0.25,0},{0.2875,0},{0.75,0},{0.7,0}}" />
<Window Type="MenuWidgets/Listbox" Name="orxonox/SingleplayerLevelListbox" >
<Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
- <Property Name="UnifiedAreaRect" Value="{{0.05,0},{0.15,0},{0.95,0},{0.92,0}}" />
+ <Property Name="UnifiedAreaRect" Value="{{0.05,0},{0.15,0},{0.95,0},{0.85,0}}" />
</Window>
+ <Window Type="MenuWidgets/RadioButton" Name="orxonox/SingleplayerShowRestrictedButton" >
+ <Property Name="Text" Value="show only restricted" />
+ <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
+ <Property Name="UnifiedAreaRect" Value="{{0.15,0},{0.87,0},{0.5,0},{.97,0}}" />
+ <Event Name="SelectStateChanged" Function="SingleplayerMenu.SingleplayerShowRestrictedButton_clicked"/>
+ </Window>
+ <Window Type="MenuWidgets/RadioButton" Name="orxonox/SingleplayerShowAllButton" >
+ <Property Name="Text" Value="show all" />
+ <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
+ <Property Name="UnifiedAreaRect" Value="{{0.65,0},{0.87,0},{0.85,0},{.97,0}}" />
+ <Event Name="SelectStateChanged" Function="SingleplayerMenu.SingleplayerShowAllButton_clicked"/>
+ </Window>
</Window>
<Window Type="MenuWidgets/Button" Name="orxonox/SingleplayerStartButton" >
<Property Name="Text" Value="Start" />
<Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
- <Property Name="UnifiedAreaRect" Value="{{0.2875,0},{0.6625,0},{0.4875,0},{0.7125,0}}" />
+ <Property Name="UnifiedAreaRect" Value="{{0.2875,0},{0.725,0},{0.4875,0},{0.775,0}}" />
<Event Name="Clicked" Function="SingleplayerMenu.SingleplayerStartButton_clicked"/>
</Window>
<Window Type="MenuWidgets/Button" Name="orxonox/SingleplayerBackButton" >
<Property Name="Text" Value="Back" />
<Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
- <Property Name="UnifiedAreaRect" Value="{{0.5125,0},{0.6625,0},{0.7125,0},{0.7125,0}}" />
+ <Property Name="UnifiedAreaRect" Value="{{0.5125,0},{0.725,0},{0.7125,0},{0.775,0}}" />
<Event Name="Clicked" Function="SingleplayerMenu.SingleplayerBackButton_clicked"/>
</Window>
</Window>
Modified: code/branches/releasetodo/data/gui/scripts/MultiplayerMenu.lua
===================================================================
--- code/branches/releasetodo/data/gui/scripts/MultiplayerMenu.lua 2010-11-06 19:17:20 UTC (rev 7625)
+++ code/branches/releasetodo/data/gui/scripts/MultiplayerMenu.lua 2010-11-06 20:52:48 UTC (rev 7626)
@@ -2,6 +2,10 @@
local P = createMenuSheet("MultiplayerMenu")
+P.levelList = {}
+P.itemList = {}
+P.showAll = false
+
function P.onLoad()
P.multiplayerMode = "startClient"
end
@@ -68,35 +72,43 @@
end
function P.showLevelList()
- local listbox = winMgr:getWindow("orxonox/MultiplayerListbox")
- CEGUI.toListbox(listbox):resetList()
+ P.createLevelList()
+end
+
+function P.createLevelList()
+ P.levelList = {}
+ P.itemList = {}
+ local listbox = CEGUI.toListbox(winMgr:getWindow("orxonox/MultiplayerListbox"))
+ listbox:resetList()
local preselect = orxonox.LevelManager:getInstance():getDefaultLevel()
- orxonox.LevelManager:getInstance():compileAvailableLevelList()
- local levelList = {}
+ local size = orxonox.LevelManager:getInstance():getNumberOfLevels()
local index = 0
- local level = ""
- while true do
+ local level = nil
+ while index < size do
level = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index)
- if level == "" then
- break
+ if level ~= nil then
+ if P.showAll or not level:hasTag("test") then
+ table.insert(P.levelList, level)
+ end
end
- table.insert(levelList, level)
index = index + 1
end
- table.sort(levelList)
- index = 1
- for k,v in pairs(levelList) do
- local item = CEGUI.createListboxTextItem(v)
+ --TODO: Reintroduce sorting, if needed.
+ --table.sort(levelList)
+ for k,v in pairs(P.levelList) do
+ local item = CEGUI.createListboxTextItem(v:getName())
item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
- item:setID(index)
- index = index + 1
- CEGUI.toListbox(listbox):addItem(item)
- if v .. ".oxw" == preselect then
+ listbox:addItem(item)
+ if v:getXMLFilename() == preselect then
listbox:setItemSelectState(item, true)
end
+ P.itemList[k] = listbox:getListboxItemFromIndex(k-1)
+ --TODO: The description as tooltip would be nice.
+ --local lItem = tolua.cast("CEGUI::ListboxItem", P.itemList[k])
+ --lItem:setTooltipText(v:getDescription())
end
- end
-
+end
+
function P.showServerList()
local listbox = winMgr:getWindow("orxonox/MultiplayerListbox")
CEGUI.toListbox(listbox):resetList()
Modified: code/branches/releasetodo/data/gui/scripts/SingleplayerMenu.lua
===================================================================
--- code/branches/releasetodo/data/gui/scripts/SingleplayerMenu.lua 2010-11-06 19:17:20 UTC (rev 7625)
+++ code/branches/releasetodo/data/gui/scripts/SingleplayerMenu.lua 2010-11-06 20:52:48 UTC (rev 7626)
@@ -2,39 +2,75 @@
local P = createMenuSheet("SingleplayerMenu")
+P.levelList = {}
+P.itemList = {}
+P.showAll = false
+
function P.onLoad()
- listbox = winMgr:getWindow("orxonox/SingleplayerLevelListbox")
- preselect = orxonox.LevelManager:getInstance():getDefaultLevel()
- size = orxonox.LevelManager:getInstance():getNumberOfLevels()
- local levelList = {}
+ local window = winMgr:getWindow("orxonox/SingleplayerShowRestrictedButton")
+ local button = tolua.cast(window,"CEGUI::RadioButton")
+ button:setSelected(true)
+ P.createLevelList()
+end
+
+function P.createLevelList()
+ P.levelList = {}
+ P.itemList = {}
+ local listbox = CEGUI.toListbox(winMgr:getWindow("orxonox/SingleplayerLevelListbox"))
+ listbox:resetList()
+ local preselect = orxonox.LevelManager:getInstance():getDefaultLevel()
+ local size = orxonox.LevelManager:getInstance():getNumberOfLevels()
local index = 0
- local level = ""
+ local level = nil
while index < size do
- level = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index)
- table.insert(levelList, level)
- index = index + 1
+ level = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index)
+ if level ~= nil then
+ if P.showAll or not level:hasTag("test") then
+ table.insert(P.levelList, level)
+ end
+ end
+ index = index + 1
end
- table.sort(levelList)
- for k,v in pairs(levelList) do
- item = CEGUI.createListboxTextItem(v)
+ --TODO: Reintroduce sorting, if needed.
+ --table.sort(levelList)
+ for k,v in pairs(P.levelList) do
+ local item = CEGUI.createListboxTextItem(v:getName())
item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
- CEGUI.toListbox(listbox):addItem(item)
- if v .. ".oxw" == preselect then
+ listbox:addItem(item)
+ if v:getXMLFilename() == preselect then
listbox:setItemSelectState(item, true)
end
+ P.itemList[k] = listbox:getListboxItemFromIndex(k-1)
+ --TODO: The description as tooltip would be nice.
+ --local lItem = tolua.cast("CEGUI::ListboxItem", P.itemList[k])
+ --lItem:setTooltipText(v:getDescription())
end
-
end
function P.SingleplayerStartButton_clicked(e)
- local choice = CEGUI.toListbox(winMgr:getWindow("orxonox/SingleplayerLevelListbox")):getFirstSelectedItem()
- if choice then
- orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw")
- orxonox.execute("startGame")
- hideAllMenuSheets()
+ local listbox = CEGUI.toListbox(winMgr:getWindow("orxonox/SingleplayerLevelListbox"))
+ local choice = listbox:getFirstSelectedItem()
+ if choice ~= nil then
+ local index = listbox:getItemIndex(choice)
+ local level = P.levelList[index+1]
+ if level ~= nil then
+ orxonox.LevelManager:getInstance():setDefaultLevel(level:getXMLFilename())
+ orxonox.execute("startGame")
+ hideAllMenuSheets()
+ end
end
end
+function P.SingleplayerShowRestrictedButton_clicked(e)
+ P.showAll = false
+ P.createLevelList()
+end
+
+function P.SingleplayerShowAllButton_clicked(e)
+ P.showAll = true
+ P.createLevelList()
+end
+
function P.SingleplayerBackButton_clicked(e)
hideMenuSheet(P.name)
end
Added: code/branches/releasetodo/src/orxonox/LevelInfo.cc
===================================================================
--- code/branches/releasetodo/src/orxonox/LevelInfo.cc (rev 0)
+++ code/branches/releasetodo/src/orxonox/LevelInfo.cc 2010-11-06 20:52:48 UTC (rev 7626)
@@ -0,0 +1,185 @@
+/*
+ * 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:
+ * Damian 'Mozork' Frick
+ * Co-authors:
+ * ...
+ *
+ */
+
+#include "LevelInfo.h"
+
+#include <sstream>
+#include <vector>
+
+#include "util/SubString.h"
+#include "core/CoreIncludes.h"
+#include "core/XMLPort.h"
+
+#include "LevelManager.h"
+
+namespace orxonox
+{
+
+ // LevelInfoItem
+
+ /**
+ @brief
+ Default constructor.
+ */
+ LevelInfoItem::LevelInfoItem()
+ {
+
+ }
+
+ /**
+ @brief
+ Constructor. Initializes the object.
+ @param name
+ The name of the Level.
+ @param filename
+ The XML-filename of the Level.
+ */
+ LevelInfoItem::LevelInfoItem(const std::string& name, const std::string filename)
+ {
+ this->setName(name);
+ this->setXMLFilename(filename);
+ }
+
+ /**
+ @brief
+ Destructor.
+ */
+ LevelInfoItem::~LevelInfoItem()
+ {
+
+ }
+
+ /**
+ @brief
+ Set the tags the Level is tagged with.
+ @param tags
+ A comma-seperated string of all the tags to be set.
+ */
+ void LevelInfoItem::setTags(const std::string& tags)
+ {
+ SubString substr = SubString(tags, ",", " "); // Split the string into tags.
+ const std::vector<std::string>& strings = substr.getAllStrings();
+ for(std::vector<std::string>::const_iterator it = strings.begin(); it != strings.end(); it++)
+ this->addTag(*it, false);
+
+ this->tagsUpdated();
+ }
+
+ /**
+ @brief
+ Add a tag to the set of tags the Level is tagged with.
+ @param tag
+ The tag to be added.
+ @param update
+ Whether the comma-seperated string of all tags should be updated. Default is true.
+ @return
+ Returns true if the tag was successfully added, if the tag was already present it returns false.
+ */
+ bool LevelInfoItem::addTag(const std::string& tag, bool update)
+ {
+ bool success = this->tags_.insert(std::string(tag)).second;
+ if(update && success)
+ this->tagsUpdated();
+ return success;
+ }
+
+ /**
+ @brief
+ Updates the comma-seperated string of all tags, if the set of tags has changed.
+ */
+ void LevelInfoItem::tagsUpdated(void)
+ {
+ std::stringstream stream;
+ std::set<std::string>::iterator temp;
+ for(std::set<std::string>::iterator it = this->tags_.begin(); it != this->tags_.end(); )
+ {
+ temp = it;
+ if(++it == this->tags_.end()) // If this is the last tag we don't add a comma.
+ stream << *temp;
+ else
+ stream << *temp << ", ";
+ }
+
+ this->tagsString_ = std::string(stream.str());
+ }
+
+ // LevelInfo
+
+ CreateFactory(LevelInfo);
+
+ /**
+ @brief
+
+ @param creator
+ The creator of this object.
+ */
+ LevelInfo::LevelInfo(BaseObject* creator) : BaseObject(creator)
+ {
+ RegisterObject(LevelInfo);
+
+ this->xmlfilename_ = this->getFilename();
+ }
+
+ /**
+ @brief
+ Destructor.
+ */
+ LevelInfo::~LevelInfo()
+ {
+
+ }
+
+ /**
+ @brief
+ Creates a LevelInfo object through XML.
+ */
+ void LevelInfo::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+ {
+ SUPER(LevelInfo, XMLPort, xmlelement, mode);
+
+ XMLPortParam(LevelInfo, "description", setDescription, getDescription, xmlelement, mode);
+ XMLPortParam(LevelInfo, "tags", setTags, getTags, xmlelement, mode);
+ }
+
+ /**
+ @brief
+ Copies the contents of this LevelInfo object to a new LevelInfoItem object.
+ This is needed, because a LeveInfo object is only created within the scope of the XML-file it is loaded with and is destroyed once that is unloaded.
+ @return
+ Returns a new LevelInfoItem with the same contents as the LevelInfo object.
+ */
+ LevelInfoItem* LevelInfo::copy(void)
+ {
+ LevelInfoItem* info = new LevelInfoItem(this->BaseObject::getName(), this->getXMLFilename());
+ info->setDescription(this->getDescription());
+ info->setTags(this->getTags());
+ return info;
+ }
+
+}
+
Modified: code/branches/releasetodo/src/orxonox/LevelInfo.h
===================================================================
--- code/branches/releasetodo/src/orxonox/LevelInfo.h 2010-11-06 19:17:20 UTC (rev 7625)
+++ code/branches/releasetodo/src/orxonox/LevelInfo.h 2010-11-06 20:52:48 UTC (rev 7626)
@@ -43,8 +43,8 @@
#include "core/BaseObject.h"
#include "core/OrxonoxClass.h"
-namespace orxonox
-{
+namespace orxonox // tolua_export
+{ // tolua_export
/**
@brief
@@ -54,8 +54,9 @@
@author
Damian 'Mozork' Frick
*/
- class _OrxonoxExport LevelInfoItem : virtual public OrxonoxClass
- {
+ class _OrxonoxExport LevelInfoItem // tolua_export
+ : virtual public OrxonoxClass
+ { // tolua_export
public:
LevelInfoItem(); //!< Default constructor.
LevelInfoItem(const std::string& name, const std::string filename); //!< Constructor. Initializes the object.
@@ -71,8 +72,7 @@
@brief Get the name of the Level.
@return Returns the name of the Level.
*/
- inline const std::string& getName(void)
- { return this->name_; }
+ inline const std::string& getName(void) { return this->name_; } // tolua_export
/**
@brief Set the description of the Level.
@@ -84,8 +84,7 @@
@brief Get the description of the Level.
@return Returns the description of the Level.
*/
- inline const std::string& getDescription() const
- { return this->description_; }
+ inline const std::string& getDescription() const { return this->description_; } // tolua_export
void setTags(const std::string& tags); //!< Set the tags the Level is tagged with.
bool addTag(const std::string& tag, bool update = true); //!< Add a tag to the set of tags the Level is tagged with.
@@ -100,15 +99,13 @@
@param tag The tag for which is checked.
@return Returns true if the Level is tagged with the input tag.
*/
- bool hasTag(const std::string& tag) const
- { return this->tags_.find(tag) != this->tags_.end(); }
+ inline bool hasTag(const std::string& tag) const { return this->tags_.find(tag) != this->tags_.end(); } // tolua_export
/**
@brief Get the XML-filename of the Level.
@return Returns the XML-filename (including *.oxw extension) of the Level.
*/
- inline const std::string& getXMLFilename(void)
- { return this->xmlfilename_; }
+ inline const std::string& getXMLFilename(void) { return this->xmlfilename_; } // tolua_export
protected:
/**
@@ -127,7 +124,7 @@
std::string description_; //!< The description of the Level.
std::set<std::string> tags_; //!< The set of tags the Level is tagged with.
std::string tagsString_; //!< The comma-seperated string of all the tags the Level is tagged with.
- };
+ }; // tolua_export
/**
@brief
@@ -187,6 +184,6 @@
LevelInfoItem* copy(void); //!< Copies the contents of this LevelInfo object to a new LevelInfoItem object.
};
-}
+} // tolua_export
#endif /* _LevelInfo_H__ */
Modified: code/branches/releasetodo/src/orxonox/LevelManager.cc
===================================================================
--- code/branches/releasetodo/src/orxonox/LevelManager.cc 2010-11-06 19:17:20 UTC (rev 7625)
+++ code/branches/releasetodo/src/orxonox/LevelManager.cc 2010-11-06 20:52:48 UTC (rev 7626)
@@ -133,20 +133,17 @@
{
this->updateAvailableLevelList();
- COUT(0) << "Number of Levels: " << this->infos_.size() << std::endl;
-
return this->availableLevels_.size();
}
- const std::string& LevelManager::getAvailableLevelListItem(unsigned int index) const
+ LevelInfoItem* LevelManager::getAvailableLevelListItem(unsigned int index) const
{
if (index >= this->availableLevels_.size())
- return BLANKSTRING;
+ return NULL;
else
{
std::map<std::string, LevelInfoItem*>::const_iterator it = this->infos_.find(this->availableLevels_[index]);
- assert(it->second);
- return it->second->getName();
+ return it->second;
}
}
@@ -171,7 +168,6 @@
for(ObjectList<LevelInfo>::iterator item = ObjectList<LevelInfo>::begin(); item != ObjectList<LevelInfo>::end(); ++item)
{
LevelInfoItem* info = item->copy();
- COUT(0) << "BUUUUUUUUUH: " << info->getName() << " | " << info->getXMLFilename() << " | " << it->substr(0, pos) << std::endl;
if(info->getXMLFilename() == *it)
{
this->infos_.insert(std::pair<std::string, LevelInfoItem*>(it->substr(0, pos),info));
Modified: code/branches/releasetodo/src/orxonox/LevelManager.h
===================================================================
--- code/branches/releasetodo/src/orxonox/LevelManager.h 2010-11-06 19:17:20 UTC (rev 7625)
+++ code/branches/releasetodo/src/orxonox/LevelManager.h 2010-11-06 20:52:48 UTC (rev 7626)
@@ -60,7 +60,7 @@
void setDefaultLevel(const std::string& levelName); //tolua_export
const std::string& getDefaultLevel() const; //tolua_export
unsigned int getNumberOfLevels(void); //tolua_export
- const std::string& getAvailableLevelListItem(unsigned int index) const; //tolua_export
+ LevelInfoItem* getAvailableLevelListItem(unsigned int index) const; //tolua_export
static LevelManager& getInstance() { return Singleton<LevelManager>::getInstance(); } // tolua_export
More information about the Orxonox-commit
mailing list