ManaPlus
Functions
BrowserBoxTools Namespace Reference

Functions

void replaceVars (std::string &data)
 
void replaceKeys (std::string &data)
 
std::string replaceLinkCommands (const std::string &link)
 
void replaceTabs (std::string &data)
 

Function Documentation

◆ replaceKeys()

void BrowserBoxTools::replaceKeys ( std::string &  data)

Definition at line 54 of file browserboxtools.cpp.

55 {
56  size_t idx1 = data.find("###");
57  while (idx1 != std::string::npos)
58  {
59  const size_t idx2 = data.find(';', idx1);
60  if (idx2 == std::string::npos)
61  break;
62 
63  const std::string str = inputManager.getKeyValueByNameLong(
64  data.substr(idx1 + 3, idx2 - idx1 - 3));
65  data.replace(idx1, idx2 - idx1 + 1, str);
66 
67  idx1 = data.find("###");
68  }
69 }
std::string getKeyValueByNameLong(const std::string &keyName)
InputManager inputManager
uint32_t data

References data, InputManager::getKeyValueByNameLong(), and inputManager.

Referenced by BrowserBox::addRow(), and StaticBrowserBox::addRow().

◆ replaceLinkCommands()

std::string BrowserBoxTools::replaceLinkCommands ( const std::string &  link)

Definition at line 71 of file browserboxtools.cpp.

72 {
73 #ifdef DYECMD
74  return link;
75 #else // DYECMD
76 
77  std::string data = link;
78 
79  if (strStartWith(data, "http://") ||
80  strStartWith(data, "https://"))
81  {
82  return data;
83  }
84 
85  if (!link.empty() && link[0] == 'm')
86  { // monster link
87  const BeingTypeId id = static_cast<BeingTypeId>(
88  atoi(link.substr(1).c_str()));
89  BeingInfo *const info = MonsterDB::get(id);
90  if (info != nullptr)
91  data = info->getName();
92  }
93  else if (!link.empty() && link[0] == 'p')
94  { // pet link
95  const BeingTypeId id = static_cast<BeingTypeId>(
96  atoi(link.substr(1).c_str()));
97  BeingInfo *const info = PETDB::get(id);
98  if (info != nullptr)
99  data = info->getName();
100  }
101  else if (!link.empty() && link[0] == 'h')
102  { // homunculus link
103  const BeingTypeId id = static_cast<BeingTypeId>(
104  atoi(link.substr(1).c_str()));
105  BeingInfo *const info = HomunculusDB::get(id);
106  if (info != nullptr)
107  data = info->getName();
108  }
109  else if (!link.empty() && link[0] == 'M')
110  { // mercenary link
111  const BeingTypeId id = static_cast<BeingTypeId>(
112  atoi(link.substr(1).c_str()));
113  BeingInfo *const info = MercenaryDB::get(id);
114  if (info != nullptr)
115  data = info->getName();
116  }
117  else if (!link.empty() && link[0] == 'q')
118  { // quest link
120  atoi(link.substr(1).c_str()));
121  }
122  else
123  { // item link
124  size_t idx = link.find(',');
125  if (idx != std::string::npos)
126  {
127  const int id = atoi(link.substr(0, idx).c_str());
128  if (id != 0)
129  {
130  STD_VECTOR<int> parts;
131  splitToIntVector(parts,
132  link.substr(idx), ',');
133  while (parts.size() < maxCards)
134  parts.push_back(0);
135  const ItemColor itemColor =
137  data = ItemDB::get(id).getName(itemColor);
138  }
139  }
140  else
141  {
142  const int id = atoi(link.c_str());
143  if (id != 0)
144  data = ItemDB::get(id).getName();
145  }
146  }
147  return data;
148 #endif // DYECMD
149 }
int BeingTypeId
Definition: beingtypeid.h:30
#define maxCards
Definition: cards.h:25
static ItemColor getColorFromCards(const int *const cards)
const std::string & getName() const
Definition: iteminfo.h:74
uint16_t ItemColor
Definition: itemcolor.h:30
bool info(InputEvent &event)
Definition: commands.cpp:57
BeingInfo * get(const BeingTypeId id)
const ItemInfo & get(const int id)
Definition: itemdb.cpp:792
BeingInfo * get(const BeingTypeId id)
BeingInfo * get(const BeingTypeId id)
Definition: monsterdb.cpp:145
BeingInfo * get(const BeingTypeId id)
Definition: petdb.cpp:157
std::string getName(const int id)
Definition: questdb.cpp:249
void splitToIntVector(std::vector< int > &tokens, const std::string &text, const char separator)
bool strStartWith(const std::string &str1, const std::string &str2)

References data, HomunculusDB::get(), MercenaryDB::get(), MonsterDB::get(), PETDB::get(), ItemDB::get(), ItemColorManager::getColorFromCards(), ItemInfo::getName(), QuestDb::getName(), Actions::info(), maxCards, splitToIntVector(), and strStartWith().

Referenced by BrowserBox::addRow(), and StaticBrowserBox::addRow().

◆ replaceTabs()

void BrowserBoxTools::replaceTabs ( std::string &  data)

Definition at line 151 of file browserboxtools.cpp.

152 {
153  size_t idx1 = data.find("\\t");
154  while (idx1 != std::string::npos)
155  {
156  const size_t idx2 = data.find(';', idx1);
157  if (idx2 == std::string::npos)
158  break;
159 
160  const unsigned int newSize = CAST_U32(
161  atoi(data.substr(
162  idx1 + 2, idx2 - idx1 - 2).c_str()));
163  std::string str = data.substr(0, idx1);
164  while (str.size() < newSize)
165  str.append(" ");
166  str.append(data.substr(idx2 + 1));
167  data = str;
168  idx1 = data.find("\\t");
169  }
170 }
#define CAST_U32
Definition: cast.h:31

References CAST_U32, and data.

Referenced by BrowserBox::addRow(), and StaticBrowserBox::addRow().

◆ replaceVars()

void BrowserBoxTools::replaceVars ( std::string &  data)

Definition at line 48 of file browserboxtools.cpp.

49 {
50  data = replaceAll(data, "%VER%", SMALL_VERSION);
51  data = replaceAll(data, "%SUPPORTURL%", settings.supportUrl);
52 }
std::string supportUrl
Definition: settings.h:121
#define SMALL_VERSION
Definition: main.h:44
Settings settings
Definition: settings.cpp:32
std::string & replaceAll(std::string &context, const std::string &from, const std::string &to)

References data, replaceAll(), settings, SMALL_VERSION, and Settings::supportUrl.

Referenced by BrowserBox::addRow(), StaticBrowserBox::addRow(), and ChatTab::chatInput().