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 | /** |
---|
30 | @file OrxoBloxScore.cc |
---|
31 | @brief Implementation of the OrxoBloxScore class. |
---|
32 | */ |
---|
33 | |
---|
34 | #include "OrxoBloxScore.h" |
---|
35 | |
---|
36 | #include "core/CoreIncludes.h" |
---|
37 | #include "core/XMLPort.h" |
---|
38 | #include "util/Convert.h" |
---|
39 | |
---|
40 | #include "infos/PlayerInfo.h" |
---|
41 | |
---|
42 | #include "OrxoBlox.h" |
---|
43 | #include "sound/WorldSound.h" ///////////////////////////// |
---|
44 | |
---|
45 | namespace orxonox |
---|
46 | { |
---|
47 | RegisterClass(OrxoBloxScore); |
---|
48 | |
---|
49 | /** |
---|
50 | @brief |
---|
51 | Constructor. Registers and initializes the object. |
---|
52 | */ |
---|
53 | OrxoBloxScore::OrxoBloxScore(Context* context) : OverlayText(context) |
---|
54 | { |
---|
55 | RegisterObject(OrxoBloxScore); |
---|
56 | |
---|
57 | this->owner_ = nullptr; |
---|
58 | |
---|
59 | this->bShowName_ = true; |
---|
60 | this->bShowScore_ = true; |
---|
61 | this->bShowPlayer_ = true; |
---|
62 | } |
---|
63 | |
---|
64 | /** |
---|
65 | @brief |
---|
66 | Destructor. |
---|
67 | */ |
---|
68 | OrxoBloxScore::~OrxoBloxScore() |
---|
69 | { |
---|
70 | } |
---|
71 | |
---|
72 | /** |
---|
73 | @brief |
---|
74 | Method to create a OrxoBloxScore through XML. |
---|
75 | */ |
---|
76 | void OrxoBloxScore::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
77 | { |
---|
78 | SUPER(OrxoBloxScore, XMLPort, xmlelement, mode); |
---|
79 | |
---|
80 | XMLPortParam(OrxoBloxScore, "showname", setShowName, getShowName, xmlelement, mode).defaultValues(false); |
---|
81 | XMLPortParam(OrxoBloxScore, "showscore", setShowScore, getShowScore, xmlelement, mode).defaultValues(false); |
---|
82 | XMLPortParam(OrxoBloxScore, "showplayer", setShowPlayer, getShowPlayer, xmlelement, mode).defaultValues(false); |
---|
83 | } |
---|
84 | |
---|
85 | /** |
---|
86 | @brief |
---|
87 | Is called each tick. |
---|
88 | Creates and sets the caption to be displayed by the OrxoBloxScore. |
---|
89 | @param dt |
---|
90 | The time that has elapsed since the last tick. |
---|
91 | */ |
---|
92 | void OrxoBloxScore::tick(float dt) |
---|
93 | { |
---|
94 | SUPER(OrxoBloxScore, tick, dt); |
---|
95 | |
---|
96 | // If the owner is set. The owner being a OrxoBlox game. |
---|
97 | if (this->owner_ != nullptr) |
---|
98 | { |
---|
99 | if (!this->owner_->hasEnded()) |
---|
100 | { |
---|
101 | // Get the player. |
---|
102 | //Fehlermeldung |
---|
103 | //player1_ = this->owner_->getPlayer(); |
---|
104 | } |
---|
105 | |
---|
106 | std::string name1; |
---|
107 | |
---|
108 | std::string score1("0"); |
---|
109 | |
---|
110 | // Save the name and score of each player as a string. |
---|
111 | if (player1_ != nullptr) |
---|
112 | { |
---|
113 | name1 = player1_->getName(); |
---|
114 | score1 = multi_cast<std::string>(this->owner_->getScore(player1_)); |
---|
115 | } |
---|
116 | |
---|
117 | // Assemble the strings, depending on what should all be displayed. |
---|
118 | std::string output1; |
---|
119 | if (this->bShowPlayer_) |
---|
120 | { |
---|
121 | if (this->bShowName_ && this->bShowScore_ && player1_ != nullptr) |
---|
122 | output1 = name1 + " - " + score1; |
---|
123 | else if (this->bShowScore_) |
---|
124 | output1 = score1; |
---|
125 | else if (this->bShowName_) |
---|
126 | output1 = name1; |
---|
127 | } |
---|
128 | |
---|
129 | std::string output("OrxoBlox"); |
---|
130 | /* Keine Ahnung wofuer das gut ist. |
---|
131 | |
---|
132 | if (this->bShowName_ || this->bShowScore_) |
---|
133 | { |
---|
134 | if (this->bShowLeftPlayer_ && this->bShowRightPlayer_) |
---|
135 | output = output1 + ':' + output2; |
---|
136 | else if (this->bShowLeftPlayer_ || this->bShowRightPlayer_) |
---|
137 | output = output1 + output2; |
---|
138 | }*/ |
---|
139 | |
---|
140 | this->setCaption(output); |
---|
141 | } |
---|
142 | } |
---|
143 | |
---|
144 | /** |
---|
145 | @brief |
---|
146 | Is called when the owner changes. |
---|
147 | Sets the owner to nullptr, if it is not a pointer to a OrxoBlox game. |
---|
148 | */ |
---|
149 | void OrxoBloxScore::changedOwner() |
---|
150 | { |
---|
151 | SUPER(OrxoBloxScore, changedOwner); |
---|
152 | |
---|
153 | if (this->getOwner() != nullptr && this->getOwner()->getGametype()) |
---|
154 | this->owner_ = orxonox_cast<OrxoBlox*>(this->getOwner()->getGametype()); |
---|
155 | else |
---|
156 | this->owner_ = nullptr; |
---|
157 | } |
---|
158 | } |
---|