ManaPlus
Namespaces | Functions | Variables
npcdialogdb.cpp File Reference

(986a3bf)

#include "resources/db/npcdialogdb.h"
#include "configuration.h"
#include "resources/beingcommon.h"
#include "resources/npcdialoginfo.h"
#include "utils/checkutils.h"
#include "utils/dtor.h"
#include "debug.h"

Go to the source code of this file.

Namespaces

 anonymous_namespace{npcdialogdb.cpp}
 

Functions

static void loadNpcDialogMenu (NpcDialogInfo *const dialog, const xmlNode *const node)
 
static void loadNpcDialogInventory (NpcDialogInfo *const dialog, xmlNode *const node)
 
static void loadNpcDialog (NpcDialogInfo *const dialog, const xmlNode *const node)
 

Variables

bool anonymous_namespace{npcdialogdb.cpp}::mLoaded = false
 
NpcDialogDB::Dialogs anonymous_namespace{npcdialogdb.cpp}::mDialogs
 

Function Documentation

◆ loadNpcDialog()

static void loadNpcDialog ( NpcDialogInfo *const  dialog,
const xmlNode *const  node 
)
static

Definition at line 135 of file npcdialogdb.cpp.

137 {
138  for_each_xml_child_node(childNode, node)
139  {
140  if (xmlNameEqual(childNode, "menu"))
141  {
142  loadNpcDialogMenu(dialog, childNode);
143  }
144  else if (xmlNameEqual(childNode, "inventory"))
145  {
146  loadNpcDialogInventory(dialog, childNode);
147  }
148  }
149 }
#define for_each_xml_child_node(var, parent)
Definition: libxml.h:161
static void loadNpcDialogMenu(NpcDialogInfo *const dialog, const xmlNode *const node)
Definition: npcdialogdb.cpp:53
static void loadNpcDialogInventory(NpcDialogInfo *const dialog, xmlNode *const node)

References for_each_xml_child_node, loadNpcDialogInventory(), and loadNpcDialogMenu().

Referenced by NpcDialogDB::loadXmlFile().

◆ loadNpcDialogInventory()

static void loadNpcDialogInventory ( NpcDialogInfo *const  dialog,
xmlNode *const  node 
)
static

Definition at line 127 of file npcdialogdb.cpp.

129 {
130  dialog->inventory.cell = XML::getProperty(node, "cell", "");
132  node, "columns", 10000, 1, 10000);
133 }
int getProperty(const xmlNodePtr node, const char *const name, int def)
Definition: libxml.cpp:174
int getIntProperty(const xmlNodePtr node, const char *const name, int def, const int min, const int max)
Definition: libxml.cpp:190
NpcInventoryInfo inventory
Definition: npcdialoginfo.h:43

References NpcInventoryInfo::cell, NpcInventoryInfo::columns, XML::getIntProperty(), XML::getProperty(), and NpcDialogInfo::inventory.

Referenced by loadNpcDialog().

◆ loadNpcDialogMenu()

static void loadNpcDialogMenu ( NpcDialogInfo *const  dialog,
const xmlNode *const  node 
)
static

Definition at line 53 of file npcdialogdb.cpp.

55 {
56  for_each_xml_child_node(childNode, node)
57  {
58  if (!xmlTypeEqual(childNode, XML_ELEMENT_NODE))
59  continue;
60 
61  if (xmlNameEqual(childNode, "button"))
62  {
63  const std::string name = XML::getProperty(childNode, "name", "");
64  const std::string value = XML::getProperty(childNode, "value", "");
65  if (value.empty())
66  continue;
67 
68  NpcButtonInfo *const button = new NpcButtonInfo;
69  button->x = XML::getIntProperty(
70  childNode, "x", 0, 0, 10000);
71  button->y = XML::getIntProperty(
72  childNode, "y", 0, 0, 10000);
73  button->name = name;
74  button->value = value;
75  button->image = XML::getProperty(childNode, "image", "");
76  if (button->name.empty() && button->image.empty())
77  {
78  reportAlways("Error: npc button without name or image")
79  delete button;
80  continue;
81  }
82  button->imageWidth = XML::getIntProperty(
83  childNode, "imageWidth", 16, 1, 1000);
84  button->imageHeight = XML::getIntProperty(
85  childNode, "imageHeight", 16, 1, 1000);
86  dialog->menu.buttons.push_back(button);
87  }
88  else if (xmlNameEqual(childNode, "image"))
89  {
90  const std::string image = XML::getProperty(childNode, "image", "");
91  if (image.empty())
92  {
93  reportAlways("Error: no image attribute found in image tag.")
94  continue;
95  }
96  NpcImageInfo *const imageInfo = new NpcImageInfo;
97  imageInfo->name = image;
98  imageInfo->x = XML::getIntProperty(
99  childNode, "x", 0, 0, 10000);
100  imageInfo->y = XML::getIntProperty(
101  childNode, "y", 0, 0, 10000);
102  dialog->menu.images.push_back(imageInfo);
103  }
104  else if (xmlNameEqual(childNode, "text"))
105  {
106  const std::string text = XML::getProperty(childNode, "text", "");
107  if (text.empty())
108  {
109  reportAlways("Error: no text attribute found in text tag.")
110  continue;
111  }
112  NpcTextInfo *const textInfo = new NpcTextInfo;
113  textInfo->text = text;
114  textInfo->x = XML::getIntProperty(
115  childNode, "x", 0, 0, 10000);
116  textInfo->y = XML::getIntProperty(
117  childNode, "y", 0, 0, 10000);
118  textInfo->width = XML::getIntProperty(
119  childNode, "width", 20, 10, 10000);
120  textInfo->height = XML::getIntProperty(
121  childNode, "height", 20, 10, 10000);
122  dialog->menu.texts.push_back(textInfo);
123  }
124  }
125 }
#define reportAlways(...)
Definition: checkutils.h:253
#define new
Definition: debug_new.h:147
if(!vert) return
MenuTypeT menu
Definition: menu.cpp:28
Definition: libxml.cpp:86
std::string name
Definition: npcbuttoninfo.h:44
std::string value
Definition: npcbuttoninfo.h:45
std::string image
Definition: npcbuttoninfo.h:46

References NpcDialogMenuInfo::buttons, for_each_xml_child_node, XML::getIntProperty(), XML::getProperty(), NpcTextInfo::height, NpcButtonInfo::image, NpcButtonInfo::imageHeight, NpcDialogMenuInfo::images, NpcButtonInfo::imageWidth, NpcDialogInfo::menu, NpcButtonInfo::name, NpcImageInfo::name, reportAlways, NpcTextInfo::text, NpcDialogMenuInfo::texts, NpcButtonInfo::value, NpcTextInfo::width, NpcButtonInfo::x, NpcImageInfo::x, NpcTextInfo::x, NpcButtonInfo::y, NpcImageInfo::y, and NpcTextInfo::y.

Referenced by loadNpcDialog().