summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-01-27 19:59:11 +0300
committerAndrei Karas <akaras@inbox.ru>2017-01-27 19:59:11 +0300
commitbfd5338c20fcd838f711ea5e96b2f37e012dc884 (patch)
tree91c242a73d9dbe89a153d364631f4d0d4f90b0fc
parent4db8641fd12c6e11257a6a45fcb2e1948fe4bcb1 (diff)
downloadplus-bfd5338c20fcd838f711ea5e96b2f37e012dc884.tar.gz
plus-bfd5338c20fcd838f711ea5e96b2f37e012dc884.tar.bz2
plus-bfd5338c20fcd838f711ea5e96b2f37e012dc884.tar.xz
plus-bfd5338c20fcd838f711ea5e96b2f37e012dc884.zip
Move links replace code from browserbox into browserboxtools.
-rw-r--r--src/gui/widgets/browserbox.cpp82
-rw-r--r--src/utils/browserboxtools.cpp83
-rw-r--r--src/utils/browserboxtools.h2
3 files changed, 86 insertions, 81 deletions
diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp
index bd565b3d6..b1793b725 100644
--- a/src/gui/widgets/browserbox.cpp
+++ b/src/gui/widgets/browserbox.cpp
@@ -23,16 +23,8 @@
#include "gui/widgets/browserbox.h"
-#include "itemcolormanager.h"
-#include "main.h"
-#include "settings.h"
-
-#include "const/resources/item/cards.h"
-
#include "enums/gui/linkhighlightmode.h"
-#include "input/inputmanager.h"
-
#include "gui/gui.h"
#include "gui/skin.h"
@@ -42,17 +34,6 @@
#include "render/graphics.h"
-#ifndef DYECMD
-#include "resources/beinginfo.h"
-#include "resources/iteminfo.h"
-
-#include "resources/db/homunculusdb.h"
-#include "resources/db/itemdb.h"
-#include "resources/db/mercenarydb.h"
-#include "resources/db/monsterdb.h"
-#include "resources/db/petdb.h"
-#endif // DYECMD
-
#include "resources/imageset.h"
#include "resources/image/image.h"
@@ -248,68 +229,7 @@ void BrowserBox::addRow(const std::string &row, const bool atTop)
bLink.y2 = bLink.y1 + font->getHeight();
if (bLink.caption.empty())
{
- bLink.caption = bLink.link;
-#ifndef DYECMD
- 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 if (!link.empty() && link[0] == 'p')
- { // pet link
- const BeingTypeId id = static_cast<BeingTypeId>(
- atoi(bLink.link.substr(1).c_str()));
- BeingInfo *info = PETDB::get(id);
- if (info)
- bLink.caption = info->getName();
- }
- else if (!link.empty() && link[0] == 'h')
- { // homunculus link
- const BeingTypeId id = static_cast<BeingTypeId>(
- atoi(bLink.link.substr(1).c_str()));
- BeingInfo *info = HomunculusDB::get(id);
- if (info)
- bLink.caption = info->getName();
- }
- else if (!link.empty() && link[0] == 'M')
- { // homunculus link
- const BeingTypeId id = static_cast<BeingTypeId>(
- atoi(bLink.link.substr(1).c_str()));
- BeingInfo *info = MercenaryDB::get(id);
- if (info)
- bLink.caption = info->getName();
- }
- else
- { // 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
-
+ bLink.caption = BrowserBoxTools::replaceLinkCommands(bLink.link);
if (translator)
bLink.caption = translator->getStr(bLink.caption);
}
diff --git a/src/utils/browserboxtools.cpp b/src/utils/browserboxtools.cpp
index 6684684ff..ff7df8d30 100644
--- a/src/utils/browserboxtools.cpp
+++ b/src/utils/browserboxtools.cpp
@@ -20,6 +20,7 @@
#include "utils/browserboxtools.h"
+#include "itemcolormanager.h"
#include "main.h"
#include "settings.h"
@@ -27,6 +28,19 @@
#include "utils/stringutils.h"
+#ifndef DYECMD
+#include "const/resources/item/cards.h"
+
+#include "resources/beinginfo.h"
+#include "resources/iteminfo.h"
+
+#include "resources/db/homunculusdb.h"
+#include "resources/db/itemdb.h"
+#include "resources/db/mercenarydb.h"
+#include "resources/db/monsterdb.h"
+#include "resources/db/petdb.h"
+#endif // DYECMD
+
#include "debug.h"
void BrowserBoxTools::replaceVars(std::string &data)
@@ -51,3 +65,72 @@ void BrowserBoxTools::replaceKeys(std::string &data)
idx1 = data.find("###");
}
}
+
+std::string BrowserBoxTools::replaceLinkCommands(const std::string &link)
+{
+#ifdef DYECMD
+ return link;
+#else // DYECMD
+
+ std::string data = link;
+
+ if (!link.empty() && link[0] == 'm')
+ { // monster link
+ const BeingTypeId id = static_cast<BeingTypeId>(
+ atoi(link.substr(1).c_str()));
+ BeingInfo *info = MonsterDB::get(id);
+ if (info)
+ data = info->getName();
+ }
+ else if (!link.empty() && link[0] == 'p')
+ { // pet link
+ const BeingTypeId id = static_cast<BeingTypeId>(
+ atoi(link.substr(1).c_str()));
+ BeingInfo *info = PETDB::get(id);
+ if (info)
+ data = info->getName();
+ }
+ else if (!link.empty() && link[0] == 'h')
+ { // homunculus link
+ const BeingTypeId id = static_cast<BeingTypeId>(
+ atoi(link.substr(1).c_str()));
+ BeingInfo *info = HomunculusDB::get(id);
+ if (info)
+ data = info->getName();
+ }
+ else if (!link.empty() && link[0] == 'M')
+ { // homunculus link
+ const BeingTypeId id = static_cast<BeingTypeId>(
+ atoi(link.substr(1).c_str()));
+ BeingInfo *info = MercenaryDB::get(id);
+ if (info)
+ data = info->getName();
+ }
+ else
+ { // item link
+ size_t idx = link.find(',');
+ if (idx != std::string::npos)
+ {
+ const int id = atoi(link.substr(0, idx).c_str());
+ if (id)
+ {
+ std::vector<int> parts;
+ splitToIntVector(parts,
+ link.substr(idx), ',');
+ while (parts.size() < maxCards)
+ parts.push_back(0);
+ const ItemColor itemColor =
+ ItemColorManager::getColorFromCards(&parts[0]);
+ data = ItemDB::get(id).getName(itemColor);
+ }
+ }
+ else
+ {
+ const int id = atoi(link.c_str());
+ if (id)
+ data = ItemDB::get(id).getName();
+ }
+ }
+ return data;
+#endif // DYECMD
+}
diff --git a/src/utils/browserboxtools.h b/src/utils/browserboxtools.h
index c2d0c9dc9..d35f4bda9 100644
--- a/src/utils/browserboxtools.h
+++ b/src/utils/browserboxtools.h
@@ -30,6 +30,8 @@ namespace BrowserBoxTools
void replaceVars(std::string &data);
void replaceKeys(std::string &data);
+
+ std::string replaceLinkCommands(const std::string &link);
} // BrowserBoxTools
#endif // UTILS_BROWSERBOXTOOLS_H