Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation2/src/modules/pong/PongScore.cc @ 6980

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

std::string tweaks:

  • Declared BLANKSTRING in UtilPrereqs.h as well (removed obsolete StringUtils.h includes to avoid dependencies)
  • Using BLANKSTRING if const std::string& return type is possible
  • Replaced a few (const) std::string arguments with const std::string&
  • if (str == "") —> if (str.empty())
  • std::string msg = name + "adsf"; —> const std::string& msg = name + "asdf";
  • std::string asdf = object→getFooBar(); —> const std::string& asdf = object→getFooBar();
  • std::string asdf = "asdf"; —> std::string asdf("asdf");
  • ostream << "."; and name + "." —> ostream << '.'; and name + '.'
  • str = ""; —> str.clear()
  • std::string asdf = ""; —> std::string asdf;
  • asdf_ = ""; (in c'tor) —> delete line
  • 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 "util/Convert.h"
32#include "core/CoreIncludes.h"
33#include "core/XMLPort.h"
34#include "Pong.h"
35#include "infos/PlayerInfo.h"
36
37namespace orxonox
38{
39    CreateFactory(PongScore);
40
41    PongScore::PongScore(BaseObject* creator) : OverlayText(creator)
42    {
43        RegisterObject(PongScore);
44
45        this->owner_ = 0;
46
47        this->bShowName_ = false;
48        this->bShowScore_ = false;
49        this->bShowLeftPlayer_ = false;
50        this->bShowRightPlayer_ = false;
51    }
52
53    PongScore::~PongScore()
54    {
55    }
56
57    void PongScore::XMLPort(Element& xmlelement, XMLPort::Mode mode)
58    {
59        SUPER(PongScore, XMLPort, xmlelement, mode);
60
61        XMLPortParam(PongScore, "showname",        setShowName,        getShowName,        xmlelement, mode).defaultValues(false);
62        XMLPortParam(PongScore, "showscore",       setShowScore,       getShowScore,       xmlelement, mode).defaultValues(false);
63        XMLPortParam(PongScore, "showleftplayer",  setShowLeftPlayer,  getShowLeftPlayer,  xmlelement, mode).defaultValues(false);
64        XMLPortParam(PongScore, "showrightplayer", setShowRightPlayer, getShowRightPlayer, xmlelement, mode).defaultValues(false);
65    }
66
67    void PongScore::tick(float dt)
68    {
69        SUPER(PongScore, tick, dt);
70
71        if (this->owner_)
72        {
73            PlayerInfo* player1 = this->owner_->getLeftPlayer();
74            PlayerInfo* player2 = this->owner_->getRightPlayer();
75
76            std::string name1;
77            std::string name2;
78
79            std::string score1("0");
80            std::string score2("0");
81
82            if (player1)
83            {
84                name1 = player1->getName();
85                score1 = multi_cast<std::string>(this->owner_->getScore(player1));
86            }
87
88            if (player2)
89            {
90                name2 = player2->getName();
91                score2 = multi_cast<std::string>(this->owner_->getScore(player2));
92            }
93
94            std::string output1;
95            if (this->bShowLeftPlayer_)
96            {
97                if (this->bShowName_ && this->bShowScore_ && player1)
98                    output1 = name1 + " - " + score1;
99                else if (this->bShowScore_)
100                    output1 = score1;
101                else if (this->bShowName_)
102                    output1 = name1;
103            }
104
105            std::string output2;
106            if (this->bShowRightPlayer_)
107            {
108                if (this->bShowName_ && this->bShowScore_ && player2)
109                    output2 = score2 + " - " + name2;
110                else if (this->bShowScore_)
111                    output2 = score2;
112                else if (this->bShowName_)
113                    output2 = name2;
114            }
115
116            std::string output("PONG");
117            if (this->bShowName_ || this->bShowScore_)
118            {
119                if (this->bShowLeftPlayer_ && this->bShowRightPlayer_)
120                    output = output1 + ':' + output2;
121                else if (this->bShowLeftPlayer_ || this->bShowRightPlayer_)
122                    output = output1 + output2;
123            }
124
125            this->setCaption(output);
126        }
127    }
128
129
130    void PongScore::changedOwner()
131    {
132        SUPER(PongScore, changedOwner);
133
134        if (this->getOwner() && this->getOwner()->getGametype())
135            this->owner_ = orxonox_cast<Pong*>(this->getOwner()->getGametype().get());
136        else
137            this->owner_ = 0;
138    }
139}
Note: See TracBrowser for help on using the repository browser.