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 | |
---|
38 | namespace orxonox |
---|
39 | { |
---|
40 | CreateFactory(OverlayGroup); |
---|
41 | |
---|
42 | SetConsoleCommand(OverlayGroup, toggleVisibility, false).setAccessLevel(AccessLevel::User); |
---|
43 | |
---|
44 | OverlayGroup* OverlayGroup::hudInstance_s = 0; |
---|
45 | |
---|
46 | using namespace Ogre; |
---|
47 | |
---|
48 | OverlayGroup::OverlayGroup() |
---|
49 | : scale_(1.0, 1.0) |
---|
50 | { |
---|
51 | RegisterObject(OverlayGroup); |
---|
52 | |
---|
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 | } |
---|
58 | |
---|
59 | OverlayGroup::~OverlayGroup() |
---|
60 | { |
---|
61 | if (this->isInitialized()) |
---|
62 | { |
---|
63 | } |
---|
64 | |
---|
65 | hudInstance_s = 0; |
---|
66 | } |
---|
67 | |
---|
68 | void OverlayGroup::XMLPort(Element& xmlElement, XMLPort::Mode mode) |
---|
69 | { |
---|
70 | BaseObject::XMLPort(xmlElement, mode); |
---|
71 | |
---|
72 | XMLPortParam(OverlayGroup, "scale", scale, getScale, xmlElement, mode); |
---|
73 | XMLPortObject(OverlayGroup, OrxonoxOverlay, "", addElement, getElement, xmlElement, mode, false, true); |
---|
74 | } |
---|
75 | |
---|
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 | } |
---|
82 | |
---|
83 | void OverlayGroup::addElement(OrxonoxOverlay* element) |
---|
84 | { |
---|
85 | if (hudElements_.find(element->getName()) != hudElements_.end()) |
---|
86 | { |
---|
87 | COUT(1) << "Ambiguous names encountered while load the HUD overlays" << std::endl; |
---|
88 | } |
---|
89 | else |
---|
90 | hudElements_[element->getName()] = element; |
---|
91 | } |
---|
92 | |
---|
93 | OrxonoxOverlay* OverlayGroup::getElement(unsigned int index) |
---|
94 | { |
---|
95 | if (index < this->hudElements_.size()) |
---|
96 | { |
---|
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; |
---|
101 | } |
---|
102 | else |
---|
103 | return 0; |
---|
104 | } |
---|
105 | |
---|
106 | /*static*/ OverlayGroup& OverlayGroup::getHUD() |
---|
107 | { |
---|
108 | assert(hudInstance_s); |
---|
109 | return *hudInstance_s; |
---|
110 | } |
---|
111 | |
---|
112 | /*static*/ void OverlayGroup::toggleVisibility(const std::string& name) |
---|
113 | { |
---|
114 | if (OverlayGroup::getHUD().hudElements_.find(name) != OverlayGroup::getHUD().hudElements_.end()) |
---|
115 | { |
---|
116 | OverlayGroup::getHUD().hudElements_[name]->setVisibility(!OverlayGroup::getHUD().hudElements_[name]->isVisible()); |
---|
117 | } |
---|
118 | } |
---|
119 | |
---|
120 | } |
---|