[11527] | 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 | * |
---|
[11544] | 22 | * |
---|
| 23 | * This HUD is used for the implementation of the campaign map. |
---|
| 24 | * So far it can only be used to give names to an object planet. |
---|
| 25 | * |
---|
[11527] | 26 | * Author: |
---|
[11544] | 27 | * Nikola Bolt |
---|
[11527] | 28 | * Co-authors: |
---|
[11544] | 29 | * Claudio Fanconi |
---|
[11527] | 30 | */ |
---|
| 31 | |
---|
| 32 | |
---|
[11544] | 33 | // Header file of this cc file |
---|
| 34 | #include "StoryModeHUD.h" |
---|
| 35 | |
---|
| 36 | // Ogre stuff |
---|
[11527] | 37 | #include <OgreCamera.h> |
---|
| 38 | #include <OgreFontManager.h> |
---|
| 39 | #include <OgreOverlayManager.h> |
---|
| 40 | #include <OgreTextAreaOverlayElement.h> |
---|
| 41 | #include <OgrePanelOverlayElement.h> |
---|
| 42 | |
---|
[11544] | 43 | // Other stuff |
---|
[11527] | 44 | #include <typeinfo> |
---|
| 45 | |
---|
| 46 | #include "util/Convert.h" |
---|
| 47 | #include "core/command/ConsoleCommandIncludes.h" |
---|
| 48 | #include "core/CoreIncludes.h" |
---|
| 49 | #include "core/XMLPort.h" |
---|
| 50 | #include "CameraManager.h" |
---|
| 51 | #include "graphics/Camera.h" |
---|
| 52 | #include "worldentities/pawns/Pawn.h" |
---|
| 53 | #include "worldentities/WorldEntity.h" |
---|
| 54 | #include "core/config/ConfigValueIncludes.h" |
---|
| 55 | #include "tools/TextureGenerator.h" |
---|
[11663] | 56 | #include "controllers/NewHumanController.h" |
---|
[11527] | 57 | |
---|
[11675] | 58 | #include "worldentities/NameableStaticEntity.h" |
---|
[11527] | 59 | |
---|
| 60 | namespace orxonox |
---|
| 61 | { |
---|
[11544] | 62 | RegisterClass ( StoryModeHUD ); |
---|
[11527] | 63 | |
---|
[11544] | 64 | // Constructor of the StoryMode HUD |
---|
| 65 | StoryModeHUD::StoryModeHUD(Context* context) : OrxonoxOverlay(context) |
---|
[11527] | 66 | { |
---|
[11544] | 67 | RegisterObject(StoryModeHUD); |
---|
[11745] | 68 | |
---|
| 69 | this->textSize_ = 1.0; |
---|
[11527] | 70 | } |
---|
| 71 | |
---|
[11544] | 72 | // Destructor of the StoryMode HUD |
---|
| 73 | StoryModeHUD::~StoryModeHUD() |
---|
[11745] | 74 | { |
---|
| 75 | for(Ogre::TextAreaOverlayElement* text : texts) |
---|
| 76 | Ogre::OverlayManager::getSingleton().destroyOverlayElement(text); |
---|
| 77 | } |
---|
[11527] | 78 | |
---|
[11544] | 79 | // Functions of the StoryMode HUD |
---|
[11527] | 80 | |
---|
[11544] | 81 | // XML Port for Level construction. |
---|
| 82 | void StoryModeHUD::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
[11527] | 83 | { |
---|
[11544] | 84 | SUPER(StoryModeHUD, XMLPort, xmlelement, mode); |
---|
[11527] | 85 | |
---|
[11544] | 86 | XMLPortParam(StoryModeHUD, "font", setFont, getFont, xmlelement, mode); |
---|
| 87 | XMLPortParam(StoryModeHUD, "textSize", setTextSize, getTextSize, xmlelement, mode); |
---|
[11527] | 88 | } |
---|
[11544] | 89 | |
---|
[11584] | 90 | void StoryModeHUD::initialize(){ |
---|
[11605] | 91 | firstTick = false; |
---|
[11584] | 92 | // Scales used for dimensions and text size |
---|
| 93 | float xScale = this->getActualSize().x; |
---|
| 94 | float yScale = this->getActualSize().y; |
---|
| 95 | |
---|
[11663] | 96 | //Sets the Camera angle at 30 degrees above it, so levels can be seen better |
---|
| 97 | CameraManager::getInstance().getActiveCamera()->setOrientation(Vector3::UNIT_X, Degree(-30)); |
---|
| 98 | |
---|
[11675] | 99 | for(NameableStaticEntity* planet : ObjectList<NameableStaticEntity>()){ |
---|
[11584] | 100 | |
---|
[11588] | 101 | |
---|
[11584] | 102 | Ogre::TextAreaOverlayElement* text = static_cast<Ogre::TextAreaOverlayElement*>( Ogre::OverlayManager::getSingleton() |
---|
| 103 | .createOverlayElement("TextArea", "StoryModeHUD_navText_" + getUniqueNumberString())); |
---|
| 104 | |
---|
| 105 | texts.push_back(text); |
---|
[11745] | 106 | text->setDimensions(xScale, yScale); |
---|
[11584] | 107 | |
---|
[11588] | 108 | //font name of the text needs to be set here, not in the xml setter function |
---|
[11745] | 109 | text->setFontName(this->fontName_); |
---|
| 110 | text->setCharHeight(this->textSize_ * yScale); |
---|
[11588] | 111 | |
---|
| 112 | //set text |
---|
[11745] | 113 | text->setCaption(planet->getLevelName()); |
---|
[11588] | 114 | |
---|
[11745] | 115 | text->hide(); |
---|
[11584] | 116 | |
---|
[11745] | 117 | this->background_->addChild(text); |
---|
[11584] | 118 | } |
---|
| 119 | } |
---|
| 120 | |
---|
[11588] | 121 | // Set the Font of this HUD. |
---|
[11544] | 122 | void StoryModeHUD::setFont(const std::string& font) |
---|
[11527] | 123 | { |
---|
| 124 | const Ogre::ResourcePtr& fontPtr = Ogre::FontManager::getSingleton().getByName(font); |
---|
| 125 | if (fontPtr.isNull()) |
---|
| 126 | { |
---|
[11588] | 127 | this->fontName_ = "Monofur"; |
---|
| 128 | orxout(internal_warning) << "StoryModeHUD: Font '" << font << "' not found. Font has been set to Monofur." << endl; |
---|
[11527] | 129 | return; |
---|
| 130 | } |
---|
| 131 | this->fontName_ = font; |
---|
| 132 | } |
---|
[11544] | 133 | |
---|
[11588] | 134 | // Gets the Font of this HUD |
---|
[11544] | 135 | const std::string& StoryModeHUD::getFont() const |
---|
[11527] | 136 | { |
---|
| 137 | return this->fontName_; |
---|
| 138 | } |
---|
| 139 | |
---|
[11544] | 140 | // Set the size of the Text |
---|
| 141 | void StoryModeHUD::setTextSize(float size) |
---|
[11527] | 142 | { |
---|
| 143 | if (size <= 0.0f) |
---|
| 144 | { |
---|
[11588] | 145 | this->textSize_ = 0.05f; |
---|
| 146 | orxout(internal_warning) << "StoryModeHUD: Non positive font size not allowed. Font size has been set to 0.05" << endl; |
---|
[11527] | 147 | return; |
---|
| 148 | } |
---|
| 149 | this->textSize_ = size; |
---|
[11560] | 150 | |
---|
[11527] | 151 | } |
---|
| 152 | |
---|
[11544] | 153 | // returns the Size of the Text |
---|
| 154 | float StoryModeHUD::getTextSize() const |
---|
[11527] | 155 | { |
---|
| 156 | return this->textSize_; |
---|
| 157 | } |
---|
| 158 | |
---|
[11544] | 159 | // Tick: this is the most important function. It's recalled every frame and makes sure things happen on the screen. |
---|
| 160 | void StoryModeHUD::tick(float dt) |
---|
[11527] | 161 | { |
---|
[11544] | 162 | SUPER(StoryModeHUD, tick, dt); |
---|
[11527] | 163 | |
---|
[11605] | 164 | if(firstTick) |
---|
| 165 | this->initialize(); |
---|
| 166 | |
---|
[11544] | 167 | // cam is the pointer which represents your camera |
---|
[11527] | 168 | Camera* cam = CameraManager::getInstance().getActiveCamera(); |
---|
| 169 | if (cam == nullptr) |
---|
[11544] | 170 | return; |
---|
| 171 | |
---|
| 172 | // camTransform is a Matrix, which converts 3D world of the game into 2D on your screen |
---|
[11527] | 173 | const Matrix4& camTransform = cam->getOgreCamera()->getProjectionMatrix() * cam->getOgreCamera()->getViewMatrix(); |
---|
| 174 | |
---|
[11745] | 175 | size_t i = 0; |
---|
[11675] | 176 | for(NameableStaticEntity* planet : ObjectList<NameableStaticEntity>()){ |
---|
[11745] | 177 | if (i >= texts.size()) { |
---|
| 178 | break; |
---|
| 179 | } |
---|
| 180 | Ogre::TextAreaOverlayElement* text = texts[i]; |
---|
| 181 | i++; |
---|
[11527] | 182 | |
---|
[11584] | 183 | // Transform to screen coordinates |
---|
| 184 | Vector3 pos = camTransform * planet->getWorldPosition(); |
---|
[11560] | 185 | |
---|
[11584] | 186 | // If you fly passed the description, it gets out of sight |
---|
| 187 | if (!(pos.z > 1.0)){ |
---|
| 188 | |
---|
| 189 | // Position text |
---|
[11745] | 190 | text->setLeft((pos.x+1)/2); // The (0,0) Coordinate is in the upper left corner. |
---|
| 191 | text->setTop((-pos.y+1)/2); // With those two calculations we set the desired positions |
---|
[11527] | 192 | |
---|
[11584] | 193 | // Make sure the overlays are shown |
---|
[11745] | 194 | text->show(); |
---|
[11584] | 195 | } |
---|
| 196 | } |
---|
[11527] | 197 | } |
---|
[11745] | 198 | } |
---|