[Orxonox-commit 4386] r9057 - in code/branches/shipSelection: data/gui/scripts data/levels src/orxonox

huttemat at orxonox.net huttemat at orxonox.net
Fri Mar 23 16:24:24 CET 2012


Author: huttemat
Date: 2012-03-23 16:24:24 +0100 (Fri, 23 Mar 2012)
New Revision: 9057

Modified:
   code/branches/shipSelection/data/gui/scripts/ShipSelectionMenu.lua
   code/branches/shipSelection/data/gui/scripts/SingleplayerMenu.lua
   code/branches/shipSelection/data/levels/tutorial.oxw
   code/branches/shipSelection/src/orxonox/LevelInfo.cc
   code/branches/shipSelection/src/orxonox/LevelInfo.h
Log:
test2

Modified: code/branches/shipSelection/data/gui/scripts/ShipSelectionMenu.lua
===================================================================
--- code/branches/shipSelection/data/gui/scripts/ShipSelectionMenu.lua	2012-03-23 15:16:03 UTC (rev 9056)
+++ code/branches/shipSelection/data/gui/scripts/ShipSelectionMenu.lua	2012-03-23 15:24:24 UTC (rev 9057)
@@ -1,16 +1,13 @@
 -- ShipSelectionMenu.lua
 
 local P = createMenuSheet("ShipSelectionMenu")
-level = nil
 P.activeTabIndexes = {}
 P.scrollbarWidth = 13
-function P.loadShips(levelname)
-    --orxonox.execute("echo " .. levelname)
-    --level = levelname
-end
+
 function P.onLoad()
---[[    P.createLevelList()
-    
+   orxonox.execute("orxout internal_warning Ships= " .. selectedlevel.getShips())
+   P.createLevelList(selectedlevel)
+--[[     
     -- create tabs with desired tab as argument (nil for all)
     P.createFilterTab("Gametypes", "gametype")
     P.createFilterTab("Missions", "mission")
@@ -39,9 +36,14 @@
             ["callback"]  = P.ShipSelectionBackButton_clicked
     })--]]
 end
