Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation/src/orxonox/overlays/stats/Scoreboard.cc @ 2499

Last change on this file since 2499 was 2498, checked in by landauf, 16 years ago

removed additional gametype_ from scoreboard
initialize scoreboard lines with visible=false

  • Property svn:eol-style set to native
File size: 4.4 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);
63
64        COUT(0) << "XMLPort executed." << std::endl;
[2495]65    }
[2386]66
[2495]67    void Scoreboard::changedVisibility()
68    {
69        SUPER(Scoreboard, changedVisibility);
70
71        for (unsigned int i = 0; i < this->lines_.size(); ++i)
72            this->lines_[i]->setVisibility(this->isVisible());
[2386]73    }
74
75    /**
[2320]76        @brief Prints the scoreboard on the screen.
77    */
[2495]78    void Scoreboard::tick(float dt)
79    {
80        const std::map<PlayerInfo*, Player>& playerList = this->getGametype()->getPlayers();
[2320]81
[2495]82        const float topOffset  = 0.2;
83        const float leftOffset = 0.075;
84        const float distance   = 0.01;
85        const float width      = 0.85;
86        const float height     = 0.05;
87        while (playerList.size() > this->lines_.size())
88        {
89            // create new lines
[2498]90            CreateLines* lines = new CreateLines(leftOffset, topOffset + (distance + height) * lines_.size(), width, height);
91            lines->setVisibility(this->isVisible());
92            this->lines_.push_back(lines);
[2495]93        }
94        while (playerList.size() < this->lines_.size())
95        {
96            // destroy lines
97            delete this->lines_.back();
98            this->lines_.pop_back();
99        }
[2320]100
[2495]101        // update board
[2320]102
[2495]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(omni_cast<std::string>(it->first->getName()));
107            this->lines_[index]->setScore(omni_cast<std::string>(it->second.frags_));
108            this->lines_[index]->setDeaths(omni_cast<std::string>(it->second.killed_));
109            index++;
110        }
[2320]111
[2495]112        //numberOfColumns = 2;
113        //numberOfLines = 3;
114        //topOffset = 0.1;
115        //lineSpacing = 0.1;
[2320]116
[2495]117        //for (unsigned int i = 0; i < this->lines_.size(); ++i)
118        //{
119        //    columnIndex = 0;
120        //    leftOffset = 0.1;
[2320]121
[2495]122        //    this->createlines_->setNumberOfColumns(numberOfColumns, i);
[2320]123
[2498]124        //    // columnText = this->getGametype()->getPlayersName();
[2495]125        //    columnText = "PlayerName";
126        //    this->createlines_->alignColumn(columnIndex, topOffset, leftOffset);
127        //    this->createlines_->setColumnText(columnIndex, columnText);
[2320]128
[2495]129        //    columnIndex++;
130        //    leftOffset = leftOffset + 0.3;
[2320]131
[2498]132        //    // columnText = this->getGametype()->getPlayersFrags();
[2495]133        //    columnText = "PlayerFrags";
134        //    this->createlines_->alignColumn(columnIndex, topOffset, leftOffset);
135        //    this->createlines_->setColumnText(columnIndex, columnText);
[2320]136
[2495]137        //    topOffset = topOffset + lineSpacing;
138        //}
[2320]139    }
[2225]140}
Note: See TracBrowser for help on using the repository browser.