From 48d66daa641c58d68a4150b1f6bf958dfb8ecb13 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 11 Dec 2014 00:22:44 +0300 Subject: Handle custom commands in npc menu. --- src/gui/popups/popupmenu.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/gui/popups/popupmenu.cpp b/src/gui/popups/popupmenu.cpp index b636d1d7c..4e85109ca 100644 --- a/src/gui/popups/popupmenu.cpp +++ b/src/gui/popups/popupmenu.cpp @@ -390,7 +390,7 @@ bool PopupMenu::addBeingMenu() FOR_EACH (std::vector::const_iterator, it, menu) { const BeingMenuItem &item = *it; - mBrowserBox->addRow("@" + item.command, item.name.c_str()); + mBrowserBox->addRow("/" + item.command, item.name.c_str()); } return true; } @@ -2024,6 +2024,25 @@ void PopupMenu::handleLink(const std::string &link, if (id >= 0) inputManager.executeAction(id); } + else if(!link.empty() && link[0] == '/') + { + std::string cmd = link.substr(1); + replaceAll(cmd, "'NAME'", mNick); + replaceAll(cmd, "'X'", toString(mX)); + replaceAll(cmd, "'Y'", toString(mY)); + replaceAll(cmd, "'BEINGID'", toString(mBeingId)); + replaceAll(cmd, "'FLOORID'", toString(mFloorItemId)); + replaceAll(cmd, "'ITEMID'", toString(mItemId)); + replaceAll(cmd, "'ITEMCOLOR'", toString(mItemColor)); + replaceAll(cmd, "'BEINGTYPEID'", toString(mType)); + replaceAll(cmd, "'PLAYER'", localPlayer->getName()); + + const size_t pos = cmd.find(' '); + const std::string type(cmd, 0, pos); + std::string args(cmd, pos == std::string::npos ? cmd.size() : pos + 1); + args = trim(args); + inputManager.executeChatCommand(type, args, mTab); + } // Unknown actions else if (link != "cancel") { -- cgit v1.2.3-70-g09d2