ManaPlus
Typedefs | Functions
NpcDialogDB Namespace Reference

Typedefs

typedef std::map< std::string, NpcDialogInfo * > Dialogs
 
typedef Dialogs::iterator DialogsIter
 

Functions

void load ()
 
void loadXmlFile (const std::string &fileName, const SkipError skipError)
 
void unload ()
 
void deleteDialog (const std::string &name)
 
NpcDialogInfogetDialog (const std::string &name)
 

Detailed Description

Color information database.

Typedef Documentation

◆ Dialogs

typedef std::map<std::string, NpcDialogInfo*> NpcDialogDB::Dialogs

Definition at line 56 of file npcdialogdb.h.

◆ DialogsIter

typedef Dialogs::iterator NpcDialogDB::DialogsIter

Definition at line 57 of file npcdialogdb.h.

Function Documentation

◆ deleteDialog()

void NpcDialogDB::deleteDialog ( const std::string &  name)

Definition at line 193 of file npcdialogdb.cpp.

194 {
195  const DialogsIter it = mDialogs.find(name);
196  if (it == mDialogs.end())
197  return;
198 
199  NpcDialogInfo *dialog = (*it).second;
200  delete_all(dialog->menu.buttons);
201  delete_all(dialog->menu.images);
202  delete_all(dialog->menu.texts);
203  mDialogs.erase(it);
204  delete dialog;
205 }
void delete_all(Container &c)
Definition: dtor.h:56
Dialogs::iterator DialogsIter
Definition: npcdialogdb.h:57
NpcDialogMenuInfo menu
Definition: npcdialoginfo.h:42
std::vector< NpcImageInfo * > images
std::vector< NpcButtonInfo * > buttons
std::vector< NpcTextInfo * > texts

References NpcDialogMenuInfo::buttons, delete_all(), NpcDialogMenuInfo::images, anonymous_namespace{npcdialogdb.cpp}::mDialogs, NpcDialogInfo::menu, and NpcDialogMenuInfo::texts.

Referenced by loadXmlFile().

◆ getDialog()

NpcDialogInfo * NpcDialogDB::getDialog ( const std::string &  name)

Definition at line 224 of file npcdialogdb.cpp.

225 {
226  const DialogsIter it = mDialogs.find(name);
227  if (it == mDialogs.end())
228  return nullptr;
229  return (*it).second;
230 }

References anonymous_namespace{npcdialogdb.cpp}::mDialogs.

Referenced by NpcDialog::setSkin().

◆ load()

void NpcDialogDB::load ( )

Loads the map remap data from maps\remap.xml.

Definition at line 40 of file npcdialogdb.cpp.

41 {
42  if (mLoaded)
43  unload();
44 
45  logger->log1("Loading npc dialog database...");
46  loadXmlFile(paths.getStringValue("npcDialogsFile"), SkipError_false);
47  loadXmlFile(paths.getStringValue("npcDialogsPatchFile"), SkipError_true);
48  loadXmlDir("npcDialogsPatchDir", loadXmlFile)
49 
50  mLoaded = true;
51 }
static void loadXmlFile(const std::string &file, const std::string &name, BadgesInfos &arr, const SkipError skipError)
Definition: badgesdb.cpp:43
#define loadXmlDir(name, function)
Definition: beingcommon.h:39
std::string getStringValue(const std::string &key) const
void log1(const char *const log_text)
Definition: logger.cpp:238
Configuration paths
Logger * logger
Definition: logger.cpp:89
void unload()
Definition: net.cpp:180
const bool SkipError_false
Definition: skiperror.h:30
const bool SkipError_true
Definition: skiperror.h:30

References Configuration::getStringValue(), loadXmlDir, loadXmlFile(), Logger::log1(), logger, anonymous_namespace{npcdialogdb.cpp}::mLoaded, paths, SkipError_false, SkipError_true, and Net::unload().

Referenced by DbManager::loadDb().

◆ loadXmlFile()

void NpcDialogDB::loadXmlFile ( const std::string &  fileName,
const SkipError  skipError 
)

Definition at line 151 of file npcdialogdb.cpp.

153 {
154  XML::Document *const doc = new XML::Document(fileName,
156  skipError);
157 
158  XmlNodeConstPtrConst root = doc->rootNode();
159  if (root == nullptr)
160  {
161  delete doc;
162  return;
163  }
164 
165  for_each_xml_child_node(node, root)
166  {
167  if (xmlNameEqual(node, "dialog"))
168  {
169  const std::string name = XML::getProperty(node, "name", "");
170  if (name.empty())
171  continue;
172 
173  deleteDialog(name);
174  NpcDialogInfo *const dialog = new NpcDialogInfo;
175  dialog->name = name;
176  dialog->hideText = XML::getBoolProperty(
177  node, "hideText", false);
178  mDialogs[name] = dialog;
179  loadNpcDialog(dialog, node);
180  }
181  else if (xmlNameEqual(node, "include"))
182  {
183  const std::string name = XML::getProperty(node, "name", "");
184  if (!name.empty())
185  loadXmlFile(name, skipError);
186  continue;
187  }
188  }
189 
190  delete doc;
191 }
xmlNodePtr rootNode()
Definition: libxml.cpp:169
#define for_each_xml_child_node(var, parent)
Definition: libxml.h:161
void deleteDialog(const std::string &name)
bool getBoolProperty(const xmlNodePtr node, const char *const name, const bool def)
Definition: libxml.cpp:269
int getProperty(const xmlNodePtr node, const char *const name, int def)
Definition: libxml.cpp:174
static void loadNpcDialog(NpcDialogInfo *const dialog, const xmlNode *const node)
std::string name
Definition: npcdialoginfo.h:44
std::string fileName
Definition: testmain.cpp:39
const bool UseVirtFs_true
Definition: usevirtfs.h:30

References deleteDialog(), fileName, for_each_xml_child_node, XML::getBoolProperty(), XML::getProperty(), NpcDialogInfo::hideText, loadNpcDialog(), loadXmlFile(), anonymous_namespace{npcdialogdb.cpp}::mDialogs, NpcDialogInfo::name, XML::Document::rootNode(), and UseVirtFs_true.

◆ unload()

void NpcDialogDB::unload ( )

Clear the remap data

Definition at line 207 of file npcdialogdb.cpp.

208 {
209  logger->log1("Unloading npc dialog database...");
210 
212  {
213  NpcDialogInfo *dialog = (*it).second;
214  delete_all(dialog->menu.buttons);
215  delete_all(dialog->menu.images);
216  delete_all(dialog->menu.texts);
217  delete dialog;
218  }
219  mDialogs.clear();
220 
221  mLoaded = false;
222 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:25

References NpcDialogMenuInfo::buttons, delete_all(), FOR_EACH, NpcDialogMenuInfo::images, Logger::log1(), logger, anonymous_namespace{npcdialogdb.cpp}::mDialogs, NpcDialogInfo::menu, anonymous_namespace{npcdialogdb.cpp}::mLoaded, and NpcDialogMenuInfo::texts.

Referenced by DbManager::unloadDb().