summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-01-13 12:12:10 +0300
committerAndrei Karas <akaras@inbox.ru>2014-01-13 12:12:10 +0300
commitb863927543393468a7153775c18ef04a59f20a7f (patch)
tree56e6d7345598c0524ac4fd7310f6a85d465ce2c3
parent6fcb5c4b9f03dd3e4b9fea0475aec2c21a8510bc (diff)
downloadplus-b863927543393468a7153775c18ef04a59f20a7f.tar.gz
plus-b863927543393468a7153775c18ef04a59f20a7f.tar.bz2
plus-b863927543393468a7153775c18ef04a59f20a7f.tar.xz
plus-b863927543393468a7153775c18ef04a59f20a7f.zip
allow auto close npc dialog if it almost closed and press moving keys.
-rw-r--r--src/actionmanager.cpp36
-rw-r--r--src/game.cpp13
-rw-r--r--src/gui/windows/npcdialog.h3
-rw-r--r--src/input/inputmanager.cpp14
-rw-r--r--src/input/inputmanager.h6
-rw-r--r--src/input/keyboarddata.h2
6 files changed, 52 insertions, 22 deletions
diff --git a/src/actionmanager.cpp b/src/actionmanager.cpp
index 9152dfe7a..cc04e60a1 100644
--- a/src/actionmanager.cpp
+++ b/src/actionmanager.cpp
@@ -87,28 +87,36 @@ extern QuitDialog *quitDialog;
namespace ActionManager
{
-impHandler(moveUp)
+static bool closeMoveNpcDialog(bool focus)
{
- if (NpcDialog *const dialog = NpcDialog::getActive())
+ NpcDialog *const dialog = NpcDialog::getActive();
+ if (dialog)
{
- dialog->refocus();
- return false;
+ if (dialog->isCloseState())
+ {
+ dialog->closeDialog();
+ return true;
+ }
+ else if (focus)
+ {
+ dialog->refocus();
+ }
}
+ return false;
+}
+
+impHandler(moveUp)
+{
if (inputManager.isActionActive(Input::KEY_EMOTE))
return directUp(event);
- return false;
+ return closeMoveNpcDialog(false);
}
impHandler(moveDown)
{
- if (NpcDialog *const dialog = NpcDialog::getActive())
- {
- dialog->refocus();
- return false;
- }
if (inputManager.isActionActive(Input::KEY_EMOTE))
return directDown(event);
- return false;
+ return closeMoveNpcDialog(false);
}
impHandler(moveLeft)
@@ -122,7 +130,7 @@ impHandler(moveLeft)
}
if (inputManager.isActionActive(Input::KEY_EMOTE))
return directLeft(event);
- return false;
+ return closeMoveNpcDialog(false);
}
impHandler(moveRight)
@@ -136,14 +144,14 @@ impHandler(moveRight)
}
if (inputManager.isActionActive(Input::KEY_EMOTE))
return directRight(event);
- return false;
+ return closeMoveNpcDialog(false);
}
impHandler(moveForward)
{
if (inputManager.isActionActive(Input::KEY_EMOTE))
return directRight(event);
- return false;
+ return closeMoveNpcDialog(false);
}
impHandler(emote)
diff --git a/src/game.cpp b/src/game.cpp
index eada32f45..52c348a7e 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -65,6 +65,7 @@
#include "gui/windows/killstats.h"
#include "gui/windows/minimap.h"
#include "gui/windows/ministatuswindow.h"
+#include "gui/windows/npcdialog.h"
#include "gui/windows/okdialog.h"
#include "gui/windows/outfitwindow.h"
#include "gui/windows/setup.h"
@@ -803,10 +804,16 @@ void Game::handleMove()
return;
// Moving player around
- if (player_node->isAlive() && !PlayerInfo::isTalking()
- && chatWindow && !chatWindow->isInputFocused()
- && !InventoryWindow::isAnyInputFocused() && !quitDialog)
+ if (player_node->isAlive()
+ && chatWindow
+ && !chatWindow->isInputFocused()
+ && !InventoryWindow::isAnyInputFocused()
+ && !quitDialog)
{
+ NpcDialog *const dialog = NpcDialog::getActive();
+ if (dialog)
+ return;
+
// Ignore input if either "ignore" key is pressed
// Stops the character moving about if the user's window manager
// uses "ignore+arrow key" to switch virtual desktops.
diff --git a/src/gui/windows/npcdialog.h b/src/gui/windows/npcdialog.h
index af68594cd..5e679d7d1 100644
--- a/src/gui/windows/npcdialog.h
+++ b/src/gui/windows/npcdialog.h
@@ -212,6 +212,9 @@ class NpcDialog final : public Window,
void mousePressed(gcn::MouseEvent &event);
+ int isCloseState() const
+ { return mActionState == NPC_ACTION_CLOSE; }
+
static void copyToClipboard(const int npcId, const int x, const int y);
static NpcDialogs mNpcDialogs;
diff --git a/src/input/inputmanager.cpp b/src/input/inputmanager.cpp
index c8c63dc4f..645bfe351 100644
--- a/src/input/inputmanager.cpp
+++ b/src/input/inputmanager.cpp
@@ -24,11 +24,11 @@
#include "game.h"
#include "touchmanager.h"
-#include "being/localplayer.h"
-
#include "input/joystick.h"
#include "input/keyboardconfig.h"
#include "input/keyboarddata.h"
+#include "being/localplayer.h"
+#include "being/playerinfo.h"
#ifdef USE_SDL2
#include "input/multitouchmanager.h"
#endif
@@ -340,6 +340,8 @@ bool InputManager::isActionActive(const int index) const
return false;
const KeyData &key = keyData[index];
+// logger->log("isActionActive mask=%d, condition=%d, index=%d",
+// mMask, key.condition, index);
if ((key.condition & mMask) != key.condition)
return false;
return true;
@@ -688,6 +690,12 @@ void InputManager::updateConditionMask()
const NpcDialog *const dialog = NpcDialog::getActive();
if (!dialog || !dialog->isTextInputFocused())
mMask |= COND_NONPCINPUT;
+ if (!dialog || dialog->isCloseState())
+ {
+ mMask |= COND_NONPCDIALOG;
+ if (!InventoryWindow::isStorageActive())
+ mMask |= COND_NOTALKING;
+ }
if (!player_node || !player_node->getDisableGameModifiers())
mMask |= COND_EMODS;
@@ -706,7 +714,7 @@ void InputManager::updateConditionMask()
bool InputManager::checkKey(const KeyData *const key) const
{
-// logger->log("mask=%d, condition=%d", mMask, key->condition);
+ //logger->log("checkKey mask=%d, condition=%d", mMask, key->condition);
if (!key || (key->condition & mMask) != key->condition)
return false;
diff --git a/src/input/inputmanager.h b/src/input/inputmanager.h
index f781a3e09..ce662611a 100644
--- a/src/input/inputmanager.h
+++ b/src/input/inputmanager.h
@@ -85,11 +85,15 @@ enum KeyCondition
COND_NOFOLLOW = 1024, // follow mode disabled
COND_INGAME = 2048, // game must be started
COND_NOBUYSELL = 4096, // no active buy or sell dialogs
+ COND_NONPCDIALOG = 8192, // no active npc dialog or
+ // dialog almost closed
+ COND_NOTALKING = 16384, // player have no opened
+ // dialogs what prevent moving
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_ARROWKEYS = 2 + 8 + 16 + 64 + 2048 + 4096
+ COND_ARROWKEYS = 2 + 8 + 16 + 64 + 2048 + 4096 + 16384
};
class InputManager final
diff --git a/src/input/keyboarddata.h b/src/input/keyboarddata.h
index 74278777f..0de9c871e 100644
--- a/src/input/keyboarddata.h
+++ b/src/input/keyboarddata.h
@@ -1974,7 +1974,7 @@ static const KeyData keyData[Input::KEY_TOTAL] = {
Input::GRP_DEFAULT,
&ActionManager::moveForward,
Input::KEY_NO_VALUE, 50,
- COND_GAME},
+ COND_ARROWKEYS},
{"keyGUICtrl",
INPUT_KEYBOARD, SDLK_LCTRL,
INPUT_UNKNOWN, Input::KEY_NO_VALUE,