Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 2, 2009, 8:42:11 PM (16 years ago)
Author:
landauf
Message:
  • Added overlay element for the Pong Gametype
  • Changed the type of the overlay's owner to BaseObject (former ControllableEntity) to allow other classes to own an overlay (for example a Gametype)
  • OverlayGroup does now use a std::set instead of a std::map to store it's overlay elements. Therefore a name is not anymore compulsory for an overlay element.
Location:
code/trunk/src/orxonox/overlays
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/orxonox/overlays/OrxonoxOverlay.h

    r2662 r2890  
    154154        virtual void changedVisibility();
    155155
    156         inline void setOwner(ControllableEntity* owner)
     156        inline void setOwner(BaseObject* owner)
    157157        {
    158158            if (this->owner_ != owner)
     
    162162            }
    163163        }
    164         inline ControllableEntity* getOwner() const
     164        inline BaseObject* getOwner() const
    165165            { return this->owner_; }
    166166        virtual void changedOwner() {}
     
    206206            We could also use the ObjectList, but that doesn't guarantee XMLPort(.) was called and is slower. */
    207207        static std::map<std::string, OrxonoxOverlay*> overlays_s;
    208         ControllableEntity* owner_;
     208        BaseObject* owner_;
    209209        OverlayGroup* group_;
    210210  };
  • code/trunk/src/orxonox/overlays/OverlayGroup.cc

    r2662 r2890  
    6363    OverlayGroup::~OverlayGroup()
    6464    {
    65         for (std::map<std::string, OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
    66             delete it->second;
     65        for (std::set<OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
     66            delete (*it);
    6767    }
    6868
     
    8383    }
    8484
    85     //! Scales every element in the map.
     85    //! Scales every element in the set.
    8686    void OverlayGroup::setScale(const Vector2& scale)
    8787    {
    88         for (std::map<std::string, OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
    89             (*it).second->scale(scale / this->scale_);
     88        for (std::set<OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
     89            (*it)->scale(scale / this->scale_);
    9090        this->scale_ = scale;
    9191    }
    9292
    93     //! Scrolls every element in the map.
     93    //! Scrolls every element in the set.
    9494    void OverlayGroup::setScroll(const Vector2& scroll)
    9595    {
    96         for (std::map<std::string, OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
    97             (*it).second->scroll(scroll - this->scroll_);
     96        for (std::set<OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
     97            (*it)->scroll(scroll - this->scroll_);
    9898        this->scroll_ = scroll;
    9999    }
     
    101101    /**
    102102    @brief
    103         Adds an element to the map (used when loading with XMLPort).
     103        Adds an element to the set (used when loading with XMLPort).
    104104    @remarks
    105105        The names of the OrxonoxOverlays have to be unique!
     
    107107    void OverlayGroup::addElement(OrxonoxOverlay* element)
    108108    {
    109         if (hudElements_.find(element->getName()) != hudElements_.end())
    110         {
    111             COUT(1) << "Ambiguous names encountered while load the HUD overlays" << std::endl;
    112         }
    113         else
    114         {
    115             hudElements_[element->getName()] = element;
    116             element->setVisible(this->isVisible());
    117             if (this->owner_)
    118                 element->setOwner(this->owner_);
    119         }
     109        hudElements_.insert(element);
     110        element->setVisible(this->isVisible());
     111        if (this->owner_)
     112            element->setOwner(this->owner_);
    120113    }
    121114
     
    125118        if (index < this->hudElements_.size())
    126119        {
    127             std::map<std::string, OrxonoxOverlay*>::const_iterator it = hudElements_.begin();
     120            std::set<OrxonoxOverlay*>::const_iterator it = hudElements_.begin();
    128121            for (unsigned int i = 0; i != index; ++it, ++i)
    129122                ;
    130             return (*it).second;
     123            return (*it);
    131124        }
    132125        else
     
    137130    void OverlayGroup::changedVisibility()
    138131    {
    139         for (std::map<std::string, OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
    140             (*it).second->setVisible(this->isVisible());
     132        for (std::set<OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
     133            (*it)->setVisible(this->isVisible());
    141134    }
    142135
    143     void OverlayGroup::setOwner(ControllableEntity* owner)
     136    void OverlayGroup::setOwner(BaseObject* owner)
    144137    {
    145138        this->owner_ = owner;
    146139
    147         for (std::map<std::string, OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
    148             (*it).second->setOwner(owner);
     140        for (std::set<OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
     141            (*it)->setOwner(owner);
    149142    }
    150143
  • code/trunk/src/orxonox/overlays/OverlayGroup.h

    r2662 r2890  
    3737#include "OrxonoxPrereqs.h"
    3838
    39 #include <map>
     39#include <set>
    4040#include <OgrePrerequisites.h>
    4141#include "core/BaseObject.h"
     
    6464        static void scrollGroup(const std::string& name, const Vector2& scroll);
    6565
    66         inline const std::map<std::string, OrxonoxOverlay*>& getOverlays() const
     66        inline const std::set<OrxonoxOverlay*>& getOverlays() const
    6767            { return this->hudElements_; }
    6868
    6969        void changedVisibility();
    7070
    71         void setOwner(ControllableEntity* owner);
    72         inline ControllableEntity* getOwner() const
     71        void setOwner(BaseObject* owner);
     72        inline BaseObject* getOwner() const
    7373            { return this->owner_; }
    7474
     
    8989
    9090    private:
    91         std::map<std::string, OrxonoxOverlay*> hudElements_;    //!< Contains all the OrxonoxOverlays of the this group.
    92         Vector2 scale_;                                         //!< Current scale (independent of the elements).
    93         Vector2 scroll_;                                        //!< Current scrolling offset.
    94         ControllableEntity* owner_;                             //!< The owner of this OverlayGroup
     91        std::set<OrxonoxOverlay*> hudElements_;    //!< Contains all the OrxonoxOverlays of the this group.
     92        Vector2 scale_;                            //!< Current scale (independent of the elements).
     93        Vector2 scroll_;                           //!< Current scrolling offset.
     94        BaseObject* owner_;                        //!< The owner of this OverlayGroup
    9595    };
    9696}
  • code/trunk/src/orxonox/overlays/hud/CMakeLists.txt

    r2710 r2890  
    77  ChatOverlay.cc
    88  GametypeStatus.cc
     9  PongScore.cc
    910)
Note: See TracChangeset for help on using the changeset viewer.