Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9208


Ignore:
Timestamp:
May 18, 2012, 3:39:47 PM (12 years ago)
Author:
smerkli
Message:

merged branch shipSelection

Location:
code/branches/presentation2012
Files:
7 edited
4 copied

Legend:

Unmodified
Added
Removed
  • code/branches/presentation2012

  • code/branches/presentation2012/data/gui/scripts/SingleplayerMenu.lua

    r9050 r9208  
    22
    33local P = createMenuSheet("SingleplayerMenu")
    4 
     4P.loadAlong = {"ShipSelectionMenu"}
    55P.levelList = {}
    66P.activeTabIndexes = {}
    77P.scrollbarWidth = 13
     8selectedlevel = {} -- level for ship selection
    89
    910function P.onLoad()
     
    4647    while index < size do
    4748        level = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index)
    48         if level ~= nil then
     49        if (level ~= nil and level:getXMLFilename() ~= "_temp.oxw") then
     50            --os.execute("echo " .. level:getXMLFilename() .." >> ~/outputorx")
    4951            local levelXMLFilename = level:getXMLFilename()
    5052            -- create an imageset for each screenshot
     
    141143
    142144function P.SingleplayerStartButton_clicked(e)
    143     local level = P.SingleplayerGetSelectedLevel()
    144     if level ~= nil then
    145         orxonox.execute("startGame " .. level:getXMLFilename())
    146         hideAllMenuSheets()
     145    selectedlevel = P.SingleplayerGetSelectedLevel()
     146    if selectedlevel ~= nil then
     147        if selectedlevel:hasTag("shipselection") then
     148            local shipSelectionMenu = showMenuSheet("ShipSelectionMenu", true)
     149            shipSelectionMenu:update()
     150        else
     151            orxonox.execute("startGame " .. selectedlevel:getXMLFilename())
     152            hideAllMenuSheets()
     153        end
    147154    end
    148155end
  • code/branches/presentation2012/data/levels/tutorial.oxw

    r9016 r9208  
    22 name = "Coding Tutorial"
    33 description = "Level for the coding tutorial."
    4  tags = "tutorial"
     4 tags = "tutorial, shipselection"
    55 screenshot = "codingtutorial.png"
     6 startingships = "spaceshipassff, spaceshipghost, spaceshipspacecruiser"
    67/>
    78
     
    1011  include("stats.oxo")
    1112  include("templates/spaceshipAssff.oxt")
     13  include("templates/spaceshipGhost.oxt")
     14  include("templates/spaceshipSpacecruiser.oxt")
    1215  include("templates/lodInformation.oxt")
    1316?>
     
    2326   skybox       = "Orxonox/skypanoramagen1"
    2427  >
    25 
    26 
    27 
    28 
    2928<Drone name="meineDrohne" primarythrust="80" auxilarythrust="10" rotationthrust="10" mass= "50" linearDamping = "0.9" angularDamping = "0.7">
    3029  <attached>
     
    5352      for i = 1, 10, 1 do
    5453    ?>
    55       <SpawnPoint position="<?lua print(math.random() * 1000 - 500) ?>,<?lua print(math.random() * 1000 - 500) ?>,<?lua print(math.random() * 1000 - 500) ?>" lookat="0,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff />
     54      <SpawnPoint position="<?lua print(math.random() * 1000 - 500) ?>,<?lua print(math.random() * 1000 - 500) ?>,<?lua print(math.random() * 1000 - 500) ?>" lookat="0,0,0" spawnclass=SpaceShip pawndesign=shipselection />
    5655    <?lua end ?>
    5756
  • code/branches/presentation2012/src/libraries/core/Loader.cc

    r8858 r9208  
    222222
    223223            orxout(verbose, context::loader) << "Namespace-tree:" << '\n' << rootNamespace->toString("  ") << endl;
    224 
     224                       
    225225            return true;
    226226        }
  • code/branches/presentation2012/src/orxonox/LevelInfo.cc

    r9016 r9208  
    9393            LevelInfoItem::possibleTags_s.insert("gametype");
    9494            LevelInfoItem::possibleTags_s.insert("minigame");
     95            LevelInfoItem::possibleTags_s.insert("shipselection");
    9596        }
    9697    }
     
    110111
    111112        this->tagsUpdated();
     113    }
     114    /**
     115    @brief
     116        Set the starting ship models of the level
     117    @param tags
     118        A comma-seperated string of all the allowed ship models for the shipselection.
     119    */
     120    void LevelInfoItem::setShips(const std::string& ships)
     121    {
     122        SubString substr = SubString(ships, ",", " "); // Split the string into tags.
     123        const std::vector<std::string>& strings = substr.getAllStrings();
     124        for(std::vector<std::string>::const_iterator it = strings.begin(); it != strings.end(); it++)
     125            this->addShip(*it, false);
     126
     127        this->shipsUpdated();
    112128    }
    113129
     
    137153    /**
    138154    @brief
     155        Add a ship model to allowed models for the shipselection
     156    @param ship
     157        The ship model to be added.
     158    @param update
     159        Whether the comma-seperated string of all ship models should be updated. Default is true.
     160    @return
     161        Returns true if the ship was successfully added, if the ship was already present it returns false.
     162    */
     163    bool LevelInfoItem::addShip(const std::string& ship, bool update)
     164    {
     165        bool success = this->ships_.insert(ship).second;
     166        if(update && success)
     167            this->shipsUpdated();
     168           
     169        return success;
     170    }
     171
     172
     173    /**
     174    @brief
    139175        Updates the comma-seperated string of all tags, if the set of tags has changed.
    140176    */
     
    155191    }
    156192
     193    /**
     194    @brief
     195        Updates the comma-seperated string of all ships, if the set of tags has changed.
     196    */
     197    void LevelInfoItem::shipsUpdated(void)
     198    {
     199        std::stringstream stream;
     200        std::set<std::string>::iterator temp;
     201        for(std::set<std::string>::iterator it = this->ships_.begin(); it != this->ships_.end(); )
     202        {
     203            temp = it;
     204            if(++it == this->ships_.end()) // If this is the last ship we don't add a comma.
     205                stream << *temp;
     206            else
     207                stream << *temp << ", ";
     208        }
     209
     210        this->startingShipsString_ = std::string(stream.str());
     211    }
    157212    // LevelInfo
    158213
     
    192247        XMLPortParam(LevelInfo, "screenshot", setScreenshot, getScreenshot, xmlelement, mode);
    193248        XMLPortParam(LevelInfo, "tags", setTags, getTags, xmlelement, mode);
     249        XMLPortParam(LevelInfo, "startingships", setShips, getShips, xmlelement, mode);
    194250    }
    195251
     
    207263        info->setScreenshot(this->getScreenshot());
    208264        info->setTags(this->getTags());
     265        info->setShips(this->getShips());
    209266        return info;
    210267    }
  • code/branches/presentation2012/src/orxonox/LevelInfo.h

    r9016 r9208  
    2424 *   Co-authors:
    2525 *      ...
    26  *
     26 *   
    2727 */
    2828
     
    4343
    4444#include "core/BaseObject.h"
     45#include <iostream>
     46#include <fstream>
    4547#include "core/OrxonoxClass.h"
    4648
     
    115117            */
    116118            inline bool hasTag(const std::string& tag) const { return this->tags_.find(tag) != this->tags_.end(); } // tolua_export
    117 
     119 
     120            void setShips(const std::string& ships); //!< Set the starting ship models of the level
     121            bool addShip(const std::string& ship, bool update = true); //!< Add a model to shipselection
     122            /**
     123            @brief Get the set of starting ship models the Level allows
     124            @return Returns a comma-seperated string of all the allowed ship models for the shipselection.
     125            */
     126            inline const std::string& getShips(void) const
     127                { return this->startingShipsString_; }   
     128            /**
     129            @brief Get whether the Level allows a specific starting ship model
     130            @param ship The ship model for which is checked.
     131            @return Returns true if the Level allows the input ship model
     132            */
     133            inline bool hasShip(const std::string& ship) const { return this->ships_.find(ship) != this->ships_.end(); } // tolua_export       
    118134            /**
    119135            @brief Get the XML-filename of the Level.
    120136            @return Returns the XML-filename (including *.oxw extension) of the Level.
    121137            */
     138
    122139            inline const std::string& getXMLFilename(void) const { return this->xmlfilename_; } // tolua_export
     140            inline void selectShip (const std::string& ship) { this->changeShip(ship); } // tolua_export
     141
    123142
    124143        protected:
     
    133152
    134153        private:
     154
     155            inline void changeShip (const std::string& model) {
     156                static std::string shipSelectionTag = "shipselection";
     157                //HACK: Read Level XML File, find "shipselection", replace with ship model
     158                std::string levelPath = "../levels/";
     159                levelPath.append(this->getXMLFilename());
     160                std::string tempPath = "../levels/";
     161                tempPath.append("_temp.oxw");
     162                orxout(user_status) << levelPath << endl;
     163                orxout(user_status) << tempPath << endl;
     164                std::ifstream myLevel (levelPath.c_str());
     165                        std::ofstream tempLevel (tempPath.c_str());
     166                        while(!myLevel.eof())
     167                        {
     168                                std::string buff;
     169                                std::getline(myLevel, buff);
     170                                std::string pawndesignString = "pawndesign=";
     171                                size_t found = buff.find(pawndesignString.append(shipSelectionTag));
     172                                if (found!= std::string::npos)
     173                                        buff = buff.substr(0, found + 11) + model + buff.substr(found+11+shipSelectionTag.length(), std::string::npos);
     174                                tempLevel.write(buff.c_str(), buff.length());
     175                                tempLevel << std::endl;
     176                        }
     177                        myLevel.close();
     178                        tempLevel.close();
     179                        orxout(user_status) << "done" << endl;
     180            }
    135181            void tagsUpdated(void); //!< Updates the comma-seperated string of all tags, if the set of tags has changed.
    136 
     182            void shipsUpdated(void); //!< Updates the comma-seperated string of all tags, if the set of tags has changed.
    137183            static void initializeTags(void); //!< Initialize the set of allowed tags.
    138184            /**
     
    152198            std::set<std::string> tags_; //!< The set of tags the Level is tagged with.
    153199            std::string tagsString_; //!< The comma-seperated string of all the tags the Level is tagged with.
     200            std::set<std::string> ships_; //!< The set of starting ship models the Level allows.
     201            std::string startingShipsString_; //!< The comma-seperated string of all the allowed ship models for the shipselection.           
    154202    }; // tolua_export
    155203
     
    161209        - @b description The description of the level.
    162210        - @b screenshot The screenshot of the level.
    163         - @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>.
    164 
     211        - @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>.
     212        - @b (optional) startingships The comma-seperated string of starting ship models
    165213        An example would be:
    166214        @code
     
    176224    @author
    177225        Damian 'Mozork' Frick
    178 
     226        @edit
     227                Matthias Hutter
    179228    @ingroup Orxonox
    180229    */
     
    223272            inline const std::string& getTags(void) const
    224273                { return this->LevelInfoItem::getTags(); }
    225 
     274            /**
     275            @brief Set the starting ship models of the level
     276            @param A comma-seperated string of all the allowed ship models for the shipselection.
     277            */
     278            inline void setShips(const std::string& ships)
     279                { this->LevelInfoItem::setShips(ships); }
     280            /**
     281            @brief Get the starting ship models of the level
     282            @return Returns a comma-seperated string of all the allowed ship models for the shipselection.
     283            */
     284            inline const std::string& getShips(void) const
     285                { return this->LevelInfoItem::getShips(); }             
    226286            LevelInfoItem* copy(void); //!< Copies the contents of this LevelInfo object to a new LevelInfoItem object.
    227 
    228287    };
    229288
  • code/branches/presentation2012/src/orxonox/LevelManager.cc

    r8891 r9208  
    256256        {
    257257            // TODO: Replace with tag?
    258             if (it->find("old/") != 0)
     258            if (it->find("old/") != 0 )
    259259            {
    260260                LevelInfoItem* info = NULL;
Note: See TracChangeset for help on using the changeset viewer.