Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Removed debug output.

  • Property svn:eol-style set to native
File size: 4.3 KB
RevLine 
[2225]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"
[2320]28#include "Scoreboard.h"
[2225]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"
[2320]40#include "objects/gametypes/Gametype.h"
[2495]41#include "objects/infos/PlayerInfo.h"
[2320]42#include "CreateLines.h"
[2225]43
44namespace orxonox
45{
46    CreateFactory(Scoreboard);
47
48    /**
[2320]49        @brief Constructor: Creates the scoreboard.
[2225]50    */
51    Scoreboard::Scoreboard(BaseObject* creator)
52        : OrxonoxOverlay(creator)
53    {
54        RegisterObject(Scoreboard);
55    }
56
[2320]57    /**
[2386]58        @brief Initializes the lines.
59    */
60    void Scoreboard::XMLPort(Element& xmlElement, XMLPort::Mode mode)
61    {
62        SUPER(Scoreboard, XMLPort, xmlElement, mode);
[2495]63    }
[2386]64
[2495]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());
[2386]71    }
72
73    /**
[2320]74        @brief Prints the scoreboard on the screen.
75    */
[2495]76    void Scoreboard::tick(float dt)
77    {
78        const std::map<PlayerInfo*, Player>& playerList = this->getGametype()->getPlayers();
[2320]79
[2495]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
[2498]88            CreateLines* lines = new CreateLines(leftOffset, topOffset + (distance + height) * lines_.size(), width, height);
89            lines->setVisibility(this->isVisible());
90            this->lines_.push_back(lines);
[2495]91        }
92        while (playerList.size() < this->lines_.size())
93        {
94            // destroy lines
95            delete this->lines_.back();
96            this->lines_.pop_back();
97        }
[2320]98
[2495]99        // update board
[2320]100
[2495]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        }
[2320]109
[2495]110        //numberOfColumns = 2;
111        //numberOfLines = 3;
112        //topOffset = 0.1;
113        //lineSpacing = 0.1;
[2320]114
[2495]115        //for (unsigned int i = 0; i < this->lines_.size(); ++i)
116        //{
117        //    columnIndex = 0;
118        //    leftOffset = 0.1;
[2320]119
[2495]120        //    this->createlines_->setNumberOfColumns(numberOfColumns, i);
[2320]121
[2498]122        //    // columnText = this->getGametype()->getPlayersName();
[2495]123        //    columnText = "PlayerName";
124        //    this->createlines_->alignColumn(columnIndex, topOffset, leftOffset);
125        //    this->createlines_->setColumnText(columnIndex, columnText);
[2320]126
[2495]127        //    columnIndex++;
128        //    leftOffset = leftOffset + 0.3;
[2320]129
[2498]130        //    // columnText = this->getGametype()->getPlayersFrags();
[2495]131        //    columnText = "PlayerFrags";
132        //    this->createlines_->alignColumn(columnIndex, topOffset, leftOffset);
133        //    this->createlines_->setColumnText(columnIndex, columnText);
[2320]134
[2495]135        //    topOffset = topOffset + lineSpacing;
136        //}
[2320]137    }
[2225]138}
Note: See TracBrowser for help on using the repository browser.