Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/mergeFS18/src/modules/overlays/hud/ChatOverlay.cc @ 12047

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