From b3f55809a8a56a5acf180371f05163091263cbda Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 29 Feb 2012 22:44:19 +0300 Subject: Fix npc menu focus/defocus issue. --- src/game.cpp | 11 ++++++----- src/gui/npcdialog.cpp | 11 +++++++++++ src/gui/npcdialog.h | 2 ++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/game.cpp b/src/game.cpp index ae8682972..a0c2a6151 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -803,12 +803,13 @@ bool Game::handleSwitchKeys(SDL_Event &event, bool &used) used = true; } } - if (dialog) + if (dialog && !dialog->isInputFocused()) { - if (keyboard.isActionActive(keyboard.KEY_MOVE_UP)) - dialog->move(1); - else if (keyboard.isActionActive(keyboard.KEY_MOVE_DOWN)) - dialog->move(-1); + if (keyboard.isActionActive(keyboard.KEY_MOVE_UP) + || keyboard.isActionActive(keyboard.KEY_MOVE_DOWN)) + { + dialog->refocus(); + } } } diff --git a/src/gui/npcdialog.cpp b/src/gui/npcdialog.cpp index 362d9db9d..1aeb76ec2 100644 --- a/src/gui/npcdialog.cpp +++ b/src/gui/npcdialog.cpp @@ -342,9 +342,20 @@ void NpcDialog::parseListItems(const std::string &itemString) mItems.push_back(tmp); if (!mItems.empty()) + { mItemList->setSelected(0); + mItemList->requestFocus(); + } else + { mItemList->setSelected(-1); + } +} + +void NpcDialog::refocus() +{ + if (!mItems.empty()) + mItemList->requestFocus(); } void NpcDialog::textRequest(const std::string &defaultText) diff --git a/src/gui/npcdialog.h b/src/gui/npcdialog.h index d4288d5c9..7bd2ee76d 100644 --- a/src/gui/npcdialog.h +++ b/src/gui/npcdialog.h @@ -177,6 +177,8 @@ class NpcDialog : public Window, public gcn::ActionListener, void restoreCamera(); + void refocus(); + private: typedef std::list DialogList; static DialogList instances; -- cgit v1.2.3-70-g09d2