Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/chat/src/modules/overlays/stats/Scoreboard.cc @ 7027

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

Removed a ton of msvc warnings revealed with OGRE v1.7 (they removed the warning suppressors in OgrePrerequisites.h).
All of them are conversions from one type to another that might be lossy (mostly double to float, please always use "3.7f" instead of "3.7" as constants when using floats).

  • 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]->changedVisibility();
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.2f;
82        const float leftOffset = 0.075f;
83        const float distance   = 0.01f;
84        const float width      = 0.85f;
85        const float height     = 0.05f;
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            lines->setOverlayGroup( this->getOverlayGroup() );
92            this->lines_.push_back(lines);
93        }
94        while (playerList.size() < this->lines_.size())
95        {
96            // destroy lines
97            delete this->lines_.back();
98            this->lines_.pop_back();
99        }
100
101        // update board
102
103        unsigned int index = 0;
104        for (std::map<PlayerInfo*, Player>::const_iterator it = playerList.begin(); it != playerList.end(); ++it)
105        {
106            this->lines_[index]->setPlayerName(multi_cast<std::string>(it->first->getName()));
107            this->lines_[index]->setScore(multi_cast<std::string>(it->second.frags_));
108            this->lines_[index]->setDeaths(multi_cast<std::string>(it->second.killed_));
109            index++;
110        }
111
112        //numberOfColumns = 2;
113        //numberOfLines = 3;
114        //topOffset = 0.1;
115        //lineSpacing = 0.1;
116
117        //for (unsigned int i = 0; i < this->lines_.size(); ++i)
118        //{
119        //    columnIndex = 0;
120        //    leftOffset = 0.1;
121
122        //    this->createlines_->setNumberOfColumns(numberOfColumns, i);
123
124        //    // columnText = this->getGametype()->getPlayersName();
125        //    columnText = "PlayerName";
126        //    this->createlines_->alignColumn(columnIndex, topOffset, leftOffset);
127        //    this->createlines_->setColumnText(columnIndex, columnText);
128
129        //    columnIndex++;
130        //    leftOffset = leftOffset + 0.3;
131
132        //    // columnText = this->getGametype()->getPlayersFrags();
133        //    columnText = "PlayerFrags";
134        //    this->createlines_->alignColumn(columnIndex, topOffset, leftOffset);
135        //    this->createlines_->setColumnText(columnIndex, columnText);
136
137        //    topOffset = topOffset + lineSpacing;
138        //}
139    }
140}
Note: See TracBrowser for help on using the repository browser.