Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/overlays/stats/Scoreboard.cc @ 3180

Last change on this file since 3180 was 3110, checked in by rgrieder, 16 years ago

Removed old msvc specific support for precompiled header files.

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