Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/overlays/OverlayGroup.cc @ 12068

Last change on this file since 12068 was 11099, checked in by muemart, 9 years ago

Fix loads of doxygen warnings and other documentation issues

  • Property svn:eol-style set to native
File size: 7.7 KB
RevLine 
[1505]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
[1604]23 *      Reto Grieder
[1505]24 *   Co-authors:
[1604]25 *      ...
[1505]26 *
27 */
28
[1623]29/**
30@file
31@brief Definition of the OverlayGroup class.
32*/
33
[1601]34#include "OverlayGroup.h"
[1505]35
[1588]36#include "core/CoreIncludes.h"
[1616]37#include "core/XMLPort.h"
[10624]38#include "core/command/ConsoleCommandIncludes.h"
[1604]39#include "OrxonoxOverlay.h"
[10624]40#include "gametypes/Gametype.h"
[1505]41
42namespace orxonox
43{
[11052]44    namespace autocompletion
45    {
46        /**
47            @brief Returns the names of all currently existing OverlayGroups.
48        */
49        ARGUMENT_COMPLETION_FUNCTION_DECLARATION(overlaygroupnames)();
50        ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(overlaygroupnames)()
51        {
52            ArgumentCompletionList names;
[11071]53            for (OverlayGroup* overlayGroup : ObjectList<OverlayGroup>())
54                names.push_back(ArgumentCompletionListElement(overlayGroup->getName(), getLowercase(overlayGroup->getName())));
[11052]55            return names;
56        }
57    }
58
59    SetConsoleCommand("OverlayGroup", "toggleVisibility", &OverlayGroup::toggleVisibility).argumentCompleter(0, autocompletion::overlaygroupnames());
60    SetConsoleCommand("OverlayGroup", "show",             &OverlayGroup::show            ).argumentCompleter(0, autocompletion::overlaygroupnames());
61    SetConsoleCommand("OverlayGroup", "scaleGroup",       &OverlayGroup::scaleGroup      ).argumentCompleter(0, autocompletion::overlaygroupnames());
62    SetConsoleCommand("OverlayGroup", "scrollGroup",      &OverlayGroup::scrollGroup     ).argumentCompleter(0, autocompletion::overlaygroupnames());
63
[9667]64    RegisterClass(OverlayGroup);
[1588]65
[9667]66    OverlayGroup::OverlayGroup(Context* context)
67        : BaseObject(context)
[1615]68    {
69        RegisterObject(OverlayGroup);
[2087]70
[11071]71        this->owner_ = nullptr;
[2662]72
[2087]73        setScale(Vector2(1.0, 1.0));
74        setScroll(Vector2(0.0, 0.0));
[1615]75    }
[1505]76
[2087]77    OverlayGroup::~OverlayGroup()
78    {
[11071]79        for (OrxonoxOverlay* hudElement : hudElements_)
80            hudElement->destroy();
[6054]81        this->hudElements_.clear();
[2087]82    }
83
[1623]84    /**
85    @brief
86        Loads the group and all its children OrxonoxOverlays.
[11099]87    @copydoc BaseObject::XMLPort()
[1623]88    */
[7401]89    void OverlayGroup::XMLPort(Element& xmlelement, XMLPort::Mode mode)
[1615]90    {
[7401]91        SUPER(OverlayGroup, XMLPort, xmlelement, mode);
[1588]92
[7401]93        XMLPortParam(OverlayGroup, "scale",  setScale,  getScale,  xmlelement, mode);
94        XMLPortParam(OverlayGroup, "scroll", setScroll, getScroll, xmlelement, mode);
[1623]95        // loads all the child elements
[7401]96        XMLPortObject(OverlayGroup, OrxonoxOverlay, "", addElement, getElement, xmlelement, mode);
[1615]97    }
[1505]98
[2890]99    //! Scales every element in the set.
[1615]100    void OverlayGroup::setScale(const Vector2& scale)
101    {
[11071]102        for (OrxonoxOverlay* hudElement : hudElements_)
103            hudElement->scale(scale / this->scale_);
[1615]104        this->scale_ = scale;
105    }
[1588]106
[2890]107    //! Scrolls every element in the set.
[1615]108    void OverlayGroup::setScroll(const Vector2& scroll)
109    {
[11071]110        for (OrxonoxOverlay* hudElement : hudElements_)
111            hudElement->scroll(scroll - this->scroll_);
[1615]112        this->scroll_ = scroll;
113    }
[1505]114
[1623]115    /**
116    @brief
[2890]117        Adds an element to the set (used when loading with XMLPort).
[1623]118    @remarks
119        The names of the OrxonoxOverlays have to be unique!
120    */
[1615]121    void OverlayGroup::addElement(OrxonoxOverlay* element)
[1564]122    {
[10624]123        hudElements_.insert(element);
[5980]124        element->setOverlayGroup( this );
[2890]125        if (this->owner_)
126            element->setOwner(this->owner_);
[1588]127    }
[1564]128
[3034]129    /**
[2911]130    @brief
131        Removes an element from the map.
[7401]132    @param element
133        A pointer to the element that is removed.
[2911]134    @return
135        Returns true if there was such an element to remove, false if not.
136    */
137    bool OverlayGroup::removeElement(OrxonoxOverlay* element)
138    {
[10624]139        if(this->hudElements_.erase(element) == 0)
[2911]140            return false;
141        return true;
142    }
143
[1623]144    //! Returns a different element as long as index < hudElements_.size().
[1615]145    OrxonoxOverlay* OverlayGroup::getElement(unsigned int index)
[1588]146    {
[1615]147        if (index < this->hudElements_.size())
148        {
[11071]149            std::set<StrongPtr<OrxonoxOverlay>>::const_iterator it = hudElements_.begin();
[1615]150            for (unsigned int i = 0; i != index; ++it, ++i)
151                ;
[10624]152            return *it;
[1615]153        }
154        else
[11071]155            return nullptr;
[1505]156    }
157
[1633]158    //! Changes the visibility of all elements
159    void OverlayGroup::changedVisibility()
160    {
[5980]161        SUPER( OverlayGroup, changedVisibility );
[6417]162
[11071]163        for (OrxonoxOverlay* hudElement : hudElements_)
164            hudElement->changedVisibility(); //inform all Child Overlays that our visibility has changed
[1633]165    }
[1614]166
[2890]167    void OverlayGroup::setOwner(BaseObject* owner)
[2662]168    {
169        this->owner_ = owner;
[1633]170
[11071]171        for (OrxonoxOverlay* hudElement : hudElements_)
172            hudElement->setOwner(owner);
[2662]173    }
174
[1623]175    //########### Console commands ############
176
177    /**
178    @brief
179        Hides/shows an overlay group by its name.
180    @param name
181        The name of the group defined BaseObject::setName() (usually done with the "name"
182        attribute in the xml file).
183    */
[1615]184    /*static*/ void OverlayGroup::toggleVisibility(const std::string& name)
[1614]185    {
[11071]186        for (OverlayGroup* group : ObjectList<OverlayGroup>())
[1615]187        {
[11071]188            if (group->getName() == name)
189                group->setVisible(!(group->isVisible()));
[1615]190        }
[1614]191    }
[8309]192   
193    /**
194    @brief
195        Shows an overlay group by its name.
196    @param name
197        The name of the group defined BaseObject::setName() (usually done with the "name" attribute in the xml file).
198    */
199    /*static*/ void OverlayGroup::show(const std::string& name)
200    {
[11071]201        for (OverlayGroup* group : ObjectList<OverlayGroup>())
[8309]202        {
[11071]203            if (group->getName() == name)
[8309]204            {
[11071]205                if(group->isVisible())
206                    group->changedVisibility();
[8309]207                else
[11071]208                    group->setVisible(!(group->isVisible()));
[8309]209            }
210        }
211    }
[1505]212
[1623]213    /**
214    @brief
215        Scales an overlay group by its name.
216    @param name
217        The name of the group defined BaseObject::setName() (usually done with the "name"
218        attribute in the xml file).
[7401]219    @param scale
220        The scaling factor
[1623]221    */
[1615]222    /*static*/ void OverlayGroup::scaleGroup(const std::string& name, float scale)
[1564]223    {
[11071]224        for (OverlayGroup* group : ObjectList<OverlayGroup>())
[1615]225        {
[11071]226            if (group->getName() == name)
227                group->scale(Vector2(scale, scale));
[1615]228        }
[1564]229    }
[1615]230
[1623]231    /**
232    @brief
233        Scrolls an overlay group by its name.
234    @param name
235        The name of the group defined BaseObject::setName() (usually done with the "name"
236        attribute in the xml file).
[7401]237    @param scroll
238        The relative translation of the overlay group
[1623]239    */
[1615]240    /*static*/ void OverlayGroup::scrollGroup(const std::string& name, const Vector2& scroll)
241    {
[11071]242        for (OverlayGroup* group : ObjectList<OverlayGroup>())
[1615]243        {
[11071]244            if (group->getName() == name)
245                group->scroll(scroll);
[1615]246        }
247    }
[1505]248}
Note: See TracBrowser for help on using the repository browser.