Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10163


Ignore:
Timestamp:
Dec 10, 2014, 3:10:55 PM (10 years ago)
Author:
aejonas
Message:

completed healthbar project

Location:
code/branches/hudHS14/src/modules/overlays/hud
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/hudHS14/src/modules/overlays/hud/HUDNavigation.cc

    r10149 r10163  
    8383        this->setAimMarkerSize(0.02f);
    8484        this->setHealthMarkerSize(0.06f);
     85        this->setHealthLevelMarkerSize(0.06f);
    8586
    8687        this->setDetectionLimit(10000.0f);
     
    118119        XMLPortParam(HUDNavigation, "aimMarkerSize", setAimMarkerSize, getAimMarkerSize, xmlelement, mode);
    119120        XMLPortParam(HUDNavigation, "healthMarkerSize", setHealthMarkerSize, getHealthMarkerSize, xmlelement, mode);
     121        XMLPortParam(HUDNavigation, "healthLevelMarkerSize", setHealthLevelMarkerSize, getHealthLevelMarkerSize, xmlelement, mode);
    120122
    121123    }
     
    305307                    {
    306308                        it->second.health_->hide();
     309                        it->second.healthLevel_->hide();
    307310                        it->second.panel_->setMaterialName(TextureGenerator::getMaterialName("arrows.png", it->first->getRadarObjectColour()));
    308311                        it->second.wasOutOfView_ = true;
     
    367370
    368371
    369                         //calculate the health of the actual selected radarViewable (while (0) is no health left, (1) is the initial health)
    370 
     372                        //calculate the health of the actual selected radarViewable (relativHealthScale: while (0) is no health left, (1) is the initial health)
    371373                    Pawn* pawnPtr = (Pawn*) (it->first->getWorldEntity());
    372374                    float health = pawnPtr->getHealth();
     
    374376                    float relativHealthScale = health/initHealth;
    375377
    376                     //values from 0 to 10
     378                    //integer values from 0 to 10 (0 is no health and 10 is full health)
    377379                    int discreteHealthScale = 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;
    378395
    379396
     
    387404                        it->second.target_->setDimensions(this->aimMarkerSize_ * this->getActualSize().x, this->aimMarkerSize_ * this->getActualSize().y);
    388405
    389                         //
     406
    390407                        //it->second.health_->setMaterialName(TextureGenerator::getMaterialName("bar2_1.png", it->first->getRadarObjectColour()));
    391408                        it->second.health_->setMaterialName(TextureGenerator::getMaterialName("barSquare.png", it->first->getRadarObjectColour()));
     
    393410                        it->second.wasOutOfView_ = false;
    394411
     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.
    395414                        if(1<=discreteHealthScale){
    396415                                it->second.health_->setTiling((float)discreteHealthScale , 1 ,0);
    397416                                it->second.health_->setDimensions(this->healthMarkerSize_ * this->getActualSize().x *0.1*discreteHealthScale, 0.75*this->healthMarkerSize_ * this->getActualSize().y);
    398417                        }
    399                     }
    400 
    401 
    402 
    403                     // Position and Dimensions (amount) health
     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.75*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.1*HealthLevel, 0.25*this->healthLevelMarkerSize_ * this->getActualSize().y);
     427                    }
     428
     429
     430
     431                    // sets Position and Dimensions (amount) health
    404432                    it->second.health_->setUV(0.0f, 0.0f, 1.0f, 1.0f);
    405433                    it->second.health_->setLeft((pos.x + 0.975f - it->second.panel_->getWidth()) * 0.5f);
    406434                    it->second.health_->setTop((-pos.y + 1.04f - it->second.panel_->getHeight()) * 0.5f);
    407                    // it->second.health_->setDimensions(this->healthMarkerSize_ * this->getActualSize().x * relativHealthScale, 0.75*this->healthMarkerSize_ * this->getActualSize().y);
    408 
    409 
     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.
    410439                    if(1<=discreteHealthScale){
    411440                    it->second.health_->setTiling((float)discreteHealthScale , 1 ,0);
     
    413442                    }
    414443
     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.1*HealthLevel, 0.25*this->healthLevelMarkerSize_ * this->getActualSize().y);
    415453
    416454
     
    424462                    it->second.text_->setTop((-pos.y + 1.0f + it->second.panel_->getHeight()) * 0.5f);
    425463
     464
     465
     466
    426467                    // Make sure the overlays are shown
    427 
    428468                    it->second.health_->show();
     469                    it->second.healthLevel_->show();
    429470                    it->second.panel_->show();
    430471                    it->second.text_->show();
     
    470511            {
    471512                it->second.health_->hide();
    472                 it->second.panel_->hide();
     513                it->second.healthLevel_->hide();
     514                it->second.panel_->hide();
    473515                it->second.text_->hide();
    474516                it->second.target_->hide();
     
    495537                if (it->second.health_ != NULL)
    496538                    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);
    497541            if (it->second.panel_ != NULL)
    498542                it->second.panel_->setDimensions(this->navMarkerSize_ * xScale, this->navMarkerSize_ * yScale);
     
    523567
    524568        // Create health
    525                 Ogre::PanelOverlayElement* health = static_cast<Ogre::PanelOverlayElement*>( Ogre::OverlayManager::getSingleton()
    526                         .createOverlayElement("Panel", "HUDNavigation_healthMarker_" + getUniqueNumberString()));
    527                 //panel->setMaterialName("Orxonox/NavTDC");
    528                 health->setMaterialName(TextureGenerator::getMaterialName("barSquare.png", object->getRadarObjectColour()));
    529                 health->setDimensions(this->healthMarkerSize_ * xScale, this->healthMarkerSize_ * yScale);
    530                 //panel->setColour(object->getRadarObjectColour());
     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);
    531580
    532581
     
    553602
    554603        health->hide();
     604        healthLevel->hide();
    555605        panel->hide();
    556606        target->hide();
     
    558608
    559609        ObjectInfo tempStruct =
    560         {   health, panel, target, text, false, false, false};
     610        {   health, healthLevel, panel, target, text, false, false, false};
    561611        this->activeObjectList_[object] = tempStruct;
    562612
    563613        this->background_->addChild(health);
     614        this->background_->addChild(healthLevel);
    564615        this->background_->addChild(panel);
    565616        this->background_->addChild(target);
     
    577628            // Detach overlays
    578629                this->background_->removeChild(it->second.health_->getName());
     630                this->background_->removeChild(it->second.healthLevel_->getName());
    579631            this->background_->removeChild(it->second.panel_->getName());
    580632            this->background_->removeChild(it->second.target_->getName());
     
    582634            // Properly destroy the overlay elements (do not use delete!)
    583635            Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second.health_);
     636            Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second.healthLevel_);
    584637            Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second.panel_);
    585638            Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second.target_);
  • code/branches/hudHS14/src/modules/overlays/hud/HUDNavigation.h

    r10122 r10163  
    7878            {
    7979
    80                 //manipulation bzw versuch !!! health additional
     80
     81
    8182                Ogre::PanelOverlayElement* health_;
     83                Ogre::PanelOverlayElement* healthLevel_;
    8284                Ogre::PanelOverlayElement* panel_;
    8385                Ogre::PanelOverlayElement* target_;
     
    98100            inline float getHealthMarkerSize() const
    99101                                { 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_; }
    100110
    101111            inline void setNavMarkerSize(float size)
     
    134144
    135145            float healthMarkerSize_;
     146            float healthLevelMarkerSize_;
    136147            float navMarkerSize_;
    137148            float aimMarkerSize_;
Note: See TracChangeset for help on using the changeset viewer.