Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 11544


Ignore:
Timestamp:
Nov 6, 2017, 4:35:06 PM (6 years ago)
Author:
fanconic
Message:

Story Mode Hud was edited, and a level file was added

Location:
code/branches/CampaignMap_HS17
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/CampaignMap_HS17/data/levels/emptyLevel.oxw

    r11526 r11544  
    88<?lua
    99  include("stats.oxo")
    10   include("StoryModeHUD2.oxo")
     10  include("HUDTemplates3.oxo")
    1111  include("templates/lodInformation.oxt")
    1212?>
     
    2727    skybox       = "Orxonox/Starbox"
    2828  >
     29
     30
     31  <SpawnPoint position="0,-100,0" lookat="0,0,0" roll=180 spawnclass=SpaceShip pawndesign=spaceshipassff />
     32
    2933
    3034  <StaticEntity position="0,0,0" direction="0,0,0" >
     
    6771    <SpawnPoint team=0 position="-200,0,0" lookat="0,0,0" spawnclass=SpaceShip pawndesign=spaceshipescort />
    6872
     73</MovableEntity>
     74
    6975   
    7076  </Scene>
  • code/branches/CampaignMap_HS17/data/overlays/StoryModeHUD2.oxo

    r11527 r11544  
    3131    <Map />
    3232
     33    <!--
    3334    <HUDNavigation
    3435     name          = "Navigation"
     
    3839     navMarkerSize = 0.00
    3940     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
    4050    />
    4151
  • code/branches/CampaignMap_HS17/src/modules/overlays/hud/StoryModeHUD.cc

    r11527 r11544  
    2020 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    2121 *
     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 *
    2226 *   Author:
    23  *      Felix Schulthess
     27 *      Nikola Bolt
    2428 *   Co-authors:
    25  *      Reto Grieder
    26  *      Oliver Scheuss
    27  *      Matthias Spalinger
    28  *
     29 *      Claudio Fanconi
    2930 */
    3031
    31 #include "HUDNavigation.h"
    3232
     33// Header file of this cc file
     34#include "StoryModeHUD.h"
     35
     36// Ogre stuff
    3337#include <OgreCamera.h>
    3438#include <OgreFontManager.h>
     
    3741#include <OgrePanelOverlayElement.h>
    3842
     43// Other stuff
    3944#include <typeinfo>
    4045
     
    5762namespace orxonox
    5863{
     64    RegisterClass ( StoryModeHUD );
    5965
    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)
    6568    {
    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 
    7871        // Set default values
    7972        this->setFont("Monofur");
    8073        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;
    8874    }
    8975
    90     HUDNavigation::~HUDNavigation()
     76    // TODO:
     77    // Destructor of the StoryMode HUD
     78    StoryModeHUD::~StoryModeHUD()
    9179    {
    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
    9881    }
    9982
    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)
    10187    {
    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);
    10492    }
    10593
    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)
    11596    {
    11697        const Ogre::ResourcePtr& fontPtr = Ogre::FontManager::getSingleton().getByName(font);
    11798        if (fontPtr.isNull())
    11899        {
    119             orxout(internal_warning) << "HUDNavigation: Font '" << font << "' not found" << endl;
     100            orxout(internal_warning) << "StoryModeHUD: Font '" << font << "' not found" << endl;
    120101            return;
    121102        }
     
    127108        }
    128109    }
    129 
    130     const std::string& HUDNavigation::getFont() const
     110   
     111    // Gets the Font of the Text   
     112    const std::string& StoryModeHUD::getFont() const
    131113    {
    132114        return this->fontName_;
    133115    }
    134116
    135     void HUDNavigation::setTextSize(float size)
     117    // Set the size of the Text
     118    void StoryModeHUD::setTextSize(float size)
    136119    {
    137120        if (size <= 0.0f)
    138121        {
    139             orxout(internal_warning) << "HUDNavigation: Negative font size not allowed" << endl;
     122            orxout(internal_warning) << "StoryModeHUD: Negative font size not allowed" << endl;
    140123            return;
    141124        }
     
    148131    }
    149132
    150     float HUDNavigation::getTextSize() const
     133    // returns the Size of the Text
     134    float StoryModeHUD::getTextSize() const
    151135    {
    152136        return this->textSize_;
    153137    }
    154138
    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)
    156141    {
    157         SUPER(HUDNavigation, tick, dt);
     142        SUPER(StoryModeHUD, tick, dt);
    158143
     144        // cam is the pointer which represents your camera
    159145        Camera* cam = CameraManager::getInstance().getActiveCamera();
    160146        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
    162150        const Matrix4& camTransform = cam->getOgreCamera()->getProjectionMatrix() * cam->getOgreCamera()->getViewMatrix();
    163151
    164         for (std::pair<RadarViewable*, unsigned int>& pair : this->sortedObjectList_)
    165         pair.second = (int)((pair.first->getRVWorldPosition() - HumanController::getLocalControllerSingleton()->getControllableEntity()->getWorldPosition()).length() + 0.5f);
    166152
    167         this->sortedObjectList_.sort(compareDistance);
     153                    //display name next to cursor
     154                    //TODO: Planet.getName()
     155                    text_->setCaption("Hello Muthafuckin' World!");
    168156
    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       
    227160                    // 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);
    229162                    it->second.text_->setTop((-pos.y + 1.0f + it->second.panel_->getHeight()) * 0.5f);
    230163
    231164                    // Make sure the overlays are shown
    232                     it->second.panel_->show();
    233165                    it->second.text_->show();
    234166
    235                     // Target marker
    236                     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() == 0
    240                             || pawn == nullptr
    241                             /* TODO : improve getTeam in such a way that it works
    242                              * || humanPawn == nullptr
    243                              * || pawn->getTeam() == humanPawn->getTeam()*/)
    244                     {
    245                         // don't show marker for not selected enemies nor if the selected doesn't move
    246                         it->second.target_->hide();
    247                     }
    248                     else // object is selected and moves
    249                     {
    250                         // get the aim position
    251                         const Vector3& targetPos = this->toAimPosition(it->first);
    252                         // Transform to screen coordinates
    253                         Vector3 screenPos = camTransform * targetPos;
    254                         // Check if the target marker is in view too
    255                         if(screenPos.z > 1 || screenPos.x < -1.0 || screenPos.x > 1.0
    256                                 || screenPos.y < -1.0 || screenPos.y > 1.0)
    257                         {
    258                             it->second.target_->hide();
    259                         }
    260                         else
    261                         {
    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;
    274167    }
    275168
    276     void HUDNavigation::addObject(RadarViewable* object)
     169    void StoryModeHUD::addObject()
    277170    {
    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 
    288171        // Scales used for dimensions and text size
    289172        float xScale = this->getActualSize().x;
    290173        float yScale = this->getActualSize().y;
    291174
    292         // Create everything needed to display the object on the radar and add it to the map
    293 
    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 
    300175        // Create text
    301176        Ogre::TextAreaOverlayElement* text = static_cast<Ogre::TextAreaOverlayElement*>( Ogre::OverlayManager::getSingleton()
    302                 .createOverlayElement("TextArea", "HUDNavigation_navText_" + getUniqueNumberString()));
     177                .createOverlayElement("TextArea", "StoryModeHUD_navText_" + getUniqueNumberString()));
    303178        text->setFontName(this->fontName_);
    304179        text->setCharHeight(this->textSize_ * yScale);
     
    306181
    307182        text->hide();
    308 
    309         ObjectInfo tempStruct =
    310         {   health, healthLevel, panel, target, text, false, false, false};
    311         this->activeObjectList_[object] = tempStruct;
    312183       
    313184        this->background_->addChild(text);
    314 
    315         this->sortedObjectList_.push_front(std::make_pair(object, (unsigned int)0));
    316185    }
    317186
    318     void HUDNavigation::removeObject(RadarViewable* viewable)
     187    void StoryModeHUD::removeObject(RadarViewable* viewable)
    319188    {
    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_);
    339190    }
    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  
    2828 */
    2929
    30 #ifndef _HUDNavigation_H__
    31 #define _HUDNavigation_H__
     30#ifndef _StoryModeHUD_H__
     31#define _StoryModeHUD_H__
    3232
    3333#include "overlays/OverlaysPrereqs.h"
     
    3838#include "util/OgreForwardRefs.h"
    3939#include "tools/interfaces/Tickable.h"
    40 #include "interfaces/RadarListener.h"
    4140#include "overlays/OrxonoxOverlay.h"
    4241
    4342namespace orxonox
    4443{
    45     class _OverlaysExport StoryModeHUD : public OrxonoxOverlay, public Tickable, public RadarListener
     44    class _OverlaysExport StoryModeHUD : public OrxonoxOverlay, public Tickable
    4645    {
    4746    public:
    48             HUDNavigation(Context* context);
    49             virtual ~HUDNavigation();
    50 
    51             void setConfigValues();
     47            StoryModeHUD(Context* context);
     48            virtual ~StoryModeHUD();
    5249
    5350            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override;
    5451            virtual void tick(float dt) override;
    5552
    56             // RadarListener interface
    57             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 override
    68                 { return 1.0f; }
    69 
    70             inline unsigned int getMarkerLimit() const
    71                 { return this->markerLimit_; }
    72 
    73             static void selectClosestTarget();
    74             static void selectNextTarget();
    7553
    7654        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     
    13157            void setTextSize(float size);
    13258            float getTextSize() const;
     
    13561            const std::string& getFont() const;
    13662
    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   
    14964            std::string fontName_;
    15065            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   
    16567    };
    16668}
    16769
    168 #endif /* _HUDNavigation_H__ */
     70#endif /* _StoryModeHUD_H__ */
Note: See TracChangeset for help on using the changeset viewer.