From e81faf5f2f26006c8129a60f495e039da398cef0 Mon Sep 17 00:00:00 2001 From: scrawl <720642+scrawl@users.noreply.github.com> Date: Thu, 8 Mar 2018 23:39:35 +0000 Subject: [PATCH] Add an option to disable GUI keyboard navigation (Bug #4333) --- apps/openmw/mwgui/keyboardnavigation.cpp | 12 ++++++++++++ apps/openmw/mwgui/keyboardnavigation.hpp | 4 ++++ apps/openmw/mwgui/windowmanagerimp.cpp | 3 +++ components/widgets/imagebutton.cpp | 9 ++++++++- components/widgets/imagebutton.hpp | 4 ++++ files/settings-default.cfg | 3 +++ 6 files changed, 34 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwgui/keyboardnavigation.cpp b/apps/openmw/mwgui/keyboardnavigation.cpp index d27185204..1374ef93d 100644 --- a/apps/openmw/mwgui/keyboardnavigation.cpp +++ b/apps/openmw/mwgui/keyboardnavigation.cpp @@ -39,6 +39,7 @@ void getKeyFocusWidgets(MyGUI::Widget* parent, std::vector& resu KeyboardNavigation::KeyboardNavigation() : mCurrentFocus(nullptr) , mModalWindow(nullptr) + , mEnabled(true) { MyGUI::WidgetManager::getInstance().registerUnlinker(this); } @@ -101,6 +102,9 @@ bool isRootParent(MyGUI::Widget* widget, MyGUI::Widget* root) void KeyboardNavigation::onFrame() { + if (!mEnabled) + return; + MyGUI::Widget* focus = MyGUI::InputManager::getInstance().getKeyFocusWidget(); if (focus == mCurrentFocus) @@ -150,6 +154,11 @@ void KeyboardNavigation::setModalWindow(MyGUI::Widget *window) mModalWindow = window; } +void KeyboardNavigation::setEnabled(bool enabled) +{ + mEnabled = enabled; +} + enum Direction { D_Left, @@ -162,6 +171,9 @@ enum Direction bool KeyboardNavigation::injectKeyPress(MyGUI::KeyCode key, unsigned int text) { + if (!mEnabled) + return false; + switch (key.getValue()) { case MyGUI::KeyCode::ArrowLeft: diff --git a/apps/openmw/mwgui/keyboardnavigation.hpp b/apps/openmw/mwgui/keyboardnavigation.hpp index 728f16a3d..7caf25690 100644 --- a/apps/openmw/mwgui/keyboardnavigation.hpp +++ b/apps/openmw/mwgui/keyboardnavigation.hpp @@ -28,6 +28,8 @@ namespace MWGui void setModalWindow(MyGUI::Widget* window); + void setEnabled(bool enabled); + private: bool switchFocus(int direction, bool wrap); @@ -40,6 +42,8 @@ namespace MWGui MyGUI::Widget* mCurrentFocus; MyGUI::Widget* mModalWindow; + + bool mEnabled; }; } diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index 300f8e39f..065699817 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -237,7 +237,10 @@ namespace MWGui MyGUI::FactoryManager::getInstance().registerFactory("Resource", "ResourceImageSetPointer"); MyGUI::ResourceManager::getInstance().load("core.xml"); + bool keyboardNav = Settings::Manager::getBool("keyboard navigation", "GUI"); mKeyboardNavigation.reset(new KeyboardNavigation()); + mKeyboardNavigation->setEnabled(keyboardNav); + Gui::ImageButton::setDefaultNeedKeyFocus(keyboardNav); mLoadingScreen = new LoadingScreen(mResourceSystem->getVFS(), mViewer); mWindows.push_back(mLoadingScreen); diff --git a/components/widgets/imagebutton.cpp b/components/widgets/imagebutton.cpp index ab0739c2c..a3b0ae28a 100644 --- a/components/widgets/imagebutton.cpp +++ b/components/widgets/imagebutton.cpp @@ -5,13 +5,20 @@ namespace Gui { + bool ImageButton::sDefaultNeedKeyFocus = true; + ImageButton::ImageButton() : Base() , mMouseFocus(false) , mMousePress(false) , mKeyFocus(false) { - setNeedKeyFocus(true); + setNeedKeyFocus(sDefaultNeedKeyFocus); + } + + void ImageButton::setDefaultNeedKeyFocus(bool enabled) + { + sDefaultNeedKeyFocus = enabled; } void ImageButton::setPropertyOverride(const std::string &_key, const std::string &_value) diff --git a/components/widgets/imagebutton.hpp b/components/widgets/imagebutton.hpp index 509b1c8c2..bfcff7997 100644 --- a/components/widgets/imagebutton.hpp +++ b/components/widgets/imagebutton.hpp @@ -18,12 +18,16 @@ namespace Gui ImageButton(); + static void setDefaultNeedKeyFocus(bool enabled); + /// Set mImageNormal, mImageHighlighted and mImagePushed based on file convention (image_idle.ext, image_over.ext and image_pressed.ext) void setImage(const std::string& image); private: void updateImage(); + static bool sDefaultNeedKeyFocus; + protected: virtual void setPropertyOverride(const std::string& _key, const std::string& _value); virtual void onMouseLostFocus(MyGUI::Widget* _new); diff --git a/files/settings-default.cfg b/files/settings-default.cfg index 23fa3a7ee..9a62d986d 100644 --- a/files/settings-default.cfg +++ b/files/settings-default.cfg @@ -147,6 +147,9 @@ werewolf overlay = true color background owned = 0.15 0.0 0.0 1.0 color crosshair owned = 1.0 0.15 0.15 1.0 +# Controls whether Arrow keys, Movement keys, Tab/Shift-Tab and Spacebar/Enter/Activate may be used to navigate GUI buttons. +keyboard navigation = true + [HUD] # Displays the crosshair or reticle when not in GUI mode.