diff options
author | Andrei Karas <akaras@inbox.ru> | 2014-12-08 22:20:27 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2014-12-08 22:20:27 +0300 |
commit | f019a9e52d0a3f5ca23681d5eb36bb2e56d37064 (patch) | |
tree | 33c4f14a56d1327b361dcc681712cfc105a7701e /src | |
parent | 13b08d35c2d96ae734da14ab58d6263287e342c9 (diff) | |
download | plus-f019a9e52d0a3f5ca23681d5eb36bb2e56d37064.tar.gz plus-f019a9e52d0a3f5ca23681d5eb36bb2e56d37064.tar.bz2 plus-f019a9e52d0a3f5ca23681d5eb36bb2e56d37064.tar.xz plus-f019a9e52d0a3f5ca23681d5eb36bb2e56d37064.zip |
Allow control popup menu by up/down keys.
Diffstat (limited to 'src')
-rw-r--r-- | src/actions/actions.cpp | 4 | ||||
-rw-r--r-- | src/actions/move.cpp | 12 | ||||
-rw-r--r-- | src/gui/popups/popupmenu.cpp | 15 | ||||
-rw-r--r-- | src/gui/popups/popupmenu.h | 6 | ||||
-rw-r--r-- | src/gui/widgets/browserbox.cpp | 28 | ||||
-rw-r--r-- | src/gui/widgets/browserbox.h | 6 |
6 files changed, 71 insertions, 0 deletions
diff --git a/src/actions/actions.cpp b/src/actions/actions.cpp index 924fac801..64d05f8ab 100644 --- a/src/actions/actions.cpp +++ b/src/actions/actions.cpp @@ -246,6 +246,10 @@ impHandler0(ok) dialog->action(ActionEvent(nullptr, "ok")); return true; } + else if (popupMenu->isPopupVisible()) + { + popupMenu->select(); + } return false; } diff --git a/src/actions/move.cpp b/src/actions/move.cpp index 0fa4d4897..c75d24c36 100644 --- a/src/actions/move.cpp +++ b/src/actions/move.cpp @@ -30,6 +30,8 @@ #include "gui/windows/npcdialog.h" #include "gui/windows/outfitwindow.h" +#include "gui/popups/popupmenu.h" + #include "net/playerhandler.h" #include "debug.h" @@ -59,6 +61,11 @@ impHandler(moveUp) { if (inputManager.isActionActive(InputAction::EMOTE)) return directUp(event); + if (popupMenu->isPopupVisible()) + { + popupMenu->moveUp(); + return true; + } return closeMoveNpcDialog(false); } @@ -66,6 +73,11 @@ impHandler(moveDown) { if (inputManager.isActionActive(InputAction::EMOTE)) return directDown(event); + if (popupMenu->isPopupVisible()) + { + popupMenu->moveDown(); + return true; + } return closeMoveNpcDialog(false); } diff --git a/src/gui/popups/popupmenu.cpp b/src/gui/popups/popupmenu.cpp index f6a2959bd..eb2144de3 100644 --- a/src/gui/popups/popupmenu.cpp +++ b/src/gui/popups/popupmenu.cpp @@ -3035,3 +3035,18 @@ void PopupMenu::showGMPopup() showPopup(getX(), getY()); } + +void PopupMenu::moveUp() +{ + mBrowserBox->moveSelectionUp(); +} + +void PopupMenu::moveDown() +{ + mBrowserBox->moveSelectionDown(); +} + +void PopupMenu::select() +{ + mBrowserBox->selectSelection(); +} diff --git a/src/gui/popups/popupmenu.h b/src/gui/popups/popupmenu.h index c98e6a26e..da0f59847 100644 --- a/src/gui/popups/popupmenu.h +++ b/src/gui/popups/popupmenu.h @@ -148,6 +148,12 @@ class PopupMenu final : public Popup, public LinkHandler void clear(); + void moveUp(); + + void moveDown(); + + void select(); + private: void setMousePos(); diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp index f6f86a42d..f87bc23e3 100644 --- a/src/gui/widgets/browserbox.cpp +++ b/src/gui/widgets/browserbox.cpp @@ -914,3 +914,31 @@ void BrowserBox::setForegroundColorAll(const Color &color1, mForegroundColor = color1; mForegroundColor2 = color2; } + +void BrowserBox::moveSelectionUp() +{ + if (mSelectedLink <= 0) + mSelectedLink = static_cast<signed>(mLinks.size()) - 1; + else + mSelectedLink --; +} + +#include "logger.h" + +void BrowserBox::moveSelectionDown() +{ + mSelectedLink ++; + if (mSelectedLink >= static_cast<signed int>(mLinks.size())) + mSelectedLink = 0; +} + +void BrowserBox::selectSelection() +{ + if (mSelectedLink < 0 || mSelectedLink >= static_cast<signed int>( + mLinks.size())) + { + return; + } + + mLinkHandler->handleLink(mLinks[mSelectedLink].link, nullptr); +} diff --git a/src/gui/widgets/browserbox.h b/src/gui/widgets/browserbox.h index 85bb758f9..4fdb45189 100644 --- a/src/gui/widgets/browserbox.h +++ b/src/gui/widgets/browserbox.h @@ -196,6 +196,12 @@ class BrowserBox final : public Widget, int getDataWidth() const { return mDataWidth; } + void moveSelectionUp(); + + void moveSelectionDown(); + + void selectSelection(); + private: int calcHeight() A_WARN_UNUSED; |