[2225] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * Benjamin Hildebrandt |
---|
| 24 | * |
---|
| 25 | */ |
---|
| 26 | |
---|
[2320] | 27 | #include "Scoreboard.h" |
---|
[2225] | 28 | |
---|
| 29 | #include "util/Convert.h" |
---|
| 30 | #include "core/CoreIncludes.h" |
---|
[2320] | 31 | #include "objects/gametypes/Gametype.h" |
---|
[2495] | 32 | #include "objects/infos/PlayerInfo.h" |
---|
[2320] | 33 | #include "CreateLines.h" |
---|
[2225] | 34 | |
---|
| 35 | namespace orxonox |
---|
| 36 | { |
---|
| 37 | CreateFactory(Scoreboard); |
---|
| 38 | |
---|
| 39 | /** |
---|
[2320] | 40 | @brief Constructor: Creates the scoreboard. |
---|
[2225] | 41 | */ |
---|
| 42 | Scoreboard::Scoreboard(BaseObject* creator) |
---|
| 43 | : OrxonoxOverlay(creator) |
---|
| 44 | { |
---|
| 45 | RegisterObject(Scoreboard); |
---|
| 46 | } |
---|
| 47 | |
---|
[2320] | 48 | /** |
---|
[2386] | 49 | @brief Initializes the lines. |
---|
| 50 | */ |
---|
| 51 | void Scoreboard::XMLPort(Element& xmlElement, XMLPort::Mode mode) |
---|
| 52 | { |
---|
| 53 | SUPER(Scoreboard, XMLPort, xmlElement, mode); |
---|
[2495] | 54 | } |
---|
[2386] | 55 | |
---|
[2495] | 56 | void Scoreboard::changedVisibility() |
---|
| 57 | { |
---|
| 58 | SUPER(Scoreboard, changedVisibility); |
---|
| 59 | |
---|
| 60 | for (unsigned int i = 0; i < this->lines_.size(); ++i) |
---|
| 61 | this->lines_[i]->setVisibility(this->isVisible()); |
---|
[2386] | 62 | } |
---|
| 63 | |
---|
| 64 | /** |
---|
[2320] | 65 | @brief Prints the scoreboard on the screen. |
---|
| 66 | */ |
---|
[2495] | 67 | void Scoreboard::tick(float dt) |
---|
| 68 | { |
---|
| 69 | const std::map<PlayerInfo*, Player>& playerList = this->getGametype()->getPlayers(); |
---|
[2320] | 70 | |
---|
[2495] | 71 | const float topOffset = 0.2; |
---|
| 72 | const float leftOffset = 0.075; |
---|
| 73 | const float distance = 0.01; |
---|
| 74 | const float width = 0.85; |
---|
| 75 | const float height = 0.05; |
---|
| 76 | while (playerList.size() > this->lines_.size()) |
---|
| 77 | { |
---|
| 78 | // create new lines |
---|
[2498] | 79 | CreateLines* lines = new CreateLines(leftOffset, topOffset + (distance + height) * lines_.size(), width, height); |
---|
| 80 | lines->setVisibility(this->isVisible()); |
---|
| 81 | this->lines_.push_back(lines); |
---|
[2495] | 82 | } |
---|
| 83 | while (playerList.size() < this->lines_.size()) |
---|
| 84 | { |
---|
| 85 | // destroy lines |
---|
| 86 | delete this->lines_.back(); |
---|
| 87 | this->lines_.pop_back(); |
---|
| 88 | } |
---|
[2320] | 89 | |
---|
[2495] | 90 | // update board |
---|
[2320] | 91 | |
---|
[2495] | 92 | unsigned int index = 0; |
---|
| 93 | for (std::map<PlayerInfo*, Player>::const_iterator it = playerList.begin(); it != playerList.end(); ++it) |
---|
| 94 | { |
---|
[3196] | 95 | this->lines_[index]->setPlayerName(multi_cast<std::string>(it->first->getName())); |
---|
| 96 | this->lines_[index]->setScore(multi_cast<std::string>(it->second.frags_)); |
---|
| 97 | this->lines_[index]->setDeaths(multi_cast<std::string>(it->second.killed_)); |
---|
[2495] | 98 | index++; |
---|
| 99 | } |
---|
[2320] | 100 | |
---|
[2495] | 101 | //numberOfColumns = 2; |
---|
| 102 | //numberOfLines = 3; |
---|
| 103 | //topOffset = 0.1; |
---|
| 104 | //lineSpacing = 0.1; |
---|
[2320] | 105 | |
---|
[2495] | 106 | //for (unsigned int i = 0; i < this->lines_.size(); ++i) |
---|
| 107 | //{ |
---|
| 108 | // columnIndex = 0; |
---|
| 109 | // leftOffset = 0.1; |
---|
[2320] | 110 | |
---|
[2495] | 111 | // this->createlines_->setNumberOfColumns(numberOfColumns, i); |
---|
[2320] | 112 | |
---|
[2498] | 113 | // // columnText = this->getGametype()->getPlayersName(); |
---|
[2495] | 114 | // columnText = "PlayerName"; |
---|
| 115 | // this->createlines_->alignColumn(columnIndex, topOffset, leftOffset); |
---|
| 116 | // this->createlines_->setColumnText(columnIndex, columnText); |
---|
[2320] | 117 | |
---|
[2495] | 118 | // columnIndex++; |
---|
| 119 | // leftOffset = leftOffset + 0.3; |
---|
[2320] | 120 | |
---|
[2498] | 121 | // // columnText = this->getGametype()->getPlayersFrags(); |
---|
[2495] | 122 | // columnText = "PlayerFrags"; |
---|
| 123 | // this->createlines_->alignColumn(columnIndex, topOffset, leftOffset); |
---|
| 124 | // this->createlines_->setColumnText(columnIndex, columnText); |
---|
[2320] | 125 | |
---|
[2495] | 126 | // topOffset = topOffset + lineSpacing; |
---|
| 127 | //} |
---|
[2320] | 128 | } |
---|
[2225] | 129 | } |
---|