Changeset 11544 for code/branches
- Timestamp:
- Nov 6, 2017, 4:35:06 PM (7 years ago)
- Location:
- code/branches/CampaignMap_HS17
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/CampaignMap_HS17/data/levels/emptyLevel.oxw
r11526 r11544 8 8 <?lua 9 9 include("stats.oxo") 10 include(" StoryModeHUD2.oxo")10 include("HUDTemplates3.oxo") 11 11 include("templates/lodInformation.oxt") 12 12 ?> … … 27 27 skybox = "Orxonox/Starbox" 28 28 > 29 30 31 <SpawnPoint position="0,-100,0" lookat="0,0,0" roll=180 spawnclass=SpaceShip pawndesign=spaceshipassff /> 32 29 33 30 34 <StaticEntity position="0,0,0" direction="0,0,0" > … … 67 71 <SpawnPoint team=0 position="-200,0,0" lookat="0,0,0" spawnclass=SpaceShip pawndesign=spaceshipescort /> 68 72 73 </MovableEntity> 74 69 75 70 76 </Scene> -
code/branches/CampaignMap_HS17/data/overlays/StoryModeHUD2.oxo
r11527 r11544 31 31 <Map /> 32 32 33 <!-- 33 34 <HUDNavigation 34 35 name = "Navigation" … … 38 39 navMarkerSize = 0.00 39 40 aimMarkerSize = 0.00 41 /> 42 --> 43 44 <!-- This is the storymode HUD we implemented, to give names to planet objects, rather than using the HUDnavigation--> 45 <StoryModeHUD 46 name = "StoryMode" 47 correctaspect = true 48 font = "Verdana" 49 textSize = 0.05 40 50 /> 41 51 -
code/branches/CampaignMap_HS17/src/modules/overlays/hud/StoryModeHUD.cc
r11527 r11544 20 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 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 * 22 26 * Author: 23 * Felix Schulthess27 * Nikola Bolt 24 28 * Co-authors: 25 * Reto Grieder 26 * Oliver Scheuss 27 * Matthias Spalinger 28 * 29 * Claudio Fanconi 29 30 */ 30 31 31 #include "HUDNavigation.h"32 32 33 // Header file of this cc file 34 #include "StoryModeHUD.h" 35 36 // Ogre stuff 33 37 #include <OgreCamera.h> 34 38 #include <OgreFontManager.h> … … 37 41 #include <OgrePanelOverlayElement.h> 38 42 43 // Other stuff 39 44 #include <typeinfo> 40 45 … … 57 62 namespace orxonox 58 63 { 64 RegisterClass ( StoryModeHUD ); 59 65 60 SetConsoleCommand("HUDNavigation","selectClosest", &HUDNavigation::selectClosestTarget).addShortcut().keybindMode(KeybindMode::OnPress); 61 SetConsoleCommand("HUDNavigation","selectNext", &HUDNavigation::selectNextTarget).addShortcut().keybindMode(KeybindMode::OnPress); 62 63 static bool compareDistance(std::pair<RadarViewable*, unsigned int> a, 64 std::pair<RadarViewable*, unsigned int> b) 66 // Constructor of the StoryMode HUD 67 StoryModeHUD::StoryModeHUD(Context* context) : OrxonoxOverlay(context) 65 68 { 66 return a.second < b.second; 67 } 68 RegisterClass ( HUDNavigation ); 69 70 HUDNavigation* HUDNavigation::localHUD_s = nullptr; 71 72 HUDNavigation::HUDNavigation(Context* context) : 73 OrxonoxOverlay(context) 74 { 75 RegisterObject(HUDNavigation); 76 this->setConfigValues(); 77 69 RegisterObject(StoryModeHUD); 70 78 71 // Set default values 79 72 this->setFont("Monofur"); 80 73 this->setTextSize(0.5f); 81 82 this->setDetectionLimit(10000.0f);83 this->currentMunitionSpeed_ = 750.0f;84 85 this->closestTarget_ = true;86 this->nextTarget_ = false;87 HUDNavigation::localHUD_s = this;88 74 } 89 75 90 HUDNavigation::~HUDNavigation() 76 // TODO: 77 // Destructor of the StoryMode HUD 78 StoryModeHUD::~StoryModeHUD() 91 79 { 92 if (this->isInitialized()) 93 { 94 for (std::map<RadarViewable*, ObjectInfo>::iterator it = this->activeObjectList_.begin(); it != this->activeObjectList_.end();) 95 removeObject((it++)->first); 96 } 97 this->sortedObjectList_.clear(); 80 98 81 } 99 82 100 void HUDNavigation::setConfigValues() 83 // Functions of the StoryMode HUD 84 85 // XML Port for Level construction. 86 void StoryModeHUD::XMLPort(Element& xmlelement, XMLPort::Mode mode) 101 87 { 102 SetConfigValue(markerLimit_, 100); 103 SetConfigValue(showDistance_, false); 88 SUPER(StoryModeHUD, XMLPort, xmlelement, mode); 89 90 XMLPortParam(StoryModeHUD, "font", setFont, getFont, xmlelement, mode); 91 XMLPortParam(StoryModeHUD, "textSize", setTextSize, getTextSize, xmlelement, mode); 104 92 } 105 93 106 107 void HUDNavigation::XMLPort(Element& xmlelement, XMLPort::Mode mode) 108 { 109 SUPER(HUDNavigation, XMLPort, xmlelement, mode); 110 111 XMLPortParam(HUDNavigation, "font", setFont, getFont, xmlelement, mode); 112 XMLPortParam(HUDNavigation, "textSize", setTextSize, getTextSize, xmlelement, mode); 113 } 114 void HUDNavigation::setFont(const std::string& font) 94 // Set the Font size of the Text. 95 void StoryModeHUD::setFont(const std::string& font) 115 96 { 116 97 const Ogre::ResourcePtr& fontPtr = Ogre::FontManager::getSingleton().getByName(font); 117 98 if (fontPtr.isNull()) 118 99 { 119 orxout(internal_warning) << " HUDNavigation: Font '" << font << "' not found" << endl;100 orxout(internal_warning) << "StoryModeHUD: Font '" << font << "' not found" << endl; 120 101 return; 121 102 } … … 127 108 } 128 109 } 129 130 const std::string& HUDNavigation::getFont() const 110 111 // Gets the Font of the Text 112 const std::string& StoryModeHUD::getFont() const 131 113 { 132 114 return this->fontName_; 133 115 } 134 116 135 void HUDNavigation::setTextSize(float size) 117 // Set the size of the Text 118 void StoryModeHUD::setTextSize(float size) 136 119 { 137 120 if (size <= 0.0f) 138 121 { 139 orxout(internal_warning) << " HUDNavigation: Negative font size not allowed" << endl;122 orxout(internal_warning) << "StoryModeHUD: Negative font size not allowed" << endl; 140 123 return; 141 124 } … … 148 131 } 149 132 150 float HUDNavigation::getTextSize() const 133 // returns the Size of the Text 134 float StoryModeHUD::getTextSize() const 151 135 { 152 136 return this->textSize_; 153 137 } 154 138 155 void HUDNavigation::tick(float dt) 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) 156 141 { 157 SUPER( HUDNavigation, tick, dt);142 SUPER(StoryModeHUD, tick, dt); 158 143 144 // cam is the pointer which represents your camera 159 145 Camera* cam = CameraManager::getInstance().getActiveCamera(); 160 146 if (cam == nullptr) 161 return; 147 return; 148 149 // camTransform is a Matrix, which converts 3D world of the game into 2D on your screen 162 150 const Matrix4& camTransform = cam->getOgreCamera()->getProjectionMatrix() * cam->getOgreCamera()->getViewMatrix(); 163 151 164 for (std::pair<RadarViewable*, unsigned int>& pair : this->sortedObjectList_)165 pair.second = (int)((pair.first->getRVWorldPosition() - HumanController::getLocalControllerSingleton()->getControllableEntity()->getWorldPosition()).length() + 0.5f);166 152 167 this->sortedObjectList_.sort(compareDistance); 153 //display name next to cursor 154 //TODO: Planet.getName() 155 text_->setCaption("Hello Muthafuckin' World!"); 168 156 169 unsigned int markerCount = 0; 170 bool closeEnough = false; // only display objects that are close enough to be relevant for the player 171 172 // if the selected object doesn't exist any more or is now out of range select the closest object 173 std::map<RadarViewable*, ObjectInfo>::iterator selectedActiveObject = this->activeObjectList_.find(this->selectedTarget_); 174 if(selectedActiveObject == this->activeObjectList_.end()) 175 { 176 this->closestTarget_ = true; 177 } 178 else if(this->detectionLimit_ < (this->selectedTarget_->getRVWorldPosition() - HumanController::getLocalControllerSingleton()->getControllableEntity()->getWorldPosition()).length() + 0.5f) 179 { 180 this->closestTarget_ = true; 181 selectedActiveObject->second.selected_ = false; 182 } 183 184 bool nextHasToBeSelected = false; 185 186 for (std::list<std::pair<RadarViewable*, unsigned int>>::iterator listIt = this->sortedObjectList_.begin(); listIt != this->sortedObjectList_.end(); ++markerCount, ++listIt) 187 { 188 189 std::map<RadarViewable*, ObjectInfo>::iterator it = this->activeObjectList_.find(listIt->first); 190 closeEnough = listIt->second < this->detectionLimit_; 191 // display radarviewables on HUD if the marker limit and max-distance is not exceeded 192 if (markerCount < this->markerLimit_ && (closeEnough || this->detectionLimit_ < 0)) 193 { 194 float textLength = 0.0f; 195 196 { 197 //display name next to cursor 198 it->second.text_->setCaption(it->first->getRadarName()); 199 textLength = it->first->getRadarName().size() * it->second.text_->getCharHeight() * 0.3f; 200 } 201 202 203 204 205 206 207 // Transform to screen coordinates 208 Vector3 pos = camTransform * it->first->getRVWorldPosition(); 209 { 210 // Object is in view 211 212 // Change material only if outOfView changed 213 if (it->second.wasOutOfView_) 214 { 215 //it->second.panel_->setMaterialName("Orxonox/NavTDC"); 216 it->second.panel_->setMaterialName(TextureGenerator::getMaterialName("tdc.png", it->first->getRadarObjectColour())); 217 it->second.panel_->setDimensions(this->navMarkerSize_ * this->getActualSize().x, this->navMarkerSize_ * this->getActualSize().y); 218 it->second.target_->setDimensions(this->aimMarkerSize_ * this->getActualSize().x, this->aimMarkerSize_ * this->getActualSize().y); 219 it->second.wasOutOfView_ = false; 220 } 221 222 // Position marker 223 it->second.panel_->setUV(0.0f, 0.0f, 1.0f, 1.0f); 224 it->second.panel_->setLeft((pos.x + 1.0f - it->second.panel_->getWidth()) * 0.5f); 225 it->second.panel_->setTop((-pos.y + 1.0f - it->second.panel_->getHeight()) * 0.5f); 226 157 // Transform to screen coordinates 158 Vector3 pos = camTransform * planet->getRVWorldPosition(); 159 227 160 // Position text 228 it->second.text_->setLeft((pos.x + 1.0f + it->second.panel_->getWidth()) * 0.5f);161 text_->setLeft((pos.x + 1.0f + it->second.panel_->getWidth()) * 0.5f); 229 162 it->second.text_->setTop((-pos.y + 1.0f + it->second.panel_->getHeight()) * 0.5f); 230 163 231 164 // Make sure the overlays are shown 232 it->second.panel_->show();233 165 it->second.text_->show(); 234 166 235 // Target marker236 const Pawn* pawn = dynamic_cast<const Pawn*>(it->first->getWorldEntity());237 /* Pawn* humanPawn = HumanController::getLocalControllerEntityAsPawn();*/238 if(!it->second.selected_239 || it->first->getRVVelocity().squaredLength() == 0240 || pawn == nullptr241 /* TODO : improve getTeam in such a way that it works242 * || humanPawn == nullptr243 * || pawn->getTeam() == humanPawn->getTeam()*/)244 {245 // don't show marker for not selected enemies nor if the selected doesn't move246 it->second.target_->hide();247 }248 else // object is selected and moves249 {250 // get the aim position251 const Vector3& targetPos = this->toAimPosition(it->first);252 // Transform to screen coordinates253 Vector3 screenPos = camTransform * targetPos;254 // Check if the target marker is in view too255 if(screenPos.z > 1 || screenPos.x < -1.0 || screenPos.x > 1.0256 || screenPos.y < -1.0 || screenPos.y > 1.0)257 {258 it->second.target_->hide();259 }260 else261 {262 it->second.target_->setLeft((screenPos.x + 1.0f - it->second.target_->getWidth()) * 0.5f);263 it->second.target_->setTop((-screenPos.y + 1.0f - it->second.target_->getHeight()) * 0.5f);264 it->second.target_->show();265 }266 }267 268 }269 }270 }271 272 this->closestTarget_ = false;273 this->nextTarget_ = false;274 167 } 275 168 276 void HUDNavigation::addObject(RadarViewable* object)169 void StoryModeHUD::addObject() 277 170 { 278 if (showObject(object) == false)279 return;280 281 if (this->activeObjectList_.size() >= this->markerLimit_)282 if (object == nullptr)283 return;284 285 // Object hasn't been added yet (we know that)286 assert(this->activeObjectList_.find(object) == this->activeObjectList_.end());287 288 171 // Scales used for dimensions and text size 289 172 float xScale = this->getActualSize().x; 290 173 float yScale = this->getActualSize().y; 291 174 292 // Create everything needed to display the object on the radar and add it to the map293 294 295 //panel->setMaterialName("Orxonox/NavTDC");296 panel->setMaterialName(TextureGenerator::getMaterialName("tdc.png", object->getRadarObjectColour()));297 panel->setDimensions(this->navMarkerSize_ * xScale, this->navMarkerSize_ * yScale);298 //panel->setColour(object->getRadarObjectColour());299 300 175 // Create text 301 176 Ogre::TextAreaOverlayElement* text = static_cast<Ogre::TextAreaOverlayElement*>( Ogre::OverlayManager::getSingleton() 302 .createOverlayElement("TextArea", " HUDNavigation_navText_" + getUniqueNumberString()));177 .createOverlayElement("TextArea", "StoryModeHUD_navText_" + getUniqueNumberString())); 303 178 text->setFontName(this->fontName_); 304 179 text->setCharHeight(this->textSize_ * yScale); … … 306 181 307 182 text->hide(); 308 309 ObjectInfo tempStruct =310 { health, healthLevel, panel, target, text, false, false, false};311 this->activeObjectList_[object] = tempStruct;312 183 313 184 this->background_->addChild(text); 314 315 this->sortedObjectList_.push_front(std::make_pair(object, (unsigned int)0));316 185 } 317 186 318 void HUDNavigation::removeObject(RadarViewable* viewable)187 void StoryModeHUD::removeObject(RadarViewable* viewable) 319 188 { 320 std::map<RadarViewable*, ObjectInfo>::iterator it = this->activeObjectList_.find(viewable); 321 322 if (this->activeObjectList_.find(viewable) != this->activeObjectList_.end()) 323 { 324 // Detach overlays 325 this->background_->removeChild(it->second.text_->getName()); 326 Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second.text_); 327 // Remove from the list 328 this->activeObjectList_.erase(viewable); 329 } 330 331 for (std::list<std::pair<RadarViewable*, unsigned int>>::iterator listIt = this->sortedObjectList_.begin(); listIt != this->sortedObjectList_.end(); ++listIt) 332 { 333 if ((listIt->first) == viewable) 334 { 335 this->sortedObjectList_.erase(listIt); 336 break; 337 } 338 } 189 Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second.text_); 339 190 } 340 341 void HUDNavigation::objectChanged(RadarViewable* viewable) 342 { 343 // TODO: niceification neccessary ;) 344 removeObject(viewable); 345 addObject(viewable); 346 } 347 348 bool HUDNavigation::showObject(RadarViewable* rv) 349 { 350 if (rv == orxonox_cast<RadarViewable*>(this->getOwner())) 351 return false; 352 assert(rv->getWorldEntity()); 353 if (rv->getWorldEntity()->isVisible() == false || rv->getRadarVisibility() == false) 354 return false; 355 return true; 356 } 191 } -
code/branches/CampaignMap_HS17/src/modules/overlays/hud/StoryModeHUD.h
r11527 r11544 28 28 */ 29 29 30 #ifndef _ HUDNavigation_H__31 #define _ HUDNavigation_H__30 #ifndef _StoryModeHUD_H__ 31 #define _StoryModeHUD_H__ 32 32 33 33 #include "overlays/OverlaysPrereqs.h" … … 38 38 #include "util/OgreForwardRefs.h" 39 39 #include "tools/interfaces/Tickable.h" 40 #include "interfaces/RadarListener.h"41 40 #include "overlays/OrxonoxOverlay.h" 42 41 43 42 namespace orxonox 44 43 { 45 class _OverlaysExport StoryModeHUD : public OrxonoxOverlay, public Tickable , public RadarListener44 class _OverlaysExport StoryModeHUD : public OrxonoxOverlay, public Tickable 46 45 { 47 46 public: 48 HUDNavigation(Context* context); 49 virtual ~HUDNavigation(); 50 51 void setConfigValues(); 47 StoryModeHUD(Context* context); 48 virtual ~StoryModeHUD(); 52 49 53 50 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override; 54 51 virtual void tick(float dt) override; 55 52 56 // RadarListener interface57 virtual void addObject(RadarViewable* object) override;58 virtual void removeObject(RadarViewable* viewable) override;59 virtual void objectChanged(RadarViewable* viewable) override;60 61 virtual void changedOwner() override;62 virtual void sizeChanged() override;63 virtual void angleChanged() override { }64 virtual void positionChanged() override { }65 virtual void radarTick(float dt) override {}66 67 virtual inline float getRadarSensitivity() const override68 { return 1.0f; }69 70 inline unsigned int getMarkerLimit() const71 { return this->markerLimit_; }72 73 static void selectClosestTarget();74 static void selectNextTarget();75 53 76 54 private: 77 struct ObjectInfo 78 { 79 80 81 82 Ogre::PanelOverlayElement* health_; 83 Ogre::PanelOverlayElement* healthLevel_; 84 Ogre::PanelOverlayElement* panel_; 85 Ogre::PanelOverlayElement* target_; 86 Ogre::TextAreaOverlayElement* text_; 87 bool outOfView_; 88 bool wasOutOfView_; 89 bool selected_; 90 }; 91 92 bool showObject(RadarViewable* rv); 93 94 // XMLPort accessors 95 inline void setHealthMarkerSize(float size) 96 { 97 this->healthMarkerSize_ = size; 98 this->sizeChanged(); 99 } 100 inline float getHealthMarkerSize() const 101 { return healthMarkerSize_; } 102 103 inline void setHealthLevelMarkerSize(float size) 104 { 105 this->healthLevelMarkerSize_ = size; 106 this->sizeChanged(); 107 } 108 inline float getHealthLevelMarkerSize() const 109 { return healthLevelMarkerSize_; } 110 111 inline void setNavMarkerSize(float size) 112 { 113 this->navMarkerSize_ = size; 114 this->sizeChanged(); 115 } 116 inline float getNavMarkerSize() const 117 { return navMarkerSize_; } 118 inline void setAimMarkerSize(float size) 119 { 120 this->aimMarkerSize_ = size; 121 this->sizeChanged(); 122 } 123 124 inline float getAimMarkerSize() const 125 { return aimMarkerSize_; } 126 inline void setDetectionLimit(float limit) 127 { this->detectionLimit_ = limit; } 128 inline float getDetectionLimit() const 129 { return this->detectionLimit_; } 130 55 Ogre::TextAreaOverlayElement* text_; 56 131 57 void setTextSize(float size); 132 58 float getTextSize() const; … … 135 61 const std::string& getFont() const; 136 62 137 float getArrowSizeX(int dist) const; 138 float getArrowSizeY(int dist) const; 139 140 Vector3 toAimPosition(RadarViewable* target) const; 141 142 std::map<RadarViewable*, ObjectInfo> activeObjectList_; 143 std::list<std::pair<RadarViewable*, unsigned int>> sortedObjectList_; 144 145 float healthMarkerSize_; 146 float healthLevelMarkerSize_; 147 float navMarkerSize_; 148 float aimMarkerSize_; 63 149 64 std::string fontName_; 150 65 float textSize_; 151 bool showDistance_; 152 153 RadarViewable* selectedTarget_; 154 155 bool closestTarget_; 156 bool nextTarget_; 157 158 static HUDNavigation* localHUD_s; //!< This is used as a filter. Only the local HUD should be influenced by the static Console Command functions. 159 160 161 float currentMunitionSpeed_; 162 163 unsigned int markerLimit_; 164 float detectionLimit_; //!< Objects that are more far away than detectionLimit_ are not displayed on the HUD. 10000.0f is the default value. 66 165 67 }; 166 68 } 167 69 168 #endif /* _ HUDNavigation_H__ */70 #endif /* _StoryModeHUD_H__ */
Note: See TracChangeset
for help on using the changeset viewer.