/* * ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Author: * Julien Kindle * */ #include "SOBHUDInfo.h" #include "core/CoreIncludes.h" #include "core/XMLPort.h" #include "util/Convert.h" #include "SOB.h" #include #include namespace orxonox { RegisterClass(SOBHUDInfo); SOBHUDInfo::SOBHUDInfo(Context* context) : OverlayText(context) { RegisterObject(SOBHUDInfo); this->SOBGame = nullptr; } void SOBHUDInfo::XMLPort(Element& xmlelement, XMLPort::Mode mode) { SUPER(SOBHUDInfo, XMLPort, xmlelement, mode); XMLPortParam(SOBHUDInfo, "type", setType, getType, xmlelement, mode).defaultValues(false); } void SOBHUDInfo::tick(float dt) { SUPER(SOBHUDInfo, tick, dt); //If you have a look at the HUD xml file, you can see there are several elements with different types. if (this->SOBGame) { if (this->type_ == "Coins") { std::stringstream ss; ss << "cc x " << std::setw(2) << std::setfill('0') << SOBGame->getCoins(); std::string s = ss.str(); this->setCaption(s); } if (this->type_ == "Points") { std::stringstream ss; ss << std::setw(6) << std::setfill('0') << SOBGame->getPoints(); std::string s = ss.str(); this->setCaption(s); } if (this->type_ == "Time") { std::stringstream ss; ss << SOBGame->getTimeLeft(); std::string s = ss.str(); this->setCaption(s); } if (this->type_ == "Info") { std::stringstream ss; ss << SOBGame->getInfoText(); std::string s = ss.str(); this->setCaption(s); } } } //No idea why, just implement this method void SOBHUDInfo::changedOwner() { SUPER(SOBHUDInfo, changedOwner); if (this->getOwner() && this->getOwner()->getGametype()) { this->SOBGame = orxonox_cast(this->getOwner()->getGametype()); } else { this->SOBGame = nullptr; } } }