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 | #include <OgreFontManager.h> |
---|
39 | #include <OgreOverlayManager.h> |
---|
40 | #include <OgreTextAreaOverlayElement.h> |
---|
41 | #include <OgrePanelOverlayElement.h> |
---|
42 | |
---|
43 | // Other stuff |
---|
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 | |
---|
62 | namespace orxonox |
---|
63 | { |
---|
64 | RegisterClass ( StoryModeHUD ); |
---|
65 | |
---|
66 | // Constructor of the StoryMode HUD |
---|
67 | StoryModeHUD::StoryModeHUD(Context* context) : OrxonoxOverlay(context) |
---|
68 | { |
---|
69 | RegisterObject(StoryModeHUD); |
---|
70 | |
---|
71 | // Set default values |
---|
72 | this->setFont("Monofur"); |
---|
73 | this->setTextSize(0.5f); |
---|
74 | } |
---|
75 | |
---|
76 | // TODO: |
---|
77 | // Destructor of the StoryMode HUD |
---|
78 | StoryModeHUD::~StoryModeHUD() |
---|
79 | { |
---|
80 | |
---|
81 | } |
---|
82 | |
---|
83 | // Functions of the StoryMode HUD |
---|
84 | |
---|
85 | // XML Port for Level construction. |
---|
86 | void StoryModeHUD::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
87 | { |
---|
88 | SUPER(StoryModeHUD, XMLPort, xmlelement, mode); |
---|
89 | |
---|
90 | XMLPortParam(StoryModeHUD, "font", setFont, getFont, xmlelement, mode); |
---|
91 | XMLPortParam(StoryModeHUD, "textSize", setTextSize, getTextSize, xmlelement, mode); |
---|
92 | } |
---|
93 | |
---|
94 | // Set the Font size of the Text. |
---|
95 | void StoryModeHUD::setFont(const std::string& font) |
---|
96 | { |
---|
97 | const Ogre::ResourcePtr& fontPtr = Ogre::FontManager::getSingleton().getByName(font); |
---|
98 | if (fontPtr.isNull()) |
---|
99 | { |
---|
100 | orxout(internal_warning) << "StoryModeHUD: Font '" << font << "' not found" << endl; |
---|
101 | return; |
---|
102 | } |
---|
103 | this->fontName_ = font; |
---|
104 | for (const auto& mapEntry : this->activeObjectList_) |
---|
105 | { |
---|
106 | if (mapEntry.second.text_ != nullptr) |
---|
107 | mapEntry.second.text_->setFontName(this->fontName_); |
---|
108 | } |
---|
109 | } |
---|
110 | |
---|
111 | // Gets the Font of the Text |
---|
112 | const std::string& StoryModeHUD::getFont() const |
---|
113 | { |
---|
114 | return this->fontName_; |
---|
115 | } |
---|
116 | |
---|
117 | // Set the size of the Text |
---|
118 | void StoryModeHUD::setTextSize(float size) |
---|
119 | { |
---|
120 | if (size <= 0.0f) |
---|
121 | { |
---|
122 | orxout(internal_warning) << "StoryModeHUD: Negative font size not allowed" << endl; |
---|
123 | return; |
---|
124 | } |
---|
125 | this->textSize_ = size; |
---|
126 | for (const auto& mapEntry : this->activeObjectList_) |
---|
127 | { |
---|
128 | if (mapEntry.second.text_) |
---|
129 | mapEntry.second.text_->setCharHeight(size); |
---|
130 | } |
---|
131 | } |
---|
132 | |
---|
133 | // returns the Size of the Text |
---|
134 | float StoryModeHUD::getTextSize() const |
---|
135 | { |
---|
136 | return this->textSize_; |
---|
137 | } |
---|
138 | |
---|
139 | // Tick: this is the most important function. It's recalled every frame and makes sure things happen on the screen. |
---|
140 | void StoryModeHUD::tick(float dt) |
---|
141 | { |
---|
142 | SUPER(StoryModeHUD, tick, dt); |
---|
143 | |
---|
144 | // cam is the pointer which represents your camera |
---|
145 | Camera* cam = CameraManager::getInstance().getActiveCamera(); |
---|
146 | if (cam == nullptr) |
---|
147 | return; |
---|
148 | |
---|
149 | // camTransform is a Matrix, which converts 3D world of the game into 2D on your screen |
---|
150 | const Matrix4& camTransform = cam->getOgreCamera()->getProjectionMatrix() * cam->getOgreCamera()->getViewMatrix(); |
---|
151 | |
---|
152 | |
---|
153 | //display name next to cursor |
---|
154 | //TODO: Planet.getName() |
---|
155 | text_->setCaption("Hello Muthafuckin' World!"); |
---|
156 | |
---|
157 | // Transform to screen coordinates |
---|
158 | Vector3 pos = camTransform * planet->getRVWorldPosition(); |
---|
159 | |
---|
160 | // Position text |
---|
161 | text_->setLeft((pos.x + 1.0f + it->second.panel_->getWidth()) * 0.5f); |
---|
162 | it->second.text_->setTop((-pos.y + 1.0f + it->second.panel_->getHeight()) * 0.5f); |
---|
163 | |
---|
164 | // Make sure the overlays are shown |
---|
165 | it->second.text_->show(); |
---|
166 | |
---|
167 | } |
---|
168 | |
---|
169 | void StoryModeHUD::addObject() |
---|
170 | { |
---|
171 | // Scales used for dimensions and text size |
---|
172 | float xScale = this->getActualSize().x; |
---|
173 | float yScale = this->getActualSize().y; |
---|
174 | |
---|
175 | // Create text |
---|
176 | Ogre::TextAreaOverlayElement* text = static_cast<Ogre::TextAreaOverlayElement*>( Ogre::OverlayManager::getSingleton() |
---|
177 | .createOverlayElement("TextArea", "StoryModeHUD_navText_" + getUniqueNumberString())); |
---|
178 | text->setFontName(this->fontName_); |
---|
179 | text->setCharHeight(this->textSize_ * yScale); |
---|
180 | text->setColour(object->getRadarObjectColour()); |
---|
181 | |
---|
182 | text->hide(); |
---|
183 | |
---|
184 | this->background_->addChild(text); |
---|
185 | } |
---|
186 | |
---|
187 | void StoryModeHUD::removeObject(RadarViewable* viewable) |
---|
188 | { |
---|
189 | Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second.text_); |
---|
190 | } |
---|
191 | } |
---|