Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/cegui0.8_ogre1.9/src/modules/overlays/hud/ChatOverlay.cc @ 12212

Last change on this file since 12212 was 11795, checked in by landauf, 7 years ago

merged ogre1.9 (including cegui0.8) into new branch

  • Property svn:eol-style set to native
File size: 2.9 KB
RevLine 
[2072]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 "ChatOverlay.h"
30
[3196]31#include <string>
[2072]32
[11795]33#if OGRE_VERSION >= 0x010900
34#   include <Overlay/OgreTextAreaOverlayElement.h>
35#else
36#   include <OgreTextAreaOverlayElement.h>
37#endif
38
[3196]39#include "util/Convert.h"
[6417]40#include "util/DisplayStringConversions.h"
[2072]41#include "core/CoreIncludes.h"
[9667]42#include "core/config/ConfigValueIncludes.h"
[7284]43#include "core/command/Executor.h"
[2072]44
[3196]45#include "tools/Timer.h"
[5735]46#include "infos/PlayerInfo.h"
[2171]47#include "PlayerManager.h"
[2072]48
49namespace orxonox
50{
[9667]51    RegisterClass(ChatOverlay);
[2072]52
[9667]53    ChatOverlay::ChatOverlay(Context* context)
54        : OverlayText(context)
[2072]55    {
56        RegisterObject(ChatOverlay);
57
58        this->displayTime_ = 0.0;
59
60        this->setConfigValues();
61    }
62
63    ChatOverlay::~ChatOverlay()
64    {
[11071]65        for (Timer* timer : this->timers_)
66            delete timer;
[2072]67    }
68
69    void ChatOverlay::setConfigValues()
70    {
71        SetConfigValue(displayTime_, 6.0f);
72    }
73
[8858]74    void ChatOverlay::incomingChat(const std::string& message, const std::string& /*name*/)
[2072]75    {
[8858]76        this->messages_.push_back(multi_cast<Ogre::DisplayString>(message));
[2072]77
[5929]78        Timer* timer = new Timer();
79        this->timers_.insert(timer); // store the timer in a set to destroy it in the destructor
[11083]80        const ExecutorPtr executor = createExecutor(createFunctor(&ChatOverlay::dropMessage, this));
[5929]81        executor->setDefaultValues(timer);
82        timer->setTimer(this->displayTime_, false, executor, true);
[2072]83
84        this->updateOverlayText();
85    }
86
[5929]87    void ChatOverlay::dropMessage(Timer* timer)
[2072]88    {
89        if (this->messages_.size() > 0)
90            this->messages_.pop_front();
91        this->updateOverlayText();
[5929]92        this->timers_.erase(timer); // the timer destroys itself, but we have to remove it from the set
[2072]93    }
94
95    void ChatOverlay::updateOverlayText()
96    {
97        this->text_->setCaption("");
98
[11071]99        for (const Ogre::DisplayString& message : this->messages_)
[2072]100        {
[11071]101            this->text_->setCaption(this->text_->getCaption() + "\n" + message);
[2072]102        }
103    }
104}
Note: See TracBrowser for help on using the repository browser.