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