Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 1627 was 1627, checked in by rgrieder, 16 years ago

some adjustment to the default value setting in the overlay files

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