| [2120] | 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 |  *      Felix Schulthess | 
|---|
 | 24 |  *   Co-authors: | 
|---|
 | 25 |  *      Fabian 'x3n' Landau, Benjamin Hildebrandt | 
|---|
 | 26 |  * | 
|---|
 | 27 |  */ | 
|---|
 | 28 |  | 
|---|
 | 29 | #include "OrxonoxStableHeaders.h" | 
|---|
 | 30 | #include "Stats.h" | 
|---|
 | 31 |  | 
|---|
 | 32 | #include <string> | 
|---|
 | 33 | #include <OgreOverlay.h> | 
|---|
 | 34 | #include <OgreOverlayElement.h> | 
|---|
 | 35 | #include <OgreOverlayManager.h> | 
|---|
 | 36 | #include <OgreOverlayContainer.h> | 
|---|
 | 37 |  | 
|---|
 | 38 | #include "util/Convert.h" | 
|---|
 | 39 | #include "util/Debug.h" | 
|---|
 | 40 | #include "core/CoreIncludes.h" | 
|---|
 | 41 | #include "core/ConfigValueIncludes.h" | 
|---|
 | 42 |  | 
|---|
 | 43 | namespace orxonox | 
|---|
 | 44 | { | 
|---|
| [2140] | 45 |     CreateFactory(Stats); | 
|---|
| [2120] | 46 |  | 
|---|
 | 47 |     /** | 
|---|
 | 48 |         @brief Constructor: Creates and initializes the Stats panel. | 
|---|
 | 49 |     */ | 
|---|
 | 50 |     Stats::Stats(BaseObject* creator) | 
|---|
 | 51 |         : OrxonoxOverlay(creator) | 
|---|
 | 52 |         , statsOverlayNoise_(0) | 
|---|
 | 53 |         , statsOverlayBorder_(0) | 
|---|
 | 54 |     { | 
|---|
 | 55 |         RegisterObject(Stats); | 
|---|
 | 56 |  | 
|---|
 | 57 |         this->setConfigValues(); | 
|---|
 | 58 |  | 
|---|
 | 59 |         // create overlay and elements | 
|---|
 | 60 |         Ogre::OverlayManager* ovMan = Ogre::OverlayManager::getSingletonPtr(); | 
|---|
 | 61 |  | 
|---|
 | 62 |         // create BorderPanel | 
|---|
| [2495] | 63 |         this->statsOverlayBorder_ = static_cast<Ogre::BorderPanelOverlayElement*>(ovMan->createOverlayElement("BorderPanel", "StatsBorderPanel" + getUniqueNumberString())); | 
|---|
 | 64 |         //this->statsOverlayBorder_->setMaterialName("StatsCenter"); | 
|---|
 | 65 |         this->statsOverlayBorder_->setBorderSize(0.003, 16 * 0.003); | 
|---|
| [2120] | 66 |         this->statsOverlayBorder_->setBorderMaterialName("StatsBorder"); | 
|---|
 | 67 |         this->statsOverlayBorder_->setTopBorderUV(0.49, 0.0, 0.51, 0.5); | 
|---|
 | 68 |         this->statsOverlayBorder_->setTopLeftBorderUV(0.0, 0.0, 0.5, 0.5); | 
|---|
 | 69 |         this->statsOverlayBorder_->setTopRightBorderUV(0.5, 0.0, 1.0, 0.5); | 
|---|
 | 70 |         this->statsOverlayBorder_->setLeftBorderUV(0.0, 0.49, 0.5, 0.51); | 
|---|
 | 71 |         this->statsOverlayBorder_->setRightBorderUV(0.5, 0.49, 1.0, 0.5); | 
|---|
 | 72 |         this->statsOverlayBorder_->setBottomBorderUV(0.49, 0.5, 0.51, 1.0); | 
|---|
 | 73 |         this->statsOverlayBorder_->setBottomLeftBorderUV(0.0, 0.5, 0.5, 1.0); | 
|---|
 | 74 |         this->statsOverlayBorder_->setBottomRightBorderUV(0.5, 0.5, 1.0, 1.0); | 
|---|
 | 75 |  | 
|---|
 | 76 |         background_->addChild(statsOverlayBorder_); | 
|---|
 | 77 |  | 
|---|
 | 78 |         // create noise | 
|---|
| [2495] | 79 |         //this->statsOverlayNoise_ = static_cast<Ogre::PanelOverlayElement*>(ovMan->createOverlayElement("Panel", "StatsNoise" + getUniqueNumberString())); | 
|---|
 | 80 |         //this->statsOverlayNoise_->setPosition(0,0); | 
|---|
 | 81 |         //this->statsOverlayNoise_->setMaterialName("StatsNoiseSmall"); | 
|---|
| [2120] | 82 |         // comment following line to disable noise | 
|---|
| [2495] | 83 |         //background_->addChild(this->statsOverlayNoise_); | 
|---|
 | 84 |     } | 
|---|
| [2120] | 85 |  | 
|---|
| [2495] | 86 |     Stats::~Stats() | 
|---|
 | 87 |     { | 
|---|
 | 88 |         if (this->isInitialized()) | 
|---|
 | 89 |         { | 
|---|
 | 90 |             Ogre::OverlayManager* ovMan = Ogre::OverlayManager::getSingletonPtr(); | 
|---|
 | 91 |             ovMan->destroyOverlayElement(this->statsOverlayBorder_); | 
|---|
 | 92 |             //ovMan->destroyOverlayElement(this->statsOverlayNoise_); | 
|---|
 | 93 |         } | 
|---|
| [2120] | 94 |     } | 
|---|
 | 95 |  | 
|---|
| [2495] | 96 |     /** | 
|---|
 | 97 |         @brief Sets the config values, describing the size of the Stats panel. | 
|---|
 | 98 |     */ | 
|---|
 | 99 |     void Stats::setConfigValues() | 
|---|
 | 100 |     { | 
|---|
 | 101 |         SetConfigValue(noiseSize_, 1.0f); | 
|---|
 | 102 |     } | 
|---|
 | 103 |  | 
|---|
 | 104 |     /** | 
|---|
 | 105 |         @brief Initializes the Stats panel. | 
|---|
 | 106 |     */ | 
|---|
 | 107 |     void Stats::XMLPort(Element& xmlElement, XMLPort::Mode mode) | 
|---|
 | 108 |     { | 
|---|
 | 109 |         OrxonoxOverlay::XMLPort(xmlElement, mode); | 
|---|
 | 110 |     } | 
|---|
 | 111 |  | 
|---|
| [2120] | 112 |     void Stats::tick(float dt) | 
|---|
 | 113 |     { | 
|---|
 | 114 |         // SUPER(Stats, tick, dt); | 
|---|
 | 115 |  | 
|---|
 | 116 |             // this creates a flickering effect (extracts exactly 80% of the texture at a random location) | 
|---|
| [2495] | 117 |             //float uRand = (rand() & 1023) / 1023.0f * 0.2f; | 
|---|
 | 118 |             //float vRand = (rand() & 1023) / 1023.0f * 0.2f; | 
|---|
 | 119 |             //this->statsOverlayNoise_->setUV(uRand, vRand, 7.5f + uRand, 7.5f + vRand); | 
|---|
| [2120] | 120 |     } | 
|---|
 | 121 |  | 
|---|
 | 122 | } | 
|---|