Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/objecthierarchy/src/orxonox/overlays/OverlayGroup.cc @ 2034

Last change on this file since 2034 was 2024, checked in by landauf, 17 years ago

added spaceship

  • Property svn:eol-style set to native
File size: 6.0 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
[1505]34#include "OrxonoxStableHeaders.h"
[1601]35#include "OverlayGroup.h"
[1505]36
[1747]37#include "util/Debug.h"
[1505]38#include "core/ConsoleCommand.h"
[1588]39#include "core/CoreIncludes.h"
[1747]40#include "core/Iterator.h"
[1616]41#include "core/XMLPort.h"
[1604]42#include "OrxonoxOverlay.h"
[1505]43
44namespace orxonox
45{
[1615]46    CreateFactory(OverlayGroup);
[1588]47
[1747]48    SetConsoleCommand(OverlayGroup, toggleVisibility, false).accessLevel(AccessLevel::User);
49    SetConsoleCommand(OverlayGroup, scaleGroup, false).accessLevel(AccessLevel::User);
50    SetConsoleCommand(OverlayGroup, scrollGroup, false).accessLevel(AccessLevel::User);
[1505]51
[2019]52    OverlayGroup::OverlayGroup(BaseObject* creator) : BaseObject(creator)
[1615]53    {
54        RegisterObject(OverlayGroup);
55    }
[1505]56
[2024]57    OverlayGroup::~OverlayGroup()
58    {
59        for (std::map<std::string, OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
60            delete it->second;
61    }
62
[1623]63    /**
64    @brief
65        Loads the group and all its children OrxonoxOverlays.
66    @copydoc
67        BaseObject::XMLPort()
68    */
[1615]69    void OverlayGroup::XMLPort(Element& xmlElement, XMLPort::Mode mode)
70    {
[1747]71        SUPER(OverlayGroup, XMLPort, xmlElement, mode);
[1588]72
[1627]73        XMLPortParam(OverlayGroup, "scale",  setScale,  getScale,  xmlElement, mode).defaultValues(Vector2(1.0, 1.0));
74        XMLPortParam(OverlayGroup, "scroll", setScroll, getScroll, xmlElement, mode).defaultValues(Vector2(0.0, 0.0));
[1623]75        // loads all the child elements
[1854]76        XMLPortObject(OverlayGroup, OrxonoxOverlay, "", addElement, getElement, xmlElement, mode);
[1615]77    }
[1505]78
[1623]79    //! Scales every element in the map.
[1615]80    void OverlayGroup::setScale(const Vector2& scale)
81    {
82        for (std::map<std::string, OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
83            (*it).second->scale(scale / this->scale_);
84        this->scale_ = scale;
85    }
[1588]86
[1623]87    //! Scrolls every element in the map.
[1615]88    void OverlayGroup::setScroll(const Vector2& scroll)
89    {
90        for (std::map<std::string, OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
91            (*it).second->scroll(scroll - this->scroll_);
92        this->scroll_ = scroll;
93    }
[1505]94
[1623]95    /**
96    @brief
97        Adds an element to the map (used when loading with XMLPort).
98    @remarks
99        The names of the OrxonoxOverlays have to be unique!
100    */
[1615]101    void OverlayGroup::addElement(OrxonoxOverlay* element)
[1564]102    {
[1615]103        if (hudElements_.find(element->getName()) != hudElements_.end())
104        {
105            COUT(1) << "Ambiguous names encountered while load the HUD overlays" << std::endl;
106        }
107        else
[1993]108        {
[1615]109            hudElements_[element->getName()] = element;
[1993]110            element->setVisible(this->isVisible());
111        }
[1588]112    }
[1564]113
[1623]114    //! Returns a different element as long as index < hudElements_.size().
[1615]115    OrxonoxOverlay* OverlayGroup::getElement(unsigned int index)
[1588]116    {
[1615]117        if (index < this->hudElements_.size())
118        {
119            std::map<std::string, OrxonoxOverlay*>::const_iterator it = hudElements_.begin();
120            for (unsigned int i = 0; i != index; ++it, ++i)
121                ;
122            return (*it).second;
123        }
124        else
125            return 0;
[1505]126    }
127
[1633]128    //! Changes the visibility of all elements
129    void OverlayGroup::changedVisibility()
130    {
131        for (std::map<std::string, OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
132            (*it).second->setVisible(this->isVisible());
133    }
[1614]134
[1633]135
[1623]136    //########### Console commands ############
137
138    /**
139    @brief
140        Hides/shows an overlay group by its name.
141    @param name
142        The name of the group defined BaseObject::setName() (usually done with the "name"
143        attribute in the xml file).
144    */
[1615]145    /*static*/ void OverlayGroup::toggleVisibility(const std::string& name)
[1614]146    {
[1747]147        for (ObjectList<OverlayGroup>::iterator it = ObjectList<OverlayGroup>::begin(); it; ++it)
[1615]148        {
149            if ((*it)->getName() == name)
[1625]150                (*it)->setVisible(!((*it)->isVisible()));
[1615]151        }
[1614]152    }
[1505]153
[1623]154    /**
155    @brief
156        Scales an overlay group by its name.
157    @param name
158        The name of the group defined BaseObject::setName() (usually done with the "name"
159        attribute in the xml file).
160    */
[1615]161    /*static*/ void OverlayGroup::scaleGroup(const std::string& name, float scale)
[1564]162    {
[1747]163        for (ObjectList<OverlayGroup>::iterator it = ObjectList<OverlayGroup>::begin(); it; ++it)
[1615]164        {
165            if ((*it)->getName() == name)
166                (*it)->scale(Vector2(scale, scale));
167        }
[1564]168    }
[1615]169
[1623]170    /**
171    @brief
172        Scrolls an overlay group by its name.
173    @param name
174        The name of the group defined BaseObject::setName() (usually done with the "name"
175        attribute in the xml file).
176    */
[1615]177    /*static*/ void OverlayGroup::scrollGroup(const std::string& name, const Vector2& scroll)
178    {
[1747]179        for (ObjectList<OverlayGroup>::iterator it = ObjectList<OverlayGroup>::begin(); it; ++it)
[1615]180        {
181            if ((*it)->getName() == name)
182                (*it)->scroll(scroll);
183        }
184    }
[1505]185}
Note: See TracBrowser for help on using the repository browser.