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 | * Johannes Ritz |
---|
24 | * Co-authors: |
---|
25 | * ... |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | /** |
---|
30 | @file CountDown.cc |
---|
31 | @brief Countdown HUD element, counting down from CountDown::counter_ to zero. |
---|
32 | |
---|
33 | In use it would like this: |
---|
34 | @code |
---|
35 | <OverlayGroup name="spacefightHUD" scale = "1, 1"> |
---|
36 | <CountDown |
---|
37 | position = "0.49, 0.05" |
---|
38 | pickpoint = "0.0, 0.0" |
---|
39 | font = "ShareTechMono" |
---|
40 | textsize = 0.06 |
---|
41 | colour = "1.0, 1.0, 1.0, 1.0" |
---|
42 | align = "right" |
---|
43 | counter = "10.0" |
---|
44 | active = "false" |
---|
45 | > |
---|
46 | <events> |
---|
47 | <activity> |
---|
48 | <EventListener event="startcounting" /> |
---|
49 | </activity> |
---|
50 | </events> |
---|
51 | </CountDown> |
---|
52 | </OverlayGroup> |
---|
53 | @endcode |
---|
54 | The counter is triggered by an event called "startcounting" and counts from 10 to 0. |
---|
55 | */ |
---|
56 | |
---|
57 | #include "CountDown.h" |
---|
58 | |
---|
59 | #include "core/CoreIncludes.h" |
---|
60 | #include "core/XMLPort.h" |
---|
61 | #include "infos/PlayerInfo.h" |
---|
62 | #include "util/Convert.h" |
---|
63 | |
---|
64 | namespace orxonox |
---|
65 | { |
---|
66 | RegisterClass(CountDown); |
---|
67 | |
---|
68 | CountDown::CountDown(Context* context) : OverlayText(context) |
---|
69 | { |
---|
70 | RegisterObject(CountDown); |
---|
71 | |
---|
72 | this->owner_ = 0; |
---|
73 | this->hasStopped_ = false; |
---|
74 | } |
---|
75 | |
---|
76 | CountDown::~CountDown() |
---|
77 | { |
---|
78 | } |
---|
79 | |
---|
80 | void CountDown::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
81 | { |
---|
82 | SUPER(CountDown, XMLPort, xmlelement, mode); |
---|
83 | XMLPortParam(CountDown, "counter", setCounter, getCounter, xmlelement, mode).defaultValues(10); |
---|
84 | } |
---|
85 | |
---|
86 | void CountDown::tick(float dt) |
---|
87 | { |
---|
88 | SUPER(CountDown, tick, dt); |
---|
89 | if (this->isActive() && !this->hasStopped_) |
---|
90 | { |
---|
91 | if (this->counter_ <= 0) |
---|
92 | { |
---|
93 | this->counter_ = 0; |
---|
94 | this->hasStopped_ = true; |
---|
95 | this->setCaption(""); |
---|
96 | } |
---|
97 | else |
---|
98 | { |
---|
99 | this->counter_ -= dt; |
---|
100 | this->setCaption(multi_cast<std::string>((int)this->counter_)); //TODO: evtl. initialize with +0.5f |
---|
101 | } |
---|
102 | } |
---|
103 | } |
---|
104 | |
---|
105 | void CountDown::changedOwner() |
---|
106 | { |
---|
107 | SUPER(CountDown, changedOwner); |
---|
108 | |
---|
109 | this->owner_ = orxonox_cast<PlayerInfo*>(this->getOwner()); |
---|
110 | } |
---|
111 | } |
---|