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 <OgreTextAreaOverlayElement.h> |
---|
32 | |
---|
33 | #include "util/Convert.h" |
---|
34 | #include "util/UTFStringConversions.h" |
---|
35 | #include "core/CoreIncludes.h" |
---|
36 | #include "core/ConfigValueIncludes.h" |
---|
37 | #include "core/Executor.h" |
---|
38 | |
---|
39 | #include "tools/Timer.h" |
---|
40 | #include "objects/infos/PlayerInfo.h" |
---|
41 | #include "PlayerManager.h" |
---|
42 | |
---|
43 | namespace orxonox |
---|
44 | { |
---|
45 | CreateFactory(ChatOverlay); |
---|
46 | |
---|
47 | ChatOverlay::ChatOverlay(BaseObject* creator) |
---|
48 | : OverlayText(creator) |
---|
49 | { |
---|
50 | RegisterObject(ChatOverlay); |
---|
51 | |
---|
52 | this->displayTime_ = 0.0; |
---|
53 | |
---|
54 | this->setConfigValues(); |
---|
55 | } |
---|
56 | |
---|
57 | ChatOverlay::~ChatOverlay() |
---|
58 | { |
---|
59 | } |
---|
60 | |
---|
61 | void ChatOverlay::setConfigValues() |
---|
62 | { |
---|
63 | SetConfigValue(displayTime_, 6.0f); |
---|
64 | } |
---|
65 | |
---|
66 | void ChatOverlay::incomingChat(const std::string& message, unsigned int senderID) |
---|
67 | { |
---|
68 | std::string text; |
---|
69 | |
---|
70 | if (senderID != CLIENTID_UNKNOWN) |
---|
71 | { |
---|
72 | std::string name = "unknown"; |
---|
73 | |
---|
74 | PlayerInfo* player = PlayerManager::getInstance().getClient(senderID); |
---|
75 | if (player) |
---|
76 | name = player->getName(); |
---|
77 | |
---|
78 | text = name + ": " + message; |
---|
79 | } |
---|
80 | else |
---|
81 | { |
---|
82 | text = message; |
---|
83 | } |
---|
84 | |
---|
85 | this->messages_.push_back(multi_cast<Ogre::UTFString>(text)); |
---|
86 | COUT(0) << "Chat: " << text << std::endl; |
---|
87 | |
---|
88 | new Timer<ChatOverlay>(this->displayTime_, false, this, createExecutor(createFunctor(&ChatOverlay::dropMessage)), true); |
---|
89 | |
---|
90 | this->updateOverlayText(); |
---|
91 | } |
---|
92 | |
---|
93 | void ChatOverlay::dropMessage() |
---|
94 | { |
---|
95 | if (this->messages_.size() > 0) |
---|
96 | this->messages_.pop_front(); |
---|
97 | this->updateOverlayText(); |
---|
98 | } |
---|
99 | |
---|
100 | void ChatOverlay::updateOverlayText() |
---|
101 | { |
---|
102 | this->text_->setCaption(""); |
---|
103 | |
---|
104 | for (std::list<Ogre::UTFString>::reverse_iterator it = this->messages_.rbegin(); it != this->messages_.rend(); ++it) |
---|
105 | { |
---|
106 | this->text_->setCaption(this->text_->getCaption() + "\n" + (*it)); |
---|
107 | } |
---|
108 | } |
---|
109 | } |
---|