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