Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 29, 2008, 11:55:37 AM (16 years ago)
Author:
rgrieder
Message:

Changed initialisation of overlay classes to the new convention.
The default values of the XML parameters are set in the constructor with the setter functions!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/objecthierarchy/src/orxonox/overlays/hud/HUDBar.cc

    r2019 r2046  
    4646    CreateFactory(BarColour);
    4747
    48     BarColour::BarColour(BaseObject* creator) : BaseObject(creator), position_(0.0)
     48    BarColour::BarColour(BaseObject* creator)
     49        : BaseObject(creator)
    4950    {
    5051        RegisterObject(BarColour);
     52
     53        setColour(ColourValue(1.0, 1.0, 1.0, 1.0));
     54        setPosition(0.0);
    5155    }
    5256
     
    5559        SUPER(BarColour, XMLPort, xmlElement, mode);
    5660
    57         XMLPortParam(BarColour, "colour", setColour, getColour, xmlElement, mode)
    58             .defaultValues(ColourValue(1.0, 1.0, 1.0, 1.0));
    59         XMLPortParam(BarColour, "position", setPosition, getPosition, xmlElement, mode).defaultValues(0.0f);
     61        XMLPortParam(BarColour, "colour", setColour, getColour, xmlElement, mode);
     62        XMLPortParam(BarColour, "position", setPosition, getPosition, xmlElement, mode);
    6063    }
    6164
     
    6366    unsigned int HUDBar::materialcount_s = 0;
    6467
    65     HUDBar::HUDBar(BaseObject* creator) : OrxonoxOverlay(creator), bar_(0), textureUnitState_(0)
     68    HUDBar::HUDBar(BaseObject* creator)
     69        : OrxonoxOverlay(creator)
    6670    {
    6771        RegisterObject(HUDBar);
     72
     73        // create new material
     74        std::string materialname = "barmaterial" + getConvertedValue<unsigned int, std::string>(materialcount_s++);
     75        Ogre::MaterialPtr material = (Ogre::MaterialPtr)Ogre::MaterialManager::getSingleton().create(materialname, "General");
     76        material->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
     77        this->textureUnitState_ = material->getTechnique(0)->getPass(0)->createTextureUnitState();
     78        this->textureUnitState_->setTextureName("bar2.tga");
     79        // use the default colour
     80        this->textureUnitState_->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, ColourValue(0.2, 0.7, 0.2));
     81
     82        this->bar_ = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton()
     83            .createOverlayElement("Panel", "HUDBar_bar_" + getUniqueNumberString()));
     84        this->bar_->setMaterialName(materialname);
     85
     86        setValue(0.4567654f);
     87        setRightToLeft(false);
     88        setAutoColour(true);
     89
     90        this->background_->addChild(bar_);
    6891    }
    6992
    7093    HUDBar::~HUDBar()
    7194    {
    72         if (this->bar_)
     95        if (this->isInitialized())
    7396            Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->bar_);
    7497    }
     
    78101        SUPER(HUDBar, XMLPort, xmlElement, mode);
    79102
    80         if (mode == XMLPort::LoadObject)
    81         {
    82             // create new material
    83             std::string materialname = "barmaterial" + getConvertedValue<unsigned int, std::string>(materialcount_s++);
    84             Ogre::MaterialPtr material = (Ogre::MaterialPtr)Ogre::MaterialManager::getSingleton().create(materialname, "General");
    85             material->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
    86             this->textureUnitState_ = material->getTechnique(0)->getPass(0)->createTextureUnitState();
    87             this->textureUnitState_->setTextureName("bar2.tga");
    88             // use the default colour
    89             this->textureUnitState_->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, ColourValue(0.2, 0.7, 0.2));
    90 
    91             this->bar_ = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton()
    92                 .createOverlayElement("Panel", "HUDBar_bar_" + getUniqueNumberString()));
    93             this->bar_->setMaterialName(materialname);
    94             this->background_->addChild(bar_);
    95         }
    96 
    97         XMLPortParam(HUDBar, "initialValue", setValue,       getValue,       xmlElement, mode).defaultValues(0.4567654f);
    98         XMLPortParam(HUDBar, "rightToLeft",  setRightToLeft, getRightToLeft, xmlElement, mode).defaultValues(false);
    99         XMLPortParam(HUDBar, "autoColour",   setAutoColour,  getAutoColour,  xmlElement, mode).defaultValues(true);
     103        XMLPortParam(HUDBar, "initialValue", setValue,       getValue,       xmlElement, mode);
     104        XMLPortParam(HUDBar, "rightToLeft",  setRightToLeft, getRightToLeft, xmlElement, mode);
     105        XMLPortParam(HUDBar, "autoColour",   setAutoColour,  getAutoColour,  xmlElement, mode);
    100106        XMLPortObject(HUDBar, BarColour, "", addColour, getColour, xmlElement, mode);
    101107    }
Note: See TracChangeset for help on using the changeset viewer.