Add an option to disable GUI keyboard navigation (Bug #4333)

pull/392/head
scrawl 7 years ago
parent 870c658500
commit e81faf5f2f
No known key found for this signature in database
GPG Key ID: 2E6CC3676024C402

@ -39,6 +39,7 @@ void getKeyFocusWidgets(MyGUI::Widget* parent, std::vector<MyGUI::Widget*>& resu
KeyboardNavigation::KeyboardNavigation() KeyboardNavigation::KeyboardNavigation()
: mCurrentFocus(nullptr) : mCurrentFocus(nullptr)
, mModalWindow(nullptr) , mModalWindow(nullptr)
, mEnabled(true)
{ {
MyGUI::WidgetManager::getInstance().registerUnlinker(this); MyGUI::WidgetManager::getInstance().registerUnlinker(this);
} }
@ -101,6 +102,9 @@ bool isRootParent(MyGUI::Widget* widget, MyGUI::Widget* root)
void KeyboardNavigation::onFrame() void KeyboardNavigation::onFrame()
{ {
if (!mEnabled)
return;
MyGUI::Widget* focus = MyGUI::InputManager::getInstance().getKeyFocusWidget(); MyGUI::Widget* focus = MyGUI::InputManager::getInstance().getKeyFocusWidget();
if (focus == mCurrentFocus) if (focus == mCurrentFocus)
@ -150,6 +154,11 @@ void KeyboardNavigation::setModalWindow(MyGUI::Widget *window)
mModalWindow = window; mModalWindow = window;
} }
void KeyboardNavigation::setEnabled(bool enabled)
{
mEnabled = enabled;
}
enum Direction enum Direction
{ {
D_Left, D_Left,
@ -162,6 +171,9 @@ enum Direction
bool KeyboardNavigation::injectKeyPress(MyGUI::KeyCode key, unsigned int text) bool KeyboardNavigation::injectKeyPress(MyGUI::KeyCode key, unsigned int text)
{ {
if (!mEnabled)
return false;
switch (key.getValue()) switch (key.getValue())
{ {
case MyGUI::KeyCode::ArrowLeft: case MyGUI::KeyCode::ArrowLeft:

@ -28,6 +28,8 @@ namespace MWGui
void setModalWindow(MyGUI::Widget* window); void setModalWindow(MyGUI::Widget* window);
void setEnabled(bool enabled);
private: private:
bool switchFocus(int direction, bool wrap); bool switchFocus(int direction, bool wrap);
@ -40,6 +42,8 @@ namespace MWGui
MyGUI::Widget* mCurrentFocus; MyGUI::Widget* mCurrentFocus;
MyGUI::Widget* mModalWindow; MyGUI::Widget* mModalWindow;
bool mEnabled;
}; };
} }

@ -237,7 +237,10 @@ namespace MWGui
MyGUI::FactoryManager::getInstance().registerFactory<ResourceImageSetPointerFix>("Resource", "ResourceImageSetPointer"); MyGUI::FactoryManager::getInstance().registerFactory<ResourceImageSetPointerFix>("Resource", "ResourceImageSetPointer");
MyGUI::ResourceManager::getInstance().load("core.xml"); MyGUI::ResourceManager::getInstance().load("core.xml");
bool keyboardNav = Settings::Manager::getBool("keyboard navigation", "GUI");
mKeyboardNavigation.reset(new KeyboardNavigation()); mKeyboardNavigation.reset(new KeyboardNavigation());
mKeyboardNavigation->setEnabled(keyboardNav);
Gui::ImageButton::setDefaultNeedKeyFocus(keyboardNav);
mLoadingScreen = new LoadingScreen(mResourceSystem->getVFS(), mViewer); mLoadingScreen = new LoadingScreen(mResourceSystem->getVFS(), mViewer);
mWindows.push_back(mLoadingScreen); mWindows.push_back(mLoadingScreen);

@ -5,13 +5,20 @@
namespace Gui namespace Gui
{ {
bool ImageButton::sDefaultNeedKeyFocus = true;
ImageButton::ImageButton() ImageButton::ImageButton()
: Base() : Base()
, mMouseFocus(false) , mMouseFocus(false)
, mMousePress(false) , mMousePress(false)
, mKeyFocus(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) void ImageButton::setPropertyOverride(const std::string &_key, const std::string &_value)

@ -18,12 +18,16 @@ namespace Gui
ImageButton(); 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) /// 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); void setImage(const std::string& image);
private: private:
void updateImage(); void updateImage();
static bool sDefaultNeedKeyFocus;
protected: protected:
virtual void setPropertyOverride(const std::string& _key, const std::string& _value); virtual void setPropertyOverride(const std::string& _key, const std::string& _value);
virtual void onMouseLostFocus(MyGUI::Widget* _new); virtual void onMouseLostFocus(MyGUI::Widget* _new);

@ -147,6 +147,9 @@ werewolf overlay = true
color background owned = 0.15 0.0 0.0 1.0 color background owned = 0.15 0.0 0.0 1.0
color crosshair owned = 1.0 0.15 0.15 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] [HUD]
# Displays the crosshair or reticle when not in GUI mode. # Displays the crosshair or reticle when not in GUI mode.

Loading…
Cancel
Save