Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/objecthierarchy/src/orxonox/overlays/hud/ChatOverlay.cc @ 2023

Last change on this file since 2023 was 2023, checked in by rgrieder, 16 years ago
  • Added support for dedicated server. Could not network test it yet, client still segfaults me.
  • Also kicked GraphicsEngine::levelSceneManager_, there are only the statistic methods left.
  • GSDedicated also derives from GSLevel, but GSLevel is not anymore a real GameState.
  • CameraHandler and LevelManager get created in GSLevel now.
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 "ChatOverlay.h"
31
32#include <OgreTextAreaOverlayElement.h>
33
34#include "core/CoreIncludes.h"
35#include "core/ConfigValueIncludes.h"
36#include "core/Executor.h"
37
38#include "network/ClientInformation.h"
39
40#include "LevelManager.h"
41#include "objects/infos/PlayerInfo.h"
42#include "overlays/console/InGameConsole.h"
43#include "tools/Timer.h"
44
45#include "util/Convert.h"
46
47namespace orxonox
48{
49    CreateFactory(ChatOverlay);
50
51    ChatOverlay::ChatOverlay(BaseObject* creator) : OverlayText(creator)
52    {
53        RegisterObject(ChatOverlay);
54
55        this->displayTime_ = 0;
56
57        this->setConfigValues();
58    }
59
60    ChatOverlay::~ChatOverlay()
61    {
62    }
63
64    void ChatOverlay::setConfigValues()
65    {
66        SetConfigValue(displayTime_, 6.0f);
67    }
68
69    void ChatOverlay::incomingChat(const std::string& message, unsigned int senderID)
70    {
71        std::string text;
72
73        if (senderID != network::CLIENTID_UNKNOWN)
74        {
75            std::string name = "unknown";
76
77            PlayerInfo* player = LevelManager::getInstance().getClient(senderID);
78            if (player)
79                name = player->getName();
80
81            text = name + ": " + message;
82        }
83        else
84        {
85            text = message;
86        }
87
88        this->messages_.push_back(InGameConsole::convert2UTF(text));
89        COUT(0) << "Chat: " << text << std::endl;
90
91        new Timer<ChatOverlay>(this->displayTime_, false, this, createExecutor(createFunctor(&ChatOverlay::dropMessage)), true);
92
93        this->updateOverlayText();
94    }
95
96    void ChatOverlay::dropMessage()
97    {
98        this->messages_.pop_front();
99        this->updateOverlayText();
100    }
101
102    void ChatOverlay::updateOverlayText()
103    {
104        this->text_->setCaption("");
105
106        for (std::list<Ogre::UTFString>::reverse_iterator it = this->messages_.rbegin(); it != this->messages_.rend(); ++it)
107        {
108            this->text_->setCaption(this->text_->getCaption() + "\n" + (*it));
109        }
110    }
111}
Note: See TracBrowser for help on using the repository browser.