Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/overlays/FadeoutText.cc @ 3109

Last change on this file since 3109 was 3099, checked in by landauf, 16 years ago

Added Gameplay messages (Announces, Killmessages and Deathmessages)

  • Property svn:eol-style set to native
File size: 3.0 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 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "OrxonoxStableHeaders.h"
30#include "FadeoutText.h"
31
32#include <OgreTextAreaOverlayElement.h>
33
34#include "core/CoreIncludes.h"
35#include "core/XMLPort.h"
36
37namespace orxonox
38{
39    CreateFactory(FadeoutText);
40
41    FadeoutText::FadeoutText(BaseObject* creator) : OverlayText(creator)
42    {
43        RegisterObject(FadeoutText);
44
45        this->delay_ = 3.0f;
46        this->fadeouttime_ = 1.0f;
47
48        this->bFadingOut_ = false;
49        this->fadeouttimer_.setTimer(3.0f, false, this, createExecutor(createFunctor(&FadeoutText::fadeout)));
50        this->fadeouttimer_.stopTimer();
51
52        this->initialAlpha_ = 1.0f;
53    }
54
55    void FadeoutText::XMLPort(Element& xmlelement, XMLPort::Mode mode)
56    {
57        SUPER(FadeoutText, XMLPort, xmlelement, mode);
58
59        XMLPortParam(FadeoutText, "delay", setDelay, getDelay, xmlelement, mode);
60        XMLPortParam(FadeoutText, "fadeout", setFadeouttime, getFadeouttime, xmlelement, mode);
61    }
62
63    void FadeoutText::tick(float dt)
64    {
65        if (this->bFadingOut_)
66        {
67            ColourValue colour = this->getColour();
68
69            if (colour.a > 0)
70            {
71                float alpha = colour.a;
72
73                alpha -= dt / this->fadeouttime_;
74                if (alpha < 0)
75                    alpha = 0;
76                colour.a = alpha;
77
78                this->text_->setColour(colour);
79            }
80            else
81            {
82                this->text_->setCaption("");
83                this->reset();
84            }
85        }
86    }
87
88    void FadeoutText::fadeout()
89    {
90        this->bFadingOut_ = true;
91    }
92
93    void FadeoutText::reset()
94    {
95        this->bFadingOut_ = false;
96
97        ColourValue colour = this->getColour();
98        colour.a = this->initialAlpha_;
99        this->text_->setColour(colour);
100    }
101
102    void FadeoutText::changedColour()
103    {
104        OverlayText::changedColour();
105
106        this->initialAlpha_ = this->getColour().a;
107    }
108
109    void FadeoutText::changedCaption()
110    {
111        OverlayText::changedCaption();
112
113        this->reset();
114        this->fadeouttimer_.setInterval(this->delay_);
115        this->fadeouttimer_.startTimer();
116    }
117}
Note: See TracBrowser for help on using the repository browser.