Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 29, 2015, 11:27:32 PM (9 years ago)
Author:
fvultier
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/fabienHS15/src/modules/overlays/hud/HUDWeapon.cc

    r10715 r10721  
    2121 *
    2222 *   Author:
    23  *      Yuning Chai
    24  *      Felix Schulthess
     23 *      Fabien Vultier
    2524 *   Co-authors:
    26  *      Reto Grieder
    27  *      Wolfgang Roenninger
     25 *      ...
    2826 *
    2927 */
     
    4846        RegisterObject(HUDWeapon);
    4947
     48        weaponModeHUDActualSize_ = Vector2(0.0f,0.0f);
     49
     50        weaponModes_ = NULL;
     51        weaponIndex_ = 0;
     52        hudWeaponModes_.clear();
     53
    5054        overlayElement_ = static_cast<Ogre::PanelOverlayElement* >(Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "HUDWeapon" + getUniqueNumberString()));
    5155        overlayElement_->setMaterialName("Orxonox/WSHUD_Weapon");
     
    7579    {
    7680        SUPER(HUDWeapon, tick, dt);
     81
     82        if (!weapon_)
     83        {
     84            // TODO: destroy this HUD id the Weapon does no more exist. (Wehen the weak pointer is NULL)
     85        }
    7786    }   
    7887
     
    8291
    8392        positionHUDChilds();
    84     }     
     93    }
     94
     95    void HUDWeapon::sizeChanged()
     96    {
     97        OrxonoxOverlay::sizeChanged();
     98
     99        positionHUDChilds();
     100    }
    85101
    86102    void HUDWeapon::changedOwner()
     
    131147        weaponModes_ = weapon_->getAllWeaponmodes();
    132148
     149        updateSize();
    133150        createHUDChilds();
    134         positionHUDChilds();       
     151        positionHUDChilds();
    135152    } 
    136153
    137154    void HUDWeapon::createHUDChilds()
    138155    {
     156        if (weaponModes_ == NULL)
     157        {
     158            return;
     159        }
     160
     161        int positionIndex = 0;
     162
    139163        for (std::multimap<unsigned int, WeaponMode*>::iterator it = weaponModes_->begin(); it != weaponModes_->end(); ++it)
    140164        {
    141165            HUDWeaponMode* hudWeaponMode = new HUDWeaponMode(this->getContext());
    142166            hudWeaponMode->setOwner(owner_);
     167            hudWeaponMode->setOverlayGroup(this->getOverlayGroup());
    143168            hudWeaponMode->setWeaponMode(it->second);
     169            hudWeaponMode->setWeaponIndex(this->weaponIndex_);                   
     170            hudWeaponMode->setAspectCorrection(false);
     171            hudWeaponMode->setPickPoint(Vector2(0.0f,0.0f));
     172
    144173            hudWeaponModes_.push_back(hudWeaponMode);
    145         }   
     174
     175            ++ positionIndex;
     176        }
    146177    }     
    147178
     
    152183        for (std::vector<WeakPtr<HUDWeaponMode> >::iterator it = hudWeaponModes_.begin(); it != hudWeaponModes_.end(); ++it)
    153184        {
    154             (*it)->setOverlayGroup(this->getOverlayGroup());           
    155             (*it)->setAspectCorrection(this->getAspectCorrection());
    156             (*it)->setPosition(this->getPosition() + Vector2(0.0f,0.025f*positionIndex));
    157             (*it)->setSize(Vector2(0.15f,0.025f));
    158             (*it)->setPickPoint(Vector2(0.0f,0.0f));
    159 
    160             ++ positionIndex;       
    161         }
    162 
    163         overlayElement_->setDimensions(1.0f,0.25f*hudWeaponModes_.size());
     185            (*it)->setWeaponModeIndex(positionIndex);
     186            (*it)->setWeaponIndex(this->weaponIndex_);
     187            (*it)->setWeaponModeHUDActualSize(this->weaponModeHUDActualSize_);
     188            (*it)->positionHUDChilds();
     189
     190            ++ positionIndex;
     191        }
    164192    } 
    165193
     
    173201        hudWeaponModes_.clear();
    174202    }
     203
     204    void HUDWeapon::updateSize()
     205    {
     206        if (weaponModes_ != NULL)
     207        {
     208            this->setSize(Vector2(weaponModeHUDActualSize_.x,weaponModeHUDActualSize_.y*weaponModes_->size()));
     209            updatePosition();
     210        }       
     211    }
     212
     213    void HUDWeapon::updatePosition()
     214    {
     215        if (weaponModes_ != NULL)
     216        {
     217            this->setPosition(Vector2(weaponModeHUDActualSize_.x*weaponIndex_,0.0f));
     218        }       
     219    }       
    175220}
Note: See TracChangeset for help on using the changeset viewer.