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 | |
---|
27 | #include "Scoreboard.h" |
---|
28 | |
---|
29 | #include "util/Convert.h" |
---|
30 | #include "core/CoreIncludes.h" |
---|
31 | #include "objects/gametypes/Gametype.h" |
---|
32 | #include "objects/infos/PlayerInfo.h" |
---|
33 | #include "CreateLines.h" |
---|
34 | |
---|
35 | namespace orxonox |
---|
36 | { |
---|
37 | CreateFactory(Scoreboard); |
---|
38 | |
---|
39 | /** |
---|
40 | @brief Constructor: Creates the scoreboard. |
---|
41 | */ |
---|
42 | Scoreboard::Scoreboard(BaseObject* creator) |
---|
43 | : OrxonoxOverlay(creator) |
---|
44 | { |
---|
45 | RegisterObject(Scoreboard); |
---|
46 | } |
---|
47 | |
---|
48 | /** |
---|
49 | @brief Initializes the lines. |
---|
50 | */ |
---|
51 | void Scoreboard::XMLPort(Element& xmlElement, XMLPort::Mode mode) |
---|
52 | { |
---|
53 | SUPER(Scoreboard, XMLPort, xmlElement, mode); |
---|
54 | } |
---|
55 | |
---|
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()); |
---|
62 | } |
---|
63 | |
---|
64 | /** |
---|
65 | @brief Prints the scoreboard on the screen. |
---|
66 | */ |
---|
67 | void Scoreboard::tick(float dt) |
---|
68 | { |
---|
69 | const std::map<PlayerInfo*, Player>& playerList = this->getGametype()->getPlayers(); |
---|
70 | |
---|
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 |
---|
79 | CreateLines* lines = new CreateLines(leftOffset, topOffset + (distance + height) * lines_.size(), width, height); |
---|
80 | lines->setVisibility(this->isVisible()); |
---|
81 | this->lines_.push_back(lines); |
---|
82 | } |
---|
83 | while (playerList.size() < this->lines_.size()) |
---|
84 | { |
---|
85 | // destroy lines |
---|
86 | delete this->lines_.back(); |
---|
87 | this->lines_.pop_back(); |
---|
88 | } |
---|
89 | |
---|
90 | // update board |
---|
91 | |
---|
92 | unsigned int index = 0; |
---|
93 | for (std::map<PlayerInfo*, Player>::const_iterator it = playerList.begin(); it != playerList.end(); ++it) |
---|
94 | { |
---|
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_)); |
---|
98 | index++; |
---|
99 | } |
---|
100 | |
---|
101 | //numberOfColumns = 2; |
---|
102 | //numberOfLines = 3; |
---|
103 | //topOffset = 0.1; |
---|
104 | //lineSpacing = 0.1; |
---|
105 | |
---|
106 | //for (unsigned int i = 0; i < this->lines_.size(); ++i) |
---|
107 | //{ |
---|
108 | // columnIndex = 0; |
---|
109 | // leftOffset = 0.1; |
---|
110 | |
---|
111 | // this->createlines_->setNumberOfColumns(numberOfColumns, i); |
---|
112 | |
---|
113 | // // columnText = this->getGametype()->getPlayersName(); |
---|
114 | // columnText = "PlayerName"; |
---|
115 | // this->createlines_->alignColumn(columnIndex, topOffset, leftOffset); |
---|
116 | // this->createlines_->setColumnText(columnIndex, columnText); |
---|
117 | |
---|
118 | // columnIndex++; |
---|
119 | // leftOffset = leftOffset + 0.3; |
---|
120 | |
---|
121 | // // columnText = this->getGametype()->getPlayersFrags(); |
---|
122 | // columnText = "PlayerFrags"; |
---|
123 | // this->createlines_->alignColumn(columnIndex, topOffset, leftOffset); |
---|
124 | // this->createlines_->setColumnText(columnIndex, columnText); |
---|
125 | |
---|
126 | // topOffset = topOffset + lineSpacing; |
---|
127 | //} |
---|
128 | } |
---|
129 | } |
---|