[10688] | 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 | * Yuning Chai |
---|
| 24 | * Felix Schulthess |
---|
| 25 | * Co-authors: |
---|
| 26 | * Reto Grieder |
---|
| 27 | * Wolfgang Roenninger |
---|
| 28 | * |
---|
| 29 | */ |
---|
| 30 | |
---|
| 31 | #include "HUDWeaponSystem.h" |
---|
| 32 | |
---|
| 33 | #include <OgreOverlayManager.h> |
---|
| 34 | #include <OgrePanelOverlayElement.h> |
---|
| 35 | |
---|
| 36 | #include "core/CoreIncludes.h" |
---|
| 37 | #include "core/XMLPort.h" |
---|
| 38 | #include "tools/TextureGenerator.h" |
---|
| 39 | #include "weaponsystem/WeaponSystem.h" |
---|
| 40 | #include "weaponsystem/WeaponPack.h" |
---|
| 41 | #include "weaponsystem/Weapon.h" |
---|
| 42 | #include "util/Convert.h" |
---|
| 43 | #include "core/class/Super.h" |
---|
| 44 | |
---|
| 45 | namespace orxonox |
---|
| 46 | { |
---|
| 47 | RegisterClass(HUDWeaponSystem); |
---|
| 48 | |
---|
| 49 | HUDWeaponSystem::HUDWeaponSystem(Context* context) : OrxonoxOverlay(context) |
---|
| 50 | { |
---|
| 51 | RegisterObject(HUDWeaponSystem); |
---|
| 52 | |
---|
[10721] | 53 | weaponModeHUDSize_ = Vector2(0.0f,0.0f); |
---|
| 54 | weaponModeHUDActualSize_ = Vector2(0.0f,0.0f); |
---|
| 55 | |
---|
[10688] | 56 | weapons_.clear(); |
---|
| 57 | hudWeapons_.clear(); |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | HUDWeaponSystem::~HUDWeaponSystem() |
---|
| 61 | { |
---|
| 62 | if (this->isInitialized()) |
---|
| 63 | { |
---|
| 64 | destroyHUDChilds(); |
---|
| 65 | } |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | void HUDWeaponSystem::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 69 | { |
---|
| 70 | SUPER(HUDWeaponSystem, XMLPort, xmlelement, mode); |
---|
| 71 | |
---|
[10721] | 72 | XMLPortParam(HUDWeaponSystem, "weaponModeHUDSize", setWeaponModeHUDSize, getWeaponModeHUDSize, xmlelement, mode); |
---|
[10688] | 73 | } |
---|
| 74 | |
---|
| 75 | void HUDWeaponSystem::tick(float dt) |
---|
| 76 | { |
---|
| 77 | SUPER(HUDWeaponSystem, tick, dt); |
---|
| 78 | |
---|
| 79 | if (this->owner_) |
---|
| 80 | { |
---|
| 81 | |
---|
| 82 | } |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | void HUDWeaponSystem::positionChanged() |
---|
| 86 | { |
---|
| 87 | OrxonoxOverlay::positionChanged(); |
---|
| 88 | |
---|
| 89 | positionHUDChilds(); |
---|
[10721] | 90 | } |
---|
[10688] | 91 | |
---|
[10721] | 92 | void HUDWeaponSystem::sizeChanged() |
---|
| 93 | { |
---|
| 94 | OrxonoxOverlay::sizeChanged(); |
---|
| 95 | |
---|
| 96 | weaponModeHUDActualSize_ = this->getActualSize(); |
---|
| 97 | |
---|
| 98 | positionHUDChilds(); |
---|
| 99 | } |
---|
| 100 | |
---|
[10688] | 101 | void HUDWeaponSystem::changedOwner() |
---|
| 102 | { |
---|
| 103 | SUPER(HUDWeaponSystem, changedOwner); |
---|
| 104 | |
---|
| 105 | this->owner_ = orxonox_cast<Pawn*>(this->getOwner()); |
---|
| 106 | |
---|
| 107 | updateWeaponList(); |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | void HUDWeaponSystem::changedOverlayGroup() |
---|
| 111 | { |
---|
| 112 | SUPER(HUDWeaponSystem, changedOverlayGroup); |
---|
| 113 | |
---|
| 114 | //this->getOverlayGroup()->addElement(this->textOverlay_.get()); |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | void HUDWeaponSystem::changedVisibility() |
---|
| 118 | { |
---|
| 119 | SUPER(HUDWeaponSystem, changedVisibility); |
---|
| 120 | |
---|
| 121 | //this->textOverlay_->setVisible(this->isVisible()); |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | void HUDWeaponSystem::changedName() |
---|
| 125 | { |
---|
| 126 | SUPER(HUDWeaponSystem, changedName); |
---|
| 127 | |
---|
| 128 | //this->textOverlay_->setName(this->getName() + "text"); |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | void HUDWeaponSystem::updateWeaponList() |
---|
| 132 | { |
---|
| 133 | if (owner_ == NULL) |
---|
| 134 | { |
---|
| 135 | return; |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | weapons_.clear(); |
---|
| 139 | |
---|
| 140 | destroyHUDChilds(); |
---|
| 141 | |
---|
| 142 | std::vector<WeaponPack*>* weaponPacks = owner_->getAllWeaponPacks(); |
---|
| 143 | |
---|
| 144 | for (std::vector<WeaponPack*>::const_iterator itPacks = weaponPacks->begin(); itPacks != weaponPacks->end(); ++itPacks) |
---|
| 145 | { |
---|
| 146 | std::vector<Weapon*>* weapons = (*itPacks)->getAllWeapons(); |
---|
| 147 | |
---|
| 148 | for (std::vector<Weapon*>::const_iterator itWeapons = weapons->begin(); itWeapons != weapons->end(); ++itWeapons) |
---|
| 149 | { |
---|
| 150 | this->weapons_.push_back(*itWeapons); |
---|
| 151 | } |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | createHUDChilds(); |
---|
[10721] | 155 | positionHUDChilds(); |
---|
[10688] | 156 | } |
---|
| 157 | |
---|
| 158 | void HUDWeaponSystem::createHUDChilds() |
---|
| 159 | { |
---|
[10721] | 160 | int positionIndex = 0; |
---|
| 161 | |
---|
[10688] | 162 | for (std::vector<WeakPtr<Weapon> >::iterator it = weapons_.begin(); it != weapons_.end(); ++it) |
---|
| 163 | { |
---|
[10721] | 164 | HUDWeapon* hudWeapon = new HUDWeapon(this->getContext()); |
---|
[10688] | 165 | hudWeapon->setOwner(owner_); |
---|
[10721] | 166 | hudWeapon->setOverlayGroup(this->getOverlayGroup()); |
---|
[10688] | 167 | hudWeapon->setWeapon(*it); |
---|
[10721] | 168 | hudWeapon->setAspectCorrection(false); |
---|
| 169 | hudWeapon->setPickPoint(Vector2(0.0f,0.0f)); |
---|
| 170 | |
---|
[10688] | 171 | hudWeapons_.push_back(hudWeapon); |
---|
[10721] | 172 | |
---|
| 173 | ++ positionIndex; |
---|
| 174 | } |
---|
[10688] | 175 | } |
---|
| 176 | |
---|
| 177 | void HUDWeaponSystem::positionHUDChilds() |
---|
| 178 | { |
---|
| 179 | int positionIndex = 0; |
---|
[10721] | 180 | //this->setSize(weaponModeHUDSize_); |
---|
| 181 | // this->weaponModeHUDActualSize_ = this->getActualSize(); |
---|
[10688] | 182 | |
---|
| 183 | for (std::vector<WeakPtr<HUDWeapon> >::iterator it = hudWeapons_.begin(); it != hudWeapons_.end(); ++it) |
---|
| 184 | { |
---|
[10721] | 185 | (*it)->setWeaponIndex(positionIndex); |
---|
| 186 | (*it)->setWeaponModeHUDActualSize(this->weaponModeHUDActualSize_); |
---|
| 187 | (*it)->positionHUDChilds(); |
---|
[10688] | 188 | |
---|
| 189 | ++ positionIndex; |
---|
[10721] | 190 | } |
---|
[10688] | 191 | } |
---|
| 192 | |
---|
| 193 | void HUDWeaponSystem::destroyHUDChilds() |
---|
| 194 | { |
---|
| 195 | for (std::vector<WeakPtr<HUDWeapon> >::iterator it = hudWeapons_.begin(); it != hudWeapons_.end(); ++it) |
---|
| 196 | { |
---|
| 197 | (*it)->destroy(); |
---|
| 198 | } |
---|
| 199 | |
---|
| 200 | hudWeapons_.clear(); |
---|
[10721] | 201 | } |
---|
[10688] | 202 | } |
---|