From 261a118937d8b1cd41cf16d983f880e5957f84b1 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 17 Jan 2016 15:57:05 +0300 Subject: Extend addchat command with support for cards. --- src/actions/commands.cpp | 28 ++++++++++++++-------------- src/resources/db/itemdb.cpp | 16 ++++++++++++++++ src/resources/db/itemdb.h | 2 ++ 3 files changed, 32 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/actions/commands.cpp b/src/actions/commands.cpp index bb43e2a9d..2cfe01720 100644 --- a/src/actions/commands.cpp +++ b/src/actions/commands.cpp @@ -284,22 +284,20 @@ impHandler(chatAdd) if (event.args.empty()) return true; - const int id = atoi(event.args.c_str()); - if (id == 0) + std::vector str; + splitToIntVector(str, event.args, ','); + if (str.empty()) return true; - Inventory *const inv = PlayerInfo::getInventory(); - const Item *item = nullptr; - if (inv) - { - // +++ need add also color here - item = inv->findItem(id, ItemColor_one); - } + int id = str[0]; + if (id == 0) + return true; - if (item) + if (ItemDB::exists(id)) { - // +++ need add also color here - chatWindow->addItemText(item->getInfo().getName()); + const std::string names = ItemDB::getNamesStr(str); + if (!names.empty()) + chatWindow->addItemText(names); return true; } @@ -308,8 +306,10 @@ impHandler(chatAdd) if (floorItem) { - // +++ need add also color here - chatWindow->addItemText(floorItem->getInfo().getName()); + str[0] = floorItem->getItemId(); + logger->log("parts: %d", (int)str.size()); + const std::string names = ItemDB::getNamesStr(str); + chatWindow->addItemText(names); } return true; } diff --git a/src/resources/db/itemdb.cpp b/src/resources/db/itemdb.cpp index b4af71c17..9a815bed6 100644 --- a/src/resources/db/itemdb.cpp +++ b/src/resources/db/itemdb.cpp @@ -1056,6 +1056,22 @@ static void loadOrderSprite(ItemInfo *const itemInfo, itemInfo->setDrawPriority(direction, priority); } +std::string ItemDB::getNamesStr(const std::vector &parts) +{ + std::string str; + FOR_EACH (std::vector::const_iterator, it, parts) + { + const int id = *it; + if (exists(id)) + { + if (!str.empty()) + str.append(","); + str.append(get(id).getName()); + } + } + return str; +} + #ifdef UNITTESTS ItemDB::NamedItemInfos &ItemDB::getNamedItemInfosTest() { diff --git a/src/resources/db/itemdb.h b/src/resources/db/itemdb.h index 9231bbfc8..7cc47b121 100644 --- a/src/resources/db/itemdb.h +++ b/src/resources/db/itemdb.h @@ -60,6 +60,8 @@ namespace ItemDB const ItemDB::ItemInfos &getItemInfos(); + std::string getNamesStr(const std::vector &parts); + #ifdef UNITTESTS ItemDB::NamedItemInfos &getNamedItemInfosTest(); #endif -- cgit v1.2.3-60-g2f50