1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-25 15:35:23 +00:00
OpenMW/apps/openmw/mwgui/textinput.cpp

85 lines
2.3 KiB
C++
Raw Normal View History

#include "textinput.hpp"
#include "../mwbase/windowmanager.hpp"
#include "../mwbase/environment.hpp"
2015-01-10 02:50:43 +01:00
#include <MyGUI_EditBox.h>
#include <MyGUI_Button.h>
2013-04-17 18:56:48 -04:00
namespace MWGui
{
2013-04-17 18:56:48 -04:00
TextInputDialog::TextInputDialog()
: WindowModal("openmw_text_input.layout")
{
// Centre dialog
center();
2013-04-17 18:56:48 -04:00
getWidget(mTextEdit, "TextEdit");
mTextEdit->eventEditSelectAccept += newDelegate(this, &TextInputDialog::onTextAccepted);
2013-04-17 18:56:48 -04:00
MyGUI::Button* okButton;
getWidget(okButton, "OKButton");
okButton->eventMouseButtonClick += MyGUI::newDelegate(this, &TextInputDialog::onOkClicked);
2013-04-17 18:56:48 -04:00
// Make sure the edit box has focus
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mTextEdit);
2013-04-17 18:56:48 -04:00
}
2013-04-17 18:56:48 -04:00
void TextInputDialog::setNextButtonShow(bool shown)
{
MyGUI::Button* okButton;
getWidget(okButton, "OKButton");
2013-04-17 18:56:48 -04:00
if (shown)
okButton->setCaption(MWBase::Environment::get().getWindowManager()->getGameSettingString("sNext", ""));
else
okButton->setCaption(MWBase::Environment::get().getWindowManager()->getGameSettingString("sOK", ""));
}
2013-04-17 18:56:48 -04:00
void TextInputDialog::setTextLabel(const std::string &label)
{
setText("LabelT", label);
}
void TextInputDialog::onOpen()
2013-04-17 18:56:48 -04:00
{
WindowModal::onOpen();
2013-04-17 18:56:48 -04:00
// Make sure the edit box has focus
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mTextEdit);
2013-04-17 18:56:48 -04:00
}
2013-04-17 18:56:48 -04:00
// widget controls
2013-04-17 18:56:48 -04:00
void TextInputDialog::onOkClicked(MyGUI::Widget* _sender)
{
if (mTextEdit->getCaption() == "")
2013-04-17 18:56:48 -04:00
{
MWBase::Environment::get().getWindowManager()->messageBox ("#{sNotifyMessage37}");
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget (mTextEdit);
2013-04-17 18:56:48 -04:00
}
else
eventDone(this);
}
2013-04-17 18:56:48 -04:00
void TextInputDialog::onTextAccepted(MyGUI::Edit* _sender)
{
onOkClicked(_sender);
2018-09-10 12:55:00 +04:00
// To do not spam onTextAccepted() again and again
MWBase::Environment::get().getWindowManager()->injectKeyRelease(MyGUI::KeyCode::None);
}
2013-04-17 18:56:48 -04:00
2015-01-10 02:50:43 +01:00
std::string TextInputDialog::getTextInput() const
{
return mTextEdit->getCaption();
2015-01-10 02:50:43 +01:00
}
void TextInputDialog::setTextInput(const std::string &text)
{
mTextEdit->setCaption(text);
}
}