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