Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 2802 was 2731, checked in by rgrieder, 16 years ago

Removed debug output.

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