Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/CampaignMap_HS17/src/modules/overlays/hud/StoryModeHUD.cc @ 11564

Last change on this file since 11564 was 11564, checked in by fanconic, 6 years ago

small changes

File size: 5.6 KB
RevLine 
[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/Math.h"
47#include "util/Convert.h"
48#include "core/command/ConsoleCommandIncludes.h"
49#include "core/CoreIncludes.h"
50#include "core/XMLPort.h"
51#include "CameraManager.h"
52#include "Scene.h"
53#include "Radar.h"
54#include "graphics/Camera.h"
55#include "controllers/HumanController.h"
56#include "worldentities/pawns/Pawn.h"
57#include "worldentities/WorldEntity.h"
58#include "core/config/ConfigValueIncludes.h"
59#include "tools/TextureGenerator.h"
60
61
62namespace orxonox
63{
[11544]64    RegisterClass ( StoryModeHUD );
[11527]65
[11544]66    // Constructor of the StoryMode HUD
67    StoryModeHUD::StoryModeHUD(Context* context) : OrxonoxOverlay(context)
[11527]68    {
[11544]69        RegisterObject(StoryModeHUD);
[11560]70
[11527]71        // Set default values
[11560]72        //this->setFont("Monofur");
73        //this->setTextSize(0.5f);
74
75        // Scales used for dimensions and text size
76        float xScale = this->getActualSize().x;
77        float yScale = this->getActualSize().y;
78
79        // Create text
80        text_ = static_cast<Ogre::TextAreaOverlayElement*>( Ogre::OverlayManager::getSingleton()
81                .createOverlayElement("TextArea", "StoryModeHUD_navText_" + getUniqueNumberString()));
82        //text->setFontName(this->fontName_);
83        //text->setCharHeight(this->textSize_ * yScale);
84        text_->setDimensions(xScale, yScale);
85
86        text_->hide();
87       
88        this->background_->addChild(text_);
[11527]89    }
90
[11544]91    // TODO:
92    // Destructor of the StoryMode HUD
93    StoryModeHUD::~StoryModeHUD()
[11527]94    {
95
96    }
97
[11544]98    // Functions of the StoryMode HUD
[11527]99
[11544]100    // XML Port for Level construction.
101    void StoryModeHUD::XMLPort(Element& xmlelement, XMLPort::Mode mode)
[11527]102    {
[11544]103        SUPER(StoryModeHUD, XMLPort, xmlelement, mode);
[11527]104
[11544]105        XMLPortParam(StoryModeHUD, "font", setFont, getFont, xmlelement, mode);
106        XMLPortParam(StoryModeHUD, "textSize", setTextSize, getTextSize, xmlelement, mode);
[11527]107    }
[11544]108
109    // Set the Font size of the Text.
110    void StoryModeHUD::setFont(const std::string& font)
[11527]111    {
112        const Ogre::ResourcePtr& fontPtr = Ogre::FontManager::getSingleton().getByName(font);
113        if (fontPtr.isNull())
114        {
[11544]115            orxout(internal_warning) << "StoryModeHUD: Font '" << font << "' not found" << endl;
[11527]116            return;
117        }
118        this->fontName_ = font;
[11560]119        if(text_ != nullptr)
120            text_->setFontName(this->fontName_);
[11527]121    }
[11544]122   
123    // Gets the Font of the Text   
124    const std::string& StoryModeHUD::getFont() const
[11527]125    {
126        return this->fontName_;
127    }
128
[11544]129    // Set the size of the Text
130    void StoryModeHUD::setTextSize(float size)
[11527]131    {
132        if (size <= 0.0f)
133        {
[11544]134            orxout(internal_warning) << "StoryModeHUD: Negative font size not allowed" << endl;
[11527]135            return;
136        }
137        this->textSize_ = size;
[11560]138       
[11527]139    }
140
[11544]141    // returns the Size of the Text
142    float StoryModeHUD::getTextSize() const
[11527]143    {
144        return this->textSize_;
145    }
146
[11544]147    // Tick: this is the most important function. It's recalled every frame and makes sure things happen on the screen.
148    void StoryModeHUD::tick(float dt)
[11527]149    {
[11544]150        SUPER(StoryModeHUD, tick, dt);
[11527]151
[11544]152        // cam is the pointer which represents your camera
[11527]153        Camera* cam = CameraManager::getInstance().getActiveCamera();
154        if (cam == nullptr)
[11544]155            return;
156
157        // camTransform is a Matrix, which converts 3D world of the game into 2D on your screen
[11527]158        const Matrix4& camTransform = cam->getOgreCamera()->getProjectionMatrix() * cam->getOgreCamera()->getViewMatrix();
159
160
[11560]161        //display name next to cursor
162        //TODO: Planet.getName()
[11564]163        text_->setCaption("Hello Muthafuckin' World!");
[11527]164
[11560]165        // Transform to screen coordinates
166        Vector3 pos = camTransform * Vector3(0,0,0); // planet->getRVWorldPosition();
167
168        // If you fly passed the description, it gets out of sight
169        if (pos.z > 1.0)
170            return;
[11544]171       
[11560]172        // Position text
173        text_->setLeft((pos.x+1)/2); // The (0,0) Coordinate is in the upper left corner.
174        text_->setTop((-pos.y+1)/2);  // With those two calculations we set the desired positions
[11527]175
[11560]176        // Make sure the overlays are shown
177        text_->show();
[11527]178
179    }
180
[11560]181    //void StoryModeHUD::addObject()
[11527]182
[11560]183    /*void StoryModeHUD::removeObject(RadarViewable* viewable)
[11527]184    {
[11544]185        Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second.text_);
[11560]186    }*/
[11544]187}
Note: See TracBrowser for help on using the repository browser.