From 451b5887beae88c1f3c139a35d23e5521e896e7d Mon Sep 17 00:00:00 2001 From: David Athay Date: Wed, 14 Jan 2009 14:11:35 +0000 Subject: Added linking to item's just using [Item Name] in chat --- src/gui/chat.cpp | 24 +++++++++++++++++++++++- src/gui/chat.h | 2 +- 2 files changed, 24 insertions(+), 2 deletions(-) (limited to 'src/gui') diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 34daab38..f391ccb9 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -46,8 +46,12 @@ #include "../net/chatserver/chatserver.h" #include "../net/gameserver/player.h" +#include "../resources/iteminfo.h" +#include "../resources/itemdb.h" + #include "../utils/dtor.h" #include "../utils/trim.h" +#include "../utils/tostring.h" ChatWindow::ChatWindow(): Window("Chat"), @@ -301,10 +305,28 @@ bool ChatWindow::isInputFocused() return mChatInput->isFocused(); } -void ChatWindow::chatSend(const std::string &msg) +void ChatWindow::chatSend(std::string &msg) { if (msg.empty()) return; + // check for item link + std::string::size_type start = msg.find('['); + if (start != std::string::npos) + { + std::string::size_type end = msg.find(']', start); + if (end != std::string::npos) + { + std::string temp = msg.substr(start+1, end-1); + ItemInfo itemInfo = ItemDB::get(temp); + msg.insert(end, "@@"); + msg.insert(start+1, "|"); + msg.insert(start+1, toString(itemInfo.getId())); + msg.insert(start+1, "@@"); + + } + } + + // Prepare ordinary message if (msg[0] != '/') { diff --git a/src/gui/chat.h b/src/gui/chat.h index bb742a77..114b389c 100644 --- a/src/gui/chat.h +++ b/src/gui/chat.h @@ -119,7 +119,7 @@ class ChatWindow : public Window, * @param msg The message text which is to be sent. * */ - void chatSend(const std::string &msg); + void chatSend(std::string &msg); /** Called to remove the channel from the channel manager */ void removeChannel(short channelId); -- cgit v1.2.3-70-g09d2