Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/overlays/hud/PongScore.cc @ 2949

Last change on this file since 2949 was 2890, checked in by landauf, 16 years ago
  • Added overlay element for the Pong Gametype
  • Changed the type of the overlay's owner to BaseObject (former ControllableEntity) to allow other classes to own an overlay (for example a Gametype)
  • OverlayGroup does now use a std::set instead of a std::map to store it's overlay elements. Therefore a name is not anymore compulsory for an overlay element.
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 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "OrxonoxStableHeaders.h"
30#include "PongScore.h"
31
32#include <OgreTextAreaOverlayElement.h>
33
34#include "core/CoreIncludes.h"
35#include "core/XMLPort.h"
36#include "util/Convert.h"
37#include "objects/gametypes/Pong.h"
38#include "objects/infos/PlayerInfo.h"
39
40namespace orxonox
41{
42    CreateFactory(PongScore);
43
44    PongScore::PongScore(BaseObject* creator) : OverlayText(creator)
45    {
46        RegisterObject(PongScore);
47
48        this->owner_ = 0;
49
50        this->bShowName_ = false;
51        this->bShowScore_ = false;
52        this->bShowLeftPlayer_ = false;
53        this->bShowRightPlayer_ = false;
54    }
55
56    PongScore::~PongScore()
57    {
58    }
59
60    void PongScore::XMLPort(Element& xmlelement, XMLPort::Mode mode)
61    {
62        SUPER(PongScore, XMLPort, xmlelement, mode);
63
64        XMLPortParam(PongScore, "showname",        setShowName,        getShowName,        xmlelement, mode).defaultValues(false);
65        XMLPortParam(PongScore, "showscore",       setShowScore,       getShowScore,       xmlelement, mode).defaultValues(false);
66        XMLPortParam(PongScore, "showleftplayer",  setShowLeftPlayer,  getShowLeftPlayer,  xmlelement, mode).defaultValues(false);
67        XMLPortParam(PongScore, "showrightplayer", setShowRightPlayer, getShowRightPlayer, xmlelement, mode).defaultValues(false);
68    }
69
70    void PongScore::tick(float dt)
71    {
72        SUPER(PongScore, tick, dt);
73
74        if (this->owner_)
75        {
76            PlayerInfo* player1 = this->owner_->getLeftPlayer();
77            PlayerInfo* player2 = this->owner_->getRightPlayer();
78
79            std::string name1;
80            std::string name2;
81
82            std::string score1 = "0";
83            std::string score2 = "0";
84
85            if (player1)
86            {
87                name1 = player1->getName();
88                score1 = convertToString(this->owner_->getScore(player1));
89            }
90
91            if (player2)
92            {
93                name2 = player2->getName();
94                score2 = convertToString(this->owner_->getScore(player2));
95            }
96
97            std::string output1;
98            if (this->bShowLeftPlayer_)
99            {
100                if (this->bShowName_ && this->bShowScore_ && player1)
101                    output1 = name1 + " - " + score1;
102                else if (this->bShowScore_)
103                    output1 = score1;
104                else if (this->bShowName_)
105                    output1 = name1;
106            }
107
108            std::string output2;
109            if (this->bShowRightPlayer_)
110            {
111                if (this->bShowName_ && this->bShowScore_ && player2)
112                    output2 = score2 + " - " + name2;
113                else if (this->bShowScore_)
114                    output2 = score2;
115                else if (this->bShowName_)
116                    output2 = name2;
117            }
118
119            std::string output = "PONG";
120            if (this->bShowName_ || this->bShowScore_)
121            {
122                if (this->bShowLeftPlayer_ && this->bShowRightPlayer_)
123                    output = output1 + ":" + output2;
124                else if (this->bShowLeftPlayer_ || this->bShowRightPlayer_)
125                    output = output1 + output2;
126            }
127
128            this->setCaption(output);
129        }
130    }
131
132
133    void PongScore::changedOwner()
134    {
135        SUPER(PongScore, changedOwner);
136
137        this->owner_ = dynamic_cast<Pong*>(this->getOwner());
138    }
139}
Note: See TracBrowser for help on using the repository browser.