Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/hud/src/orxonox/overlays/OverlayGroup.cc @ 1614

Last change on this file since 1614 was 1614, checked in by rgrieder, 16 years ago
  • Dots on the Radar actually disappear now when a Ship gets destroyed…
  • svn save to keep History of HUDText when renaming AND moving
  • Property svn:eol-style set to native
File size: 3.2 KB
Line 
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:
23 *      Reto Grieder
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "OrxonoxStableHeaders.h"
30#include "OverlayGroup.h"
31
32#include <assert.h>
33#include "core/Debug.h"
34#include "core/ConsoleCommand.h"
35#include "core/CoreIncludes.h"
36#include "OrxonoxOverlay.h"
37
38namespace orxonox
39{
40  CreateFactory(OverlayGroup);
41
42  SetConsoleCommand(OverlayGroup, toggleVisibility, false).setAccessLevel(AccessLevel::User);
43  SetConsoleCommand(OverlayGroup, scaleGroup, false).setAccessLevel(AccessLevel::User);
44
45  using namespace Ogre;
46
47  OverlayGroup::OverlayGroup()
48    : scale_(1.0, 1.0)
49  {
50    RegisterObject(OverlayGroup);
51  }
52
53  OverlayGroup::~OverlayGroup()
54  {
55  }
56
57  void OverlayGroup::XMLPort(Element& xmlElement, XMLPort::Mode mode)
58  {
59    BaseObject::XMLPort(xmlElement, mode);
60
61    XMLPortParam(OverlayGroup, "scale", scale, getScale, xmlElement, mode);
62    XMLPortObject(OverlayGroup, OrxonoxOverlay, "", addElement, getElement, xmlElement, mode, false, true);
63  }
64
65  void OverlayGroup::scale(const Vector2& scale)
66  {
67    for (std::map<std::string, OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
68      (*it).second->scale(scale);
69    this->scale_ = scale;
70  }
71
72  void OverlayGroup::addElement(OrxonoxOverlay* element)
73  {
74    if (hudElements_.find(element->getName()) != hudElements_.end())
75    {
76      COUT(1) << "Ambiguous names encountered while load the HUD overlays" << std::endl;
77    }
78    else
79      hudElements_[element->getName()] = element;
80  }
81
82  OrxonoxOverlay* OverlayGroup::getElement(unsigned int index)
83  {
84    if (index < this->hudElements_.size())
85    {
86      std::map<std::string, OrxonoxOverlay*>::const_iterator it = hudElements_.begin();
87      for (unsigned int i = 0; i != index; ++it, ++i)
88        ;
89      return (*it).second;
90    }
91    else
92      return 0;
93  }
94
95
96  /*static*/ void OverlayGroup::toggleVisibility(const std::string& name)
97  {
98    for (Iterator<OverlayGroup> it = ObjectList<OverlayGroup>::begin(); it; ++it)
99    {
100        if ((*it)->getName() == name)
101            (*it)->setVisibility(!((*it)->isVisible()));
102    }
103  }
104
105  /*static*/ void OverlayGroup::scaleGroup(const std::string& name, float scale)
106  {
107    for (Iterator<OverlayGroup> it = ObjectList<OverlayGroup>::begin(); it; ++it)
108    {
109        if ((*it)->getName() == name)
110            (*it)->scale(Vector2(scale, scale));
111    }
112  }
113}
Note: See TracBrowser for help on using the repository browser.