From 926a702799f919bbe75f3e8adcac30129749a963 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 10 Dec 2014 13:25:38 +0300 Subject: Show custom menu for npc. Also fix loading menu. --- src/gui/popups/popupmenu.cpp | 49 +++++++++++++++++++++++++++++++++----------- src/gui/popups/popupmenu.h | 2 ++ src/resources/db/npcdb.cpp | 8 ++++---- 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 &menu = info->getMenu(); + FOR_EACH (std::vector::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( 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); } -- cgit v1.2.3-70-g09d2