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 | { |
---|
45 | CreateFactory(Stats); |
---|
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 | |
---|
60 | /** |
---|
61 | @brief Sets the config values, describing the size of the Stats panel. |
---|
62 | */ |
---|
63 | void Stats::setConfigValues() |
---|
64 | { |
---|
65 | SetConfigValue(noiseSize_, 1.0f); |
---|
66 | } |
---|
67 | |
---|
68 | /** |
---|
69 | @brief Initializes the Stats panel. |
---|
70 | */ |
---|
71 | void Stats::XMLPort(Element& xmlElement, XMLPort::Mode mode) |
---|
72 | { |
---|
73 | OrxonoxOverlay::XMLPort(xmlElement, mode); |
---|
74 | |
---|
75 | // create overlay and elements |
---|
76 | Ogre::OverlayManager* ovMan = Ogre::OverlayManager::getSingletonPtr(); |
---|
77 | |
---|
78 | // create BorderPanel |
---|
79 | this->statsOverlayBorder_ = static_cast<Ogre::BorderPanelOverlayElement*>(ovMan->createOverlayElement("BorderPanel", "StatsBorderPanel")); |
---|
80 | this->statsOverlayBorder_->setMaterialName("StatsCenter"); |
---|
81 | this->statsOverlayBorder_->setBorderSize(0.02, 0.02, 0.02, 0.02); |
---|
82 | this->statsOverlayBorder_->setBorderMaterialName("StatsBorder"); |
---|
83 | this->statsOverlayBorder_->setTopBorderUV(0.49, 0.0, 0.51, 0.5); |
---|
84 | this->statsOverlayBorder_->setTopLeftBorderUV(0.0, 0.0, 0.5, 0.5); |
---|
85 | this->statsOverlayBorder_->setTopRightBorderUV(0.5, 0.0, 1.0, 0.5); |
---|
86 | this->statsOverlayBorder_->setLeftBorderUV(0.0, 0.49, 0.5, 0.51); |
---|
87 | this->statsOverlayBorder_->setRightBorderUV(0.5, 0.49, 1.0, 0.5); |
---|
88 | this->statsOverlayBorder_->setBottomBorderUV(0.49, 0.5, 0.51, 1.0); |
---|
89 | this->statsOverlayBorder_->setBottomLeftBorderUV(0.0, 0.5, 0.5, 1.0); |
---|
90 | this->statsOverlayBorder_->setBottomRightBorderUV(0.5, 0.5, 1.0, 1.0); |
---|
91 | |
---|
92 | background_->addChild(statsOverlayBorder_); |
---|
93 | |
---|
94 | // create noise |
---|
95 | this->statsOverlayNoise_ = static_cast<Ogre::PanelOverlayElement*>(ovMan->createOverlayElement("Panel", "StatsNoise")); |
---|
96 | this->statsOverlayNoise_->setPosition(0,0); |
---|
97 | this->statsOverlayNoise_->setMaterialName("StatsNoiseSmall"); |
---|
98 | // comment following line to disable noise |
---|
99 | background_->addChild(this->statsOverlayNoise_); |
---|
100 | |
---|
101 | } |
---|
102 | |
---|
103 | /** |
---|
104 | @brief Used to control the actual scrolling and the cursor. |
---|
105 | */ |
---|
106 | |
---|
107 | void Stats::tick(float dt) |
---|
108 | { |
---|
109 | // SUPER(Stats, tick, dt); |
---|
110 | |
---|
111 | // this creates a flickering effect (extracts exactly 80% of the texture at a random location) |
---|
112 | float uRand = (rand() & 1023) / 1023.0f * 0.2f; |
---|
113 | float vRand = (rand() & 1023) / 1023.0f * 0.2f; |
---|
114 | this->statsOverlayNoise_->setUV(uRand, vRand, 7.5f + uRand, 7.5f + vRand); |
---|
115 | } |
---|
116 | |
---|
117 | } |
---|