Restore the previous key focus widget when exiting modal dialog

new-script-api
scrawl 7 years ago
parent bbafe1e456
commit 269094ba8d

@ -67,14 +67,15 @@ WindowModal::WindowModal(const std::string& parLayout)
void WindowModal::onOpen()
{
MyGUI::InputManager::getInstance ().addWidgetModal (mMainWidget);
// Order important. We need to save the key focus widget before its unset
MWBase::Environment::get().getWindowManager()->addCurrentModal(this); //Set so we can escape it if needed
MyGUI::InputManager::getInstance ().addWidgetModal (mMainWidget);
}
void WindowModal::onClose()
{
MyGUI::InputManager::getInstance ().removeWidgetModal (mMainWidget);
MWBase::Environment::get().getWindowManager()->removeCurrentModal(this);
MyGUI::InputManager::getInstance ().removeWidgetModal (mMainWidget);
}
NoDrop::NoDrop(DragAndDrop *drag, MyGUI::Widget *widget)

@ -16,6 +16,7 @@
#include <MyGUI_Gui.h>
#include <MyGUI_ClipboardManager.h>
#include <MyGUI_RenderManager.h>
#include <MyGUI_WidgetManager.h>
#include <SDL_keyboard.h>
#include <SDL_clipboard.h>
@ -136,6 +137,7 @@ namespace MWGui
, mWorkQueue(workQueue)
, mViewer(viewer)
, mConsoleOnlyScripts(consoleOnlyScripts)
, mSaveKeyFocus(NULL)
, mCurrentModals()
, mHud(NULL)
, mMap(NULL)
@ -260,6 +262,8 @@ 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());
@ -496,6 +500,8 @@ namespace MWGui
MyGUI::ClipboardManager::getInstance().eventClipboardChanged.clear();
MyGUI::ClipboardManager::getInstance().eventClipboardRequested.clear();
MyGUI::WidgetManager::getInstance().unregisterUnlinker(this);
delete mConsole;
delete mMessageBoxManager;
delete mHud;
@ -1608,6 +1614,12 @@ namespace MWGui
return mLoadingScreen;
}
void WindowManager::_unlinkWidget(MyGUI::Widget *widget)
{
if (widget == mSaveKeyFocus)
mSaveKeyFocus = NULL;
}
bool WindowManager::getCursorVisible()
{
return mCursorVisible;
@ -1818,6 +1830,17 @@ namespace MWGui
{
if (!mCurrentModals.empty())
mCurrentModals.top()->exit();
if (mCurrentModals.empty())
MyGUI::InputManager::getInstance().setKeyFocusWidget(mSaveKeyFocus);
}
void WindowManager::addCurrentModal(WindowModal *input)
{
if (mCurrentModals.empty())
mSaveKeyFocus = MyGUI::InputManager::getInstance().getKeyFocusWidget();
mCurrentModals.push(input);
}
void WindowManager::removeCurrentModal(WindowModal* input)
@ -1827,6 +1850,9 @@ namespace MWGui
if(!mCurrentModals.empty())
if(input == mCurrentModals.top())
mCurrentModals.pop();
if (mCurrentModals.empty())
MyGUI::InputManager::getInstance().setKeyFocusWidget(mSaveKeyFocus);
}
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
class WindowManager : public MWBase::WindowManager, MyGUI::IUnlinkWidget
{
public:
typedef std::pair<std::string, int> Faction;
@ -142,6 +142,8 @@ 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);
@ -341,7 +343,7 @@ namespace MWGui
/// Sets the current Modal
/** Used to send exit command to active Modal when Esc is pressed **/
virtual void addCurrentModal(WindowModal* input) {mCurrentModals.push(input);}
virtual void addCurrentModal(WindowModal* input);
/// Removes the top Modal
/** Used when one Modal adds another Modal
@ -404,6 +406,8 @@ 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…
Cancel
Save