Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Removed old msvc specific support for precompiled header files.

  • Property svn:eol-style set to native
File size: 4.3 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 "PongScore.h"
30
31#include <OgreTextAreaOverlayElement.h>
32
33#include "core/CoreIncludes.h"
34#include "core/XMLPort.h"
35#include "util/Convert.h"
36#include "objects/gametypes/Pong.h"
37#include "objects/infos/PlayerInfo.h"
38
39namespace orxonox
40{
41    CreateFactory(PongScore);
42
43    PongScore::PongScore(BaseObject* creator) : OverlayText(creator)
44    {
45        RegisterObject(PongScore);
46
47        this->owner_ = 0;
48
49        this->bShowName_ = false;
50        this->bShowScore_ = false;
51        this->bShowLeftPlayer_ = false;
52        this->bShowRightPlayer_ = false;
53    }
54
55    PongScore::~PongScore()
56    {
57    }
58
59    void PongScore::XMLPort(Element& xmlelement, XMLPort::Mode mode)
60    {
61        SUPER(PongScore, XMLPort, xmlelement, mode);
62
63        XMLPortParam(PongScore, "showname",        setShowName,        getShowName,        xmlelement, mode).defaultValues(false);
64        XMLPortParam(PongScore, "showscore",       setShowScore,       getShowScore,       xmlelement, mode).defaultValues(false);
65        XMLPortParam(PongScore, "showleftplayer",  setShowLeftPlayer,  getShowLeftPlayer,  xmlelement, mode).defaultValues(false);
66        XMLPortParam(PongScore, "showrightplayer", setShowRightPlayer, getShowRightPlayer, xmlelement, mode).defaultValues(false);
67    }
68
69    void PongScore::tick(float dt)
70    {
71        SUPER(PongScore, tick, dt);
72
73        if (this->owner_)
74        {
75            PlayerInfo* player1 = this->owner_->getLeftPlayer();
76            PlayerInfo* player2 = this->owner_->getRightPlayer();
77
78            std::string name1;
79            std::string name2;
80
81            std::string score1 = "0";
82            std::string score2 = "0";
83
84            if (player1)
85            {
86                name1 = player1->getName();
87                score1 = convertToString(this->owner_->getScore(player1));
88            }
89
90            if (player2)
91            {
92                name2 = player2->getName();
93                score2 = convertToString(this->owner_->getScore(player2));
94            }
95
96            std::string output1;
97            if (this->bShowLeftPlayer_)
98            {
99                if (this->bShowName_ && this->bShowScore_ && player1)
100                    output1 = name1 + " - " + score1;
101                else if (this->bShowScore_)
102                    output1 = score1;
103                else if (this->bShowName_)
104                    output1 = name1;
105            }
106
107            std::string output2;
108            if (this->bShowRightPlayer_)
109            {
110                if (this->bShowName_ && this->bShowScore_ && player2)
111                    output2 = score2 + " - " + name2;
112                else if (this->bShowScore_)
113                    output2 = score2;
114                else if (this->bShowName_)
115                    output2 = name2;
116            }
117
118            std::string output = "PONG";
119            if (this->bShowName_ || this->bShowScore_)
120            {
121                if (this->bShowLeftPlayer_ && this->bShowRightPlayer_)
122                    output = output1 + ":" + output2;
123                else if (this->bShowLeftPlayer_ || this->bShowRightPlayer_)
124                    output = output1 + output2;
125            }
126
127            this->setCaption(output);
128        }
129    }
130
131
132    void PongScore::changedOwner()
133    {
134        SUPER(PongScore, changedOwner);
135
136        if (this->getOwner() && this->getOwner()->getGametype())
137            this->owner_ = dynamic_cast<Pong*>(this->getOwner()->getGametype());
138        else
139            this->owner_ = 0;
140    }
141}
Note: See TracBrowser for help on using the repository browser.