| 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 |  *      Benjamin Hildebrandt | 
|---|
| 24 |  * | 
|---|
| 25 |  */ | 
|---|
| 26 |  | 
|---|
| 27 | #include "CreateLines.h" | 
|---|
| 28 |  | 
|---|
| 29 | #include <string> | 
|---|
| 30 | #include <OgreOverlay.h> | 
|---|
| 31 | #include <OgreOverlayElement.h> | 
|---|
| 32 | #include <OgreOverlayManager.h> | 
|---|
| 33 | #include <OgreOverlayContainer.h> | 
|---|
| 34 |  | 
|---|
| 35 | #include "util/Convert.h" | 
|---|
| 36 | #include "util/Debug.h" | 
|---|
| 37 | #include "core/CoreIncludes.h" | 
|---|
| 38 | #include "core/ConfigValueIncludes.h" | 
|---|
| 39 |  | 
|---|
| 40 | #include "overlays/OverlayText.h" | 
|---|
| 41 | #include "overlays/stats/Stats.h" | 
|---|
| 42 |  | 
|---|
| 43 | namespace orxonox | 
|---|
| 44 | { | 
|---|
| 45 |     /** | 
|---|
| 46 |         @brief Constructor: Creates a line. | 
|---|
| 47 |     */ | 
|---|
| 48 |     CreateLines::CreateLines(float leftOffset, float topOffset, float width, float height) | 
|---|
| 49 |     { | 
|---|
| 50 |         playerNameText_ = new OverlayText(0); | 
|---|
| 51 |         playerNameText_->setTextSize(0.04); | 
|---|
| 52 |         playerNameText_->setColour(ColourValue(0, 0.75, 0.2, 1)); | 
|---|
| 53 |         playerNameText_->setPosition(Vector2(0.1, topOffset + 0.01)); | 
|---|
| 54 |  | 
|---|
| 55 |         scoreText_ = new OverlayText(0); | 
|---|
| 56 |         scoreText_->setTextSize(0.04); | 
|---|
| 57 |         scoreText_->setColour(ColourValue(0, 0.75, 0.2, 1)); | 
|---|
| 58 |         scoreText_->setPosition(Vector2(0.6, topOffset + 0.01)); | 
|---|
| 59 |  | 
|---|
| 60 |         deathsText_ = new OverlayText(0); | 
|---|
| 61 |         deathsText_->setTextSize(0.04); | 
|---|
| 62 |         deathsText_->setColour(ColourValue(0, 0.75, 0.2, 1)); | 
|---|
| 63 |         deathsText_->setPosition(Vector2(0.8, topOffset + 0.01)); | 
|---|
| 64 |  | 
|---|
| 65 |         background_ = new Stats(0); | 
|---|
| 66 |         background_->setPosition(Vector2(leftOffset, topOffset)); | 
|---|
| 67 |         background_->setSize(Vector2(width, height)); | 
|---|
| 68 |     } | 
|---|
| 69 |  | 
|---|
| 70 |     CreateLines::~CreateLines() | 
|---|
| 71 |     { | 
|---|
| 72 |         delete this->playerNameText_; | 
|---|
| 73 |         delete this->scoreText_; | 
|---|
| 74 |         delete this->deathsText_; | 
|---|
| 75 |         delete this->background_; | 
|---|
| 76 |     } | 
|---|
| 77 |  | 
|---|
| 78 |     void CreateLines::setPlayerName(const std::string& str) | 
|---|
| 79 |     { | 
|---|
| 80 |         this->playerNameText_->setCaption(str); | 
|---|
| 81 |     } | 
|---|
| 82 |  | 
|---|
| 83 |     void CreateLines::setScore(const std::string& str) | 
|---|
| 84 |     { | 
|---|
| 85 |         this->scoreText_->setCaption(str); | 
|---|
| 86 |     } | 
|---|
| 87 |  | 
|---|
| 88 |     void CreateLines::setDeaths(const std::string& str) | 
|---|
| 89 |     { | 
|---|
| 90 |         this->deathsText_->setCaption(str); | 
|---|
| 91 |     } | 
|---|
| 92 |  | 
|---|
| 93 |     void CreateLines::setVisibility(bool visible) | 
|---|
| 94 |     { | 
|---|
| 95 |         this->scoreText_->setVisible(visible); | 
|---|
| 96 |         this->deathsText_->setVisible(visible); | 
|---|
| 97 |         this->playerNameText_->setVisible(visible); | 
|---|
| 98 |         this->background_->setVisible(visible); | 
|---|
| 99 |     } | 
|---|
| 100 |  | 
|---|
| 101 |     /** | 
|---|
| 102 |         @brief Ensures that the number of OverlayElements is equal to numberOfColumns. | 
|---|
| 103 |     */ | 
|---|
| 104 |     //void CreateLines::setNumberOfColumns(unsigned int numberOfColumns, unsigned int lineIndex) { | 
|---|
| 105 |  | 
|---|
| 106 |     //    Ogre::OverlayManager* ovMan = Ogre::OverlayManager::getSingletonPtr(); | 
|---|
| 107 |  | 
|---|
| 108 |     //    unsigned int colIndex = 0; | 
|---|
| 109 |  | 
|---|
| 110 |     //    while (textColumns_.size() < numberOfColumns) | 
|---|
| 111 |     //    { | 
|---|
| 112 |     //        Ogre::TextAreaOverlayElement* tempTextArea = static_cast<Ogre::TextAreaOverlayElement*>(ovMan->createOverlayElement("TextArea", "StatsLineTextArea" + getName() + convertToString(lineIndex) + convertToString(colIndex))); | 
|---|
| 113 |     //        textColumns_.push_back(tempTextArea); | 
|---|
| 114 |     //        this->background_->addChild(tempTextArea); | 
|---|
| 115 |  | 
|---|
| 116 |     //        colIndex++; | 
|---|
| 117 |     //    } | 
|---|
| 118 |  | 
|---|
| 119 |     //    while (textColumns_.size() > numberOfColumns) | 
|---|
| 120 |     //    { | 
|---|
| 121 |     //        this->background_->_removeChild(textColumns_.back()); | 
|---|
| 122 |     //        ovMan->destroyOverlayElement(textColumns_.back()); | 
|---|
| 123 |     //        textColumns_.pop_back(); | 
|---|
| 124 |     //    } | 
|---|
| 125 |     //} | 
|---|
| 126 |  | 
|---|
| 127 |     //void CreateLines::alignColumn(int columnIndex, float leftOffset, float topOffset) | 
|---|
| 128 |     //{ | 
|---|
| 129 |     //    this->textColumns_[columnIndex]->setPosition(leftOffset, topOffset); | 
|---|
| 130 |     //} | 
|---|
| 131 |  | 
|---|
| 132 |     //void CreateLines::setColumnText(int columnIndex, std::string columnText) | 
|---|
| 133 |     //{ | 
|---|
| 134 |     //    this->textColumns_[columnIndex]->setCaption(columnText); | 
|---|
| 135 |     //} | 
|---|
| 136 | } | 
|---|