[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 | |
---|
| 32 | #include "core/Debug.h" |
---|
| 33 | #include "core/ConsoleCommand.h" |
---|
[1588] | 34 | #include "core/CoreIncludes.h" |
---|
[1616] | 35 | #include "core/XMLPort.h" |
---|
[1604] | 36 | #include "OrxonoxOverlay.h" |
---|
[1505] | 37 | |
---|
| 38 | namespace orxonox |
---|
| 39 | { |
---|
[1615] | 40 | CreateFactory(OverlayGroup); |
---|
[1588] | 41 | |
---|
[1615] | 42 | SetConsoleCommand(OverlayGroup, toggleVisibility, false).setAccessLevel(AccessLevel::User); |
---|
| 43 | SetConsoleCommand(OverlayGroup, scaleGroup, false).setAccessLevel(AccessLevel::User); |
---|
| 44 | SetConsoleCommand(OverlayGroup, scrollGroup, false).setAccessLevel(AccessLevel::User); |
---|
[1505] | 45 | |
---|
[1615] | 46 | OverlayGroup::OverlayGroup() |
---|
| 47 | : scale_(1.0, 1.0) |
---|
| 48 | { |
---|
| 49 | RegisterObject(OverlayGroup); |
---|
| 50 | } |
---|
[1505] | 51 | |
---|
[1615] | 52 | OverlayGroup::~OverlayGroup() |
---|
| 53 | { |
---|
| 54 | } |
---|
[1588] | 55 | |
---|
[1615] | 56 | void OverlayGroup::XMLPort(Element& xmlElement, XMLPort::Mode mode) |
---|
| 57 | { |
---|
| 58 | BaseObject::XMLPort(xmlElement, mode); |
---|
[1588] | 59 | |
---|
[1615] | 60 | XMLPortParam(OverlayGroup, "scale", setScale, getScale, xmlElement, mode); |
---|
| 61 | XMLPortParam(OverlayGroup, "scroll", setScroll, getScroll, xmlElement, mode); |
---|
| 62 | XMLPortObject(OverlayGroup, OrxonoxOverlay, "", addElement, getElement, xmlElement, mode, false, true); |
---|
| 63 | } |
---|
[1505] | 64 | |
---|
[1615] | 65 | void OverlayGroup::setScale(const Vector2& scale) |
---|
| 66 | { |
---|
| 67 | for (std::map<std::string, OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it) |
---|
| 68 | (*it).second->scale(scale / this->scale_); |
---|
| 69 | this->scale_ = scale; |
---|
| 70 | } |
---|
[1588] | 71 | |
---|
[1615] | 72 | void OverlayGroup::setScroll(const Vector2& scroll) |
---|
| 73 | { |
---|
| 74 | for (std::map<std::string, OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it) |
---|
| 75 | (*it).second->scroll(scroll - this->scroll_); |
---|
| 76 | this->scroll_ = scroll; |
---|
| 77 | } |
---|
[1505] | 78 | |
---|
[1615] | 79 | void OverlayGroup::addElement(OrxonoxOverlay* element) |
---|
[1564] | 80 | { |
---|
[1615] | 81 | if (hudElements_.find(element->getName()) != hudElements_.end()) |
---|
| 82 | { |
---|
| 83 | COUT(1) << "Ambiguous names encountered while load the HUD overlays" << std::endl; |
---|
| 84 | } |
---|
| 85 | else |
---|
| 86 | hudElements_[element->getName()] = element; |
---|
[1588] | 87 | } |
---|
[1564] | 88 | |
---|
[1615] | 89 | OrxonoxOverlay* OverlayGroup::getElement(unsigned int index) |
---|
[1588] | 90 | { |
---|
[1615] | 91 | if (index < this->hudElements_.size()) |
---|
| 92 | { |
---|
| 93 | std::map<std::string, OrxonoxOverlay*>::const_iterator it = hudElements_.begin(); |
---|
| 94 | for (unsigned int i = 0; i != index; ++it, ++i) |
---|
| 95 | ; |
---|
| 96 | return (*it).second; |
---|
| 97 | } |
---|
| 98 | else |
---|
| 99 | return 0; |
---|
[1505] | 100 | } |
---|
| 101 | |
---|
[1614] | 102 | |
---|
[1615] | 103 | /*static*/ void OverlayGroup::toggleVisibility(const std::string& name) |
---|
[1614] | 104 | { |
---|
[1615] | 105 | for (Iterator<OverlayGroup> it = ObjectList<OverlayGroup>::begin(); it; ++it) |
---|
| 106 | { |
---|
| 107 | if ((*it)->getName() == name) |
---|
| 108 | (*it)->setVisibility(!((*it)->isVisible())); |
---|
| 109 | } |
---|
[1614] | 110 | } |
---|
[1505] | 111 | |
---|
[1615] | 112 | /*static*/ void OverlayGroup::scaleGroup(const std::string& name, float scale) |
---|
[1564] | 113 | { |
---|
[1615] | 114 | for (Iterator<OverlayGroup> it = ObjectList<OverlayGroup>::begin(); it; ++it) |
---|
| 115 | { |
---|
| 116 | if ((*it)->getName() == name) |
---|
| 117 | (*it)->scale(Vector2(scale, scale)); |
---|
| 118 | } |
---|
[1564] | 119 | } |
---|
[1615] | 120 | |
---|
| 121 | /*static*/ void OverlayGroup::scrollGroup(const std::string& name, const Vector2& scroll) |
---|
| 122 | { |
---|
| 123 | for (Iterator<OverlayGroup> it = ObjectList<OverlayGroup>::begin(); it; ++it) |
---|
| 124 | { |
---|
| 125 | if ((*it)->getName() == name) |
---|
| 126 | (*it)->scroll(scroll); |
---|
| 127 | } |
---|
| 128 | } |
---|
[1505] | 129 | } |
---|