pressing enter when a messagebox is prompting for "ok", will activate ok button

This commit is contained in:
Tom Mason 2013-02-10 14:58:46 +00:00
parent 814969dcae
commit 158c6fc9fa
7 changed files with 50 additions and 2 deletions

View file

@ -199,6 +199,7 @@ namespace MWBase
///< Hides dialog and schedules dialog to be deleted. ///< Hides dialog and schedules dialog to be deleted.
virtual void messageBox (const std::string& message, const std::vector<std::string>& buttons) = 0; virtual void messageBox (const std::string& message, const std::vector<std::string>& buttons) = 0;
virtual void enterPressed () = 0;
virtual int readPressedButton() = 0; virtual int readPressedButton() = 0;
///< returns the index of the pressed button or -1 if no button was pressed (->MessageBoxmanager->InteractiveMessageBox) ///< returns the index of the pressed button or -1 if no button was pressed (->MessageBoxmanager->InteractiveMessageBox)

View file

@ -1,3 +1,5 @@
#include <components/misc/stringops.hpp>
#include "messagebox.hpp" #include "messagebox.hpp"
using namespace MWGui; using namespace MWGui;
@ -133,6 +135,10 @@ void MessageBoxManager::setMessageBoxSpeed (int speed)
mMessageBoxSpeed = speed; mMessageBoxSpeed = speed;
} }
void MessageBoxManager::enterPressed ()
{
mInterMessageBoxe->enterPressed();
}
int MessageBoxManager::readPressedButton () int MessageBoxManager::readPressedButton ()
{ {
@ -359,7 +365,25 @@ InteractiveMessageBox::InteractiveMessageBox(MessageBoxManager& parMessageBoxMan
} }
} }
void InteractiveMessageBox::enterPressed()
{
std::string ok = Misc::StringUtils::lowerCase(MyGUI::LanguageManager::getInstance().replaceTags("#{sOK}"));
std::vector<MyGUI::ButtonPtr>::const_iterator button;
for(button = mButtons.begin(); button != mButtons.end(); ++button)
{
if(Misc::StringUtils::lowerCase((*button)->getCaption()) == ok)
buttonActivated(*button);
}
}
void InteractiveMessageBox::mousePressed (MyGUI::Widget* pressed) void InteractiveMessageBox::mousePressed (MyGUI::Widget* pressed)
{
buttonActivated (pressed);
}
void InteractiveMessageBox::buttonActivated (MyGUI::Widget* pressed)
{ {
mMarkedToDelete = true; mMarkedToDelete = true;
int index = 0; int index = 0;

View file

@ -34,7 +34,8 @@ namespace MWGui
void removeMessageBox (float time, MessageBox *msgbox); void removeMessageBox (float time, MessageBox *msgbox);
bool removeMessageBox (MessageBox *msgbox); bool removeMessageBox (MessageBox *msgbox);
void setMessageBoxSpeed (int speed); void setMessageBoxSpeed (int speed);
void enterPressed();
int readPressedButton (); int readPressedButton ();
MWBase::WindowManager *mWindowManager; MWBase::WindowManager *mWindowManager;
@ -70,12 +71,15 @@ namespace MWGui
{ {
public: public:
InteractiveMessageBox (MessageBoxManager& parMessageBoxManager, const std::string& message, const std::vector<std::string>& buttons); InteractiveMessageBox (MessageBoxManager& parMessageBoxManager, const std::string& message, const std::vector<std::string>& buttons);
void enterPressed ();
void mousePressed (MyGUI::Widget* _widget); void mousePressed (MyGUI::Widget* _widget);
int readPressedButton (); int readPressedButton ();
bool mMarkedToDelete; bool mMarkedToDelete;
private: private:
void buttonActivated (MyGUI::Widget* _widget);
MessageBoxManager& mMessageBoxManager; MessageBoxManager& mMessageBoxManager;
MyGUI::EditPtr mMessageWidget; MyGUI::EditPtr mMessageWidget;
MyGUI::WidgetPtr mButtonsWidget; MyGUI::WidgetPtr mButtonsWidget;

View file

@ -560,6 +560,11 @@ void WindowManager::messageBox (const std::string& message, const std::vector<st
} }
} }
void WindowManager::enterPressed ()
{
mMessageBoxManager->enterPressed();
}
int WindowManager::readPressedButton () int WindowManager::readPressedButton ()
{ {
return mMessageBoxManager->readPressedButton(); return mMessageBoxManager->readPressedButton();

View file

@ -189,6 +189,7 @@ namespace MWGui
virtual void removeDialog(OEngine::GUI::Layout* dialog); ///< Hides dialog and schedules dialog to be deleted. virtual void removeDialog(OEngine::GUI::Layout* dialog); ///< Hides dialog and schedules dialog to be deleted.
virtual void messageBox (const std::string& message, const std::vector<std::string>& buttons); virtual void messageBox (const std::string& message, const std::vector<std::string>& buttons);
virtual void enterPressed ();
virtual int readPressedButton (); ///< returns the index of the pressed button or -1 if no button was pressed (->MessageBoxmanager->InteractiveMessageBox) virtual int readPressedButton (); ///< returns the index of the pressed button or -1 if no button was pressed (->MessageBoxmanager->InteractiveMessageBox)
virtual void onFrame (float frameDuration); virtual void onFrame (float frameDuration);

View file

@ -51,6 +51,7 @@ namespace MWInput
, mUIYMultiplier (Settings::Manager::getFloat("ui y multiplier", "Input")) , mUIYMultiplier (Settings::Manager::getFloat("ui y multiplier", "Input"))
, mPreviewPOVDelay(0.f) , mPreviewPOVDelay(0.f)
, mTimeIdle(0.f) , mTimeIdle(0.f)
, mEnterPressed(false)
{ {
Ogre::RenderWindow* window = ogre.getWindow (); Ogre::RenderWindow* window = ogre.getWindow ();
size_t windowHnd; size_t windowHnd;
@ -239,6 +240,10 @@ namespace MWInput
void InputManager::update(float dt, bool loading) void InputManager::update(float dt, bool loading)
{ {
// Pressing enter when a messagebox is prompting for "ok" will activate the ok button
if(mEnterPressed && MWBase::Environment::get().getWindowManager()->isGuiMode() && MWBase::Environment::get().getWindowManager()->getMode() == MWGui::GM_InterMessageBox)
MWBase::Environment::get().getWindowManager()->enterPressed();
// Tell OIS to handle all input events // Tell OIS to handle all input events
mKeyboard->capture(); mKeyboard->capture();
mMouse->capture(); mMouse->capture();
@ -251,7 +256,7 @@ namespace MWInput
// update values of channels (as a result of pressed keys) // update values of channels (as a result of pressed keys)
if (!loading) if (!loading)
mInputCtrl->update(dt); mInputCtrl->update(dt);
// Update windows/gui as a result of input events // Update windows/gui as a result of input events
// For instance this could mean opening a new window/dialog, // For instance this could mean opening a new window/dialog,
// by doing this after the input events are handled we // by doing this after the input events are handled we
@ -426,6 +431,9 @@ namespace MWInput
bool InputManager::keyPressed( const OIS::KeyEvent &arg ) bool InputManager::keyPressed( const OIS::KeyEvent &arg )
{ {
if(arg.key == OIS::KC_RETURN && MWBase::Environment::get().getWindowManager()->isGuiMode() && MWBase::Environment::get().getWindowManager()->getMode() != MWGui::GM_Console)
mEnterPressed = true;
mInputCtrl->keyPressed (arg); mInputCtrl->keyPressed (arg);
unsigned int text = arg.text; unsigned int text = arg.text;
#ifdef __APPLE__ // filter \016 symbol for F-keys on OS X #ifdef __APPLE__ // filter \016 symbol for F-keys on OS X
@ -442,6 +450,9 @@ namespace MWInput
bool InputManager::keyReleased( const OIS::KeyEvent &arg ) bool InputManager::keyReleased( const OIS::KeyEvent &arg )
{ {
if(arg.key == OIS::KC_RETURN)
mEnterPressed = false;
mInputCtrl->keyReleased (arg); mInputCtrl->keyReleased (arg);
MyGUI::InputManager::getInstance().injectKeyRelease(MyGUI::KeyCode::Enum(arg.key)); MyGUI::InputManager::getInstance().injectKeyRelease(MyGUI::KeyCode::Enum(arg.key));

View file

@ -151,6 +151,8 @@ namespace MWInput
std::map<std::string, bool> mControlSwitch; std::map<std::string, bool> mControlSwitch;
bool mEnterPressed;
private: private:
void adjustMouseRegion(int width, int height); void adjustMouseRegion(int width, int height);