[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" |
---|
[5735] | 31 | #include "gametypes/Gametype.h" |
---|
| 32 | #include "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 | |
---|
[5929] | 48 | Scoreboard::~Scoreboard() |
---|
| 49 | { |
---|
| 50 | while (this->lines_.size() > 0) |
---|
| 51 | { |
---|
| 52 | // destroy lines |
---|
| 53 | delete this->lines_.back(); |
---|
| 54 | this->lines_.pop_back(); |
---|
| 55 | } |
---|
| 56 | } |
---|
| 57 | |
---|
[2320] | 58 | /** |
---|
[2386] | 59 | @brief Initializes the lines. |
---|
| 60 | */ |
---|
| 61 | void Scoreboard::XMLPort(Element& xmlElement, XMLPort::Mode mode) |
---|
| 62 | { |
---|
| 63 | SUPER(Scoreboard, XMLPort, xmlElement, mode); |
---|
[2495] | 64 | } |
---|
[2386] | 65 | |
---|
[2495] | 66 | void Scoreboard::changedVisibility() |
---|
| 67 | { |
---|
| 68 | SUPER(Scoreboard, changedVisibility); |
---|
| 69 | |
---|
| 70 | for (unsigned int i = 0; i < this->lines_.size(); ++i) |
---|
| 71 | this->lines_[i]->setVisibility(this->isVisible()); |
---|
[2386] | 72 | } |
---|
| 73 | |
---|
| 74 | /** |
---|
[2320] | 75 | @brief Prints the scoreboard on the screen. |
---|
| 76 | */ |
---|
[2495] | 77 | void Scoreboard::tick(float dt) |
---|
| 78 | { |
---|
| 79 | const std::map<PlayerInfo*, Player>& playerList = this->getGametype()->getPlayers(); |
---|
[2320] | 80 | |
---|
[2495] | 81 | const float topOffset = 0.2; |
---|
| 82 | const float leftOffset = 0.075; |
---|
| 83 | const float distance = 0.01; |
---|
| 84 | const float width = 0.85; |
---|
| 85 | const float height = 0.05; |
---|
| 86 | while (playerList.size() > this->lines_.size()) |
---|
| 87 | { |
---|
| 88 | // create new lines |
---|
[2498] | 89 | CreateLines* lines = new CreateLines(leftOffset, topOffset + (distance + height) * lines_.size(), width, height); |
---|
| 90 | lines->setVisibility(this->isVisible()); |
---|
| 91 | this->lines_.push_back(lines); |
---|
[2495] | 92 | } |
---|
| 93 | while (playerList.size() < this->lines_.size()) |
---|
| 94 | { |
---|
| 95 | // destroy lines |
---|
| 96 | delete this->lines_.back(); |
---|
| 97 | this->lines_.pop_back(); |
---|
| 98 | } |
---|
[2320] | 99 | |
---|
[2495] | 100 | // update board |
---|
[2320] | 101 | |
---|
[2495] | 102 | unsigned int index = 0; |
---|
| 103 | for (std::map<PlayerInfo*, Player>::const_iterator it = playerList.begin(); it != playerList.end(); ++it) |
---|
| 104 | { |
---|
[3196] | 105 | this->lines_[index]->setPlayerName(multi_cast<std::string>(it->first->getName())); |
---|
| 106 | this->lines_[index]->setScore(multi_cast<std::string>(it->second.frags_)); |
---|
| 107 | this->lines_[index]->setDeaths(multi_cast<std::string>(it->second.killed_)); |
---|
[2495] | 108 | index++; |
---|
| 109 | } |
---|
[2320] | 110 | |
---|
[2495] | 111 | //numberOfColumns = 2; |
---|
| 112 | //numberOfLines = 3; |
---|
| 113 | //topOffset = 0.1; |
---|
| 114 | //lineSpacing = 0.1; |
---|
[2320] | 115 | |
---|
[2495] | 116 | //for (unsigned int i = 0; i < this->lines_.size(); ++i) |
---|
| 117 | //{ |
---|
| 118 | // columnIndex = 0; |
---|
| 119 | // leftOffset = 0.1; |
---|
[2320] | 120 | |
---|
[2495] | 121 | // this->createlines_->setNumberOfColumns(numberOfColumns, i); |
---|
[2320] | 122 | |
---|
[2498] | 123 | // // columnText = this->getGametype()->getPlayersName(); |
---|
[2495] | 124 | // columnText = "PlayerName"; |
---|
| 125 | // this->createlines_->alignColumn(columnIndex, topOffset, leftOffset); |
---|
| 126 | // this->createlines_->setColumnText(columnIndex, columnText); |
---|
[2320] | 127 | |
---|
[2495] | 128 | // columnIndex++; |
---|
| 129 | // leftOffset = leftOffset + 0.3; |
---|
[2320] | 130 | |
---|
[2498] | 131 | // // columnText = this->getGametype()->getPlayersFrags(); |
---|
[2495] | 132 | // columnText = "PlayerFrags"; |
---|
| 133 | // this->createlines_->alignColumn(columnIndex, topOffset, leftOffset); |
---|
| 134 | // this->createlines_->setColumnText(columnIndex, columnText); |
---|
[2320] | 135 | |
---|
[2495] | 136 | // topOffset = topOffset + lineSpacing; |
---|
| 137 | //} |
---|
[2320] | 138 | } |
---|
[2225] | 139 | } |
---|