Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/hoverHS15/src/modules/hover/TimeHUD.cc @ 10926

Last change on this file since 10926 was 10900, checked in by meierman, 9 years ago

Judihui it works

File size: 2.7 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 *      Cyrill Burgener
24 *
25 */
26
27#include "TimeHUD.h"
28
29#include "core/CoreIncludes.h"
30#include "core/XMLPort.h"
31#include "util/Convert.h"
32#include "Hover.h"
33
34namespace orxonox
35{
36    RegisterClass(TimeHUD);
37
38    TimeHUD::TimeHUD(Context* context) : OverlayText(context)
39    {
40        RegisterObject(TimeHUD);
41
42        this->_time = 0.0f;
43        this->_running = false;
44        this->hoverGame = 0;
45        setRunning(true);
46    }
47
48    void TimeHUD::XMLPort(Element& xmlelement, XMLPort::Mode mode)
49    {
50        SUPER(TimeHUD, XMLPort, xmlelement, mode);
51    }
52
53    inline std::string getTimeString(float time) {
54        std::ostringstream ss;
55
56        int h = ((int) (time * 100.0f)) % 100;
57        int s = ((int) time) % 60;
58        int m = (int) (time / 60.0f);
59
60        ss << m << ":";
61
62        if(s < 10) {
63            ss << 0;
64        }
65        ss << s << ":";
66
67        if(h < 10) {
68            ss << 0;
69        }
70        ss << h << "s";
71        return ss.str();
72    }
73
74    void TimeHUD::tick(float dt)
75    {
76        SUPER(TimeHUD, tick, dt);
77
78        if(this->_running) {
79            this->_time += dt;
80        }
81        if (this->hoverGame)
82        {
83            this->setCaption(getTimeString(this->_time));
84        }
85        if(this->hoverGame->getFlags() == 0)
86            setRunning(false);
87       
88    }
89
90    void TimeHUD::changedOwner()
91    {
92        SUPER(TimeHUD, changedOwner);
93
94        if (this->getOwner() && this->getOwner()->getGametype())
95        {
96            this->hoverGame = orxonox_cast<Hover*>(this->getOwner()->getGametype());
97        }
98        else
99        {
100            this->hoverGame = 0;
101        }
102    }
103
104    void TimeHUD::setRunning(bool running) 
105    {
106        this->_running = running;
107    }
108
109    bool TimeHUD::isRunning() {
110        return this->_running;
111    }
112
113    void TimeHUD::reset()
114    {
115        this->_time = 0;
116    }
117}
Note: See TracBrowser for help on using the repository browser.