diff options
author | David Athay <ko2fan@gmail.com> | 2009-01-14 14:11:35 +0000 |
---|---|---|
committer | David Athay <ko2fan@gmail.com> | 2009-01-14 14:11:35 +0000 |
commit | 451b5887beae88c1f3c139a35d23e5521e896e7d (patch) | |
tree | e1d5f5058311a1121d1eb2c122eb3d1eb5cee372 /src | |
parent | ac3d5127cb7f3e3a4f5fa7a3ceb6f7c8de6808be (diff) | |
download | mana-451b5887beae88c1f3c139a35d23e5521e896e7d.tar.gz mana-451b5887beae88c1f3c139a35d23e5521e896e7d.tar.bz2 mana-451b5887beae88c1f3c139a35d23e5521e896e7d.tar.xz mana-451b5887beae88c1f3c139a35d23e5521e896e7d.zip |
Added linking to item's just using [Item Name] in chat
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/chat.cpp | 24 | ||||
-rw-r--r-- | src/gui/chat.h | 2 | ||||
-rw-r--r-- | src/resources/itemdb.cpp | 31 | ||||
-rw-r--r-- | src/resources/itemdb.h | 3 | ||||
-rw-r--r-- | src/resources/iteminfo.h | 7 |
5 files changed, 65 insertions, 2 deletions
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); diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index 04828d1b..5dfcfb87 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -37,6 +37,7 @@ namespace { ItemDB::ItemInfos mItemInfos; + ItemDB::NamedItemInfos mNamedItemInfos; ItemInfo *mUnknown; bool mLoaded = false; } @@ -136,6 +137,7 @@ void ItemDB::load() int attackRange = XML::getProperty(node, "attack-range", 0); ItemInfo *itemInfo = new ItemInfo; + itemInfo->setId(id); itemInfo->setImageName(image); itemInfo->setName(name.empty() ? "Unnamed" : name); itemInfo->setDescription(description); @@ -169,6 +171,18 @@ void ItemDB::load() } mItemInfos[id] = itemInfo; + if (!name.empty()) + { + NamedItemInfoIterator itr = mNamedItemInfos.find(name); + if (itr == mNamedItemInfos.end()) + { + mNamedItemInfos[name] = itemInfo; + } + else + { + logger->log("ItemDB: Duplicate name of item found item %d", id); + } + } #define CHECK_PARAM(param, error_value) \ if (param == error_value) \ @@ -217,6 +231,23 @@ const ItemInfo& ItemDB::get(int id) } } +const ItemInfo& ItemDB::get(const std::string &name) +{ + assert(mLoaded && !name.empty()); + + NamedItemInfoIterator i = mNamedItemInfos.find(name); + + if (i == mNamedItemInfos.end()) + { + logger->log("ItemDB: Error, unknown item name %s", name.c_str()); + return *mUnknown; + } + else + { + return *(i->second); + } +} + void loadSpriteRef(ItemInfo *itemInfo, xmlNodePtr node) { std::string gender = XML::getProperty(node, "gender", "unisex"); diff --git a/src/resources/itemdb.h b/src/resources/itemdb.h index 20756a52..1d814f34 100644 --- a/src/resources/itemdb.h +++ b/src/resources/itemdb.h @@ -42,10 +42,13 @@ namespace ItemDB void unload(); const ItemInfo& get(int id); + const ItemInfo& get(const std::string &name); // Items database typedef std::map<int, ItemInfo*> ItemInfos; + typedef std::map<std::string, ItemInfo*> NamedItemInfos; typedef ItemInfos::iterator ItemInfoIterator; + typedef NamedItemInfos::iterator NamedItemInfoIterator; } #endif diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h index 7cc3ba15..1c1d8467 100644 --- a/src/resources/iteminfo.h +++ b/src/resources/iteminfo.h @@ -122,6 +122,12 @@ class ItemInfo { } + void setId(int id) + { mId = id; } + + int getId() const + { return mId; } + void setName(const std::string &name) { mName = name; } @@ -189,6 +195,7 @@ class ItemInfo char mType; /**< Item type. */ short mWeight; /**< Weight in grams. */ int mView; /**< Item ID of how this item looks. */ + int mId; /**< Item ID */ // Equipment related members SpriteAction mAttackType; /**< Attack type, in case of weapon. */ |