Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10242


Ignore:
Timestamp:
Feb 1, 2015, 8:58:38 PM (9 years ago)
Author:
landauf
Message:

merged hudHS14

Location:
code/branches/presentationHS14merge
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentationHS14merge

  • code/branches/presentationHS14merge/data/overlays/HUDTemplates3.oxo

    r9939 r10242  
    8282     background        = "Orxonox/HealthBarBackground"
    8383     size              = "0.35, 0.0875"
    84      position          = "1.0 , 0.1 "
     84     position          = "1 ,0.1"
    8585     pickpoint         = "1, 1"
    8686     bartexture        = "healthbar_bar.png"
  • code/branches/presentationHS14merge/src/modules/overlays/hud/HUDNavigation.cc

    r9939 r10242  
    8282        this->setNavMarkerSize(0.03f);
    8383        this->setAimMarkerSize(0.02f);
     84        this->setHealthMarkerSize(0.06f);
     85        this->setHealthLevelMarkerSize(0.06f);
    8486
    8587        this->setDetectionLimit(10000.0f);
     
    116118        XMLPortParam(HUDNavigation, "detectionLimit", setDetectionLimit, getDetectionLimit, xmlelement, mode);
    117119        XMLPortParam(HUDNavigation, "aimMarkerSize", setAimMarkerSize, getAimMarkerSize, xmlelement, mode);
     120        XMLPortParam(HUDNavigation, "healthMarkerSize", setHealthMarkerSize, getHealthMarkerSize, xmlelement, mode);
     121        XMLPortParam(HUDNavigation, "healthLevelMarkerSize", setHealthLevelMarkerSize, getHealthLevelMarkerSize, xmlelement, mode);
     122
    118123    }
    119124
     
    206211        for (std::list<std::pair<RadarViewable*, unsigned int> >::iterator listIt = this->sortedObjectList_.begin(); listIt != this->sortedObjectList_.end(); ++markerCount, ++listIt)
    207212        {
     213
    208214            std::map<RadarViewable*, ObjectInfo>::iterator it = this->activeObjectList_.find(listIt->first);
    209215            closeEnough = listIt->second < this->detectionLimit_;
     
    275281
    276282
     283
     284
    277285                // Transform to screen coordinates
    278286                Vector3 pos = camTransform * it->first->getRVWorldPosition();
     
    298306                    if (!it->second.wasOutOfView_)
    299307                    {
     308                        it->second.health_->hide();
     309                        it->second.healthLevel_->hide();
    300310                        it->second.panel_->setMaterialName(TextureGenerator::getMaterialName("arrows.png", it->first->getRadarObjectColour()));
    301311                        it->second.wasOutOfView_ = true;
     
    357367                    // Object is in view
    358368
     369
     370
     371
     372                    //calculate the health of the actual selected radarViewable (relativHealthScale: while (0) is no health left, (1) is the initial health)
     373                    Pawn* pawnPtr = (Pawn*) (it->first->getWorldEntity());
     374                    float health = pawnPtr->getHealth();
     375                    float initHealth = pawnPtr->getMaxHealth();
     376                    float relativHealthScale = health/initHealth;
     377
     378                    //integer values from 0 to 10 (0 is no health and 10 is full health)
     379                    int discreteHealthScale = (int)(10*relativHealthScale);
     380
     381                    //calculate the HealthLevel (= OponentLevel or Strength) there are 5 Levels
     382                    //Level 1, Level 2,... , Level 5
     383                    int HealthLevel = 1;
     384
     385                    if(initHealth < 200)
     386                        HealthLevel = 1;
     387                    if(200 <= initHealth && initHealth < 500)
     388                        HealthLevel = 2;
     389                    if(500 <= initHealth && initHealth < 1000)
     390                        HealthLevel = 3;
     391                    if(1000 <= initHealth && initHealth < 2500)
     392                        HealthLevel = 4;
     393                    if(2500 <= initHealth)
     394                        HealthLevel = 5;
     395
     396
     397
    359398                    // Change material only if outOfView changed
    360399                    if (it->second.wasOutOfView_)
     
    364403                        it->second.panel_->setDimensions(this->navMarkerSize_ * this->getActualSize().x, this->navMarkerSize_ * this->getActualSize().y);
    365404                        it->second.target_->setDimensions(this->aimMarkerSize_ * this->getActualSize().x, this->aimMarkerSize_ * this->getActualSize().y);
     405
     406
     407                        //it->second.health_->setMaterialName(TextureGenerator::getMaterialName("bar2_1.png", it->first->getRadarObjectColour()));
     408                        it->second.health_->setMaterialName(TextureGenerator::getMaterialName("barSquare.png", it->first->getRadarObjectColour()));
     409                        it->second.health_->setDimensions(this->healthMarkerSize_ * this->getActualSize().x , 0.75f*this->healthMarkerSize_ * this->getActualSize().y);
    366410                        it->second.wasOutOfView_ = false;
    367                     }
     411
     412                        // because as soon as relative health drops below 10% (0.1) the descrete value is 0 but as long as the
     413                        // spaceship is still intact there should be at least one part of the bar left.
     414                        if(1<=discreteHealthScale){
     415                            it->second.health_->setTiling((float)discreteHealthScale , 1 ,0);
     416                            it->second.health_->setDimensions(this->healthMarkerSize_ * this->getActualSize().x *0.1f*discreteHealthScale, 0.75f*this->healthMarkerSize_ * this->getActualSize().y);
     417                        }
     418
     419
     420
     421                        //healthLevel
     422                        it->second.healthLevel_->setMaterialName(TextureGenerator::getMaterialName("barSquare.png", it->first->getRadarObjectColour()));
     423                        it->second.healthLevel_->setDimensions(this->healthLevelMarkerSize_ * this->getActualSize().x , 0.75f*this->healthLevelMarkerSize_ * this->getActualSize().y);
     424                        it->second.wasOutOfView_ = false;
     425                        it->second.healthLevel_->setTiling((float)HealthLevel , 1 ,0);
     426                        it->second.healthLevel_->setDimensions(this->healthLevelMarkerSize_ * this->getActualSize().x *0.1f*HealthLevel, 0.25f*this->healthLevelMarkerSize_ * this->getActualSize().y);
     427                    }
     428
     429
     430
     431                    // sets Position and Dimensions (amount) health
     432                    it->second.health_->setUV(0.0f, 0.0f, 1.0f, 1.0f);
     433                    it->second.health_->setLeft((pos.x + 0.975f - it->second.panel_->getWidth()) * 0.5f);
     434                    it->second.health_->setTop((-pos.y + 1.04f - it->second.panel_->getHeight()) * 0.5f);
     435
     436
     437                    // because as soon as relative health drops below 10% (0.1) the descrete value is 0 but as long as the
     438                    // spaceship is still intact there should be at least one part of the bar left.
     439                    if(1<=discreteHealthScale){
     440                    it->second.health_->setTiling((float)discreteHealthScale , 1 ,0);
     441                    it->second.health_->setDimensions(this->healthMarkerSize_ * this->getActualSize().x *0.1f*discreteHealthScale, 0.75f*this->healthMarkerSize_ * this->getActualSize().y);
     442                    }
     443
     444
     445                    //sets Position and Dimensions (level) of healthLevel
     446                    it->second.healthLevel_->setMaterialName(TextureGenerator::getMaterialName("barSquare.png", it->first->getRadarObjectColour()));
     447                    it->second.healthLevel_->setUV(0.0f, 0.0f, 1.0f, 1.0f);
     448                    it->second.healthLevel_->setLeft((pos.x + 0.975f - it->second.panel_->getWidth()) * 0.5f);
     449                    it->second.healthLevel_->setTop((-pos.y + 1.125f - it->second.panel_->getHeight()) * 0.5f);
     450
     451                    it->second.healthLevel_->setTiling((float)HealthLevel , 1 ,0);
     452                    it->second.healthLevel_->setDimensions(this->healthLevelMarkerSize_ * this->getActualSize().x *0.1f*HealthLevel, 0.25f*this->healthLevelMarkerSize_ * this->getActualSize().y);
     453
    368454
    369455                    // Position marker
     
    376462                    it->second.text_->setTop((-pos.y + 1.0f + it->second.panel_->getHeight()) * 0.5f);
    377463
     464
     465
     466
    378467                    // Make sure the overlays are shown
     468                    it->second.health_->show();
     469                    it->second.healthLevel_->show();
    379470                    it->second.panel_->show();
    380471                    it->second.text_->show();
     
    419510
    420511            {
     512                it->second.health_->hide();
     513                it->second.healthLevel_->hide();
    421514                it->second.panel_->hide();
    422515                it->second.text_->hide();
     
    442535        for (std::map<RadarViewable*, ObjectInfo>::iterator it = this->activeObjectList_.begin(); it != this->activeObjectList_.end(); ++it)
    443536        {
     537            if (it->second.health_ != NULL)
     538                it->second.health_->setDimensions(this->healthMarkerSize_ * xScale, this->healthMarkerSize_ * yScale);
     539            if (it->second.healthLevel_ != NULL)
     540                it->second.healthLevel_->setDimensions(this->healthLevelMarkerSize_ * xScale, this->healthLevelMarkerSize_ * yScale);
    444541            if (it->second.panel_ != NULL)
    445542                it->second.panel_->setDimensions(this->navMarkerSize_ * xScale, this->navMarkerSize_ * yScale);
     
    468565
    469566        // Create everything needed to display the object on the radar and add it to the map
     567
     568        // Create health
     569        Ogre::PanelOverlayElement* health = static_cast<Ogre::PanelOverlayElement*>( Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "HUDNavigation_healthMarker_" + getUniqueNumberString()));
     570        //panel->setMaterialName("Orxonox/NavTDC");
     571        health->setMaterialName(TextureGenerator::getMaterialName("barSquare.png", object->getRadarObjectColour()));
     572        health->setDimensions(this->healthMarkerSize_ * xScale, this->healthMarkerSize_ * yScale);
     573        //panel->setColour(object->getRadarObjectColour());
     574
     575        // Create healthLevel
     576        Ogre::PanelOverlayElement* healthLevel = static_cast<Ogre::PanelOverlayElement*>( Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "HUDNavigation_healthLevelMarker_" + getUniqueNumberString()));
     577        //panel->setMaterialName("Orxonox/NavTDC");
     578        health->setMaterialName(TextureGenerator::getMaterialName("barSquare.png", object->getRadarObjectColour()));
     579        health->setDimensions(this->healthLevelMarkerSize_ * xScale, this->healthLevelMarkerSize_ * yScale);
     580
    470581
    471582        // Create arrow/marker
     
    490601        text->setColour(object->getRadarObjectColour());
    491602
     603        health->hide();
     604        healthLevel->hide();
    492605        panel->hide();
    493606        target->hide();
     
    495608
    496609        ObjectInfo tempStruct =
    497         {   panel, target, text, false, false, false};
     610        {   health, healthLevel, panel, target, text, false, false, false};
    498611        this->activeObjectList_[object] = tempStruct;
    499612
     613        this->background_->addChild(health);
     614        this->background_->addChild(healthLevel);
    500615        this->background_->addChild(panel);
    501616        this->background_->addChild(target);
     
    512627        {
    513628            // Detach overlays
     629            this->background_->removeChild(it->second.health_->getName());
     630            this->background_->removeChild(it->second.healthLevel_->getName());
    514631            this->background_->removeChild(it->second.panel_->getName());
    515632            this->background_->removeChild(it->second.target_->getName());
    516633            this->background_->removeChild(it->second.text_->getName());
    517634            // Properly destroy the overlay elements (do not use delete!)
     635            Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second.health_);
     636            Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second.healthLevel_);
    518637            Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second.panel_);
    519638            Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second.target_);
  • code/branches/presentationHS14merge/src/modules/overlays/hud/HUDNavigation.h

    r9667 r10242  
    7777            struct ObjectInfo
    7878            {
     79
     80
     81
     82                Ogre::PanelOverlayElement* health_;
     83                Ogre::PanelOverlayElement* healthLevel_;
    7984                Ogre::PanelOverlayElement* panel_;
    8085                Ogre::PanelOverlayElement* target_;
     
    8893
    8994            // 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
    90111            inline void setNavMarkerSize(float size)
    91112            {
     
    100121                this->sizeChanged();
    101122            }
     123
    102124            inline float getAimMarkerSize() const
    103125                { return aimMarkerSize_; }
     
    121143            std::list<std::pair<RadarViewable*, unsigned int> > sortedObjectList_;
    122144
     145            float healthMarkerSize_;
     146            float healthLevelMarkerSize_;
    123147            float navMarkerSize_;
    124148            float aimMarkerSize_;
Note: See TracChangeset for help on using the changeset viewer.