summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-05-18 19:42:42 +0300
committerAndrei Karas <akaras@inbox.ru>2013-05-18 19:43:41 +0300
commit00c7073096a7bf40cee7595d0d419b9feff1c120 (patch)
tree307e3c76b2eb7b828478a8cd8f323158d26ca766 /src
parent25a143ac11baebc9ecaf5c2c05d4808f20d54e3c (diff)
downloadmv-00c7073096a7bf40cee7595d0d419b9feff1c120.tar.gz
mv-00c7073096a7bf40cee7595d0d419b9feff1c120.tar.bz2
mv-00c7073096a7bf40cee7595d0d419b9feff1c120.tar.xz
mv-00c7073096a7bf40cee7595d0d419b9feff1c120.zip
Add ability to call input action from commands.
add new commands: /drop - drop from first slot. /dropn - drop fro any slots. /movetotarget - move to target position. /movetohome - move to home position. /sethome - set home position.
Diffstat (limited to 'src')
-rw-r--r--src/commandhandler.cpp25
-rw-r--r--src/commandhandler.h8
-rw-r--r--src/commands.h170
3 files changed, 117 insertions, 86 deletions
diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp
index a9b5672ee..d769f121f 100644
--- a/src/commandhandler.cpp
+++ b/src/commandhandler.cpp
@@ -22,6 +22,8 @@
#include "commandhandler.h"
+#include "inputmanager.h"
+
#include "gui/widgets/chattab.h"
#include "utils/gettext.h"
@@ -37,7 +39,7 @@ CommandHandler::CommandHandler() :
{
const std::string name = commands[f].name;
if (!name.empty())
- mCommands[name] = commands[f].func;
+ mCommands[name] = &commands[f];
}
}
@@ -68,7 +70,7 @@ void CommandHandler::invokeCommand(const std::string &type,
const CommandsMapIter it = mCommands.find(type);
if (it != mCommands.end())
{
- ((*it).second)(args, tab);
+ callFunc(*(*it).second, args, tab);
}
else if (!tab->handleCommand(type, args))
{
@@ -80,12 +82,23 @@ void CommandHandler::invokeCommand(const std::string &type,
}
}
+void CommandHandler::callFunc(const CommandInfo &info,
+ const std::string &args,
+ ChatTab *const tab)
+{
+ CommandFuncPtr func = info.func;
+ if (func)
+ func(args, tab);
+ else
+ inputManager.executeAction(info.actionId);
+}
+
void CommandHandler::invokeCommand(const int type,
const bool warn)
{
if (type < 0 || type >= END_COMMANDS)
return;
- (commands[type].func)("", nullptr);
+ callFunc(commands[type], "", nullptr);
}
void CommandHandler::invokeCommand(const int type,
@@ -94,7 +107,7 @@ void CommandHandler::invokeCommand(const int type,
{
if (type < 0 || type >= END_COMMANDS)
return;
- (commands[type].func)("", tab);
+ callFunc(commands[type], "", tab);
}
void CommandHandler::invokeCommand(const int type,
@@ -103,7 +116,7 @@ void CommandHandler::invokeCommand(const int type,
{
if (type < 0 || type >= END_COMMANDS)
return;
- (commands[type].func)(args, nullptr);
+ callFunc(commands[type], args, nullptr);
}
void CommandHandler::invokeCommand(const int type,
@@ -113,5 +126,5 @@ void CommandHandler::invokeCommand(const int type,
{
if (type < 0 || type >= END_COMMANDS)
return;
- (commands[type].func)(args, tab);
+ callFunc(commands[type], args, tab);
}
diff --git a/src/commandhandler.h b/src/commandhandler.h
index 2bcd9e596..a655d8d32 100644
--- a/src/commandhandler.h
+++ b/src/commandhandler.h
@@ -33,7 +33,7 @@ class ChatTab;
extern ChatTab *localChatTab;
-typedef std::map<std::string, CommandFuncPtr> CommandsMap;
+typedef std::map<std::string, const CommandInfo*> CommandsMap;
typedef CommandsMap::const_iterator CommandsMapIter;
/**
@@ -89,6 +89,12 @@ class CommandHandler final
friend class ChatTab;
friend class WhisperTab;
CommandsMap mCommands;
+
+ private:
+ void callFunc(const CommandInfo &info,
+ const std::string &args,
+ ChatTab *const tab);
+
};
extern CommandHandler *commandHandler;
diff --git a/src/commands.h b/src/commands.h
index f990ab69a..182faa895 100644
--- a/src/commands.h
+++ b/src/commands.h
@@ -24,6 +24,7 @@
#define COMMANDS_H
#include "playerrelations.h"
+#include "keydata.h"
#include <string>
@@ -42,6 +43,7 @@ struct CommandInfo
{
const char *name;
CommandFuncPtr func;
+ int actionId;
};
namespace Commands
@@ -204,91 +206,101 @@ enum
COMMAND_REMOVENAME,
COMMAND_DISABLEAWAY,
COMMAND_ENABLEAWAY,
+ COMMAND_DROP,
+ COMMAND_DROPN,
+ COMMAND_MOVETOTARGET,
+ COMMAND_MOVETOHOME,
+ COMMAND_SETHOME,
COMMAND_HACK,
END_COMMANDS,
};
static const CommandInfo commands[] =
{
- {"closeall", &Commands::closeAll},
- {"ignoreall", &Commands::ignoreAll},
- {"help", &Commands::help},
- {"announce", &Commands::announce},
- {"where", &Commands::where},
- {"who", &Commands::who},
- {"msg", Commands::msg},
- {"whisper", Commands::msg},
- {"w", &Commands::msg},
- {"query", Commands::query},
- {"q", &Commands::query},
- {"ignore", &Commands::ignore},
- {"unignore", &Commands::unignore},
- {"friend", Commands::beFriend},
- {"befriend", &Commands::beFriend},
- {"disregard", &Commands::disregard},
- {"neutral", &Commands::neutral},
- {"blacklist", &Commands::blackList},
- {"enemy", &Commands::enemy},
- {"erase", &Commands::erase},
- {"clear", &Commands::clear},
- {"cleangraphics", &Commands::cleanGraphics},
- {"cleanfonts", &Commands::cleanFonts},
- {"createparty", &Commands::createParty},
- {"createguild", &Commands::createGuild},
- {"party", &Commands::party},
- {"me", &Commands::me},
- {"toggle", &Commands::toggle},
- {"present", &Commands::present},
- {"quit", &Commands::quit},
- {"all", &Commands::showAll},
- {"move", &Commands::move},
- {"target", &Commands::target},
- {"atkhuman", &Commands::attackHuman},
- {"outfit", &Commands::outfit},
- {"emote", &Commands::emote},
- {"away", &Commands::away},
- {"pseudoaway", &Commands::pseudoAway},
- {"follow", &Commands::follow},
- {"heal", &Commands::heal},
- {"navigate", &Commands::navigate},
- {"imitation", &Commands::imitation},
- {"mail", &Commands::mail},
- {"trade", &Commands::trade},
- {"priceload", &Commands::priceLoad},
- {"pricesave", &Commands::priceSave},
- {"cacheinfo", &Commands::cacheInfo},
- {"disconnect", &Commands::disconnect},
- {"undress", &Commands::undress},
- {"attack", &Commands::attack},
- {"dirs", &Commands::dirs},
- {"info", &Commands::info},
- {"wait", &Commands::wait},
- {"uptime", &Commands::uptime},
- {"addpriorityattack", &Commands::addPriorityAttack},
- {"addattack", &Commands::addAttack},
- {"removeattack", Commands::removeAttack},
- {"removeignoreattack", &Commands::removeAttack},
- {"addignoreattack", &Commands::addIgnoreAttack},
- {"dump", &Commands::dump},
- {"serverignoreall", &Commands::serverIgnoreAll},
- {"serverunignoreall", &Commands::serverUnIgnoreAll},
- {"setdrop", &Commands::setDrop},
- {"error", &Commands::error},
- {"dumpg", &Commands::dumpGraphics},
- {"dumpe", &Commands::dumpEnvironment},
- {"dumpt", &Commands::dumpTests},
- {"dumpogl", &Commands::dumpOGL},
- {"url", &Commands::url},
- {"open", &Commands::open},
- {"execute", &Commands::execute},
- {"testsdlfont", &Commands::testsdlfont},
- {"enablehighlight", &Commands::enableHighlight},
- {"disablehighlight", &Commands::disableHighlight},
- {"", &Commands::dontRemoveName},
- {"", &Commands::removeName},
- {"disableaway", &Commands::disableAway},
- {"enableaway", &Commands::enableAway},
- {"hack", &Commands::hack}
+ {"closeall", &Commands::closeAll, -1},
+ {"ignoreall", &Commands::ignoreAll, -1},
+ {"help", &Commands::help, -1},
+ {"announce", &Commands::announce, -1},
+ {"where", &Commands::where, -1},
+ {"who", &Commands::who, -1},
+ {"msg", Commands::msg, -1},
+ {"whisper", Commands::msg, -1},
+ {"w", &Commands::msg, -1},
+ {"query", Commands::query, -1},
+ {"q", &Commands::query, -1},
+ {"ignore", &Commands::ignore, -1},
+ {"unignore", &Commands::unignore, -1},
+ {"friend", Commands::beFriend, -1},
+ {"befriend", &Commands::beFriend, -1},
+ {"disregard", &Commands::disregard, -1},
+ {"neutral", &Commands::neutral, -1},
+ {"blacklist", &Commands::blackList, -1},
+ {"enemy", &Commands::enemy, -1},
+ {"erase", &Commands::erase, -1},
+ {"clear", &Commands::clear, -1},
+ {"cleangraphics", &Commands::cleanGraphics, -1},
+ {"cleanfonts", &Commands::cleanFonts, -1},
+ {"createparty", &Commands::createParty, -1},
+ {"createguild", &Commands::createGuild, -1},
+ {"party", &Commands::party, -1},
+ {"me", &Commands::me, -1},
+ {"toggle", &Commands::toggle, -1},
+ {"present", &Commands::present, -1},
+ {"quit", &Commands::quit, -1},
+ {"all", &Commands::showAll, -1},
+ {"move", &Commands::move, -1},
+ {"target", &Commands::target, -1},
+ {"atkhuman", &Commands::attackHuman, -1},
+ {"outfit", &Commands::outfit, -1},
+ {"emote", &Commands::emote, -1},
+ {"away", &Commands::away, -1},
+ {"pseudoaway", &Commands::pseudoAway, -1},
+ {"follow", &Commands::follow, -1},
+ {"heal", &Commands::heal, -1},
+ {"navigate", &Commands::navigate, -1},
+ {"imitation", &Commands::imitation, -1},
+ {"mail", &Commands::mail, -1},
+ {"trade", &Commands::trade, -1},
+ {"priceload", &Commands::priceLoad, -1},
+ {"pricesave", &Commands::priceSave, -1},
+ {"cacheinfo", &Commands::cacheInfo, -1},
+ {"disconnect", &Commands::disconnect, -1},
+ {"undress", &Commands::undress, -1},
+ {"attack", &Commands::attack, -1},
+ {"dirs", &Commands::dirs, -1},
+ {"info", &Commands::info, -1},
+ {"wait", &Commands::wait, -1},
+ {"uptime", &Commands::uptime, -1},
+ {"addpriorityattack", &Commands::addPriorityAttack, -1},
+ {"addattack", &Commands::addAttack, -1},
+ {"removeattack", Commands::removeAttack, -1},
+ {"removeignoreattack", &Commands::removeAttack, -1},
+ {"addignoreattack", &Commands::addIgnoreAttack, -1},
+ {"dump", &Commands::dump, -1},
+ {"serverignoreall", &Commands::serverIgnoreAll, -1},
+ {"serverunignoreall", &Commands::serverUnIgnoreAll, -1},
+ {"setdrop", &Commands::setDrop, -1},
+ {"error", &Commands::error, -1},
+ {"dumpg", &Commands::dumpGraphics, -1},
+ {"dumpe", &Commands::dumpEnvironment, -1},
+ {"dumpt", &Commands::dumpTests, -1},
+ {"dumpogl", &Commands::dumpOGL, -1},
+ {"url", &Commands::url, -1},
+ {"open", &Commands::open, -1},
+ {"execute", &Commands::execute, -1},
+ {"testsdlfont", &Commands::testsdlfont, -1},
+ {"enablehighlight", &Commands::enableHighlight, -1},
+ {"disablehighlight", &Commands::disableHighlight, -1},
+ {"", &Commands::dontRemoveName, -1},
+ {"", &Commands::removeName, -1},
+ {"disableaway", &Commands::disableAway, -1},
+ {"enableaway", &Commands::enableAway, -1},
+ {"drop", nullptr, Input::KEY_QUICK_DROP},
+ {"dropn", nullptr, Input::KEY_QUICK_DROPN},
+ {"movetotarget", nullptr, Input::KEY_MOVE_TO_TARGET},
+ {"movetohome", nullptr, Input::KEY_MOVE_TO_HOME},
+ {"sethome", nullptr, Input::KEY_SET_HOME},
+ {"hack", &Commands::hack, -1}
};
#undef decHandler