mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-11-04 12:56:39 +00:00 
			
		
		
		
	Remember key focus per GUI mode
Among other things, this will remember the focused button in the container window, allowing quick looting of multiple containers.
This commit is contained in:
		
							parent
							
								
									35110fb2f8
								
							
						
					
					
						commit
						5f440a29bd
					
				
					 4 changed files with 48 additions and 21 deletions
				
			
		| 
						 | 
					@ -28,10 +28,35 @@ void getKeyFocusWidgets(MyGUI::Widget* parent, std::vector<MyGUI::Widget*>& resu
 | 
				
			||||||
 | 
					
 | 
				
			||||||
KeyboardNavigation::KeyboardNavigation()
 | 
					KeyboardNavigation::KeyboardNavigation()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					    MyGUI::WidgetManager::getInstance().registerUnlinker(this);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
KeyboardNavigation::~KeyboardNavigation()
 | 
					KeyboardNavigation::~KeyboardNavigation()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					    MyGUI::WidgetManager::getInstance().unregisterUnlinker(this);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void KeyboardNavigation::saveFocus(int mode)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    mKeyFocus[mode] = MyGUI::InputManager::getInstance().getKeyFocusWidget();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void KeyboardNavigation::restoreFocus(int mode)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    std::map<int, MyGUI::Widget*>::const_iterator found = mKeyFocus.find(mode);
 | 
				
			||||||
 | 
					    if (found != mKeyFocus.end())
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        MyGUI::Widget* w = found->second;
 | 
				
			||||||
 | 
					        if (w && w->getVisible() && w->getEnabled())
 | 
				
			||||||
 | 
					            MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(found->second);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void KeyboardNavigation::_unlinkWidget(MyGUI::Widget *widget)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    for (std::pair<const int, MyGUI::Widget*>& w : mKeyFocus)
 | 
				
			||||||
 | 
					        if (w.second == widget)
 | 
				
			||||||
 | 
					            w.second = nullptr;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool isButtonFocus()
 | 
					bool isButtonFocus()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,11 +2,12 @@
 | 
				
			||||||
#define OPENMW_MWGUI_KEYBOARDNAVIGATION_H
 | 
					#define OPENMW_MWGUI_KEYBOARDNAVIGATION_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <MyGUI_KeyCode.h>
 | 
					#include <MyGUI_KeyCode.h>
 | 
				
			||||||
 | 
					#include <MyGUI_IUnlinkWidget.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace MWGui
 | 
					namespace MWGui
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    class KeyboardNavigation
 | 
					    class KeyboardNavigation : public MyGUI::IUnlinkWidget
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
    public:
 | 
					    public:
 | 
				
			||||||
        KeyboardNavigation();
 | 
					        KeyboardNavigation();
 | 
				
			||||||
| 
						 | 
					@ -15,11 +16,18 @@ namespace MWGui
 | 
				
			||||||
        /// @return Was the key handled by this class?
 | 
					        /// @return Was the key handled by this class?
 | 
				
			||||||
        bool injectKeyPress(MyGUI::KeyCode key, unsigned int text);
 | 
					        bool injectKeyPress(MyGUI::KeyCode key, unsigned int text);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        void saveFocus(int mode);
 | 
				
			||||||
 | 
					        void restoreFocus(int mode);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        void _unlinkWidget(MyGUI::Widget* widget);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private:
 | 
					    private:
 | 
				
			||||||
        bool switchFocus(int direction, bool wrap);
 | 
					        bool switchFocus(int direction, bool wrap);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// Send button press event to focused button
 | 
					        /// Send button press event to focused button
 | 
				
			||||||
        bool accept();
 | 
					        bool accept();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        std::map<int, MyGUI::Widget*> mKeyFocus;
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -137,7 +137,6 @@ namespace MWGui
 | 
				
			||||||
      , mWorkQueue(workQueue)
 | 
					      , mWorkQueue(workQueue)
 | 
				
			||||||
      , mViewer(viewer)
 | 
					      , mViewer(viewer)
 | 
				
			||||||
      , mConsoleOnlyScripts(consoleOnlyScripts)
 | 
					      , mConsoleOnlyScripts(consoleOnlyScripts)
 | 
				
			||||||
      , mSaveKeyFocus(NULL)
 | 
					 | 
				
			||||||
      , mCurrentModals()
 | 
					      , mCurrentModals()
 | 
				
			||||||
      , mHud(NULL)
 | 
					      , mHud(NULL)
 | 
				
			||||||
      , mMap(NULL)
 | 
					      , mMap(NULL)
 | 
				
			||||||
| 
						 | 
					@ -261,8 +260,6 @@ namespace MWGui
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        MyGUI::InputManager::getInstance().eventChangeKeyFocus += MyGUI::newDelegate(this, &WindowManager::onKeyFocusChanged);
 | 
					        MyGUI::InputManager::getInstance().eventChangeKeyFocus += MyGUI::newDelegate(this, &WindowManager::onKeyFocusChanged);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        MyGUI::WidgetManager::getInstance().registerUnlinker(this);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Create all cursors in advance
 | 
					        // Create all cursors in advance
 | 
				
			||||||
        createCursors();
 | 
					        createCursors();
 | 
				
			||||||
        onCursorChange(MyGUI::PointerManager::getInstance().getDefaultPointer());
 | 
					        onCursorChange(MyGUI::PointerManager::getInstance().getDefaultPointer());
 | 
				
			||||||
| 
						 | 
					@ -505,8 +502,6 @@ namespace MWGui
 | 
				
			||||||
        MyGUI::ClipboardManager::getInstance().eventClipboardChanged.clear();
 | 
					        MyGUI::ClipboardManager::getInstance().eventClipboardChanged.clear();
 | 
				
			||||||
        MyGUI::ClipboardManager::getInstance().eventClipboardRequested.clear();
 | 
					        MyGUI::ClipboardManager::getInstance().eventClipboardRequested.clear();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        MyGUI::WidgetManager::getInstance().unregisterUnlinker(this);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        delete mConsole;
 | 
					        delete mConsole;
 | 
				
			||||||
        delete mMessageBoxManager;
 | 
					        delete mMessageBoxManager;
 | 
				
			||||||
        delete mHud;
 | 
					        delete mHud;
 | 
				
			||||||
| 
						 | 
					@ -1171,8 +1166,10 @@ namespace MWGui
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (!mGuiModes.empty())
 | 
					            if (!mGuiModes.empty())
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                mKeyboardNavigation->saveFocus(mGuiModes.back());
 | 
				
			||||||
                mGuiModeStates[mGuiModes.back()].update(false);
 | 
					                mGuiModeStates[mGuiModes.back()].update(false);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            mGuiModes.push_back(mode);
 | 
					            mGuiModes.push_back(mode);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            mGuiModeStates[mode].update(true);
 | 
					            mGuiModeStates[mode].update(true);
 | 
				
			||||||
| 
						 | 
					@ -1181,6 +1178,8 @@ namespace MWGui
 | 
				
			||||||
        for (WindowBase* window : mGuiModeStates[mode].mWindows)
 | 
					        for (WindowBase* window : mGuiModeStates[mode].mWindows)
 | 
				
			||||||
            window->setPtr(arg);
 | 
					            window->setPtr(arg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        mKeyboardNavigation->restoreFocus(mode);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        bool gameMode = !isGuiMode();
 | 
					        bool gameMode = !isGuiMode();
 | 
				
			||||||
        MWBase::Environment::get().getInputManager()->changeInputMode(!gameMode);
 | 
					        MWBase::Environment::get().getInputManager()->changeInputMode(!gameMode);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1197,6 +1196,7 @@ namespace MWGui
 | 
				
			||||||
        if (!mGuiModes.empty())
 | 
					        if (!mGuiModes.empty())
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            const GuiMode mode = mGuiModes.back();
 | 
					            const GuiMode mode = mGuiModes.back();
 | 
				
			||||||
 | 
					            mKeyboardNavigation->saveFocus(mode);
 | 
				
			||||||
            mGuiModes.pop_back();
 | 
					            mGuiModes.pop_back();
 | 
				
			||||||
            mGuiModeStates[mode].update(false);
 | 
					            mGuiModeStates[mode].update(false);
 | 
				
			||||||
            if (!noSound)
 | 
					            if (!noSound)
 | 
				
			||||||
| 
						 | 
					@ -1204,7 +1204,11 @@ namespace MWGui
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!mGuiModes.empty())
 | 
					        if (!mGuiModes.empty())
 | 
				
			||||||
            mGuiModeStates[mGuiModes.back()].update(true);
 | 
					        {
 | 
				
			||||||
 | 
					            const GuiMode mode = mGuiModes.back();
 | 
				
			||||||
 | 
					            mGuiModeStates[mode].update(true);
 | 
				
			||||||
 | 
					            mKeyboardNavigation->restoreFocus(mode);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        bool gameMode = !isGuiMode();
 | 
					        bool gameMode = !isGuiMode();
 | 
				
			||||||
        MWBase::Environment::get().getInputManager()->changeInputMode(!gameMode);
 | 
					        MWBase::Environment::get().getInputManager()->changeInputMode(!gameMode);
 | 
				
			||||||
| 
						 | 
					@ -1564,12 +1568,6 @@ namespace MWGui
 | 
				
			||||||
        return mLoadingScreen;
 | 
					        return mLoadingScreen;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void WindowManager::_unlinkWidget(MyGUI::Widget *widget)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        if (widget == mSaveKeyFocus)
 | 
					 | 
				
			||||||
            mSaveKeyFocus = NULL;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    bool WindowManager::getCursorVisible()
 | 
					    bool WindowManager::getCursorVisible()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return mCursorVisible;
 | 
					        return mCursorVisible;
 | 
				
			||||||
| 
						 | 
					@ -1789,7 +1787,7 @@ namespace MWGui
 | 
				
			||||||
    void WindowManager::addCurrentModal(WindowModal *input)
 | 
					    void WindowManager::addCurrentModal(WindowModal *input)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if (mCurrentModals.empty())
 | 
					        if (mCurrentModals.empty())
 | 
				
			||||||
            mSaveKeyFocus = MyGUI::InputManager::getInstance().getKeyFocusWidget();
 | 
					            mKeyboardNavigation->saveFocus(getMode());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        mCurrentModals.push(input);
 | 
					        mCurrentModals.push(input);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -1803,7 +1801,7 @@ namespace MWGui
 | 
				
			||||||
                mCurrentModals.pop();
 | 
					                mCurrentModals.pop();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (mCurrentModals.empty())
 | 
					        if (mCurrentModals.empty())
 | 
				
			||||||
            MyGUI::InputManager::getInstance().setKeyFocusWidget(mSaveKeyFocus);
 | 
					            mKeyboardNavigation->restoreFocus(getMode());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void WindowManager::onVideoKeyPressed(MyGUI::Widget *_sender, MyGUI::KeyCode _key, MyGUI::Char _char)
 | 
					    void WindowManager::onVideoKeyPressed(MyGUI::Widget *_sender, MyGUI::KeyCode _key, MyGUI::Char _char)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -124,7 +124,7 @@ namespace MWGui
 | 
				
			||||||
  class JailScreen;
 | 
					  class JailScreen;
 | 
				
			||||||
  class KeyboardNavigation;
 | 
					  class KeyboardNavigation;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  class WindowManager : public MWBase::WindowManager, MyGUI::IUnlinkWidget
 | 
					  class WindowManager : public MWBase::WindowManager
 | 
				
			||||||
  {
 | 
					  {
 | 
				
			||||||
  public:
 | 
					  public:
 | 
				
			||||||
    typedef std::pair<std::string, int> Faction;
 | 
					    typedef std::pair<std::string, int> Faction;
 | 
				
			||||||
| 
						 | 
					@ -142,8 +142,6 @@ namespace MWGui
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    virtual Loading::Listener* getLoadingScreen();
 | 
					    virtual Loading::Listener* getLoadingScreen();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void _unlinkWidget(MyGUI::Widget* widget);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /// @note This method will block until the video finishes playing
 | 
					    /// @note This method will block until the video finishes playing
 | 
				
			||||||
    /// (and will continually update the window while doing so)
 | 
					    /// (and will continually update the window while doing so)
 | 
				
			||||||
    virtual void playVideo(const std::string& name, bool allowSkipping);
 | 
					    virtual void playVideo(const std::string& name, bool allowSkipping);
 | 
				
			||||||
| 
						 | 
					@ -406,8 +404,6 @@ namespace MWGui
 | 
				
			||||||
    MWWorld::Ptr mSelectedEnchantItem;
 | 
					    MWWorld::Ptr mSelectedEnchantItem;
 | 
				
			||||||
    MWWorld::Ptr mSelectedWeapon;
 | 
					    MWWorld::Ptr mSelectedWeapon;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    MyGUI::Widget* mSaveKeyFocus;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    std::stack<WindowModal*> mCurrentModals;
 | 
					    std::stack<WindowModal*> mCurrentModals;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Markers placed manually by the player. Must be shared between both map views (the HUD map and the map window).
 | 
					    // Markers placed manually by the player. Must be shared between both map views (the HUD map and the map window).
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue