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 | * Florian Zinggeler |
---|
24 | * |
---|
25 | */ |
---|
26 | |
---|
27 | #include "SOBHUDInfo.h" |
---|
28 | |
---|
29 | #include "core/CoreIncludes.h" |
---|
30 | #include "core/XMLPort.h" |
---|
31 | #include "util/Convert.h" |
---|
32 | #include "SOB.h" |
---|
33 | #include <sstream> |
---|
34 | #include <iomanip> |
---|
35 | |
---|
36 | |
---|
37 | |
---|
38 | namespace orxonox |
---|
39 | { |
---|
40 | RegisterClass(SOBHUDInfo); |
---|
41 | |
---|
42 | SOBHUDInfo::SOBHUDInfo(Context* context) : OverlayText(context) |
---|
43 | { |
---|
44 | RegisterObject(SOBHUDInfo); |
---|
45 | |
---|
46 | this->SOBGame = nullptr; |
---|
47 | |
---|
48 | } |
---|
49 | |
---|
50 | void SOBHUDInfo::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
51 | { |
---|
52 | SUPER(SOBHUDInfo, XMLPort, xmlelement, mode); |
---|
53 | XMLPortParam(SOBHUDInfo, "type", setType, getType, xmlelement, mode).defaultValues(false); |
---|
54 | |
---|
55 | |
---|
56 | } |
---|
57 | |
---|
58 | void SOBHUDInfo::tick(float dt) |
---|
59 | { |
---|
60 | SUPER(SOBHUDInfo, tick, dt); |
---|
61 | |
---|
62 | if (this->SOBGame) |
---|
63 | { |
---|
64 | |
---|
65 | // setPosition(Vector2(0.1, 0.65)); |
---|
66 | if (this->type_ == "Coins") { |
---|
67 | // this->setCaption("Game ends in 30 seconds.\nPress (e)xit / (q)uit to go to the main menu.\nTo restart fly out of the screen!"); |
---|
68 | |
---|
69 | |
---|
70 | std::stringstream ss; |
---|
71 | ss << "cc x " << std::setw(2) << std::setfill('0') << SOBGame->getCoins(); |
---|
72 | std::string s = ss.str(); |
---|
73 | |
---|
74 | this->setCaption(s); |
---|
75 | |
---|
76 | } |
---|
77 | if (this->type_ == "Points") { |
---|
78 | std::stringstream ss; |
---|
79 | ss << std::setw(6) << std::setfill('0') << SOBGame->getPoints(); |
---|
80 | std::string s = ss.str(); |
---|
81 | this->setCaption(s); |
---|
82 | } |
---|
83 | if (this->type_ == "Time") { |
---|
84 | std::stringstream ss; |
---|
85 | ss << SOBGame->getTimeLeft(); |
---|
86 | std::string s = ss.str(); |
---|
87 | this->setCaption(s); |
---|
88 | } |
---|
89 | |
---|
90 | |
---|
91 | |
---|
92 | // const std::string& Level = multi_cast<std::string>(this->SOBGame->getLevel()); |
---|
93 | // if (this->SOBGame->lives <= 0) |
---|
94 | // { |
---|
95 | // setPosition(Vector2(0.1, 0.65)); |
---|
96 | // this->setCaption("Game ends in 30 seconds.\nPress (e)xit / (q)uit to go to the main menu.\nTo restart fly out of the screen!"); |
---|
97 | // setTextSize(0.05); |
---|
98 | // this->SOBGame->bEndGame = true; |
---|
99 | // } |
---|
100 | // else if (this->SOBGame->bShowLevel) |
---|
101 | // { |
---|
102 | // setTextSize(0.1); |
---|
103 | // setPosition(Vector2(0.3, 0.55)); |
---|
104 | // std::stringstream sstm; |
---|
105 | // sstm << "Level " << Level; |
---|
106 | // this->setCaption(sstm.str()); // + level |
---|
107 | // } |
---|
108 | // else |
---|
109 | // { |
---|
110 | // setTextSize(0.04); |
---|
111 | // setPosition(Vector2(0.14, 0.055)); |
---|
112 | // this->setCaption(Level); |
---|
113 | // } |
---|
114 | // //////////// |
---|
115 | // const std::string& points = multi_cast<std::string>(this->SOBGame->getPoints()); |
---|
116 | // if (this->SOBGame->lives <= 0) |
---|
117 | // { |
---|
118 | // setTextSize(0.2); |
---|
119 | // setPosition(Vector2(0.1, 0.25)); |
---|
120 | // this->setCaption("Final score:\n" + points); |
---|
121 | // this->setColour(ColourValue(1, 0, 0, 1)); |
---|
122 | // } |
---|
123 | // else |
---|
124 | // { |
---|
125 | // setTextSize(0.04); |
---|
126 | // setPosition(Vector2(0.14, 0.1)); |
---|
127 | // this->setColour(ColourValue(1, 1, 1, 1)); |
---|
128 | // this->setCaption(points); |
---|
129 | // } |
---|
130 | |
---|
131 | // ///////////// |
---|
132 | // int mult = this->SOBGame->getMultiplier(); |
---|
133 | // const std::string& Multiplier = "X " + multi_cast<std::string>(mult); |
---|
134 | // this->setCaption(Multiplier); |
---|
135 | // this->setColour(ColourValue(1, 0, 0, clamp(float(mult * 0.1), 0.0f, 1.0f))); |
---|
136 | // this->setTextSize(clamp(float(mult * 0.1), 0.0f, 1.0f) * 0.01f + 0.04f); |
---|
137 | |
---|
138 | } |
---|
139 | } |
---|
140 | |
---|
141 | void SOBHUDInfo::changedOwner() |
---|
142 | { |
---|
143 | SUPER(SOBHUDInfo, changedOwner); |
---|
144 | |
---|
145 | if (this->getOwner() && this->getOwner()->getGametype()) |
---|
146 | { |
---|
147 | this->SOBGame = orxonox_cast<SOB*>(this->getOwner()->getGametype()); |
---|
148 | } |
---|
149 | else |
---|
150 | { |
---|
151 | this->SOBGame = nullptr; |
---|
152 | } |
---|
153 | } |
---|
154 | } |
---|