Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core5/src/modules/overlays/stats/Scoreboard.cc @ 5818

Last change on this file since 5818 was 5818, checked in by rgrieder, 15 years ago

Small bugfix for the second to last commit: InputStates only exist in graphics mode.
And added destruction code for the ScoreBoard.

  • Property svn:eol-style set to native
File size: 4.3 KB
Line 
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
35namespace 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    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    /**
59        @brief Initializes the lines.
60    */
61    void Scoreboard::XMLPort(Element& xmlElement, XMLPort::Mode mode)
62    {
63        SUPER(Scoreboard, XMLPort, xmlElement, mode);
64    }
65
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());
72    }
73
74    /**
75        @brief Prints the scoreboard on the screen.
76    */
77    void Scoreboard::tick(float dt)
78    {
79        const std::map<PlayerInfo*, Player>& playerList = this->getGametype()->getPlayers();
80
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
89            CreateLines* lines = new CreateLines(leftOffset, topOffset + (distance + height) * lines_.size(), width, height);
90            lines->setVisibility(this->isVisible());
91            this->lines_.push_back(lines);
92        }
93        while (playerList.size() < this->lines_.size())
94        {
95            // destroy lines
96            delete this->lines_.back();
97            this->lines_.pop_back();
98        }
99
100        // update board
101
102        unsigned int index = 0;
103        for (std::map<PlayerInfo*, Player>::const_iterator it = playerList.begin(); it != playerList.end(); ++it)
104        {
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_));
108            index++;
109        }
110
111        //numberOfColumns = 2;
112        //numberOfLines = 3;
113        //topOffset = 0.1;
114        //lineSpacing = 0.1;
115
116        //for (unsigned int i = 0; i < this->lines_.size(); ++i)
117        //{
118        //    columnIndex = 0;
119        //    leftOffset = 0.1;
120
121        //    this->createlines_->setNumberOfColumns(numberOfColumns, i);
122
123        //    // columnText = this->getGametype()->getPlayersName();
124        //    columnText = "PlayerName";
125        //    this->createlines_->alignColumn(columnIndex, topOffset, leftOffset);
126        //    this->createlines_->setColumnText(columnIndex, columnText);
127
128        //    columnIndex++;
129        //    leftOffset = leftOffset + 0.3;
130
131        //    // columnText = this->getGametype()->getPlayersFrags();
132        //    columnText = "PlayerFrags";
133        //    this->createlines_->alignColumn(columnIndex, topOffset, leftOffset);
134        //    this->createlines_->setColumnText(columnIndex, columnText);
135
136        //    topOffset = topOffset + lineSpacing;
137        //}
138    }
139}
Note: See TracBrowser for help on using the repository browser.