diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-09-27 01:35:58 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-09-27 01:35:58 +0300 |
commit | 5f5cba799299df65d74a99e7d37800b90c91b538 (patch) | |
tree | 34d653cc8144fe0f6581c5d2b5db4f52d23bff9a /src/gui/widgets/browserbox.cpp | |
parent | a4fb19cf0333c4ed46ba07c5f25a2524c2ef6a11 (diff) | |
download | mv-5f5cba799299df65d74a99e7d37800b90c91b538.tar.gz mv-5f5cba799299df65d74a99e7d37800b90c91b538.tar.bz2 mv-5f5cba799299df65d74a99e7d37800b90c91b538.tar.xz mv-5f5cba799299df65d74a99e7d37800b90c91b538.zip |
Add support for links to monsters.
Format is: @@mID|@@
Example: [@@m1002|@@]
Diffstat (limited to 'src/gui/widgets/browserbox.cpp')
-rw-r--r-- | src/gui/widgets/browserbox.cpp | 55 |
1 files changed, 36 insertions, 19 deletions
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<int> 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<BeingTypeId>( + 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<int> 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 |