[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); |
---|
[11527] | 68 | } |
---|
| 69 | |
---|
[11544] | 70 | // Destructor of the StoryMode HUD |
---|
| 71 | StoryModeHUD::~StoryModeHUD() |
---|
[11527] | 72 | { |
---|
[11584] | 73 | for(Ogre::TextAreaOverlayElement* text : texts) |
---|
| 74 | delete text; |
---|
[11527] | 75 | } |
---|
| 76 | |
---|
[11544] | 77 | // Functions of the StoryMode HUD |
---|
[11527] | 78 | |
---|
[11544] | 79 | // XML Port for Level construction. |
---|
| 80 | void StoryModeHUD::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
[11527] | 81 | { |
---|
[11544] | 82 | SUPER(StoryModeHUD, XMLPort, xmlelement, mode); |
---|
[11527] | 83 | |
---|
[11544] | 84 | XMLPortParam(StoryModeHUD, "font", setFont, getFont, xmlelement, mode); |
---|
| 85 | XMLPortParam(StoryModeHUD, "textSize", setTextSize, getTextSize, xmlelement, mode); |
---|
[11527] | 86 | } |
---|
[11544] | 87 | |
---|
[11584] | 88 | void StoryModeHUD::initialize(){ |
---|
[11605] | 89 | firstTick = false; |
---|
[11584] | 90 | // Scales used for dimensions and text size |
---|
| 91 | float xScale = this->getActualSize().x; |
---|
| 92 | float yScale = this->getActualSize().y; |
---|
| 93 | |
---|
[11663] | 94 | //Sets the Camera angle at 30 degrees above it, so levels can be seen better |
---|
| 95 | CameraManager::getInstance().getActiveCamera()->setOrientation(Vector3::UNIT_X, Degree(-30)); |
---|
| 96 | |
---|
[11588] | 97 | int i = 0; |
---|
[11675] | 98 | for(NameableStaticEntity* planet : ObjectList<NameableStaticEntity>()){ |
---|
[11584] | 99 | |
---|
[11588] | 100 | |
---|
[11584] | 101 | Ogre::TextAreaOverlayElement* text = static_cast<Ogre::TextAreaOverlayElement*>( Ogre::OverlayManager::getSingleton() |
---|
| 102 | .createOverlayElement("TextArea", "StoryModeHUD_navText_" + getUniqueNumberString())); |
---|
| 103 | |
---|
| 104 | texts.push_back(text); |
---|
| 105 | texts[i]->setDimensions(xScale, yScale); |
---|
| 106 | |
---|
[11588] | 107 | //font name of the text needs to be set here, not in the xml setter function |
---|
| 108 | texts[i]->setFontName(this->fontName_); |
---|
| 109 | texts[i]->setCharHeight(this->textSize_ * yScale); |
---|
| 110 | |
---|
| 111 | //set text |
---|
| 112 | texts[i]->setCaption(planet->getLevelName()); |
---|
| 113 | |
---|
[11584] | 114 | texts[i]->hide(); |
---|
| 115 | |
---|
| 116 | this->background_->addChild(texts[i]); |
---|
[11588] | 117 | i++; |
---|
[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 | |
---|
[11584] | 175 | int i = 0; |
---|
[11675] | 176 | for(NameableStaticEntity* planet : ObjectList<NameableStaticEntity>()){ |
---|
[11527] | 177 | |
---|
[11584] | 178 | // Transform to screen coordinates |
---|
| 179 | Vector3 pos = camTransform * planet->getWorldPosition(); |
---|
[11560] | 180 | |
---|
[11584] | 181 | // If you fly passed the description, it gets out of sight |
---|
| 182 | if (!(pos.z > 1.0)){ |
---|
| 183 | |
---|
| 184 | // Position text |
---|
| 185 | texts[i]->setLeft((pos.x+1)/2); // The (0,0) Coordinate is in the upper left corner. |
---|
| 186 | texts[i]->setTop((-pos.y+1)/2); // With those two calculations we set the desired positions |
---|
[11527] | 187 | |
---|
[11584] | 188 | // Make sure the overlays are shown |
---|
| 189 | texts[i]->show(); |
---|
| 190 | } |
---|
| 191 | i++; |
---|
[11527] | 192 | |
---|
[11584] | 193 | } |
---|
[11527] | 194 | } |
---|
[11544] | 195 | } |
---|