Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 1610 was 1609, checked in by rgrieder, 17 years ago

svn save, just in case…
(doesn't compile at all!)

  • Property svn:eol-style set to native
File size: 3.3 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
29#include "OrxonoxStableHeaders.h"
[1601]30#include "OverlayGroup.h"
[1505]31
[1588]32#include <assert.h>
[1505]33#include "core/Debug.h"
34#include "core/ConsoleCommand.h"
[1588]35#include "core/CoreIncludes.h"
[1604]36#include "OrxonoxOverlay.h"
[1505]37
38namespace orxonox
39{
[1604]40  CreateFactory(OverlayGroup);
[1588]41
[1604]42  SetConsoleCommand(OverlayGroup, toggleVisibility, false).setAccessLevel(AccessLevel::User);
[1505]43
[1604]44  OverlayGroup* OverlayGroup::hudInstance_s = 0;
[1588]45
[1604]46  using namespace Ogre;
[1505]47
[1604]48  OverlayGroup::OverlayGroup()
49    : scale_(1.0, 1.0)
50  {
51    RegisterObject(OverlayGroup);
[1588]52
[1604]53    // Singleton like in Ogre. Constructor and destructor are public,
54    // but the assert prevents from having multiple instances.
55    assert(hudInstance_s == 0);
56    hudInstance_s = this;
57  }
[1588]58
[1604]59  OverlayGroup::~OverlayGroup()
60  {
61    if (this->isInitialized())
[1567]62    {
63    }
64
[1604]65    hudInstance_s = 0;
66  }
[1588]67
[1604]68  void OverlayGroup::XMLPort(Element& xmlElement, XMLPort::Mode mode)
69  {
70    BaseObject::XMLPort(xmlElement, mode);
[1505]71
[1609]72    XMLPortParam(OverlayGroup, "scale", scale, getScale, xmlElement, mode);
[1604]73    XMLPortObject(OverlayGroup, OrxonoxOverlay, "", addElement, getElement, xmlElement, mode, false, true);
74  }
[1588]75
[1604]76  void OverlayGroup::scale(const Vector2& scale)
77  {
78    for (std::map<std::string, OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
79      (*it).second->scale(scale);
80    this->scale_ = scale;
81  }
[1505]82
[1604]83  void OverlayGroup::addElement(OrxonoxOverlay* element)
84  {
85    if (hudElements_.find(element->getName()) != hudElements_.end())
[1564]86    {
[1604]87      COUT(1) << "Ambiguous names encountered while load the HUD overlays" << std::endl;
[1588]88    }
[1604]89    else
90      hudElements_[element->getName()] = element;
91  }
[1564]92
[1604]93  OrxonoxOverlay* OverlayGroup::getElement(unsigned int index)
94  {
95    if (index < this->hudElements_.size())
[1588]96    {
[1604]97      std::map<std::string, OrxonoxOverlay*>::const_iterator it = hudElements_.begin();
98      for (unsigned int i = 0; i != index; ++it, ++i)
99        ;
100      return (*it).second;
[1505]101    }
[1604]102    else
103      return 0;
104  }
[1505]105
[1604]106  /*static*/ OverlayGroup& OverlayGroup::getHUD()
107  {
108    assert(hudInstance_s);
109    return *hudInstance_s;
110  }
[1505]111
[1604]112  /*static*/ void OverlayGroup::toggleVisibility(const std::string& name)
113  {
114    if (OverlayGroup::getHUD().hudElements_.find(name) != OverlayGroup::getHUD().hudElements_.end())
[1564]115    {
[1604]116      OverlayGroup::getHUD().hudElements_[name]->setVisibility(!OverlayGroup::getHUD().hudElements_[name]->isVisible());
[1564]117    }
[1604]118  }
[1564]119
[1505]120}
Note: See TracBrowser for help on using the repository browser.