Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/cegui0.8_ogre1.9/src/modules/overlays/hud/StoryModeHUD.cc @ 12125

Last change on this file since 12125 was 11796, checked in by landauf, 7 years ago

fixed build

  • Property svn:eol-style set to native
File size: 6.5 KB
Line 
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 *   
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 *
26 *   Author:
27 *      Nikola Bolt
28 *   Co-authors:
29 *      Claudio Fanconi
30 */
31
32
33// Header file of this cc file
34#include "StoryModeHUD.h"
35
36// Ogre stuff
37#include <OgreCamera.h>
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
49
50// Other stuff
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"
63#include "controllers/NewHumanController.h"
64
65#include "worldentities/NameableStaticEntity.h"
66
67namespace orxonox
68{
69    RegisterClass ( StoryModeHUD );
70
71    // Constructor of the StoryMode HUD
72    StoryModeHUD::StoryModeHUD(Context* context) : OrxonoxOverlay(context)
73    {
74        RegisterObject(StoryModeHUD);
75
76        this->textSize_ = 1.0;
77    }
78
79    // Destructor of the StoryMode HUD
80    StoryModeHUD::~StoryModeHUD()
81    {
82        for(Ogre::TextAreaOverlayElement* text : texts)
83            Ogre::OverlayManager::getSingleton().destroyOverlayElement(text);
84    }
85
86    // Functions of the StoryMode HUD
87
88    // XML Port for Level construction.
89    void StoryModeHUD::XMLPort(Element& xmlelement, XMLPort::Mode mode)
90    {
91        SUPER(StoryModeHUD, XMLPort, xmlelement, mode);
92
93        XMLPortParam(StoryModeHUD, "font", setFont, getFont, xmlelement, mode);
94        XMLPortParam(StoryModeHUD, "textSize", setTextSize, getTextSize, xmlelement, mode);
95    }
96
97    void StoryModeHUD::initialize(){
98        firstTick = false;
99        // Scales used for dimensions and text size
100        float xScale = this->getActualSize().x;
101        float yScale = this->getActualSize().y;
102
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
106        for(NameableStaticEntity* planet : ObjectList<NameableStaticEntity>()){
107
108
109            Ogre::TextAreaOverlayElement* text = static_cast<Ogre::TextAreaOverlayElement*>( Ogre::OverlayManager::getSingleton()
110                    .createOverlayElement("TextArea", "StoryModeHUD_navText_" + getUniqueNumberString()));
111
112            texts.push_back(text);
113            text->setDimensions(xScale, yScale);
114
115            //font name of the text needs to be set here, not in the xml setter function
116            text->setFontName(this->fontName_);
117            text->setCharHeight(this->textSize_ * yScale);
118
119            //set text
120            text->setCaption(planet->getLevelName());
121
122            text->hide();
123       
124            this->background_->addChild(text);
125        }
126    }
127
128    // Set the Font of this HUD.
129    void StoryModeHUD::setFont(const std::string& font)
130    {
131        const Ogre::ResourcePtr& fontPtr = Ogre::FontManager::getSingleton().getByName(font);
132        if (fontPtr.isNull())
133        {
134            this->fontName_ = "Monofur";
135            orxout(internal_warning) << "StoryModeHUD: Font '" << font << "' not found. Font has been set to Monofur." << endl;
136            return;
137        }
138        this->fontName_ = font;
139    }
140   
141    // Gets the Font of this HUD   
142    const std::string& StoryModeHUD::getFont() const
143    {
144        return this->fontName_;
145    }
146
147    // Set the size of the Text
148    void StoryModeHUD::setTextSize(float size)
149    {
150        if (size <= 0.0f)
151        {
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;
154            return;
155        }
156        this->textSize_ = size;
157       
158    }
159
160    // returns the Size of the Text
161    float StoryModeHUD::getTextSize() const
162    {
163        return this->textSize_;
164    }
165
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)
168    {
169        SUPER(StoryModeHUD, tick, dt);
170
171        if(firstTick)
172            this->initialize();
173
174        // cam is the pointer which represents your camera
175        Camera* cam = CameraManager::getInstance().getActiveCamera();
176        if (cam == nullptr)
177            return;
178
179        // camTransform is a Matrix, which converts 3D world of the game into 2D on your screen
180        const Matrix4& camTransform = cam->getOgreCamera()->getProjectionMatrix() * cam->getOgreCamera()->getViewMatrix();
181
182        size_t i = 0;
183        for(NameableStaticEntity* planet : ObjectList<NameableStaticEntity>()){
184            if (i >= texts.size()) {
185                break;
186            }
187            Ogre::TextAreaOverlayElement* text = texts[i];
188            i++;
189
190            // Transform to screen coordinates
191            Vector3 pos = camTransform * planet->getWorldPosition();
192
193            // If you fly passed the description, it gets out of sight
194            if (!(pos.z > 1.0)){
195                   
196                // Position text
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
199
200                // Make sure the overlays are shown
201                text->show();
202            }
203        }
204    }
205}
Note: See TracBrowser for help on using the repository browser.