---[[
-function P.createLevelList()
-    P.levelList = {}
+
+function P.createShipList(level)
+
+    orxonox.execute("orxout internal_warning Ships= " .. selectedlevel:getShips())
+    --local stream = selectedlevel:getShips()
+    --local substr = stream
+    --while substr.find(",")
+    --[[
     local size = orxonox.LevelManager:getInstance():getNumberOfLevels()
     local index = 0
     local level = nil
@@ -59,9 +61,11 @@
             table.insert(P.levelList, level)
         end
         index = index + 1
-    end
+    end--]]
 end
 
+
+
 function P.createFilterTab(name, tag)
     -- create unique tab window name
     local tabName = "orxonox/ShipSelectionLevelTab"

Modified: code/branches/shipSelection/data/gui/scripts/SingleplayerMenu.lua
===================================================================
--- code/branches/shipSelection/data/gui/scripts/SingleplayerMenu.lua	2012-03-23 15:16:03 UTC (rev 9056)
+++ code/branches/shipSelection/data/gui/scripts/SingleplayerMenu.lua	2012-03-23 15:24:24 UTC (rev 9057)
@@ -5,6 +5,7 @@
 P.levelList = {}
 P.activeTabIndexes = {}
 P.scrollbarWidth = 13
+selectedlevel = {} -- level for ship selection
 
 function P.onLoad()
     P.createLevelList()
@@ -140,14 +141,12 @@
 end
 
 function P.SingleplayerStartButton_clicked(e)
-    local level = P.SingleplayerGetSelectedLevel()
-    if level ~= nil then
-
-        if level:hasTag("shipselection") then
+    selectedlevel = P.SingleplayerGetSelectedLevel()
+    if selectedlevel ~= nil then
+        if selectedlevel:hasTag("shipselection") then
             local shipSelectionMenu = showMenuSheet("ShipSelectionMenu", true)
-            shipSelectionMenu:loadShips(level:getXMLFilename())
         else
-            orxonox.execute("startGame " .. level:getXMLFilename())
+            orxonox.execute("startGame " .. selectedlevel:getXMLFilename())
             hideAllMenuSheets()
 	end
     end

Modified: code/branches/shipSelection/data/levels/tutorial.oxw
===================================================================
--- code/branches/shipSelection/data/levels/tutorial.oxw	2012-03-23 15:16:03 UTC (rev 9056)
+++ code/branches/shipSelection/data/levels/tutorial.oxw	2012-03-23 15:24:24 UTC (rev 9057)
@@ -3,6 +3,7 @@
  description = "Level for the coding tutorial."
  tags = "tutorial, shipselection"
  screenshot = "codingtutorial.png"
+ startingships = "spaceshipGhost, spaceshipPirate, spaceshipSpacecruiser"
 />
 
 <?lua

Modified: code/branches/shipSelection/src/orxonox/LevelInfo.cc
===================================================================
--- code/branches/shipSelection/src/orxonox/LevelInfo.cc	2012-03-23 15:16:03 UTC (rev 9056)
+++ code/branches/shipSelection/src/orxonox/LevelInfo.cc	2012-03-23 15:24:24 UTC (rev 9057)
@@ -111,7 +111,22 @@
 
         this->tagsUpdated();
     }
+    /**
+    @brief
+        Set the starting ship models of the level
+    @param tags
+        A comma-seperated string of all the allowed ship models for the shipselection.
+    */
+    void LevelInfoItem::setShips(const std::string& ships)
+    {
+        SubString substr = SubString(ships, ",", " "); // 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->addShip(*it, false);
 
+        this->shipsUpdated();
+    }
+
     /**
     @brief
         Add a tag to the set of tags the Level is tagged with.
@@ -137,6 +152,25 @@
 
     /**
     @brief
+        Add a ship model to allowed models for the shipselection
+    @param ship
+        The ship model to be added.
+    @param update
+        Whether the comma-seperated string of all ship models should be updated. Default is true.
+    @return
+        Returns true if the ship was successfully added, if the ship was already present it returns false.
+    */
+    bool LevelInfoItem::addShip(const std::string& ship, bool update)
+    {
+        bool success = this->tags_.insert(ship).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)
@@ -155,6 +189,25 @@
         this->tagsString_ = std::string(stream.str());
     }
 
+    /**
+    @brief
+        Updates the comma-seperated string of all ships, if the set of tags has changed.
+    */
+    void LevelInfoItem::shipsUpdated(void)
+    {
+        std::stringstream stream;
+        std::set<std::string>::iterator temp;
+        for(std::set<std::string>::iterator it = this->ships_.begin(); it != this->ships_.end(); )
+        {
+            temp = it;
+            if(++it == this->ships_.end()) // If this is the last ship we don't add a comma.
+                stream << *temp;
+            else
+                stream << *temp << ", ";
+        }
+
+        this->startingShipsString_ = std::string(stream.str());
+    }
     // LevelInfo
 
     CreateFactory(LevelInfo);
@@ -192,6 +245,7 @@
         XMLPortParam(LevelInfo, "description", setDescription, getDescription, xmlelement, mode);
         XMLPortParam(LevelInfo, "screenshot", setScreenshot, getScreenshot, xmlelement, mode);
         XMLPortParam(LevelInfo, "tags", setTags, getTags, xmlelement, mode);
