Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 2662 was 2662, checked in by rgrieder, 15 years ago

Merged presentation branch back to trunk.

  • Property svn:eol-style set to native
File size: 4.4 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        COUT(0) << "XMLPort executed." << std::endl;
65    }
66
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());
73    }
74
75    /**
76        @brief Prints the scoreboard on the screen.
77    */
78    void Scoreboard::tick(float dt)
79    {
80        const std::map<PlayerInfo*, Player>& playerList = this->getGametype()->getPlayers();
81
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
90            CreateLines* lines = new CreateLines(leftOffset, topOffset + (distance + height) * lines_.size(), width, height);
91            lines->setVisibility(this->isVisible());
92            this->lines_.push_back(lines);
93        }
94        while (playerList.size() < this->lines_.size())
95        {
96            // destroy lines
97            delete this->lines_.back();
98            this->lines_.pop_back();
99        }
100
101        // update board
102
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        }
111
112        //numberOfColumns = 2;
113        //numberOfLines = 3;
114        //topOffset = 0.1;
115        //lineSpacing = 0.1;
116
117        //for (unsigned int i = 0; i < this->lines_.size(); ++i)
118        //{
119        //    columnIndex = 0;
120        //    leftOffset = 0.1;
121
122        //    this->createlines_->setNumberOfColumns(numberOfColumns, i);
123
124        //    // columnText = this->getGametype()->getPlayersName();
125        //    columnText = "PlayerName";
126        //    this->createlines_->alignColumn(columnIndex, topOffset, leftOffset);
127        //    this->createlines_->setColumnText(columnIndex, columnText);
128
129        //    columnIndex++;
130        //    leftOffset = leftOffset + 0.3;
131
132        //    // columnText = this->getGametype()->getPlayersFrags();
133        //    columnText = "PlayerFrags";
134        //    this->createlines_->alignColumn(columnIndex, topOffset, leftOffset);
135        //    this->createlines_->setColumnText(columnIndex, columnText);
136
137        //    topOffset = topOffset + lineSpacing;
138        //}
139    }
140}
Note: See TracBrowser for help on using the repository browser.