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 +++++++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 12 deletions(-) (limited to 'src/gui/popups/popupmenu.cpp') 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) -- cgit v1.2.3-60-g2f50