Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/overlays/hud/TeamBaseMatchScore.cc @ 3104

Last change on this file since 3104 was 3104, checked in by landauf, 15 years ago

Added two new HUD-elements for TeamBaseMatch and UnderAttack

  • Property svn:eol-style set to native
File size: 4.2 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 "TeamBaseMatchScore.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/TeamBaseMatch.h"
38#include "objects/infos/PlayerInfo.h"
39
40namespace orxonox
41{
42    CreateFactory(TeamBaseMatchScore);
43
44    TeamBaseMatchScore::TeamBaseMatchScore(BaseObject* creator) : OverlayText(creator)
45    {
46        RegisterObject(TeamBaseMatchScore);
47
48        this->owner_ = 0;
49
50        this->bShowBases_ = false;
51        this->bShowScore_ = false;
52        this->bShowLeftTeam_ = false;
53        this->bShowRightTeam_ = false;
54    }
55
56    TeamBaseMatchScore::~TeamBaseMatchScore()
57    {
58    }
59
60    void TeamBaseMatchScore::XMLPort(Element& xmlelement, XMLPort::Mode mode)
61    {
62        SUPER(TeamBaseMatchScore, XMLPort, xmlelement, mode);
63
64        XMLPortParam(TeamBaseMatchScore, "showbases",     setShowBases,     getShowBases,     xmlelement, mode).defaultValues(false);
65        XMLPortParam(TeamBaseMatchScore, "showscore",     setShowScore,     getShowScore,     xmlelement, mode).defaultValues(false);
66        XMLPortParam(TeamBaseMatchScore, "showleftteam",  setShowLeftTeam,  getShowLeftTeam,  xmlelement, mode).defaultValues(false);
67        XMLPortParam(TeamBaseMatchScore, "showrightteam", setShowRightTeam, getShowRightTeam, xmlelement, mode).defaultValues(false);
68    }
69
70    void TeamBaseMatchScore::tick(float dt)
71    {
72        SUPER(TeamBaseMatchScore, tick, dt);
73
74        if (this->owner_)
75        {
76            std::string bases1 = "(" + convertToString(this->owner_->getTeamBases(0)) + ")";
77            std::string bases2 = "(" + convertToString(this->owner_->getTeamBases(1)) + ")";
78
79            std::string score1 = convertToString(this->owner_->getTeamPoints(0));
80            std::string score2 = convertToString(this->owner_->getTeamPoints(1));
81
82            std::string output1;
83            if (this->bShowLeftTeam_)
84            {
85                if (this->bShowBases_ && this->bShowScore_)
86                    output1 = bases1 + " - " + score1;
87                else if (this->bShowScore_)
88                    output1 = score1;
89                else if (this->bShowBases_)
90                    output1 = bases1;
91            }
92
93            std::string output2;
94            if (this->bShowRightTeam_)
95            {
96                if (this->bShowBases_ && this->bShowScore_)
97                    output2 = score2 + " - " + bases2;
98                else if (this->bShowScore_)
99                    output2 = score2;
100                else if (this->bShowBases_)
101                    output2 = bases2;
102            }
103
104            std::string output = "";
105            if (this->bShowBases_ || this->bShowScore_)
106            {
107                if (this->bShowLeftTeam_ && this->bShowRightTeam_)
108                    output = output1 + ":" + output2;
109                else if (this->bShowLeftTeam_ || this->bShowRightTeam_)
110                    output = output1 + output2;
111            }
112
113            this->setCaption(output);
114        }
115    }
116
117
118    void TeamBaseMatchScore::changedOwner()
119    {
120        SUPER(TeamBaseMatchScore, changedOwner);
121
122        if (this->getOwner() && this->getOwner()->getGametype())
123            this->owner_ = dynamic_cast<TeamBaseMatch*>(this->getOwner()->getGametype());
124        else
125            this->owner_ = 0;
126    }
127}
Note: See TracBrowser for help on using the repository browser.