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