From 5f5cba799299df65d74a99e7d37800b90c91b538 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 27 Sep 2016 01:35:58 +0300 Subject: Add support for links to monsters. Format is: @@mID|@@ Example: [@@m1002|@@] --- src/gui/widgets/browserbox.cpp | 55 +++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 19 deletions(-) (limited to 'src/gui') diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp index a229cb10f..098ee0d64 100644 --- a/src/gui/widgets/browserbox.cpp +++ b/src/gui/widgets/browserbox.cpp @@ -40,10 +40,15 @@ #include "render/graphics.h" -#include "resources/imageset.h" +#ifndef DYECMD +#include "resources/beinginfo.h" #include "resources/iteminfo.h" #include "resources/db/itemdb.h" +#include "resources/db/monsterdb.h" +#endif // DYECMD + +#include "resources/imageset.h" #include "resources/image/image.h" @@ -247,26 +252,38 @@ void BrowserBox::addRow(const std::string &row, const bool atTop) { bLink.caption = bLink.link; #ifndef DYECMD - size_t idx = bLink.link.find(","); - if (idx != std::string::npos) - { - const int id = atoi(bLink.link.substr(0, idx).c_str()); - if (id) - { - std::vector parts; - splitToIntVector(parts, bLink.link.substr(idx), ','); - while (parts.size() < maxCards) - parts.push_back(0); - const ItemColor itemColor = - ItemColorManager::getColorFromCards(&parts[0]); - bLink.caption = ItemDB::get(id).getName(itemColor); - } + const std::string link = bLink.link; + if (!link.empty() && link[0] == 'm') + { // monster link + const BeingTypeId id = static_cast( + atoi(bLink.link.substr(1).c_str())); + BeingInfo *info = MonsterDB::get(id); + if (info) + bLink.caption = info->getName(); } else - { - const int id = atoi(bLink.link.c_str()); - if (id) - bLink.caption = ItemDB::get(id).getName(); + { // item link + size_t idx = bLink.link.find(","); + if (idx != std::string::npos) + { + const int id = atoi(bLink.link.substr(0, idx).c_str()); + if (id) + { + std::vector parts; + splitToIntVector(parts, bLink.link.substr(idx), ','); + while (parts.size() < maxCards) + parts.push_back(0); + const ItemColor itemColor = + ItemColorManager::getColorFromCards(&parts[0]); + bLink.caption = ItemDB::get(id).getName(itemColor); + } + } + else + { + const int id = atoi(bLink.link.c_str()); + if (id) + bLink.caption = ItemDB::get(id).getName(); + } } #endif // DYECMD -- cgit v1.2.3-60-g2f50