+        XMLPortParam(LevelInfo, "startingships", setShips, getShips, xmlelement, mode);
     }
 
     /**
@@ -207,6 +261,7 @@
         info->setDescription(this->getDescription());
         info->setScreenshot(this->getScreenshot());
         info->setTags(this->getTags());
+        info->setShips(this->getShips());
         return info;
     }
 

Modified: code/branches/shipSelection/src/orxonox/LevelInfo.h
===================================================================
--- code/branches/shipSelection/src/orxonox/LevelInfo.h	2012-03-23 15:16:03 UTC (rev 9056)
+++ code/branches/shipSelection/src/orxonox/LevelInfo.h	2012-03-23 15:24:24 UTC (rev 9057)
@@ -23,7 +23,7 @@
  *      Damian 'Mozork' Frick
  *   Co-authors:
  *      ...
- *
+ *   
  */
 
 /**
@@ -114,11 +114,26 @@
             @return Returns true if the Level is tagged with the input tag.
             */
             inline bool hasTag(const std::string& tag) const { return this->tags_.find(tag) != this->tags_.end(); } // tolua_export
-
+ 
+            void setShips(const std::string& ships); //!< Set the starting ship models of the level
+            bool addShip(const std::string& ship, bool update = true); //!< Add a model to shipselection
             /**
+            @brief Get the set of starting ship models the Level allows
+            @return Returns a comma-seperated string of all the allowed ship models for the shipselection.
+            */
+            inline const std::string& getShips(void) const
+                { return this->startingShipsString_; }    
+            /**
+            @brief Get whether the Level allows a specific starting ship model
+            @param ship The ship model for which is checked.
+            @return Returns true if the Level allows the input ship model
+            */
+            inline bool hasShip(const std::string& ship) const { return this->ships_.find(ship) != this->ships_.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) const { return this->xmlfilename_; } // tolua_export
 
         protected:
@@ -133,7 +148,7 @@
 
         private:
             void tagsUpdated(void); //!< Updates the comma-seperated string of all tags, if the set of tags has changed.
-
+            void shipsUpdated(void); //!< Updates the comma-seperated string of all tags, if the set of tags has changed.
             static void initializeTags(void); //!< Initialize the set of allowed tags.
             /**
             @brief Check whether an input tag is allowed.
@@ -151,6 +166,8 @@
             std::string screenshot_; //!< The screenshot 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.
+            std::set<std::string> ships_; //!< The set of starting ship models the Level allows.
+            std::string startingShipsString_; //!< The comma-seperated string of all the allowed ship models for the shipselection.            
     }; // tolua_export
 
     /**
@@ -160,8 +177,8 @@
         - @b name The name of the level.
         - @b description The description of the level.
         - @b screenshot The screenshot of the level.
-        - @b tags A comma-seperated string of tags. Allowed tags are: <em>test</em>, <em>singleplayer</em>, <em>multiplayer</em>, <em>showcase</em>, <em>tutorial</em>, <em>presentation</em>.
-
+        - @b tags A comma-seperated string of tags. Allowed tags are: <em>test</em>, <em>singleplayer</em>, <em>multiplayer</em>, <em>showcase</em>, <em>tutorial</em>, <em>presentation</em>, <em>shipselection</em>.
+        - @b (optional) startingships The comma-seperated string of starting ship models 
         An example would be:
         @code
         <LevelInfo
@@ -175,7 +192,8 @@
 
     @author
         Damian 'Mozork' Frick
-
+	@edit
+		Matthias Hutter
     @ingroup Orxonox
     */
     class _OrxonoxExport LevelInfo : public BaseObject, public LevelInfoItem
@@ -222,9 +240,19 @@
             */
             inline const std::string& getTags(void) const
                 { return this->LevelInfoItem::getTags(); }
-
+            /**
+            @brief Set the starting ship models of the level
+            @param A comma-seperated string of all the allowed ship models for the shipselection.
+            */
+            inline void setShips(const std::string& ships)
+                { this->LevelInfoItem::setShips(ships); }
+            /**
+            @brief Get the starting ship models of the level
+            @return Returns a comma-seperated string of all the allowed ship models for the shipselection.
+            */
+            inline const std::string& getShips(void) const
+                { return this->LevelInfoItem::getShips(); }              
             LevelInfoItem* copy(void); //!< Copies the contents of this LevelInfo object to a new LevelInfoItem object.
-
     };
 
     /**




More information about the Orxonox-commit mailing list