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 "gametypes/Gametype.h" |
---|
32 | #include "infos/PlayerInfo.h" |
---|
33 | #include "CreateLines.h" |
---|
34 | |
---|
35 | namespace orxonox |
---|
36 | { |
---|
37 | RegisterClass(Scoreboard); |
---|
38 | |
---|
39 | /** |
---|
40 | @brief Constructor: Creates the scoreboard. |
---|
41 | */ |
---|
42 | Scoreboard::Scoreboard(Context* context) |
---|
43 | : OrxonoxOverlay(context) |
---|
44 | { |
---|
45 | RegisterObject(Scoreboard); |
---|
46 | } |
---|
47 | |
---|
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 | |
---|
58 | void Scoreboard::changedVisibility() |
---|
59 | { |
---|
60 | SUPER(Scoreboard, changedVisibility); |
---|
61 | |
---|
62 | for (unsigned int i = 0; i < this->lines_.size(); ++i) |
---|
63 | this->lines_[i]->changedVisibility(); |
---|
64 | } |
---|
65 | |
---|
66 | /** |
---|
67 | @brief Prints the scoreboard on the screen. |
---|
68 | */ |
---|
69 | void Scoreboard::tick(float dt) |
---|
70 | { |
---|
71 | const std::map<PlayerInfo*, Player>& playerList = this->getGametype()->getPlayers(); |
---|
72 | |
---|
73 | const float topOffset = 0.2f; |
---|
74 | const float leftOffset = 0.075f; |
---|
75 | const float distance = 0.01f; |
---|
76 | const float width = 0.85f; |
---|
77 | const float height = 0.05f; |
---|
78 | while (playerList.size() > this->lines_.size()) |
---|
79 | { |
---|
80 | // create new lines |
---|
81 | CreateLines* lines = new CreateLines(leftOffset, topOffset + (distance + height) * lines_.size(), width, height); |
---|
82 | lines->setVisibility(this->isVisible()); |
---|
83 | lines->setOverlayGroup( this->getOverlayGroup() ); |
---|
84 | this->lines_.push_back(lines); |
---|
85 | } |
---|
86 | while (playerList.size() < this->lines_.size()) |
---|
87 | { |
---|
88 | // destroy lines |
---|
89 | delete this->lines_.back(); |
---|
90 | this->lines_.pop_back(); |
---|
91 | } |
---|
92 | |
---|
93 | // update board |
---|
94 | |
---|
95 | unsigned int index = 0; |
---|
96 | for (std::map<PlayerInfo*, Player>::const_iterator it = playerList.begin(); it != playerList.end(); ++it) |
---|
97 | { |
---|
98 | this->lines_[index]->setPlayerName(multi_cast<std::string>(it->first->getName())); |
---|
99 | this->lines_[index]->setScore(multi_cast<std::string>(it->second.frags_)); |
---|
100 | this->lines_[index]->setDeaths(multi_cast<std::string>(it->second.killed_)); |
---|
101 | index++; |
---|
102 | } |
---|
103 | |
---|
104 | //numberOfColumns = 2; |
---|
105 | //numberOfLines = 3; |
---|
106 | //topOffset = 0.1; |
---|
107 | //lineSpacing = 0.1; |
---|
108 | |
---|
109 | //for (unsigned int i = 0; i < this->lines_.size(); ++i) |
---|
110 | //{ |
---|
111 | // columnIndex = 0; |
---|
112 | // leftOffset = 0.1; |
---|
113 | |
---|
114 | // this->createlines_->setNumberOfColumns(numberOfColumns, i); |
---|
115 | |
---|
116 | // // columnText = this->getGametype()->getPlayersName(); |
---|
117 | // columnText = "PlayerName"; |
---|
118 | // this->createlines_->alignColumn(columnIndex, topOffset, leftOffset); |
---|
119 | // this->createlines_->setColumnText(columnIndex, columnText); |
---|
120 | |
---|
121 | // columnIndex++; |
---|
122 | // leftOffset = leftOffset + 0.3; |
---|
123 | |
---|
124 | // // columnText = this->getGametype()->getPlayersFrags(); |
---|
125 | // columnText = "PlayerFrags"; |
---|
126 | // this->createlines_->alignColumn(columnIndex, topOffset, leftOffset); |
---|
127 | // this->createlines_->setColumnText(columnIndex, columnText); |
---|
128 | |
---|
129 | // topOffset = topOffset + lineSpacing; |
---|
130 | //} |
---|
131 | } |
---|
132 | } |
---|