Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 29, 2010, 12:30:32 PM (15 years ago)
Author:
dafrick
Message:

Working towards a functioning PickupInventory.

Location:
code/branches/pickup4/src
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • code/branches/pickup4/src/modules/pickup/CMakeLists.txt

    r6524 r6632  
    1515  FIND_HEADER_FILES
    1616  TOLUA_FILES
     17    PickupManager.h
     18    PickupRepresentation.h
    1719  DEFINE_SYMBOL
    1820    "PICKUP_SHARED_BUILD"
  • code/branches/pickup4/src/modules/pickup/PickupManager.cc

    r6540 r6632  
    3535
    3636#include "core/CoreIncludes.h"
     37#include "core/LuaState.h"
     38#include "core/GUIManager.h"
    3739#include "core/ScopedSingletonManager.h"
    3840#include "core/Identifier.h"
    3941#include "interfaces/PickupCarrier.h"
     42#include "infos/PlayerInfo.h"
    4043#include "worldentities/pawns/Pawn.h"
    4144#include "PickupRepresentation.h"
    4245
     46#include "ToluaBindPickup.h"
     47
    4348namespace orxonox
    4449{
    45 
     50    // Register tolua_open function when loading the library
     51    DeclareToluaInterface(Pickup);
     52   
    4653    ManageScopedSingleton(PickupManager, ScopeID::Root, false);
     54   
     55    /*static*/ const std::string PickupManager::guiName_s = "PickupInventory";
    4756   
    4857    /**
     
    110119    }
    111120   
     121    PickupCarrier* PickupManager::getPawn(void)
     122    {
     123        Pawn* pawn = dynamic_cast<Pawn*>(GUIManager::getInstancePtr()->getPlayer(PickupManager::guiName_s)->getControllableEntity());
     124        if(pawn == NULL)
     125            return NULL;
     126        return dynamic_cast<PickupCarrier*>(pawn);
     127    }
     128   
     129    unsigned int PickupManager::getNumCarrierChildren(PickupCarrier* carrier)
     130    {
     131        return carrier->getNumCarrierChildren();
     132    }
     133           
     134    PickupCarrier* PickupManager::getCarrierChild(unsigned int index, PickupCarrier* carrier)
     135    {
     136        return carrier->getCarrierChild(index);
     137    }
     138   
     139    PickupRepresentation* PickupManager::getPickupRepresentation(unsigned int index, PickupCarrier* carrier)
     140    {
     141        Pickupable* pickup = carrier->getPickup(index);
     142        if(pickup == NULL)
     143            return NULL;
     144       
     145        return this->getRepresentation(pickup->getPickupIdentifier());
     146    }
     147   
     148
     149    unsigned int PickupManager::getNumPickups(PickupCarrier* carrier)
     150    {
     151        return carrier->getNumPickups();
     152    }
     153   
     154    void PickupManager::dropPickup(unsigned int index, PickupCarrier* carrier)
     155    {
     156        Pickupable* pickup = carrier->getPickup(index);
     157        carrier->drop(pickup);
     158    }
     159   
     160    void PickupManager::usePickup(unsigned int index, PickupCarrier* carrier, bool use)
     161    {
     162        Pickupable* pickup = carrier->getPickup(index);
     163        pickup->setUsed(use);
     164    }
     165   
    112166}
  • code/branches/pickup4/src/modules/pickup/PickupManager.h

    r6540 r6632  
    4444#include "core/OrxonoxClass.h"
    4545
    46 namespace orxonox
    47 {
     46namespace orxonox // tolua_export
     47{ // tolua_export
     48
     49    //TODO: Remove after transfer to orxonox/pickup
     50    class PickupCarrier; // tolua_export
    4851
    4952    /**
    5053    @brief
    5154        Manages Pickupables.
    52         In essence has two tasks to fulfill. Firstly it must link Pickupables (through their PickupIdentifiers) and their PickupRepresentations. Secondly it manages the Pickup GUI.
     55        In essence has two tasks to fulfill. Firstly it must link Pickupables (through their PickupIdentifiers) and their PickupRepresentations. Secondly it manages the PickupInventory.
    5356        //TODO: Manage Pickup GUI.
    5457    @author
    5558        Damian 'Mozork' Frick
    5659    */
    57     class _PickupExport PickupManager : public Singleton<PickupManager>, public OrxonoxClass
    58     {
     60    class _PickupExport PickupManager // tolua_export
     61        : public Singleton<PickupManager>, public OrxonoxClass
     62    { // tolua_export
    5963        friend class Singleton<PickupManager>;
    6064       
     
    6367            virtual ~PickupManager();
    6468           
    65             static PickupManager& getInstance() { return Singleton<PickupManager>::getInstance(); }
     69            static PickupManager& getInstance() { return Singleton<PickupManager>::getInstance(); } // tolua_export
    6670           
    6771            bool registerRepresentation(const PickupIdentifier* identifier, PickupRepresentation* representation); //!< Registers a PickupRepresentation together with the PickupIdentifier of the Pickupable the PickupRepresentation represents.
    6872            PickupRepresentation* getRepresentation(const PickupIdentifier* identifier); //!< Get the PickupRepresentation representing the Pickupable with the input PickupIdentifier.
    6973           
     74            // tolua_begin
     75            PickupCarrier* getPawn(void);
     76           
     77            unsigned int getNumCarrierChildren(PickupCarrier* carrier);
     78            PickupCarrier* getCarrierChild(unsigned int index, PickupCarrier* carrier);
     79           
     80            unsigned int getNumPickups(PickupCarrier* carrier);
     81            PickupRepresentation* getPickupRepresentation(unsigned int index, PickupCarrier* carrier);
     82            void dropPickup(unsigned int index, PickupCarrier* carrier);
     83            void usePickup(unsigned int index, PickupCarrier* carrier, bool use);
     84            // tolua_end
     85           
    7086        private:
    7187            static PickupManager* singletonPtr_s;
     88            static const std::string guiName_s;
    7289           
    7390            PickupRepresentation* defaultRepresentation_; //!< The default PickupRepresentation.
    7491            std::map<const PickupIdentifier*, PickupRepresentation*, PickupIdentifierCompare> representations_; //!< Map linking PickupIdentifiers (representing types if Pickupables) and PickupRepresentations.
    7592       
    76     };
     93    }; // tolua_export
    7794   
    78 }
     95} // tolua_export
    7996
    8097#endif // _PickupManager_H__
  • code/branches/pickup4/src/modules/pickup/PickupPrereqs.h

    r6524 r6632  
    6565namespace orxonox
    6666{
    67 
     67   
    6868    class DroppedPickup;
    6969    class Pickup;
  • code/branches/pickup4/src/modules/pickup/PickupRepresentation.cc

    r6540 r6632  
    8686        this->name_ = "Pickup";
    8787        this->spawnerTemplate_ = "";
     88        this->inventoryRepresentation_ = "";
    8889        this->pickup_ = NULL;
    8990    }
     
    100101        XMLPortParam(PickupRepresentation, "description", setDescription, getDescription, xmlelement, mode);
    101102        XMLPortParam(PickupRepresentation, "spawnerTemplate", setSpawnerTemplate, getSpawnerTemplate, xmlelement, mode);
     103        XMLPortParam(PickupRepresentation, "inventoryRepresentation", setInventoryRepresentation, getInventoryRepresentation, xmlelement, mode);
    102104        XMLPortObject(PickupRepresentation, Pickupable, "pickup", setPickup, getPickup, xmlelement, mode);
    103105        XMLPortObject(PickupRepresentation, StaticEntity, "spawner-representation", setSpawnerRepresentation, getSpawnerRepresentationIndex, xmlelement, mode);
  • code/branches/pickup4/src/modules/pickup/PickupRepresentation.h

    r6540 r6632  
    4545#include "core/BaseObject.h"
    4646
    47 namespace orxonox
    48 {
     47namespace orxonox // tolua_export
     48{ // tolua_export
    4949
    5050    /**
     
    5353        They are created through XML and are registered with the PickupManager.
    5454    */
    55     class _PickupExport PickupRepresentation : public BaseObject
    56     {
     55    class _PickupExport PickupRepresentation // tolua_export
     56        : public BaseObject
     57    { // tolua_export
    5758       
    5859        public:
     
    9091                { this->spawnerRepresentation_ = representation; }
    9192            /**
     93            @brief Set the image representing the pickup in the PickupInventory.
     94            @param image A string with the name of the image representing the pickup.
     95            */
     96            inline void setInventoryRepresentation(const std::string& image)
     97                { this->inventoryRepresentation_ = image; }
     98            /**
    9299            @brief Set the Pickupable that is represented by this PickupRepresentation.
    93100            @param pickup A pointer to the Pickupable.
     
    100107            @return Returns the name.
    101108            */
    102             inline const std::string& getName(void)
    103                 { return this->name_; }
     109            inline const std::string& getName(void) { return this->name_; } // tolua_export
    104110            /**
    105111            @brief Get the description of the Pickupable represented by this PickupRepresentation.
    106112            @return Returns the description.
    107113            */
    108             inline const std::string& getDescription(void)
    109                 { return this->description_; }
     114            inline const std::string& getDescription(void) { return this->description_; } // tolua_export
    110115            /**
    111116            @brief Get the name of spawnerTemplate the Pickupable represented by this PickupRepresentation.
     
    121126            inline const StaticEntity* getSpawnerRepresentationIndex(unsigned int index)
    122127                { if(index == 0) return this->spawnerRepresentation_; return NULL; }
     128            /**
     129            @brief Get the name of the image representing the pickup in the PickupInventory.
     130            @return Returns the name of the image as a string.
     131            */
     132            inline const std::string& getInventoryRepresentation(void) { return this->inventoryRepresentation_; } // tolua_export
    123133            /**
    124134            @brief Get the Pickupable represented by this PickupRepresentation.
     
    139149            std::string spawnerTemplate_; //!<  The name of the template of this PickupRepresentation.
    140150            StaticEntity* spawnerRepresentation_; //!< The spawnerRepresentation of this PickupRepresentation.
     151            std::string inventoryRepresentation_; //!< The name of an image representing the pickup in the PickupInventory. TODO: Exact format and placement of image?
    141152           
    142153            Pickupable* pickup_; //!< The Pickupable that is represented by this PickupRepresentation.
    143154           
    144     };
     155    }; // tolua_export
    145156
    146 }
     157} // tolua_export
    147158   
    148159#endif // _PickupRepresentation_H__
  • code/branches/pickup4/src/orxonox/CMakeLists.txt

    r6524 r6632  
    5858    MoodManager.h
    5959    controllers/HumanController.h
     60    interfaces/PickupCarrier.h
    6061    sound/SoundManager.h
    6162  DEFINE_SYMBOL
  • code/branches/pickup4/src/orxonox/interfaces/InterfaceCompilation.cc

    r6534 r6632  
    6060        RegisterRootObject(PickupCarrier);
    6161       
     62        this->setCarrierName("PickupCarrier");
    6263    }
    6364   
  • code/branches/pickup4/src/orxonox/interfaces/PickupCarrier.h

    r6563 r6632  
    4545#include "core/OrxonoxClass.h"
    4646
    47 namespace orxonox
    48 {
    49 
    50     //! Pre-declarations.
     47namespace orxonox // tolua_export
     48{ // tolua_export
     49
     50    //! Forward-declarations.
     51    class PickupManager;
    5152    class Pickup;
    5253    class HealthPickup;
     
    5960        Damian 'Mozork' Frick
    6061    */
    61     class _OrxonoxExport PickupCarrier : virtual public OrxonoxClass
    62     {
     62    class _OrxonoxExport PickupCarrier  // tolua_export
     63        : virtual public OrxonoxClass
     64    { // tolua_export
    6365        //! So that the different Pickupables have full access to their PickupCarrier.
     66        friend class Pickupable;
     67        friend class PickupManager;
    6468        //! Friends.
    65         friend class Pickupable;
    6669        friend class Pickup;
    6770        friend class HealthPickup;
     
    116119                   
    117120                    //! Go recursively through all children to check whether they are a target.
    118                     std::list<PickupCarrier*>* children = this->getCarrierChildren();
    119                     for(std::list<PickupCarrier*>::const_iterator it = children->begin(); it != children->end(); it++)
     121                    std::vector<PickupCarrier*>* children = this->getCarrierChildren();
     122                    for(std::vector<PickupCarrier*>::const_iterator it = children->begin(); it != children->end(); it++)
    120123                    {
    121124                        if((*it)->isTarget(pickup))
     
    143146                   
    144147                    //! Go recursively through all children to check whether they are the target.
    145                     std::list<PickupCarrier*>* children = this->getCarrierChildren();
    146                     for(std::list<PickupCarrier*>::iterator it = children->begin(); it != children->end(); it++)
     148                    std::vector<PickupCarrier*>* children = this->getCarrierChildren();
     149                    for(std::vector<PickupCarrier*>::iterator it = children->begin(); it != children->end(); it++)
    147150                    {
    148151                        if(pickup->isTarget(*it))
     
    162165            */
    163166            virtual const Vector3& getCarrierPosition(void) = 0;
     167           
     168            const std::string& getCarrierName(void) { return this->carrierName_; } // tolua_export
    164169           
    165170        protected:       
     
    170175            @return Returns a pointer to a list of all direct children.
    171176            */
    172             virtual std::list<PickupCarrier*>* getCarrierChildren(void) = 0;
     177            virtual std::vector<PickupCarrier*>* getCarrierChildren(void) = 0;
    173178            /**
    174179            @brief Get the parent of this PickupSpawner
     
    184189            std::set<Pickupable*>& getPickups(void)
    185190                { return this->pickups_; }
     191               
     192            void setCarrierName(const std::string& name)
     193                { this->carrierName_ = name; }
    186194       
    187195        private:
    188196            std::set<Pickupable*> pickups_; //!< The list of Pickupables carried by this PickupCarrier.
    189            
    190     };
    191 }
     197            std::string carrierName_;
     198           
     199            unsigned int getNumCarrierChildren(void)
     200                {
     201                    std::vector<PickupCarrier*>* list = this->getCarrierChildren();
     202                    unsigned int size = list->size();
     203                    delete list;
     204                    return size;
     205                }
     206           
     207            PickupCarrier* getCarrierChild(unsigned int index)
     208                {
     209                    std::vector<PickupCarrier*>* list = this->getCarrierChildren();
     210                    if(list->size() < index)
     211                        return NULL;
     212                    PickupCarrier* carrier = (*list)[index];
     213                    delete list;
     214                    return carrier;
     215                }
     216           
     217            Pickupable* getPickup(unsigned int index)
     218                {
     219                    std::set<Pickupable*>::iterator it;
     220                    for(it = this->pickups_.begin(); index != 0 && it != this->pickups_.end(); it++)
     221                        index--;
     222                    if(it == this->pickups_.end())
     223                        return NULL;
     224                    return *it;
     225                }
     226           
     227            unsigned int getNumPickups(void)
     228                { return this->pickups_.size(); }
     229           
     230           
     231    }; // tolua_export
     232} // tolua_export
    192233
    193234#endif /* _PickupCarrier_H__ */
  • code/branches/pickup4/src/orxonox/overlays/OrxonoxOverlay.cc

    r6502 r6632  
    327327        {
    328328            OrxonoxOverlay* overlay= it->second;
     329            COUT(1) << "MUP" << std::endl;
    329330            if(overlay->isVisible())
     331            {
    330332                overlay->hide();
     333                COUT(1) << "HIDE " << name << std::endl;
     334            }
    331335            else
     336            {
    332337                overlay->show();
     338                COUT(1) << "SHOW " << name << std::endl;
     339            }
    333340        }
    334341    }
  • code/branches/pickup4/src/orxonox/worldentities/pawns/Pawn.h

    r6540 r6632  
    3737#include "worldentities/ControllableEntity.h"
    3838
    39 namespace orxonox
    40 {
    41     class _OrxonoxExport Pawn : public ControllableEntity, public RadarViewable, public PickupCarrier
    42     {
     39namespace orxonox // tolua_export
     40{ // tolua_export
     41    class _OrxonoxExport Pawn // tolua_export
     42        : public ControllableEntity, public RadarViewable, public PickupCarrier
     43    { // tolua_export
    4344        friend class WeaponSystem;
    4445
     
    132133            bool bAlive_;
    133134
    134             virtual std::list<PickupCarrier*>* getCarrierChildren(void)
    135                 { return new std::list<PickupCarrier*>(); }
     135            virtual std::vector<PickupCarrier*>* getCarrierChildren(void)
     136                { return new std::vector<PickupCarrier*>(); }
    136137            virtual PickupCarrier* getCarrierParent(void)
    137138                { return NULL; }
     
    155156
    156157            Vector3 aimPosition_;
    157     };
    158 }
     158    }; // tolua_export
     159} // tolua_export
    159160
    160161#endif /* _Pawn_H__ */
Note: See TracChangeset for help on using the changeset viewer.