Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/overlays/stats/Scoreboard.cc @ 11071

Last change on this file since 11071 was 11071, checked in by landauf, 8 years ago

merged branch cpp11_v3 back to trunk

  • Property svn:eol-style set to native
File size: 4.1 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
[2320]27#include "Scoreboard.h"
[2225]28
29#include "util/Convert.h"
30#include "core/CoreIncludes.h"
[5735]31#include "gametypes/Gametype.h"
32#include "infos/PlayerInfo.h"
[2320]33#include "CreateLines.h"
[2225]34
35namespace orxonox
36{
[9667]37    RegisterClass(Scoreboard);
[2225]38
39    /**
[2320]40        @brief Constructor: Creates the scoreboard.
[2225]41    */
[9667]42    Scoreboard::Scoreboard(Context* context)
43        : OrxonoxOverlay(context)
[2225]44    {
45        RegisterObject(Scoreboard);
46    }
47
[5929]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
[2495]58    void Scoreboard::changedVisibility()
59    {
60        SUPER(Scoreboard, changedVisibility);
61
[11071]62        for (CreateLines* line : this->lines_)
63            line->changedVisibility();
[2386]64    }
65
66    /**
[2320]67        @brief Prints the scoreboard on the screen.
68    */
[2495]69    void Scoreboard::tick(float dt)
70    {
71        const std::map<PlayerInfo*, Player>& playerList = this->getGametype()->getPlayers();
[2320]72
[6502]73        const float topOffset  = 0.2f;
74        const float leftOffset = 0.075f;
75        const float distance   = 0.01f;
76        const float width      = 0.85f;
77        const float height     = 0.05f;
[2495]78        while (playerList.size() > this->lines_.size())
79        {
80            // create new lines
[2498]81            CreateLines* lines = new CreateLines(leftOffset, topOffset + (distance + height) * lines_.size(), width, height);
82            lines->setVisibility(this->isVisible());
[5980]83            lines->setOverlayGroup( this->getOverlayGroup() );
[2498]84            this->lines_.push_back(lines);
[2495]85        }
86        while (playerList.size() < this->lines_.size())
87        {
88            // destroy lines
89            delete this->lines_.back();
90            this->lines_.pop_back();
91        }
[2320]92
[2495]93        // update board
[2320]94
[2495]95        unsigned int index = 0;
[11071]96        for (const auto& mapEntry : playerList)
[2495]97        {
[11071]98            this->lines_[index]->setPlayerName(multi_cast<std::string>(mapEntry.first->getName()));
99            this->lines_[index]->setScore(multi_cast<std::string>(mapEntry.second.frags_));
100            this->lines_[index]->setDeaths(multi_cast<std::string>(mapEntry.second.killed_));
[2495]101            index++;
102        }
[2320]103
[2495]104        //numberOfColumns = 2;
105        //numberOfLines = 3;
106        //topOffset = 0.1;
107        //lineSpacing = 0.1;
[2320]108
[2495]109        //for (unsigned int i = 0; i < this->lines_.size(); ++i)
110        //{
111        //    columnIndex = 0;
112        //    leftOffset = 0.1;
[2320]113
[2495]114        //    this->createlines_->setNumberOfColumns(numberOfColumns, i);
[2320]115
[2498]116        //    // columnText = this->getGametype()->getPlayersName();
[2495]117        //    columnText = "PlayerName";
118        //    this->createlines_->alignColumn(columnIndex, topOffset, leftOffset);
119        //    this->createlines_->setColumnText(columnIndex, columnText);
[2320]120
[2495]121        //    columnIndex++;
122        //    leftOffset = leftOffset + 0.3;
[2320]123
[2498]124        //    // columnText = this->getGametype()->getPlayersFrags();
[2495]125        //    columnText = "PlayerFrags";
126        //    this->createlines_->alignColumn(columnIndex, topOffset, leftOffset);
127        //    this->createlines_->setColumnText(columnIndex, columnText);
[2320]128
[2495]129        //    topOffset = topOffset + lineSpacing;
130        //}
[2320]131    }
[2225]132}
Note: See TracBrowser for help on using the repository browser.