[Orxonox-commit 6906] r11527 - in code/branches/CampaignMap_HS17: data/overlays src/modules/overlays/hud
boltn at orxonox.net
boltn at orxonox.net
Mon Oct 30 16:36:26 CET 2017
Author: boltn
Date: 2017-10-30 16:36:26 +0100 (Mon, 30 Oct 2017)
New Revision: 11527
Added:
code/branches/CampaignMap_HS17/data/overlays/StoryModeHUD2.oxo
code/branches/CampaignMap_HS17/src/modules/overlays/hud/StoryModeHUD.cc
code/branches/CampaignMap_HS17/src/modules/overlays/hud/StoryModeHUD.h
Log:
Files fuer den story mode hud ge-added (noch nicht fertig)
Added: code/branches/CampaignMap_HS17/data/overlays/StoryModeHUD2.oxo
===================================================================
--- code/branches/CampaignMap_HS17/data/overlays/StoryModeHUD2.oxo (rev 0)
+++ code/branches/CampaignMap_HS17/data/overlays/StoryModeHUD2.oxo 2017-10-30 15:36:26 UTC (rev 11527)
@@ -0,0 +1,61 @@
+<!--
+<Template name="defaultHUD">
+ <OverlayGroup name = "defaultHUD" scale = "1, 1">
+ <ChatOverlay
+ name = "chat"
+ position = "0.03, 0.5"
+ font = "VeraMono"
+ caption = ""
+ textsize = 0.025
+ />
+
+ <GametypeStatus
+ name = "state"
+ position = "0.5, 0.85"
+ font = "VeraMono"
+ textsize = 0.05
+ colour = "1.0, 1.0, 0.0, 0.8"
+ align = "center"
+ />
+ </OverlayGroup>
+</Template>
+-->
+
+<Template name="spectatorhud">
+ <OverlayGroup name = "spectatorhud" scale = "1, 1">
+ </OverlayGroup>
+</Template>
+
+<Template name="spaceshiphud">
+ <OverlayGroup name = "spaceshiphud" scale = "1, 1">
+ <Map />
+
+ <HUDNavigation
+ name = "Navigation"
+ correctaspect = true
+ font = "Arial"
+ textsize = 0.03
+ navMarkerSize = 0.00
+ aimMarkerSize = 0.00
+ />
+
+ <GUIOverlay
+ name = "QuestGUI"
+ guiname = "QuestGUI"
+ visible = "false"
+ />
+
+ <GUIOverlay
+ name = "PickupInventory"
+ guiname = "PickupInventory"
+ visible = "false"
+ />
+
+ <GUIOverlay
+ name = "Dialogue"
+ guiname = "Dialogue"
+ visible = "false"
+ />
+
+ </OverlayGroup>
+</Template>
Added: code/branches/CampaignMap_HS17/src/modules/overlays/hud/StoryModeHUD.cc
===================================================================
--- code/branches/CampaignMap_HS17/src/modules/overlays/hud/StoryModeHUD.cc (rev 0)
+++ code/branches/CampaignMap_HS17/src/modules/overlays/hud/StoryModeHUD.cc 2017-10-30 15:36:26 UTC (rev 11527)
@@ -0,0 +1,356 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Felix Schulthess
+ * Co-authors:
+ * Reto Grieder
+ * Oliver Scheuss
+ * Matthias Spalinger
+ *
+ */
+
+#include "HUDNavigation.h"
+
+#include <OgreCamera.h>
+#include <OgreFontManager.h>
+#include <OgreOverlayManager.h>
+#include <OgreTextAreaOverlayElement.h>
+#include <OgrePanelOverlayElement.h>
+
+#include <typeinfo>
+
+#include "util/Math.h"
+#include "util/Convert.h"
+#include "core/command/ConsoleCommandIncludes.h"
+#include "core/CoreIncludes.h"
+#include "core/XMLPort.h"
+#include "CameraManager.h"
+#include "Scene.h"
+#include "Radar.h"
+#include "graphics/Camera.h"
+#include "controllers/HumanController.h"
+#include "worldentities/pawns/Pawn.h"
+#include "worldentities/WorldEntity.h"
+#include "core/config/ConfigValueIncludes.h"
+#include "tools/TextureGenerator.h"
+
+
+namespace orxonox
+{
+
+ SetConsoleCommand("HUDNavigation","selectClosest", &HUDNavigation::selectClosestTarget).addShortcut().keybindMode(KeybindMode::OnPress);
+ SetConsoleCommand("HUDNavigation","selectNext", &HUDNavigation::selectNextTarget).addShortcut().keybindMode(KeybindMode::OnPress);
+
+ static bool compareDistance(std::pair<RadarViewable*, unsigned int> a,
+ std::pair<RadarViewable*, unsigned int> b)
+ {
+ return a.second < b.second;
+ }
+ RegisterClass ( HUDNavigation );
+
+ HUDNavigation* HUDNavigation::localHUD_s = nullptr;
+
+ HUDNavigation::HUDNavigation(Context* context) :
+ OrxonoxOverlay(context)
+ {
+ RegisterObject(HUDNavigation);
+ this->setConfigValues();
+
+ // Set default values
+ this->setFont("Monofur");
+ this->setTextSize(0.5f);
+
+ this->setDetectionLimit(10000.0f);
+ this->currentMunitionSpeed_ = 750.0f;
+
+ this->closestTarget_ = true;
+ this->nextTarget_ = false;
+ HUDNavigation::localHUD_s = this;
+ }
+
+ HUDNavigation::~HUDNavigation()
+ {
+ if (this->isInitialized())
+ {
+ for (std::map<RadarViewable*, ObjectInfo>::iterator it = this->activeObjectList_.begin(); it != this->activeObjectList_.end();)
+ removeObject((it++)->first);
+ }
+ this->sortedObjectList_.clear();
+ }
+
+ void HUDNavigation::setConfigValues()
+ {
+ SetConfigValue(markerLimit_, 100);
+ SetConfigValue(showDistance_, false);
+ }
+
+
+ void HUDNavigation::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+ {
+ SUPER(HUDNavigation, XMLPort, xmlelement, mode);
+
+ XMLPortParam(HUDNavigation, "font", setFont, getFont, xmlelement, mode);
+ XMLPortParam(HUDNavigation, "textSize", setTextSize, getTextSize, xmlelement, mode);
+ }
+ void HUDNavigation::setFont(const std::string& font)
+ {
+ const Ogre::ResourcePtr& fontPtr = Ogre::FontManager::getSingleton().getByName(font);
+ if (fontPtr.isNull())
+ {
+ orxout(internal_warning) << "HUDNavigation: Font '" << font << "' not found" << endl;
+ return;
+ }
+ this->fontName_ = font;
+ for (const auto& mapEntry : this->activeObjectList_)
+ {
+ if (mapEntry.second.text_ != nullptr)
+ mapEntry.second.text_->setFontName(this->fontName_);
+ }
+ }
+
+ const std::string& HUDNavigation::getFont() const
+ {
+ return this->fontName_;
+ }
+
+ void HUDNavigation::setTextSize(float size)
+ {
+ if (size <= 0.0f)
+ {
+ orxout(internal_warning) << "HUDNavigation: Negative font size not allowed" << endl;
+ return;
+ }
+ this->textSize_ = size;
+ for (const auto& mapEntry : this->activeObjectList_)
+ {
+ if (mapEntry.second.text_)
+ mapEntry.second.text_->setCharHeight(size);
+ }
+ }
+
+ float HUDNavigation::getTextSize() const
+ {
+ return this->textSize_;
+ }
+
+ void HUDNavigation::tick(float dt)
+ {
+ SUPER(HUDNavigation, tick, dt);
+
+ Camera* cam = CameraManager::getInstance().getActiveCamera();
+ if (cam == nullptr)
+ return;
+ const Matrix4& camTransform = cam->getOgreCamera()->getProjectionMatrix() * cam->getOgreCamera()->getViewMatrix();
+
+ for (std::pair<RadarViewable*, unsigned int>& pair : this->sortedObjectList_)
+ pair.second = (int)((pair.first->getRVWorldPosition() - HumanController::getLocalControllerSingleton()->getControllableEntity()->getWorldPosition()).length() + 0.5f);
+
+ this->sortedObjectList_.sort(compareDistance);
+
+ unsigned int markerCount = 0;
+ bool closeEnough = false; // only display objects that are close enough to be relevant for the player
+
+ // if the selected object doesn't exist any more or is now out of range select the closest object
+ std::map<RadarViewable*, ObjectInfo>::iterator selectedActiveObject = this->activeObjectList_.find(this->selectedTarget_);
+ if(selectedActiveObject == this->activeObjectList_.end())
+ {
+ this->closestTarget_ = true;
+ }
+ else if(this->detectionLimit_ < (this->selectedTarget_->getRVWorldPosition() - HumanController::getLocalControllerSingleton()->getControllableEntity()->getWorldPosition()).length() + 0.5f)
+ {
+ this->closestTarget_ = true;
+ selectedActiveObject->second.selected_ = false;
+ }
+
+ bool nextHasToBeSelected = false;
+
+ for (std::list<std::pair<RadarViewable*, unsigned int>>::iterator listIt = this->sortedObjectList_.begin(); listIt != this->sortedObjectList_.end(); ++markerCount, ++listIt)
+ {
+
+ std::map<RadarViewable*, ObjectInfo>::iterator it = this->activeObjectList_.find(listIt->first);
+ closeEnough = listIt->second < this->detectionLimit_;
+ // display radarviewables on HUD if the marker limit and max-distance is not exceeded
+ if (markerCount < this->markerLimit_ && (closeEnough || this->detectionLimit_ < 0))
+ {
+ float textLength = 0.0f;
+
+ {
+ //display name next to cursor
+ it->second.text_->setCaption(it->first->getRadarName());
+ textLength = it->first->getRadarName().size() * it->second.text_->getCharHeight() * 0.3f;
+ }
+
+
+
+
+
+
+ // Transform to screen coordinates
+ Vector3 pos = camTransform * it->first->getRVWorldPosition();
+ {
+ // Object is in view
+
+ // Change material only if outOfView changed
+ if (it->second.wasOutOfView_)
+ {
+ //it->second.panel_->setMaterialName("Orxonox/NavTDC");
+ it->second.panel_->setMaterialName(TextureGenerator::getMaterialName("tdc.png", it->first->getRadarObjectColour()));
+ it->second.panel_->setDimensions(this->navMarkerSize_ * this->getActualSize().x, this->navMarkerSize_ * this->getActualSize().y);
+ it->second.target_->setDimensions(this->aimMarkerSize_ * this->getActualSize().x, this->aimMarkerSize_ * this->getActualSize().y);
+ it->second.wasOutOfView_ = false;
+ }
+
+ // Position marker
+ it->second.panel_->setUV(0.0f, 0.0f, 1.0f, 1.0f);
+ it->second.panel_->setLeft((pos.x + 1.0f - it->second.panel_->getWidth()) * 0.5f);
+ it->second.panel_->setTop((-pos.y + 1.0f - it->second.panel_->getHeight()) * 0.5f);
+
+ // Position text
+ it->second.text_->setLeft((pos.x + 1.0f + it->second.panel_->getWidth()) * 0.5f);
+ it->second.text_->setTop((-pos.y + 1.0f + it->second.panel_->getHeight()) * 0.5f);
+
+ // Make sure the overlays are shown
+ it->second.panel_->show();
+ it->second.text_->show();
+
+ // Target marker
+ const Pawn* pawn = dynamic_cast<const Pawn*>(it->first->getWorldEntity());
+ /* Pawn* humanPawn = HumanController::getLocalControllerEntityAsPawn();*/
+ if(!it->second.selected_
+ || it->first->getRVVelocity().squaredLength() == 0
+ || pawn == nullptr
+ /* TODO : improve getTeam in such a way that it works
+ * || humanPawn == nullptr
+ * || pawn->getTeam() == humanPawn->getTeam()*/)
+ {
+ // don't show marker for not selected enemies nor if the selected doesn't move
+ it->second.target_->hide();
+ }
+ else // object is selected and moves
+ {
+ // get the aim position
+ const Vector3& targetPos = this->toAimPosition(it->first);
+ // Transform to screen coordinates
+ Vector3 screenPos = camTransform * targetPos;
+ // Check if the target marker is in view too
+ if(screenPos.z > 1 || screenPos.x < -1.0 || screenPos.x > 1.0
+ || screenPos.y < -1.0 || screenPos.y > 1.0)
+ {
+ it->second.target_->hide();
+ }
+ else
+ {
+ it->second.target_->setLeft((screenPos.x + 1.0f - it->second.target_->getWidth()) * 0.5f);
+ it->second.target_->setTop((-screenPos.y + 1.0f - it->second.target_->getHeight()) * 0.5f);
+ it->second.target_->show();
+ }
+ }
+
+ }
+ }
+ }
+
+ this->closestTarget_ = false;
+ this->nextTarget_ = false;
+ }
+
+ void HUDNavigation::addObject(RadarViewable* object)
+ {
+ if (showObject(object) == false)
+ return;
+
+ if (this->activeObjectList_.size() >= this->markerLimit_)
+ if (object == nullptr)
+ return;
+
+ // Object hasn't been added yet (we know that)
+ assert(this->activeObjectList_.find(object) == this->activeObjectList_.end());
+
+ // Scales used for dimensions and text size
+ float xScale = this->getActualSize().x;
+ float yScale = this->getActualSize().y;
+
+ // Create everything needed to display the object on the radar and add it to the map
+
+
+ //panel->setMaterialName("Orxonox/NavTDC");
+ panel->setMaterialName(TextureGenerator::getMaterialName("tdc.png", object->getRadarObjectColour()));
+ panel->setDimensions(this->navMarkerSize_ * xScale, this->navMarkerSize_ * yScale);
+ //panel->setColour(object->getRadarObjectColour());
+
+ // Create text
+ Ogre::TextAreaOverlayElement* text = static_cast<Ogre::TextAreaOverlayElement*>( Ogre::OverlayManager::getSingleton()
+ .createOverlayElement("TextArea", "HUDNavigation_navText_" + getUniqueNumberString()));
+ text->setFontName(this->fontName_);
+ text->setCharHeight(this->textSize_ * yScale);
+ text->setColour(object->getRadarObjectColour());
+
+ text->hide();
+
+ ObjectInfo tempStruct =
+ { health, healthLevel, panel, target, text, false, false, false};
+ this->activeObjectList_[object] = tempStruct;
+
+ this->background_->addChild(text);
+
+ this->sortedObjectList_.push_front(std::make_pair(object, (unsigned int)0));
+ }
+
+ void HUDNavigation::removeObject(RadarViewable* viewable)
+ {
+ std::map<RadarViewable*, ObjectInfo>::iterator it = this->activeObjectList_.find(viewable);
+
+ if (this->activeObjectList_.find(viewable) != this->activeObjectList_.end())
+ {
+ // Detach overlays
+ this->background_->removeChild(it->second.text_->getName());
+ Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second.text_);
+ // Remove from the list
+ this->activeObjectList_.erase(viewable);
+ }
+
+ for (std::list<std::pair<RadarViewable*, unsigned int>>::iterator listIt = this->sortedObjectList_.begin(); listIt != this->sortedObjectList_.end(); ++listIt)
+ {
+ if ((listIt->first) == viewable)
+ {
+ this->sortedObjectList_.erase(listIt);
+ break;
+ }
+ }
+ }
+
+ void HUDNavigation::objectChanged(RadarViewable* viewable)
+ {
+ // TODO: niceification neccessary ;)
+ removeObject(viewable);
+ addObject(viewable);
+ }
+
+ bool HUDNavigation::showObject(RadarViewable* rv)
+ {
+ if (rv == orxonox_cast<RadarViewable*>(this->getOwner()))
+ return false;
+ assert(rv->getWorldEntity());
+ if (rv->getWorldEntity()->isVisible() == false || rv->getRadarVisibility() == false)
+ return false;
+ return true;
+ }
\ No newline at end of file
Added: code/branches/CampaignMap_HS17/src/modules/overlays/hud/StoryModeHUD.h
===================================================================
--- code/branches/CampaignMap_HS17/src/modules/overlays/hud/StoryModeHUD.h (rev 0)
+++ code/branches/CampaignMap_HS17/src/modules/overlays/hud/StoryModeHUD.h 2017-10-30 15:36:26 UTC (rev 11527)
@@ -0,0 +1,168 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. S
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Felix Schulthess
+ * Co-authors:
+ * Reto Grieder
+ * Matthias Spalinger
+ *
+ */
+
+#ifndef _HUDNavigation_H__
+#define _HUDNavigation_H__
+
+#include "overlays/OverlaysPrereqs.h"
+
+#include <map>
+#include <string>
+
+#include "util/OgreForwardRefs.h"
+#include "tools/interfaces/Tickable.h"
+#include "interfaces/RadarListener.h"
+#include "overlays/OrxonoxOverlay.h"
+
+namespace orxonox
+{
+ class _OverlaysExport StoryModeHUD : public OrxonoxOverlay, public Tickable, public RadarListener
+ {
+ public:
+ HUDNavigation(Context* context);
+ virtual ~HUDNavigation();
+
+ void setConfigValues();
+
+ virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override;
+ virtual void tick(float dt) override;
+
+ // RadarListener interface
+ virtual void addObject(RadarViewable* object) override;
+ virtual void removeObject(RadarViewable* viewable) override;
+ virtual void objectChanged(RadarViewable* viewable) override;
+
+ virtual void changedOwner() override;
+ virtual void sizeChanged() override;
+ virtual void angleChanged() override { }
+ virtual void positionChanged() override { }
+ virtual void radarTick(float dt) override {}
+
+ virtual inline float getRadarSensitivity() const override
+ { return 1.0f; }
+
+ inline unsigned int getMarkerLimit() const
+ { return this->markerLimit_; }
+
+ static void selectClosestTarget();
+ static void selectNextTarget();
+
+ private:
+ struct ObjectInfo
+ {
+
+
+
+ Ogre::PanelOverlayElement* health_;
+ Ogre::PanelOverlayElement* healthLevel_;
+ Ogre::PanelOverlayElement* panel_;
+ Ogre::PanelOverlayElement* target_;
+ Ogre::TextAreaOverlayElement* text_;
+ bool outOfView_;
+ bool wasOutOfView_;
+ bool selected_;
+ };
+
+ bool showObject(RadarViewable* rv);
+
+ // XMLPort accessors
+ inline void setHealthMarkerSize(float size)
+ {
+ this->healthMarkerSize_ = size;
+ this->sizeChanged();
+ }
+ inline float getHealthMarkerSize() const
+ { return healthMarkerSize_; }
+
+ inline void setHealthLevelMarkerSize(float size)
+ {
+ this->healthLevelMarkerSize_ = size;
+ this->sizeChanged();
+ }
+ inline float getHealthLevelMarkerSize() const
+ { return healthLevelMarkerSize_; }
+
+ inline void setNavMarkerSize(float size)
+ {
+ this->navMarkerSize_ = size;
+ this->sizeChanged();
+ }
+ inline float getNavMarkerSize() const
+ { return navMarkerSize_; }
+ inline void setAimMarkerSize(float size)
+ {
+ this->aimMarkerSize_ = size;
+ this->sizeChanged();
+ }
+
+ inline float getAimMarkerSize() const
+ { return aimMarkerSize_; }
+ inline void setDetectionLimit(float limit)
+ { this->detectionLimit_ = limit; }
+ inline float getDetectionLimit() const
+ { return this->detectionLimit_; }
+
+ void setTextSize(float size);
+ float getTextSize() const;
+
+ void setFont(const std::string& font);
+ const std::string& getFont() const;
+
+ float getArrowSizeX(int dist) const;
+ float getArrowSizeY(int dist) const;
+
+ Vector3 toAimPosition(RadarViewable* target) const;
+
+ std::map<RadarViewable*, ObjectInfo> activeObjectList_;
+ std::list<std::pair<RadarViewable*, unsigned int>> sortedObjectList_;
+
+ float healthMarkerSize_;
+ float healthLevelMarkerSize_;
+ float navMarkerSize_;
+ float aimMarkerSize_;
+ std::string fontName_;
+ float textSize_;
+ bool showDistance_;
+
+ RadarViewable* selectedTarget_;
+
+ bool closestTarget_;
+ bool nextTarget_;
+
+ static HUDNavigation* localHUD_s; //!< This is used as a filter. Only the local HUD should be influenced by the static Console Command functions.
+
+
+ float currentMunitionSpeed_;
+
+ unsigned int markerLimit_;
+ float detectionLimit_; //!< Objects that are more far away than detectionLimit_ are not displayed on the HUD. 10000.0f is the default value.
+ };
+}
+
+#endif /* _HUDNavigation_H__ */
More information about the Orxonox-commit
mailing list