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