summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-12-10 13:25:38 +0300
committerAndrei Karas <akaras@inbox.ru>2014-12-10 13:25:38 +0300
commit926a702799f919bbe75f3e8adcac30129749a963 (patch)
tree387e4b0bf80904863e056bd71d36ff36f5a221b6 /src
parentb4de7c68b240dd1b63ac1b78feb0721977cdb171 (diff)
downloadmanaverse-926a702799f919bbe75f3e8adcac30129749a963.tar.gz
manaverse-926a702799f919bbe75f3e8adcac30129749a963.tar.bz2
manaverse-926a702799f919bbe75f3e8adcac30129749a963.tar.xz
manaverse-926a702799f919bbe75f3e8adcac30129749a963.zip
Show custom menu for npc.
Also fix loading menu.
Diffstat (limited to 'src')
-rw-r--r--src/gui/popups/popupmenu.cpp49
-rw-r--r--src/gui/popups/popupmenu.h2
-rw-r--r--src/resources/db/npcdb.cpp8
3 files changed, 43 insertions, 16 deletions
diff --git a/src/gui/popups/popupmenu.cpp b/src/gui/popups/popupmenu.cpp
index eb2144de3..b636d1d7c 100644
--- a/src/gui/popups/popupmenu.cpp
+++ b/src/gui/popups/popupmenu.cpp
@@ -85,6 +85,8 @@
#include "resources/mapitemtype.h"
#include "resources/skillconsts.h"
+#include "resources/db/npcdb.h"
+
#include "resources/map/map.h"
#include "resources/map/mapitem.h"
#include "resources/map/speciallayer.h"
@@ -245,21 +247,25 @@ void PopupMenu::showPopup(const int x, const int y, const Being *const being)
}
case ActorType::Npc:
- // TRANSLATORS: popup menu item
- // TRANSLATORS: talk with npc
- mBrowserBox->addRow("talk", _("Talk"));
- if (serverFeatures->haveNpcWhispers())
+ if (!addBeingMenu())
{
// TRANSLATORS: popup menu item
- // TRANSLATORS: whisper to npc
- mBrowserBox->addRow("npc whisper", _("Whisper"));
+ // TRANSLATORS: talk with npc
+ mBrowserBox->addRow("talk", _("Talk"));
+ if (serverFeatures->haveNpcWhispers())
+ {
+ // TRANSLATORS: popup menu item
+ // TRANSLATORS: whisper to npc
+ mBrowserBox->addRow("npc whisper", _("Whisper"));
+ }
+ // TRANSLATORS: popup menu item
+ // TRANSLATORS: buy from npc
+ mBrowserBox->addRow("buy", _("Buy"));
+ // TRANSLATORS: popup menu item
+ // TRANSLATORS: sell to npc
+ mBrowserBox->addRow("sell", _("Sell"));
}
- // TRANSLATORS: popup menu item
- // TRANSLATORS: buy from npc
- mBrowserBox->addRow("buy", _("Buy"));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: sell to npc
- mBrowserBox->addRow("sell", _("Sell"));
+
mBrowserBox->addRow("##3---");
// TRANSLATORS: popup menu item
// TRANSLATORS: move to npc location
@@ -370,6 +376,25 @@ void PopupMenu::showPopup(const int x, const int y, const Being *const being)
showPopup(x, y);
}
+bool PopupMenu::addBeingMenu()
+{
+ Being *being = actorManager->findBeing(mBeingId);
+ if (!being)
+ return false;
+
+ BeingInfo *const info = NPCDB::get(being->getSubType());
+ if (!info)
+ return false;
+
+ const std::vector<BeingMenuItem> &menu = info->getMenu();
+ FOR_EACH (std::vector<BeingMenuItem>::const_iterator, it, menu)
+ {
+ const BeingMenuItem &item = *it;
+ mBrowserBox->addRow("@" + item.command, item.name.c_str());
+ }
+ return true;
+}
+
void PopupMenu::setMousePos()
{
if (viewport)
diff --git a/src/gui/popups/popupmenu.h b/src/gui/popups/popupmenu.h
index da0f59847..e60d13d8d 100644
--- a/src/gui/popups/popupmenu.h
+++ b/src/gui/popups/popupmenu.h
@@ -187,6 +187,8 @@ class PopupMenu final : public Popup, public LinkHandler
void showGMPopup();
+ bool addBeingMenu();
+
BrowserBox *mBrowserBox;
ScrollArea *mScrollArea;
diff --git a/src/resources/db/npcdb.cpp b/src/resources/db/npcdb.cpp
index 5f7c48b0b..4d9fea247 100644
--- a/src/resources/db/npcdb.cpp
+++ b/src/resources/db/npcdb.cpp
@@ -111,11 +111,11 @@ void NPCDB::loadXmlFile(const std::string &fileName)
SpriteDisplay display;
for_each_xml_child_node(spriteNode, npcNode)
{
- if (!spriteNode->xmlChildrenNode)
- continue;
-
if (xmlNameEqual(spriteNode, "sprite"))
{
+ if (!spriteNode->xmlChildrenNode)
+ continue;
+
SpriteReference *const currentSprite = new SpriteReference;
currentSprite->sprite = reinterpret_cast<const char*>(
spriteNode->xmlChildrenNode->content);
@@ -131,7 +131,7 @@ void NPCDB::loadXmlFile(const std::string &fileName)
else if (xmlNameEqual(spriteNode, "menu"))
{
std::string name = XML::getProperty(spriteNode, "name", "");
- std::string command = XML::getProperty(spriteNode,
+ std::string command = XML::langProperty(spriteNode,
"command", "");
currentInfo->addMenu(name, command);
}