summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-01-11 12:24:18 +0300
committerAndrei Karas <akaras@inbox.ru>2014-01-11 12:24:18 +0300
commita154e6e99dfc72636770920f497d57c278b96996 (patch)
treeac56e36ace297bbfae1e60516103b1d23c8c35ba /src
parent9306c6f2671a89fe84d1eb35d54550e58dd74d49 (diff)
downloadmanaverse-a154e6e99dfc72636770920f497d57c278b96996.tar.gz
manaverse-a154e6e99dfc72636770920f497d57c278b96996.tar.bz2
manaverse-a154e6e99dfc72636770920f497d57c278b96996.tar.xz
manaverse-a154e6e99dfc72636770920f497d57c278b96996.zip
Block moving character by arrow keys in buy/sell dialogs.
Check repeat keys for action condition.
Diffstat (limited to 'src')
-rw-r--r--src/input/inputmanager.cpp26
-rw-r--r--src/input/inputmanager.h8
-rw-r--r--src/input/keyboarddata.h8
3 files changed, 31 insertions, 11 deletions
diff --git a/src/input/inputmanager.cpp b/src/input/inputmanager.cpp
index 2bc0786fb..383362eed 100644
--- a/src/input/inputmanager.cpp
+++ b/src/input/inputmanager.cpp
@@ -38,10 +38,12 @@
#include "gui/widgets/tabs/setup_input.h"
+#include "gui/windows/buydialog.h"
#include "gui/windows/chatwindow.h"
#include "gui/windows/inventorywindow.h"
#include "gui/windows/npcdialog.h"
#include "gui/windows/npcpostdialog.h"
+#include "gui/windows/selldialog.h"
#include "gui/windows/setup.h"
#include "gui/windows/textdialog.h"
#include "gui/windows/tradewindow.h"
@@ -332,7 +334,18 @@ void InputManager::callbackNewKey()
mSetupInput->newKeyCallback(mNewKeyIndex);
}
-bool InputManager::isActionActive(const int index)
+bool InputManager::isActionActive(const int index) const
+{
+ if (!isActionActive0(index))
+ return false;
+
+ const KeyData &key = keyData[index];
+ if ((key.condition & mMask) != key.condition)
+ return false;
+ return true;
+}
+
+bool InputManager::isActionActive0(const int index) const
{
if (keyboard.isActionActive(index))
return true;
@@ -657,6 +670,9 @@ void InputManager::updateConditionMask()
mMask |= COND_NOINPUT;
}
+ if (!BuyDialog::isActive() && !SellDialog::isActive())
+ mMask |= COND_NOBUYSELL;
+
if (!player_node || !player_node->getAway())
mMask |= COND_NOAWAY;
@@ -676,8 +692,8 @@ void InputManager::updateConditionMask()
if (!player_node || !player_node->getDisableGameModifiers())
mMask |= COND_EMODS;
- if (!isActionActive(Input::KEY_STOP_ATTACK)
- && !isActionActive(Input::KEY_UNTARGET))
+ if (!isActionActive0(Input::KEY_STOP_ATTACK)
+ && !isActionActive0(Input::KEY_UNTARGET))
{
mMask |= COND_NOTARGET;
}
@@ -690,12 +706,12 @@ void InputManager::updateConditionMask()
bool InputManager::checkKey(const KeyData *const key) const
{
-// logger->log("mask=%d, condition=%d", mMask, key->condition);
+ logger->log("mask=%d, condition=%d", mMask, key->condition);
if (!key || (key->condition & mMask) != key->condition)
return false;
return (key->modKeyIndex == Input::KEY_NO_VALUE
- || isActionActive(key->modKeyIndex));
+ || isActionActive0(key->modKeyIndex));
}
bool InputManager::invokeKey(const KeyData *const key, const int keyNum)
diff --git a/src/input/inputmanager.h b/src/input/inputmanager.h
index 1a65220c6..f781a3e09 100644
--- a/src/input/inputmanager.h
+++ b/src/input/inputmanager.h
@@ -84,10 +84,12 @@ enum KeyCondition
// pressed
COND_NOFOLLOW = 1024, // follow mode disabled
COND_INGAME = 2048, // game must be started
+ COND_NOBUYSELL = 4096, // no active buy or sell dialogs
COND_SHORTCUT = 2 + 4 + 16 + 512 + 2048, // flags for shortcut keys
COND_SHORTCUT0 = 2 + 4 + 16 + 512, // flags for shortcut keys
COND_GAME = 2 + 4 + 8 + 16 + 64 + 2048, // main game key
- COND_GAME2 = 2 + 8 + 16 + 64 + 2048
+ COND_GAME2 = 2 + 8 + 16 + 64 + 2048,
+ COND_ARROWKEYS = 2 + 8 + 16 + 64 + 2048 + 4096
};
class InputManager final
@@ -130,7 +132,7 @@ class InputManager final
void unassignKey();
- static bool isActionActive(const int index) A_WARN_UNUSED;
+ bool isActionActive(const int index) const A_WARN_UNUSED;
/**
* Set the index of the new key to be assigned.
@@ -174,6 +176,8 @@ class InputManager final
void executeAction(const int keyNum);
protected:
+ bool isActionActive0(const int index) const A_WARN_UNUSED;
+
Setup_Input *mSetupInput; /**< Reference to setup window */
int mNewKeyIndex; /**< Index of new key to be assigned */
diff --git a/src/input/keyboarddata.h b/src/input/keyboarddata.h
index 5dd9e84a3..74278777f 100644
--- a/src/input/keyboarddata.h
+++ b/src/input/keyboarddata.h
@@ -40,28 +40,28 @@ static const KeyData keyData[Input::KEY_TOTAL] = {
Input::GRP_DEFAULT,
&ActionManager::moveUp,
Input::KEY_NO_VALUE, 50,
- COND_GAME2},
+ COND_ARROWKEYS},
{"keyMoveDown",
INPUT_KEYBOARD, SDLK_DOWN,
INPUT_UNKNOWN, Input::KEY_NO_VALUE,
Input::GRP_DEFAULT,
&ActionManager::moveDown,
Input::KEY_NO_VALUE, 50,
- COND_GAME2},
+ COND_ARROWKEYS},
{"keyMoveLeft",
INPUT_KEYBOARD, SDLK_LEFT,
INPUT_UNKNOWN, Input::KEY_NO_VALUE,
Input::GRP_DEFAULT,
&ActionManager::moveLeft,
Input::KEY_NO_VALUE, 50,
- COND_GAME},
+ COND_ARROWKEYS},
{"keyMoveRight",
INPUT_KEYBOARD, SDLK_RIGHT,
INPUT_UNKNOWN, Input::KEY_NO_VALUE,
Input::GRP_DEFAULT,
&ActionManager::moveRight,
Input::KEY_NO_VALUE, 50,
- COND_GAME},
+ COND_ARROWKEYS},
{"keyAttack",
INPUT_KEYBOARD, SDLK_LCTRL,
INPUT_UNKNOWN, Input::KEY_NO_VALUE,